65 lines
2.2 KiB
JavaScript
65 lines
2.2 KiB
JavaScript
"use strict";
|
||
/**
|
||
* @author linhuiw
|
||
* @desc 初始化 kiwi 项目的文件以及配置
|
||
*/
|
||
Object.defineProperty(exports, "__esModule", { value: true });
|
||
exports.initProject = void 0;
|
||
const path = require("path");
|
||
const fs = require("fs");
|
||
const const_1 = require("./const");
|
||
/**
|
||
* 创建配置文件
|
||
* @param existDir 配置文件夹地址
|
||
* @returns
|
||
*/
|
||
function createConfigFile(existDir) {
|
||
// 在根目录创建配置文件
|
||
const configDir = path.resolve(process.cwd(), `./${const_1.CANARY_CONFIG_FILE}`);
|
||
// 如果已经有配置文件就不要动了
|
||
if (fs.existsSync(configDir))
|
||
return;
|
||
const config = Object.assign({}, const_1.PROJECT_CONFIG.defaultConfig);
|
||
// 有配置文件夹
|
||
if (existDir && fs.existsSync(existDir)) {
|
||
config.canaryDir = existDir;
|
||
}
|
||
// 创建新的配置文件
|
||
fs.writeFile(configDir, JSON.stringify(config, null, 2), err => err && console.log(err));
|
||
}
|
||
/**
|
||
* 创建中文配置示例文件
|
||
*/
|
||
function createCnFile() {
|
||
// 中文配置文件夹地址
|
||
const cnDir = `${const_1.PROJECT_CONFIG.dir}/zh-CN`;
|
||
// 没有则创建
|
||
if (!fs.existsSync(cnDir)) {
|
||
fs.mkdirSync(cnDir);
|
||
fs.writeFile(`${cnDir}/index.ts`, const_1.PROJECT_CONFIG.zhIndexFile, err => err && console.log(err));
|
||
fs.writeFile(`${cnDir}/common.ts`, const_1.PROJECT_CONFIG.zhTestFile, err => err && console.log(err));
|
||
}
|
||
}
|
||
/**
|
||
* 初始化国际化项目
|
||
* @param existDir 配置文件夹地址
|
||
*/
|
||
function initProject(existDir) {
|
||
// 有用户输入的文件夹,不存在默认位置创建
|
||
if (existDir && !fs.existsSync(existDir)) {
|
||
console.log('\n输入的目录不存在,已为你生成默认文件夹');
|
||
fs.mkdirSync(const_1.PROJECT_CONFIG.dir);
|
||
}
|
||
// 没有输入,默认位置创建
|
||
else if (!existDir && !fs.existsSync(const_1.PROJECT_CONFIG.dir)) {
|
||
fs.mkdirSync(const_1.PROJECT_CONFIG.dir);
|
||
}
|
||
// 创建配置文件
|
||
createConfigFile(existDir);
|
||
// 没有已经存在的配置文件夹,创建默认的配置文件示例
|
||
if (!(existDir && fs.existsSync(existDir))) {
|
||
createCnFile();
|
||
}
|
||
}
|
||
exports.initProject = initProject;
|
||
//# sourceMappingURL=init.js.map
|