Skip to content

Commit

Permalink
refactor: env-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
1160007652 committed Apr 15, 2021
1 parent 96b6408 commit 370f434
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 18 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion packages/@muniz/cli-i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions packages/@muniz/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
13 changes: 12 additions & 1 deletion packages/@muniz/cli/src/core/middleWare/isCommand/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand Down Expand Up @@ -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] });
}

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/@muniz/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion packages/@muniz/ink-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions packages/@muniz/muniz-plugin-create/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion packages/@muniz/servers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
5 changes: 1 addition & 4 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 脚手架 项目打包成功'
2 changes: 0 additions & 2 deletions scripts/initData/system.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"MUNIZ_CLI_DEBUG": false,
"MUNIZ_PLUGIN_DEV": false,
"languageLocale": "zhCN",
"plugins": []
}
23 changes: 23 additions & 0 deletions scripts/publish.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 370f434

Please sign in to comment.