@xpack/xpm-lib 3.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 (94) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +223 -0
  3. package/dist/index.d.ts +16 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +30 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/lib/chmod-recursive.d.ts +7 -0
  8. package/dist/lib/chmod-recursive.d.ts.map +1 -0
  9. package/dist/lib/chmod-recursive.js +81 -0
  10. package/dist/lib/chmod-recursive.js.map +1 -0
  11. package/dist/lib/errors.d.ts +11 -0
  12. package/dist/lib/errors.d.ts.map +1 -0
  13. package/dist/lib/errors.js +26 -0
  14. package/dist/lib/errors.js.map +1 -0
  15. package/dist/lib/functions/chmod-recursive.d.ts +7 -0
  16. package/dist/lib/functions/chmod-recursive.d.ts.map +1 -0
  17. package/dist/lib/functions/chmod-recursive.js +81 -0
  18. package/dist/lib/functions/chmod-recursive.js.map +1 -0
  19. package/dist/lib/functions/perform-substitutions.d.ts +20 -0
  20. package/dist/lib/functions/perform-substitutions.d.ts.map +1 -0
  21. package/dist/lib/functions/perform-substitutions.js +85 -0
  22. package/dist/lib/functions/perform-substitutions.js.map +1 -0
  23. package/dist/lib/functions/utils.d.ts +30 -0
  24. package/dist/lib/functions/utils.d.ts.map +1 -0
  25. package/dist/lib/functions/utils.js +70 -0
  26. package/dist/lib/functions/utils.js.map +1 -0
  27. package/dist/lib/init-template-base.d.ts +46 -0
  28. package/dist/lib/init-template-base.d.ts.map +1 -0
  29. package/dist/lib/init-template-base.js +275 -0
  30. package/dist/lib/init-template-base.js.map +1 -0
  31. package/dist/lib/liquid-actions.d.ts +32 -0
  32. package/dist/lib/liquid-actions.d.ts.map +1 -0
  33. package/dist/lib/liquid-actions.js +113 -0
  34. package/dist/lib/liquid-actions.js.map +1 -0
  35. package/dist/lib/liquid-build-configurations.d.ts +49 -0
  36. package/dist/lib/liquid-build-configurations.d.ts.map +1 -0
  37. package/dist/lib/liquid-build-configurations.js +267 -0
  38. package/dist/lib/liquid-build-configurations.js.map +1 -0
  39. package/dist/lib/liquid-drop.d.ts +13 -0
  40. package/dist/lib/liquid-drop.d.ts.map +1 -0
  41. package/dist/lib/liquid-drop.js +56 -0
  42. package/dist/lib/liquid-drop.js.map +1 -0
  43. package/dist/lib/liquid-engine.d.ts +5 -0
  44. package/dist/lib/liquid-engine.d.ts.map +1 -0
  45. package/dist/lib/liquid-engine.js +85 -0
  46. package/dist/lib/liquid-engine.js.map +1 -0
  47. package/dist/lib/liquid-package.d.ts +17 -0
  48. package/dist/lib/liquid-package.d.ts.map +1 -0
  49. package/dist/lib/liquid-package.js +70 -0
  50. package/dist/lib/liquid-package.js.map +1 -0
  51. package/dist/lib/package.d.ts +66 -0
  52. package/dist/lib/package.d.ts.map +1 -0
  53. package/dist/lib/package.js +700 -0
  54. package/dist/lib/package.js.map +1 -0
  55. package/dist/lib/perform-substitutions.d.ts +20 -0
  56. package/dist/lib/perform-substitutions.d.ts.map +1 -0
  57. package/dist/lib/perform-substitutions.js +85 -0
  58. package/dist/lib/perform-substitutions.js.map +1 -0
  59. package/dist/lib/policies.d.ts +13 -0
  60. package/dist/lib/policies.d.ts.map +1 -0
  61. package/dist/lib/policies.js +31 -0
  62. package/dist/lib/policies.js.map +1 -0
  63. package/dist/lib/substitutions-variables.d.ts +117 -0
  64. package/dist/lib/substitutions-variables.d.ts.map +1 -0
  65. package/dist/lib/substitutions-variables.js +51 -0
  66. package/dist/lib/substitutions-variables.js.map +1 -0
  67. package/dist/lib/types.d.ts +70 -0
  68. package/dist/lib/types.d.ts.map +1 -0
  69. package/dist/lib/types.js +13 -0
  70. package/dist/lib/types.js.map +1 -0
  71. package/dist/lib/utils.d.ts +30 -0
  72. package/dist/lib/utils.d.ts.map +1 -0
  73. package/dist/lib/utils.js +70 -0
  74. package/dist/lib/utils.js.map +1 -0
  75. package/dist/tsconfig.tsbuildinfo +1 -0
  76. package/package.json +102 -0
  77. package/src/README.md +10 -0
  78. package/src/index.ts +35 -0
  79. package/src/lib/errors.ts +29 -0
  80. package/src/lib/functions/chmod-recursive.ts +103 -0
  81. package/src/lib/functions/perform-substitutions.ts +116 -0
  82. package/src/lib/functions/utils.ts +88 -0
  83. package/src/lib/init-template-base.ts +401 -0
  84. package/src/lib/liquid-actions.ts +179 -0
  85. package/src/lib/liquid-build-configurations.ts +410 -0
  86. package/src/lib/liquid-drop.ts +99 -0
  87. package/src/lib/liquid-engine.ts +135 -0
  88. package/src/lib/liquid-package.ts +108 -0
  89. package/src/lib/package.ts +946 -0
  90. package/src/lib/policies.ts +49 -0
  91. package/src/lib/substitutions-variables.ts +177 -0
  92. package/src/lib/types.ts +109 -0
  93. package/src/package.json +3 -0
  94. package/src/tsconfig.json +10 -0
@@ -0,0 +1,30 @@
1
+ export declare function isPrimitive(value: unknown): boolean;
2
+ export declare function isJsonObject(value: unknown): boolean;
3
+ export declare function isJsonArray(value: unknown): boolean;
4
+ export declare function isNonEmptyJsonObject(value: unknown): boolean;
5
+ export declare function isString(value: unknown): value is string;
6
+ /**
7
+ * Replace non alphanumeric chars with dashes to make the paths
8
+ * comply with filesystem names.
9
+ *
10
+ * @param {string} input A path candidate.
11
+ * @returns {string} A validated path.
12
+ */
13
+ export declare function filterPath(input: string): string;
14
+ /**
15
+ * Replace non alphanumeric chars with dashes to make the paths
16
+ * comply with Posix filesystem names.
17
+ *
18
+ * @param {string} input A path candidate.
19
+ * @returns {string} A validated path.
20
+ */
21
+ export declare function filterPosixPath(input: string): string;
22
+ /**
23
+ * Replace non alphanumeric chars with dashes to make the paths
24
+ * comply with Windows filesystem names.
25
+ *
26
+ * @param {string} input A path candidate.
27
+ * @returns {string} A validated path.
28
+ */
29
+ export declare function filterWin32Path(input: string): string;
30
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/lib/functions/utils.ts"],"names":[],"mappings":"AAmBA,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAInD;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEpD;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEnD;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAE5D;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAExD;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAShD;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAKrD;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAKrD"}
@@ -0,0 +1,70 @@
1
+ /*
2
+ * This file is part of the xPack project (http://xpack.github.io).
3
+ * Copyright (c) 2021-2026 Liviu Ionescu. All rights reserved.
4
+ *
5
+ * Permission to use, copy, modify, and/or distribute this software
6
+ * for any purpose is hereby granted, under the terms of the MIT license.
7
+ *
8
+ * If a copy of the license was not distributed with this file, it can
9
+ * be obtained from https://opensource.org/license/mit.
10
+ */
11
+ /* eslint max-len: [ "error", 80, { "ignoreUrls": true } ] */
12
+ // ----------------------------------------------------------------------------
13
+ import * as os from 'node:os';
14
+ // ----------------------------------------------------------------------------
15
+ export function isPrimitive(value) {
16
+ return ((typeof value !== 'object' && typeof value !== 'function') || value === null);
17
+ }
18
+ export function isJsonObject(value) {
19
+ return value !== undefined && !isPrimitive(value) && !Array.isArray(value);
20
+ }
21
+ export function isJsonArray(value) {
22
+ return value !== undefined && Array.isArray(value);
23
+ }
24
+ export function isNonEmptyJsonObject(value) {
25
+ return isJsonObject(value) && Object.keys(value).length > 0;
26
+ }
27
+ export function isString(value) {
28
+ return typeof value === 'string';
29
+ }
30
+ /**
31
+ * Replace non alphanumeric chars with dashes to make the paths
32
+ * comply with filesystem names.
33
+ *
34
+ * @param {string} input A path candidate.
35
+ * @returns {string} A validated path.
36
+ */
37
+ export function filterPath(input) {
38
+ /* c8 ignore start */ /* istanbul ignore next */
39
+ const fixed = os.platform() === 'win32'
40
+ ? input.replace(/[^a-zA-Z0-9\\:]+/g, '-')
41
+ : input.replace(/[^a-zA-Z0-9/]+/g, '-');
42
+ /* c8 ignore stop */
43
+ return fixed.replace(/--/g, '-');
44
+ }
45
+ /**
46
+ * Replace non alphanumeric chars with dashes to make the paths
47
+ * comply with Posix filesystem names.
48
+ *
49
+ * @param {string} input A path candidate.
50
+ * @returns {string} A validated path.
51
+ */
52
+ export function filterPosixPath(input) {
53
+ /* istanbul ignore next */
54
+ const fixed = input.replace(/[^a-zA-Z0-9/]+/g, '-');
55
+ return fixed.replace(/--/g, '-');
56
+ }
57
+ /**
58
+ * Replace non alphanumeric chars with dashes to make the paths
59
+ * comply with Windows filesystem names.
60
+ *
61
+ * @param {string} input A path candidate.
62
+ * @returns {string} A validated path.
63
+ */
64
+ export function filterWin32Path(input) {
65
+ /* istanbul ignore next */
66
+ const fixed = input.replace(/[^a-zA-Z0-9\\:]+/g, '-');
67
+ return fixed.replace(/--/g, '-');
68
+ }
69
+ // ----------------------------------------------------------------------------
70
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/lib/functions/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,6DAA6D;AAE7D,+EAA+E;AAE/E,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAE7B,+EAA+E;AAE/E,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,OAAO,CACL,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,UAAU,CAAC,IAAI,KAAK,KAAK,IAAI,CAC7E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0B;IAC1B,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,mBAAmB,EAAE,GAAG,CAAC,CAAA;IAErD,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;AAClC,CAAC;AAED,+EAA+E"}
@@ -0,0 +1,46 @@
1
+ import { Liquid } from 'liquidjs';
2
+ import { Logger } from '@xpack/logger';
3
+ import { XpmContext } from './types.js';
4
+ export type XpmInitTemplatePropertiesDefinitions = Record<string, XpmInitTemplatePropertiesDefinition>;
5
+ export interface XpmInitTemplatePropertiesDefinition {
6
+ label: string;
7
+ description: string;
8
+ type: 'select' | 'string' | 'number' | 'boolean';
9
+ items: Record<string, string | XpmInitTemplateItemValue>;
10
+ isMandatory?: boolean;
11
+ default?: string | number | boolean;
12
+ }
13
+ export type XpmInitTemplatePlatform = 'linux' | 'linux-x64' | 'linux-arm64' | 'win32' | 'darwin' | 'darwin-x64' | 'darwin-arm64';
14
+ export interface XpmInitTemplateItemValue {
15
+ platforms: XpmInitTemplatePlatform[];
16
+ message: string;
17
+ }
18
+ export interface XpmInitTemplateSubstitutionsVariables {
19
+ properties: Record<string, string | boolean | number>;
20
+ [key: string]: unknown;
21
+ }
22
+ export declare abstract class XpmInitTemplateBase {
23
+ context: XpmContext;
24
+ log: Logger;
25
+ propertiesDefinitions: XpmInitTemplatePropertiesDefinitions;
26
+ __dirname: string;
27
+ templatesPath: string;
28
+ engine: Liquid;
29
+ substitutionsVariables?: XpmInitTemplateSubstitutionsVariables;
30
+ constructor({ context, propertiesDefinitions, __dirname, templatesPath, }: {
31
+ context: XpmContext;
32
+ propertiesDefinitions: XpmInitTemplatePropertiesDefinitions;
33
+ __dirname: string;
34
+ templatesPath: string;
35
+ });
36
+ run(): Promise<void>;
37
+ abstract generate(isInteractive: boolean): Promise<void>;
38
+ validateValue(name: string, value: string): string | boolean | number;
39
+ askForMoreValues(): Promise<void>;
40
+ isPlatformSupported(platforms: string[] | undefined): boolean;
41
+ copyFile(sourceFileRelativePath: string, destinationFilePath?: string): Promise<void>;
42
+ copyFolder(source: string, destination?: string): Promise<void>;
43
+ copyFolderRecursive(sourceFolderPath: string, destinationFolderPath: string): Promise<void>;
44
+ render(inputFileRelativePath: string, outputFileRelativePath: string, substitutionsVariables?: XpmInitTemplateSubstitutionsVariables): Promise<void>;
45
+ }
46
+ //# sourceMappingURL=init-template-base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init-template-base.d.ts","sourceRoot":"","sources":["../../src/lib/init-template-base.ts"],"names":[],"mappings":"AA2BA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEjC,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAEtC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAMvC,MAAM,MAAM,oCAAoC,GAAG,MAAM,CACvD,MAAM,EACN,mCAAmC,CACpC,CAAA;AAED,MAAM,WAAW,mCAAmC;IAClD,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,MAAM,CAAA;IACnB,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAA;IAChD,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,wBAAwB,CAAC,CAAA;IACxD,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;CACpC;AAED,MAAM,MAAM,uBAAuB,GAC/B,OAAO,GACP,WAAW,GACX,aAAa,GACb,OAAO,GACP,QAAQ,GACR,YAAY,GACZ,cAAc,CAAA;AAElB,MAAM,WAAW,wBAAwB;IAEvC,SAAS,EAAE,uBAAuB,EAAE,CAAA;IACpC,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,qCAAqC;IACpD,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC,CAAA;IAC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275 @@
1
+ /*
2
+ * This file is part of the xPack project (http://xpack.github.io).
3
+ * Copyright (c) 2021-2026 Liviu Ionescu. All rights reserved.
4
+ *
5
+ * Permission to use, copy, modify, and/or distribute this software
6
+ * for any purpose is hereby granted, under the terms of the MIT license.
7
+ *
8
+ * If a copy of the license was not distributed with this file, it can
9
+ * be obtained from https://opensource.org/license/mit.
10
+ */
11
+ /* eslint max-len: [ "error", 80, { "ignoreUrls": true } ] */
12
+ // ----------------------------------------------------------------------------
13
+ import * as util from 'node:util';
14
+ import * as readline from 'node:readline/promises';
15
+ import * as path from 'node:path';
16
+ import * as fs from 'node:fs/promises';
17
+ // https://www.npmjs.com/package/make-dir
18
+ import { makeDirectory } from 'make-dir';
19
+ // https://www.npmjs.com/package/cp-file
20
+ import { copyFile } from 'cp-file';
21
+ // https://www.npmjs.com/package/liquidjs
22
+ import { Liquid } from 'liquidjs';
23
+ import { XpmOutputError, XpmSyntaxError } from './errors.js';
24
+ import assert from 'node:assert';
25
+ // ----------------------------------------------------------------------------
26
+ export class XpmInitTemplateBase {
27
+ // --------------------------------------------------------------------------
28
+ // Members.
29
+ context;
30
+ log;
31
+ propertiesDefinitions = {};
32
+ __dirname;
33
+ templatesPath;
34
+ engine;
35
+ substitutionsVariables;
36
+ // --------------------------------------------------------------------------
37
+ // Constructor.
38
+ constructor({ context, propertiesDefinitions, __dirname, templatesPath, }) {
39
+ this.context = context;
40
+ this.log = context.log;
41
+ this.propertiesDefinitions = propertiesDefinitions;
42
+ this.__dirname = __dirname;
43
+ this.templatesPath = templatesPath;
44
+ // https://liquidjs.com
45
+ this.engine = new Liquid({
46
+ root: this.templatesPath,
47
+ cache: false,
48
+ strictFilters: true, // default: false
49
+ strictVariables: true, // default: false
50
+ trimTagRight: false, // default: false
51
+ trimTagLeft: false, // default: false
52
+ greedy: false,
53
+ });
54
+ }
55
+ async run() {
56
+ const log = this.log;
57
+ log.trace(`${this.constructor.name}.run()`);
58
+ log.info();
59
+ const context = this.context;
60
+ const config = context.config;
61
+ assert(config.properties);
62
+ let isError = false;
63
+ for (const [key, val] of Object.entries(config.properties)) {
64
+ try {
65
+ config.properties[key] = this.validateValue(key, val);
66
+ }
67
+ catch (err) {
68
+ if (err instanceof Error) {
69
+ log.error(err.message);
70
+ }
71
+ isError = true;
72
+ }
73
+ }
74
+ if (isError) {
75
+ throw new XpmSyntaxError();
76
+ }
77
+ // Properties set by `--property name=value` are in `config.properties`.
78
+ // If there is at least one mandatory property without an explicit value,
79
+ // enter the interactive mode and ask for the missing values.
80
+ const mustAsk = Object.keys(this.propertiesDefinitions).some((key) => {
81
+ return (this.propertiesDefinitions[key].isMandatory && !config.properties?.[key]);
82
+ });
83
+ let isInteractive;
84
+ if (mustAsk) {
85
+ // Need to ask for more values.
86
+ if (!(process.stdin.isTTY && process.stdout.isTTY)) {
87
+ throw new XpmSyntaxError('Interactive mode not possible without a TTY.');
88
+ }
89
+ await this.askForMoreValues();
90
+ log.trace(util.inspect(config.properties));
91
+ // Reset start time to skip interactive time.
92
+ context.startTime = Date.now();
93
+ isInteractive = true;
94
+ }
95
+ else {
96
+ // Properties without explicit values get their defaults.
97
+ Object.entries(this.propertiesDefinitions).forEach(([key, val]) => {
98
+ assert(config.properties);
99
+ if (!config.properties[key] && val.default) {
100
+ config.properties[key] = val.default;
101
+ }
102
+ });
103
+ isInteractive = false;
104
+ }
105
+ const currentTime = new Date();
106
+ const substitutionsVariables = {
107
+ // Spread all config properties.
108
+ ...config.properties,
109
+ // Also pass the properties grouped.
110
+ properties: config.properties,
111
+ propertiesNames: Object.keys(config.properties),
112
+ projectName: config.projectName,
113
+ year: currentTime.getFullYear().toString(),
114
+ };
115
+ this.substitutionsVariables = substitutionsVariables;
116
+ await this.generate(isInteractive);
117
+ }
118
+ validateValue(name, value) {
119
+ const propDef = this.propertiesDefinitions[name];
120
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
121
+ if (propDef === undefined) {
122
+ throw new Error(`Unsupported property '${name}'`);
123
+ }
124
+ if (propDef.type === 'select') {
125
+ if (propDef.items[value]) {
126
+ if (typeof propDef.items[value] === 'string') {
127
+ return value;
128
+ }
129
+ else if (typeof propDef.items[value] === 'object' &&
130
+ this.isPlatformSupported(propDef.items[value].platforms)) {
131
+ return value;
132
+ }
133
+ }
134
+ }
135
+ else if (propDef.type === 'boolean') {
136
+ if (value === 'true') {
137
+ return true;
138
+ }
139
+ else if (value === 'false') {
140
+ return false;
141
+ }
142
+ }
143
+ else if (propDef.type === 'number') {
144
+ return Number(value);
145
+ }
146
+ if (value === '' && propDef.default !== undefined) {
147
+ return propDef.default;
148
+ }
149
+ throw new Error(`Unsupported value '${value}' for property '${name}'`);
150
+ }
151
+ async askForMoreValues() {
152
+ const context = this.context;
153
+ const config = context.config;
154
+ assert(config.properties);
155
+ const rl = readline.createInterface({
156
+ input: process.stdin,
157
+ output: process.stdout,
158
+ });
159
+ for (const name of Object.keys(this.propertiesDefinitions)) {
160
+ if (config.properties[name]) {
161
+ continue;
162
+ }
163
+ const definition = this.propertiesDefinitions[name];
164
+ let prompt = `${definition.label}?`;
165
+ if (definition.type === 'select') {
166
+ prompt += ' (';
167
+ const validItems = [];
168
+ for (const [ikey, ival] of Object.entries(definition.items)) {
169
+ if (typeof ival === 'string') {
170
+ validItems.push(ikey);
171
+ }
172
+ else if (typeof ival === 'object' &&
173
+ this.isPlatformSupported(ival.platforms)) {
174
+ validItems.push(ikey);
175
+ }
176
+ }
177
+ prompt += validItems.join(', ');
178
+ prompt += ', ?)';
179
+ }
180
+ else if (definition.type === 'boolean') {
181
+ prompt += ' (true, false, ?)';
182
+ }
183
+ if (definition.default !== undefined) {
184
+ prompt += ` [${String(definition.default)}]`;
185
+ }
186
+ prompt += ': ';
187
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
188
+ while (true) {
189
+ const answer = (await rl.question(prompt)).trim();
190
+ try {
191
+ const value = this.validateValue(name, answer);
192
+ config.properties[name] = value;
193
+ break;
194
+ }
195
+ catch (err) {
196
+ if (err instanceof Error) {
197
+ this.log.trace(err.message);
198
+ }
199
+ console.log(definition.description);
200
+ if (definition.type === 'select') {
201
+ for (const [ikey, ival] of Object.entries(definition.items)) {
202
+ if (typeof ival === 'string') {
203
+ console.log(`- ${ikey}: ${ival}`);
204
+ }
205
+ else if (typeof ival === 'object' &&
206
+ this.isPlatformSupported(ival.platforms)) {
207
+ console.log(`- ${ikey}: ${ival.message}`);
208
+ }
209
+ }
210
+ }
211
+ }
212
+ }
213
+ }
214
+ }
215
+ isPlatformSupported(platforms) {
216
+ if (!platforms || platforms.length === 0) {
217
+ return false;
218
+ }
219
+ if (platforms.includes(`${process.platform}-${process.arch}`)) {
220
+ return true;
221
+ }
222
+ if (platforms.includes(process.platform)) {
223
+ return true;
224
+ }
225
+ return false;
226
+ }
227
+ async copyFile(sourceFileRelativePath, destinationFilePath = sourceFileRelativePath) {
228
+ const log = this.log;
229
+ await makeDirectory(path.dirname(destinationFilePath));
230
+ const sourceFileAbsolutePath = path.resolve(this.templatesPath, sourceFileRelativePath);
231
+ await copyFile(sourceFileAbsolutePath, destinationFilePath);
232
+ log.info(`File '${destinationFilePath}' copied.`);
233
+ }
234
+ async copyFolder(source, destination = source) {
235
+ const log = this.log;
236
+ await this.copyFolderRecursive(path.resolve(this.templatesPath, source), path.resolve(destination));
237
+ log.info(`Folder '${destination}' copied.`);
238
+ }
239
+ async copyFolderRecursive(sourceFolderPath, destinationFolderPath) {
240
+ // const log = this.log
241
+ await makeDirectory(path.dirname(destinationFolderPath));
242
+ const dirents = await fs.readdir(sourceFolderPath, {
243
+ withFileTypes: true,
244
+ });
245
+ for (const dirent of dirents) {
246
+ // log.trace(dirent.name)
247
+ if (dirent.isDirectory()) {
248
+ await this.copyFolderRecursive(path.join(sourceFolderPath, dirent.name), path.join(destinationFolderPath, dirent.name));
249
+ }
250
+ else {
251
+ await copyFile(path.join(sourceFolderPath, dirent.name), path.join(destinationFolderPath, dirent.name));
252
+ }
253
+ }
254
+ }
255
+ async render(inputFileRelativePath, outputFileRelativePath,
256
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
257
+ substitutionsVariables = this.substitutionsVariables) {
258
+ const log = this.log;
259
+ log.trace(`render(${inputFileRelativePath}, ${outputFileRelativePath})`);
260
+ await makeDirectory(path.dirname(outputFileRelativePath));
261
+ // const headerPath = path.resolve(codePath, `${pnam}.h`)
262
+ try {
263
+ const fileContent = (await this.engine.renderFile(inputFileRelativePath, substitutionsVariables));
264
+ await fs.writeFile(outputFileRelativePath, fileContent, 'utf8');
265
+ }
266
+ catch (err) {
267
+ if (err instanceof Error) {
268
+ throw new XpmOutputError(err.message);
269
+ }
270
+ }
271
+ log.info(`File '${outputFileRelativePath}' generated.`);
272
+ }
273
+ }
274
+ // ----------------------------------------------------------------------------
275
+ //# sourceMappingURL=init-template-base.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init-template-base.js","sourceRoot":"","sources":["../../src/lib/init-template-base.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,6DAA6D;AAE7D,+EAA+E;AAE/E,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,KAAK,QAAQ,MAAM,wBAAwB,CAAA;AAClD,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAEtC,yCAAyC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC,wCAAwC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAElC,yCAAyC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAKjC,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC5D,OAAO,MAAM,MAAM,aAAa,CAAA;AAsChC,+EAA+E;AAE/E,MAAM,OAAgB,mBAAmB;IACvC,6EAA6E;IAC7E,WAAW;IAEX,OAAO,CAAY;IACnB,GAAG,CAAQ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AY,KAAK,EAAE,CAAC;gBACzB,MAAM,IAAI,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;YACvC,CAAC;QACH,CAAC;QACD,GAAG,CAAC,IAAI,CAAC,SAAS,sBAAsB,cAAc,CAAC,CAAA;IACzD,CAAC;CACF;AAED,+EAA+E"}
@@ -0,0 +1,32 @@
1
+ import { Logger } from '@xpack/logger';
2
+ import { XpmLiquidEngine } from './liquid-engine.js';
3
+ import { XpmLiquidSubstitutionsVariables, XpmLiquidSubstitutionsStrings } from './substitutions-variables.js';
4
+ import { JsonActions } from './types.js';
5
+ export declare class XpmLiquidActions {
6
+ #private;
7
+ readonly log: Logger;
8
+ readonly engine: XpmLiquidEngine;
9
+ readonly substitutionsVariables: XpmLiquidSubstitutionsVariables;
10
+ readonly jsonActions: JsonActions;
11
+ constructor({ log, engine, substitutionsVariables, jsonActions, }: {
12
+ log: Logger;
13
+ engine: XpmLiquidEngine;
14
+ substitutionsVariables: XpmLiquidSubstitutionsVariables;
15
+ jsonActions: JsonActions | undefined;
16
+ });
17
+ initialise(): Promise<void>;
18
+ empty(): boolean;
19
+ names(): string[];
20
+ has(actionName: string): boolean;
21
+ get(actionName: string): XpmLiquidAction;
22
+ }
23
+ export declare class XpmLiquidAction {
24
+ #private;
25
+ matrixParameters?: XpmLiquidSubstitutionsStrings;
26
+ constructor({ actionName, parentActions, }: {
27
+ actionName: string;
28
+ parentActions: XpmLiquidActions;
29
+ });
30
+ getCommands(): Promise<string[]>;
31
+ }
32
+ //# sourceMappingURL=liquid-actions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"liquid-actions.d.ts","sourceRoot":"","sources":["../../src/lib/liquid-actions.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAEtC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,EACL,+BAA+B,EAC/B,6BAA6B,EAC9B,MAAM,8BAA8B,CAAA;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAMxC,qBAAa,gBAAgB;;IAI3B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAA;IAChC,QAAQ,CAAC,sBAAsB,EAAE,+BAA+B,CAAA;IAChE,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAA;gBASrB,EACV,GAAG,EACH,MAAM,EACN,sBAAsB,EACtB,WAAW,GACZ,EAAE;QACD,GAAG,EAAE,MAAM,CAAA;QACX,MAAM,EAAE,eAAe,CAAA;QACvB,sBAAsB,EAAE,+BAA+B,CAAA;QACvD,WAAW,EAAE,WAAW,GAAG,SAAS,CAAA;KACrC;IAgBK,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAoBjC,KAAK,IAAI,OAAO;IAIhB,KAAK,IAAI,MAAM,EAAE;IAOjB,GAAG,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO;IAIhC,GAAG,CAAC,UAAU,EAAE,MAAM,GAAG,eAAe;CASzC;AAKD,qBAAa,eAAe;;IAQ1B,gBAAgB,CAAC,EAAE,6BAA6B,CAAA;gBAMpC,EACV,UAAU,EACV,aAAa,GACd,EAAE;QACD,UAAU,EAAE,MAAM,CAAA;QAClB,aAAa,EAAE,gBAAgB,CAAA;KAChC;IAUK,WAAW,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;CAwBvC"}
@@ -0,0 +1,113 @@
1
+ /*
2
+ * This file is part of the xPack project (http://xpack.github.io).
3
+ * Copyright (c) 2021-2026 Liviu Ionescu. All rights reserved.
4
+ *
5
+ * Permission to use, copy, modify, and/or distribute this software
6
+ * for any purpose is hereby granted, under the terms of the MIT license.
7
+ *
8
+ * If a copy of the license was not distributed with this file, it can
9
+ * be obtained from https://opensource.org/license/mit.
10
+ */
11
+ /* eslint max-len: [ "error", 80, { "ignoreUrls": true } ] */
12
+ // ----------------------------------------------------------------------------
13
+ // import assert from 'assert'
14
+ import os from 'node:os';
15
+ import { performSubstitutions } from './functions/perform-substitutions.js';
16
+ // ----------------------------------------------------------------------------
17
+ // A collection of actions.
18
+ export class XpmLiquidActions {
19
+ // --------------------------------------------------------------------------
20
+ // Members.
21
+ log;
22
+ engine;
23
+ substitutionsVariables;
24
+ jsonActions;
25
+ #map;
26
+ #isInitialised = false;
27
+ // --------------------------------------------------------------------------
28
+ // Constructor and async initialiser.
29
+ constructor({ log, engine, substitutionsVariables, jsonActions, }) {
30
+ log.trace(`${XpmLiquidActions.name}()`);
31
+ this.log = log;
32
+ this.engine = engine;
33
+ this.substitutionsVariables = substitutionsVariables;
34
+ this.jsonActions = jsonActions ?? {};
35
+ // Possibly empty if there are no actions.
36
+ this.#map = new Map();
37
+ // log.trace('substitutionsVariables => ', this.substitutionsVariables)
38
+ // The rest of the initialisation is done in the async initialiser.
39
+ }
40
+ // eslint-disable-next-line @typescript-eslint/require-await
41
+ async initialise() {
42
+ if (this.#isInitialised) {
43
+ return;
44
+ }
45
+ for (const actionName of Object.keys(this.jsonActions)) {
46
+ // TODO: expand templates in names
47
+ this.#map.set(actionName, undefined);
48
+ }
49
+ this.log.trace(`${XpmLiquidActions.name}.initialise() =>`, Array.from(this.#map.keys()));
50
+ this.#isInitialised = true;
51
+ }
52
+ // --------------------------------------------------------------------------
53
+ // Methods.
54
+ empty() {
55
+ return this.#map.size === 0;
56
+ }
57
+ names() {
58
+ const actionNames = Array.from(this.#map.keys());
59
+ this.log.trace(`${XpmLiquidActions.name}.names() =>`, actionNames);
60
+ return actionNames;
61
+ }
62
+ has(actionName) {
63
+ return this.#map.has(actionName);
64
+ }
65
+ get(actionName) {
66
+ let action = this.#map.get(actionName);
67
+ if (action === undefined) {
68
+ action = new XpmLiquidAction({ actionName, parentActions: this });
69
+ this.#map.set(actionName, action);
70
+ }
71
+ return action;
72
+ }
73
+ }
74
+ // ----------------------------------------------------------------------------
75
+ // An individual action.
76
+ export class XpmLiquidAction {
77
+ // --------------------------------------------------------------------------
78
+ // Members.
79
+ #actionName;
80
+ #parentActions;
81
+ // For templates, the actual values.
82
+ matrixParameters;
83
+ #commands;
84
+ // --------------------------------------------------------------------------
85
+ // Constructor.
86
+ constructor({ actionName, parentActions, }) {
87
+ parentActions.log.trace(`${XpmLiquidAction.name}(${actionName})`);
88
+ this.#actionName = actionName;
89
+ this.#parentActions = parentActions;
90
+ }
91
+ // --------------------------------------------------------------------------
92
+ // Methods.
93
+ async getCommands() {
94
+ if (this.#commands === undefined) {
95
+ // Silently accept empty or non-existing actions.
96
+ const jsonAction = this.#parentActions.jsonActions[this.#actionName] ?? '';
97
+ const input = Array.isArray(jsonAction)
98
+ ? jsonAction.join(os.EOL)
99
+ : jsonAction;
100
+ const substituted = await performSubstitutions({
101
+ input,
102
+ engine: this.#parentActions.engine,
103
+ substitutionsVariables: this.#parentActions.substitutionsVariables,
104
+ log: this.#parentActions.log,
105
+ });
106
+ this.#commands = substituted.split(os.EOL);
107
+ }
108
+ this.#parentActions.log.trace(`${XpmLiquidAction.name}.commands() =>`, this.#commands);
109
+ return this.#commands;
110
+ }
111
+ }
112
+ // ----------------------------------------------------------------------------
113
+ //# sourceMappingURL=liquid-actions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"liquid-actions.js","sourceRoot":"","sources":["../../src/lib/liquid-actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,6DAA6D;AAE7D,+EAA+E;AAE/E,8BAA8B;AAC9B,OAAO,EAAE,MAAM,SAAS,CAAA;AAUxB,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAA;AAE3E,+EAA+E;AAE/E,2BAA2B;AAC3B,MAAM,OAAO,gBAAgB;IAC3B,6EAA6E;IAC7E,WAAW;IAEF,GAAG,CAAQ;IACX,MAAM,CAAiB;IACvB,sBAAsB,CAAiC;IACvD,WAAW,CAAa;IAExB,IAAI,CAA0C;IAEvD,cAAc,GAAG,KAAK,CAAA;IAEtB,6EAA6E;IAC7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