@enonic/cli-test
Advanced tools
Comparing version 0.0.24 to 0.0.25
{ | ||
"name": "@enonic/cli-test", | ||
"description": "Command-line interface for Enonic XP", | ||
"version": "0.0.24", | ||
"version": "0.0.25", | ||
"scripts": { | ||
"postinstall": "node postinstall.js install", | ||
"uninstall": "node postinstall.js uninstall" | ||
"postinstall": "node postinstall.js install" | ||
}, | ||
@@ -19,7 +18,7 @@ "repository": { | ||
"directories": { | ||
"bin": "dist" | ||
"bin": "dist/bin" | ||
}, | ||
"goBinary": { | ||
"name": "enonic", | ||
"path": "./bin" | ||
"path": "bin" | ||
}, | ||
@@ -26,0 +25,0 @@ "homepage": "https://developer.enonic.com/docs/enonic-cli/", |
#!/usr/bin/env node | ||
"use strict"; | ||
// Thanks to author of https://github.com/sanathkr/go-npm, we were able to modify his code to work with private packages | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
const _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var path = require('path'), | ||
const path = require('path'), | ||
mkdirp = require('mkdirp'), | ||
@@ -12,3 +11,3 @@ fs = require('fs'); | ||
// Mapping from Node's `process.arch` to Golang's `$GOARCH` | ||
var ARCH_MAPPING = { | ||
const ARCH_MAPPING = { | ||
"ia32": "386", | ||
@@ -20,3 +19,3 @@ "x64": "amd64", | ||
// Mapping between Node's `process.platform` to Golang's | ||
var PLATFORM_MAPPING = { | ||
const PLATFORM_MAPPING = { | ||
"darwin": "darwin", | ||
@@ -28,38 +27,2 @@ "linux": "linux", | ||
async function getInstallationPath() { | ||
// `npm bin` will output the path where binary files should be installed | ||
const value = await execShellCommand("npm config get prefix"); | ||
var dir = null; | ||
if (value) { | ||
dir = path.join(value.trim(), "bin"); | ||
} else { | ||
console.error('Enonic CLI could not be installed globally.'); | ||
} | ||
await mkdirp(dir); | ||
return dir; | ||
} | ||
async function verifyAndPlaceBinary(binName, binPath, callback) { | ||
if (!fs.existsSync(path.join(binPath, binName))) { | ||
return callback('Downloaded binary does not contain the binary specified in configuration - ' + binName); | ||
} | ||
// Get installation path for executables under node | ||
const installationPath = await getInstallationPath(); | ||
// Copy the executable to the path | ||
fs.rename(path.join(binPath, binName), path.join(installationPath, binName), (err) => { | ||
if(!err){ | ||
console.info("Enonic CLI is successfully installed."); | ||
callback(null); | ||
}else{ | ||
callback(err); | ||
} | ||
}); | ||
} | ||
function validateConfiguration(packageJson) { | ||
@@ -95,3 +58,3 @@ | ||
var packageJsonPath = path.join(".", "package.json"); | ||
const packageJsonPath = path.join(".", "package.json"); | ||
if (!fs.existsSync(packageJsonPath)) { | ||
@@ -102,4 +65,4 @@ console.error("Unable to find package.json. " + "Please run this script at root of the package you want to be installed"); | ||
var packageJson = JSON.parse(fs.readFileSync(packageJsonPath)); | ||
var error = validateConfiguration(packageJson); | ||
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath)); | ||
const error = validateConfiguration(packageJson); | ||
if (error && error.length > 0) { | ||
@@ -111,6 +74,9 @@ console.error("Invalid package.json: " + error); | ||
// We have validated the config. It exists in all its glory | ||
var binName = packageJson.goBinary.name; | ||
var binPath = packageJson.goBinary.path; | ||
var version = packageJson.version; | ||
if (version[0] === 'v') version = version.substring(1); // strip the 'v' if necessary v0.0.1 => 0.0.1 | ||
let binName = packageJson.goBinary.name; | ||
const binPath = packageJson.goBinary.path; | ||
let version = packageJson.version; | ||
if (version[0] === 'v') { | ||
// strip the 'v' if necessary v0.0.1 => 0.0.1 | ||
version = version.substring(1); | ||
} | ||
@@ -138,11 +104,9 @@ // Binary name on Windows has .exe suffix | ||
*/ | ||
var INVALID_INPUT = "Invalid inputs"; | ||
async function install(callback) { | ||
var opts = parsePackageJson(); | ||
if (!opts) return callback(INVALID_INPUT); | ||
mkdirp.sync(opts.binPath); | ||
console.info(`Copying the relevant binary for your platform ${process.platform}`); | ||
function install(callback) { | ||
const opts = parsePackageJson(); | ||
if (!opts) return callback("Invalid inputs"); | ||
var source = path.join('dist', `enonic_${PLATFORM_MAPPING[process.platform]}_${ARCH_MAPPING[process.arch]}`, opts.binName); | ||
const source = path.join('dist', `enonic_${PLATFORM_MAPPING[process.platform]}_${ARCH_MAPPING[process.arch]}`, opts.binName); | ||
console.info(source); | ||
@@ -154,55 +118,21 @@ if (!fs.existsSync(source)) { | ||
var target = path.join('dist', opts.binName); | ||
const targetPath = path.join('dist', opts.binPath); | ||
mkdirp.sync(targetPath); | ||
//const target = path.join('dist', opts.binName); | ||
const target = path.join(targetPath, opts.binName); | ||
console.info(target); | ||
console.info(`Copying the relevant binary for your platform ${process.platform}`); | ||
fs.copyFileSync(source, target, fs.constants.COPYFILE_FICLONE); | ||
//await verifyAndPlaceBinary(opts.binName, opts.binPath, callback); | ||
} | ||
async function uninstall(callback) { | ||
var opts = parsePackageJson(); | ||
try { | ||
const installationPath = await getInstallationPath(); | ||
fs.unlink(path.join(installationPath, opts.binName),(err)=>{ | ||
if(err){ | ||
return callback(err); | ||
} | ||
}); | ||
} catch (ex) { | ||
// Ignore errors when deleting the file. | ||
} | ||
console.info("Enonic CLI is successfully uninstalled."); | ||
return callback(null); | ||
} | ||
// Parse command line arguments and call the right method | ||
var actions = { | ||
"install": install, | ||
"uninstall": uninstall | ||
}; | ||
/** | ||
* Executes a shell command and return it as a Promise. | ||
* @param cmd {string} | ||
* @return {Promise<string>} | ||
*/ | ||
function execShellCommand(cmd) { | ||
const exec = require('child_process').exec; | ||
return new Promise((resolve, reject) => { | ||
exec(cmd, (error, stdout, stderr) => { | ||
if (error) { | ||
console.warn(error); | ||
} | ||
resolve(stdout? stdout : stderr); | ||
}); | ||
}); | ||
} | ||
var argv = process.argv; | ||
const argv = process.argv; | ||
if (argv && argv.length > 2) { | ||
var cmd = process.argv[2]; | ||
if (!actions[cmd]) { | ||
console.log("Invalid command. `install` and `uninstall` are the only supported commands"); | ||
const cmd = process.argv[2]; | ||
if (cmd !== "install") { | ||
console.log("Invalid command. `install` is the only supported command."); | ||
process.exit(1); | ||
} | ||
actions[cmd](function (err) { | ||
install(function (err) { | ||
if (err) { | ||
@@ -209,0 +139,0 @@ console.error(err); |
<p align="center"> | ||
<a href="https://enonic.com"> | ||
<img src="https://enonic.com/_/asset/com.enonic.web.enonic.com/img/enonic-logo.svg" width="50%" /> | ||
<img src="https://enonic.com/_/asset/com.enonic.web.enonic.com/img/enonic-logo.svg" width="290px" style="margin-top: 10px;" /> | ||
</a> | ||
@@ -5,0 +5,0 @@ </p> |
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
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
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
0
107190936
14
112