@afoures/auto-release 0.1.1 → 0.2.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 +3 -3
- package/dist/lib/commands/init.mjs +127 -52
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,11 +17,11 @@ Release management should be simple. `auto-release` lets you focus on building f
|
|
|
17
17
|
## Quick Start
|
|
18
18
|
|
|
19
19
|
```bash
|
|
20
|
-
npx auto-release init
|
|
20
|
+
npx --package=@afoures/auto-release@latest auto-release init
|
|
21
21
|
# or
|
|
22
|
-
|
|
22
|
+
pnpx --package=@afoures/auto-release@latest auto-release init
|
|
23
23
|
# or
|
|
24
|
-
bunx auto-release init
|
|
24
|
+
bunx --package=@afoures/auto-release@latest auto-release init
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
This creates `auto-release.config.ts` and sets up the `.changes` directory.
|
|
@@ -7,48 +7,58 @@ import { access, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
|
7
7
|
|
|
8
8
|
//#region src/lib/commands/init.ts
|
|
9
9
|
function generate_config_source(options) {
|
|
10
|
-
const { apps, changes_dir,
|
|
11
|
-
const imports = ["import { define_config } from \"auto-release\";"];
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (
|
|
15
|
-
|
|
10
|
+
const { apps, changes_dir, target_branch, default_release_branch_prefix, git } = options;
|
|
11
|
+
const imports = ["import { define_config } from \"@afoures/auto-release\";"];
|
|
12
|
+
const component_types = /* @__PURE__ */ new Set();
|
|
13
|
+
for (const app of apps) for (const component of app.components) component_types.add(component.type);
|
|
14
|
+
if (component_types.size > 0) {
|
|
15
|
+
const components = Array.from(component_types).sort();
|
|
16
|
+
imports.push(`import { ${components.join(", ")} } from "@afoures/auto-release/components";`);
|
|
17
|
+
}
|
|
18
|
+
const versioning_types = /* @__PURE__ */ new Set();
|
|
19
|
+
for (const app of apps) versioning_types.add(app.versioning);
|
|
20
|
+
if (versioning_types.size > 0) {
|
|
21
|
+
const versioning = Array.from(versioning_types).sort();
|
|
22
|
+
imports.push(`import { ${versioning.join(", ")} } from "@afoures/auto-release/versioning";`);
|
|
23
|
+
}
|
|
24
|
+
if (git.platform === "github") imports.push("import { github } from \"@afoures/auto-release/platforms\";");
|
|
25
|
+
else imports.push("import { gitlab } from \"@afoures/auto-release/platforms\";");
|
|
16
26
|
const lines = [
|
|
17
27
|
...imports,
|
|
18
28
|
"",
|
|
19
29
|
"export default define_config({"
|
|
20
30
|
];
|
|
21
|
-
lines.push(` changes_dir: ${JSON.stringify(changes_dir)},`);
|
|
22
|
-
lines.push(
|
|
23
|
-
lines.push(" apps: [");
|
|
31
|
+
if (changes_dir !== ".changes") lines.push(` changes_dir: ${JSON.stringify(changes_dir)},`);
|
|
32
|
+
lines.push(" apps: {");
|
|
24
33
|
apps.forEach((app, index) => {
|
|
25
|
-
lines.push(
|
|
26
|
-
lines.push(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
lines.push(` ${JSON.stringify(pkg)},`);
|
|
34
|
+
lines.push(` ${JSON.stringify(app.name)}: {`);
|
|
35
|
+
lines.push(" components: [");
|
|
36
|
+
app.components.forEach((component) => {
|
|
37
|
+
lines.push(` ${component.type}(${JSON.stringify(component.path)}),`);
|
|
30
38
|
});
|
|
31
39
|
lines.push(" ],");
|
|
32
|
-
lines.push(` versioning: ${app.versioning
|
|
33
|
-
lines.push(
|
|
34
|
-
lines.push(
|
|
35
|
-
lines.push(" },");
|
|
36
|
-
lines.push(index === apps.length - 1 ? " }" : " },");
|
|
40
|
+
lines.push(` versioning: ${app.versioning}(),`);
|
|
41
|
+
lines.push(` changelog: ${JSON.stringify(app.changelog_path)},`);
|
|
42
|
+
lines.push(index === apps.length - 1 ? " }," : " },");
|
|
37
43
|
});
|
|
38
|
-
lines.push("
|
|
44
|
+
lines.push(" },");
|
|
45
|
+
lines.push(" git: {");
|
|
39
46
|
if (git.platform === "github") {
|
|
40
|
-
lines.push("
|
|
41
|
-
lines.push(`
|
|
42
|
-
lines.push(`
|
|
43
|
-
lines.push(`
|
|
44
|
-
lines.push("
|
|
47
|
+
lines.push(" platform: github({");
|
|
48
|
+
lines.push(` token: process.env.${git.token_env}!,`);
|
|
49
|
+
lines.push(` owner: ${JSON.stringify(git.owner)},`);
|
|
50
|
+
lines.push(` repo: ${JSON.stringify(git.repo)},`);
|
|
51
|
+
lines.push(" }),");
|
|
45
52
|
} else {
|
|
46
|
-
lines.push("
|
|
47
|
-
lines.push(`
|
|
48
|
-
lines.push(`
|
|
49
|
-
if (git.host) lines.push(`
|
|
50
|
-
lines.push("
|
|
53
|
+
lines.push(" platform: gitlab({");
|
|
54
|
+
lines.push(` token: process.env.${git.token_env}!,`);
|
|
55
|
+
lines.push(` project_id: ${JSON.stringify(git.project_id)},`);
|
|
56
|
+
if (git.host) lines.push(` host: ${JSON.stringify(git.host)},`);
|
|
57
|
+
lines.push(" }),");
|
|
51
58
|
}
|
|
59
|
+
if (target_branch !== "main") lines.push(` target_branch: ${JSON.stringify(target_branch)},`);
|
|
60
|
+
if (default_release_branch_prefix !== "release") lines.push(` default_release_branch_prefix: ${JSON.stringify(default_release_branch_prefix)},`);
|
|
61
|
+
lines.push(" },");
|
|
52
62
|
lines.push("});", "");
|
|
53
63
|
return lines.join("\n");
|
|
54
64
|
}
|
|
@@ -78,10 +88,10 @@ async function detect_package_manager(cwd, package_json) {
|
|
|
78
88
|
}
|
|
79
89
|
function get_install_command(package_manager) {
|
|
80
90
|
switch (package_manager) {
|
|
81
|
-
case "pnpm": return "pnpm add -D auto-release";
|
|
82
|
-
case "yarn": return "yarn add -D auto-release";
|
|
83
|
-
case "bun": return "bun add -d auto-release";
|
|
84
|
-
default: return "npm install --save-dev auto-release";
|
|
91
|
+
case "pnpm": return "pnpm add -D @afoures/auto-release";
|
|
92
|
+
case "yarn": return "yarn add -D @afoures/auto-release";
|
|
93
|
+
case "bun": return "bun add -d @afoures/auto-release";
|
|
94
|
+
default: return "npm install --save-dev @afoures/auto-release";
|
|
85
95
|
}
|
|
86
96
|
}
|
|
87
97
|
async function ensure_package_json(path) {
|
|
@@ -154,7 +164,7 @@ const init = create_command({
|
|
|
154
164
|
package_manager = selection;
|
|
155
165
|
}
|
|
156
166
|
if (!package_manager) throw new Error("Package manager selection failed");
|
|
157
|
-
if (!(Boolean(package_json.dependencies?.["auto-release"]) || Boolean(package_json.devDependencies?.["auto-release"]))) {
|
|
167
|
+
if (!(Boolean(package_json.dependencies?.["@afoures/auto-release"]) || Boolean(package_json.devDependencies?.["@afoures/auto-release"]))) {
|
|
158
168
|
const install_spinner = spinner();
|
|
159
169
|
install_spinner.start("Installing auto-release...");
|
|
160
170
|
try {
|
|
@@ -184,7 +194,17 @@ const init = create_command({
|
|
|
184
194
|
cancel("Initialization cancelled");
|
|
185
195
|
return { status: "success" };
|
|
186
196
|
}
|
|
187
|
-
const
|
|
197
|
+
const default_release_branch_prefix = release_prefix_input.trim();
|
|
198
|
+
const target_branch_input = await text({
|
|
199
|
+
message: "Target branch (main branch for PRs)",
|
|
200
|
+
initialValue: "main",
|
|
201
|
+
validate: (value = "") => value.trim().length === 0 ? "Target branch cannot be empty" : void 0
|
|
202
|
+
});
|
|
203
|
+
if (isCancel(target_branch_input)) {
|
|
204
|
+
cancel("Initialization cancelled");
|
|
205
|
+
return { status: "success" };
|
|
206
|
+
}
|
|
207
|
+
const target_branch = target_branch_input.trim();
|
|
188
208
|
const app_count_input = await text({
|
|
189
209
|
message: "How many apps should auto-release manage?",
|
|
190
210
|
initialValue: "1",
|
|
@@ -211,16 +231,63 @@ const init = create_command({
|
|
|
211
231
|
return { status: "success" };
|
|
212
232
|
}
|
|
213
233
|
const app_name = normalize_app_name(app_name_input);
|
|
214
|
-
const
|
|
215
|
-
message: `
|
|
216
|
-
initialValue:
|
|
217
|
-
validate: (value = "") =>
|
|
234
|
+
const component_count_input = await text({
|
|
235
|
+
message: `How many components for ${app_name}?`,
|
|
236
|
+
initialValue: "1",
|
|
237
|
+
validate: (value = "") => {
|
|
238
|
+
const parsed = Number.parseInt(value, 10);
|
|
239
|
+
return Number.isNaN(parsed) || parsed <= 0 ? "Enter a positive number" : void 0;
|
|
240
|
+
}
|
|
218
241
|
});
|
|
219
|
-
if (isCancel(
|
|
242
|
+
if (isCancel(component_count_input)) {
|
|
220
243
|
cancel("Initialization cancelled");
|
|
221
244
|
return { status: "success" };
|
|
222
245
|
}
|
|
223
|
-
const
|
|
246
|
+
const component_count = Number.parseInt(component_count_input, 10);
|
|
247
|
+
const components = [];
|
|
248
|
+
for (let comp_index = 0; comp_index < component_count; comp_index++) {
|
|
249
|
+
const component_type_choice = await select({
|
|
250
|
+
message: `Component #${comp_index + 1} type for ${app_name}`,
|
|
251
|
+
options: [
|
|
252
|
+
{
|
|
253
|
+
value: "node",
|
|
254
|
+
label: "Node (package.json)"
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
value: "bun",
|
|
258
|
+
label: "Bun (package.json)"
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
value: "expo",
|
|
262
|
+
label: "Expo (package.json + app.json)"
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
value: "php",
|
|
266
|
+
label: "PHP (composer.json)"
|
|
267
|
+
}
|
|
268
|
+
]
|
|
269
|
+
});
|
|
270
|
+
if (isCancel(component_type_choice)) {
|
|
271
|
+
cancel("Initialization cancelled");
|
|
272
|
+
return { status: "success" };
|
|
273
|
+
}
|
|
274
|
+
const component_type = component_type_choice;
|
|
275
|
+
const default_path = app_count === 1 && component_count === 1 ? "." : `apps/${app_name}`;
|
|
276
|
+
const component_path_input = await text({
|
|
277
|
+
message: `Component #${comp_index + 1} path for ${app_name}`,
|
|
278
|
+
initialValue: default_path,
|
|
279
|
+
validate: (value = "") => value.trim().length === 0 ? "Component path is required" : void 0
|
|
280
|
+
});
|
|
281
|
+
if (isCancel(component_path_input)) {
|
|
282
|
+
cancel("Initialization cancelled");
|
|
283
|
+
return { status: "success" };
|
|
284
|
+
}
|
|
285
|
+
const component_path = component_path_input.trim();
|
|
286
|
+
components.push({
|
|
287
|
+
type: component_type,
|
|
288
|
+
path: component_path
|
|
289
|
+
});
|
|
290
|
+
}
|
|
224
291
|
const changelog_input = await text({
|
|
225
292
|
message: `Changelog path for ${app_name}`,
|
|
226
293
|
initialValue: app_count === 1 ? "CHANGELOG.md" : `apps/${app_name}/CHANGELOG.md`,
|
|
@@ -234,13 +301,20 @@ const init = create_command({
|
|
|
234
301
|
const version_choice = await select({
|
|
235
302
|
message: `Versioning strategy for ${app_name}`,
|
|
236
303
|
initialValue: "semver",
|
|
237
|
-
options: [
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
304
|
+
options: [
|
|
305
|
+
{
|
|
306
|
+
value: "semver",
|
|
307
|
+
label: "Semver (1.2.3) - major, minor, patch"
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
value: "calver",
|
|
311
|
+
label: "Calver (YYYY.MM.micro) - feature, fix"
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
value: "markver",
|
|
315
|
+
label: "Markver (1.0.0) - marketing, feature, fix"
|
|
316
|
+
}
|
|
317
|
+
]
|
|
244
318
|
});
|
|
245
319
|
if (isCancel(version_choice)) {
|
|
246
320
|
cancel("Initialization cancelled");
|
|
@@ -248,7 +322,7 @@ const init = create_command({
|
|
|
248
322
|
}
|
|
249
323
|
apps.push({
|
|
250
324
|
name: app_name,
|
|
251
|
-
|
|
325
|
+
components,
|
|
252
326
|
changelog_path,
|
|
253
327
|
versioning: version_choice
|
|
254
328
|
});
|
|
@@ -352,7 +426,8 @@ const init = create_command({
|
|
|
352
426
|
await writeFile(config_path, generate_config_source({
|
|
353
427
|
apps,
|
|
354
428
|
changes_dir,
|
|
355
|
-
|
|
429
|
+
target_branch,
|
|
430
|
+
default_release_branch_prefix,
|
|
356
431
|
git: git_answers
|
|
357
432
|
}), "utf-8");
|
|
358
433
|
await create_changes_directories(context.cwd, changes_dir, apps);
|
|
@@ -360,7 +435,7 @@ const init = create_command({
|
|
|
360
435
|
log.success("Generated auto-release.config.ts");
|
|
361
436
|
log.success(`Change files directory: ${changes_dir}`);
|
|
362
437
|
apps.forEach((app) => {
|
|
363
|
-
log.success(`App ${app.name} ready with ${app.
|
|
438
|
+
log.success(`App ${app.name} ready with ${app.components.length} component(s)`);
|
|
364
439
|
});
|
|
365
440
|
outro("auto-release init complete!");
|
|
366
441
|
return {
|