custom-app
Version:
ITIMS��Ʒ�鿪��ר��React���,�Dz��ý��ּ�dhcc-app���������
86 lines (78 loc) • 2.79 kB
JavaScript
const exec = require('child_process').exec;
const fs = require('fs-extra')
const path = require('path')
const chalk = require('chalk')
let spinner = require('../util/spinner');
let util = require('../util/util.js')
function init (projectName, options) {
const cwd = options.cwd || process.cwd()
const reactAppPath = util.getReactAppPath(cwd);
execPath = path.join(reactAppPath, 'src')
const targetDir = path.join(reactAppPath, 'src', projectName)
// let moduleName = ''
// let packageJson = require(path.join(reactAppPath, 'package.json'))
// if (packageJson) {
// moduleName = packageJson.name
// }
// const realName=(moduleName != '' ? (moduleName + '-') : '') + projectName;
if (!fs.existsSync(targetDir)) {
//fs.mkdirSync(targetDir)
let execList = []
let useDHCCRegistry = function () {
return new Promise(function (resolve, reject) {
spinner.logWithSpinner('', chalk.cyan('nrm use dhcc start'))
var install_webpack = 'nrm use dhcc';
exec(install_webpack, { cwd: execPath }, function (err, stdout, stderr) {
if (err) {
console.error(chalk.red('nrm use dhcc失败:' + stderr));
spinner.stopSpinner();
} else {
spinner.logWithSpinner('', stdout)
spinner.logWithSpinner(chalk.cyan('nrm use dhcc complete'))
spinner.logWithSpinner(' ');
resolve();
}
});
})
}
//execList.push(useDHCCRegistry);
//安装webpack webpack-cli
let loadDEMO = function () {
return new Promise(function (resolve, reject) {
spinner.logWithSpinner('', chalk.cyan('itims4-2ndpage DEMO installing'))
var install_webpack = 'itims4 initTpl ' + projectName;
exec(install_webpack, { cwd: execPath }, function (err, stdout, stderr) {
if (err) {
console.error(chalk.red('itims4-2ndpage DEMO 安装失败:' + stderr));
spinner.stopSpinner();
} else {
spinner.logWithSpinner('', stdout)
spinner.logWithSpinner(chalk.cyan('itims4-2ndpage DEMO installed complete'))
spinner.logWithSpinner(' ', ' ');
resolve();
}
});
})
}
execList.push(loadDEMO);
async function queue (arr) {
let res = null
for (let promise of arr) {
res = await promise(res)
}
return await res
}
queue(execList)
.then(data => {
spinner.stopSpinner();
// callback && callback.call();
})
} else {
console.log(chalk.red(projectName + '已经存在'));
}
}
var execPath;
module.exports = (...args) => {
console.log(args)
init(...args)
}