flutter-pro-cli
Version:
flutter project cli
37 lines (33 loc) • 721 B
JavaScript
const fs = require('fs');
const binPath = `${__dirname}/../`;
const currentPath = process.cwd();
/**
* @desc 获取项目名
*
*/
function getProjectName() {
let yamlConfig = fs.readFileSync(`${currentPath}/pubspec.yaml`, {encoding: 'utf8'});
let pos = yamlConfig.indexOf('name:');
if(pos < 0) {
return false;
}
let subYamlConfig = yamlConfig.substr(pos+5);
pos = subYamlConfig.indexOf("\n");
if(pos < 0){
return false;
}
return subYamlConfig.substr(0, pos).trim();
}
/**
* @desc 创建文件夹
*
*/
function createDir(dirPath) {
if(!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath);
}
}
module.exports = {
getProjectName,
createDir
}