@pubinfo/cli 2.1.3 → 2.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{build-CBpkrIHc.js → build-TpYdEV_-.js} +2 -2
- package/dist/{dev-C17amTjs.js → dev-DVlLrfjX.js} +2 -2
- package/dist/generate-9OAGGbjc.js +63 -0
- package/dist/generate-MJ0AbXtK.js +33 -0
- package/dist/{icon-Dp4dXbYT.js → icon-B2EyVw8p.js} +1 -1
- package/dist/index.js +10 -8
- package/dist/monorepo-BY87UC9C.js +265 -0
- package/dist/{preview-CL5eJUy5.js → preview-BVVgNnhp.js} +1 -1
- package/dist/setup-CACbESTE.js +3 -0
- package/package.json +6 -5
- package/dist/setup-tGwcxPxN.js +0 -3
- /package/dist/{commit-BsodnARP.js → commit-r-63XXfJ.js} +0 -0
- /package/dist/{index.d.ts → index-Dp-QJh5Z.d.ts} +0 -0
- /package/dist/{setup-DTOe0VmW.js → setup-BdawX0W3.js} +0 -0
- /package/dist/{upgrade-R63l7RcU.js → upgrade-B-Zl5nkj.js} +0 -0
- /package/dist/{vite-BeiYc40N.js → vite-bwhDbW7x.js} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as runVite } from "./vite-
|
|
2
|
-
import { t as setup_default } from "./setup-
|
|
1
|
+
import { t as runVite } from "./vite-bwhDbW7x.js";
|
|
2
|
+
import { t as setup_default } from "./setup-BdawX0W3.js";
|
|
3
3
|
import { defineCommand, runMain } from "citty";
|
|
4
4
|
|
|
5
5
|
//#region src/commands/build.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as runVite } from "./vite-
|
|
2
|
-
import { t as setup_default } from "./setup-
|
|
1
|
+
import { t as runVite } from "./vite-bwhDbW7x.js";
|
|
2
|
+
import { t as setup_default } from "./setup-BdawX0W3.js";
|
|
3
3
|
import { defineCommand, runMain } from "citty";
|
|
4
4
|
|
|
5
5
|
//#region src/commands/dev.ts
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { n as ensureValidIdentifier, r as resolvePubinfoVersionFromApps, t as ensureMonorepoAppsDir } from "./generate-MJ0AbXtK.js";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { defineCommand } from "citty";
|
|
4
|
+
import { resolve } from "node:path";
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
import { logger } from "@pubinfo/shared";
|
|
7
|
+
import { generate } from "create-pubinfo";
|
|
8
|
+
|
|
9
|
+
//#region src/commands/generate.ts
|
|
10
|
+
const require = createRequire(import.meta.url);
|
|
11
|
+
const createPubinfoPkgPath = require.resolve("create-pubinfo/package.json");
|
|
12
|
+
const createPubinfoPkg = require("create-pubinfo/package.json");
|
|
13
|
+
const monorepoAppTemplatePath = resolve(resolve(createPubinfoPkgPath, ".."), "templates/pubinfo-monorepo/apps/basic");
|
|
14
|
+
const fallbackVersion = createPubinfoPkg.version;
|
|
15
|
+
var generate_default = defineCommand({
|
|
16
|
+
meta: {
|
|
17
|
+
name: "generate",
|
|
18
|
+
description: "在 monorepo apps 目录下创建新的 pubinfo 应用"
|
|
19
|
+
},
|
|
20
|
+
args: {
|
|
21
|
+
name: {
|
|
22
|
+
type: "positional",
|
|
23
|
+
required: true,
|
|
24
|
+
description: "应用目录名称,例如 admin"
|
|
25
|
+
},
|
|
26
|
+
key: {
|
|
27
|
+
type: "string",
|
|
28
|
+
description: "应用标识,默认与目录名称一致"
|
|
29
|
+
},
|
|
30
|
+
rbac: {
|
|
31
|
+
type: "boolean",
|
|
32
|
+
default: true,
|
|
33
|
+
description: "是否包含 RBAC 模块"
|
|
34
|
+
},
|
|
35
|
+
openapi: {
|
|
36
|
+
type: "boolean",
|
|
37
|
+
default: false,
|
|
38
|
+
description: "是否启用 openapi 自动生成"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
async run({ args }) {
|
|
42
|
+
const appsDir = ensureMonorepoAppsDir(resolve("."));
|
|
43
|
+
const appName = args.name;
|
|
44
|
+
ensureValidIdentifier(appName, "应用名称");
|
|
45
|
+
const targetDir = resolve(appsDir, appName);
|
|
46
|
+
if (existsSync(targetDir)) throw new Error(`应用 ${appName} 已存在,请选择其他名称`);
|
|
47
|
+
const key = args.key ?? appName;
|
|
48
|
+
ensureValidIdentifier(key, "应用标识");
|
|
49
|
+
await generate({
|
|
50
|
+
templateName: "pubinfo-monorepo",
|
|
51
|
+
templatePath: monorepoAppTemplatePath,
|
|
52
|
+
targetDir,
|
|
53
|
+
key,
|
|
54
|
+
version: await resolvePubinfoVersionFromApps(appsDir) || fallbackVersion,
|
|
55
|
+
modules: args.rbac === false ? [] : ["rbac"],
|
|
56
|
+
openapi: Boolean(args.openapi)
|
|
57
|
+
});
|
|
58
|
+
logger.success(`应用 ${appName} 创建完成,位于 apps/${appName}`);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
export { generate_default as default };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import { globby } from "globby";
|
|
5
|
+
|
|
6
|
+
//#region src/utils/generate.ts
|
|
7
|
+
const INVALID_NAME_RE = /[<>:"/\\|?*\s]/;
|
|
8
|
+
function ensureValidIdentifier(value, label) {
|
|
9
|
+
if (!value) throw new Error(`${label} 不能为空`);
|
|
10
|
+
if (INVALID_NAME_RE.test(value)) throw new Error(`${label} 不能包含空格或特殊字符 (<>:"/\\|?*)`);
|
|
11
|
+
}
|
|
12
|
+
function ensureMonorepoAppsDir(root) {
|
|
13
|
+
const appsDir = resolve(root, "apps");
|
|
14
|
+
if (!existsSync(appsDir)) throw new Error("未检测到 apps 目录,请在 pubinfo monorepo 根目录执行该命令");
|
|
15
|
+
if (!existsSync(resolve(root, "pnpm-workspace.yaml"))) throw new Error("未找到 pnpm-workspace.yaml,当前目录不是 pubinfo monorepo 工程");
|
|
16
|
+
return appsDir;
|
|
17
|
+
}
|
|
18
|
+
async function resolvePubinfoVersionFromApps(appsDir) {
|
|
19
|
+
const pkgFiles = await globby("**/package.json", {
|
|
20
|
+
cwd: appsDir,
|
|
21
|
+
absolute: true,
|
|
22
|
+
onlyFiles: true
|
|
23
|
+
});
|
|
24
|
+
for (const file of pkgFiles) {
|
|
25
|
+
const content = await readFile(file, "utf8");
|
|
26
|
+
const pkg = JSON.parse(content);
|
|
27
|
+
const version = pkg.dependencies?.pubinfo || pkg.devDependencies?.pubinfo;
|
|
28
|
+
if (version) return version;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
export { ensureValidIdentifier as n, resolvePubinfoVersionFromApps as r, ensureMonorepoAppsDir as t };
|
|
@@ -3,8 +3,8 @@ import fs from "node:fs/promises";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import process from "node:process";
|
|
5
5
|
import { logger } from "@pubinfo/shared";
|
|
6
|
-
import { load } from "cheerio";
|
|
7
6
|
import { globby } from "globby";
|
|
7
|
+
import { load } from "cheerio";
|
|
8
8
|
|
|
9
9
|
//#region src/commands/icon.ts
|
|
10
10
|
function parseNumberLike(v) {
|
package/dist/index.js
CHANGED
|
@@ -3,20 +3,22 @@ import { fileURLToPath } from "node:url";
|
|
|
3
3
|
|
|
4
4
|
//#region package.json
|
|
5
5
|
var name = "@pubinfo/cli";
|
|
6
|
-
var version = "2.1.
|
|
6
|
+
var version = "2.1.4";
|
|
7
7
|
var description = "CLI for Pubinfo";
|
|
8
8
|
|
|
9
9
|
//#endregion
|
|
10
10
|
//#region src/commands/index.ts
|
|
11
11
|
const _rDefault = (r) => r.default || r;
|
|
12
12
|
const commands = {
|
|
13
|
-
dev: () => import("./dev-
|
|
14
|
-
build: () => import("./build-
|
|
15
|
-
preview: () => import("./preview-
|
|
16
|
-
setup: () => import("./setup-
|
|
17
|
-
commit: () => import("./commit-
|
|
18
|
-
icon: () => import("./icon-
|
|
19
|
-
upgrade: () => import("./upgrade-
|
|
13
|
+
dev: () => import("./dev-DVlLrfjX.js").then(_rDefault),
|
|
14
|
+
build: () => import("./build-TpYdEV_-.js").then(_rDefault),
|
|
15
|
+
preview: () => import("./preview-BVVgNnhp.js").then(_rDefault),
|
|
16
|
+
setup: () => import("./setup-CACbESTE.js").then(_rDefault),
|
|
17
|
+
commit: () => import("./commit-r-63XXfJ.js").then(_rDefault),
|
|
18
|
+
icon: () => import("./icon-B2EyVw8p.js").then(_rDefault),
|
|
19
|
+
upgrade: () => import("./upgrade-B-Zl5nkj.js").then(_rDefault),
|
|
20
|
+
generate: () => import("./generate-9OAGGbjc.js").then(_rDefault),
|
|
21
|
+
monorepo: () => import("./monorepo-BY87UC9C.js").then(_rDefault)
|
|
20
22
|
};
|
|
21
23
|
|
|
22
24
|
//#endregion
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { n as ensureValidIdentifier } from "./generate-MJ0AbXtK.js";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { defineCommand } from "citty";
|
|
4
|
+
import { cp, mkdir, mkdtemp, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
5
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
6
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
7
|
+
import { logger } from "@pubinfo/shared";
|
|
8
|
+
import { generate } from "create-pubinfo";
|
|
9
|
+
import { globby } from "globby";
|
|
10
|
+
import { tmpdir } from "node:os";
|
|
11
|
+
|
|
12
|
+
//#region src/utils/monorepo.ts
|
|
13
|
+
const APP_DIRECTORIES = [
|
|
14
|
+
"src",
|
|
15
|
+
"public",
|
|
16
|
+
"mock",
|
|
17
|
+
"mocks",
|
|
18
|
+
"tests",
|
|
19
|
+
"test",
|
|
20
|
+
"e2e"
|
|
21
|
+
];
|
|
22
|
+
const APP_FILES = [
|
|
23
|
+
"index.html",
|
|
24
|
+
"openapi.config.ts",
|
|
25
|
+
"openapi.config.ts.hbs",
|
|
26
|
+
"pubinfo.config.ts",
|
|
27
|
+
"pubinfo.config.js",
|
|
28
|
+
"tsconfig.json",
|
|
29
|
+
"tsconfig.app.json",
|
|
30
|
+
"tsconfig.node.json",
|
|
31
|
+
"uno.config.ts",
|
|
32
|
+
"uno.config.js",
|
|
33
|
+
"vitest.config.ts",
|
|
34
|
+
"vitest.config.js",
|
|
35
|
+
"vitest.setup.ts",
|
|
36
|
+
"vite.config.ts",
|
|
37
|
+
"vite.config.js"
|
|
38
|
+
];
|
|
39
|
+
const TEMPLATE_ROOT_FILES = [
|
|
40
|
+
".browserslistrc",
|
|
41
|
+
".editorconfig",
|
|
42
|
+
".gitignore",
|
|
43
|
+
".npmrc",
|
|
44
|
+
"eslint.config.ts",
|
|
45
|
+
"stylelint.config.js",
|
|
46
|
+
"pnpm-workspace.yaml"
|
|
47
|
+
];
|
|
48
|
+
const ENV_PATTERNS = [".env", ".env.*"];
|
|
49
|
+
function hasDependency(pkg, dep) {
|
|
50
|
+
return Boolean(pkg.dependencies?.[dep] || pkg.devDependencies?.[dep]);
|
|
51
|
+
}
|
|
52
|
+
function formatTimestamp(date) {
|
|
53
|
+
const pad = (value) => value.toString().padStart(2, "0");
|
|
54
|
+
return `${[
|
|
55
|
+
date.getFullYear().toString(),
|
|
56
|
+
pad(date.getMonth() + 1),
|
|
57
|
+
pad(date.getDate())
|
|
58
|
+
].join("")}-${[
|
|
59
|
+
pad(date.getHours()),
|
|
60
|
+
pad(date.getMinutes()),
|
|
61
|
+
pad(date.getSeconds())
|
|
62
|
+
].join("")}`;
|
|
63
|
+
}
|
|
64
|
+
async function backupPath(rootDir, backupDir, target) {
|
|
65
|
+
if (!existsSync(target)) return;
|
|
66
|
+
const dest = resolve(backupDir, relative(rootDir, target));
|
|
67
|
+
await mkdir(dirname(dest), { recursive: true });
|
|
68
|
+
await cp(target, dest, {
|
|
69
|
+
recursive: true,
|
|
70
|
+
force: true
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
async function movePath(rootDir, destinationRoot, backupDir, relativePath) {
|
|
74
|
+
const source = resolve(rootDir, relativePath);
|
|
75
|
+
if (!existsSync(source)) return false;
|
|
76
|
+
const dest = resolve(destinationRoot, relativePath);
|
|
77
|
+
if (existsSync(dest)) throw new Error(`目标路径 ${relative(rootDir, dest)} 已存在,无法覆盖`);
|
|
78
|
+
await backupPath(rootDir, backupDir, source);
|
|
79
|
+
await mkdir(dirname(dest), { recursive: true });
|
|
80
|
+
await rename(source, dest);
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
async function copyTemplateFile(templateRoot, rootDir, backupDir, relativePath) {
|
|
84
|
+
const source = resolve(templateRoot, relativePath);
|
|
85
|
+
if (!existsSync(source)) return;
|
|
86
|
+
const target = resolve(rootDir, relativePath);
|
|
87
|
+
if (existsSync(target)) await backupPath(rootDir, backupDir, target);
|
|
88
|
+
await mkdir(dirname(target), { recursive: true });
|
|
89
|
+
await cp(source, target, {
|
|
90
|
+
recursive: true,
|
|
91
|
+
force: true
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
function deriveDefaultAppName(pkgName) {
|
|
95
|
+
if (!pkgName) return "app";
|
|
96
|
+
let base = pkgName.trim();
|
|
97
|
+
if (base.startsWith("@")) {
|
|
98
|
+
const slashIndex = base.indexOf("/");
|
|
99
|
+
base = slashIndex === -1 ? base.slice(1) : base.slice(slashIndex + 1);
|
|
100
|
+
}
|
|
101
|
+
return base.replace(/\//g, "-").replace(/[^\w-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "") || "app";
|
|
102
|
+
}
|
|
103
|
+
async function extractStorageKey(rootDir) {
|
|
104
|
+
const settingsPath = resolve(rootDir, "src/settings.ts");
|
|
105
|
+
if (!existsSync(settingsPath)) return;
|
|
106
|
+
return (await readFile(settingsPath, "utf8")).match(/storagePrefix:\s*['"]([^'"\\]+)['"]/)?.[1];
|
|
107
|
+
}
|
|
108
|
+
function detectModulesFromPackage(pkg) {
|
|
109
|
+
const modules = [];
|
|
110
|
+
if (hasDependency(pkg, "@pubinfo/module-rbac")) modules.push("rbac");
|
|
111
|
+
return modules;
|
|
112
|
+
}
|
|
113
|
+
function detectOpenapiEnabled(pkg) {
|
|
114
|
+
return hasDependency(pkg, "@pubinfo/openapi") || hasDependency(pkg, "@pubinfo/preset-openapi") || Boolean(pkg.scripts?.openapi);
|
|
115
|
+
}
|
|
116
|
+
function resolvePubinfoVersionFromPackage(pkg) {
|
|
117
|
+
return pkg.dependencies?.pubinfo || pkg.devDependencies?.pubinfo;
|
|
118
|
+
}
|
|
119
|
+
function buildWorkspacePackageName(originalName) {
|
|
120
|
+
if (!originalName) return "pubinfo-monorepo";
|
|
121
|
+
if (originalName.endsWith("-workspace")) return originalName;
|
|
122
|
+
if (originalName.startsWith("@")) {
|
|
123
|
+
const [scope, name] = originalName.slice(1).split("/");
|
|
124
|
+
if (!name) return originalName;
|
|
125
|
+
return `@${scope}/${name.endsWith("-workspace") ? name : `${name}-workspace`}`;
|
|
126
|
+
}
|
|
127
|
+
return `${originalName}-workspace`;
|
|
128
|
+
}
|
|
129
|
+
function preserveFields(target, source, fields) {
|
|
130
|
+
for (const field of fields) {
|
|
131
|
+
const value = source[field];
|
|
132
|
+
if (value !== void 0) target[field] = value;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
async function convertToMonorepo(options) {
|
|
136
|
+
const { rootDir, templateRoot, appName, force, rootPackageJson, rootPackageJsonContent, packageManager } = options;
|
|
137
|
+
if (existsSync(resolve(rootDir, "pnpm-workspace.yaml")) && !force) throw new Error("已检测到 pnpm-workspace.yaml,当前目录可能已经是 monorepo,如需继续请使用 --force");
|
|
138
|
+
const appsDir = resolve(rootDir, "apps");
|
|
139
|
+
await mkdir(appsDir, { recursive: true });
|
|
140
|
+
const appDir = resolve(appsDir, appName);
|
|
141
|
+
if (existsSync(appDir)) throw new Error(`应用目录 apps/${appName} 已存在,请更换名称或清理后再试`);
|
|
142
|
+
await mkdir(appDir, { recursive: true });
|
|
143
|
+
const backupDir = resolve(rootDir, ".pubinfo", "monorepo-backup", formatTimestamp(/* @__PURE__ */ new Date()));
|
|
144
|
+
await mkdir(backupDir, { recursive: true });
|
|
145
|
+
for (const dir of APP_DIRECTORIES) await movePath(rootDir, appDir, backupDir, dir);
|
|
146
|
+
for (const file of APP_FILES) await movePath(rootDir, appDir, backupDir, file);
|
|
147
|
+
const envFiles = await globby(ENV_PATTERNS, {
|
|
148
|
+
cwd: rootDir,
|
|
149
|
+
dot: true,
|
|
150
|
+
onlyFiles: true
|
|
151
|
+
});
|
|
152
|
+
for (const env of envFiles) await movePath(rootDir, appDir, backupDir, env);
|
|
153
|
+
const rootPkgPath = resolve(rootDir, "package.json");
|
|
154
|
+
const appPkgPath = resolve(appDir, "package.json");
|
|
155
|
+
await mkdir(dirname(appPkgPath), { recursive: true });
|
|
156
|
+
if (existsSync(appPkgPath)) throw new Error(`目标应用 package.json 已存在:apps/${appName}/package.json`);
|
|
157
|
+
await writeFile(appPkgPath, rootPackageJsonContent);
|
|
158
|
+
await backupPath(rootDir, backupDir, rootPkgPath);
|
|
159
|
+
const templatePkg = JSON.parse(await readFile(resolve(templateRoot, "package.json"), "utf8"));
|
|
160
|
+
templatePkg.name = buildWorkspacePackageName(rootPackageJson.name);
|
|
161
|
+
templatePkg.packageManager = packageManager || templatePkg.packageManager;
|
|
162
|
+
templatePkg.description = rootPackageJson.description || templatePkg.description || `Workspace for ${rootPackageJson.name ?? "pubinfo app"}`;
|
|
163
|
+
preserveFields(templatePkg, rootPackageJson, [
|
|
164
|
+
"license",
|
|
165
|
+
"author",
|
|
166
|
+
"repository",
|
|
167
|
+
"bugs",
|
|
168
|
+
"homepage"
|
|
169
|
+
]);
|
|
170
|
+
await writeFile(rootPkgPath, `${JSON.stringify(templatePkg, null, 2)}\n`);
|
|
171
|
+
for (const file of TEMPLATE_ROOT_FILES) await copyTemplateFile(templateRoot, rootDir, backupDir, file);
|
|
172
|
+
const lockFile = resolve(rootDir, "pnpm-lock.yaml");
|
|
173
|
+
if (existsSync(lockFile)) {
|
|
174
|
+
await backupPath(rootDir, backupDir, lockFile);
|
|
175
|
+
await rm(lockFile, { force: true });
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
appDir,
|
|
179
|
+
backupDir
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
//#endregion
|
|
184
|
+
//#region src/commands/monorepo.ts
|
|
185
|
+
const require = createRequire(import.meta.url);
|
|
186
|
+
const createPubinfoPkg = (() => {
|
|
187
|
+
try {
|
|
188
|
+
const pkgPath = resolve(dirname(require.resolve("create-pubinfo")), "../package.json");
|
|
189
|
+
return { version: JSON.parse(readFileSync(pkgPath, "utf8")).version ?? "latest" };
|
|
190
|
+
} catch {
|
|
191
|
+
logger.warn("无法解析 create-pubinfo 版本,将使用最新版本");
|
|
192
|
+
return { version: "latest" };
|
|
193
|
+
}
|
|
194
|
+
})();
|
|
195
|
+
var monorepo_default = defineCommand({
|
|
196
|
+
meta: {
|
|
197
|
+
name: "monorepo",
|
|
198
|
+
description: "将现有 pubinfo 单体工程转换为 monorepo 结构"
|
|
199
|
+
},
|
|
200
|
+
args: {
|
|
201
|
+
app: {
|
|
202
|
+
type: "string",
|
|
203
|
+
description: "应用目录名称,将生成在 apps/<name>"
|
|
204
|
+
},
|
|
205
|
+
key: {
|
|
206
|
+
type: "string",
|
|
207
|
+
description: "应用 storage key,默认尝试从 src/settings.ts 推断"
|
|
208
|
+
},
|
|
209
|
+
force: {
|
|
210
|
+
type: "boolean",
|
|
211
|
+
default: false,
|
|
212
|
+
description: "强制执行,忽略已有 pnpm-workspace.yaml 等检查"
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
async run({ args }) {
|
|
216
|
+
const rootDir = resolve(".");
|
|
217
|
+
const pkgPath = resolve(rootDir, "package.json");
|
|
218
|
+
if (!existsSync(pkgPath)) throw new Error("未找到 package.json,无法识别当前工程");
|
|
219
|
+
const pkgContent = await readFile(pkgPath, "utf8");
|
|
220
|
+
const pkg = JSON.parse(pkgContent);
|
|
221
|
+
const defaultAppName = deriveDefaultAppName(pkg.name);
|
|
222
|
+
const appName = args.app ?? defaultAppName;
|
|
223
|
+
ensureValidIdentifier(appName, "应用名称");
|
|
224
|
+
const detectedKey = await extractStorageKey(rootDir);
|
|
225
|
+
const key = args.key ?? detectedKey ?? appName;
|
|
226
|
+
ensureValidIdentifier(key, "应用标识");
|
|
227
|
+
const modules = detectModulesFromPackage(pkg);
|
|
228
|
+
const openapi = detectOpenapiEnabled(pkg);
|
|
229
|
+
const detectedVersion = resolvePubinfoVersionFromPackage(pkg);
|
|
230
|
+
const resolvedVersion = detectedVersion ?? createPubinfoPkg.version;
|
|
231
|
+
if (!detectedVersion) logger.info("未在 package.json 中检测到 pubinfo 依赖,将使用 create-pubinfo 默认版本");
|
|
232
|
+
const tempDir = await mkdtemp(join(tmpdir(), "pubinfo-monorepo-"));
|
|
233
|
+
try {
|
|
234
|
+
await generate({
|
|
235
|
+
templateName: "pubinfo-monorepo",
|
|
236
|
+
targetDir: tempDir,
|
|
237
|
+
key,
|
|
238
|
+
version: resolvedVersion,
|
|
239
|
+
modules,
|
|
240
|
+
openapi,
|
|
241
|
+
dir: appName
|
|
242
|
+
});
|
|
243
|
+
const { appDir, backupDir } = await convertToMonorepo({
|
|
244
|
+
rootDir,
|
|
245
|
+
templateRoot: tempDir,
|
|
246
|
+
appName,
|
|
247
|
+
force: Boolean(args.force),
|
|
248
|
+
rootPackageJson: pkg,
|
|
249
|
+
rootPackageJsonContent: pkgContent,
|
|
250
|
+
packageManager: pkg.packageManager
|
|
251
|
+
});
|
|
252
|
+
logger.success(`monorepo 结构已准备完成,应用目录:${relative(rootDir, appDir)}`);
|
|
253
|
+
logger.info(`备份文件位于:${relative(rootDir, backupDir)}`);
|
|
254
|
+
logger.info("请运行 pnpm install 以安装新的依赖,并使用 pnpm --filter apps/<app> dev 启动开发服务器");
|
|
255
|
+
} finally {
|
|
256
|
+
await rm(tempDir, {
|
|
257
|
+
recursive: true,
|
|
258
|
+
force: true
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
//#endregion
|
|
265
|
+
export { monorepo_default as default };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pubinfo/cli",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.1.
|
|
4
|
+
"version": "2.1.4",
|
|
5
5
|
"description": "CLI for Pubinfo",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": "./bin/pubinfo.mjs"
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"node": "^20.19.0 || >=22.12.0"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
|
-
"@pubinfo/vite": "2.1.
|
|
21
|
+
"@pubinfo/vite": "2.1.4"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"cheerio": "^1.1.2",
|
|
@@ -26,12 +26,13 @@
|
|
|
26
26
|
"execa": "^9.6.0",
|
|
27
27
|
"globby": "^14.1.0",
|
|
28
28
|
"pkg-types": "^2.3.0",
|
|
29
|
-
"@pubinfo/commitlint": "2.1.
|
|
30
|
-
"@pubinfo/shared": "2.1.
|
|
29
|
+
"@pubinfo/commitlint": "2.1.4",
|
|
30
|
+
"@pubinfo/shared": "2.1.4",
|
|
31
|
+
"create-pubinfo": "2.1.4"
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|
|
33
34
|
"@types/node": "^24.0.10",
|
|
34
|
-
"@pubinfo/vite": "2.1.
|
|
35
|
+
"@pubinfo/vite": "2.1.4"
|
|
35
36
|
},
|
|
36
37
|
"scripts": {
|
|
37
38
|
"dev": "tsdown --watch",
|
package/dist/setup-tGwcxPxN.js
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|