@o3r/schematics
Version:
Schematics module of the Otter framework
37 lines • 1.63 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.NodeRunScriptTask = void 0;
const options_1 = require("@angular-devkit/schematics/tasks/package-manager/options");
const package_manager_runner_1 = require("../../utility/package-manager-runner");
/**
* Configuration used to run Node script via Package Manager.
* Warning: The command only supports single quote strings when run with NPM. In NPM, the " character will be replaced by its char code
* Note that this only works if the necessary files are created on the disk (doesn't work on tree)
*/
class NodeRunScriptTask {
constructor(script, workingDirectory, packageManager) {
this.script = script;
this.workingDirectory = workingDirectory;
this.packageManager = packageManager;
}
toConfiguration() {
const packageManager = this.packageManager || (0, package_manager_runner_1.getPackageManager)();
const scriptString = JSON.stringify(this.script);
const scriptStringInQuotes = this.script
.replace(/"/g, '\' + String.fromCharCode(34) + \'');
const script = packageManager === 'npm'
? `exec --call "node -e \\"${scriptStringInQuotes}\\""`
: `node -e ${scriptString}`;
return {
name: options_1.NodePackageName,
options: {
command: 'exec',
packageName: script,
workingDirectory: this.workingDirectory,
packageManager
}
};
}
}
exports.NodeRunScriptTask = NodeRunScriptTask;
//# sourceMappingURL=npm-node-run.js.map
;