@emulsify/cli 2.4.1 → 2.4.2
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.
|
@@ -409,6 +409,8 @@ export default async function systemInstall(name, options) {
|
|
|
409
409
|
}
|
|
410
410
|
}
|
|
411
411
|
catch (e) {
|
|
412
|
+
if (e instanceof CliError)
|
|
413
|
+
throw e;
|
|
412
414
|
console.error('System configuration errors:', e);
|
|
413
415
|
throw new CliError(`The system install failed due to the validation errors reported above. Please fix the errors in the "${systemConf.name}" configuration and try again.`);
|
|
414
416
|
}
|
package/dist/schemas/system.json
CHANGED
|
@@ -19,6 +19,10 @@
|
|
|
19
19
|
"format": "uri",
|
|
20
20
|
"description": "Git URL to the repository containing the system"
|
|
21
21
|
},
|
|
22
|
+
"minimumCliVersion": {
|
|
23
|
+
"type": "string",
|
|
24
|
+
"description": "Minimum Emulsify CLI version required to use this system"
|
|
25
|
+
},
|
|
22
26
|
"structure": {
|
|
23
27
|
"type": "array",
|
|
24
28
|
"description": "Objects that describe the structure of the system. Each structural item depicts a category within the system, such as a component folder, and MUST be implemented within each of the system's variants",
|
|
@@ -62,13 +66,11 @@
|
|
|
62
66
|
"$ref": "variant.json#/definitions/files"
|
|
63
67
|
}
|
|
64
68
|
},
|
|
65
|
-
"additionalProperties": false,
|
|
66
69
|
"required": ["platform", "structureImplementations", "components"]
|
|
67
70
|
}
|
|
68
71
|
]
|
|
69
72
|
}
|
|
70
73
|
}
|
|
71
74
|
},
|
|
72
|
-
"additionalProperties": false,
|
|
73
75
|
"required": ["name", "homepage", "repository", "structure"]
|
|
74
76
|
}
|
|
@@ -49,7 +49,6 @@
|
|
|
49
49
|
"description": "Relative path to the folder that will hold all of the assets, components, and files related to the structure"
|
|
50
50
|
}
|
|
51
51
|
},
|
|
52
|
-
"additionalProperties": false,
|
|
53
52
|
"required": ["name", "directory"]
|
|
54
53
|
}
|
|
55
54
|
},
|
|
@@ -83,7 +82,6 @@
|
|
|
83
82
|
}
|
|
84
83
|
}
|
|
85
84
|
},
|
|
86
|
-
"additionalProperties": false,
|
|
87
85
|
"required": ["name", "structure"]
|
|
88
86
|
}
|
|
89
87
|
},
|
|
@@ -110,7 +108,6 @@
|
|
|
110
108
|
"description": "Text describing the intended purpose of the folder"
|
|
111
109
|
}
|
|
112
110
|
},
|
|
113
|
-
"additionalProperties": false,
|
|
114
111
|
"required": ["name", "path", "destinationPath"]
|
|
115
112
|
}
|
|
116
113
|
},
|
|
@@ -137,7 +134,6 @@
|
|
|
137
134
|
"description": "Text describing the intended purpose of the file"
|
|
138
135
|
}
|
|
139
136
|
},
|
|
140
|
-
"additionalProperties": false,
|
|
141
137
|
"required": ["name", "path", "destinationPath"]
|
|
142
138
|
}
|
|
143
139
|
}
|
|
@@ -159,7 +155,6 @@
|
|
|
159
155
|
"$ref": "#/definitions/files"
|
|
160
156
|
}
|
|
161
157
|
},
|
|
162
|
-
"additionalProperties": false,
|
|
163
158
|
"required": [
|
|
164
159
|
"platform",
|
|
165
160
|
"structureImplementations",
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { Ajv } from 'ajv';
|
|
2
2
|
import addFormats from 'ajv-formats';
|
|
3
|
+
import CliError from '../../lib/CliError.js';
|
|
4
|
+
import log from '../../lib/log.js';
|
|
5
|
+
const upgradeCommand = 'npm i -g @emulsify/cli@latest';
|
|
3
6
|
async function loadSchemas() {
|
|
4
7
|
const [{ default: systemSchema }, { default: variantSchema }] = await Promise.all([
|
|
5
8
|
import('../../schemas/system.json', { with: { type: 'json' } }),
|
|
@@ -7,21 +10,70 @@ async function loadSchemas() {
|
|
|
7
10
|
]);
|
|
8
11
|
return { systemSchema, variantSchema };
|
|
9
12
|
}
|
|
13
|
+
async function createValidator() {
|
|
14
|
+
const [schemas, { default: packageInfo }] = await Promise.all([
|
|
15
|
+
loadSchemas(),
|
|
16
|
+
import('../../../package.json', { with: { type: 'json' } }),
|
|
17
|
+
]);
|
|
18
|
+
const ajv = new Ajv();
|
|
19
|
+
addFormats(ajv, ['uri']);
|
|
20
|
+
ajv.addSchema(schemas.variantSchema, 'variant.json');
|
|
21
|
+
return {
|
|
22
|
+
validate: ajv.compile(schemas.systemSchema),
|
|
23
|
+
schemas,
|
|
24
|
+
runningVersion: packageInfo.version,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
10
27
|
let validatorPromise;
|
|
11
|
-
|
|
12
|
-
if (
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
28
|
+
function checkMinimumCliVersion({ name, minimumCliVersion }, runningVersion) {
|
|
29
|
+
if (minimumCliVersion === undefined)
|
|
30
|
+
return;
|
|
31
|
+
const minimum = minimumCliVersion.match(/^(\d+)\.(\d+)\.(\d+)(?:[-+].+)?$/);
|
|
32
|
+
if (!minimum) {
|
|
33
|
+
throw new CliError(`The ${JSON.stringify(name)} system has an invalid minimumCliVersion ${JSON.stringify(minimumCliVersion)}. Use a version such as "2.5.0".`);
|
|
34
|
+
}
|
|
35
|
+
const running = runningVersion.split(/[.+-]/, 3).map(Number);
|
|
36
|
+
const required = minimum.slice(1).map(Number);
|
|
37
|
+
const index = required.findIndex((part, i) => part !== running[i]);
|
|
38
|
+
if (index !== -1 && running[index] < required[index]) {
|
|
39
|
+
throw new CliError(`The ${JSON.stringify(name)} system requires Emulsify CLI ${minimumCliVersion} or newer. You are running ${runningVersion}. Upgrade with: ${upgradeCommand}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function warnUnknownProperties(systemConfig, { systemSchema, variantSchema }) {
|
|
43
|
+
const unknown = [];
|
|
44
|
+
const collect = (value, properties, location) => {
|
|
45
|
+
const keys = Object.keys(value).filter((key) => !Object.hasOwn(properties, key));
|
|
46
|
+
if (keys.length > 0) {
|
|
47
|
+
unknown.push(`${location}: ${keys.join(', ')}`);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
collect(systemConfig, systemSchema.properties, 'system');
|
|
51
|
+
const variantProperties = systemSchema.properties.variants.items.anyOf[0].properties;
|
|
52
|
+
const items = [
|
|
53
|
+
['structureImplementations', 'structure implementation'],
|
|
54
|
+
['components', 'component'],
|
|
55
|
+
['directories', 'directory'],
|
|
56
|
+
['files', 'file'],
|
|
57
|
+
];
|
|
58
|
+
for (const [index, variant] of (systemConfig.variants ?? []).entries()) {
|
|
59
|
+
const location = `variant[${index}] (${JSON.stringify(variant.platform)})`;
|
|
60
|
+
collect(variant, variantProperties, location);
|
|
61
|
+
for (const [key, label] of items) {
|
|
62
|
+
for (const item of variant[key] ?? []) {
|
|
63
|
+
collect(item, variantSchema.definitions[key].items.properties, `${location} ${label} ${JSON.stringify(item.name)}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (unknown.length > 0) {
|
|
68
|
+
log('warn', `This system uses configuration this version of Emulsify CLI does not understand (${unknown.join('; ')}). Upgrade with \`${upgradeCommand}\` if the system is not behaving as documented.`);
|
|
19
69
|
}
|
|
20
|
-
return validatorPromise;
|
|
21
70
|
}
|
|
22
71
|
export default async function validateSystemConfig(systemConfig) {
|
|
23
|
-
const validate = await
|
|
72
|
+
const { validate, schemas, runningVersion } = await (validatorPromise ??=
|
|
73
|
+
createValidator());
|
|
24
74
|
if (validate(systemConfig)) {
|
|
75
|
+
checkMinimumCliVersion(systemConfig, runningVersion);
|
|
76
|
+
warnUnknownProperties(systemConfig, schemas);
|
|
25
77
|
return { valid: true, systemConfig };
|
|
26
78
|
}
|
|
27
79
|
return { valid: false, errors: validate.errors };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@emulsify/cli",
|
|
3
3
|
"productName": "Emulsify CLI",
|
|
4
|
-
"version": "2.4.
|
|
4
|
+
"version": "2.4.2",
|
|
5
5
|
"description": "Build and use component systems in Drupal, WordPress, or standalone front ends.",
|
|
6
6
|
"repository": "git@github.com:emulsify-ds/emulsify-cli.git",
|
|
7
7
|
"author": "Patrick Coffey <patrickcoffey48@gmail.com>",
|
|
@@ -80,6 +80,6 @@
|
|
|
80
80
|
"consola": "^3.4.2",
|
|
81
81
|
"fs-extra": "^11.4.0",
|
|
82
82
|
"progress": "^2.0.3",
|
|
83
|
-
"simple-git": "^
|
|
83
|
+
"simple-git": "^4.0.2"
|
|
84
84
|
}
|
|
85
85
|
}
|