初始化项目
This commit is contained in:
commit
4ab6cf96c0
38 files changed
+8362
No files matched your search
@@ -0,0 +1,64 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs-extra');
|
||||
//const inquirer = require('inquirer');
|
||||
|
||||
//随机路径名
|
||||
exports.randomActName = () => {
|
||||
let d = new Date();
|
||||
let m = (d.getMonth() + 1) < 10 ? '0' + (d.getMonth() + 1) : (d.getMonth() + 1).toString();
|
||||
let dd = d.getDate() < 10 ? '0' + d.getDate() : d.getDate();
|
||||
let str = d.getFullYear() + m + dd + String.fromCharCode(Math.floor(Math.random() * 26) + "a".charCodeAt(0)) + Math.floor(Math.random() * 10);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
//模板路径名
|
||||
exports.tplTypePath = (type) => {
|
||||
let _path = '';
|
||||
if(type) {
|
||||
_path = path.join('template', type);
|
||||
}else{
|
||||
_path = path.join('template', 'react');
|
||||
}
|
||||
return _path;
|
||||
}
|
||||
|
||||
|
||||
//初始化后的路径信息
|
||||
exports.paths = (pathName, rootPath) => {
|
||||
return {
|
||||
pathName:pathName,
|
||||
rootPath:rootPath,
|
||||
targetPath:path.join(rootPath, 'src', 'pages' , pathName)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
//获取项目config
|
||||
exports.configJson = (targetPath) => {
|
||||
let jsonPath = path.join(targetPath, 'config.json');
|
||||
|
||||
return require(jsonPath);
|
||||
}
|
||||
|
||||
//是否存在该目录
|
||||
exports.pathExists = async (pathName, rootPath) => {
|
||||
let targetPath = path.join(rootPath, 'src', 'pages' , pathName);
|
||||
let exists = await fs.pathExists(targetPath);
|
||||
return exists;
|
||||
// if(exists) {
|
||||
// return true;
|
||||
// }else{
|
||||
// return '没有该目录,请重新输入'
|
||||
// }
|
||||
}
|
||||
|
||||
//会话流
|
||||
// exports.inquirer = (option, promps, cb) => {
|
||||
// inquirer.prompt(promps).then(function (answers) {
|
||||
// //console.log('\n',answers)
|
||||
// option = Object.assign(answers,option);
|
||||
|
||||
// if(cb) cb(option);
|
||||
// });
|
||||
// }
|
||||
Reference in new issue
Block a user