This commit is contained in:
parent
a7f596aa0a
commit
4207d6e467
@ -2,6 +2,15 @@
|
|||||||
const os = require("os");
|
const os = require("os");
|
||||||
const kitfunction = require("./kitfunction");
|
const kitfunction = require("./kitfunction");
|
||||||
|
|
||||||
|
async function getAvailableRemote() {
|
||||||
|
const remote = await $context.get("remote");
|
||||||
|
if (!(await remote.check())) {
|
||||||
|
$logger.error("远程仓库不可用");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return remote;
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
init : function () {
|
init : function () {
|
||||||
return this;
|
return this;
|
||||||
@ -57,8 +66,6 @@ async function main(){
|
|||||||
const vm = require('vm');
|
const vm = require('vm');
|
||||||
const script = new vm.Script(projectScript + ";" + step + "()");
|
const script = new vm.Script(projectScript + ";" + step + "()");
|
||||||
|
|
||||||
// 注入全局变量
|
|
||||||
const kitfunction = require("./kitfunction")
|
|
||||||
const context = kitfunction;
|
const context = kitfunction;
|
||||||
|
|
||||||
script.runInNewContext(context, {
|
script.runInNewContext(context, {
|
||||||
@ -83,53 +90,81 @@ async function main(){
|
|||||||
});
|
});
|
||||||
|
|
||||||
parser.addCmdLine("remote", "验证远程仓库可达;", async function () {
|
parser.addCmdLine("remote", "验证远程仓库可达;", async function () {
|
||||||
let remote = await $context.get("remote")
|
const remote = await getAvailableRemote();
|
||||||
if (!(await remote.check())) {
|
if (remote) {
|
||||||
$logger.error("远程仓库不可用")
|
$logger.info("远程仓库可用");
|
||||||
return
|
|
||||||
} else {
|
|
||||||
$logger.info("远程仓库可用")
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
parser.addCmdLine("publish [localFile] [remotePath]", "发布到远程仓库", async function (cli) {
|
parser.addCmdLine("check", "验证远程仓库可达;", async function () {
|
||||||
|
const remote = await getAvailableRemote();
|
||||||
|
if (remote) {
|
||||||
|
$logger.info("远程仓库可用");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
parser.addCmdLine("publish [localFile] [remotePath]", "发布到远程仓库; localFile 为空时使用当前目录 meta.json", async function (cli) {
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
let localFile = cli.getParamValue("localFile");
|
let localFile = cli.getParamValue("localFile");
|
||||||
if (!fs.existsSync(localFile)) {
|
let remotePath = cli.getParamValue("remotePath");
|
||||||
$logger.error("本地文件不存在")
|
|
||||||
return
|
if (localFile && !fs.existsSync(localFile)) {
|
||||||
|
$logger.error("本地文件不存在");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let remotePath = cli.getParamValue("remotePath");
|
if (!localFile && !fs.existsSync("meta.json")) {
|
||||||
if (!remotePath) {
|
$logger.error("没有找到本地配置 meta.json");
|
||||||
$logger.info("使用本地配置路径")
|
return;
|
||||||
if (!fs.existsSync("meta.json")) {
|
|
||||||
$logger.error("没有找到本地配置")
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const remote = await getAvailableRemote();
|
||||||
|
if (!remote) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (remotePath) {
|
||||||
|
$logger.info("发布到远程路径 " + remotePath);
|
||||||
} else {
|
} else {
|
||||||
$logger.info("发布到远程路径 " + remotePath)
|
$logger.info("使用 meta.json 中的 group/id/version 规则发布");
|
||||||
}
|
}
|
||||||
let remote = await $context.get("remote")
|
await remote.publish(localFile, remotePath);
|
||||||
if (!(await remote.check())) {
|
$logger.info("发布成功");
|
||||||
$logger.error("远程仓库不可用")
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
$logger.info("远程仓库可用")
|
|
||||||
}
|
|
||||||
await remote.publish(localFile, remotePath)
|
|
||||||
$logger.info("发布成功")
|
|
||||||
});
|
});
|
||||||
|
|
||||||
parser.addCmdLine("install [module]", "安装/更新模块;", async function (cli) {
|
parser.addCmdLine("install [module]", "安装/更新模块; 支持 myapp、myapp@1.0、/docker/net/myapp", async function (cli) {
|
||||||
let remote = await $context.get("remote")
|
const remote = await getAvailableRemote();
|
||||||
if (!(await remote.check())) {
|
if (!remote) {
|
||||||
$logger.error("远程仓库不可用")
|
return;
|
||||||
return
|
|
||||||
} else {
|
|
||||||
$logger.info("远程仓库可用")
|
|
||||||
}
|
}
|
||||||
remote.install(cli.getParamValue("module"))
|
await remote.install(cli.getParamValue("module"));
|
||||||
|
});
|
||||||
|
|
||||||
|
parser.addCmdLine("list [module]", "列出本地已安装版本;", async function (cli) {
|
||||||
|
let module = cli.getParamValue("module");
|
||||||
|
if (!module) {
|
||||||
|
module = "kit";
|
||||||
|
}
|
||||||
|
const remote = await $context.get("remote");
|
||||||
|
await remote.list(module);
|
||||||
|
});
|
||||||
|
|
||||||
|
parser.addCmdLine("use <module-version>", "切换到已安装版本,例如 myapp@1.0;", async function (cli) {
|
||||||
|
const remote = await $context.get("remote");
|
||||||
|
const version = await remote.use(cli.getParamValue("module-version"));
|
||||||
|
$logger.info("当前版本 " + version);
|
||||||
|
});
|
||||||
|
|
||||||
|
parser.addCmdLine("rollback <module>", "回滚到上一个已安装版本;", async function (cli) {
|
||||||
|
const remote = await $context.get("remote");
|
||||||
|
const version = await remote.rollback(cli.getParamValue("module"));
|
||||||
|
$logger.info("当前版本 " + version);
|
||||||
|
});
|
||||||
|
|
||||||
|
parser.addCmdLine("remove <module-version>", "删除本地已安装版本,例如 myapp@1.0;", async function (cli) {
|
||||||
|
const remote = await $context.get("remote");
|
||||||
|
await remote.remove(cli.getParamValue("module-version"));
|
||||||
|
$logger.info("删除成功");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user