@git.zone/cli 8.2.1 → 8.2.3

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 (63) hide show
  1. package/dist_ts/00_commitinfo_data.js +1 -1
  2. package/dist_ts/gitzone.cli.js +8 -2
  3. package/dist_ts/gitzone.logging.js +2 -2
  4. package/dist_ts/mod_commit/mod.plugins.d.ts +1 -2
  5. package/dist_ts/mod_commit/mod.plugins.js +2 -3
  6. package/dist_ts/mod_deprecate/helpers.deprecation.d.ts +1 -1
  7. package/dist_ts/mod_deprecate/helpers.deprecation.js +32 -9
  8. package/dist_ts/mod_format/formatters/assets.formatter.js +3 -2
  9. package/dist_ts/mod_format/formatters/license.formatter.js +5 -3
  10. package/dist_ts/mod_format/formatters/templates.formatter.d.ts +1 -1
  11. package/dist_ts/mod_format/formatters/templates.formatter.js +4 -3
  12. package/dist_ts/mod_format/helpers.licensecheck.d.ts +12 -0
  13. package/dist_ts/mod_format/helpers.licensecheck.js +17 -0
  14. package/dist_ts/mod_format/mod.plugins.d.ts +1 -3
  15. package/dist_ts/mod_format/mod.plugins.js +2 -4
  16. package/dist_ts/mod_release/helpers.commitinfo.d.ts +20 -0
  17. package/dist_ts/mod_release/helpers.commitinfo.js +81 -0
  18. package/dist_ts/mod_release/helpers.npmartifact.d.ts +2 -0
  19. package/dist_ts/mod_release/helpers.npmartifact.js +4 -3
  20. package/dist_ts/mod_release/index.js +3 -5
  21. package/dist_ts/mod_release/mod.plugins.d.ts +0 -2
  22. package/dist_ts/mod_release/mod.plugins.js +1 -3
  23. package/dist_ts/mod_services/classes.dockercontainer.js +3 -3
  24. package/dist_ts/mod_services/classes.interprocesslock.js +2 -2
  25. package/dist_ts/mod_services/classes.legacymongomigration.js +2 -2
  26. package/dist_ts/mod_services/classes.servicemanager.js +2 -2
  27. package/dist_ts/mod_services/index.js +5 -5
  28. package/dist_ts/mod_services/mod.plugins.d.ts +1 -2
  29. package/dist_ts/mod_services/mod.plugins.js +2 -3
  30. package/dist_ts/mod_template/classes.scaftemplate.d.ts +44 -0
  31. package/dist_ts/mod_template/classes.scaftemplate.js +115 -0
  32. package/dist_ts/mod_template/index.d.ts +2 -2
  33. package/dist_ts/mod_template/index.js +3 -2
  34. package/dist_ts/mod_template/mod.plugins.d.ts +6 -2
  35. package/dist_ts/mod_template/mod.plugins.js +7 -3
  36. package/dist_ts/plugins.d.ts +1 -2
  37. package/dist_ts/plugins.js +2 -3
  38. package/package.json +7 -8
  39. package/readme.md +8 -4
  40. package/ts/00_commitinfo_data.ts +1 -1
  41. package/ts/gitzone.cli.ts +8 -5
  42. package/ts/gitzone.logging.ts +1 -1
  43. package/ts/mod_commit/mod.plugins.ts +1 -2
  44. package/ts/mod_deprecate/helpers.deprecation.ts +63 -15
  45. package/ts/mod_format/formatters/assets.formatter.ts +2 -1
  46. package/ts/mod_format/formatters/license.formatter.ts +11 -6
  47. package/ts/mod_format/formatters/templates.formatter.ts +3 -2
  48. package/ts/mod_format/helpers.licensecheck.ts +40 -0
  49. package/ts/mod_format/mod.plugins.ts +0 -4
  50. package/ts/mod_release/helpers.commitinfo.ts +108 -0
  51. package/ts/mod_release/helpers.npmartifact.ts +3 -2
  52. package/ts/mod_release/index.ts +2 -4
  53. package/ts/mod_release/mod.plugins.ts +0 -4
  54. package/ts/mod_services/classes.dockercontainer.ts +2 -2
  55. package/ts/mod_services/classes.interprocesslock.ts +1 -1
  56. package/ts/mod_services/classes.legacymongomigration.ts +1 -1
  57. package/ts/mod_services/classes.servicemanager.ts +1 -1
  58. package/ts/mod_services/index.ts +4 -4
  59. package/ts/mod_services/mod.plugins.ts +1 -2
  60. package/ts/mod_template/classes.scaftemplate.ts +159 -0
  61. package/ts/mod_template/index.ts +2 -1
  62. package/ts/mod_template/mod.plugins.ts +7 -2
  63. package/ts/plugins.ts +0 -2
@@ -0,0 +1,159 @@
1
+ import * as plugins from './mod.plugins.js';
2
+ import { answerDefaultsWithoutTerminal, withPrompts } from '../helpers.prompts.js';
3
+
4
+ /** The file at the root of a template folder that configures the template. */
5
+ export const scafConfigFileName = '.smartscaf.yml';
6
+
7
+ /** The content of a template's `.smartscaf.yml`. */
8
+ export interface IScafTemplateConfig {
9
+ /** The answers offered for missing variables, keyed by their dotted name. */
10
+ defaults: Record<string, unknown>;
11
+ /** Template folders, relative to this one, whose files are merged into it. */
12
+ dependencies: {
13
+ merge: string[];
14
+ };
15
+ /** Shell commands run in the destination after the template is written. */
16
+ runafter: string[];
17
+ }
18
+
19
+ /**
20
+ * A handlebars template folder: every file is rendered with the supplied
21
+ * variables, a `fileName` frontmatter entry renames the rendered file, and
22
+ * `{-{ … }-}` survives rendering as `{{ … }}`.
23
+ */
24
+ export class ScafTemplate {
25
+ public readonly dirPath: string;
26
+ public config: IScafTemplateConfig = {
27
+ defaults: {},
28
+ dependencies: { merge: [] },
29
+ runafter: [],
30
+ };
31
+ /** The template files, followed by the files of every merged template. */
32
+ public templateFiles: plugins.smartfile.SmartFile[] = [];
33
+ public suppliedVariables: Record<string, unknown> = {};
34
+ public missingVariables: string[] = [];
35
+
36
+ constructor(dirPathArg: string) {
37
+ this.dirPath = plugins.path.resolve(dirPathArg);
38
+ }
39
+
40
+ /** Reads the template folder, its configuration and the templates it merges. */
41
+ public async readTemplateFromDir(): Promise<void> {
42
+ const ownFiles = await readFolderFiles(this.dirPath);
43
+ const configFile = ownFiles.find((fileArg) => fileArg.path === scafConfigFileName);
44
+ const parsedConfig = configFile
45
+ ? ((await plugins.smartyaml.yamlStringToObject(
46
+ configFile.contents.toString(),
47
+ )) as Partial<IScafTemplateConfig> | null)
48
+ : null;
49
+ this.config = {
50
+ defaults: parsedConfig?.defaults ?? {},
51
+ dependencies: { merge: parsedConfig?.dependencies?.merge ?? [] },
52
+ runafter: parsedConfig?.runafter ?? [],
53
+ };
54
+
55
+ this.templateFiles = ownFiles;
56
+ for (const dependency of this.config.dependencies.merge) {
57
+ const dependencyDir = plugins.path.join(this.dirPath, dependency);
58
+ if (!(await plugins.smartfs.directory(dependencyDir).exists())) {
59
+ throw new Error(
60
+ `Template ${this.dirPath} merges ${dependency}, which is not a folder at ${dependencyDir}`,
61
+ );
62
+ }
63
+ this.templateFiles.push(...(await readFolderFiles(dependencyDir)));
64
+ }
65
+ }
66
+
67
+ /** Merges the given variables into the supplied ones and updates the missing variables. */
68
+ public async supplyVariables(variablesArg: Record<string, unknown>): Promise<void> {
69
+ this.suppliedVariables = {
70
+ ...this.suppliedVariables,
71
+ ...variablesArg,
72
+ };
73
+ this.missingVariables = await this.findMissingVariables();
74
+ }
75
+
76
+ /**
77
+ * Asks for every missing variable, offering the template default. Without an
78
+ * interactive terminal the defaults are taken.
79
+ */
80
+ public async askCliForMissingVariables(): Promise<void> {
81
+ this.missingVariables = await this.findMissingVariables();
82
+ if (this.missingVariables.length === 0) {
83
+ return;
84
+ }
85
+ const questions: plugins.smartconsole.IInputQuestion[] = this.missingVariables.map(
86
+ (variableArg) => {
87
+ const defaultValue = this.config.defaults[variableArg];
88
+ return {
89
+ name: variableArg,
90
+ type: 'input',
91
+ default: defaultValue ? String(defaultValue) : 'undefined variable',
92
+ message: `What is the value of ${variableArg}?`,
93
+ };
94
+ },
95
+ );
96
+ const answers = await withPrompts((promptsArg) =>
97
+ promptsArg.askAll(questions, answerDefaultsWithoutTerminal),
98
+ );
99
+ for (const [variable, value] of Object.entries(answers)) {
100
+ plugins.smartobject.smartAdd(this.suppliedVariables, variable, value);
101
+ }
102
+ }
103
+
104
+ /** Renders every template file in memory; the template files stay untouched. */
105
+ public async renderToMemory(): Promise<plugins.smartfile.SmartFile[]> {
106
+ const renderedFiles: plugins.smartfile.SmartFile[] = [];
107
+ for (const templateFile of this.getContentFiles()) {
108
+ const document = await plugins.smartmarkdown.parseFrontmatter(
109
+ plugins.smarthbs.renderString(templateFile.contents.toString(), this.suppliedVariables),
110
+ );
111
+ const fileName = document.data.fileName;
112
+ const filePath =
113
+ typeof fileName === 'string' && fileName
114
+ ? plugins.path.join(plugins.path.dirname(templateFile.path), fileName)
115
+ : templateFile.path;
116
+ renderedFiles.push(
117
+ plugins.smartFileFactory.fromBuffer(
118
+ filePath,
119
+ Buffer.from(await plugins.smarthbs.postprocess(document.content)),
120
+ templateFile.base,
121
+ ),
122
+ );
123
+ }
124
+ return renderedFiles;
125
+ }
126
+
127
+ /** Renders the template into the destination folder and runs its `runafter` commands there. */
128
+ public async writeToDisk(destinationDirArg: string): Promise<void> {
129
+ const renderedFiles = await this.renderToMemory();
130
+ await plugins.smartFileFactory
131
+ .virtualDirectoryFromFileArray(renderedFiles)
132
+ .saveToDisk(destinationDirArg);
133
+ const smartshellInstance = new plugins.smartshell.Smartshell({ executor: 'bash' });
134
+ for (const command of this.config.runafter) {
135
+ await smartshellInstance.execStrict(command, { cwd: destinationDirArg });
136
+ }
137
+ }
138
+
139
+ /** The files that get rendered: everything except the configuration of each merged template. */
140
+ private getContentFiles(): plugins.smartfile.SmartFile[] {
141
+ return this.templateFiles.filter((fileArg) => fileArg.path !== scafConfigFileName);
142
+ }
143
+
144
+ private async findMissingVariables(): Promise<string[]> {
145
+ const missingVariables = new Set<string>();
146
+ for (const templateFile of this.getContentFiles()) {
147
+ for (const variable of await plugins.smarthbs.checkVarsSatisfaction(
148
+ templateFile.contents.toString(),
149
+ this.suppliedVariables,
150
+ )) {
151
+ missingVariables.add(variable);
152
+ }
153
+ }
154
+ return [...missingVariables];
155
+ }
156
+ }
157
+
158
+ const readFolderFiles = async (dirPathArg: string): Promise<plugins.smartfile.SmartFile[]> =>
159
+ (await plugins.smartFileFactory.virtualDirectoryFromPath(dirPathArg)).listFiles();
@@ -1,5 +1,6 @@
1
1
  import * as plugins from './mod.plugins.js';
2
2
  import * as paths from '../paths.js';
3
+ import { ScafTemplate } from './classes.scaftemplate.js';
3
4
 
4
5
  import { logger } from '../gitzone.logging.js';
5
6
  import { answerDefaultsWithoutTerminal, ask, stringChoices } from '../helpers.prompts.js';
@@ -17,7 +18,7 @@ export const isTemplate = async (templateNameArg: string) => {
17
18
 
18
19
  export const getTemplate = async (templateNameArg: string) => {
19
20
  if (await isTemplate(templateNameArg)) {
20
- const localScafTemplate = new plugins.smartscaf.ScafTemplate(
21
+ const localScafTemplate = new ScafTemplate(
21
22
  getTemplatePath(templateNameArg),
22
23
  );
23
24
  await localScafTemplate.readTemplateFromDir();
@@ -1,6 +1,11 @@
1
1
  export * from '../plugins.js';
2
2
 
3
3
  import * as smartfile from '@push.rocks/smartfile';
4
- import * as smartscaf from '@push.rocks/smartscaf';
4
+ import * as smarthbs from '@push.rocks/smarthbs/iso';
5
+ import * as smartmarkdown from '@push.rocks/smartmarkdown/iso';
6
+ import * as smartobject from '@push.rocks/smartobject';
7
+ import * as smartyaml from '@push.rocks/smartyaml';
5
8
 
6
- export { smartfile, smartscaf };
9
+ export const smartFileFactory = smartfile.SmartFileFactory.nodeFs();
10
+
11
+ export { smartfile, smarthbs, smartmarkdown, smartobject, smartyaml };
package/ts/plugins.ts CHANGED
@@ -18,7 +18,6 @@ import * as smartshell from '@push.rocks/smartshell';
18
18
  import * as smartnetwork from '@push.rocks/smartnetwork';
19
19
  import * as smartfile from '@push.rocks/smartfile';
20
20
  import { SmartFs, SmartFsProviderNode } from '@push.rocks/smartfs';
21
- import * as smartdelay from '@push.rocks/smartdelay';
22
21
 
23
22
  // @lossless.org scope
24
23
  import * as objectstorage from '@lossless.org/client/objectstorage';
@@ -68,7 +67,6 @@ export {
68
67
  smartshell,
69
68
  smartnetwork,
70
69
  smartfile,
71
- smartdelay,
72
70
  objectstorage,
73
71
  s3,
74
72
  tsdockerReleaseProtocol,