@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.
- package/README.md +16 -212
- package/dist/classes/actions.d.ts +58 -0
- package/dist/classes/actions.d.ts.map +1 -0
- package/dist/classes/actions.js +250 -0
- package/dist/classes/actions.js.map +1 -0
- package/dist/classes/build-configurations.d.ts +78 -0
- package/dist/classes/build-configurations.d.ts.map +1 -0
- package/dist/classes/build-configurations.js +489 -0
- package/dist/classes/build-configurations.js.map +1 -0
- package/dist/classes/combinations-generator.d.ts +19 -0
- package/dist/classes/combinations-generator.d.ts.map +1 -0
- package/dist/classes/combinations-generator.js +48 -0
- package/dist/classes/combinations-generator.js.map +1 -0
- package/dist/classes/data-model.d.ts +21 -0
- package/dist/classes/data-model.d.ts.map +1 -0
- package/dist/classes/data-model.js +47 -0
- package/dist/classes/data-model.js.map +1 -0
- package/dist/classes/errors.d.ts +13 -0
- package/dist/classes/errors.d.ts.map +1 -0
- package/dist/classes/errors.js +13 -0
- package/dist/classes/errors.js.map +1 -0
- package/dist/classes/init-template-base.d.ts +47 -0
- package/dist/classes/init-template-base.d.ts.map +1 -0
- package/dist/classes/init-template-base.js +358 -0
- package/dist/classes/init-template-base.js.map +1 -0
- package/dist/classes/liquid-drop.d.ts +28 -0
- package/dist/classes/liquid-drop.d.ts.map +1 -0
- package/dist/classes/liquid-drop.js +70 -0
- package/dist/classes/liquid-drop.js.map +1 -0
- package/dist/classes/liquid-engine.d.ts +7 -0
- package/dist/classes/liquid-engine.d.ts.map +1 -0
- package/dist/classes/liquid-engine.js +72 -0
- package/dist/classes/liquid-engine.js.map +1 -0
- package/dist/classes/package.d.ts +31 -0
- package/dist/classes/package.d.ts.map +1 -0
- package/dist/classes/package.js +268 -0
- package/dist/classes/package.js.map +1 -0
- package/dist/classes/platform-detector.d.ts +14 -0
- package/dist/classes/platform-detector.d.ts.map +1 -0
- package/dist/classes/platform-detector.js +26 -0
- package/dist/classes/platform-detector.js.map +1 -0
- package/dist/classes/policies.d.ts +14 -0
- package/dist/classes/policies.d.ts.map +1 -0
- package/dist/classes/policies.js +20 -0
- package/dist/classes/policies.js.map +1 -0
- package/dist/classes/template-expander.d.ts +29 -0
- package/dist/classes/template-expander.d.ts.map +1 -0
- package/dist/classes/template-expander.js +62 -0
- package/dist/classes/template-expander.js.map +1 -0
- package/dist/data/substitutions-variables.d.ts +43 -0
- package/dist/data/substitutions-variables.d.ts.map +1 -0
- package/dist/{lib → data}/substitutions-variables.js +1 -16
- package/dist/data/substitutions-variables.js.map +1 -0
- package/dist/functions/chmod-recursively.d.ts +9 -0
- package/dist/functions/chmod-recursively.d.ts.map +1 -0
- package/dist/functions/chmod-recursively.js +66 -0
- package/dist/functions/chmod-recursively.js.map +1 -0
- package/dist/functions/filter-paths.d.ts +5 -0
- package/dist/functions/filter-paths.d.ts.map +1 -0
- package/dist/functions/filter-paths.js +16 -0
- package/dist/functions/filter-paths.js.map +1 -0
- package/dist/functions/is-something.d.ts +9 -0
- package/dist/functions/is-something.d.ts.map +1 -0
- package/dist/functions/is-something.js +25 -0
- package/dist/functions/is-something.js.map +1 -0
- package/dist/functions/matrix-expander.d.ts +17 -0
- package/dist/functions/matrix-expander.d.ts.map +1 -0
- package/dist/functions/matrix-expander.js +52 -0
- package/dist/functions/matrix-expander.js.map +1 -0
- package/dist/functions/perform-substitutions.d.ts +12 -0
- package/dist/functions/perform-substitutions.d.ts.map +1 -0
- package/dist/functions/perform-substitutions.js +76 -0
- package/dist/functions/perform-substitutions.js.map +1 -0
- package/dist/functions/utils.d.ts +8 -0
- package/dist/functions/utils.d.ts.map +1 -0
- package/dist/functions/utils.js +16 -0
- package/dist/functions/utils.js.map +1 -0
- package/dist/index.d.ts +22 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -29
- package/dist/index.js.map +1 -1
- package/dist/{lib/types.d.ts → types/json.d.ts} +31 -22
- package/dist/types/json.d.ts.map +1 -0
- package/dist/types/json.js +2 -0
- package/dist/types/json.js.map +1 -0
- package/dist/types/xpm-init-template.d.ts +21 -0
- package/dist/types/xpm-init-template.d.ts.map +1 -0
- package/dist/types/xpm-init-template.js +2 -0
- package/dist/types/xpm-init-template.js.map +1 -0
- package/dist/types/xpm.d.ts +16 -0
- package/dist/types/xpm.d.ts.map +1 -0
- package/dist/types/xpm.js +2 -0
- package/dist/types/xpm.js.map +1 -0
- package/package.json +53 -44
- package/src/CODE-REVIEW.md +2167 -0
- package/src/README.md +393 -6
- package/src/classes/actions.ts +1157 -0
- package/src/classes/build-configurations.ts +2127 -0
- package/src/classes/combinations-generator.ts +331 -0
- package/src/classes/data-model.ts +337 -0
- package/src/classes/errors.ts +105 -0
- package/src/classes/init-template-base.ts +1028 -0
- package/src/classes/liquid-drop.ts +376 -0
- package/src/classes/liquid-engine.ts +249 -0
- package/src/classes/package.ts +765 -0
- package/src/classes/platform-detector.ts +237 -0
- package/src/classes/policies.ts +200 -0
- package/src/classes/template-expander.ts +330 -0
- package/src/data/substitutions-variables.ts +390 -0
- package/src/functions/chmod-recursively.ts +195 -0
- package/src/functions/filter-paths.ts +126 -0
- package/src/functions/is-something.ts +223 -0
- package/src/functions/matrix-expander.ts +172 -0
- package/src/functions/perform-substitutions.ts +253 -0
- package/src/functions/utils.ts +151 -0
- package/src/index.ts +72 -19
- package/src/types/json.ts +519 -0
- package/src/types/xpm-init-template.ts +282 -0
- package/src/types/xpm.ts +162 -0
- package/dist/lib/chmod-recursive.d.ts +0 -7
- package/dist/lib/chmod-recursive.d.ts.map +0 -1
- package/dist/lib/chmod-recursive.js +0 -81
- package/dist/lib/chmod-recursive.js.map +0 -1
- package/dist/lib/errors.d.ts +0 -11
- package/dist/lib/errors.d.ts.map +0 -1
- package/dist/lib/errors.js +0 -26
- package/dist/lib/errors.js.map +0 -1
- package/dist/lib/functions/chmod-recursive.d.ts +0 -7
- package/dist/lib/functions/chmod-recursive.d.ts.map +0 -1
- package/dist/lib/functions/chmod-recursive.js +0 -81
- package/dist/lib/functions/chmod-recursive.js.map +0 -1
- package/dist/lib/functions/perform-substitutions.d.ts +0 -20
- package/dist/lib/functions/perform-substitutions.d.ts.map +0 -1
- package/dist/lib/functions/perform-substitutions.js +0 -85
- package/dist/lib/functions/perform-substitutions.js.map +0 -1
- package/dist/lib/functions/utils.d.ts +0 -30
- package/dist/lib/functions/utils.d.ts.map +0 -1
- package/dist/lib/functions/utils.js +0 -70
- package/dist/lib/functions/utils.js.map +0 -1
- package/dist/lib/init-template-base.d.ts +0 -46
- package/dist/lib/init-template-base.d.ts.map +0 -1
- package/dist/lib/init-template-base.js +0 -281
- package/dist/lib/init-template-base.js.map +0 -1
- package/dist/lib/liquid-actions.d.ts +0 -37
- package/dist/lib/liquid-actions.d.ts.map +0 -1
- package/dist/lib/liquid-actions.js +0 -148
- package/dist/lib/liquid-actions.js.map +0 -1
- package/dist/lib/liquid-build-configurations.d.ts +0 -47
- package/dist/lib/liquid-build-configurations.d.ts.map +0 -1
- package/dist/lib/liquid-build-configurations.js +0 -282
- package/dist/lib/liquid-build-configurations.js.map +0 -1
- package/dist/lib/liquid-drop.d.ts +0 -13
- package/dist/lib/liquid-drop.d.ts.map +0 -1
- package/dist/lib/liquid-drop.js +0 -56
- package/dist/lib/liquid-drop.js.map +0 -1
- package/dist/lib/liquid-engine.d.ts +0 -5
- package/dist/lib/liquid-engine.d.ts.map +0 -1
- package/dist/lib/liquid-engine.js +0 -85
- package/dist/lib/liquid-engine.js.map +0 -1
- package/dist/lib/liquid-package.d.ts +0 -17
- package/dist/lib/liquid-package.d.ts.map +0 -1
- package/dist/lib/liquid-package.js +0 -70
- package/dist/lib/liquid-package.js.map +0 -1
- package/dist/lib/package.d.ts +0 -66
- package/dist/lib/package.d.ts.map +0 -1
- package/dist/lib/package.js +0 -700
- package/dist/lib/package.js.map +0 -1
- package/dist/lib/perform-substitutions.d.ts +0 -20
- package/dist/lib/perform-substitutions.d.ts.map +0 -1
- package/dist/lib/perform-substitutions.js +0 -85
- package/dist/lib/perform-substitutions.js.map +0 -1
- package/dist/lib/policies.d.ts +0 -14
- package/dist/lib/policies.d.ts.map +0 -1
- package/dist/lib/policies.js +0 -33
- package/dist/lib/policies.js.map +0 -1
- package/dist/lib/substitutions-variables.d.ts +0 -117
- package/dist/lib/substitutions-variables.d.ts.map +0 -1
- package/dist/lib/substitutions-variables.js.map +0 -1
- package/dist/lib/types.d.ts.map +0 -1
- package/dist/lib/types.js +0 -13
- package/dist/lib/types.js.map +0 -1
- package/dist/lib/utils.d.ts +0 -30
- package/dist/lib/utils.d.ts.map +0 -1
- package/dist/lib/utils.js +0 -70
- package/dist/lib/utils.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/src/lib/errors.ts +0 -29
- package/src/lib/functions/chmod-recursive.ts +0 -103
- package/src/lib/functions/perform-substitutions.ts +0 -116
- package/src/lib/functions/utils.ts +0 -88
- package/src/lib/init-template-base.ts +0 -408
- package/src/lib/liquid-actions.ts +0 -223
- package/src/lib/liquid-build-configurations.ts +0 -433
- package/src/lib/liquid-drop.ts +0 -99
- package/src/lib/liquid-engine.ts +0 -135
- package/src/lib/liquid-package.ts +0 -108
- package/src/lib/package.ts +0 -947
- package/src/lib/policies.ts +0 -51
- package/src/lib/substitutions-variables.ts +0 -177
- package/src/lib/types.ts +0 -109
- package/src/package.json +0 -3
- package/src/tsconfig.json +0 -10
|
@@ -1,223 +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 { Logger } from '@xpack/logger'
|
|
20
|
-
|
|
21
|
-
import { XpmLiquidEngine } from './liquid-engine.js'
|
|
22
|
-
import {
|
|
23
|
-
XpmLiquidSubstitutionsVariables,
|
|
24
|
-
XpmLiquidSubstitutionsStrings,
|
|
25
|
-
} from './substitutions-variables.js'
|
|
26
|
-
import { JsonActions, JsonActionValue } from './types.js'
|
|
27
|
-
import { performSubstitutions } from './functions/perform-substitutions.js'
|
|
28
|
-
|
|
29
|
-
// ----------------------------------------------------------------------------
|
|
30
|
-
|
|
31
|
-
// A collection of actions.
|
|
32
|
-
export class XpmLiquidActions {
|
|
33
|
-
// --------------------------------------------------------------------------
|
|
34
|
-
// Members.
|
|
35
|
-
|
|
36
|
-
readonly log: Logger
|
|
37
|
-
readonly engine: XpmLiquidEngine
|
|
38
|
-
readonly substitutionsVariables: XpmLiquidSubstitutionsVariables
|
|
39
|
-
readonly jsonActions: JsonActions
|
|
40
|
-
|
|
41
|
-
readonly #actionsMap: Map<string, XpmLiquidAction | undefined>
|
|
42
|
-
readonly #jsonActionsNamesMap: Map<string, string>
|
|
43
|
-
|
|
44
|
-
#isInitialised = false
|
|
45
|
-
|
|
46
|
-
// --------------------------------------------------------------------------
|
|
47
|
-
// Constructor and async initialiser.
|
|
48
|
-
|
|
49
|
-
constructor({
|
|
50
|
-
log,
|
|
51
|
-
engine,
|
|
52
|
-
substitutionsVariables,
|
|
53
|
-
inheritedActionsMap,
|
|
54
|
-
jsonActions,
|
|
55
|
-
}: {
|
|
56
|
-
log: Logger
|
|
57
|
-
engine: XpmLiquidEngine
|
|
58
|
-
substitutionsVariables: XpmLiquidSubstitutionsVariables
|
|
59
|
-
inheritedActionsMap?: Map<string, XpmLiquidAction>
|
|
60
|
-
jsonActions: JsonActions | undefined
|
|
61
|
-
}) {
|
|
62
|
-
log.trace(`${XpmLiquidActions.name}()`)
|
|
63
|
-
|
|
64
|
-
this.log = log
|
|
65
|
-
this.engine = engine
|
|
66
|
-
this.substitutionsVariables = substitutionsVariables
|
|
67
|
-
this.jsonActions = jsonActions ?? {}
|
|
68
|
-
|
|
69
|
-
// Possibly empty if there are no actions.
|
|
70
|
-
this.#actionsMap = new Map<string, XpmLiquidAction | undefined>()
|
|
71
|
-
|
|
72
|
-
if (inheritedActionsMap !== undefined) {
|
|
73
|
-
for (const [
|
|
74
|
-
inheritedActionName,
|
|
75
|
-
inheritedAction,
|
|
76
|
-
] of inheritedActionsMap) {
|
|
77
|
-
// Make copies of the actions, do not alter the inherited ones.
|
|
78
|
-
const action = new XpmLiquidAction({
|
|
79
|
-
actionName: inheritedActionName,
|
|
80
|
-
jsonAction: inheritedAction.jsonAction,
|
|
81
|
-
parentActions: this,
|
|
82
|
-
})
|
|
83
|
-
this.#actionsMap.set(inheritedActionName, action)
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
this.#jsonActionsNamesMap = new Map<string, string>()
|
|
88
|
-
|
|
89
|
-
// log.trace('substitutionsVariables => ', this.substitutionsVariables)
|
|
90
|
-
// The rest of the initialisation is done in the async initialiser.
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
94
|
-
async initialise(): Promise<void> {
|
|
95
|
-
if (this.#isInitialised) {
|
|
96
|
-
return
|
|
97
|
-
}
|
|
98
|
-
for (const actionName of Object.keys(this.jsonActions)) {
|
|
99
|
-
if (actionName.includes('{{')) {
|
|
100
|
-
// TODO: expand templates and generate multiple actions.
|
|
101
|
-
} else {
|
|
102
|
-
this.#actionsMap.set(actionName, undefined)
|
|
103
|
-
this.#jsonActionsNamesMap.set(actionName, actionName)
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
this.log.trace(
|
|
108
|
-
`${XpmLiquidActions.name}.initialise() =>`,
|
|
109
|
-
Array.from(this.#actionsMap.keys())
|
|
110
|
-
)
|
|
111
|
-
|
|
112
|
-
this.#isInitialised = true
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// --------------------------------------------------------------------------
|
|
116
|
-
// Methods.
|
|
117
|
-
|
|
118
|
-
empty(): boolean {
|
|
119
|
-
return this.#actionsMap.size === 0
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
names(): string[] {
|
|
123
|
-
const actionNames = Array.from(this.#actionsMap.keys())
|
|
124
|
-
|
|
125
|
-
this.log.trace(`${XpmLiquidActions.name}.names() =>`, actionNames)
|
|
126
|
-
return actionNames
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
has(actionName: string): boolean {
|
|
130
|
-
return this.#actionsMap.has(actionName)
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
get(actionName: string): XpmLiquidAction {
|
|
134
|
-
let action = this.#actionsMap.get(actionName)
|
|
135
|
-
if (action === undefined) {
|
|
136
|
-
const jsonActionName: string =
|
|
137
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
138
|
-
this.#jsonActionsNamesMap.get(actionName)!
|
|
139
|
-
const jsonAction = this.jsonActions[jsonActionName] ?? ''
|
|
140
|
-
action = new XpmLiquidAction({
|
|
141
|
-
actionName,
|
|
142
|
-
jsonAction,
|
|
143
|
-
parentActions: this,
|
|
144
|
-
})
|
|
145
|
-
this.#actionsMap.set(actionName, action)
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return action
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// ----------------------------------------------------------------------------
|
|
153
|
-
|
|
154
|
-
// An individual action.
|
|
155
|
-
export class XpmLiquidAction {
|
|
156
|
-
// --------------------------------------------------------------------------
|
|
157
|
-
// Members.
|
|
158
|
-
|
|
159
|
-
readonly actionName: string
|
|
160
|
-
// readonly jsonActionName: string
|
|
161
|
-
readonly jsonAction: JsonActionValue
|
|
162
|
-
parentActions: XpmLiquidActions
|
|
163
|
-
|
|
164
|
-
// For templates, the actual values.
|
|
165
|
-
matrixParameters?: XpmLiquidSubstitutionsStrings
|
|
166
|
-
#commands?: string[]
|
|
167
|
-
|
|
168
|
-
// --------------------------------------------------------------------------
|
|
169
|
-
// Constructor.
|
|
170
|
-
|
|
171
|
-
constructor({
|
|
172
|
-
actionName,
|
|
173
|
-
// jsonActionName,
|
|
174
|
-
jsonAction,
|
|
175
|
-
parentActions,
|
|
176
|
-
}: {
|
|
177
|
-
actionName: string
|
|
178
|
-
// jsonActionName: string
|
|
179
|
-
jsonAction: JsonActionValue
|
|
180
|
-
parentActions: XpmLiquidActions
|
|
181
|
-
}) {
|
|
182
|
-
assert(actionName)
|
|
183
|
-
// assert(jsonActionName)
|
|
184
|
-
assert(parentActions)
|
|
185
|
-
|
|
186
|
-
parentActions.log.trace(`${XpmLiquidAction.name}(${actionName})`)
|
|
187
|
-
|
|
188
|
-
this.actionName = actionName
|
|
189
|
-
// this.jsonActionName = jsonActionName
|
|
190
|
-
this.jsonAction = jsonAction
|
|
191
|
-
this.parentActions = parentActions
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
// --------------------------------------------------------------------------
|
|
195
|
-
// Methods.
|
|
196
|
-
|
|
197
|
-
async getCommands(): Promise<string[]> {
|
|
198
|
-
if (this.#commands === undefined) {
|
|
199
|
-
// Silently accept empty or non-existing actions.
|
|
200
|
-
const jsonAction = this.jsonAction
|
|
201
|
-
const input = Array.isArray(jsonAction)
|
|
202
|
-
? jsonAction.join(os.EOL)
|
|
203
|
-
: jsonAction
|
|
204
|
-
|
|
205
|
-
const substituted = await performSubstitutions({
|
|
206
|
-
input,
|
|
207
|
-
engine: this.parentActions.engine,
|
|
208
|
-
substitutionsVariables: this.parentActions.substitutionsVariables,
|
|
209
|
-
log: this.parentActions.log,
|
|
210
|
-
})
|
|
211
|
-
|
|
212
|
-
this.#commands = substituted.split(os.EOL)
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
this.parentActions.log.trace(
|
|
216
|
-
`${XpmLiquidAction.name}.commands() =>`,
|
|
217
|
-
this.#commands
|
|
218
|
-
)
|
|
219
|
-
return this.#commands
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// ----------------------------------------------------------------------------
|
|
@@ -1,433 +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 path from 'node:path'
|
|
18
|
-
|
|
19
|
-
import { Logger } from '@xpack/logger'
|
|
20
|
-
|
|
21
|
-
import { XpmLiquidEngine } from './liquid-engine.js'
|
|
22
|
-
import {
|
|
23
|
-
XpmLiquidSubstitutionsVariables,
|
|
24
|
-
XpmLiquidSubstitutionsStrings,
|
|
25
|
-
} from './substitutions-variables.js'
|
|
26
|
-
import { buildFolderRelativePathPropertyName } from './liquid-package.js'
|
|
27
|
-
import {
|
|
28
|
-
JsonBuildConfiguration,
|
|
29
|
-
JsonBuildConfigurations,
|
|
30
|
-
JsonDependencies,
|
|
31
|
-
} from './types.js'
|
|
32
|
-
import { performSubstitutions } from './functions/perform-substitutions.js'
|
|
33
|
-
import { XpmLiquidAction, XpmLiquidActions } from './liquid-actions.js'
|
|
34
|
-
import { isString } from './functions/utils.js'
|
|
35
|
-
import { filterPath } from './functions/utils.js'
|
|
36
|
-
|
|
37
|
-
// ----------------------------------------------------------------------------
|
|
38
|
-
|
|
39
|
-
// A collection of build configurations.
|
|
40
|
-
export class XpmLiquidBuildConfigurations {
|
|
41
|
-
// --------------------------------------------------------------------------
|
|
42
|
-
// Members.
|
|
43
|
-
|
|
44
|
-
readonly log: Logger
|
|
45
|
-
readonly engine: XpmLiquidEngine
|
|
46
|
-
readonly substitutionsVariables: XpmLiquidSubstitutionsVariables
|
|
47
|
-
readonly jsonBuildConfigurations: JsonBuildConfigurations
|
|
48
|
-
|
|
49
|
-
readonly #buildConfigurationsMap: Map<
|
|
50
|
-
string,
|
|
51
|
-
XpmLiquidBuildConfiguration | undefined
|
|
52
|
-
>
|
|
53
|
-
readonly #jsonBuildConfigurationsNamesMap: Map<string, string>
|
|
54
|
-
|
|
55
|
-
#isInitialised = false
|
|
56
|
-
|
|
57
|
-
// --------------------------------------------------------------------------
|
|
58
|
-
// Constructor and async initialiser.
|
|
59
|
-
|
|
60
|
-
constructor({
|
|
61
|
-
log,
|
|
62
|
-
engine,
|
|
63
|
-
substitutionsVariables,
|
|
64
|
-
jsonBuildConfigurations,
|
|
65
|
-
}: {
|
|
66
|
-
log: Logger
|
|
67
|
-
engine: XpmLiquidEngine
|
|
68
|
-
substitutionsVariables: XpmLiquidSubstitutionsVariables
|
|
69
|
-
jsonBuildConfigurations: JsonBuildConfigurations | undefined
|
|
70
|
-
}) {
|
|
71
|
-
assert(log)
|
|
72
|
-
assert(engine)
|
|
73
|
-
assert(substitutionsVariables)
|
|
74
|
-
|
|
75
|
-
log.trace(`${XpmLiquidBuildConfigurations.name}()`)
|
|
76
|
-
|
|
77
|
-
this.log = log
|
|
78
|
-
this.engine = engine
|
|
79
|
-
this.substitutionsVariables = substitutionsVariables
|
|
80
|
-
this.jsonBuildConfigurations = jsonBuildConfigurations ?? {}
|
|
81
|
-
|
|
82
|
-
// Possibly empty if there are no build configurations.
|
|
83
|
-
this.#buildConfigurationsMap = new Map<
|
|
84
|
-
string,
|
|
85
|
-
XpmLiquidBuildConfiguration | undefined
|
|
86
|
-
>()
|
|
87
|
-
this.#jsonBuildConfigurationsNamesMap = new Map<string, string>()
|
|
88
|
-
// log.trace('substitutionsVariables => ', this.substitutionsVariables)
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
92
|
-
async initialise(): Promise<void> {
|
|
93
|
-
if (this.#isInitialised) {
|
|
94
|
-
return
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
for (const buildConfigurationName of Object.keys(
|
|
98
|
-
this.jsonBuildConfigurations
|
|
99
|
-
)) {
|
|
100
|
-
if (buildConfigurationName.includes('{{')) {
|
|
101
|
-
// TODO: expand templates and generate multiple build configurations.
|
|
102
|
-
} else {
|
|
103
|
-
this.#buildConfigurationsMap.set(buildConfigurationName, undefined)
|
|
104
|
-
this.#jsonBuildConfigurationsNamesMap.set(
|
|
105
|
-
buildConfigurationName,
|
|
106
|
-
buildConfigurationName
|
|
107
|
-
)
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
this.log.trace(
|
|
112
|
-
`${XpmLiquidBuildConfigurations.name}.initialise() =>`,
|
|
113
|
-
Array.from(this.#buildConfigurationsMap.keys())
|
|
114
|
-
)
|
|
115
|
-
|
|
116
|
-
this.#isInitialised = true
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// --------------------------------------------------------------------------
|
|
120
|
-
// Methods.
|
|
121
|
-
|
|
122
|
-
empty(): boolean {
|
|
123
|
-
return this.#buildConfigurationsMap.size === 0
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
names(): string[] {
|
|
127
|
-
const buildConfigurationsNames = Array.from(
|
|
128
|
-
this.#buildConfigurationsMap.keys()
|
|
129
|
-
)
|
|
130
|
-
|
|
131
|
-
this.log.trace(
|
|
132
|
-
`${XpmLiquidBuildConfigurations.name}.names() =>`,
|
|
133
|
-
buildConfigurationsNames
|
|
134
|
-
)
|
|
135
|
-
return buildConfigurationsNames
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
hasJson(buildConfigurationName: string): boolean {
|
|
139
|
-
return this.#jsonBuildConfigurationsNamesMap.has(buildConfigurationName)
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
getJson(buildConfigurationName: string): JsonBuildConfiguration {
|
|
143
|
-
return this.jsonBuildConfigurations[
|
|
144
|
-
this.getJsonName(buildConfigurationName)
|
|
145
|
-
]
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
isHidden(buildConfigurationName: string): boolean {
|
|
149
|
-
return (
|
|
150
|
-
this.jsonBuildConfigurations[this.getJsonName(buildConfigurationName)]
|
|
151
|
-
.hidden ?? false
|
|
152
|
-
)
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
has(buildConfigurationName: string): boolean {
|
|
156
|
-
return this.#buildConfigurationsMap.has(buildConfigurationName)
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
async get(
|
|
160
|
-
buildConfigurationName: string
|
|
161
|
-
): Promise<XpmLiquidBuildConfiguration> {
|
|
162
|
-
let buildConfiguration = this.#buildConfigurationsMap.get(
|
|
163
|
-
buildConfigurationName
|
|
164
|
-
)
|
|
165
|
-
if (buildConfiguration === undefined) {
|
|
166
|
-
const jsonBuildConfigurationName: string =
|
|
167
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
168
|
-
this.#jsonBuildConfigurationsNamesMap.get(buildConfigurationName)!
|
|
169
|
-
|
|
170
|
-
const jsonBuildConfiguration =
|
|
171
|
-
this.jsonBuildConfigurations[jsonBuildConfigurationName] ?? {}
|
|
172
|
-
|
|
173
|
-
buildConfiguration = new XpmLiquidBuildConfiguration({
|
|
174
|
-
buildConfigurationName,
|
|
175
|
-
// jsonBuildConfigurationName,
|
|
176
|
-
jsonBuildConfiguration,
|
|
177
|
-
parentBuildConfigurations: this,
|
|
178
|
-
})
|
|
179
|
-
await buildConfiguration.initialise()
|
|
180
|
-
this.#buildConfigurationsMap.set(
|
|
181
|
-
buildConfigurationName,
|
|
182
|
-
buildConfiguration
|
|
183
|
-
)
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
return buildConfiguration
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
getJsonName(buildConfigurationName: string): string {
|
|
190
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
191
|
-
return this.#jsonBuildConfigurationsNamesMap.get(buildConfigurationName)!
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// ----------------------------------------------------------------------------
|
|
196
|
-
|
|
197
|
-
// An individual build configuration.
|
|
198
|
-
export class XpmLiquidBuildConfiguration {
|
|
199
|
-
// --------------------------------------------------------------------------
|
|
200
|
-
// Members.
|
|
201
|
-
|
|
202
|
-
readonly hidden: boolean
|
|
203
|
-
|
|
204
|
-
// The actual (un-substituted) name from package.json.
|
|
205
|
-
// readonly jsonBuildConfigurationName: string
|
|
206
|
-
// Points to the actual buildConfiguration in package.json.
|
|
207
|
-
readonly jsonBuildConfiguration: JsonBuildConfiguration
|
|
208
|
-
|
|
209
|
-
substitutionsVariables: XpmLiquidSubstitutionsVariables
|
|
210
|
-
|
|
211
|
-
properties: XpmLiquidSubstitutionsStrings = {}
|
|
212
|
-
|
|
213
|
-
jsonDependencies: JsonDependencies = {}
|
|
214
|
-
jsonDevDependencies: JsonDependencies = {}
|
|
215
|
-
|
|
216
|
-
// For templates, the actual values.
|
|
217
|
-
matrixParameters?: XpmLiquidSubstitutionsStrings
|
|
218
|
-
|
|
219
|
-
// The name after performing the substitutions.
|
|
220
|
-
readonly #buildConfigurationName: string
|
|
221
|
-
|
|
222
|
-
readonly #parentBuildConfigurations: XpmLiquidBuildConfigurations
|
|
223
|
-
|
|
224
|
-
#actions: XpmLiquidActions | undefined
|
|
225
|
-
|
|
226
|
-
#buildFolderRelativePath?: string
|
|
227
|
-
|
|
228
|
-
#isInitialised = false
|
|
229
|
-
|
|
230
|
-
// --------------------------------------------------------------------------
|
|
231
|
-
// Constructor and async initialiser.
|
|
232
|
-
|
|
233
|
-
constructor({
|
|
234
|
-
buildConfigurationName, // The Liquid-processed name.
|
|
235
|
-
// jsonBuildConfigurationName, // The raw name from package.json.
|
|
236
|
-
jsonBuildConfiguration,
|
|
237
|
-
parentBuildConfigurations,
|
|
238
|
-
}: {
|
|
239
|
-
buildConfigurationName: string
|
|
240
|
-
// jsonBuildConfigurationName: string
|
|
241
|
-
jsonBuildConfiguration: JsonBuildConfiguration
|
|
242
|
-
parentBuildConfigurations: XpmLiquidBuildConfigurations
|
|
243
|
-
}) {
|
|
244
|
-
assert(buildConfigurationName)
|
|
245
|
-
// assert(jsonBuildConfigurationName)
|
|
246
|
-
assert(jsonBuildConfiguration)
|
|
247
|
-
assert(parentBuildConfigurations)
|
|
248
|
-
|
|
249
|
-
parentBuildConfigurations.log.trace(
|
|
250
|
-
`${XpmLiquidBuildConfiguration.name}(${buildConfigurationName})`
|
|
251
|
-
)
|
|
252
|
-
|
|
253
|
-
this.#buildConfigurationName = buildConfigurationName
|
|
254
|
-
// this.jsonBuildConfigurationName = jsonBuildConfigurationName
|
|
255
|
-
this.jsonBuildConfiguration = jsonBuildConfiguration
|
|
256
|
-
this.#parentBuildConfigurations = parentBuildConfigurations
|
|
257
|
-
|
|
258
|
-
this.substitutionsVariables = {
|
|
259
|
-
...this.#parentBuildConfigurations.substitutionsVariables,
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
this.hidden = this.jsonBuildConfiguration.hidden ?? false
|
|
263
|
-
|
|
264
|
-
// The rest of the initialisation is done in the async initialiser.
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
async initialise(): Promise<void> {
|
|
268
|
-
if (this.#isInitialised) {
|
|
269
|
-
return
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
const log = this.#parentBuildConfigurations.log
|
|
273
|
-
const jsonBuildConfiguration = this.jsonBuildConfiguration
|
|
274
|
-
|
|
275
|
-
// TODO: add matrixParameters
|
|
276
|
-
|
|
277
|
-
// Process both the new 'inherits' and the deprecated 'inherit'.
|
|
278
|
-
let inherits: string[] = []
|
|
279
|
-
if (isString(jsonBuildConfiguration.inherits)) {
|
|
280
|
-
inherits = [jsonBuildConfiguration.inherits]
|
|
281
|
-
} else if (Array.isArray(jsonBuildConfiguration.inherits)) {
|
|
282
|
-
inherits = jsonBuildConfiguration.inherits as string[]
|
|
283
|
-
} else if (isString(jsonBuildConfiguration.inherit)) {
|
|
284
|
-
inherits = [jsonBuildConfiguration.inherit]
|
|
285
|
-
} else if (Array.isArray(jsonBuildConfiguration.inherit)) {
|
|
286
|
-
inherits = jsonBuildConfiguration.inherit as string[]
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
const inheritedActionsMap: Map<string, XpmLiquidAction> = new Map<
|
|
290
|
-
string,
|
|
291
|
-
XpmLiquidAction
|
|
292
|
-
>()
|
|
293
|
-
|
|
294
|
-
// Add inherited configuration properties.
|
|
295
|
-
// TODO: detect circular references.
|
|
296
|
-
for (const inheritedBuildConfigurationName of inherits) {
|
|
297
|
-
if (
|
|
298
|
-
this.#parentBuildConfigurations.hasJson(inheritedBuildConfigurationName)
|
|
299
|
-
) {
|
|
300
|
-
const inheritedBuildConfiguration =
|
|
301
|
-
await this.#parentBuildConfigurations.get(
|
|
302
|
-
inheritedBuildConfigurationName
|
|
303
|
-
)
|
|
304
|
-
|
|
305
|
-
this.properties = {
|
|
306
|
-
...this.properties,
|
|
307
|
-
...inheritedBuildConfiguration.properties,
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
this.jsonDependencies = {
|
|
311
|
-
...this.jsonDependencies,
|
|
312
|
-
...inheritedBuildConfiguration.jsonDependencies,
|
|
313
|
-
}
|
|
314
|
-
this.jsonDevDependencies = {
|
|
315
|
-
...this.jsonDevDependencies,
|
|
316
|
-
...inheritedBuildConfiguration.jsonDevDependencies,
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
await inheritedBuildConfiguration.actions.initialise()
|
|
320
|
-
for (const actionName of inheritedBuildConfiguration.actions.names()) {
|
|
321
|
-
const action = inheritedBuildConfiguration.actions.get(actionName)
|
|
322
|
-
inheritedActionsMap.set(actionName, action)
|
|
323
|
-
}
|
|
324
|
-
} else {
|
|
325
|
-
log.warn(
|
|
326
|
-
'buildConfiguration',
|
|
327
|
-
this.#buildConfigurationName,
|
|
328
|
-
'inherits from missing',
|
|
329
|
-
inheritedBuildConfigurationName,
|
|
330
|
-
'(ignored)'
|
|
331
|
-
)
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
this.properties = {
|
|
336
|
-
...this.properties,
|
|
337
|
-
...jsonBuildConfiguration.properties,
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
this.jsonDependencies = {
|
|
341
|
-
...this.jsonDependencies,
|
|
342
|
-
...jsonBuildConfiguration.dependencies,
|
|
343
|
-
}
|
|
344
|
-
this.jsonDevDependencies = {
|
|
345
|
-
...this.jsonDevDependencies,
|
|
346
|
-
...jsonBuildConfiguration.devDependencies,
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
this.substitutionsVariables = {
|
|
350
|
-
...this.#parentBuildConfigurations.substitutionsVariables,
|
|
351
|
-
properties: {
|
|
352
|
-
...this.substitutionsVariables.properties,
|
|
353
|
-
...this.properties,
|
|
354
|
-
},
|
|
355
|
-
configuration: {
|
|
356
|
-
...jsonBuildConfiguration,
|
|
357
|
-
name: this.#buildConfigurationName,
|
|
358
|
-
},
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
// Add the buildFolderRelativePath property.
|
|
362
|
-
// Note: the async initialiser was needed due to this async operation.
|
|
363
|
-
const properties = this.substitutionsVariables.properties
|
|
364
|
-
properties.buildFolderRelativePath = await this.getBuildFolderRelativePath()
|
|
365
|
-
|
|
366
|
-
// Please note that substitutionsVariables is not fully set at this point;
|
|
367
|
-
// it will be in the async initialiser after the constructor returns.
|
|
368
|
-
this.#actions = new XpmLiquidActions({
|
|
369
|
-
log: this.#parentBuildConfigurations.log,
|
|
370
|
-
engine: this.#parentBuildConfigurations.engine,
|
|
371
|
-
substitutionsVariables: this.substitutionsVariables,
|
|
372
|
-
inheritedActionsMap,
|
|
373
|
-
jsonActions: this.jsonBuildConfiguration.actions,
|
|
374
|
-
})
|
|
375
|
-
// Note: this must be done manually by the application.
|
|
376
|
-
// await this.#actions.initialise()
|
|
377
|
-
|
|
378
|
-
log.trace(
|
|
379
|
-
`${XpmLiquidBuildConfiguration.name}.initialise() =>`,
|
|
380
|
-
this.#buildConfigurationName
|
|
381
|
-
)
|
|
382
|
-
log.trace('properties => ', this.properties)
|
|
383
|
-
log.trace('dependencies => ', this.jsonDependencies)
|
|
384
|
-
log.trace('devDependencies => ', this.jsonDevDependencies)
|
|
385
|
-
// log.trace('substitutionsVariables => ', this.substitutionsVariables)
|
|
386
|
-
|
|
387
|
-
this.#isInitialised = true
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
// --------------------------------------------------------------------------
|
|
391
|
-
// Methods.
|
|
392
|
-
|
|
393
|
-
get actions(): XpmLiquidActions {
|
|
394
|
-
assert(this.#actions !== undefined)
|
|
395
|
-
return this.#actions
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
async getBuildFolderRelativePath(): Promise<string> {
|
|
399
|
-
this.#buildFolderRelativePath ??= await this.#getBuildFolderRelativePath()
|
|
400
|
-
return this.#buildFolderRelativePath
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
async #getBuildFolderRelativePath(): Promise<string> {
|
|
404
|
-
const log = this.#parentBuildConfigurations.log
|
|
405
|
-
|
|
406
|
-
let folderPath: string
|
|
407
|
-
if (
|
|
408
|
-
buildFolderRelativePathPropertyName in
|
|
409
|
-
this.substitutionsVariables.properties
|
|
410
|
-
) {
|
|
411
|
-
folderPath = this.substitutionsVariables.properties[
|
|
412
|
-
buildFolderRelativePathPropertyName
|
|
413
|
-
] as string
|
|
414
|
-
if (folderPath !== '') {
|
|
415
|
-
try {
|
|
416
|
-
return await performSubstitutions({
|
|
417
|
-
log,
|
|
418
|
-
engine: this.#parentBuildConfigurations.engine,
|
|
419
|
-
input: folderPath,
|
|
420
|
-
substitutionsVariables: this.substitutionsVariables,
|
|
421
|
-
})
|
|
422
|
-
} catch (err) {
|
|
423
|
-
log.trace(err)
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
// Provide a default value, based on the name.
|
|
429
|
-
return path.join('build', filterPath(this.#buildConfigurationName))
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
// ----------------------------------------------------------------------------
|