Support for bootstrapping updated commonplace scripts

This commit is contained in:
Matt Basta 2013-08-06 16:17:53 -07:00
Родитель 35219d959f
Коммит 1c1f1761cb
1 изменённых файлов: 60 добавлений и 46 удалений

Просмотреть файл

@ -79,12 +79,22 @@ function update() {
console.log('Starting `npm update`...'); console.log('Starting `npm update`...');
var npm_update = spawn('npm', ['update', '-g', 'commonplace']); var npm_update = spawn('npm', ['update', '-g', 'commonplace']);
npm_update.stdout.on('data', function(data) { function writer(stream) {
console.log('[npm]', data + ''); var new_line = true;
}); return function(data) {
npm_update.stderr.on('data', function(data) { if (new_line) {
console.warn('[npm]', data + ''); process.stdout.write('[npm] ');
}); new_line = false;
}
process.stdout.write(data);
if (data[data.length - 1] == '\n') {
new_line = true;
}
}
}
npm_update.stdout.on('data', writer(process.stdout));
npm_update.stderr.on('data', writer(process.stderr));
npm_update.on('close', function(code) { npm_update.on('close', function(code) {
if (code !== 0) { if (code !== 0) {
@ -92,54 +102,58 @@ function update() {
return; return;
} }
console.log('`npm update` complete.'); console.log('`npm update` complete.');
do_update();
spawn('commonplace', ['update']).on('close', function(code) {
if (code) {
console.error('Error updating commonplace');
} else {
console.log('Bootstrapped commonplace update successful!');
}
});
}); });
} else {
do_update(); return;
} }
function do_update() { var commonplace_src = path.resolve(__dirname, '../src');
var commonplace_src = path.resolve(__dirname, '../src'); var local_src = path.resolve(process.cwd(), info.src_dir());
var local_src = path.resolve(process.cwd(), info.src_dir());
_check_version( _check_version(
local_src, local_src,
function() { // Same function() { // Same
console.warn('Commonplace installation up-to-date.'); console.warn('Commonplace installation up-to-date.');
process.exit(); process.exit();
}, },
function(local_version, current_version) { // Different function(local_version, current_version) { // Different
console.log('Updating from ' + local_version + ' to ' + current_version); console.log('Updating from ' + local_version + ' to ' + current_version);
}, },
function() { // Neither function() { // Neither
console.error('No commonplace installation found.'); console.error('No commonplace installation found.');
process.exit(1); process.exit(1);
} }
); );
function update_file(file) { function update_file(file) {
fs.readFile(file, function(err, data) { fs.readFile(file, function(err, data) {
fs.writeFile(file.replace(commonplace_src, local_src), data, function(err) { fs.writeFile(file.replace(commonplace_src, local_src), data, function(err) {
if (err) { if (err) {
console.error('Error updating ' + file, err); console.error('Error updating ' + file, err);
} }
});
}); });
});
}
var extensions = ['.js', '.dist', '.woff', '.svg'];
function update_type() {
if (!extensions.length) {
console.log('Update complete!');
return;
} }
var extensions = ['.js', '.dist', '.woff', '.svg']; var ext = extensions.pop();
console.log('Updating ' + ext + ' files.');
function update_type() { utils.globEach(commonplace_src, ext, update_file, update_type);
if (!extensions.length) {
console.log('Update complete!');
return;
}
var ext = extensions.pop();
console.log('Updating ' + ext + ' files.');
utils.globEach(commonplace_src, ext, update_file, update_type);
}
} }
} }