@git.zone/cli 2.14.3 → 2.16.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.
Files changed (55) hide show
  1. package/.smartconfig.json +36 -11
  2. package/assets/templates/service/npmextra.json +8 -2
  3. package/assets/templates/smartconfig/_smartconfig.json +5 -1
  4. package/assets/templates/website/npmextra.json +8 -2
  5. package/dist_ts/00_commitinfo_data.js +1 -1
  6. package/dist_ts/gitzone.cli.js +15 -1
  7. package/dist_ts/helpers.changelog.d.ts +16 -0
  8. package/dist_ts/helpers.changelog.js +114 -0
  9. package/dist_ts/helpers.smartconfigmigrations.d.ts +7 -0
  10. package/dist_ts/helpers.smartconfigmigrations.js +161 -0
  11. package/dist_ts/helpers.workflow.d.ts +97 -0
  12. package/dist_ts/helpers.workflow.js +258 -0
  13. package/dist_ts/mod_commit/index.js +190 -303
  14. package/dist_ts/mod_commit/mod.helpers.d.ts +23 -0
  15. package/dist_ts/mod_commit/mod.helpers.js +22 -15
  16. package/dist_ts/mod_commit/mod.ui.d.ts +1 -1
  17. package/dist_ts/mod_commit/mod.ui.js +7 -2
  18. package/dist_ts/mod_config/classes.commitconfig.d.ts +6 -0
  19. package/dist_ts/mod_config/classes.commitconfig.js +28 -4
  20. package/dist_ts/mod_config/classes.releaseconfig.js +13 -7
  21. package/dist_ts/mod_config/index.js +77 -29
  22. package/dist_ts/mod_format/formatters/smartconfig.formatter.js +3 -57
  23. package/dist_ts/mod_release/index.d.ts +3 -0
  24. package/dist_ts/mod_release/index.js +299 -0
  25. package/dist_ts/mod_release/mod.plugins.d.ts +3 -0
  26. package/dist_ts/mod_release/mod.plugins.js +4 -0
  27. package/dist_ts/mod_standard/index.js +29 -3
  28. package/dist_ts/mod_tools/classes.packagemanager.d.ts +27 -0
  29. package/dist_ts/mod_tools/classes.packagemanager.js +140 -0
  30. package/dist_ts/mod_tools/index.d.ts +4 -0
  31. package/dist_ts/mod_tools/index.js +290 -0
  32. package/dist_ts/mod_tools/mod.plugins.d.ts +1 -0
  33. package/dist_ts/mod_tools/mod.plugins.js +2 -0
  34. package/license +2 -2
  35. package/package.json +20 -30
  36. package/readme.hints.md +15 -17
  37. package/readme.md +251 -415
  38. package/ts/00_commitinfo_data.ts +1 -1
  39. package/ts/gitzone.cli.ts +16 -0
  40. package/ts/helpers.changelog.ts +165 -0
  41. package/ts/helpers.smartconfigmigrations.ts +192 -0
  42. package/ts/helpers.workflow.ts +387 -0
  43. package/ts/mod_commit/index.ts +233 -435
  44. package/ts/mod_commit/mod.helpers.ts +28 -16
  45. package/ts/mod_commit/mod.ui.ts +7 -2
  46. package/ts/mod_config/classes.commitconfig.ts +33 -3
  47. package/ts/mod_config/classes.releaseconfig.ts +14 -7
  48. package/ts/mod_config/index.ts +89 -28
  49. package/ts/mod_format/formatters/smartconfig.formatter.ts +2 -62
  50. package/ts/mod_release/index.ts +393 -0
  51. package/ts/mod_release/mod.plugins.ts +5 -0
  52. package/ts/mod_standard/index.ts +28 -2
  53. package/ts/mod_tools/classes.packagemanager.ts +176 -0
  54. package/ts/mod_tools/index.ts +359 -0
  55. package/ts/mod_tools/mod.plugins.ts +1 -0
@@ -0,0 +1,359 @@
1
+ import * as plugins from "./mod.plugins.js";
2
+ import { commitinfo } from "../00_commitinfo_data.js";
3
+ import type { ICliMode } from "../helpers.climode.js";
4
+ import { getCliMode, printJson } from "../helpers.climode.js";
5
+ import {
6
+ PackageManagerUtil,
7
+ type IInstalledPackage,
8
+ type IPackageUpdateInfo,
9
+ } from "./classes.packagemanager.js";
10
+
11
+ export const GITZONE_PACKAGES = [
12
+ "@git.zone/cli",
13
+ "@git.zone/tsdoc",
14
+ "@git.zone/tsbuild",
15
+ "@git.zone/tstest",
16
+ "@git.zone/tspublish",
17
+ "@git.zone/tsbundle",
18
+ "@git.zone/tsdocker",
19
+ "@git.zone/tsview",
20
+ "@git.zone/tswatch",
21
+ "@git.zone/tsrust",
22
+ ];
23
+
24
+ export const run = async (argvArg: any = {}): Promise<void> => {
25
+ const mode = await getCliMode(argvArg);
26
+ const command = argvArg._?.[1] || "help";
27
+
28
+ if (mode.help || command === "help") {
29
+ showHelp(mode);
30
+ return;
31
+ }
32
+
33
+ switch (command) {
34
+ case "update":
35
+ await runUpdate(argvArg, mode);
36
+ break;
37
+ case "install":
38
+ await runInstall(argvArg, mode);
39
+ break;
40
+ default:
41
+ showHelp(mode);
42
+ break;
43
+ }
44
+ };
45
+
46
+ async function runUpdate(argvArg: any, mode: ICliMode): Promise<void> {
47
+ const verbose = Boolean(argvArg.v || argvArg.verbose);
48
+ const pmUtil = new PackageManagerUtil();
49
+
50
+ console.log("Scanning for installed @git.zone packages...\n");
51
+
52
+ const pnpmInfo = await pmUtil.getPnpmVersionInfo();
53
+ if (!pnpmInfo.available) {
54
+ console.log("pnpm is required for gitzone tools update, but it was not found.");
55
+ return;
56
+ }
57
+
58
+ console.log("Package manager:\n");
59
+ console.log(" Name Current Latest Status");
60
+ console.log(" ----------------------------------------------");
61
+ const latestPnpm = (pnpmInfo.latestVersion || "unknown").padEnd(12);
62
+ const pnpmStatus = pnpmInfo.latestVersion === null
63
+ ? "? Version unknown"
64
+ : pnpmInfo.needsUpdate
65
+ ? "Update available"
66
+ : "Up to date";
67
+ console.log(` ${"pnpm".padEnd(9)}${pnpmInfo.currentVersion.padEnd(12)}${latestPnpm}${pnpmStatus}`);
68
+ console.log("");
69
+
70
+ if (verbose) {
71
+ console.log("Using pnpm as the supported global package manager.\n");
72
+ }
73
+
74
+ const selfUpdated = await handleSelfUpdate(pmUtil, mode);
75
+ if (selfUpdated) {
76
+ return;
77
+ }
78
+
79
+ const installedPackages = await pmUtil.getInstalledPackages();
80
+ const packageInfos = await getPackageUpdateInfos(pmUtil, installedPackages);
81
+
82
+ if (packageInfos.length === 0) {
83
+ console.log("No managed @git.zone packages found installed globally.");
84
+ return;
85
+ }
86
+
87
+ console.log("Installed @git.zone packages:\n");
88
+ console.log(" Package Current Latest Status");
89
+ console.log(" ------------------------------------------------------------");
90
+ for (const packageInfo of packageInfos) {
91
+ const status = packageInfo.latestVersion === "unknown"
92
+ ? "? Version unknown"
93
+ : packageInfo.needsUpdate
94
+ ? "Update available"
95
+ : "Up to date";
96
+ console.log(
97
+ ` ${packageInfo.name.padEnd(28)}${packageInfo.currentVersion.padEnd(12)}${packageInfo.latestVersion.padEnd(12)}${status}`,
98
+ );
99
+ }
100
+ console.log("");
101
+
102
+ await printMissingPackages(pmUtil, installedPackages);
103
+
104
+ const packagesToUpdate = packageInfos.filter((packageInfo) => packageInfo.needsUpdate);
105
+ if (packagesToUpdate.length === 0) {
106
+ console.log("All managed packages are up to date.");
107
+ return;
108
+ }
109
+
110
+ console.log(`Found ${packagesToUpdate.length} package(s) with available updates.\n`);
111
+
112
+ if (!mode.yes && !mode.interactive) {
113
+ console.log("Run gitzone tools update -y to update without prompts.");
114
+ return;
115
+ }
116
+
117
+ let shouldUpdate = mode.yes;
118
+ if (!shouldUpdate) {
119
+ const interactInstance = new plugins.smartinteract.SmartInteract();
120
+ const answer = await interactInstance.askQuestion({
121
+ type: "confirm",
122
+ name: "confirmUpdate",
123
+ message: "Do you want to update these packages?",
124
+ default: true,
125
+ });
126
+ shouldUpdate = answer.value === true;
127
+ }
128
+
129
+ if (!shouldUpdate) {
130
+ console.log("Update cancelled.");
131
+ return;
132
+ }
133
+
134
+ await installPackages(pmUtil, packagesToUpdate.map((packageInfo) => packageInfo.name), "updated");
135
+ }
136
+
137
+ async function runInstall(argvArg: any, mode: ICliMode): Promise<void> {
138
+ const verbose = Boolean(argvArg.v || argvArg.verbose);
139
+ const pmUtil = new PackageManagerUtil();
140
+
141
+ console.log("Scanning for missing @git.zone packages...\n");
142
+
143
+ const pnpmAvailable = await pmUtil.detectPnpm();
144
+ if (!pnpmAvailable) {
145
+ console.log("pnpm is required for gitzone tools install, but it was not found.");
146
+ return;
147
+ }
148
+
149
+ if (verbose) {
150
+ console.log("Using pnpm as the supported global package manager.\n");
151
+ }
152
+
153
+ const installedPackages = await pmUtil.getInstalledPackages();
154
+ const installedNames = new Set(installedPackages.map((packageInfo) => packageInfo.name));
155
+ const missingPackages = GITZONE_PACKAGES.filter((packageName) => !installedNames.has(packageName));
156
+
157
+ if (missingPackages.length === 0) {
158
+ console.log("All managed @git.zone packages are already installed.");
159
+ return;
160
+ }
161
+
162
+ console.log(`Found ${missingPackages.length} missing package(s).\n`);
163
+
164
+ if (!mode.yes && !mode.interactive) {
165
+ await printPackageListWithLatest(pmUtil, missingPackages);
166
+ console.log("Run gitzone tools install -y to install all missing packages without prompts.");
167
+ return;
168
+ }
169
+
170
+ let selectedPackages = missingPackages;
171
+ if (!mode.yes) {
172
+ const choicesWithVersions: Array<{ name: string; value: string }> = [];
173
+ for (const packageName of missingPackages) {
174
+ const latest = await pmUtil.getLatestVersion(packageName);
175
+ choicesWithVersions.push({
176
+ name: `${packageName}${latest ? `@${latest}` : ""}`,
177
+ value: packageName,
178
+ });
179
+ }
180
+
181
+ const interactInstance = new plugins.smartinteract.SmartInteract();
182
+ const answer = await interactInstance.askQuestion({
183
+ type: "checkbox",
184
+ name: "packages",
185
+ message: "Select packages to install:",
186
+ default: missingPackages,
187
+ choices: choicesWithVersions,
188
+ });
189
+
190
+ selectedPackages = answer.value as string[];
191
+ if (selectedPackages.length === 0) {
192
+ console.log("No packages selected. Nothing to install.");
193
+ return;
194
+ }
195
+ }
196
+
197
+ await installPackages(pmUtil, selectedPackages, "installed");
198
+ }
199
+
200
+ async function handleSelfUpdate(
201
+ pmUtil: PackageManagerUtil,
202
+ mode: ICliMode,
203
+ ): Promise<boolean> {
204
+ console.log("Checking for gitzone self-update...\n");
205
+ const currentVersion = commitinfo.version;
206
+ const latestVersion = await pmUtil.getLatestVersion("@git.zone/cli");
207
+
208
+ if (!latestVersion || !pmUtil.isNewerVersion(currentVersion, latestVersion)) {
209
+ console.log(` @git.zone/cli ${currentVersion} Up to date\n`);
210
+ return false;
211
+ }
212
+
213
+ console.log(` @git.zone/cli ${currentVersion} -> ${latestVersion} Update available\n`);
214
+
215
+ if (!mode.yes && !mode.interactive) {
216
+ console.log("Run gitzone tools update -y to update gitzone first.");
217
+ return true;
218
+ }
219
+
220
+ let shouldUpdate = mode.yes;
221
+ if (!shouldUpdate) {
222
+ const interactInstance = new plugins.smartinteract.SmartInteract();
223
+ const answer = await interactInstance.askQuestion({
224
+ type: "confirm",
225
+ name: "confirmSelfUpdate",
226
+ message: "Do you want to update gitzone itself first?",
227
+ default: true,
228
+ });
229
+ shouldUpdate = answer.value === true;
230
+ }
231
+
232
+ if (!shouldUpdate) {
233
+ console.log("Skipping gitzone self-update.\n");
234
+ return false;
235
+ }
236
+
237
+ const success = await pmUtil.installLatest("@git.zone/cli");
238
+ if (!success) {
239
+ console.log("\ngitzone self-update failed. Continuing with the current version.\n");
240
+ return false;
241
+ }
242
+
243
+ console.log("\ngitzone has been updated. Re-run gitzone tools update to check remaining packages.");
244
+ return true;
245
+ }
246
+
247
+ async function getPackageUpdateInfos(
248
+ pmUtil: PackageManagerUtil,
249
+ installedPackages: IInstalledPackage[],
250
+ ): Promise<IPackageUpdateInfo[]> {
251
+ const packageInfos: IPackageUpdateInfo[] = [];
252
+ for (const installedPackage of installedPackages) {
253
+ if (!GITZONE_PACKAGES.includes(installedPackage.name)) {
254
+ continue;
255
+ }
256
+ const latestVersion = await pmUtil.getLatestVersion(installedPackage.name);
257
+ packageInfos.push({
258
+ name: installedPackage.name,
259
+ currentVersion: installedPackage.version,
260
+ latestVersion: latestVersion || "unknown",
261
+ needsUpdate: latestVersion
262
+ ? pmUtil.isNewerVersion(installedPackage.version, latestVersion)
263
+ : false,
264
+ });
265
+ }
266
+ return packageInfos;
267
+ }
268
+
269
+ async function printMissingPackages(
270
+ pmUtil: PackageManagerUtil,
271
+ installedPackages: IInstalledPackage[],
272
+ ): Promise<void> {
273
+ const installedNames = new Set(installedPackages.map((packageInfo) => packageInfo.name));
274
+ const missingPackages = GITZONE_PACKAGES.filter((packageName) => !installedNames.has(packageName));
275
+ if (missingPackages.length === 0) {
276
+ return;
277
+ }
278
+
279
+ console.log("Not installed (managed @git.zone packages):\n");
280
+ await printPackageListWithLatest(pmUtil, missingPackages);
281
+ console.log("Run gitzone tools install to install missing packages.\n");
282
+ }
283
+
284
+ async function printPackageListWithLatest(
285
+ pmUtil: PackageManagerUtil,
286
+ packageNames: string[],
287
+ ): Promise<void> {
288
+ console.log(" Package Latest");
289
+ console.log(" ----------------------------------------");
290
+ for (const packageName of packageNames) {
291
+ const latest = await pmUtil.getLatestVersion(packageName);
292
+ console.log(` ${packageName.padEnd(28)} ${latest || "unknown"}`);
293
+ }
294
+ console.log("");
295
+ }
296
+
297
+ async function installPackages(
298
+ pmUtil: PackageManagerUtil,
299
+ packageNames: string[],
300
+ action: "installed" | "updated",
301
+ ): Promise<void> {
302
+ let successCount = 0;
303
+ let failCount = 0;
304
+
305
+ for (const packageName of packageNames) {
306
+ const success = await pmUtil.installLatest(packageName);
307
+ if (success) {
308
+ console.log(` ${packageName} ${action} successfully`);
309
+ successCount++;
310
+ } else {
311
+ console.log(` ${packageName} failed`);
312
+ failCount++;
313
+ }
314
+ }
315
+
316
+ console.log("");
317
+ if (failCount === 0) {
318
+ console.log(`All ${successCount} package(s) ${action} successfully.`);
319
+ } else {
320
+ console.log(`${successCount} package(s) ${action}, ${failCount} failed.`);
321
+ }
322
+ }
323
+
324
+ export function showHelp(mode?: ICliMode): void {
325
+ if (mode?.json) {
326
+ printJson({
327
+ name: "gitzone tools",
328
+ usage: "gitzone tools <command> [options]",
329
+ commands: [
330
+ { name: "update", description: "Check and update globally installed @git.zone packages" },
331
+ { name: "install", description: "Install missing managed @git.zone packages" },
332
+ ],
333
+ flags: [
334
+ { flag: "-y, --yes", description: "Run without confirmation prompts" },
335
+ { flag: "-v, --verbose", description: "Show package manager diagnostics" },
336
+ ],
337
+ packageManager: "pnpm",
338
+ managedPackages: GITZONE_PACKAGES,
339
+ });
340
+ return;
341
+ }
342
+
343
+ console.log("");
344
+ console.log("Usage: gitzone tools <command> [options]");
345
+ console.log("");
346
+ console.log("Commands:");
347
+ console.log(" update Check and update globally installed @git.zone packages");
348
+ console.log(" install Install missing managed @git.zone packages");
349
+ console.log("");
350
+ console.log("Options:");
351
+ console.log(" -y, --yes Run without confirmation prompts");
352
+ console.log(" -v, --verbose Show package manager diagnostics");
353
+ console.log("");
354
+ console.log("Examples:");
355
+ console.log(" gitzone tools update");
356
+ console.log(" gitzone tools update -y");
357
+ console.log(" gitzone tools install");
358
+ console.log("");
359
+ }
@@ -0,0 +1 @@
1
+ export * from "../plugins.js";