Files
wdp/task/util.js
T
2018-11-12 17:48:13 +08:00

64 lines
1.6 KiB
JavaScript

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);
// });
// }