diff --git a/package.json b/package.json index ed85b69..4610762 100644 --- a/package.json +++ b/package.json @@ -10,10 +10,9 @@ ], "scripts": { "muniz": "CLI_ENV=development EXTERNAL_PLUGIN_ENV=production babel-node packages/@muniz/cli/src/bin/cli.js", - "dev": "./scripts/dev.sh", "build": "./scripts/build.sh", "clear": "./scripts/clear.sh", - "publish": "lerna publish", + "build:publish": "./scripts/publish.sh", "commit": "git-cz" }, "config": { diff --git a/packages/@muniz/cli-i18n/package.json b/packages/@muniz/cli-i18n/package.json index f5cf0b5..f34a26a 100644 --- a/packages/@muniz/cli-i18n/package.json +++ b/packages/@muniz/cli-i18n/package.json @@ -26,7 +26,7 @@ "url": "git+https://github.com/1160007652/muniz-cli.git" }, "scripts": { - "dev": "babel --root-mode upward src -d dist", + "build": "babel --root-mode upward src -d dist", "test": "echo \"Error: run tests from root\" && exit 1" }, "bugs": { diff --git a/packages/@muniz/cli/package.json b/packages/@muniz/cli/package.json index 55957ca..1c1c9f8 100755 --- a/packages/@muniz/cli/package.json +++ b/packages/@muniz/cli/package.json @@ -26,8 +26,8 @@ "node": ">=v12.18.3" }, "scripts": { - "dev": "babel --root-mode upward src -d dist", - "generateCommandDesc": "muniz --mode=pro --type=desc", + "build": "babel --root-mode upward src -d dist", + "generateCommandDesc": "CLI_ENV=production EXTERNAL_PLUGIN_ENV=development node ./dist/bin/cli.js --mode=pro --type=desc ", "test": "echo \"Error: run tests from root\" && exit 1" }, "dependencies": { diff --git a/packages/@muniz/cli/src/core/middleWare/isCommand/index.js b/packages/@muniz/cli/src/core/middleWare/isCommand/index.js index a63b067..03a4f77 100644 --- a/packages/@muniz/cli/src/core/middleWare/isCommand/index.js +++ b/packages/@muniz/cli/src/core/middleWare/isCommand/index.js @@ -18,10 +18,16 @@ const isCommand = async (ctx, next) => { if (process.env.CLI_ENV === 'development') { ctx.pkgPath = path.join(ctx.pkgPath, '/src'); + const _astCommands = await i18nCommand({ pkgPath: ctx.pkgPath }); + ctx.astCommands = _astCommands[MunizConfig.languageLocale]; + } else if (process.env.EXTERNAL_PLUGIN_ENV === 'development') { + ctx.pkgPath = path.join(ctx.pkgPath, '/dist'); + console.log(ctx.pkgPath); const _astCommands = await i18nCommand({ pkgPath: ctx.pkgPath }); ctx.astCommands = _astCommands[MunizConfig.languageLocale]; } else { ctx.pkgPath = path.join(ctx.pkgPath, '/dist'); + console.log(ctx.pkgPath); ctx.astCommands = fs.readJsonSync(path.join(ctx.pkgPath, '/configs/commandHelp.json'))[MunizConfig.languageLocale]; } @@ -51,7 +57,7 @@ const isCommand = async (ctx, next) => { */ // 如果不是插件开发状态,获取当前执行命令对应的 “插件-包名称” - if (process.env.EXTERNAL_PLUGIN_ENV !== 'development') { + if (process.env.EXTERNAL_PLUGIN_ENV === 'production') { ctx.pkgName = await lowdbAction.getPluginPkgName({ shortName: argv.command[0] }); } @@ -81,6 +87,11 @@ const isCommand = async (ctx, next) => { if (process.env.CLI_ENV === 'development') { ctx.pkgPath = path.join(ctx.pkgPath, '/src'); + const _astCommands = await i18nCommand({ pkgPath: ctx.pkgPath }); + ctx.astCommands = _astCommands[MunizConfig.languageLocale]; + } else if (process.env.EXTERNAL_PLUGIN_ENV === 'development') { + ctx.pkgPath = path.join(ctx.pkgPath, '/dist'); + const _astCommands = await i18nCommand({ pkgPath: ctx.pkgPath }); ctx.astCommands = _astCommands[MunizConfig.languageLocale]; } else { diff --git a/packages/@muniz/cli/src/core/middleWare/runCommand/index.js b/packages/@muniz/cli/src/core/middleWare/runCommand/index.js index d66473b..b4e038e 100644 --- a/packages/@muniz/cli/src/core/middleWare/runCommand/index.js +++ b/packages/@muniz/cli/src/core/middleWare/runCommand/index.js @@ -32,7 +32,7 @@ const runCommand = async (ctx, next) => { } } else { // 当前执行插件, 是否是 走 开发状态 通道 - if (process.env.EXTERNAL_PLUGIN_ENV !== 'development') { + if (process.env.EXTERNAL_PLUGIN_ENV === 'production') { const { pluginCommand } = require(ctx.pkgPath); pluginCommand({ commandPath: _astCommands.path, diff --git a/packages/@muniz/common/package.json b/packages/@muniz/common/package.json index 457a844..8fc8d47 100755 --- a/packages/@muniz/common/package.json +++ b/packages/@muniz/common/package.json @@ -26,7 +26,7 @@ "url": "git+https://github.com/1160007652/muniz-cli.git" }, "scripts": { - "dev": "babel --root-mode upward src --out-dir dist", + "build": "babel --root-mode upward src --out-dir dist", "test": "echo \"Error: run tests from root\" && exit 1" }, "bugs": { diff --git a/packages/@muniz/ink-ui/package.json b/packages/@muniz/ink-ui/package.json index 5b3f1fe..0127f95 100755 --- a/packages/@muniz/ink-ui/package.json +++ b/packages/@muniz/ink-ui/package.json @@ -25,7 +25,7 @@ "url": "git+https://github.com/1160007652/muniz-cli.git" }, "scripts": { - "dev": "babel --root-mode upward src --out-dir dist", + "build": "babel --root-mode upward src --out-dir dist", "test": "echo \"Error: run tests from root\" && exit 1" }, "bugs": { diff --git a/packages/@muniz/muniz-plugin-create/package.json b/packages/@muniz/muniz-plugin-create/package.json index 637b581..63bf44b 100755 --- a/packages/@muniz/muniz-plugin-create/package.json +++ b/packages/@muniz/muniz-plugin-create/package.json @@ -27,8 +27,8 @@ "url": "https://github.com/1160007652/muniz-cli/issues" }, "scripts": { - "dev": "babel --root-mode upward src --out-dir dist", - "generateCommandDesc": "muniz --mode=pro --type=desc ", + "build": "babel --root-mode upward src --out-dir dist", + "generateCommandDesc": "CLI_ENV=production EXTERNAL_PLUGIN_ENV=development node ../cli/dist/bin/cli.js --mode=pro --type=desc", "test": "echo \"Error: run tests from root\" && exit 1" }, "dependencies": { diff --git a/packages/@muniz/servers/package.json b/packages/@muniz/servers/package.json index 6945575..45f2a97 100644 --- a/packages/@muniz/servers/package.json +++ b/packages/@muniz/servers/package.json @@ -25,7 +25,7 @@ "url": "git+https://github.com/1160007652/muniz-cli.git" }, "scripts": { - "dev": "babel --root-mode upward src -d dist", + "build": "babel --root-mode upward src -d dist", "test": "echo \"Error: run tests from root\" && exit 1" }, "bugs": { diff --git a/scripts/build.sh b/scripts/build.sh index 27c7852..78f76bf 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -4,7 +4,7 @@ rm -rf ./packages/@muniz/*/dist # 进行文件打包 -lerna run dev +lerna run build # 修改 命令行执行权限,【由于 Babel 编译出的文件权限不够】 chmod +x ./packages/@muniz/cli/dist/bin/cli.js @@ -15,8 +15,5 @@ cp -f ./packages/@muniz/cli/src/configs/system.json ./packages/@muniz/cli/dist/c # 生成命令 lerna run generateCommandDesc -# 拷贝文件 -cp -f ./scripts/initData/system.json ./packages/@muniz/cli/dist/configs/system.json - # 提示打包成功 echo 'Muniz 脚手架 项目打包成功' diff --git a/scripts/initData/system.json b/scripts/initData/system.json index 415b8e5..1beb108 100644 --- a/scripts/initData/system.json +++ b/scripts/initData/system.json @@ -1,6 +1,4 @@ { - "MUNIZ_CLI_DEBUG": false, - "MUNIZ_PLUGIN_DEV": false, "languageLocale": "zhCN", "plugins": [] } diff --git a/scripts/publish.sh b/scripts/publish.sh new file mode 100755 index 0000000..8f63371 --- /dev/null +++ b/scripts/publish.sh @@ -0,0 +1,23 @@ +# 生产环境脚本 - 发布到 npm、git 仓库 + +# 首次启动时删除之前构建出的“dist”文件夹 +rm -rf ./packages/@muniz/*/dist + +# 进行文件打包 +lerna run build + +# 修改 命令行执行权限,【由于 Babel 编译出的文件权限不够】 +chmod +x ./packages/@muniz/cli/dist/bin/cli.js + +# 拷贝文件 +cp -f ./scripts/initData/system.json ./packages/@muniz/cli/dist/configs/system.json + +# 生成命令 +lerna run generateCommandDesc + +# 提示打包成功 +echo 'Muniz 脚手架 项目打包成功' + +# 发布脚手架 +lerna publish +