diff --git a/.gitignore b/.gitignore index 38087f2..ee8247a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,15 @@ sls-sample-app-2.0.3.tgz loopback-example-app*.tgz _suite _onto +intl/MSG.json +intl/de +intl/es +intl/fr +intl/it +intl/ja +intl/ko +intl/pt +intl/ru +intl/zh-Hans +intl/zh-Hant +intl/en/*.json diff --git a/index.js b/index.js index 589e633..445e4e4 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ var Parser = require('posix-getopt').BasicParser; var debug = require('debug')('strong-build'); var fmt = require('util').format; var fs = require('fs'); +var g = require('strong-globalize'); var git = require('./lib/git'); var path = require('path'); var pump = require('pump'); @@ -11,7 +12,7 @@ var vasync = require('vasync'); var zlib = require('zlib'); function printHelp($0, prn) { - var USAGE = fs.readFileSync(require.resolve('./sl-build.txt'), 'utf-8') + var USAGE = g.t('sl-build.txt') .replace(/%MAIN%/g, $0) .trim(); @@ -30,10 +31,10 @@ function runCommand(cmd, callback) { } function runWait(cmd, callback) { - console.log('Running `%s`', cmd); + g.log('Running `%s`', cmd); runCommand(cmd, function(er, output) { if (er) { - console.error('Error on `%s`:', cmd); + g.error('Error on `%s`:', cmd); reportRunError(er, output); return callback(er); } @@ -52,7 +53,7 @@ function runStep(cmd) { function reportRunError(er, output) { if (!er) return; - console.error('Failed to run `%s`:', er.message); + g.error('Failed to run `%s`:', er.message); if (output && output !== '') { process.stderr.write(output); } @@ -83,6 +84,8 @@ exports.build = function build(argv, callback) { var pack; var commit; + g.setRootDir(__dirname); + while ((option = parser.getopt()) !== undefined) { switch (option.option) { case 'v': @@ -108,7 +111,7 @@ exports.build = function build(argv, callback) { install = true; break; case 'b': - console.error('Warning: the --bundle option now does nothing and ' + + g.error('Warning: the --bundle option now does nothing and ' + 'should not be used'); break; case 'p': @@ -124,15 +127,15 @@ exports.build = function build(argv, callback) { commit = false; break; default: - console.error('Invalid usage (near option \'%s\'), try `%s --help`.', + g.error('Invalid usage (near option \'%s\'), try `{{%s --help}}`.', option.optopt, $0); - return callback(Error('usage')); + return callback(g.Error('usage')); } } if (parser.optind() !== argv.length) { - console.error('Invalid usage (extra arguments), try `%s --help`.', $0); - return callback(Error('usage')); + g.error('Invalid usage (extra arguments), try `{{%s --help}}`.', $0); + return callback(g.Error('usage')); } // With no actions selected, do everything we can (onto requires an argument, @@ -149,8 +152,8 @@ exports.build = function build(argv, callback) { } if (commit && !git.isGit()) { - console.error('Cannot perform commit on non-git working directory'); - return callback(Error('usage')); + g.error('Cannot perform commit on {{non-git}} working directory'); + return callback(g.Error('usage')); } var steps = []; @@ -178,7 +181,7 @@ exports.build = function build(argv, callback) { try { git.ensureBranch(onto); } catch (er) { - console.error('%s', er.message); + g.error('%s', er.message); return callback(er); } return callback(); @@ -188,13 +191,13 @@ exports.build = function build(argv, callback) { try { var info = git.syncBranch(onto); if (info.srcBranch && info.dstBranch) { - console.log('Merged source tree of `%s` onto `%s`', + g.log('Merged source tree of `%s` onto `%s`', info.srcBranch, info.dstBranch); } else { - console.log('Not merging HEAD into `%s`, already up to date.', onto); + g.log('Not merging {{HEAD}} into `%s`, already up to date.', onto); } } catch (er) { - console.error('%s', er.message); + g.error('%s', er.message); return callback(er); } return callback(); @@ -223,7 +226,7 @@ exports.build = function build(argv, callback) { var tarStream = strongPack(process.cwd()); var dstFile = fs.createWriteStream(dst, 'binary'); var gz = zlib.createGzip(); - console.log('Packing application in to %s', dst); + g.log('Packing application in to %s', dst); pump(tarStream, gz, dstFile, callback); } @@ -231,9 +234,9 @@ exports.build = function build(argv, callback) { try { var info = git.commitAll(onto); if (info.branch) { - console.log('Committed build products onto `%s`', info.branch); + g.log('Committed build products onto `%s`', info.branch); } else { - console.log('Build products already up to date on `%s`', onto); + g.log('Build products already up to date on `%s`', onto); } } catch (er) { console.error('%s', er.message); diff --git a/intl/en/sl-build.txt b/intl/en/sl-build.txt new file mode 100644 index 0000000..828c26d --- /dev/null +++ b/intl/en/sl-build.txt @@ -0,0 +1,22 @@ +usage: {{%MAIN%}} [options] + +Build a node application package. + +With no options, the default depends on whether a git repository is detected or not. + +If a {{git}} repository is detected the default is `{{--git}}`: install and commit the build results to the "{{deploy}}" branch, which will be created if it does not already exist. + +If no {{git}} repository is detected the default is `{{--npm}}`: install and pack the build results into a `{{-.tgz}}` file. + +Options: + {{-h,--help}} Print this message and exit. + {{-v,--version}} Print version and exit. + {{-n,--npm}} Same as `{{--install --pack}}`. + {{-g,--git}} Same as `{{--install --commit}}`. + {{-i,--install}} Install dependencies (without scripts, by default). + {{-s,--scripts}} If installing, run scripts (to build addons). + {{-p,--pack}} Pack into a publishable archive. + +Git specific options: + {{-c,--commit}} Commit build output (branch specified by {{--onto}}). + {{--onto BRANCH}} Branch to commit build results to, created if necessary ("{{deploy}}", by default). diff --git a/lib/git.js b/lib/git.js index ea25662..564b7da 100644 --- a/lib/git.js +++ b/lib/git.js @@ -2,6 +2,7 @@ var debug = require('debug')('strong-build'); var lodash = require('lodash'); var path = require('path'); var shell = require('shelljs'); +var g = require('strong-globalize'); var util = require('util'); function fmt() { @@ -22,11 +23,11 @@ function execSync(cmd, error, noOutput) { if (exec.code !== 0) { var output = exec.output.replace('fatal: ', ''); - console.log('Error on `%s`:\n %s', cmd, output); + g.log('Error on `%s`:\n %s', cmd, output); throw Error(error); } - console.log('Running `%s`', cmd); + g.log('Running `%s`', cmd); // git on success may still write messages to stderr, and shelljs combines // stdout and stderr (sucky). This effect commit-tree, for example, when dest @@ -81,7 +82,7 @@ exports.ensureBranch = function ensureBranch(name) { if (!info.ref) execSync( fmt('git branch "%s"', name), - fmt('Failed to create branch "%s"', name) + g.t('Failed to create branch "%s"', name) ); }; @@ -102,7 +103,7 @@ exports.syncBranch = function gitSyncBranch(gitDstBranch) { var gitSrcTreeSha = execSync( 'git log -1 --pretty=format:"%t" HEAD', - 'Failed to parse branch `HEAD`, is this a git repository?' + g.t('Failed to parse branch `{{HEAD}}`, is this a git repository?') ); // Commit the source tree to the head of the destination branch, and update @@ -111,12 +112,12 @@ exports.syncBranch = function gitSyncBranch(gitDstBranch) { var commitSha = execSync( fmt('git commit-tree -p "%s" -p "%s" -m "%s" %s', dst.ref, src.ref, message, gitSrcTreeSha), - fmt('Failed to commit `%s` onto `%s`', src.ref, gitDstBranch) + g.t('Failed to commit `%s` onto `%s`', src.ref, gitDstBranch) ); execSync( fmt('git update-ref "%s" %s', dst.ref, commitSha), - fmt('Failed to merge `%s` onto `%s`', src.ref, gitDstBranch) + g.t('Failed to merge `%s` onto `%s`', src.ref, gitDstBranch) ); return { @@ -130,17 +131,17 @@ exports.syncBranch = function gitSyncBranch(gitDstBranch) { exports.commitAll = function gitCommitAll(gitDstBranch) { execSync( fmt('git add --force --all .'), - fmt('Failed to add build products') + g.t('Failed to add build products') ); var treeSha = execSync( fmt('git write-tree'), - fmt('Failed to stage build products for commit') + g.t('Failed to stage build products for commit') ); var dst = resolveBranch(gitDstBranch); var commitSha = execSync( fmt('git commit-tree -p "%s" -m "Commit build products" %s', dst.ref, treeSha), - fmt('Failed to create build products commit for `%s`', gitDstBranch), + g.t('Failed to create build products commit for `%s`', gitDstBranch), true ); @@ -151,7 +152,7 @@ exports.commitAll = function gitCommitAll(gitDstBranch) { execSync( fmt('git update-ref "%s" %s', dst.ref, commitSha), - fmt('Failed to commit build products to `%s`', gitDstBranch) + g.t('Failed to commit build products to `%s`', gitDstBranch) ); return { diff --git a/package.json b/package.json index 87b3734..3ea2ba0 100644 --- a/package.json +++ b/package.json @@ -29,11 +29,13 @@ "sl-build": "./bin/sl-build.js" }, "dependencies": { + "cldr-data": "^28.0.3", "debug": "^2.0.0", "lodash": "^3.8.0", "posix-getopt": "^1.0.0", "pump": "^1.0.1", "shelljs": "^0.4.0", + "strong-globalize": "^1.0.0", "strong-pack": "^1.0.0", "vasync": "^1.4.3" }, diff --git a/sl-build.txt b/sl-build.txt deleted file mode 100644 index fddc1f3..0000000 --- a/sl-build.txt +++ /dev/null @@ -1,27 +0,0 @@ -usage: %MAIN% [options] - -Build a node application package. - -With no options, the default depends on whether a git repository is -detected or not. - -If a git repository is detected the default is `--git`: install and commit the -build results to the "deploy" branch, which will be created if it does not -already exist. - -If no git repository is detected the default is `--npm`: install and -pack the build results into a `-.tgz` file. - -Options: - -h,--help Print this message and exit. - -v,--version Print version and exit. - -n,--npm Same as `--install --pack`. - -g,--git Same as `--install --commit`. - -i,--install Install dependencies (without scripts, by default). - -s,--scripts If installing, run scripts (to build addons). - -p,--pack Pack into a publishable archive. - -Git specific options: - -c,--commit Commit build output (branch specified by --onto). - --onto BRANCH Branch to commit build results to, created if - necessary ("deploy", by default). diff --git a/test/build-example.js b/test/build-example.js index fc0bc00..b401709 100644 --- a/test/build-example.js +++ b/test/build-example.js @@ -38,6 +38,7 @@ module.exports = function buildExample(fixture, args, callback) { } }); + sh.cd(__dirname); sh.rm('-rf', '_suite'); sh.cp('-Rf', fmt('fixtures/%s/*', fixture), '_suite'); sh.cd('_suite'); diff --git a/test/test-build-install-nodeps.js b/test/test-build-install-nodeps.js index d226958..0a84713 100644 --- a/test/test-build-install-nodeps.js +++ b/test/test-build-install-nodeps.js @@ -5,5 +5,9 @@ var test = require('shelljs').test; require('./build-example')('zero-dependency', ['-i'], function(er) { debug('built with error?', er); assert.ifError(er); - assert(!test('-d', 'node_modules'), 'no node_modules created'); + if (process.versions.node.split('.')[0] === '5') { + assert(test('-d', 'node_modules'), 'node_modules created'); + } else { + assert(!test('-d', 'node_modules'), 'no node_modules created'); + } });