@icebreakers/monorepo 3.2.17 → 4.0.0
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/README.md +181 -52
- package/bin/mo.js +2 -0
- package/bin/rc.js +2 -0
- package/bin/repo.js +2 -0
- package/bin/repoctl.js +2 -0
- package/dist/cli.mjs +1067 -76
- package/dist/commands-MPDw9wMy.mjs +2501 -0
- package/dist/config-BGCo7USv.mjs +120 -0
- package/dist/create-flow-BEHRojMs.mjs +179 -0
- package/dist/index-BBxViYZd.d.mts +1049 -0
- package/dist/index.d.mts +383 -713
- package/dist/index.mjs +6 -2
- package/dist/rolldown-runtime-twds-ZHy.mjs +14 -0
- package/dist/tooling-DyUe-eiv.mjs +427 -0
- package/dist/tooling-entry.d.mts +2 -0
- package/dist/tooling-entry.mjs +2 -0
- package/dist/types-CRtyTy2K.mjs +213 -0
- package/dist/workspace-DS6LAL71.mjs +118 -0
- package/package.json +43 -34
- package/resources/skills/icebreakers-monorepo-cli/SKILL.md +12 -10
- package/resources/skills/icebreakers-monorepo-cli/references/commands.md +166 -21
- package/resources/skills/icebreakers-monorepo-cli/references/config.md +13 -9
- package/resources/skills/icebreakers-monorepo-cli/references/templates.md +30 -5
- package/tsconfig.base.json +23 -0
- package/dist/cli.cjs +0 -116
- package/dist/cli.d.cts +0 -1
- package/dist/index.cjs +0 -82
- package/dist/index.d.cts +0 -918
- package/dist/upgrade-CEtZ-XOF.mjs +0 -1513
- package/dist/upgrade-d3Q-0wfw.cjs +0 -1850
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-twds-ZHy.mjs";
|
|
2
|
+
import path from "pathe";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import { loadConfig } from "c12";
|
|
5
|
+
//#region src/core/config.ts
|
|
6
|
+
var config_exports = /* @__PURE__ */ __exportAll({
|
|
7
|
+
configExtensions: () => configExtensions,
|
|
8
|
+
defineMonorepoConfig: () => defineMonorepoConfig,
|
|
9
|
+
getMonorepoConfigCandidates: () => getMonorepoConfigCandidates,
|
|
10
|
+
loadMonorepoConfig: () => loadMonorepoConfig,
|
|
11
|
+
loadMonorepoConfigDetails: () => loadMonorepoConfigDetails,
|
|
12
|
+
resolveCommandConfig: () => resolveCommandConfig,
|
|
13
|
+
resolveToolingConfig: () => resolveToolingConfig
|
|
14
|
+
});
|
|
15
|
+
/**
|
|
16
|
+
* 简单的内存缓存,避免同一次命令中重复走磁盘加载配置。
|
|
17
|
+
*/
|
|
18
|
+
const cache = /* @__PURE__ */ new Map();
|
|
19
|
+
const configExtensions = [
|
|
20
|
+
"ts",
|
|
21
|
+
"mts",
|
|
22
|
+
"cts",
|
|
23
|
+
"js",
|
|
24
|
+
"mjs",
|
|
25
|
+
"cjs"
|
|
26
|
+
];
|
|
27
|
+
function getMonorepoConfigCandidates(cwd) {
|
|
28
|
+
return {
|
|
29
|
+
repoctl: configExtensions.map((ext) => path.resolve(cwd, `repoctl.config.${ext}`)),
|
|
30
|
+
monorepo: configExtensions.map((ext) => path.resolve(cwd, `monorepo.config.${ext}`))
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function findConfigFiles(cwd, baseName) {
|
|
34
|
+
return getMonorepoConfigCandidates(cwd)[baseName].filter((file) => fs.existsSync(file));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* 基于 c12 的通用配置加载逻辑,支持多种配置文件格式。
|
|
38
|
+
*/
|
|
39
|
+
async function loadConfigInternal(cwd) {
|
|
40
|
+
const repoctlConfigFiles = findConfigFiles(cwd, "repoctl");
|
|
41
|
+
const monorepoConfigFiles = findConfigFiles(cwd, "monorepo");
|
|
42
|
+
if (repoctlConfigFiles.length > 0 && monorepoConfigFiles.length > 0) throw new Error(`Found both repoctl and monorepo config files in ${cwd}. Please keep only one of them. repoctl candidates: ${repoctlConfigFiles.join(", ")}; monorepo candidates: ${monorepoConfigFiles.join(", ")}`);
|
|
43
|
+
const { config, configFile } = await loadConfig({
|
|
44
|
+
name: repoctlConfigFiles.length > 0 ? "repoctl" : "monorepo",
|
|
45
|
+
cwd,
|
|
46
|
+
rcFile: false,
|
|
47
|
+
defaults: {},
|
|
48
|
+
globalRc: false,
|
|
49
|
+
packageJson: false
|
|
50
|
+
});
|
|
51
|
+
return {
|
|
52
|
+
file: configFile && fs.existsSync(configFile) ? fs.realpathSync(configFile) : null,
|
|
53
|
+
config: config ?? {}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* 为 `repoctl.config.ts` / `monorepo.config.ts` 提供类型提示的辅助函数。
|
|
58
|
+
*
|
|
59
|
+
* 推荐在用户项目中这样写:
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* import { defineMonorepoConfig } from '@icebreakers/monorepo'
|
|
64
|
+
*
|
|
65
|
+
* export default defineMonorepoConfig({
|
|
66
|
+
* tooling: {
|
|
67
|
+
* vitest: {
|
|
68
|
+
* includeWorkspaceRootConfig: false,
|
|
69
|
+
* },
|
|
70
|
+
* },
|
|
71
|
+
* })
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
function defineMonorepoConfig(config) {
|
|
75
|
+
return config;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* 加载配置对象和实际命中的配置文件路径,供诊断和脚本集成使用。
|
|
79
|
+
* 优先级为 `repoctl.config.*`,如果两者同时存在则直接报错。
|
|
80
|
+
*
|
|
81
|
+
* @param cwd 配置文件解析起点
|
|
82
|
+
* @returns 配置文件路径和解析后的配置对象;未找到时 file 为 null、config 为空对象
|
|
83
|
+
*/
|
|
84
|
+
async function loadMonorepoConfigDetails(cwd) {
|
|
85
|
+
const key = path.resolve(cwd);
|
|
86
|
+
if (!cache.has(key)) cache.set(key, loadConfigInternal(key));
|
|
87
|
+
return cache.get(key);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* 加载指定目录的 `repoctl.config.*` 或 `monorepo.config.*`,并在当前进程内做内存缓存。
|
|
91
|
+
* 优先级为 `repoctl.config.*`,如果两者同时存在则直接报错。
|
|
92
|
+
*
|
|
93
|
+
* @param cwd 配置文件解析起点
|
|
94
|
+
* @returns 解析后的配置对象;未找到时返回空对象
|
|
95
|
+
*/
|
|
96
|
+
async function loadMonorepoConfig(cwd) {
|
|
97
|
+
const { config } = await loadMonorepoConfigDetails(cwd);
|
|
98
|
+
return config;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* 获取单个命令对应的配置块。
|
|
102
|
+
*
|
|
103
|
+
* @param name 命令名称,对应 `repoctl.config.ts` / `monorepo.config.ts -> commands.<name>`
|
|
104
|
+
* @param cwd 配置文件解析起点
|
|
105
|
+
* @returns 对应命令配置;未配置时返回空对象
|
|
106
|
+
*/
|
|
107
|
+
async function resolveCommandConfig(name, cwd) {
|
|
108
|
+
return ((await loadMonorepoConfig(cwd)).commands ?? {})[name] ?? {};
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* 获取 `repoctl.config.ts` / `monorepo.config.ts` 中完整的 `tooling` 配置块。
|
|
112
|
+
*
|
|
113
|
+
* @param cwd 配置文件解析起点
|
|
114
|
+
* @returns `tooling` 配置;未配置时返回空对象
|
|
115
|
+
*/
|
|
116
|
+
async function resolveToolingConfig(cwd) {
|
|
117
|
+
return (await loadMonorepoConfig(cwd)).tooling ?? {};
|
|
118
|
+
}
|
|
119
|
+
//#endregion
|
|
120
|
+
export { loadMonorepoConfig as a, resolveToolingConfig as c, getMonorepoConfigCandidates as i, config_exports as n, loadMonorepoConfigDetails as o, defineMonorepoConfig as r, resolveCommandConfig as s, configExtensions as t };
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { _ as getCreateChoices, h as createNewProject, y as resolveCreateNewProjectPlan } from "./commands-MPDw9wMy.mjs";
|
|
2
|
+
import { d as logger, g as fs } from "./types-CRtyTy2K.mjs";
|
|
3
|
+
import { s as resolveCommandConfig } from "./config-BGCo7USv.mjs";
|
|
4
|
+
import path from "pathe";
|
|
5
|
+
import process from "node:process";
|
|
6
|
+
import { input, select } from "@icebreakers/monorepo-templates";
|
|
7
|
+
//#region src/cli/commands/package/intents.ts
|
|
8
|
+
const createIntentChoices = [
|
|
9
|
+
{
|
|
10
|
+
value: "library",
|
|
11
|
+
name: "Library",
|
|
12
|
+
description: "创建一个可发布的库包",
|
|
13
|
+
defaultTemplate: "tsdown",
|
|
14
|
+
defaultBaseDir: "packages"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
value: "web-app",
|
|
18
|
+
name: "Web App",
|
|
19
|
+
description: "创建一个前后端一体的 Web 应用",
|
|
20
|
+
defaultTemplate: "vue-hono",
|
|
21
|
+
defaultBaseDir: "apps"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
value: "api-service",
|
|
25
|
+
name: "API Service",
|
|
26
|
+
description: "创建一个 Hono API 服务",
|
|
27
|
+
defaultTemplate: "hono-server",
|
|
28
|
+
defaultBaseDir: "apps"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
value: "docs-site",
|
|
32
|
+
name: "Docs Site",
|
|
33
|
+
description: "创建一个文档站点",
|
|
34
|
+
defaultTemplate: "vitepress",
|
|
35
|
+
defaultBaseDir: "apps"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
value: "cli-tool",
|
|
39
|
+
name: "CLI Tool",
|
|
40
|
+
description: "创建一个命令行工具",
|
|
41
|
+
defaultTemplate: "cli",
|
|
42
|
+
defaultBaseDir: "apps"
|
|
43
|
+
}
|
|
44
|
+
];
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/cli/commands/package/create-flow.ts
|
|
47
|
+
function normalizeTargetName(name, baseDir) {
|
|
48
|
+
if (name.includes("/")) return name;
|
|
49
|
+
return `${baseDir}/${name}`;
|
|
50
|
+
}
|
|
51
|
+
function resolveBaseDirFromTemplate(type) {
|
|
52
|
+
return createIntentChoices.find((item) => item.defaultTemplate === type)?.defaultBaseDir;
|
|
53
|
+
}
|
|
54
|
+
function normalizeNameForTemplate(name, type) {
|
|
55
|
+
if (!type) return name;
|
|
56
|
+
const baseDir = resolveBaseDirFromTemplate(type);
|
|
57
|
+
if (!baseDir) return name;
|
|
58
|
+
return normalizeTargetName(name, baseDir);
|
|
59
|
+
}
|
|
60
|
+
function formatPlanPath(cwd, targetPath) {
|
|
61
|
+
const relative = path.relative(cwd, targetPath);
|
|
62
|
+
return relative && relative !== "." ? relative : targetPath;
|
|
63
|
+
}
|
|
64
|
+
function printCreatePlan(plan) {
|
|
65
|
+
logger.log("");
|
|
66
|
+
logger.log("Create preview:");
|
|
67
|
+
logger.log(` template: ${plan.template}${plan.usedFallback ? ` (fallback from ${plan.requestedTemplate})` : ""}`);
|
|
68
|
+
logger.log(` source: ${formatPlanPath(plan.cwd, plan.sourceDir)}`);
|
|
69
|
+
logger.log(` target: ${formatPlanPath(plan.cwd, plan.targetDir)}${plan.targetExists ? " (already exists)" : ""}`);
|
|
70
|
+
logger.log(` package: ${plan.packageName}`);
|
|
71
|
+
logger.log(` package json: ${plan.hasPackageJson ? plan.packageJsonFileName : "not included in template"}`);
|
|
72
|
+
logger.log("");
|
|
73
|
+
logger.info("dry run only; no files were written");
|
|
74
|
+
}
|
|
75
|
+
function printCreatePlanJson(plan) {
|
|
76
|
+
logger.log(JSON.stringify(plan, null, 2));
|
|
77
|
+
}
|
|
78
|
+
function formatCreatePlan(plan) {
|
|
79
|
+
return [
|
|
80
|
+
"Create preview:",
|
|
81
|
+
` template: ${plan.template}${plan.usedFallback ? ` (fallback from ${plan.requestedTemplate})` : ""}`,
|
|
82
|
+
` source: ${formatPlanPath(plan.cwd, plan.sourceDir)}`,
|
|
83
|
+
` target: ${formatPlanPath(plan.cwd, plan.targetDir)}${plan.targetExists ? " (already exists)" : ""}`,
|
|
84
|
+
` package: ${plan.packageName}`,
|
|
85
|
+
` package json: ${plan.hasPackageJson ? plan.packageJsonFileName : "not included in template"}`,
|
|
86
|
+
"",
|
|
87
|
+
"dry run only; no files were written"
|
|
88
|
+
].join("\n");
|
|
89
|
+
}
|
|
90
|
+
async function emitCreatePlan(plan, options, cwd) {
|
|
91
|
+
if (!options.out) {
|
|
92
|
+
if (options.json) printCreatePlanJson(plan);
|
|
93
|
+
else printCreatePlan(plan);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const content = options.json ? JSON.stringify(plan, null, 2) : formatCreatePlan(plan);
|
|
97
|
+
const outFile = path.resolve(cwd, options.out);
|
|
98
|
+
await fs.outputFile(outFile, `${content}\n`, "utf8");
|
|
99
|
+
logger.success(`wrote ${path.relative(cwd, outFile)}`);
|
|
100
|
+
}
|
|
101
|
+
function handleCreateFlowError(error, json = false) {
|
|
102
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
103
|
+
if (json) logger.log(JSON.stringify({ error: message }, null, 2));
|
|
104
|
+
else logger.error(message);
|
|
105
|
+
process.exitCode = 1;
|
|
106
|
+
return {
|
|
107
|
+
dryRun: false,
|
|
108
|
+
failed: true
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
async function runCreateFlow(cwd, inputName, options = {}) {
|
|
112
|
+
try {
|
|
113
|
+
const createConfig = await resolveCommandConfig("create", cwd);
|
|
114
|
+
const explicitTemplate = options.template ?? createConfig?.type ?? createConfig?.defaultTemplate;
|
|
115
|
+
let packageName = inputName;
|
|
116
|
+
if (!explicitTemplate) {
|
|
117
|
+
const intent = await select({
|
|
118
|
+
message: "你要创建什么?",
|
|
119
|
+
choices: createIntentChoices,
|
|
120
|
+
default: "library"
|
|
121
|
+
});
|
|
122
|
+
const intentChoice = createIntentChoices.find((item) => item.value === intent);
|
|
123
|
+
if (!intentChoice) throw new Error(`未找到 intent: ${intent}`);
|
|
124
|
+
if (!packageName) packageName = await input({
|
|
125
|
+
message: "请输入名称",
|
|
126
|
+
default: "my-module"
|
|
127
|
+
});
|
|
128
|
+
let type = intentChoice.defaultTemplate;
|
|
129
|
+
if (intent === "library") type = await select({
|
|
130
|
+
message: "请选择库模板",
|
|
131
|
+
choices: [{
|
|
132
|
+
name: "TypeScript Library",
|
|
133
|
+
value: "tsdown",
|
|
134
|
+
description: "通用 TS 库"
|
|
135
|
+
}, {
|
|
136
|
+
name: "Vue Component Library",
|
|
137
|
+
value: "vue-lib",
|
|
138
|
+
description: "Vue 组件库"
|
|
139
|
+
}],
|
|
140
|
+
default: "tsdown"
|
|
141
|
+
});
|
|
142
|
+
const createOptions = {
|
|
143
|
+
name: normalizeTargetName(packageName, intentChoice.defaultBaseDir),
|
|
144
|
+
cwd,
|
|
145
|
+
...type !== void 0 ? { type } : {}
|
|
146
|
+
};
|
|
147
|
+
if (options.dryRun) {
|
|
148
|
+
await emitCreatePlan(await resolveCreateNewProjectPlan(createOptions), options, cwd);
|
|
149
|
+
return { dryRun: true };
|
|
150
|
+
}
|
|
151
|
+
await createNewProject(createOptions);
|
|
152
|
+
return { dryRun: false };
|
|
153
|
+
}
|
|
154
|
+
if (!packageName) packageName = await input({
|
|
155
|
+
message: "请输入包名",
|
|
156
|
+
default: createConfig?.name ?? "my-package"
|
|
157
|
+
});
|
|
158
|
+
const type = explicitTemplate ?? await select({
|
|
159
|
+
message: "请选择模板类型",
|
|
160
|
+
choices: getCreateChoices(createConfig?.choices),
|
|
161
|
+
default: "tsdown"
|
|
162
|
+
});
|
|
163
|
+
const createOptions = {
|
|
164
|
+
name: normalizeNameForTemplate(packageName, type),
|
|
165
|
+
cwd,
|
|
166
|
+
...type !== void 0 ? { type } : {}
|
|
167
|
+
};
|
|
168
|
+
if (options.dryRun) {
|
|
169
|
+
await emitCreatePlan(await resolveCreateNewProjectPlan(createOptions), options, cwd);
|
|
170
|
+
return { dryRun: true };
|
|
171
|
+
}
|
|
172
|
+
await createNewProject(createOptions);
|
|
173
|
+
return { dryRun: false };
|
|
174
|
+
} catch (error) {
|
|
175
|
+
return handleCreateFlowError(error, options.json);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
//#endregion
|
|
179
|
+
export { runCreateFlow };
|