зеркало из https://github.com/mozilla/commonplace.git
remove fiddle (bug TBD)
This commit is contained in:
Родитель
01657d4158
Коммит
b31bd23b3f
|
@ -8,7 +8,6 @@ function help() {
|
|||
'Commands:',
|
||||
' extract_strings This command will extract strings into a `.pot` file.',
|
||||
' langpacks This command will generate langpacks out of `.po` files.',
|
||||
' fiddle Installs Commonplace project dependencies.',
|
||||
'',
|
||||
'Read more: https://github.com/mozilla/commonplace/wiki/CLI-Tools'
|
||||
].join('\n'));
|
||||
|
@ -27,25 +26,27 @@ var commonplace = require('../lib/commonplace');
|
|||
|
||||
switch (argv[0]) {
|
||||
case 'clean':
|
||||
console.log('This command has been deprecated by Gulp. Use `make clean` instead.');
|
||||
console.log('This command has been removed. Use `make clean` instead.');
|
||||
break;
|
||||
case 'compile':
|
||||
console.log('This command has been deprecated by Gulp. Use `make build` instead.');
|
||||
console.log('This command has been remove. Use `make build` instead.');
|
||||
break;
|
||||
case 'extract_strings':
|
||||
commonplace.extract_l10n();
|
||||
break;
|
||||
case 'includes':
|
||||
console.log('This command has been deprecated by Gulp. Use `make build` instead.');
|
||||
console.log('This command has been removed. Use `make build` instead.');
|
||||
break;
|
||||
case 'langpacks':
|
||||
commonplace.generate_langpacks();
|
||||
break;
|
||||
case 'lint':
|
||||
console.log('This command has been deprecated by Gulp. Use `make lint` instead.');
|
||||
console.log('This command has been removed. Use `make lint` instead.');
|
||||
break;
|
||||
case 'fiddle':
|
||||
commonplace.fiddle();
|
||||
console.log('This command has been removed. ' +
|
||||
'Use http://marketplace.readthedocs.org/latest/topics/docker.html ' +
|
||||
'instead.');
|
||||
break;
|
||||
case 'help':
|
||||
help();
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
var child_process = require('child_process');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
|
@ -135,150 +134,8 @@ function extract_l10n() {
|
|||
}
|
||||
|
||||
|
||||
function fiddle() {
|
||||
var now = (new Date()).getTime();
|
||||
var package_json_path = path.resolve(process.cwd(), 'package.json');
|
||||
if (!fs.existsSync(package_json_path)) {
|
||||
console.error('No package.json file found.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
var package_json = fs.readFileSync(package_json_path);
|
||||
var package_json_parsed = JSON.parse(package_json.toString());
|
||||
|
||||
// Check that there are deps to extract.
|
||||
if (!('commonplaceDependencies' in package_json_parsed)) {
|
||||
console.warn('No Commonplace dependencies found in package.json.');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
var projects_target = path.resolve(process.cwd(), 'commonplace_projects');
|
||||
if (!fs.existsSync(projects_target)) {
|
||||
fs.mkdirSync(projects_target);
|
||||
}
|
||||
|
||||
function clone(git_url, name, callback) {
|
||||
console.log('Cloning `' + git_url + '`');
|
||||
var git_clone = spawn('git', ['clone', git_url, name], {cwd: projects_target});
|
||||
git_clone.stderr.pipe(process.stderr);
|
||||
git_clone.on('close', function(code) {
|
||||
if (code !== 0) {
|
||||
console.error('`git clone` of project "' + name + '" failed with non-zero exit code.');
|
||||
}
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
function pull(name, callback) {
|
||||
console.log('Updating', name);
|
||||
var git_pull = spawn('git', ['pull', '-r', 'origin', 'master'],
|
||||
{cwd: path.resolve(projects_target, name)});
|
||||
git_pull.stderr.pipe(process.stderr);
|
||||
git_pull.on('close', function(code) {
|
||||
if (code !== 0) {
|
||||
console.error('`git pull -r` on project "' + name + '" failed with non-zero exit code.');
|
||||
}
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
function run_make_init(name, callback) {
|
||||
// Runs make init, which pulls Bower dependencies and runs Gulp stuff.
|
||||
var make_init = spawn('make', ['init'],
|
||||
{cwd: path.resolve(projects_target, name)});
|
||||
make_init.stderr.pipe(process.stderr);
|
||||
make_init.on('close', function(code) {
|
||||
if (code !== 0) {
|
||||
console.error('`make init` on project "' + name + '" failed with non-zero exit code.');
|
||||
}
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
function run_make_build(name, callback) {
|
||||
// Runs make build which builds the project.
|
||||
var make_init = spawn('make', ['build'],
|
||||
{cwd: path.resolve(projects_target, name)});
|
||||
make_init.stderr.pipe(process.stderr);
|
||||
make_init.on('close', function(code) {
|
||||
if (code !== 0) {
|
||||
console.error('`make build` on project "' + name + '" failed with non-zero exit code.');
|
||||
}
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
function make_symlinks(name, data, callback) {
|
||||
if (!data.symlinks) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
for (var sym_path in data.symlinks) {
|
||||
if (!data.symlinks.hasOwnProperty(sym_path)) continue;
|
||||
var symlink = data.symlinks[sym_path];
|
||||
var sym_destination = path.resolve(process.cwd(), symlink);
|
||||
// Don't create link if it already exists.
|
||||
if (fs.existsSync(sym_destination)) continue;
|
||||
fs.symlinkSync(path.resolve(projects_target, name, sym_path), sym_destination);
|
||||
}
|
||||
callback();
|
||||
}
|
||||
|
||||
var deps = package_json_parsed.commonplaceDependencies;
|
||||
var deps_started = 0;
|
||||
var spawn = child_process.spawn;
|
||||
Object.keys(deps).forEach(function(dep) {
|
||||
deps_started++;
|
||||
var data = deps[dep];
|
||||
var proj_path = path.resolve(projects_target, data.name);
|
||||
fs.exists(proj_path, function(exists) {
|
||||
var proj_src = srcDir(proj_path);
|
||||
if (!exists) {
|
||||
clone(dep, data.name, callback_update);
|
||||
} else {
|
||||
pull(data.name, callback_update);
|
||||
}
|
||||
|
||||
function callback_update() {
|
||||
// Make the symlinks if any are requested.
|
||||
make_symlinks(data.name, data, callback_symlink);
|
||||
}
|
||||
|
||||
function callback_symlink() {
|
||||
// Remove existing compiled files from the project.
|
||||
clean(proj_src, callback_clean);
|
||||
}
|
||||
|
||||
function callback_clean() {
|
||||
// Copy `.dist` files to their destinations.
|
||||
run_make_init(data.name, callback_init);
|
||||
}
|
||||
|
||||
function callback_init() {
|
||||
// Compile the assets for the project.
|
||||
run_make_build(data.name, callback_includes);
|
||||
}
|
||||
|
||||
function callback_includes() {
|
||||
// Complete the update process.
|
||||
deps_started--;
|
||||
if (!deps_started) {
|
||||
finished();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function finished() {
|
||||
console.log('Finished fiddling.');
|
||||
var duration = new Date().getTime() - now;
|
||||
console.log('Completed in', Math.round(duration / 10) / 100, 'seconds.');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.generate_langpacks = generate_langpacks;
|
||||
module.exports.extract_l10n = extract_l10n;
|
||||
module.exports.fiddle = fiddle;
|
||||
|
||||
module.exports.config = require('./config');
|
||||
module.exports.template_optimizer = require('./template_optimizer');
|
||||
|
|
43
lib/utils.js
43
lib/utils.js
|
@ -1,25 +1,6 @@
|
|||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
var opts = module.exports.opts = function(opts, defaults) {
|
||||
if (!opts) {
|
||||
opts = process.argv;
|
||||
}
|
||||
|
||||
var out = defaults || {},
|
||||
last, i, is_flag;
|
||||
for(i = 0; i < opts.length; i++) {
|
||||
is_flag = opts[i].substr(0, 1) === '-';
|
||||
if (is_flag && last) {
|
||||
out[last] = true;
|
||||
} else if (!is_flag && last) {
|
||||
out[last] = opts[i];
|
||||
}
|
||||
last = is_flag ? opts[i].replace(/^\-+/, '') : null;
|
||||
}
|
||||
if (last) out[last] = true;
|
||||
return out;
|
||||
};
|
||||
|
||||
var globEach = module.exports.globEach = function(path_, ext, callback, doneCallback) {
|
||||
var wildcard = ext === '*';
|
||||
|
@ -63,27 +44,3 @@ module.exports.glob = function(path_, ext, done) {
|
|||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.globSync = function(path_, ext, done) {
|
||||
var results = [];
|
||||
var list = fs.readdirSync(path_);
|
||||
var pending = list.length;
|
||||
var wildcard = ext === '*';
|
||||
|
||||
if (!pending) return done(null, results);
|
||||
list.forEach(function(file) {
|
||||
file = path_ + '/' + file;
|
||||
var stat = fs.statSync(file);
|
||||
if (stat && stat.isDirectory()) {
|
||||
module.exports.globSync(file, ext, function(err, res) {
|
||||
results = results.concat(res);
|
||||
if (!--pending) done(null, results);
|
||||
});
|
||||
} else {
|
||||
// If it's got the right extension, add it to the list.
|
||||
if(wildcard || file.substr(file.length - ext.length) == ext)
|
||||
results.push(path.normalize(file));
|
||||
if (!--pending) done(null, results);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче