Skip to content

Commit

Permalink
[FIX] Prefer local over global CLI version
Browse files Browse the repository at this point in the history
When running the global "ui5" command while a local @ui5/cli version is
installed for the current project, the local one should be preferred.

Fixes: #58
  • Loading branch information
matz3 committed Oct 1, 2018
1 parent 5757bd9 commit d3c213d
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 19 deletions.
43 changes: 29 additions & 14 deletions bin/ui5.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,36 @@ if (pkg.engines && pkg.engines.node && !semver.satisfies(nodeVersion, pkg.engine
process.exit(1);
}

const updateNotifier = require("update-notifier");
const cli = require("yargs");
(function() {
// Wrapping in IIFE to use return

updateNotifier({
pkg,
updateCheckInterval: 1000 * 60 * 60 * 24, // 1 day
shouldNotifyInNpmScript: true
}).notify();
const importLocal = require("import-local");
// Prefer a local installation of @ui5/cli.
// This will invoke the local CLI, so no further action required
if (importLocal(__filename)) {
return;
}

// CLI modules
cli.commandDir("../lib/cli/commands");
const updateNotifier = require("update-notifier");
const cli = require("yargs");

// Format terminal output to full available width
cli.wrap(cli.terminalWidth());
updateNotifier({
pkg,
updateCheckInterval: 1000 * 60 * 60 * 24, // 1 day
shouldNotifyInNpmScript: true
}).notify();

// yargs registers a get method on the argv property.
// The property needs to be accessed to initialize everything.
cli.argv;
// Explicitly set CLI version as the yargs default might
// be wrong in case a local CLI installation is used
cli.version(pkg.version);

// CLI modules
cli.commandDir("../lib/cli/commands");

// Format terminal output to full available width
cli.wrap(cli.terminalWidth());

// yargs registers a get method on the argv property.
// The property needs to be accessed to initialize everything.
cli.argv;
})();
67 changes: 62 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"@ui5/logger": "^0.2.0",
"@ui5/project": "^0.2.0",
"@ui5/server": "^0.2.1",
"import-local": "^2.0.0",
"js-yaml": "^3.10.0",
"opn": "^5.1.0",
"semver": "^5.5.0",
Expand Down

0 comments on commit d3c213d

Please sign in to comment.