@releasekit/notes 0.3.0-next.3 → 0.3.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 +2 -0
- package/dist/cli.js +0 -173
- package/package.json +14 -12
- package/dist/aggregator-JZ3VUZKP.js +0 -13
- package/dist/chunk-QCF6V2IY.js +0 -135
- package/dist/chunk-QUBVC5LF.js +0 -1488
- package/dist/chunk-TSLTZ26C.js +0 -163
- package/dist/cli.cjs +0 -1939
- package/dist/cli.d.cts +0 -1
- package/dist/cli.d.ts +0 -1
- package/dist/index.cjs +0 -1866
- package/dist/index.d.cts +0 -219
- package/dist/index.d.ts +0 -219
- package/dist/index.js +0 -61
package/dist/chunk-TSLTZ26C.js
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
formatVersion,
|
|
3
|
-
prependVersion,
|
|
4
|
-
renderMarkdown
|
|
5
|
-
} from "./chunk-QCF6V2IY.js";
|
|
6
|
-
|
|
7
|
-
// src/monorepo/aggregator.ts
|
|
8
|
-
import * as fs from "fs";
|
|
9
|
-
import * as path from "path";
|
|
10
|
-
import { debug, info, success } from "@releasekit/core";
|
|
11
|
-
|
|
12
|
-
// src/monorepo/splitter.ts
|
|
13
|
-
function splitByPackage(contexts) {
|
|
14
|
-
const byPackage = /* @__PURE__ */ new Map();
|
|
15
|
-
for (const ctx of contexts) {
|
|
16
|
-
byPackage.set(ctx.packageName, ctx);
|
|
17
|
-
}
|
|
18
|
-
return byPackage;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// src/monorepo/aggregator.ts
|
|
22
|
-
function writeFile(outputPath, content, dryRun) {
|
|
23
|
-
if (dryRun) {
|
|
24
|
-
info(`Would write to ${outputPath}`);
|
|
25
|
-
debug(content);
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
const dir = path.dirname(outputPath);
|
|
29
|
-
if (!fs.existsSync(dir)) {
|
|
30
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
31
|
-
}
|
|
32
|
-
fs.writeFileSync(outputPath, content, "utf-8");
|
|
33
|
-
success(`Changelog written to ${outputPath}`);
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
function aggregateToRoot(contexts) {
|
|
37
|
-
const aggregated = {
|
|
38
|
-
packageName: "monorepo",
|
|
39
|
-
version: contexts[0]?.version ?? "0.0.0",
|
|
40
|
-
previousVersion: contexts[0]?.previousVersion ?? null,
|
|
41
|
-
date: (/* @__PURE__ */ new Date()).toISOString().split("T")[0] ?? "",
|
|
42
|
-
repoUrl: contexts[0]?.repoUrl ?? null,
|
|
43
|
-
entries: []
|
|
44
|
-
};
|
|
45
|
-
for (const ctx of contexts) {
|
|
46
|
-
for (const entry of ctx.entries) {
|
|
47
|
-
aggregated.entries.push({
|
|
48
|
-
...entry,
|
|
49
|
-
scope: entry.scope ? `${ctx.packageName}/${entry.scope}` : ctx.packageName
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return aggregated;
|
|
54
|
-
}
|
|
55
|
-
function writeMonorepoChangelogs(contexts, options, config, dryRun) {
|
|
56
|
-
const files = [];
|
|
57
|
-
if (options.mode === "root" || options.mode === "both") {
|
|
58
|
-
const rootPath = path.join(options.rootPath, "CHANGELOG.md");
|
|
59
|
-
const fmtOpts = { includePackageName: true };
|
|
60
|
-
info(`Writing root changelog to ${rootPath}`);
|
|
61
|
-
let rootContent;
|
|
62
|
-
if (config.updateStrategy === "prepend" && fs.existsSync(rootPath)) {
|
|
63
|
-
const newSections = contexts.map((ctx) => formatVersion(ctx, fmtOpts)).join("\n");
|
|
64
|
-
const existing = fs.readFileSync(rootPath, "utf-8");
|
|
65
|
-
const headerEnd = existing.indexOf("\n## ");
|
|
66
|
-
if (headerEnd >= 0) {
|
|
67
|
-
rootContent = `${existing.slice(0, headerEnd)}
|
|
68
|
-
|
|
69
|
-
${newSections}
|
|
70
|
-
${existing.slice(headerEnd + 1)}`;
|
|
71
|
-
} else {
|
|
72
|
-
rootContent = renderMarkdown(contexts, fmtOpts);
|
|
73
|
-
}
|
|
74
|
-
} else {
|
|
75
|
-
rootContent = renderMarkdown(contexts, fmtOpts);
|
|
76
|
-
}
|
|
77
|
-
if (writeFile(rootPath, rootContent, dryRun)) {
|
|
78
|
-
files.push(rootPath);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
if (options.mode === "packages" || options.mode === "both") {
|
|
82
|
-
const byPackage = splitByPackage(contexts);
|
|
83
|
-
const packageDirMap = buildPackageDirMap(options.rootPath, options.packagesPath);
|
|
84
|
-
for (const [packageName, ctx] of byPackage) {
|
|
85
|
-
const simpleName = packageName.split("/").pop();
|
|
86
|
-
const packageDir = packageDirMap.get(packageName) ?? (simpleName ? packageDirMap.get(simpleName) : void 0) ?? null;
|
|
87
|
-
if (packageDir) {
|
|
88
|
-
const changelogPath = path.join(packageDir, "CHANGELOG.md");
|
|
89
|
-
info(`Writing changelog for ${packageName} to ${changelogPath}`);
|
|
90
|
-
const pkgContent = config.updateStrategy === "prepend" && fs.existsSync(changelogPath) ? prependVersion(changelogPath, ctx) : renderMarkdown([ctx]);
|
|
91
|
-
if (writeFile(changelogPath, pkgContent, dryRun)) {
|
|
92
|
-
files.push(changelogPath);
|
|
93
|
-
}
|
|
94
|
-
} else {
|
|
95
|
-
info(`Could not find directory for package ${packageName}, skipping`);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return files;
|
|
100
|
-
}
|
|
101
|
-
function buildPackageDirMap(rootPath, packagesPath) {
|
|
102
|
-
const map = /* @__PURE__ */ new Map();
|
|
103
|
-
const packagesDir = path.join(rootPath, packagesPath);
|
|
104
|
-
if (!fs.existsSync(packagesDir)) {
|
|
105
|
-
return map;
|
|
106
|
-
}
|
|
107
|
-
for (const entry of fs.readdirSync(packagesDir, { withFileTypes: true })) {
|
|
108
|
-
if (!entry.isDirectory()) continue;
|
|
109
|
-
const dirPath = path.join(packagesDir, entry.name);
|
|
110
|
-
map.set(entry.name, dirPath);
|
|
111
|
-
const packageJsonPath = path.join(dirPath, "package.json");
|
|
112
|
-
if (fs.existsSync(packageJsonPath)) {
|
|
113
|
-
try {
|
|
114
|
-
const pkg = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
|
|
115
|
-
if (pkg.name) {
|
|
116
|
-
map.set(pkg.name, dirPath);
|
|
117
|
-
}
|
|
118
|
-
} catch {
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return map;
|
|
123
|
-
}
|
|
124
|
-
function detectMonorepo(cwd) {
|
|
125
|
-
const pnpmWorkspacesPath = path.join(cwd, "pnpm-workspace.yaml");
|
|
126
|
-
const packageJsonPath = path.join(cwd, "package.json");
|
|
127
|
-
if (fs.existsSync(pnpmWorkspacesPath)) {
|
|
128
|
-
const content = fs.readFileSync(pnpmWorkspacesPath, "utf-8");
|
|
129
|
-
const packagesMatch = content.match(/packages:\s*\n\s*-\s*['"]([^'"]+)['"]/);
|
|
130
|
-
if (packagesMatch?.[1]) {
|
|
131
|
-
const packagesGlob = packagesMatch[1];
|
|
132
|
-
const packagesPath = packagesGlob.replace(/\/?\*$/, "").replace(/\/\*\*$/, "");
|
|
133
|
-
return { isMonorepo: true, packagesPath: packagesPath || "packages" };
|
|
134
|
-
}
|
|
135
|
-
return { isMonorepo: true, packagesPath: "packages" };
|
|
136
|
-
}
|
|
137
|
-
if (fs.existsSync(packageJsonPath)) {
|
|
138
|
-
try {
|
|
139
|
-
const content = fs.readFileSync(packageJsonPath, "utf-8");
|
|
140
|
-
const pkg = JSON.parse(content);
|
|
141
|
-
if (pkg.workspaces) {
|
|
142
|
-
const workspaces = Array.isArray(pkg.workspaces) ? pkg.workspaces : pkg.workspaces.packages;
|
|
143
|
-
if (workspaces?.length) {
|
|
144
|
-
const firstWorkspace = workspaces[0];
|
|
145
|
-
if (firstWorkspace) {
|
|
146
|
-
const packagesPath = firstWorkspace.replace(/\/?\*$/, "").replace(/\/\*\*$/, "");
|
|
147
|
-
return { isMonorepo: true, packagesPath: packagesPath || "packages" };
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
} catch {
|
|
152
|
-
return { isMonorepo: false, packagesPath: "" };
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return { isMonorepo: false, packagesPath: "" };
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
export {
|
|
159
|
-
splitByPackage,
|
|
160
|
-
aggregateToRoot,
|
|
161
|
-
writeMonorepoChangelogs,
|
|
162
|
-
detectMonorepo
|
|
163
|
-
};
|