UNPKG

custom-app

Version:

ITIMS��Ʒ�鿪��ר��React���,�Dz��ý��ּ�dhcc-app���������

245 lines (229 loc) 8.93 kB
let exec = require('child_process').exec; let spinner = require('../util/spinner'); let chalk = require('chalk') let path = require('path'); let fs = require("fs"); let execList = []; //初始化package.json let initPackageJSON = function () { return new Promise(function (resolve, reject) { spinner.logWithSpinner('', chalk.cyan('pacakge.json init start')) var install_webpack = 'npm init -y'; exec(install_webpack, { cwd: execPath }, function (err, stdout, stderr) { if (err) { console.error(chalk.red('package.json 初始化失败:' + stderr)); console.log(stdout); spinner.stopSpinner(); } else { spinner.logWithSpinner('', stdout) spinner.logWithSpinner(chalk.cyan('pacakge.json init complete')) spinner.logWithSpinner(' '); resolve(); } }); }) } execList.push(initPackageJSON); let useTaobaoRegistry = function () { return new Promise(function (resolve, reject) { spinner.logWithSpinner('', chalk.cyan('nrm use taobao start')) var install_webpack = 'nrm use taobao'; exec(install_webpack, function (err, stdout, stderr) { if (err) { console.error(chalk.red('nrm use taobao失败:' + stderr)); spinner.stopSpinner(); } else { spinner.logWithSpinner('', stdout) spinner.logWithSpinner(chalk.cyan('nrm use taobao complete')) spinner.logWithSpinner(' '); resolve(); } }); }) } execList.push(useTaobaoRegistry); //安装webpack webpack-cli let installWebpack = function () { return new Promise(function (resolve, reject) { spinner.logWithSpinner('', chalk.cyan('webpack webpack-cli webpack-dev-server install start')) var install_webpack = 'npm i webpack webpack-cli webpack-dev-server -D'; exec(install_webpack, function (err, stdout, stderr) { if (err) { console.error(chalk.red('webpack 安装失败:' + stderr)); console.log(stdout); spinner.stopSpinner(); } else { spinner.logWithSpinner('', stdout) spinner.logWithSpinner(chalk.cyan('webpack webpack-cli install complete')) spinner.logWithSpinner(' ', ' '); resolve(); } }); }) } execList.push(installWebpack); //安装基本插件 //autodll-webpack-plugin 动态链接库自动打包工具 //html-web-plugin clean-webpack-plugin webpack-merge url-loader //@babel/core babel-loader @babel/preset-env @babel/preset-react //style-loader css-loader let installBasePlugin = function () { return new Promise(function (resolve, reject) { spinner.logWithSpinner('', chalk.cyan('development base plugin installing')) var react_webpack = 'npm i glob webpack-bundle-analyzer uglifyjs-webpack-plugin html-webpack-plugin webpack-merge clean-webpack-plugin@1.0.1 url-loader babel-plugin-import @babel/core babel-loader @babel/preset-env @babel/preset-react @babel/plugin-proposal-class-properties file-loader node-sass style-loader css-loader postcss-loader sass-loader less-loader autoprefixer mini-css-extract-plugin terser-webpack-plugin optimize-css-assets-webpack-plugin -D'; exec(react_webpack, { cwd: execPath }, function (err, stdout, stderr) { if (err) { console.error(chalk.red('base plugin 安装失败:' + stderr)) console.log(stdout); spinner.stopSpinner(); } else { spinner.logWithSpinner('', stdout) spinner.logWithSpinner(chalk.cyan('development base plugin installed complete \n')) spinner.logWithSpinner(' ', ' '); resolve(); } }); }) } execList.push(installBasePlugin); let installEnvlugin = function () { return new Promise(function (resolve, reject) { spinner.logWithSpinner('', chalk.cyan('production base plugin installing')) var react_webpack = 'npm i chalk commander ora ssh2 archiver'; exec(react_webpack, { cwd: execPath }, function (err, stdout, stderr) { if (err) { console.error(chalk.red('production base plugin 安装失败:' + stderr)) console.log(stdout); spinner.stopSpinner(); } else { spinner.logWithSpinner('', stdout) spinner.logWithSpinner(chalk.cyan('production base plugin installed complete \n')) spinner.logWithSpinner(' ', ' '); resolve(); } }); }) } //execList.push(installEnvlugin); //安装react react-dom let installReact = function () { return new Promise(function (resolve, reject) { spinner.logWithSpinner('', chalk.cyan('react react-dom redux react-redux react-router react-router-dom react-lazyload prop-types installing')) var react_webpack = 'npm i react react-dom redux react-redux redux-thunk react-router react-router-dom react-lazyload prop-types'; exec(react_webpack, function (err, stdout, stderr) { if (err) { console.error(chalk.red('react 安装失败:' + stderr)); console.log(stdout); spinner.stopSpinner(); } else { spinner.logWithSpinner('', stdout) spinner.logWithSpinner(chalk.cyan('react react-dom installed complete \n')) spinner.logWithSpinner(' ', ' '); resolve(); } }); }) } execList.push(installReact); //安装semantic-ui-react semantic-ui-css react的UI框架 let installSemantic = function () { return new Promise(function (resolve, reject) { spinner.logWithSpinner('', chalk.cyan('semantic-ui-react installing')) var semantic_webpack = 'npm i semantic-ui-react'; exec(semantic_webpack, function (err, stdout, stderr) { if (err) { console.error(chalk.red('semantic-ui-react 安装失败:' + stderr)) console.log(stdout); spinner.stopSpinner(); } else { spinner.logWithSpinner('', stdout) spinner.logWithSpinner(chalk.cyan('semantic-ui-react installed complete \n')) spinner.logWithSpinner(' ', ' '); resolve(); } }); }) } execList.push(installSemantic); //安装antd react的UI框架 let installAntd = function () { return new Promise(function (resolve, reject) { spinner.logWithSpinner('', chalk.cyan('antd installing')) var semantic_webpack = 'npm i antd'; exec(semantic_webpack, function (err, stdout, stderr) { if (err) { console.error(chalk.red('antd 安装失败:' + stderr)) console.log(stdout); spinner.stopSpinner(); } else { spinner.logWithSpinner('', stdout) spinner.logWithSpinner(chalk.cyan('antd installed complete \n')) spinner.logWithSpinner(' ', ' '); resolve(); } }); }) } execList.push(installAntd); 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, 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); //安装itims4-2ndpage 二级页面模板插件 let install2ndpage = function () { return new Promise(function (resolve, reject) { spinner.logWithSpinner('', chalk.cyan('itims4-2ndpage installing')) var semantic_webpack = 'npm i semantic-ui-css axios immutable redux-immutable itims-help itims4-header dhcc-app-dll react-transition-group'; exec(semantic_webpack, { cwd: execPath }, function (err, stdout, stderr) { if (err) { console.error(chalk.red('itims4-2ndpage 安装失败:' + stderr)) console.log(stdout); spinner.stopSpinner(); } else { spinner.logWithSpinner('', stdout) spinner.logWithSpinner(chalk.cyan('itims4-2ndpage installed complete \n')) spinner.logWithSpinner(' ', ' '); resolve(); } }); }) } execList.push(install2ndpage); //execList = [initPackageJSON] async function queue (arr) { let res = null for (let promise of arr) { res = await promise(res) } return await res } var execPath; var srcPath; var moduleName; module.exports = function (reactAppPath, mmoduleName, projectName, callback) { moduleName = mmoduleName; srcPath = reactAppPath + "/src"; execPath = path.join(reactAppPath, projectName == '.' ? '' : 'src', projectName); if (!fs.existsSync(srcPath)) { chalk.cyan('根目录下创建src目录') fs.mkdirSync(srcPath); } queue(execList) .then(data => { callback && callback.call(); }) }