|
|
const inquirer = require('inquirer');
|
|
|
const shelljs = require('shelljs');
|
|
|
const path = require('path');
|
|
|
const _ = require('lodash');
|
|
|
const fs = require('fs');
|
|
|
const cp = require('child_process');
|
|
|
|
|
|
module.exports = ({code_path, env}) => {
|
|
|
const dirs = shelljs.ls(path.join(__dirname, '../mode'));
|
|
|
|
|
|
inquirer.prompt([
|
|
|
{
|
|
|
type: 'list',
|
|
|
name: 'mode',
|
|
|
message: '选择小程序主体开发主体',
|
|
|
choices: dirs
|
|
|
}
|
|
|
]).then(({mode}) => {
|
|
|
try {
|
|
|
const configs = shelljs.ls(path.join(__dirname, '../mode', mode));
|
|
|
|
|
|
_.each(configs, c => {
|
|
|
if (/\.js$/.test(c)) {
|
|
|
const fileName = c.replace(/\.js$/, '');
|
|
|
const baseConfig = require(path.join(__dirname, '../config', `${fileName}.base.js`));
|
|
|
let envConfig, modeConfig;
|
|
|
const genConfig = require('./gen-config');
|
|
|
const wxrc = require('./wxrc');
|
|
|
|
|
|
if (env === 'production') {
|
|
|
envConfig = require(path.join(__dirname, '../config', `${fileName}.prod.js`));
|
|
|
} else {
|
|
|
envConfig = require(path.join(__dirname, '../config', `${fileName}.dev.js`));
|
|
|
}
|
|
|
modeConfig = require(path.join(__dirname, '../mode', mode, `${fileName}.js`));
|
|
|
const fullConfig = _.merge(baseConfig, envConfig, modeConfig);
|
|
|
|
|
|
fs.writeFile(path.join(__dirname, '../', code_path, c),
|
|
|
`export default ${JSON.stringify(fullConfig, null, 2)}`,
|
|
|
err => {
|
|
|
if (err) {
|
|
|
throw err;
|
|
|
}
|
|
|
});
|
|
|
} else if (/\.json$/.test(c)) {
|
|
|
const baseConfig = require(path.join(__dirname, '../config', c));
|
|
|
const modeConfig = require(path.join(__dirname, '../mode', mode, c));
|
|
|
const fullConfig = _.merge(baseConfig, modeConfig);
|
|
|
module.exports = ({code_path, env}) => {
|
|
|
genConfig({code_path, env}).then(() => wxrc()).then(({wxpath}) => {
|
|
|
const ls = cp.spawn(`${wxpath}/cli`, ['-o', path.join(__dirname, '../', code_path)]);
|
|
|
|
|
|
fs.writeFile(path.join(__dirname, '../', code_path, c), JSON.stringify(fullConfig, null, 2), err => {
|
|
|
if (err) {
|
|
|
throw err;
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
} catch (e) {
|
|
|
console.error(e);
|
|
|
}
|
|
|
ls.stdout.on('data', (data) => {
|
|
|
console.log(data.toString());
|
|
|
});
|
|
|
ls.stderr.on('data', (data) => {
|
|
|
console.log(data.toString());
|
|
|
});
|
|
|
}).catch(e => {
|
|
|
console.error('error', e);
|
|
|
});
|
|
|
}; |
...
|
...
|
|