You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ja...@apache.org on 2019/05/21 15:38:43 UTC
[cordova-coho] branch master updated: Improvements to src/main.js
(#221)
This is an automated email from the ASF dual-hosted git repository.
janpio pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-coho.git
The following commit(s) were added to refs/heads/master by this push:
new e838cc0 Improvements to src/main.js (#221)
e838cc0 is described below
commit e838cc0f821593a3042f22bec681e5809ee7d33b
Author: Chris Brody <ch...@gmail.com>
AuthorDate: Tue May 21 11:38:39 2019 -0400
Improvements to src/main.js (#221)
* src/main.js check npm dependencies before require statements
* declare all imports at top-level file scope
* avoid an ugly error message in case `coho` is
run with npm dependencies not installed
* src/main.js var -> const / let
* check-npm-install-util.js & lazy-require-util.js out of main.js
* show correct path to run "npm install", if needed
* [SQUASH-FIX] require('./lazy-require-util') with no ".js" at the end
for the sake of consistency
---
src/check-npm-install-util.js | 31 ++++++++++++++++++++++++
src/lazy-require-util.js | 28 ++++++++++++++++++++++
src/main.js | 56 ++++++++++++++++++++-----------------------
3 files changed, 85 insertions(+), 30 deletions(-)
diff --git a/src/check-npm-install-util.js b/src/check-npm-install-util.js
new file mode 100644
index 0000000..a0f5257
--- /dev/null
+++ b/src/check-npm-install-util.js
@@ -0,0 +1,31 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+
+try {
+ // Ensure npm install has been run.
+ Object.keys(require('../package').dependencies).forEach(require);
+} catch (e) {
+ const path = require('path'); // Built-in Node.js module
+ console.log(
+ 'Please run "npm install" from this directory:\n\t' +
+ path.join(__dirname, '..')); // correct path
+ process.exit(2);
+}
+
+module.exports = {};
diff --git a/src/lazy-require-util.js b/src/lazy-require-util.js
new file mode 100644
index 0000000..f327b62
--- /dev/null
+++ b/src/lazy-require-util.js
@@ -0,0 +1,28 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+
+function * lazyRequire (name, opt_prop) {
+ if (opt_prop) {
+ yield require(name)[opt_prop];
+ } else {
+ yield require(name);
+ }
+}
+
+module.exports = lazyRequire;
diff --git a/src/main.js b/src/main.js
index 070fbbd..de3c14f 100644
--- a/src/main.js
+++ b/src/main.js
@@ -17,29 +17,19 @@ specific language governing permissions and limitations
under the License.
*/
-var executil = require('./executil');
+// Verify that npm install was run before importing anything else
+require('./check-npm-install-util');
-try {
- var co = require('co');
- var optimist = require('optimist');
- // Ensure npm install has been run.
- Object.keys(require('../package').dependencies).forEach(require);
-} catch (e) {
- console.log('Please run "npm install" from this directory:\n\t' + __dirname); // eslint-disable-line no-path-concat
- process.exit(2);
-}
-var apputil = require('./apputil');
+const co = require('co');
+const optimist = require('optimist');
-function * lazyRequire (name, opt_prop) {
- if (opt_prop) {
- yield require(name)[opt_prop];
- } else {
- yield require(name);
- }
-}
+const executil = require('./executil');
+const apputil = require('./apputil');
+
+const lazyRequire = require('./lazy-require-util');
module.exports = function () {
- var repoCommands = [
+ const repoCommands = [
{
name: 'repo-clone',
desc: 'Clones git repositories as siblings of cordova-coho (unless --no-chdir or --global is used).',
@@ -69,7 +59,8 @@ module.exports = function () {
desc: 'Update specified git remote to point to corresponding apache github repo',
entryPoint: lazyRequire('./remote-update')
}];
- var releaseCommands = [{
+
+ const releaseCommands = [{
name: 'prepare-platform-release-branch',
desc: 'Branches, updates JS, updates VERSION. Safe to run multiple times.',
entryPoint: lazyRequire('./platform-release', 'prepareReleaseBranchCommand')
@@ -130,7 +121,8 @@ module.exports = function () {
desc: 'Unpublishes last nightly versions for all specified repositories',
entryPoint: lazyRequire('./npm-publish', 'unpublishNightly')
}];
- var otherCommands = [{
+
+ const otherCommands = [{
name: 'list-pulls',
desc: 'Shows a list of GitHub pull requests for all specified repositories.',
entryPoint: lazyRequire('./list-pulls')
@@ -171,9 +163,9 @@ module.exports = function () {
console.log(require('../package').version);
yield Promise.resolve();
}
- }
- ];
- var commandMap = {};
+ }];
+
+ const commandMap = {};
function addToCommandMap (cmd) {
commandMap[cmd.name] = cmd;
}
@@ -183,7 +175,7 @@ module.exports = function () {
// aliases:
commandMap['foreach'] = commandMap['for-each'];
- var usage = 'Usage: $0 command [options]\n\n';
+ let usage = 'Usage: $0 command [options]\n\n';
function addCommandUsage (cmd) {
usage += ' ' + cmd.name + ': ' + cmd.desc + '\n';
}
@@ -203,8 +195,9 @@ module.exports = function () {
usage += ' ./cordova-coho/coho for-each -r plugins "git clean -fd"\n';
usage += ' ./cordova-coho/coho last-week --me';
- var command = commandMap[optimist.argv._[0]];
- var opts = optimist
+ const command = commandMap[optimist.argv._[0]];
+
+ let opts = optimist
.usage(usage)
.options('verbose', {
desc: 'Enable verbose logging',
@@ -232,8 +225,9 @@ module.exports = function () {
default: true
});
}
- var argv = opts.check(function (argv) {
- var commandName = argv._[0];
+
+ const argv = opts.check(function (argv) {
+ const commandName = argv._[0];
if (!commandName) {
throw 'No command specified.';
}
@@ -244,6 +238,7 @@ module.exports = function () {
throw 'No repositories specified, see list-repos';
}
}).argv;
+
if (!command.noChdir) {
// Change directory to be a sibling of coho.
apputil.initWorkingDir(argv.chdir);
@@ -254,6 +249,7 @@ module.exports = function () {
if (argv.verbose) {
executil.verbose = true;
}
- var entry = command.entryPoint;
+
+ const entry = command.entryPoint;
co(entry).then();
};
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org