Skip to content

Commit

Permalink
mri-cli@1.1.0 rewrite mri-dev mri-prod mri-build
Browse files Browse the repository at this point in the history
  • Loading branch information
mizi-lin committed Oct 23, 2018
1 parent 708dfea commit 33470c9
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 343 deletions.
139 changes: 2 additions & 137 deletions bin/mri-build
Original file line number Diff line number Diff line change
Expand Up @@ -7,144 +7,9 @@

'use strict';

const _program = require('commander');
const _fse = require('fs-extra');
const _exists = require('fs').existsSync;
const _readFileSync = require('fs').readFileSync;
const _createReadStream = require('fs').createReadStream;
const _join = require('path').join;
const _ = require('lodash');
const _chalk = require('chalk');
const _shell = require('shelljs');
const {log, error, debug} = console;
const {green, red, yellow, grey} = _chalk;

const $command = require('../service/command');
const $util = require('../service/util');
const $pages = require('../service/pages');
const $env = require('../service/env');
const $initThemeRoot = require('../service/theme-root');
const $upgrade = require('../service/upgrade');
const $root = require('../service/root');
const $_project = require('../process/project');

const MRI_ENV = 'test';

const cwd = process.cwd();

// 所有cli命令均要在 项目的根目录下运行
if(!$root.judgeRoot(cwd)) {
log('\n');
log(red`当前路径${cwd}`);
log(red`不是mri的根目录,请切换到根目录后重新执行命令\n`);
let root = $root.getRoot();
root && log(`cd ${$root.getRoot()} \n\n`);
return void 0;
}

// 自动更新test代码, 并checkout .mrirc.js
log(`---=> auto git fetch`);
_shell.exec(`
git fetch -u origin mri-common:mri-common
git checkout mri-common -- .mrirc
git checkout mri-common -- .umirc.js
rm -rf .mrirc.js
mv .mrirc .mrirc.js
git rm --cache .mrirc > /dev/null
rm -rf .mrirc
`);

// 设置 command 信息
$command(MRI_ENV);

// 获得当前运行主题
const theme = _program.args[0];

if(!theme) {
error(`${red('### ERRO =>')} theme 未输入`);
return void 0;
} else {}

/**
* 检测 src/theme/${theme} 是否存在
*/
log(`---=> 检测当前主题是否存在`);

let themePath = _join(process.cwd(), `src/theme/${theme}`);
if(!_exists(themePath)){
error(`${red('### ERRO =>')} 当前主题不存在 ${theme} 不存在`);
return void 0;
}

/**
* 检测 .mrirc.js
*/
let mrircPath = _join(process.cwd(), `./.mrirc.js`);
if(_exists(mrircPath)) {
log(`---=> 更新或安装包`);
if(!_program['NO_INSTALL']) {
$upgrade(mrircPath);
}
}

/**
* 生成 pages 文件
*/

if(!$pages(theme, MRI_ENV)) {
error(red(`@@@=> 路由文件写入失败`));
return void 0;
}

/**
* 写入 src/theme/index.ts
*/
$initThemeRoot(theme, MRI_ENV);

log(`\n\n---=> 读取环境配置信息`);

/**
* 获得环境变量
* @type {*|string|string}
*/
let {env, config} = $env(theme, MRI_ENV);

/**
* 是否强制启动MRI
*
* //-> 关闭端口
* //-> env: BABEL_CACHE=none
*/
if(_program.FORCE) {
_shell.exec(`
lsof -i :${config.PORT}|grep node|awk '{print $2}'|grep -v PID|xargs kill -9
`);

env = env.replace('BABEL_CACHE=1', 'BABEL_CACHE=none');
}

if(_.isNil(env)) {
return void 0;
}

log(`\n\n---=> 正在启动主题 => ${green(theme)}` );

_shell.exec(`
_cross=./node_modules/.bin/cross-env
_umi=./node_modules/.bin/umi
echo 'umi ${MRI_ENV} ${env}'
# $_umi -v
$_cross MRI_ENV=${MRI_ENV} ${env} $_umi build
`);












$_project(MRI_ENV);

83 changes: 2 additions & 81 deletions bin/mri-dev
Original file line number Diff line number Diff line change
Expand Up @@ -7,88 +7,9 @@

'use strict';

const _program = require('commander');
const _fse = require('fs-extra');
const _exists = require('fs').existsSync;
const _readFileSync = require('fs').readFileSync;
const _createReadStream = require('fs').createReadStream;
const _join = require('path').join;
const _ = require('lodash');
const _chalk = require('chalk');
const _shell = require('shelljs');
const _spawn = require('cross-spawn');
const { log, error, debug } = console;
const { green, red, yellow, grey } = _chalk;

const $command = require('../service/command');
const $util = require('../service/util');
const $pages = require('../service/pages');
const $env = require('../service/env');
const $initThemeRoot = require('../service/theme-root');
const $root = require('../service/root');
const $interface = require('../service/interface');
const $upgrade = require('../service/upgrade');
const $Bus = require('../service/bus');
const $_project = require('../process/project');

const MRI_ENV = 'dev';
const cwd = process.cwd();

/**
* 配置command
*/
$command(MRI_ENV);

/**
* 所有的命令均要在在根目录上运行
*/

const root = $Bus.inRoot();

/**
* 主题(项目)校验
*/
const theme = _program.args[0];

$Bus.theme(theme);

/**
* fetch 代码
* 更新 .mrirc.js 文件
*/
$Bus.fetch();

/**
* 判断是否要升级系统
*/
$Bus.mriUpdate();

/**
* 校验是否要安装包
*/
$Bus.install();

/**
* 生成umi约定式路由文件
* src/pages
*/
$Bus.pages(theme, MRI_ENV);

/**
* 生成mri关联的手机
*/
$Bus.mrifile(theme, MRI_ENV);

/**
* 获得环境变量
*/
let env = $Bus.env(theme, MRI_ENV);

log(`\n\n---=> 正在启动主题 => ${green(theme)}`);
$_project(MRI_ENV);

_shell.exec(`
_cross=./node_modules/.bin/cross-env
_umi=./node_modules/.bin/umi
echo develop env ${MRI_ENV}
echo "umi environment variable ::=> ${env}"
$_cross MRI_ENV=${MRI_ENV} ${env} $_umi dev
`);
127 changes: 2 additions & 125 deletions bin/mri-prod
Original file line number Diff line number Diff line change
Expand Up @@ -7,132 +7,9 @@

'use strict';

const _program = require('commander');
const _fse = require('fs-extra');
const _exists = require('fs').existsSync;
const _readFileSync = require('fs').readFileSync;
const _createReadStream = require('fs').createReadStream;
const _join = require('path').join;
const _ = require('lodash');
const _chalk = require('chalk');
const _shell = require('shelljs');
const {log, error, debug} = console;
const {green, red, yellow, grey} = _chalk;

const $command = require('../service/command');
const $util = require('../service/util');
const $pages = require('../service/pages');
const $env = require('../service/env');
const $initThemeRoot = require('../service/theme-root');
const $upgrade = require('../service/upgrade');
const $root = require('../service/root');
const $_project = require('../process/project');

const MRI_ENV = 'prod';

const cwd = process.cwd();


// 所有cli命令均要在 项目的根目录下运行
if(!$root.judgeRoot(cwd)) {
log('\n');
log(red`当前路径${cwd}`);
log(red`不是mri的根目录,请切换到根目录后重新执行命令\n`);
let root = $root.getRoot();
root && log(`cd ${$root.getRoot()} \n\n`);
return void 0;
}

// 自动更新test代码, 并checkout .mrirc.js
log(`---=> auto git fetch`);
_shell.exec(`
git fetch -u origin mri-common:mri-common
git checkout mri-common -- .mrirc
git checkout mri-common -- .umirc.js
rm -rf .mrirc.js
mv .mrirc .mrirc.js
git rm --cache .mrirc > /dev/null
rm -rf .mrirc
`);

// 设置 command 信息
$command(MRI_ENV);

// 获得当前运行主题
const theme = _program.args[0];

if(!theme) {
error(`${red('### ERRO =>')} theme 未输入`);
return void 0;
} else {}

/**
* 检测 src/theme/${theme} 是否存在
*/
log(`---=> 检测当前主题是否存在`);

let themePath = _join(process.cwd(), `src/theme/${theme}`);
if(!_exists(themePath)){
error(`${red('### ERRO =>')} 当前主题不存在 ${theme} 不存在`);
return void 0;
}

/**
* 检测 .mrirc.js
*/
let mrircPath = _join(process.cwd(), `./.mrirc.js`);
if(_exists(mrircPath)) {
log(`---=> 更新或安装包`);
if(!_program['NO_INSTALL']) {
$upgrade(mrircPath);
}
}

/**
* 生成 pages 文件
*/

if(!$pages(theme, MRI_ENV)) {
error(red(`@@@=> 路由文件写入失败`));
return void 0;
}

/**
* 写入 src/theme/index.ts
*/
$initThemeRoot(theme, MRI_ENV);

log(`\n\n---=> 读取环境配置信息`);

/**
* 获得环境变量
* @type {*|string|string}
*/
let {env, config} = $env(theme, MRI_ENV);

/**
* 是否强制启动MRI
*
* //-> 关闭端口
* //-> env: BABEL_CACHE=none
*/
if(_program.FORCE) {
_shell.exec(`
lsof -i :${config.PORT}|awk '{print $2}'|grep -v PID|xargs kill -9
`);

env = env.replace('BABEL_CACHE=1', 'BABEL_CACHE=none');
}

if(_.isNil(env)) {
return void 0;
}

log(`\n\n---=> 正在启动主题 => ${green(theme)}` );
$_project(MRI_ENV);

_shell.exec(`
_cross=./node_modules/.bin/cross-env
_umi=./node_modules/.bin/umi
echo 'umi ${MRI_ENV} ${env}'
# $_umi -v
$_cross MRI_ENV=${MRI_ENV} ${env} $_umi build
`);
Loading

0 comments on commit 33470c9

Please sign in to comment.