@git.zone/cli 10.0.0 → 11.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.
Files changed (34) hide show
  1. package/.smartconfig.json +5 -3
  2. package/assets/templates/cli/cli.ts.js +1 -1
  3. package/assets/templates/npm/.package.json +4 -6
  4. package/assets/templates/npm/test/test.ts +1 -1
  5. package/assets/templates/service/.package.json +3 -6
  6. package/assets/templates/wcc/.package.json +3 -6
  7. package/assets/templates/wcc_update/html/index.html +2 -2
  8. package/assets/templates/website/.package.json +3 -6
  9. package/assets/templates/website/npmextra.json +3 -1
  10. package/assets/templates/website_update/html/index.html +4 -4
  11. package/dist_ts/00_commitinfo_data.js +1 -1
  12. package/dist_ts/helpers.packagefiles.js +2 -2
  13. package/dist_ts/helpers.tssea.d.ts +2 -2
  14. package/dist_ts/helpers.tssea.js +2 -2
  15. package/dist_ts/mod_commit/mod.plugins.d.ts +1 -1
  16. package/dist_ts/mod_commit/mod.plugins.js +2 -2
  17. package/dist_ts/mod_format/formatters/assets.formatter.js +2 -2
  18. package/dist_ts/mod_format/formatters/templates.formatter.d.ts +3 -2
  19. package/dist_ts/mod_format/formatters/templates.formatter.js +61 -14
  20. package/dist_ts/mod_format/formatters/tsconfig.formatter.js +2 -2
  21. package/dist_ts/mod_tools/index.js +3 -8
  22. package/dist_ts/plugins.d.ts +1 -1
  23. package/dist_ts/plugins.js +2 -2
  24. package/package.json +6 -11
  25. package/readme.md +10 -8
  26. package/ts/00_commitinfo_data.ts +1 -1
  27. package/ts/helpers.packagefiles.ts +1 -1
  28. package/ts/helpers.tssea.ts +4 -4
  29. package/ts/mod_commit/mod.plugins.ts +1 -1
  30. package/ts/mod_format/formatters/assets.formatter.ts +1 -1
  31. package/ts/mod_format/formatters/templates.formatter.ts +80 -14
  32. package/ts/mod_format/formatters/tsconfig.formatter.ts +1 -1
  33. package/ts/mod_tools/index.ts +2 -7
  34. package/ts/plugins.ts +1 -1
@@ -32,32 +32,86 @@ interface IJsonObjectParseOutcome {
32
32
  reason?: string;
33
33
  }
34
34
 
35
+ /**
36
+ * The rendered files of a template, or why it cannot render: a variable the
37
+ * configuration does not supply would render as an empty string.
38
+ */
39
+ type TTemplateRenderOutcome =
40
+ | { files: Map<string, string> }
41
+ | { unsatisfiedReasons: string[] };
42
+
43
+ /**
44
+ * Module values the templates link as `https://<value>/…`: a host with an
45
+ * optional port and path, never a whole URL or a trailing slash.
46
+ */
47
+ const templateHostKeys = ['assetbrokerUrl', 'legalUrl'];
48
+ const templateHostPattern = /^[a-z0-9]([a-z0-9.-]*[a-z0-9])?(:\d{1,5})?(\/[^\s/?#]+)*$/i;
49
+
50
+ /**
51
+ * The module values the templates render with. A blank value, or a host value
52
+ * that is not a bare host, is left out, so a template that uses it reports it
53
+ * as unsatisfied; the reason is kept for that report.
54
+ */
55
+ const getTemplateModuleVariables = (
56
+ moduleArg: object | undefined,
57
+ ): { module: Record<string, unknown>; unusableReasons: Map<string, string> } => {
58
+ const module: Record<string, unknown> = {};
59
+ const unusableReasons = new Map<string, string>();
60
+ for (const [key, value] of Object.entries(moduleArg ?? {})) {
61
+ if (value === undefined || value === null) {
62
+ continue;
63
+ }
64
+ if (typeof value === 'string' && value.trim() === '') {
65
+ unusableReasons.set(`module.${key}`, 'is empty');
66
+ } else if (
67
+ templateHostKeys.includes(key) &&
68
+ !(typeof value === 'string' && templateHostPattern.test(value))
69
+ ) {
70
+ unusableReasons.set(
71
+ `module.${key}`,
72
+ `is ${JSON.stringify(value)}, not a host (host[:port][/path], without a scheme or a trailing slash)`,
73
+ );
74
+ } else {
75
+ module[key] = value;
76
+ }
77
+ }
78
+ return { module, unusableReasons };
79
+ };
80
+
35
81
  export class TemplatesFormatter extends BaseFormatter {
36
- private replacementWarnings: IFormatWarning[] = [];
82
+ private templateWarnings: IFormatWarning[] = [];
37
83
 
38
84
  get name(): string {
39
85
  return 'templates';
40
86
  }
41
87
 
42
88
  async validate(): Promise<IFormatWarning[]> {
43
- return this.replacementWarnings;
89
+ return this.templateWarnings;
44
90
  }
45
91
 
46
92
  /**
47
- * Render a template directory and return a map of path → content.
93
+ * Render a template directory into a map of path → content. Templates read
94
+ * `module` and `projectType` from the `@git.zone/cli` configuration.
48
95
  */
49
- private async renderTemplate(templateName: string): Promise<Map<string, string>> {
96
+ private async renderTemplate(templateName: string): Promise<TTemplateRenderOutcome> {
50
97
  const templateDir = plugins.path.join(paths.templatesDir, templateName);
51
98
 
52
99
  const scafTemplate = new ScafTemplate(templateDir);
53
100
  await scafTemplate.readTemplateFromDir();
54
101
 
55
102
  const gitzoneData = this.project.gitzoneConfig?.data;
56
- if (gitzoneData) {
57
- await scafTemplate.supplyVariables({
58
- module: gitzoneData.module,
59
- projectType: gitzoneData.projectType,
60
- });
103
+ const { module, unusableReasons } = getTemplateModuleVariables(gitzoneData?.module);
104
+ await scafTemplate.supplyVariables({
105
+ module,
106
+ projectType: gitzoneData?.projectType,
107
+ });
108
+ if (scafTemplate.missingVariables.length > 0) {
109
+ return {
110
+ unsatisfiedReasons: scafTemplate.missingVariables.map(
111
+ (variableArg) =>
112
+ `@git.zone/cli.${variableArg} ${unusableReasons.get(variableArg) ?? 'is not set'}`,
113
+ ),
114
+ };
61
115
  }
62
116
 
63
117
  const renderedFiles = await scafTemplate.renderToMemory();
@@ -66,14 +120,14 @@ export class TemplatesFormatter extends BaseFormatter {
66
120
  for (const file of renderedFiles) {
67
121
  fileMap.set(file.path, file.contents.toString());
68
122
  }
69
- return fileMap;
123
+ return { files: fileMap };
70
124
  }
71
125
 
72
126
  async analyze(): Promise<IPlannedChange[]> {
73
127
  const changes: IPlannedChange[] = [];
74
128
  const project = this.project;
75
129
  const projectType = project.gitzoneConfig?.data?.projectType;
76
- this.replacementWarnings = [];
130
+ this.templateWarnings = [];
77
131
 
78
132
  // VSCode template - for all projects
79
133
  const vscodeChanges = await this.analyzeTemplate('vscode', [
@@ -218,15 +272,27 @@ export class TemplatesFormatter extends BaseFormatter {
218
272
  return changes;
219
273
  }
220
274
 
221
- let renderedFiles: Map<string, string>;
275
+ let rendered: TTemplateRenderOutcome;
222
276
  try {
223
- renderedFiles = await this.renderTemplate(templateName);
277
+ rendered = await this.renderTemplate(templateName);
224
278
  } catch (error) {
225
279
  const errorMessage = error instanceof Error ? error.message : String(error);
226
280
  logVerbose(`Failed to render template ${templateName}: ${errorMessage}`);
227
281
  return changes;
228
282
  }
229
283
 
284
+ // An unrendered variable would be written as an empty string (a page
285
+ // linking `https:///fonts/fonts.css`), so the plan carries an error instead,
286
+ // which also keeps `gitzone format --write` from writing anything.
287
+ if ('unsatisfiedReasons' in rendered) {
288
+ const destPaths = files.map((fileArg) => fileArg.destPath).join(', ');
289
+ const message = `The ${templateName} template cannot render ${destPaths} from .smartconfig.json: ${rendered.unsatisfiedReasons.join('; ')}.`;
290
+ this.templateWarnings.push({ level: 'error', message, module: this.name });
291
+ logVerbose(message);
292
+ return changes;
293
+ }
294
+ const renderedFiles = rendered.files;
295
+
230
296
  for (const file of files) {
231
297
  // Look up by templatePath first, then destPath (frontmatter may rename files)
232
298
  const processedContent = renderedFiles.get(file.templatePath)
@@ -256,7 +322,7 @@ export class TemplatesFormatter extends BaseFormatter {
256
322
  // where the decision is made: in the plan the user confirms.
257
323
  if (outcome.replacedReason) {
258
324
  const replacementMessage = `${file.destPath} is replaced by the ${templateName} template instead of merged, because ${outcome.replacedReason}. Top-level keys only this project declares are lost.`;
259
- this.replacementWarnings.push({
325
+ this.templateWarnings.push({
260
326
  level: 'warning',
261
327
  message: replacementMessage,
262
328
  module: this.name,
@@ -39,7 +39,7 @@ export class TsconfigFormatter extends BaseFormatter {
39
39
  // Get module paths from tspublish, merging with existing custom paths
40
40
  const tspublishPaths: Record<string, string[]> = {};
41
41
  try {
42
- const tsPublishMod = await import('@git.zone/tspublish');
42
+ const tsPublishMod = await import('@git.zone/tsrepo/publish');
43
43
  const tsPublishInstance = new tsPublishMod.TsPublish();
44
44
  const publishModules = await tsPublishInstance.getModuleSubDirs(paths.cwd);
45
45
 
@@ -11,16 +11,11 @@ import {
11
11
 
12
12
  export const GITZONE_PACKAGES = [
13
13
  "@git.zone/cli",
14
- "@git.zone/tsdoc",
15
- "@git.zone/tsbuild",
16
- "@git.zone/tstest",
17
- "@git.zone/tspublish",
18
- "@git.zone/tsbundle",
14
+ "@git.zone/tsrepo",
15
+ "@git.zone/rsrepo",
19
16
  "@git.zone/tsdocker",
20
17
  "@git.zone/tsdeploy",
21
18
  "@git.zone/tsview",
22
- "@git.zone/tswatch",
23
- "@git.zone/tsrust",
24
19
  ];
25
20
 
26
21
  export const run = async (argvArg: any = {}): Promise<void> => {
package/ts/plugins.ts CHANGED
@@ -27,7 +27,7 @@ import * as objectstorage from '@lossless.org/client/objectstorage';
27
27
 
28
28
  import * as s3 from '@aws-sdk/client-s3';
29
29
  import * as tsdockerReleaseProtocol from '@git.zone/tsdocker/dist_ts/classes.releaseprotocol.js';
30
- import * as tspublish from '@git.zone/tspublish';
30
+ import * as tspublish from '@git.zone/tsrepo/publish';
31
31
 
32
32
  export type {
33
33
  IReleaseCapabilitiesResult,