@xpack/xpm-lib 3.1.2 → 4.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 (202) hide show
  1. package/README.md +16 -212
  2. package/dist/classes/actions.d.ts +58 -0
  3. package/dist/classes/actions.d.ts.map +1 -0
  4. package/dist/classes/actions.js +250 -0
  5. package/dist/classes/actions.js.map +1 -0
  6. package/dist/classes/build-configurations.d.ts +78 -0
  7. package/dist/classes/build-configurations.d.ts.map +1 -0
  8. package/dist/classes/build-configurations.js +489 -0
  9. package/dist/classes/build-configurations.js.map +1 -0
  10. package/dist/classes/combinations-generator.d.ts +19 -0
  11. package/dist/classes/combinations-generator.d.ts.map +1 -0
  12. package/dist/classes/combinations-generator.js +48 -0
  13. package/dist/classes/combinations-generator.js.map +1 -0
  14. package/dist/classes/data-model.d.ts +21 -0
  15. package/dist/classes/data-model.d.ts.map +1 -0
  16. package/dist/classes/data-model.js +47 -0
  17. package/dist/classes/data-model.js.map +1 -0
  18. package/dist/classes/errors.d.ts +13 -0
  19. package/dist/classes/errors.d.ts.map +1 -0
  20. package/dist/classes/errors.js +13 -0
  21. package/dist/classes/errors.js.map +1 -0
  22. package/dist/classes/init-template-base.d.ts +47 -0
  23. package/dist/classes/init-template-base.d.ts.map +1 -0
  24. package/dist/classes/init-template-base.js +358 -0
  25. package/dist/classes/init-template-base.js.map +1 -0
  26. package/dist/classes/liquid-drop.d.ts +28 -0
  27. package/dist/classes/liquid-drop.d.ts.map +1 -0
  28. package/dist/classes/liquid-drop.js +70 -0
  29. package/dist/classes/liquid-drop.js.map +1 -0
  30. package/dist/classes/liquid-engine.d.ts +7 -0
  31. package/dist/classes/liquid-engine.d.ts.map +1 -0
  32. package/dist/classes/liquid-engine.js +72 -0
  33. package/dist/classes/liquid-engine.js.map +1 -0
  34. package/dist/classes/package.d.ts +31 -0
  35. package/dist/classes/package.d.ts.map +1 -0
  36. package/dist/classes/package.js +268 -0
  37. package/dist/classes/package.js.map +1 -0
  38. package/dist/classes/platform-detector.d.ts +14 -0
  39. package/dist/classes/platform-detector.d.ts.map +1 -0
  40. package/dist/classes/platform-detector.js +26 -0
  41. package/dist/classes/platform-detector.js.map +1 -0
  42. package/dist/classes/policies.d.ts +14 -0
  43. package/dist/classes/policies.d.ts.map +1 -0
  44. package/dist/classes/policies.js +20 -0
  45. package/dist/classes/policies.js.map +1 -0
  46. package/dist/classes/template-expander.d.ts +29 -0
  47. package/dist/classes/template-expander.d.ts.map +1 -0
  48. package/dist/classes/template-expander.js +62 -0
  49. package/dist/classes/template-expander.js.map +1 -0
  50. package/dist/data/substitutions-variables.d.ts +43 -0
  51. package/dist/data/substitutions-variables.d.ts.map +1 -0
  52. package/dist/{lib → data}/substitutions-variables.js +1 -16
  53. package/dist/data/substitutions-variables.js.map +1 -0
  54. package/dist/functions/chmod-recursively.d.ts +9 -0
  55. package/dist/functions/chmod-recursively.d.ts.map +1 -0
  56. package/dist/functions/chmod-recursively.js +66 -0
  57. package/dist/functions/chmod-recursively.js.map +1 -0
  58. package/dist/functions/filter-paths.d.ts +5 -0
  59. package/dist/functions/filter-paths.d.ts.map +1 -0
  60. package/dist/functions/filter-paths.js +16 -0
  61. package/dist/functions/filter-paths.js.map +1 -0
  62. package/dist/functions/is-something.d.ts +9 -0
  63. package/dist/functions/is-something.d.ts.map +1 -0
  64. package/dist/functions/is-something.js +25 -0
  65. package/dist/functions/is-something.js.map +1 -0
  66. package/dist/functions/matrix-expander.d.ts +17 -0
  67. package/dist/functions/matrix-expander.d.ts.map +1 -0
  68. package/dist/functions/matrix-expander.js +52 -0
  69. package/dist/functions/matrix-expander.js.map +1 -0
  70. package/dist/functions/perform-substitutions.d.ts +12 -0
  71. package/dist/functions/perform-substitutions.d.ts.map +1 -0
  72. package/dist/functions/perform-substitutions.js +76 -0
  73. package/dist/functions/perform-substitutions.js.map +1 -0
  74. package/dist/functions/utils.d.ts +8 -0
  75. package/dist/functions/utils.d.ts.map +1 -0
  76. package/dist/functions/utils.js +16 -0
  77. package/dist/functions/utils.js.map +1 -0
  78. package/dist/index.d.ts +22 -15
  79. package/dist/index.d.ts.map +1 -1
  80. package/dist/index.js +22 -29
  81. package/dist/index.js.map +1 -1
  82. package/dist/{lib/types.d.ts → types/json.d.ts} +31 -22
  83. package/dist/types/json.d.ts.map +1 -0
  84. package/dist/types/json.js +2 -0
  85. package/dist/types/json.js.map +1 -0
  86. package/dist/types/xpm-init-template.d.ts +21 -0
  87. package/dist/types/xpm-init-template.d.ts.map +1 -0
  88. package/dist/types/xpm-init-template.js +2 -0
  89. package/dist/types/xpm-init-template.js.map +1 -0
  90. package/dist/types/xpm.d.ts +16 -0
  91. package/dist/types/xpm.d.ts.map +1 -0
  92. package/dist/types/xpm.js +2 -0
  93. package/dist/types/xpm.js.map +1 -0
  94. package/package.json +53 -44
  95. package/src/CODE-REVIEW.md +2167 -0
  96. package/src/README.md +393 -6
  97. package/src/classes/actions.ts +1157 -0
  98. package/src/classes/build-configurations.ts +2127 -0
  99. package/src/classes/combinations-generator.ts +331 -0
  100. package/src/classes/data-model.ts +337 -0
  101. package/src/classes/errors.ts +105 -0
  102. package/src/classes/init-template-base.ts +1028 -0
  103. package/src/classes/liquid-drop.ts +376 -0
  104. package/src/classes/liquid-engine.ts +249 -0
  105. package/src/classes/package.ts +765 -0
  106. package/src/classes/platform-detector.ts +237 -0
  107. package/src/classes/policies.ts +200 -0
  108. package/src/classes/template-expander.ts +330 -0
  109. package/src/data/substitutions-variables.ts +390 -0
  110. package/src/functions/chmod-recursively.ts +195 -0
  111. package/src/functions/filter-paths.ts +126 -0
  112. package/src/functions/is-something.ts +223 -0
  113. package/src/functions/matrix-expander.ts +172 -0
  114. package/src/functions/perform-substitutions.ts +253 -0
  115. package/src/functions/utils.ts +151 -0
  116. package/src/index.ts +72 -19
  117. package/src/types/json.ts +519 -0
  118. package/src/types/xpm-init-template.ts +282 -0
  119. package/src/types/xpm.ts +162 -0
  120. package/dist/lib/chmod-recursive.d.ts +0 -7
  121. package/dist/lib/chmod-recursive.d.ts.map +0 -1
  122. package/dist/lib/chmod-recursive.js +0 -81
  123. package/dist/lib/chmod-recursive.js.map +0 -1
  124. package/dist/lib/errors.d.ts +0 -11
  125. package/dist/lib/errors.d.ts.map +0 -1
  126. package/dist/lib/errors.js +0 -26
  127. package/dist/lib/errors.js.map +0 -1
  128. package/dist/lib/functions/chmod-recursive.d.ts +0 -7
  129. package/dist/lib/functions/chmod-recursive.d.ts.map +0 -1
  130. package/dist/lib/functions/chmod-recursive.js +0 -81
  131. package/dist/lib/functions/chmod-recursive.js.map +0 -1
  132. package/dist/lib/functions/perform-substitutions.d.ts +0 -20
  133. package/dist/lib/functions/perform-substitutions.d.ts.map +0 -1
  134. package/dist/lib/functions/perform-substitutions.js +0 -85
  135. package/dist/lib/functions/perform-substitutions.js.map +0 -1
  136. package/dist/lib/functions/utils.d.ts +0 -30
  137. package/dist/lib/functions/utils.d.ts.map +0 -1
  138. package/dist/lib/functions/utils.js +0 -70
  139. package/dist/lib/functions/utils.js.map +0 -1
  140. package/dist/lib/init-template-base.d.ts +0 -46
  141. package/dist/lib/init-template-base.d.ts.map +0 -1
  142. package/dist/lib/init-template-base.js +0 -281
  143. package/dist/lib/init-template-base.js.map +0 -1
  144. package/dist/lib/liquid-actions.d.ts +0 -37
  145. package/dist/lib/liquid-actions.d.ts.map +0 -1
  146. package/dist/lib/liquid-actions.js +0 -148
  147. package/dist/lib/liquid-actions.js.map +0 -1
  148. package/dist/lib/liquid-build-configurations.d.ts +0 -47
  149. package/dist/lib/liquid-build-configurations.d.ts.map +0 -1
  150. package/dist/lib/liquid-build-configurations.js +0 -282
  151. package/dist/lib/liquid-build-configurations.js.map +0 -1
  152. package/dist/lib/liquid-drop.d.ts +0 -13
  153. package/dist/lib/liquid-drop.d.ts.map +0 -1
  154. package/dist/lib/liquid-drop.js +0 -56
  155. package/dist/lib/liquid-drop.js.map +0 -1
  156. package/dist/lib/liquid-engine.d.ts +0 -5
  157. package/dist/lib/liquid-engine.d.ts.map +0 -1
  158. package/dist/lib/liquid-engine.js +0 -85
  159. package/dist/lib/liquid-engine.js.map +0 -1
  160. package/dist/lib/liquid-package.d.ts +0 -17
  161. package/dist/lib/liquid-package.d.ts.map +0 -1
  162. package/dist/lib/liquid-package.js +0 -70
  163. package/dist/lib/liquid-package.js.map +0 -1
  164. package/dist/lib/package.d.ts +0 -66
  165. package/dist/lib/package.d.ts.map +0 -1
  166. package/dist/lib/package.js +0 -700
  167. package/dist/lib/package.js.map +0 -1
  168. package/dist/lib/perform-substitutions.d.ts +0 -20
  169. package/dist/lib/perform-substitutions.d.ts.map +0 -1
  170. package/dist/lib/perform-substitutions.js +0 -85
  171. package/dist/lib/perform-substitutions.js.map +0 -1
  172. package/dist/lib/policies.d.ts +0 -14
  173. package/dist/lib/policies.d.ts.map +0 -1
  174. package/dist/lib/policies.js +0 -33
  175. package/dist/lib/policies.js.map +0 -1
  176. package/dist/lib/substitutions-variables.d.ts +0 -117
  177. package/dist/lib/substitutions-variables.d.ts.map +0 -1
  178. package/dist/lib/substitutions-variables.js.map +0 -1
  179. package/dist/lib/types.d.ts.map +0 -1
  180. package/dist/lib/types.js +0 -13
  181. package/dist/lib/types.js.map +0 -1
  182. package/dist/lib/utils.d.ts +0 -30
  183. package/dist/lib/utils.d.ts.map +0 -1
  184. package/dist/lib/utils.js +0 -70
  185. package/dist/lib/utils.js.map +0 -1
  186. package/dist/tsconfig.tsbuildinfo +0 -1
  187. package/src/lib/errors.ts +0 -29
  188. package/src/lib/functions/chmod-recursive.ts +0 -103
  189. package/src/lib/functions/perform-substitutions.ts +0 -116
  190. package/src/lib/functions/utils.ts +0 -88
  191. package/src/lib/init-template-base.ts +0 -408
  192. package/src/lib/liquid-actions.ts +0 -223
  193. package/src/lib/liquid-build-configurations.ts +0 -433
  194. package/src/lib/liquid-drop.ts +0 -99
  195. package/src/lib/liquid-engine.ts +0 -135
  196. package/src/lib/liquid-package.ts +0 -108
  197. package/src/lib/package.ts +0 -947
  198. package/src/lib/policies.ts +0 -51
  199. package/src/lib/substitutions-variables.ts +0 -177
  200. package/src/lib/types.ts +0 -109
  201. package/src/package.json +0 -3
  202. package/src/tsconfig.json +0 -10
@@ -1,99 +0,0 @@
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
-
12
- /* eslint max-len: [ "error", 80, { "ignoreUrls": true } ] */
13
-
14
- // ----------------------------------------------------------------------------
15
-
16
- // https://www.npmjs.com/package/liquidjs
17
- import { Liquid, Context, Drop } from 'liquidjs'
18
-
19
- // https://www.npmjs.com/package/@xpack/logger
20
- import { Logger } from '@xpack/logger'
21
-
22
- import { XpmLiquidSubstitutionsStrings } from './substitutions-variables.js'
23
-
24
- // ----------------------------------------------------------------------------
25
-
26
- // https://liquidjs.com/
27
-
28
- export class XpmLiquidPropertiesDrop extends Drop {
29
- // --------------------------------------------------------------------------
30
- // Members.
31
-
32
- readonly #log: Logger
33
- readonly #properties: XpmLiquidSubstitutionsStrings
34
- readonly #engine: Liquid
35
-
36
- // --------------------------------------------------------------------------
37
- // Constructor.
38
-
39
- constructor({
40
- log,
41
- engine,
42
- properties,
43
- }: {
44
- log: Logger
45
- engine: Liquid
46
- properties: XpmLiquidSubstitutionsStrings
47
- }) {
48
- super()
49
-
50
- log.trace(`${XpmLiquidPropertiesDrop.name}()`)
51
-
52
- this.#log = log
53
- this.#engine = engine
54
- this.#properties = properties
55
- }
56
-
57
- // --------------------------------------------------------------------------
58
- // Methods.
59
-
60
- override async liquidMethodMissing(
61
- key: string,
62
- context: Context
63
- ): Promise<string | string[]> {
64
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
65
- if (this.#properties[key] === undefined) {
66
- throw new Error(`properties have no ${key} key`)
67
- }
68
-
69
- const log = this.#log
70
-
71
- const value = this.#properties[key] ?? ''
72
- log.trace(
73
- `${XpmLiquidPropertiesDrop.name}.liquidMethodMissing('${key}') value = |`,
74
- value,
75
- '|'
76
- )
77
-
78
- let result: string | string[]
79
-
80
- const valueString = Array.isArray(value) ? value.join('') : value
81
- if (valueString.includes('{{') || valueString.includes('{%')) {
82
- result = (await this.#engine.parseAndRender(
83
- valueString,
84
- context
85
- )) as string
86
- } else {
87
- result = value
88
- }
89
- log.trace(
90
- `${XpmLiquidPropertiesDrop.name}.liquidMethodMissing('${key}') ` +
91
- `result = |`,
92
- result,
93
- '|'
94
- )
95
- return result
96
- }
97
- }
98
-
99
- // ----------------------------------------------------------------------------
@@ -1,135 +0,0 @@
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
-
12
- /* eslint max-len: [ "error", 80, { "ignoreUrls": true } ] */
13
-
14
- // ----------------------------------------------------------------------------
15
-
16
- import * as os from 'node:os'
17
- import * as path from 'node:path'
18
- import * as util from 'node:util'
19
-
20
- // https://www.npmjs.com/package/liquidjs
21
- import { Liquid } from 'liquidjs'
22
-
23
- // ----------------------------------------------------------------------------
24
-
25
- export class XpmLiquidEngine extends Liquid {
26
- // --------------------------------------------------------------------------
27
- // Members.
28
-
29
- // --------------------------------------------------------------------------
30
- // Constructor.
31
-
32
- constructor() {
33
- super({
34
- strictFilters: true,
35
- strictVariables: true,
36
- trimTagLeft: false,
37
- trimTagRight: false,
38
- trimOutputLeft: false,
39
- trimOutputRight: false,
40
- greedy: false,
41
- lenientIf: true,
42
- })
43
-
44
- // https://liquidjs.com/api/classes/liquid_.liquid.html#registerFilter
45
- // https://nodejs.org/dist/latest-v16.x/docs/api/path.html
46
-
47
- // Add the main path manipulation functions.
48
- this.registerFilter('path_basename', (p: string, ...arg) =>
49
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
50
- path.basename(p, ...arg)
51
- )
52
-
53
- this.registerFilter('path_dirname', (p: string) => path.dirname(p))
54
-
55
- this.registerFilter('path_normalize', (p: string) => path.normalize(p))
56
-
57
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
58
- this.registerFilter('path_join', (p, ...args) => path.join(p, ...args))
59
-
60
- this.registerFilter('path_relative', (from: string, to: string) =>
61
- path.relative(from, to)
62
- )
63
-
64
- this.registerFilter('path_posix_basename', (p: string, ...arg) =>
65
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
66
- path.posix.basename(p, ...arg)
67
- )
68
-
69
- this.registerFilter('path_posix_dirname', (p: string) =>
70
- path.posix.dirname(p)
71
- )
72
-
73
- this.registerFilter('path_posix_normalize', (p: string) =>
74
- path.posix.normalize(p)
75
- )
76
-
77
- this.registerFilter('path_posix_join', (p, ...args) =>
78
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
79
- path.posix.join(p, ...args)
80
- )
81
-
82
- this.registerFilter('path_posix_relative', (from: string, to: string) =>
83
- path.posix.relative(from, to)
84
- )
85
-
86
- this.registerFilter('path_win32_basename', (p: string, ...arg) =>
87
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
88
- path.win32.basename(p, ...arg)
89
- )
90
-
91
- this.registerFilter('path_win32_dirname', (p: string) =>
92
- path.win32.dirname(p)
93
- )
94
-
95
- this.registerFilter('path_win32_normalize', (p: string) =>
96
- path.win32.normalize(p)
97
- )
98
-
99
- this.registerFilter('path_win32_join', (p, ...args) =>
100
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
101
- path.win32.join(p, ...args)
102
- )
103
-
104
- this.registerFilter('path_win32_relative', (from: string, to: string) =>
105
- path.win32.relative(from, to)
106
- )
107
-
108
- // https://nodejs.org/dist/latest-v16.x/docs/api/util.html
109
-
110
- this.registerFilter('util_format', (format, ...args) => {
111
- // console.log([...args])
112
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
113
- return util.format(format, ...args)
114
- })
115
-
116
- // Custom action.
117
- this.registerFilter(
118
- 'to_filename',
119
- // Replace non alphanumeric chars with dashes to make the paths
120
- // comply with filesystem names.
121
- (input: string): string => {
122
- /* c8 ignore start */ /* istanbul ignore next */
123
- const fixed =
124
- os.platform() === 'win32'
125
- ? input.replace(/[^a-zA-Z0-9\\:]+/g, '-')
126
- : input.replace(/[^a-zA-Z0-9/]+/g, '-')
127
- /* c8 ignore stop */
128
-
129
- return fixed.replace(/--/g, '-')
130
- }
131
- )
132
- }
133
- }
134
-
135
- // ----------------------------------------------------------------------------
@@ -1,108 +0,0 @@
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
-
12
- /* eslint max-len: [ "error", 80, { "ignoreUrls": true } ] */
13
-
14
- // ----------------------------------------------------------------------------
15
-
16
- import assert from 'node:assert'
17
- import * as os from 'node:os'
18
-
19
- import { Liquid } from 'liquidjs'
20
-
21
- import { Logger } from '@xpack/logger'
22
-
23
- import { isJsonObject } from './functions/utils.js'
24
- import {
25
- xpmLiquidSubstitutionsVariablesBase,
26
- XpmLiquidSubstitutionsVariables,
27
- } from './substitutions-variables.js'
28
- import { XpmLiquidEngine } from './liquid-engine.js'
29
- import { XpmLiquidActions } from './liquid-actions.js'
30
- import { XpmLiquidBuildConfigurations } from './liquid-build-configurations.js'
31
- import { JsonXpmPackage } from './types.js'
32
-
33
- // ----------------------------------------------------------------------------
34
-
35
- export const buildFolderRelativePathPropertyName = 'buildFolderRelativePath'
36
-
37
- // ----------------------------------------------------------------------------
38
-
39
- export class XpmLiquidPackage {
40
- // --------------------------------------------------------------------------
41
- // Members.
42
-
43
- readonly #log: Logger
44
- readonly #engine: Liquid
45
- readonly #jsonPackage: JsonXpmPackage
46
-
47
- readonly topLiquidSubstitutionsVariables: XpmLiquidSubstitutionsVariables
48
-
49
- readonly topActions: XpmLiquidActions
50
- readonly buildConfigurations: XpmLiquidBuildConfigurations
51
-
52
- // --------------------------------------------------------------------------
53
- // Constructor and async initialiser.
54
-
55
- constructor({
56
- log,
57
- jsonPackage,
58
- }: {
59
- log: Logger
60
- jsonPackage: JsonXpmPackage
61
- }) {
62
- log.trace(`${XpmLiquidPackage.name}()`)
63
-
64
- this.#log = log
65
- this.#engine = new XpmLiquidEngine()
66
-
67
- assert(isJsonObject(jsonPackage.xpack))
68
- this.#jsonPackage = jsonPackage
69
-
70
- // os.version() available since 12.x
71
- assert(
72
- typeof os.version === 'function',
73
- 'Mandatory os.version available only since 12.x'
74
- )
75
-
76
- this.topLiquidSubstitutionsVariables = {
77
- ...xpmLiquidSubstitutionsVariablesBase,
78
- package: jsonPackage,
79
- }
80
-
81
- if (isJsonObject(jsonPackage.xpack.properties)) {
82
- this.topLiquidSubstitutionsVariables.properties = {
83
- ...jsonPackage.xpack.properties,
84
- }
85
- }
86
-
87
- // Prevent adding/removing properties.
88
- Object.seal(this.topLiquidSubstitutionsVariables)
89
-
90
- // Empty actions.
91
- this.topActions = new XpmLiquidActions({
92
- log: this.#log,
93
- engine: this.#engine,
94
- substitutionsVariables: this.topLiquidSubstitutionsVariables,
95
- jsonActions: this.#jsonPackage.xpack.actions,
96
- })
97
-
98
- // Empty build configurations.
99
- this.buildConfigurations = new XpmLiquidBuildConfigurations({
100
- log: this.#log,
101
- engine: this.#engine,
102
- substitutionsVariables: this.topLiquidSubstitutionsVariables,
103
- jsonBuildConfigurations: this.#jsonPackage.xpack.buildConfigurations,
104
- })
105
- }
106
- }
107
-
108
- // ----------------------------------------------------------------------------