2
0
mirror of https://github.com/thumbsup/thumbsup synced 2024-11-03 15:40:14 +00:00

Fix #1 : report progress of operations in the console

This commit is contained in:
rprieto 2014-05-19 22:23:59 +10:00
parent d7d9a9e3a9
commit 1687999976
2 changed files with 95 additions and 93 deletions

View File

@ -4,11 +4,8 @@ var path = require('path');
var async = require('async');
var pad = require('pad');
var regen = require('regen');
var galleries = require('./galleries');
var render = require('./render');
var website = require('./website');
var thumbs = require('./thumbs');
var files = require('./files');
exports.build = function(opts) {
@ -27,131 +24,71 @@ exports.build = function(opts) {
fs.mkdirp(opts.output);
var media = path.join(opts.output, 'media');
function website(callback) {
galleries.fromDisk(opts.input, opts.thumbSize, function(err, list) {
if (err) return callback(err);
var style = opts.css ? path.basename(opts.css) : null;
async.series([
var rendered = render.gallery(list, list[0], opts.title, style);
var outputPath = path.join(opts.output, 'index.html');
fs.writeFileSync(outputPath, rendered);
list.forEach(function(folder) {
var rendered = render.gallery(list, folder, opts.title, style);
var outputPath = path.join(opts.output, folder.url);
fs.writeFileSync(outputPath, rendered);
});
callback();
});
}
function staticWebsite(callback) {
website.build(opts, callback);
},
function support(callback) {
var src = path.join(__dirname, '..', 'public');
var dest = path.join(opts.output, 'public');
copyFolder(src, dest, callback);
}
function customStyle(callback) {
if (opts.css) {
var dest = path.join(opts.output, 'public', path.basename(opts.css));
fs.copy(opts.css, dest, callback);
} else {
callback();
}
}
function copyMedia(callback) {
regen({
buildStep('Original media', {
cwd: opts.input,
src: '**/*.{jpg,jpeg,png,mp4,mov}',
dest: media + '/original/$path/$name.$ext',
process: fs.copy
}, callback);
}
}),
function photoLarge(callback) {
regen({
buildStep('Photos (large)', {
cwd: opts.input,
src: '**/*.{jpg,jpeg,png}',
dest: media + '/large/$path/$name.$ext',
process: thumbs.photoLarge
}, callback);
}
process: thumbs.photoLarge,
}),
function photoThumbs(callback) {
regen({
buildStep('Photos (thumbs)', {
cwd: opts.input,
src: '**/*.{jpg,jpeg,png}',
dest: media + '/thumbs/$path/$name.$ext',
process: thumbs.photoSquare
}, callback);
}
process: thumbs.photoSquare,
}),
function videoWeb(callback) {
regen({
buildStep('Videos (web)', {
cwd: opts.input,
src: '**/*.{mp4,mov}',
dest: media + '/large/$path/$name.mp4',
process: thumbs.videoWeb
}, callback);
}
process: thumbs.videoWeb,
}),
function videoLarge(callback) {
regen({
buildStep('Videos (poster)', {
cwd: opts.input,
src: '**/*.{mp4,mov}',
dest: media + '/large/$path/$name.jpg',
process: thumbs.videoLarge
}, callback);
}
process: thumbs.videoLarge,
}),
function videoThumbs(callback) {
regen({
buildStep('Videos (thumbs)', {
cwd: opts.input,
src: '**/*.{mp4,mov}',
dest: media + '/thumbs/$path/$name.jpg',
process: thumbs.videoSquare
}, callback);
}
process: thumbs.videoSquare,
})
async.series([
step('Website', website),
step('Support', support),
step('Custom styles', customStyle),
step('Original media', copyMedia),
step('Photos (large)', photoLarge),
step('Photos (thumbs)', photoThumbs),
step('Videos (web)', videoWeb),
step('Videos (large)', videoLarge),
step('Videos (thumbs)', videoThumbs)
], finish);
};
function copyFolder(src, dest, callback) {
var src = path.resolve(src);
var dest = path.resolve(dest);
if (files.newer(src, dest)) {
fs.copy(src, dest, callback);
} else {
callback();
function buildStep(message, opts) {
return function(callback) {
regen(_.extend(opts, {
report: pad(message, 20) + '$progress'
}), callback);
}
}
function step(msg, fn) {
return function(callback) {
console.log(pad(msg, 20) + '[STARTED]')
fn(function(err) {
console.log(pad(msg, 20) + (err ? '[FAILED]\n' : '[OK]'));
callback(err);
});
};
}
function finish(err) {
console.log(err || 'Done');
console.log();
console.log(err || 'Gallery generated successfully');
console.log();
process.exit(err ? 1 : 0)
}

65
src/website.js Normal file
View File

@ -0,0 +1,65 @@
var fs = require('fs-extra');
var path = require('path');
var async = require('async');
var pad = require('pad');
var galleries = require('./galleries');
var render = require('./render');
var files = require('./files');
exports.build = function(opts, callback) {
function website(callback) {
galleries.fromDisk(opts.input, opts.thumbSize, function(err, list) {
if (err) return callback(err);
var style = opts.css ? path.basename(opts.css) : null;
var rendered = render.gallery(list, list[0], opts.title, style);
var outputPath = path.join(opts.output, 'index.html');
fs.writeFileSync(outputPath, rendered);
list.forEach(function(folder) {
var rendered = render.gallery(list, folder, opts.title, style);
var outputPath = path.join(opts.output, folder.url);
fs.writeFileSync(outputPath, rendered);
});
callback();
});
}
function support(callback) {
var src = path.join(__dirname, '..', 'public');
var dest = path.join(opts.output, 'public');
copyFolder(src, dest, callback);
}
function customStyle(callback) {
if (opts.css) {
var dest = path.join(opts.output, 'public', path.basename(opts.css));
fs.copy(opts.css, dest, callback);
} else {
callback();
}
}
process.stdout.write(pad('Static website', 20));
async.series([], function(err) {
process.stdout
callback(err);
console.log('[===================] done');
});
};
function copyFolder(src, dest, callback) {
var src = path.resolve(src);
var dest = path.resolve(dest);
if (files.newer(src, dest)) {
fs.copy(src, dest, callback);
} else {
callback();
}
}