@afoures/auto-release 0.1.2 → 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.
@@ -1,6 +1,5 @@
1
1
  import { create_command } from "../cli.mjs";
2
2
  import { exec } from "../utils/exec.mjs";
3
- import { name } from "../../package.mjs";
4
3
  import { cancel, confirm, intro, isCancel, log, outro, select, spinner, text } from "@clack/prompts";
5
4
  import { basename, dirname, join } from "node:path";
6
5
  import { constants } from "node:fs";
@@ -8,48 +7,58 @@ import { access, mkdir, readFile, writeFile } from "node:fs/promises";
8
7
 
9
8
  //#region src/lib/commands/init.ts
10
9
  function generate_config_source(options) {
11
- const { apps, changes_dir, release_branch_prefix, git } = options;
12
- const imports = ["import { define_config } from \"auto-release\";"];
13
- if (apps.some((app) => app.versioning === "semver")) imports.push("import { semver } from \"auto-release/versioning/semver\";");
14
- if (apps.some((app) => app.versioning === "calver")) imports.push("import { calver } from \"auto-release/versioning/calver\";");
15
- if (git.platform === "github") imports.push("import { github } from \"auto-release/git/github\";");
16
- else imports.push("import { gitlab } from \"auto-release/git/gitlab\";");
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\";");
17
26
  const lines = [
18
27
  ...imports,
19
28
  "",
20
29
  "export default define_config({"
21
30
  ];
22
- lines.push(` changes_dir: ${JSON.stringify(changes_dir)},`);
23
- lines.push(` release_branch_prefix: ${JSON.stringify(release_branch_prefix)},`);
24
- lines.push(" apps: [");
31
+ if (changes_dir !== ".changes") lines.push(` changes_dir: ${JSON.stringify(changes_dir)},`);
32
+ lines.push(" apps: {");
25
33
  apps.forEach((app, index) => {
26
- lines.push(" {");
27
- lines.push(` name: ${JSON.stringify(app.name)},`);
28
- lines.push(" packages: [");
29
- app.packages.forEach((pkg) => {
30
- 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)}),`);
31
38
  });
32
39
  lines.push(" ],");
33
- lines.push(` versioning: ${app.versioning === "semver" ? "semver()" : "calver()"},`);
34
- lines.push(" changelog: {");
35
- lines.push(` path: ${JSON.stringify(app.changelog_path)},`);
36
- lines.push(" },");
37
- 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 ? " }," : " },");
38
43
  });
39
- lines.push(" ],");
44
+ lines.push(" },");
45
+ lines.push(" git: {");
40
46
  if (git.platform === "github") {
41
- lines.push(" git: github({");
42
- lines.push(` token: process.env.${git.token_env}!,`);
43
- lines.push(` owner: ${JSON.stringify(git.owner)},`);
44
- lines.push(` repo: ${JSON.stringify(git.repo)},`);
45
- 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(" }),");
46
52
  } else {
47
- lines.push(" git: gitlab({");
48
- lines.push(` token: process.env.${git.token_env}!,`);
49
- lines.push(` project_id: ${JSON.stringify(git.project_id)},`);
50
- if (git.host) lines.push(` host: ${JSON.stringify(git.host)},`);
51
- 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(" }),");
52
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(" },");
53
62
  lines.push("});", "");
54
63
  return lines.join("\n");
55
64
  }
@@ -79,10 +88,10 @@ async function detect_package_manager(cwd, package_json) {
79
88
  }
80
89
  function get_install_command(package_manager) {
81
90
  switch (package_manager) {
82
- case "pnpm": return `pnpm add -D ${name}`;
83
- case "yarn": return `yarn add -D ${name}`;
84
- case "bun": return `bun add -d ${name}`;
85
- default: return `npm install --save-dev ${name}`;
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";
86
95
  }
87
96
  }
88
97
  async function ensure_package_json(path) {
@@ -155,7 +164,7 @@ const init = create_command({
155
164
  package_manager = selection;
156
165
  }
157
166
  if (!package_manager) throw new Error("Package manager selection failed");
158
- 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"]))) {
159
168
  const install_spinner = spinner();
160
169
  install_spinner.start("Installing auto-release...");
161
170
  try {
@@ -185,7 +194,17 @@ const init = create_command({
185
194
  cancel("Initialization cancelled");
186
195
  return { status: "success" };
187
196
  }
188
- const release_branch_prefix = release_prefix_input.trim();
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();
189
208
  const app_count_input = await text({
190
209
  message: "How many apps should auto-release manage?",
191
210
  initialValue: "1",
@@ -212,16 +231,63 @@ const init = create_command({
212
231
  return { status: "success" };
213
232
  }
214
233
  const app_name = normalize_app_name(app_name_input);
215
- const package_paths_input = await text({
216
- message: `Package paths for ${app_name} (comma separated)`,
217
- initialValue: app_count === 1 ? "." : `apps/${app_name}`,
218
- validate: (value = "") => value.trim().length === 0 ? "At least one package path is required" : void 0
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
+ }
219
241
  });
220
- if (isCancel(package_paths_input)) {
242
+ if (isCancel(component_count_input)) {
221
243
  cancel("Initialization cancelled");
222
244
  return { status: "success" };
223
245
  }
224
- const package_paths = package_paths_input.split(",").map((path) => path.trim()).filter(Boolean);
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
+ }
225
291
  const changelog_input = await text({
226
292
  message: `Changelog path for ${app_name}`,
227
293
  initialValue: app_count === 1 ? "CHANGELOG.md" : `apps/${app_name}/CHANGELOG.md`,
@@ -235,13 +301,20 @@ const init = create_command({
235
301
  const version_choice = await select({
236
302
  message: `Versioning strategy for ${app_name}`,
237
303
  initialValue: "semver",
238
- options: [{
239
- value: "semver",
240
- label: "Semver (1.2.3)"
241
- }, {
242
- value: "calver",
243
- label: "Calver (YYYY.MM.micro)"
244
- }]
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
+ ]
245
318
  });
246
319
  if (isCancel(version_choice)) {
247
320
  cancel("Initialization cancelled");
@@ -249,7 +322,7 @@ const init = create_command({
249
322
  }
250
323
  apps.push({
251
324
  name: app_name,
252
- packages: package_paths,
325
+ components,
253
326
  changelog_path,
254
327
  versioning: version_choice
255
328
  });
@@ -353,7 +426,8 @@ const init = create_command({
353
426
  await writeFile(config_path, generate_config_source({
354
427
  apps,
355
428
  changes_dir,
356
- release_branch_prefix,
429
+ target_branch,
430
+ default_release_branch_prefix,
357
431
  git: git_answers
358
432
  }), "utf-8");
359
433
  await create_changes_directories(context.cwd, changes_dir, apps);
@@ -361,7 +435,7 @@ const init = create_command({
361
435
  log.success("Generated auto-release.config.ts");
362
436
  log.success(`Change files directory: ${changes_dir}`);
363
437
  apps.forEach((app) => {
364
- log.success(`App ${app.name} ready with ${app.packages.length} package(s)`);
438
+ log.success(`App ${app.name} ready with ${app.components.length} component(s)`);
365
439
  });
366
440
  outro("auto-release init complete!");
367
441
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@afoures/auto-release",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "A file based release management tool for monorepos",
5
5
  "homepage": "https://github.com/afoures/auto-release#readme",
6
6
  "bugs": {
package/dist/package.mjs DELETED
@@ -1,5 +0,0 @@
1
- //#region package.json
2
- var name = "@afoures/auto-release";
3
-
4
- //#endregion
5
- export { name };