UNPKG

@molejs/mole-tools

Version:

Configuration and scripts for Mole App.

117 lines (96 loc) 2.62 kB
#!/usr/bin/env node 'use strict'; require('colorful').colorful(); const shelljs = require('shelljs'); const path = require('path'); const Utils = require('../utils/index'); const program = require('commander'); const runCmd = require('../runCmd'); program.on('--help', () => { console.log(' Usage:'.to.bold.blue.color); console.log(); }); program .option('-p, --platform [platform]', '指定编译平台, ios | android') .option('-t, --type [type]', '指定编译类型,beta | official') .parse(process.argv); const project_dir = path.resolve(__dirname, '../../../../../'); const platform = program.platform; const type = program.type; const buildAssetsScriptDir = path.resolve(__dirname, '../../scripts/build-assets.js'); const publishGitlabScriptDir = path.resolve(__dirname, '../../scripts/publish.js'); const taskList = { start: { clear: true, shells: [ 'webpack --config webpack.conf.js --progress --hide-modules --colors --watch' ] }, 'start-official': { clear: true, shells: ['webpack --config webpack.conf.js --progress --hide-modules --colors --watch'] }, "build": { clear: true, shells: [ `webpack --config webpack.conf.js --progress --colors`, `node ${buildAssetsScriptDir}`, ], }, "publish": { clear: true, refs: ['build'], shells: [ `cross-env NODE_ENV=production platform=${platform} build_type=${type} node ${publishGitlabScriptDir}`, ], } }; function runScripts(task) { if (!task.shells) { return ; } if (task.refs) { task.refs.forEach((ref)=>{ runScripts(taskList[ref]); }); } task.shells.forEach((shell)=>{ if (shell) { shelljs.exec(shell); } }); } const task = program.args[0]; if (!task) { program.help(); } else { // console.log('mole-tools run', task); const taskConfig = taskList[task]; if (!taskConfig) { console.warn('未知的scripts命令: "' + task + '".'); console.warn('或许你需要升级mole-tools?'); return; } if (taskConfig.clear) { runCmd(path.resolve(__dirname, '../../scripts/clear.js')); } //const shells = taskConfig; runScripts(taskConfig); // shells.forEach((shell)=>{ // if (shell) { // // shell = Utils.formatString(shell, { // // platform: program.platform, // // type: program.type, // // }); // if (shell.refs) { // shell.refs.forEach((refTask)=>{ // shell.exec(shell); // }); // } // // 执行脚本 // try { // shelljs.exec(shell); // } catch (e) {} // } // }); }