Files
2019-01-12 21:15:23 +08:00

58 lines
1.3 KiB
JavaScript

const path = require('path');
const fs = require('fs-extra');
const chalk = require('chalk');
//const webpack = require('webpack');
//const webpackDevServer = require('webpack-dev-server');
const util = require('./util');
const webpackConfig = require('./webpack.react');
let _paths = {};
let _configJson = {};
exports.init = (type, paths, command) => {
if(type != 'react') {
console.error(chalk.bold.red('暂不支持该类型模板!'));
return;
}
_paths = paths;
let tplPath = path.join(_paths.rootPath, util.tplTypePath(type));
fs.copy(tplPath, _paths.targetPath)
.then(() => {
console.log(chalk.bold.green('生成模板成功!'));
_configJson = util.configJson(_paths.targetPath);
if(_configJson.template == 'react') {
webpackConfig.run(paths, command);
}
})
.catch(err => {
console.error(err);
console.error(chalk.bold.red('生成模板失败!'));
});
}
exports.dev = (paths, command) => {
_paths = paths;
_configJson = util.configJson(_paths.targetPath);
if(_configJson.template == 'react') {
webpackConfig.run(paths, command);
}
}
exports.pack = (paths, command) => {
_paths = paths;
_configJson = util.configJson(_paths.targetPath);
if(_configJson.template == 'react') {
webpackConfig.run(paths, command);
}
}