From 324dfddb2709c66d61e078e6b728253e03f0cf33 Mon Sep 17 00:00:00 2001 From: Xc Date: Sat, 12 Apr 2025 14:37:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86rename=E5=91=BD?= =?UTF-8?q?=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/build.js | 2 +- lib/clean.js | 2 +- lib/create.js | 7 ++--- lib/createConfig.js | 3 ++- lib/file-handle.d.ts | 2 ++ lib/file-handle.js | 21 +++++++-------- lib/index.js | 9 +++++++ lib/makeDependency.js | 2 +- lib/makeDomain.js | 2 +- lib/makeLocale.js | 2 +- lib/makeRouter.js | 2 +- lib/rename.js | 40 ++++++++++++++++++++--------- lib/run.js | 2 +- lib/server/initialize.d.ts | 1 + lib/server/initialize.js | 3 ++- lib/server/start.d.ts | 1 + lib/server/start.js | 5 ++-- lib/server/watch.d.ts | 1 + lib/template.js | 23 +++++++++-------- lib/utils.js | 15 ++++++----- src/index.ts | 9 +++++++ src/rename.ts | 39 ++++++++++++++++++++-------- templateFiles/initializeFeatures.ts | 2 +- 23 files changed, 129 insertions(+), 66 deletions(-) diff --git a/lib/build.js b/lib/build.js index 3bc5fa6..a32a364 100644 --- a/lib/build.js +++ b/lib/build.js @@ -1,6 +1,5 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = build; const tslib_1 = require("tslib"); const tip_style_1 = require("./tip-style"); const cross_spawn_1 = tslib_1.__importDefault(require("cross-spawn")); @@ -154,3 +153,4 @@ async function build(cmd) { (0, tip_style_1.Error)(`${(0, tip_style_1.error)(`target could only be web or mp(wechatMp) or rn(native)`)}`); } } +exports.default = build; diff --git a/lib/clean.js b/lib/clean.js index 5e0e07f..b6b057e 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -1,6 +1,5 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = run; const tslib_1 = require("tslib"); const tip_style_1 = require("./tip-style"); const cross_spawn_1 = tslib_1.__importDefault(require("cross-spawn")); @@ -49,3 +48,4 @@ async function run(options) { process.exit(-1); } } +exports.default = run; diff --git a/lib/create.js b/lib/create.js index b30d4c1..71ea8dd 100644 --- a/lib/create.js +++ b/lib/create.js @@ -1,7 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.create = create; -exports.update = update; +exports.update = exports.create = void 0; const tslib_1 = require("tslib"); const ts = tslib_1.__importStar(require("typescript")); const fs_1 = require("fs"); @@ -243,7 +242,7 @@ async function create(dirName, cmd) { } // 获取package.json内容 const packageJson = (0, template_1.packageJsonContent)({ - name: DEFAULT_PROJECT_NAME, // 后面再统一rename + name: DEFAULT_PROJECT_NAME, version, description, cliName: config_1.CLI_NAME, @@ -266,6 +265,7 @@ async function create(dirName, cmd) { (0, tip_style_1.Error)((0, tip_style_1.error)(err)); } } +exports.create = create; async function update(dirName, subDirName, cmd) { const isDev = cmd.dev ? true : false; try { @@ -292,3 +292,4 @@ async function update(dirName, subDirName, cmd) { console.error((0, tip_style_1.error)(err.message)); } } +exports.update = update; diff --git a/lib/createConfig.js b/lib/createConfig.js index 4c8e467..71233f6 100644 --- a/lib/createConfig.js +++ b/lib/createConfig.js @@ -1,6 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.CreateCompilerConfig = CreateCompilerConfig; +exports.CreateCompilerConfig = void 0; /** * 创建一个oak编译器配置 * @param raw 原始配置 @@ -11,6 +11,7 @@ function CreateCompilerConfig(raw) { // 在这里可以做配置的预处理 return raw; } +exports.CreateCompilerConfig = CreateCompilerConfig; /** * 将compiler.js中的模块导出使用以下形式: * module.exports = CreateComilerConfig({}) diff --git a/lib/file-handle.d.ts b/lib/file-handle.d.ts index 8c3c1bf..906763d 100644 --- a/lib/file-handle.d.ts +++ b/lib/file-handle.d.ts @@ -1,3 +1,5 @@ +/// +/// import { PathLike } from 'fs'; import { checkFileExistsAndCreateType } from './enum'; /** diff --git a/lib/file-handle.js b/lib/file-handle.js index 3e5b805..14f0c2f 100644 --- a/lib/file-handle.js +++ b/lib/file-handle.js @@ -1,15 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.readDirPath = readDirPath; -exports.readDirGetFile = readDirGetFile; -exports.parseJsonFiles = parseJsonFiles; -exports.parseJsonFile = parseJsonFile; -exports.deleteFolderRecursive = deleteFolderRecursive; -exports.writeFile = writeFile; -exports.readFile = readFile; -exports.copyFolder = copyFolder; -exports.checkFileExists = checkFileExists; -exports.checkFileExistsAndCreate = checkFileExistsAndCreate; +exports.checkFileExistsAndCreate = exports.checkFileExists = exports.copyFolder = exports.readFile = exports.writeFile = exports.deleteFolderRecursive = exports.parseJsonFile = exports.parseJsonFiles = exports.readDirGetFile = exports.readDirPath = void 0; const fs_1 = require("fs"); const path_1 = require("path"); const enum_1 = require("./enum"); @@ -34,6 +25,7 @@ function readDirPath(entry) { } return pathList; } +exports.readDirPath = readDirPath; /** * @name 读取指定目录的文件(不进行深度遍历,只获取根目录) * @export @@ -44,6 +36,7 @@ function readDirGetFile(entry) { const dirInfo = (0, fs_1.readdirSync)(entry); return dirInfo; } +exports.readDirGetFile = readDirGetFile; /** * @name 解析json文件(数组) * @export @@ -58,6 +51,7 @@ function parseJsonFiles(arr) { } return result; } +exports.parseJsonFiles = parseJsonFiles; /** * @name 解析单个文件json * @export @@ -73,6 +67,7 @@ function parseJsonFile(file) { return; } } +exports.parseJsonFile = parseJsonFile; /** * @name 删除文件夹 * @export @@ -102,6 +97,7 @@ function deleteFolderRecursive(entry) { // console.log("文件夹不存在"); } } +exports.deleteFolderRecursive = deleteFolderRecursive; ; function writeFile(path, data) { try { @@ -112,6 +108,7 @@ function writeFile(path, data) { (0, tip_style_1.Error)((0, tip_style_1.error)('文件写入失败')); } } +exports.writeFile = writeFile; function readFile(path, options) { try { const data = (0, fs_1.readFileSync)(path, options); @@ -122,6 +119,7 @@ function readFile(path, options) { (0, tip_style_1.Error)((0, tip_style_1.error)('文件读取失败')); } } +exports.readFile = readFile; /** * @name 拷贝文件夹 * @export @@ -183,6 +181,7 @@ function copyFolder(currentDir, targetDir, overwrite = false) { throw new global.Error(`需要copy的文件夹不存在: ${currentDir}`); } } +exports.copyFolder = copyFolder; /** * @name 检测文件/文件夹是否存在 * @export @@ -192,6 +191,7 @@ function copyFolder(currentDir, targetDir, overwrite = false) { function checkFileExists(path) { return (0, fs_1.existsSync)(path); } +exports.checkFileExists = checkFileExists; /** * @name 检测文件/文件夹是否存在,不存在则创建 * @export @@ -217,3 +217,4 @@ function checkFileExistsAndCreate(path, data, type = enum_1.checkFileExistsAndCr throw new global.Error(`${path} already exists!`); } } +exports.checkFileExistsAndCreate = checkFileExistsAndCreate; diff --git a/lib/index.js b/lib/index.js index a65420f..95aa26d 100755 --- a/lib/index.js +++ b/lib/index.js @@ -12,6 +12,7 @@ const run_1 = tslib_1.__importDefault(require("./run")); const clean_1 = tslib_1.__importDefault(require("./clean")); const config_1 = require("./config"); const tip_style_1 = require("./tip-style"); +const rename_1 = require("./rename"); /** * @name 未知参数错误提示 * @param {string} methodName @@ -91,6 +92,14 @@ commander_1.default .option('-m, --module', 'module') .description(`create a new project powered by ${config_1.CLI_NAME}`) .action(create_1.create); +commander_1.default + .rename('rename') + .option('-on --old-name', 'oldName') + .option('-nn --new-name', 'newName') + .option('-ot --old-title', 'oldTitle') + .option('-nt --new-title', 'newTitle') + .description('rename an existed project') + .action(rename_1.rename); commander_1.default .command('update [subDirName]') .usage('') diff --git a/lib/makeDependency.js b/lib/makeDependency.js index 0c0d27d..07f6a2e 100644 --- a/lib/makeDependency.js +++ b/lib/makeDependency.js @@ -1,6 +1,5 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = make; const tslib_1 = require("tslib"); const tip_style_1 = require("./tip-style"); const cross_spawn_1 = tslib_1.__importDefault(require("cross-spawn")); @@ -21,3 +20,4 @@ async function make(cmd) { process.exit(-1); } } +exports.default = make; diff --git a/lib/makeDomain.js b/lib/makeDomain.js index eb140b2..c5c89e4 100644 --- a/lib/makeDomain.js +++ b/lib/makeDomain.js @@ -1,6 +1,5 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = make; const tslib_1 = require("tslib"); const tip_style_1 = require("./tip-style"); const cross_spawn_1 = tslib_1.__importDefault(require("cross-spawn")); @@ -21,3 +20,4 @@ async function make() { process.exit(-1); } } +exports.default = make; diff --git a/lib/makeLocale.js b/lib/makeLocale.js index f27f7fa..7da9a71 100644 --- a/lib/makeLocale.js +++ b/lib/makeLocale.js @@ -1,6 +1,5 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = make; const tslib_1 = require("tslib"); const tip_style_1 = require("./tip-style"); const localeBuilder_1 = tslib_1.__importDefault(require("oak-domain/lib/compiler/localeBuilder")); @@ -19,3 +18,4 @@ async function make(cmd) { process.exit(-1); } } +exports.default = make; diff --git a/lib/makeRouter.js b/lib/makeRouter.js index d3a5196..61eda2b 100644 --- a/lib/makeRouter.js +++ b/lib/makeRouter.js @@ -1,6 +1,5 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = make; const tslib_1 = require("tslib"); const tip_style_1 = require("./tip-style"); const cross_spawn_1 = tslib_1.__importDefault(require("cross-spawn")); @@ -31,3 +30,4 @@ async function make(cmd, watch) { process.exit(-1); } } +exports.default = make; diff --git a/lib/rename.js b/lib/rename.js index 395233a..68ec97c 100644 --- a/lib/rename.js +++ b/lib/rename.js @@ -1,11 +1,11 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.renameProject = renameProject; -exports.rename = rename; +exports.rename = exports.renameProject = void 0; const path_1 = require("path"); const fs_1 = require("fs"); const editTemplate_1 = require("@react-native-community/cli/build/commands/init/editTemplate"); const tip_style_1 = require("./tip-style"); +const process_1 = require("process"); async function renameProject(dir, name, title, placeholderName, placeholderTitle) { // replace package.json中的name const packageJsonFilePath = (0, path_1.join)(dir, 'package.json'); @@ -31,6 +31,12 @@ async function renameProject(dir, name, title, placeholderName, placeholderTitle pcjJson.projectname = title; const newPcjContent = JSON.stringify(pcjJson, undefined, 4); (0, fs_1.writeFileSync)(pcjFilePath, newPcjContent); + // src/locales/common/zh_CN.json中的name + const commonLocalePath = (0, path_1.join)(dir, 'src', 'locales', 'common', 'zh_CN.json'); + const clpJson = require(commonLocalePath); + clpJson.name = title; + const newClpJson = JSON.stringify(clpJson, undefined, 4); + (0, fs_1.writeFileSync)(commonLocalePath, newClpJson); // replace native下的相关数据 const cwd = process.cwd(); process.chdir((0, path_1.join)(dir, 'native')); @@ -43,15 +49,25 @@ async function renameProject(dir, name, title, placeholderName, placeholderTitle process.chdir(cwd); (0, tip_style_1.Success)(`${(0, tip_style_1.success)(`Change project name to ${(0, tip_style_1.primary)(name)}, project title to ${(0, tip_style_1.primary)(title)}`)}`); } +exports.renameProject = renameProject; async function rename(cmd) { - const { projectName, displayName } = cmd; - // todo 取native/android下的name和title作为placeholder,再调用renameProject + const { oldName, newName, oldTitle, newTitle } = cmd; + if (!oldName) { + (0, tip_style_1.Error)((0, tip_style_1.error)('oldName must not be empty')); + (0, process_1.exit)(-1); + } + if (!newName) { + (0, tip_style_1.Error)((0, tip_style_1.error)('newName must not be empty')); + (0, process_1.exit)(-1); + } + if (!oldTitle) { + (0, tip_style_1.Error)((0, tip_style_1.error)('oldTitle must not be empty')); + (0, process_1.exit)(-1); + } + if (!newTitle) { + (0, tip_style_1.Error)((0, tip_style_1.error)('newTitle must not be empty')); + (0, process_1.exit)(-1); + } + renameProject(process.cwd(), newName, newTitle, oldName, oldTitle); } -/* changePlaceholderInTemplate({ - projectName: 'taicang', - projectTitle: '太藏', - placeholderName: 'oak-template', - placeholderTitle: 'oak template project', -}).then( - () => console.log('success') -); */ +exports.rename = rename; diff --git a/lib/run.js b/lib/run.js index bfb8be2..4d431e1 100644 --- a/lib/run.js +++ b/lib/run.js @@ -1,6 +1,5 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = run; const tslib_1 = require("tslib"); const tip_style_1 = require("./tip-style"); const cross_spawn_1 = tslib_1.__importDefault(require("cross-spawn")); @@ -60,3 +59,4 @@ async function run(options) { process.exit(-1); } } +exports.default = run; diff --git a/lib/server/initialize.d.ts b/lib/server/initialize.d.ts index b13884d..964ab37 100644 --- a/lib/server/initialize.d.ts +++ b/lib/server/initialize.d.ts @@ -1,3 +1,4 @@ +/// import { EntityDict } from 'oak-domain/lib/types'; import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain'; import { BackendRuntimeContext } from 'oak-frontend-base/lib/context/BackendRuntimeContext'; diff --git a/lib/server/initialize.js b/lib/server/initialize.js index acdfa85..90f692b 100644 --- a/lib/server/initialize.js +++ b/lib/server/initialize.js @@ -1,6 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.initialize = initialize; +exports.initialize = void 0; /// const oak_backend_base_1 = require("oak-backend-base"); async function initialize(path) { @@ -10,3 +10,4 @@ async function initialize(path) { await appLoader.unmount(); console.log('data initialized'); } +exports.initialize = initialize; diff --git a/lib/server/start.d.ts b/lib/server/start.d.ts index 2e45380..4507fbd 100644 --- a/lib/server/start.d.ts +++ b/lib/server/start.d.ts @@ -1,3 +1,4 @@ +/// import './polyfill'; import { BackendRuntimeContext } from 'oak-frontend-base/lib/context/BackendRuntimeContext'; import { Connector, EntityDict } from 'oak-domain/lib/types'; diff --git a/lib/server/start.js b/lib/server/start.js index 183c1e0..98f06f1 100644 --- a/lib/server/start.js +++ b/lib/server/start.js @@ -1,6 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.startup = startup; +exports.startup = void 0; const tslib_1 = require("tslib"); /// require("./polyfill"); @@ -55,7 +55,7 @@ async function startup(path, connector, omitWatchers, omitTimers, routine) { } : serverConfiguration.cors ? { - origin: serverConfiguration.cors.origin, //socket.io配置cors origin是支持数组和字符串 + origin: serverConfiguration.cors.origin, allowedHeaders: [ ...corsHeaders.concat(connector.getCorsHeader()), ...(serverConfiguration.cors.headers || []), @@ -302,3 +302,4 @@ async function startup(path, connector, omitWatchers, omitTimers, routine) { }; return shutdown; } +exports.startup = startup; diff --git a/lib/server/watch.d.ts b/lib/server/watch.d.ts index 122b4de..45b0b46 100644 --- a/lib/server/watch.d.ts +++ b/lib/server/watch.d.ts @@ -1,3 +1,4 @@ +/// export type LogFormatterProp = { level: "info" | "warn" | "error"; caller: NodeJS.CallSite | null; diff --git a/lib/template.js b/lib/template.js index 5faa203..c187434 100644 --- a/lib/template.js +++ b/lib/template.js @@ -1,16 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.packageJsonContent = packageJsonContent; -exports.tsConfigJsonContent = tsConfigJsonContent; -exports.tsConfigBuildJsonContent = tsConfigBuildJsonContent; -exports.tsConfigPathsJsonContent = tsConfigPathsJsonContent; -exports.tsConfigMpJsonContent = tsConfigMpJsonContent; -exports.tsConfigWebJsonContent = tsConfigWebJsonContent; -exports.projectConfigContentWithWeChatMp = projectConfigContentWithWeChatMp; -exports.appJsonContentWithWeChatMp = appJsonContentWithWeChatMp; -exports.oakConfigContentWithWeChatMp = oakConfigContentWithWeChatMp; -exports.oakConfigContentWithWeb = oakConfigContentWithWeb; -exports.updateCompilerJsContent = updateCompilerJsContent; +exports.updateCompilerJsContent = exports.oakConfigContentWithWeb = exports.oakConfigContentWithWeChatMp = exports.appJsonContentWithWeChatMp = exports.projectConfigContentWithWeChatMp = exports.tsConfigWebJsonContent = exports.tsConfigMpJsonContent = exports.tsConfigPathsJsonContent = exports.tsConfigBuildJsonContent = exports.tsConfigJsonContent = exports.packageJsonContent = void 0; const tslib_1 = require("tslib"); const child_process_1 = require("child_process"); const fs_1 = require("fs"); @@ -309,6 +299,7 @@ function packageJsonContent({ name, version, description, cliName, cliBinName, i } `; } +exports.packageJsonContent = packageJsonContent; function tsConfigJsonContent() { return `{ "extends": "./tsconfig.paths.json", @@ -360,6 +351,7 @@ function tsConfigJsonContent() { ] }`; } +exports.tsConfigJsonContent = tsConfigJsonContent; function tsConfigBuildJsonContent() { return `{ "extends": "./tsconfig.build.paths.json", @@ -399,6 +391,7 @@ function tsConfigBuildJsonContent() { ] }`; } +exports.tsConfigBuildJsonContent = tsConfigBuildJsonContent; function tsConfigPathsJsonContent(deps) { const paths = { "@project/*": [ @@ -427,6 +420,7 @@ function tsConfigPathsJsonContent(deps) { } }, null, '\t'); } +exports.tsConfigPathsJsonContent = tsConfigPathsJsonContent; function tsConfigMpJsonContent() { return `{ "extends": "./tsconfig.paths.json", @@ -474,6 +468,7 @@ function tsConfigMpJsonContent() { ] }`; } +exports.tsConfigMpJsonContent = tsConfigMpJsonContent; function tsConfigWebJsonContent() { return `{ "extends": "./tsconfig.paths.json", @@ -523,6 +518,7 @@ function tsConfigWebJsonContent() { ] }`; } +exports.tsConfigWebJsonContent = tsConfigWebJsonContent; function projectConfigContentWithWeChatMp(oakConfigName, projectname, miniVersion) { return `{ "description": "项目配置文件", @@ -598,6 +594,7 @@ function projectConfigContentWithWeChatMp(oakConfigName, projectname, miniVersio } }`; } +exports.projectConfigContentWithWeChatMp = projectConfigContentWithWeChatMp; function appJsonContentWithWeChatMp(isDev) { const pages = [ '@project/pages/store/list/index', @@ -621,18 +618,21 @@ function appJsonContentWithWeChatMp(isDev) { "sitemapLocation": "sitemap.json" }`; } +exports.appJsonContentWithWeChatMp = appJsonContentWithWeChatMp; function oakConfigContentWithWeChatMp() { return `{ "theme": { } }`; } +exports.oakConfigContentWithWeChatMp = oakConfigContentWithWeChatMp; function oakConfigContentWithWeb() { return `{ "theme": { } }`; } +exports.oakConfigContentWithWeb = oakConfigContentWithWeb; function updateCompilerJsContent(directory, deps) { const compilerJsPath = (0, path_1.join)(directory, 'configuration', 'compiler.js'); (0, assert_1.default)((0, fs_1.existsSync)(compilerJsPath)); @@ -691,3 +691,4 @@ function updateCompilerJsContent(directory, deps) { (0, fs_1.writeFileSync)(compilerJsPath, code); } } +exports.updateCompilerJsContent = updateCompilerJsContent; diff --git a/lib/utils.js b/lib/utils.js index 857ccdb..19c6772 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,12 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.findJson = findJson; -exports.getStr = getStr; -exports.difference = difference; -exports.intersect = intersect; -exports.union = union; -exports.formatJsonByFile = formatJsonByFile; -exports.deWeight = deWeight; +exports.deWeight = exports.formatJsonByFile = exports.union = exports.intersect = exports.difference = exports.getStr = exports.findJson = void 0; /** * @name 从一组路径里查找到所有json文件 * @export @@ -24,6 +18,7 @@ function findJson(pathArr) { } return result; } +exports.findJson = findJson; /** * @name 已知前后文取中间文本 * @export @@ -37,6 +32,7 @@ function getStr(str, start, end) { let res = str.match(reg); return res ? res[1] : null; } +exports.getStr = getStr; /** * @name 差集 * @export @@ -48,6 +44,7 @@ function getStr(str, start, end) { function difference(current, target) { return new Set([...target].filter(x => !current.has(x))); } +exports.difference = difference; /** * @name 获取交集 * @export @@ -59,6 +56,7 @@ function difference(current, target) { function intersect(current, target) { return new Set([...target].filter(x => current.has(x))); } +exports.intersect = intersect; /** * @name 获取并集 * @export @@ -70,6 +68,7 @@ function intersect(current, target) { function union(current, target) { return new Set([...current, ...target]); } +exports.union = union; /** * @name 格式化json * @export @@ -80,6 +79,7 @@ function union(current, target) { function formatJsonByFile(data) { return JSON.stringify(data, null, 2); } +exports.formatJsonByFile = formatJsonByFile; /** * @name 数组对象去重 * @export @@ -96,3 +96,4 @@ function deWeight(arr, type) { } return new Set([...map.values()]); } +exports.deWeight = deWeight; diff --git a/src/index.ts b/src/index.ts index 42effca..088ef39 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,6 +9,7 @@ import run from './run'; import clean from './clean'; import { CLI_VERSION, CLI_NAME } from './config'; import { error, warn } from './tip-style'; +import { rename } from './rename'; /** * @name 未知参数错误提示 @@ -100,6 +101,14 @@ program .option('-m, --module', 'module') .description(`create a new project powered by ${CLI_NAME}`) .action(create); +program + .rename('rename') + .option('-on --old-name', 'oldName') + .option('-nn --new-name', 'newName') + .option('-ot --old-title', 'oldTitle') + .option('-nt --new-title', 'newTitle') + .description('rename an existed project') + .action(rename); program .command('update [subDirName]') .usage('') diff --git a/src/rename.ts b/src/rename.ts index 54ae08a..1f2d04f 100644 --- a/src/rename.ts +++ b/src/rename.ts @@ -10,6 +10,7 @@ import { warn, Warn, } from './tip-style'; +import { exit } from 'process'; export async function renameProject(dir: string, name: string, title: string, placeholderName: string, placeholderTitle: string) { // replace package.json中的name @@ -40,6 +41,13 @@ export async function renameProject(dir: string, name: string, title: string, pl const newPcjContent = JSON.stringify(pcjJson, undefined, 4); writeFileSync(pcjFilePath, newPcjContent); + // src/locales/common/zh_CN.json中的name + const commonLocalePath = join(dir, 'src', 'locales', 'common', 'zh_CN.json'); + const clpJson = require(commonLocalePath); + clpJson.name = title; + const newClpJson = JSON.stringify(clpJson, undefined, 4); + writeFileSync(commonLocalePath, newClpJson); + // replace native下的相关数据 const cwd = process.cwd(); process.chdir(join(dir, 'native')); @@ -61,15 +69,24 @@ export async function renameProject(dir: string, name: string, title: string, pl } export async function rename(cmd: any) { - const { projectName, displayName } = cmd; - // todo 取native/android下的name和title作为placeholder,再调用renameProject -} + const { oldName, newName, oldTitle, newTitle } = cmd; -/* changePlaceholderInTemplate({ - projectName: 'taicang', - projectTitle: '太藏', - placeholderName: 'oak-template', - placeholderTitle: 'oak template project', -}).then( - () => console.log('success') -); */ \ No newline at end of file + if (!oldName) { + Error(error('oldName must not be empty')); + exit(-1); + } + if (!newName) { + Error(error('newName must not be empty')); + exit(-1); + } + if (!oldTitle) { + Error(error('oldTitle must not be empty')); + exit(-1); + } + if (!newTitle) { + Error(error('newTitle must not be empty')); + exit(-1); + } + + renameProject(process.cwd(), newName, newTitle, oldName, oldTitle); +} \ No newline at end of file diff --git a/templateFiles/initializeFeatures.ts b/templateFiles/initializeFeatures.ts index 0ccc8dc..0f3d692 100644 --- a/templateFiles/initializeFeatures.ts +++ b/templateFiles/initializeFeatures.ts @@ -12,5 +12,5 @@ import { EntityDict } from '@project/oak-app-domain'; */ export default async function initialize(features: FeatureDict & BasicFeatures) { // await initializeOgb0Features(features, accessConfiguration, undefined, [Qiniu]); - // features.locales.loadServerData(['projectName-l-common', 'projectName-l-error', 'projectName-l-menu]); + // features.locales.loadServerData(['projectName-l-common', 'projectName-l-error', 'projectName-l-menu']); } \ No newline at end of file