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`...');
var npm_update = spawn('npm', ['update', '-g', 'commonplace']);
npm_update.stdout.on('data', function(data) {
console.log('[npm]', data + '');
});
npm_update.stderr.on('data', function(data) {
console.warn('[npm]', data + '');
});
function writer(stream) {
var new_line = true;
return function(data) {
if (new_line) {
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) {
if (code !== 0) {
@ -92,54 +102,58 @@ function update() {
return;
}
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 local_src = path.resolve(process.cwd(), info.src_dir());
var commonplace_src = path.resolve(__dirname, '../src');
var local_src = path.resolve(process.cwd(), info.src_dir());
_check_version(
local_src,
function() { // Same
console.warn('Commonplace installation up-to-date.');
process.exit();
},
function(local_version, current_version) { // Different
console.log('Updating from ' + local_version + ' to ' + current_version);
},
function() { // Neither
console.error('No commonplace installation found.');
process.exit(1);
}
);
_check_version(
local_src,
function() { // Same
console.warn('Commonplace installation up-to-date.');
process.exit();
},
function(local_version, current_version) { // Different
console.log('Updating from ' + local_version + ' to ' + current_version);
},
function() { // Neither
console.error('No commonplace installation found.');
process.exit(1);
}
);
function update_file(file) {
fs.readFile(file, function(err, data) {
fs.writeFile(file.replace(commonplace_src, local_src), data, function(err) {
if (err) {
console.error('Error updating ' + file, err);
}
});
function update_file(file) {
fs.readFile(file, function(err, data) {
fs.writeFile(file.replace(commonplace_src, local_src), data, function(err) {
if (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'];
function 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);
}
var ext = extensions.pop();
console.log('Updating ' + ext + ' files.');
utils.globEach(commonplace_src, ext, update_file, update_type);
}
}