v3-installer
Advanced tools
Comparing version 1.0.24 to 1.0.25
@@ -19,5 +19,6 @@ /** | ||
/* 要添加的脚本内容 */ | ||
/* 要添加的脚本内容,如果存在相同的命令则不做改变,否则更新命令 */ | ||
scripts["v3:install"] = scripts["v3:install"] || "v3installer -i" | ||
scripts["v3:uninstall"] = scripts["v3:uninstall"] || "v3installer -u"; | ||
scripts["npm:install"] = scripts["npm:install"] || "v3installer -n"; | ||
@@ -24,0 +25,0 @@ ioUtils.write(packageJsonPath, JSON.stringify(packageJson, null, "\t")).catch(err => { |
@@ -12,2 +12,3 @@ #!/usr/bin/env node | ||
.option('-u, --uninstall', '卸载当前已安装的依赖构件') | ||
.option('-n, --npminstall', '安装原生npm插件') | ||
.parse(process.argv); | ||
@@ -19,4 +20,6 @@ /* 根据命令行参数确定执行安装还是卸载操作 */ | ||
v3installer._simpleUnistall(program.args); | ||
} else if (program.npminstall) { | ||
v3installer._npmInstall(program.args); | ||
} else { | ||
program.help(); | ||
} |
63
index.js
@@ -15,2 +15,3 @@ /** | ||
const V3PlatformResult = require('./src/model/V3PlatformResult'); | ||
const pathUtils = require('./src/utils/PathUtils'); | ||
module.exports = { | ||
@@ -30,4 +31,5 @@ _handleError: function (err, simpleMode) { | ||
break; | ||
default: | ||
errMsg = err.message; | ||
} | ||
} else { | ||
@@ -41,5 +43,5 @@ errMsg = err.stack; | ||
}, | ||
_handleSuccess: function (simpleMode) { | ||
_handleSuccess: function (simpleMode, message) { | ||
if (simpleMode) { | ||
new V3PlatformResult(true, "PluginInstallSuccess", "安装本地V3平台插件完成!").consoleStr(); | ||
new V3PlatformResult(true, "PluginInstallSuccess", message || "安装本地V3平台插件完成!").consoleStr(); | ||
} else { | ||
@@ -116,3 +118,3 @@ console.log('安装本地V3平台插件完成!'); | ||
} else { | ||
let libCode = 'dev'; | ||
let libCode; | ||
let downAndInstall = () => { | ||
@@ -181,3 +183,3 @@ /*@TODO 根据参数从vstore中搜索构件并显示列表 */ | ||
} catch (err) { | ||
this._handleError('传入的vstore账号参数格式错误!',true); | ||
this._handleError('传入的vstore账号参数格式错误!', true); | ||
return; | ||
@@ -188,3 +190,3 @@ } | ||
console.log('开始安装本地V3平台插件,请稍候...'); | ||
let installer = new VPlatformPluginInstaller(pluginPath, null, true, argCfg); | ||
let installer = new VPlatformPluginInstaller(pluginPath, true, argCfg); | ||
let promise = installer.install(); | ||
@@ -196,6 +198,6 @@ promise.then(() => { | ||
console.log('安装V3平台插件出现错误!'); | ||
this._handleError(err,true); | ||
this._handleError(err, true); | ||
}); | ||
} else { | ||
this._handleError(`插件路径${argPath}不存在,安装失败!`,true); | ||
this._handleError(`插件路径${argPath}不存在,安装失败!`, true); | ||
} | ||
@@ -206,5 +208,48 @@ }, | ||
*/ | ||
_simpleUnistall:function(args){ | ||
_simpleUnistall: function (args) { | ||
PluginUninstall._simpleUnistall(args[0] || null); | ||
}, | ||
/** | ||
* 提供npm原生插件批量安装功能 | ||
*/ | ||
_npmInstall: function (args) { | ||
//排除列表过滤后的安装列表 | ||
let installList = []; | ||
let metadataPath = path.resolve(pathUtils.getPluginPath(), 'metadata.json'); | ||
try { | ||
let metadata = require(metadataPath); | ||
for (let i = 0; i < args.length; i++) { | ||
let checkName = args[i]; | ||
if (args[i].indexOf('@') > 0) { | ||
checkName = args[i].substring(0, args[i].indexOf('@')); | ||
} | ||
if (metadata.excludePlugins.indexOf(checkName) < 0) { | ||
installList.push(args[i]); | ||
} | ||
} | ||
let promises = []; | ||
installList.forEach(plugin => { | ||
let install = new Promise((resolve, reject) => { | ||
console.log(`正在安装 ${plugin} ...`); | ||
childProcess.exec(`npm i ${plugin} --save-dev`, (err, stdout, stderr) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
console.log(`${plugin} 安装完成.`); | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
promises.push(install); | ||
}); | ||
Promise.all(promises).then(() => { | ||
this._handleSuccess(true, "插件安装完成!"); | ||
}).catch(err => { | ||
this._handleError(err, true); | ||
}); | ||
} catch (err) { | ||
this._handleError(err, true); | ||
console.log(`读取元信息文件${metadataPath}失败!`); | ||
} | ||
} | ||
} |
{ | ||
"name": "v3-installer", | ||
"version": "1.0.24", | ||
"version": "1.0.25", | ||
"description": "v3二次开发插件安装器", | ||
@@ -11,5 +11,7 @@ "main": "index.js", | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"prepublish": "node bin/prepublihs.js", | ||
"install": "node bin/init.js", | ||
"v3:install": "v3installer -i", | ||
"v3:uninstall": "v3installer -u" | ||
"v3:uninstall": "v3installer -u", | ||
"npm:install": "v3installer -n" | ||
}, | ||
@@ -16,0 +18,0 @@ "keywords": [ |
@@ -13,3 +13,4 @@ /** | ||
const PluginDepInfo = require('../model/PluginDepInfo'); | ||
const cacheUtils = require('../utils/CacheUtils'); | ||
const stringUtils = require('../utils/StringUtils'); | ||
class PluginAnalyzer { | ||
@@ -22,9 +23,6 @@ /** | ||
*/ | ||
constructor(pluginJarPath, pluginName, unZipDir) { | ||
constructor(pluginJarPath) { | ||
this.pluginJarPath = pluginJarPath; | ||
this.unZipDir = unZipDir; | ||
this.pluginName = pluginName; | ||
this.cfgPath = unZipDir + PathSep + pluginName; | ||
/* node插件的解压路径 */ | ||
this.nodejsPluginPath = unZipDir + PathSep + "nodePlugin"; | ||
this.tgzCachePath = cacheUtils.getTgzCachePath(); | ||
this.cfgPath = path.join(this.tgzCachePath, 'v3cfgCache'); | ||
/* 保存从jar包中解析到的v3配置文件信息 */ | ||
@@ -34,9 +32,15 @@ this.v3DevConfigs = []; | ||
this.tgzFiles = []; | ||
this.jarMd5 = stringUtils.toMd5(path.basename(this.pluginJarPath)); | ||
} | ||
/* 解压jar包到指定文件夹下 */ | ||
/* 解压jar包内的tgz文件到指定文件夹下 */ | ||
_decompressJar() { | ||
return new Promise((resolve, reject) => { | ||
decompress(this.pluginJarPath, this.nodejsPluginPath, { | ||
decompress(this.pluginJarPath, this.tgzCachePath, { | ||
filter: (data) => { | ||
return data.type == 'file' && data.path.endsWith('.tgz'); | ||
}, | ||
map: (file) => { | ||
/* 使用jar包文件名的md5值作为解压出来的tgz文件名 */ | ||
file.path = this.jarMd5 + path.extname(file.path); | ||
return file; | ||
} | ||
@@ -46,3 +50,3 @@ }).then((files) => { | ||
for (let i = 0; i < files.length; i++) { | ||
let filePath = path.resolve(this.nodejsPluginPath, files[i].path); | ||
let filePath = path.resolve(this.tgzCachePath, files[i].path); | ||
TgzFiles.push(filePath); | ||
@@ -60,5 +64,7 @@ /* 同时保存到解析器属性中 */ | ||
_getV3DevConfigFromTgz(TgzFiles) { | ||
let tzgManifest = cacheUtils.getManifest(this.tgzCachePath); | ||
return new Promise((resolve, reject) => { | ||
let getV3cfg = () => { | ||
if (TgzFiles.length == 0) { | ||
cacheUtils.updateTgzManifest(tzgManifest); | ||
resolve(this.v3DevConfigs); | ||
@@ -71,2 +77,6 @@ return; | ||
return data.type == 'file' && data.path.endsWith('.v3devrc'); | ||
}, | ||
map: (file) => { | ||
file.path = path.basename(file.path); | ||
return file; | ||
} | ||
@@ -77,7 +87,16 @@ }).then((files) => { | ||
for (let i = 0; i < files.length; i++) { | ||
cfgFiles.push(this.cfgPath + PathSep + files[i].path); | ||
cfgFiles.push(path.join(this.cfgPath, files[i].path)); | ||
} | ||
try { | ||
for (let j = 0; j < cfgFiles.length; j++) { | ||
this.v3DevConfigs.push(JSON.parse(fs.readFileSync(cfgFiles[j]))); | ||
let v3cfg = JSON.parse(fs.readFileSync(cfgFiles[j])); | ||
this.v3DevConfigs.push(v3cfg); | ||
/* 保存清单缓存信息 */ | ||
tzgManifest.push({ | ||
symbolicName: v3cfg.symbolicName, | ||
jarMd5: this.jarMd5, | ||
type: v3cfg.type, | ||
libType: v3cfg.libType, | ||
filePath: tgzFile | ||
}); | ||
} | ||
@@ -174,3 +193,3 @@ fileUtils.removeDirectory(this.cfgPath); | ||
/* 移除临时文件夹 */ | ||
fileUtils.removeDirectory(xmlPath); | ||
//fileUtils.removeDirectory(xmlPath); | ||
getDepInfo(); | ||
@@ -199,3 +218,3 @@ }); | ||
console.error(e); | ||
fileUtils.removeDirectory(this.unZipDir); | ||
fileUtils.removeDirectory(this.tgzCachePath); | ||
} | ||
@@ -202,0 +221,0 @@ }); |
@@ -14,2 +14,3 @@ const configUtils = require('../utils/ConfigUtils'); | ||
const prompt = require('inquirer').prompt; | ||
/* 从vstore中安装构件到本地 */ | ||
@@ -23,10 +24,8 @@ class VPlatformPluginInstaller { | ||
*/ | ||
constructor(jarFiles, downloadPath, simpleMode, vstoreCfg) { | ||
constructor(jarFiles, simpleMode, vstoreCfg) { | ||
this.jarFiles = jarFiles; | ||
this.simpleMode = simpleMode || false; | ||
this.downloadPath = downloadPath || this._getNewDirPath(); | ||
this.vstoreCfg = vstoreCfg; | ||
vstoreCfg.simpleMode = this.simpleMode; | ||
this.downloader = new VpluginDownloader(this.downloadPath, vstoreCfg); | ||
this.unZipDir = pathUtils.getPluginPath() + PathSep + "analyTmp" | ||
this.downloader = new VpluginDownloader(vstoreCfg); | ||
} | ||
@@ -70,3 +69,3 @@ | ||
/* 解析器 */ | ||
let pluginAnalyzer = new PluginAnalyzer(file, this.symbolicName, this.unZipDir); | ||
let pluginAnalyzer = new PluginAnalyzer(file); | ||
pluginAnalyzer._analyze().then((result) => { | ||
@@ -115,3 +114,3 @@ if (result.length == 2) { | ||
/* 解析器 */ | ||
let pluginAnalyzer = new PluginAnalyzer(file, this.symbolicName, this.unZipDir); | ||
let pluginAnalyzer = new PluginAnalyzer(file); | ||
pluginAnalyzer._decompressJar().then((TgzFiles) => { | ||
@@ -157,23 +156,22 @@ tgzFiles = tgzFiles.concat(TgzFiles); | ||
return new Promise((resolve, reject) => { | ||
let npmInstall = () => { | ||
if (tgzFiles.length == 0) { | ||
resolve(); | ||
return; | ||
} | ||
let tgzfile = tgzFiles.pop(); | ||
console.log('安装:' + tgzfile); | ||
childProcess.exec("npm install " + tgzfile + " --no-save --ignore-scripts", { | ||
cwd: pathUtils.getPluginPath() | ||
}, (err, stdout, stderr) => { | ||
if (err) { | ||
reject(err); | ||
return; | ||
} | ||
console.log(stdout); | ||
npmInstall(); | ||
let promises = []; | ||
tgzFiles.forEach(tgzfile => { | ||
let install = new Promise((resolve, reject) => { | ||
console.log(`正在安装 ${tgzfile} ...`); | ||
childProcess.exec(`npm i ${tgzfile} --save-dev`, (err, stdout, stderr) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
console.log(`${tgzfile} 安装完成.`); | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
//childProcess.execSync("npm install " + tgzfile + " --no-save --ignore-scripts"); | ||
npmInstall(); | ||
} //npmInstall | ||
npmInstall(); | ||
promises.push(install); | ||
}); | ||
Promise.all(promises).then(() => { | ||
resolve(); | ||
}).catch(err => { | ||
reject(err); | ||
}) | ||
}); | ||
@@ -214,4 +212,4 @@ } | ||
this._preInstall().then(tgzFiles => { | ||
this._installPluginByUnzip(tgzFiles).then(() => { | ||
this._afterInstall(); | ||
this._installNodeJsPlugin(tgzFiles).then(() => { | ||
//this._afterInstall(); | ||
resolve(); | ||
@@ -254,4 +252,4 @@ }); | ||
_afterInstall() { | ||
fileUtils.removeDirectory(this.downloadPath); | ||
fileUtils.removeDirectory(this.unZipDir); | ||
//fileUtils.removeDirectory(this.downloadPath); | ||
//fileUtils.removeDirectory(this.unZipDir); | ||
} | ||
@@ -258,0 +256,0 @@ /* 将解析出来的依赖添加到用户项目配置文件中 */ |
@@ -12,2 +12,3 @@ /** | ||
const fs = require('fs'); | ||
const cacheUtils = require('../utils/CacheUtils'); | ||
class VpluginDownloader { | ||
@@ -19,5 +20,5 @@ /** | ||
*/ | ||
constructor(downloadPath, config) { | ||
constructor(config) { | ||
this.taskList = []; | ||
this.downloadPath = downloadPath || this._getNewDirPath(); | ||
this.downloadPath = cacheUtils.getJarCachePath(); | ||
this.config = config; | ||
@@ -61,3 +62,3 @@ } | ||
/* 获取文件id */ | ||
_getFileId(task) { | ||
_getFileInfo(task) { | ||
return new Promise((resolve, reject) => { | ||
@@ -110,4 +111,4 @@ /* 内部函数 */ | ||
try { | ||
let fildId = body.data.results.componentVers.result.datas.values[0].fileId; | ||
resolve(fildId); | ||
let resultValue = body.data.results.componentVers.result.datas.values[0]; | ||
resolve(resultValue); | ||
return; | ||
@@ -135,2 +136,3 @@ } catch (e) { | ||
_start() { | ||
let Jarmanifest = cacheUtils.getManifest(this.downloadPath); | ||
return new Promise((resolve, reject) => { | ||
@@ -141,2 +143,4 @@ /* 已经下载完成的文件列表 */ | ||
if (this.taskList.length == 0) { | ||
/* 保存缓存信息 */ | ||
cacheUtils.updateJarManifest(Jarmanifest); | ||
resolve(finishFiles); | ||
@@ -147,25 +151,40 @@ return; | ||
console.log(`下载插件: ${task.name}`); | ||
this._getFileId(task).then((fileId) => { | ||
let params = { | ||
data: { | ||
dataId: fileId | ||
} | ||
}; | ||
let json = JSON.stringify(params); | ||
let encodedJson = encodeURIComponent(json); | ||
let paramData = { | ||
token: encodedJson | ||
}; | ||
let absPath = path.join(this.downloadPath, task.name + ".jar"); | ||
needle.get("http://www.toone.com.cn:8808/module-operation!executeOperation?operation=PartFileDown&token=" + encodedJson, { | ||
output: absPath | ||
}, (err, resp, body) => { | ||
if (err) { | ||
reject(err); | ||
return; | ||
this._getFileInfo(task).then((fileInfo) => { | ||
let catchfile = cacheUtils.getJarFromCache(task.name); | ||
/* 如果从vstore中获取的文件id与缓存的文件id相同则采用本地缓存,否则下载新文件 */ | ||
if (catchfile && catchfile.vstoreId == fileInfo.fileId) { | ||
finishFiles[task.name] = catchfile.filePath; | ||
download(); | ||
} else { | ||
let params = { | ||
data: { | ||
dataId: fileInfo.fileId | ||
} | ||
}; | ||
/* 如果没有出错则添加到已下载列表,然后开启下一个任务 */ | ||
finishFiles[task.name] = absPath; | ||
download(); | ||
}); | ||
let json = JSON.stringify(params); | ||
let encodedJson = encodeURIComponent(json); | ||
let paramData = { | ||
token: encodedJson | ||
}; | ||
let absPath = path.join(this.downloadPath, task.name + ".jar"); | ||
needle.get("http://www.toone.com.cn:8808/module-operation!executeOperation?operation=PartFileDown&token=" + encodedJson, { | ||
output: absPath | ||
}, (err, resp, body) => { | ||
if (err) { | ||
reject(err); | ||
return; | ||
}; | ||
/* 如果没有出错则添加到已下载列表,然后开启下一个任务 */ | ||
finishFiles[task.name] = absPath; | ||
Jarmanifest.push({ | ||
symbolicName: task.name, | ||
libType: task.libType, | ||
vstoreId: fileInfo.fileId, | ||
version: fileInfo.bundleVersion, | ||
filePath: absPath, | ||
time: Date.now() | ||
}); | ||
download(); | ||
}); | ||
} | ||
}).catch(err => { | ||
@@ -172,0 +191,0 @@ reject(err); |
@@ -15,4 +15,3 @@ const pathUtils = require('../utils/PathUtils'); | ||
this.libType = libType; | ||
this.downloadPath = this._getNewDirPath(); | ||
this.downloader = new VpluginDownloader(this.downloadPath); | ||
this.downloader = new VpluginDownloader(); | ||
this.unZipDir = pathUtils.getPluginPath() + PathSep + "analyTmp" | ||
@@ -41,3 +40,3 @@ } | ||
/* 使用本地安装器 */ | ||
let vplatformPluginInstaller = new VPlatformPluginInstaller(Object.values(fileList), this.downloadPath, false, { | ||
let vplatformPluginInstaller = new VPlatformPluginInstaller(Object.values(fileList), false, { | ||
libType: this.libType | ||
@@ -44,0 +43,0 @@ }); |
@@ -28,3 +28,3 @@ /** | ||
this.keywords = keywords; | ||
params.data.libCode = libCode; | ||
params.data.libCode = libCode||'dev'; | ||
} | ||
@@ -31,0 +31,0 @@ /* 查询操作 */ |
@@ -151,3 +151,3 @@ const fs = require("fs"); | ||
} catch (err) { | ||
console.log('目录删除失败!'); | ||
console.log(`目录${dirPath}删除失败!`); | ||
console.log(err); | ||
@@ -154,0 +154,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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
91006
2348
25
19