smartclient-eval
Advanced tools
Comparing version 0.9.5 to 0.9.6
68
Lib.js
@@ -32,7 +32,9 @@ #!/usr/bin/env node | ||
const readline = require("readline"); | ||
const fs = require("fs-extra"); | ||
const path = require("path"); | ||
const util = require("util"); | ||
const fs = require("fs-extra"); | ||
const readline = require("readline"); | ||
const { spawnSync } = require("child_process"); | ||
class CommonLib { | ||
@@ -96,16 +98,62 @@ | ||
/** | ||
* (Internal) Returns available version of npm. Allows npm-version-dependent handling. | ||
* | ||
* @return (number) | ||
*/ | ||
static getNpmVersion() { | ||
let isWindows = process.platform == "win32", | ||
result | ||
; | ||
try { | ||
result = spawnSync(isWindows ? "npm.cmd" : "npm", ["--version"]); | ||
if (result.status == 0) { | ||
return parseFloat(result.stdout.toString().trim()); | ||
} else { | ||
console.warn("Unable to find npm version [status " + result.status + "]: " + | ||
result.stderr); | ||
} | ||
} catch (e) { | ||
console.warn("Unable to find npm version: " + e); | ||
} | ||
} | ||
/** | ||
* (Internal) Returns whether interactive prompting is allowed. It is not allowed in newer | ||
* versions of npm when commands are run via lifecycle hooks - install, uninstall, update. | ||
* | ||
* @return (number) | ||
*/ | ||
static supportsInteraction() { | ||
return this.getNpmVersion() < 7 || process.argv[2] == "true"; | ||
} | ||
/** | ||
* (Internal) Prompt user and return answer. Allow automatic "yes". | ||
* | ||
* @param (string) prompt - prompt to user | ||
* @param {boolean) yes - assume "yes" without interaction | ||
* @param (string) question - question text to show the user | ||
* @param {boolean) interactive - should this method wait for the user to type a response | ||
* @param {string) forcedAnswer - default if caller wants interactive but it isn't possible | ||
* @return (string) typed or automatic response | ||
*/ | ||
static async prompt(prompt, yes) { | ||
if (yes) { | ||
let auto = "yes"; | ||
console.log(prompt + "yes"); | ||
return true; | ||
static async prompt(question, interactive, forcedAnswer) { | ||
let auto = "yes"; | ||
// if interaction is possible, default to interactive mode | ||
if (this.supportsInteraction()) { | ||
if (interactive == null) interactive = true; | ||
// otherwise, default to no interaction, but use "safe" answers | ||
// if this explicitly overrides what has been passed via param | ||
} else { | ||
if (interactive == true) { | ||
auto = forcedAnswer; | ||
} | ||
interactive = false; | ||
} | ||
if (!interactive) { | ||
console.log(question + auto); | ||
return auto == "yes"; | ||
} | ||
// interactive console session; parse what the user typed | ||
let answer = await CommonLib.question(prompt); | ||
let answer = await CommonLib.question(question); | ||
return answer != null && (answer.trim() === "" || answer.match(/^y(es)?$/i)); | ||
@@ -112,0 +160,0 @@ } |
@@ -31,8 +31,9 @@ { | ||
"scripts": { | ||
"install": "node update.js", | ||
"uninstall": "node uninstall.js", | ||
"help": "npm run update --showUsage", | ||
"update": "node update.js" | ||
"reconfig": "node update.js true", | ||
"update": "node update.js false", | ||
"install": "node update.js false", | ||
"uninstall": "node uninstall.js false" | ||
}, | ||
"version": "0.9.5" | ||
"version": "0.9.6" | ||
} |
@@ -24,3 +24,3 @@ Provides access to | ||
npm run update [flags] | ||
npm run reconfig [flags] | ||
@@ -50,3 +50,4 @@ where the supported flags are: | ||
response to all queries during install; default | ||
is to not prompt to support newer npm releases | ||
is to not prompt during install or update in | ||
npm versions 7 and above as it's not supported | ||
@@ -59,3 +60,3 @@ | ||
Note that since 'npm update' no longer runs a module's update script if the | ||
version hasn't changed, you must use the syntax above, run from the module | ||
version hasn't changed, you must use the command above, run from the module | ||
directory, to update the runtime(s) if the module has already been installed. | ||
@@ -72,7 +73,7 @@ (The smartclient-eval module is versioned separately from nightly SDK builds.) | ||
npm run update --date=latest | ||
npm run reconfig --date=latest | ||
Update to SmartClient 13.0 branch, installing all skins: | ||
npm run update --branch=13.0 --skins=all | ||
npm run reconfig --branch=13.0 --skins=all | ||
@@ -89,12 +90,7 @@ ### npm v7 | ||
You have a few alternatives to this default behavior: | ||
* You can pass "--prompt" to "npm install ...". Due to npm v7 rules, installing the module | ||
this way will skip the download and installation of the SmartClient framework and skins, | ||
and the isc-config.json configuration file won't be created. So afterwards, to install | ||
the missing assets you should navigate down to the module directory (in node_modules) and | ||
manually execute "npm run update [flags]", passing your install flags. | ||
* In addition to "--prompt", you can also pass "--foreground-scripts" as a flag to the install | ||
command to allow output as in npm v6, but in npm v7 this seems to trigger other timing logs | ||
that obfuscate what we print. Hopefully, support for the "--foreground-scripts" flag will | ||
improve in future npm releases. | ||
If you want to avoid unexpected hidden downloads or existing directories getting replaced, you | ||
can explicitly specify "--prompt", and in npm v7+, though it cannot actually prompt you, that | ||
will cause the minimal impact response to be assumed, rather than an automatic answer of "yes" | ||
to every question. So, for example, downloads will be skipped as well as removing files. You | ||
can then change to the module directory and do an "npm run reconfig ..." for full interaction. | ||
@@ -101,0 +97,0 @@ "Uninstall" is no longer a lifecycle event in npm v7, so a module's uninstall script declared |
@@ -40,3 +40,2 @@ #!/usr/bin/env node | ||
const readline = require("readline"); | ||
const { spawnSync } = require("child_process"); | ||
@@ -158,3 +157,4 @@ const Const = require("./Const"); | ||
let isomorphicPath = this._getIscDir(location), | ||
let forcedAnswer = "yes", | ||
isomorphicPath = this._getIscDir(location), | ||
question = "Install SmartClient " + branch + " runtime, build date " + date + | ||
@@ -166,5 +166,6 @@ ", at " + isomorphicPath | ||
question += " (removing the directory currently present at install path)" | ||
} else if (config.location && config.location == location) { | ||
} else { | ||
question += " (replacing the existing SmartClient installation there)"; | ||
} | ||
forcedAnswer = "no"; | ||
} | ||
@@ -175,3 +176,3 @@ | ||
let answer = await CommonLib.prompt(question + "? [yes]: ", !prompt); | ||
let answer = await CommonLib.prompt(question + "? [yes]: ", prompt, forcedAnswer); | ||
if (answer) { | ||
@@ -240,3 +241,4 @@ Update._getSmartClientLink(branch, date, query, Const.DOWNLOAD_DIR, | ||
"It looks like we're about to re-download the same core runtime(s) " + | ||
"already installed with no configuration change. Skip? [yes]: ", !prompt); | ||
"already installed with no configuration change. Skip? [yes]: ", prompt, | ||
"yes"); | ||
if (skip) { | ||
@@ -941,3 +943,3 @@ | ||
" for SmartClient. Add"; | ||
let answer = await CommonLib.prompt(question + "? [yes]: ", !prompt); | ||
let answer = await CommonLib.prompt(question + "? [yes]: ", prompt, "no"); | ||
if (answer) | ||
@@ -1060,24 +1062,2 @@ { | ||
/** | ||
* (Internal) Returns available version of npm. Allows npm-version-dependent handling. | ||
* | ||
* @return (number) | ||
*/ | ||
static getNpmVersion() { | ||
let isWindows = process.platform == "win32", | ||
result | ||
; | ||
try { | ||
result = spawnSync(isWindows ? "npm.cmd" : "npm", ["--version"]); | ||
if (result.status == 0) { | ||
return parseFloat(result.stdout.toString().trim()); | ||
} else { | ||
console.warn("Unable to find npm version [status " + result.status + "]: " + | ||
result.stderr); | ||
} | ||
} catch (e) { | ||
console.warn("Unable to find npm version: " + e); | ||
} | ||
} | ||
/** | ||
* (Internal) Returns whether to consider "prompt" option true | ||
@@ -1084,0 +1064,0 @@ * |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
75983
1515
162