Authored by 陈峰

mini cli

{
"wxpath": "/Applications/wechatwebdevtools.app/Contents/Resources/app.nw/bin"
}
\ No newline at end of file
... ...
... ... @@ -28,6 +28,7 @@ App({
awakeReported: false
},
onLaunch(options) {
console.log(wx.getExtConfigSync());
this.globalData.udid = udid.get(); // 生成 UDID
verify.gen(); // 此处返回是是 Promise,需要调用接口的业务,最好在 then 里边执行
... ...
const inquirer = require('inquirer');
const shelljs = require('shelljs');
const path = require('path');
const _ = require('lodash');
const fs = require('fs');
module.exports = ({code_path, env}) => {
const dirs = shelljs.ls(path.join(__dirname, '../mode'));
return inquirer.prompt([
{
type: 'list',
name: 'mode',
message: '选择小程序主体开发主体',
choices: dirs
}
]).then(({mode}) => {
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;
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),
`/* eslint-disable */
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);
fs.writeFile(path.join(__dirname, '../', code_path, c), JSON.stringify(fullConfig, null, 2), err => {
if (err) {
throw err;
}
});
}
});
});
};
... ...
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);
});
};
... ...
const path = require('path');
const cp = require('child_process');
const genConfig = require('./gen-config');
const wxrc = require('./wxrc');
module.exports = ({code_path, ver, desc}) => {
console.log(code_path, ver, desc);
genConfig({code_path, env: 'production'}).then(() => wxrc()).then(({wxpath}) => {
const ls = cp.spawn(`${wxpath}/cli`, [
'-u', `${ver}@${path.join(__dirname, '../', code_path)}`, '--upload-desc', desc
]);
ls.stdout.on('data', (data) => {
console.log(data.toString());
});
ls.stderr.on('data', (data) => {
console.log(data.toString());
});
}).catch(e => {
console.error('error', e);
});
};
... ...
const inquirer = require('inquirer');
const path = require('path');
const fs = require('fs');
module.exports = () => {
const configPath = path.join(__dirname, '../.wxrc');
const existDev = fs.existsSync(configPath);
return new Promise((resolve, reject) => {
let wxrc;
if (existDev) {
wxrc = JSON.parse(fs.readFileSync(configPath));
} else {
inquirer.prompt([
{
type: 'input',
name: 'wxpath',
message: '小程序开发者工具安装目录',
}
]).then(({wxpath}) => {
fs.writeFile(configPath, wxpath);
wxrc = {
wxpath
};
});
}
if (!fs.existsSync(path.join(wxrc.wxpath, 'cli'))) {
return reject('请先安装微信开发者工具');
}
resolve(wxrc);
});
};
... ...
module.exports = {
appid: 'wxe8bfc9b404772199'
appid: 'wx3f08685409f22510'
};
... ...
{
"appid": "wxe8bfc9b404772199",
"projectname": "%E7%BA%A2%E4%BA%BA%E5%B0%8F%E5%BA%97"
"appid": "wx3f08685409f22510",
"projectname": "有货店铺-VANS"
}
\ No newline at end of file
... ...
{
"appid": "wxe8bfc9b40477219922222",
"projectname": "%E7%BA%A2%E4%BA%BA%E5%B0%8F%E5%BA%97"
"appid": "wxe8bfc9b404772199",
"projectname": "有货官方-VANS"
}
\ No newline at end of file
... ...