You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
thumbsup/src/index.js

52 lines
1.2 KiB
JavaScript

const fs = require('fs-extra')
const Listr = require('listr')
const steps = require('./steps/index')
const summary = require('./steps/summary')
const website = require('./website/website')
10 years ago
exports.build = function (opts) {
const tasks = new Listr([
{
title: 'Indexing folder',
task: (ctx, task) => {
fs.mkdirpSync(opts.output)
return steps.index(opts, (err, files, album) => {
if (!err) {
ctx.files = files
ctx.album = album
}
})
}
},
{
title: 'Resizing media',
task: (ctx, task) => {
return steps.process(ctx.files, opts, task)
}
},
{
title: 'Cleaning up',
enabled: (ctx) => opts.cleanup,
task: (ctx) => {
return steps.cleanup(ctx.files, opts.output)
}
},
{
title: 'Creating website',
task: (ctx) => new Promise((resolve, reject) => {
website.build(ctx.album, opts, err => {
err ? reject(err) : resolve()
})
})
}
])
tasks.run().then(ctx => {
console.log('\n' + summary.create(ctx) + '\n')
process.exit(0)
}).catch(err => {
console.log('\nUnexpected error', err)
process.exit(1)
})
}