@squiz/component-cli-lib 1.32.1-alpha.8 → 1.33.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/.npm/_logs/{2023-04-21T03_36_57_069Z-debug-0.log → 2023-05-10T02_49_28_328Z-debug-0.log} +14 -14
- package/lib/index.js +356 -119
- package/lib/index.js.map +4 -4
- package/package.json +9 -9
- package/src/component-dev.ts +11 -0
- package/src/integration-tests/__components__/matrix-asset-uri/manifest.json +1 -1
- package/src/integration-tests/upload-and-render-component.integration.spec.ts +2 -2
- package/src/upload-component-folder.ts +27 -26
- package/tsconfig.tsbuildinfo +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@squiz/component-cli-lib",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.33.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
"author": "",
|
|
14
14
|
"license": "ISC",
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"@squiz/component-lib": "1.
|
|
17
|
-
"@squiz/component-web-api-lib": "1.
|
|
18
|
-
"@squiz/dx-common-lib": "1.
|
|
19
|
-
"@squiz/dx-json-schema-lib": "1.
|
|
20
|
-
"@squiz/dx-logger-lib": "1.
|
|
21
|
-
"@squiz/virus-scanner-lib": "1.
|
|
16
|
+
"@squiz/component-lib": "1.33.0",
|
|
17
|
+
"@squiz/component-web-api-lib": "1.33.0",
|
|
18
|
+
"@squiz/dx-common-lib": "1.33.0",
|
|
19
|
+
"@squiz/dx-json-schema-lib": "1.33.0",
|
|
20
|
+
"@squiz/dx-logger-lib": "1.33.0",
|
|
21
|
+
"@squiz/virus-scanner-lib": "1.33.0",
|
|
22
22
|
"@types/cli-color": "2.0.2",
|
|
23
23
|
"@types/express": "4.17.17",
|
|
24
24
|
"@types/jest": "28.1.8",
|
|
@@ -32,12 +32,12 @@
|
|
|
32
32
|
"typescript": "4.9.4"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@squiz/render-runtime-lib": "1.
|
|
35
|
+
"@squiz/render-runtime-lib": "1.33.0",
|
|
36
36
|
"archiver": "5.3.1",
|
|
37
37
|
"axios": "1.3.2",
|
|
38
38
|
"cli-color": "^2.0.2",
|
|
39
39
|
"open": "^8.4.0",
|
|
40
40
|
"supertest": "^6.2.3"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "39f24b55ea7d5077df241753f723d549a117e91d"
|
|
43
43
|
}
|
package/src/component-dev.ts
CHANGED
|
@@ -9,6 +9,7 @@ import path from 'path';
|
|
|
9
9
|
import { ComponentFunctionService, ComponentSetServiceForLocalDev, ManifestServiceForDev } from '@squiz/component-lib';
|
|
10
10
|
import open from 'open';
|
|
11
11
|
import { DevelopmentApiKeyService } from '@squiz/dx-common-lib';
|
|
12
|
+
import { ComponentLogger } from '@squiz/component-logger-lib';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* startDevelopmentRender starts a dev-mode render stack for any
|
|
@@ -27,6 +28,15 @@ export function startDevelopmentRender(
|
|
|
27
28
|
format: options.loggingFormat || 'human',
|
|
28
29
|
silent: process.env.NODE_ENV === 'test',
|
|
29
30
|
});
|
|
31
|
+
|
|
32
|
+
const devComponentLogger = new ComponentLogger({
|
|
33
|
+
enabled: false,
|
|
34
|
+
tenantId: 'dev-tenant-id',
|
|
35
|
+
logUrl: '',
|
|
36
|
+
key: '',
|
|
37
|
+
tags: 'tag-foo tag-foo2',
|
|
38
|
+
});
|
|
39
|
+
|
|
30
40
|
const dataMountPoint = path.resolve(process.cwd(), componentPath);
|
|
31
41
|
|
|
32
42
|
const rootUrl = `http://localhost:${options.port}`;
|
|
@@ -40,6 +50,7 @@ export function startDevelopmentRender(
|
|
|
40
50
|
maxWorkers: 2,
|
|
41
51
|
},
|
|
42
52
|
logger,
|
|
53
|
+
devComponentLogger,
|
|
43
54
|
);
|
|
44
55
|
const componentFunctionService = new ComponentFunctionService(rootUrl);
|
|
45
56
|
const componentSetService = new ComponentSetServiceForLocalDev(logger);
|
|
@@ -191,7 +191,7 @@ describe('uploading a component', () => {
|
|
|
191
191
|
id: contentItemId,
|
|
192
192
|
schemaName: 'smoke-test-components/matrix-asset-uri/1.0.0/main',
|
|
193
193
|
content: {
|
|
194
|
-
text: 'matrix-asset://canary.uat.matrix.squiz.cloud/
|
|
194
|
+
text: 'matrix-asset://canary.uat.matrix.squiz.cloud/123',
|
|
195
195
|
},
|
|
196
196
|
});
|
|
197
197
|
|
|
@@ -199,7 +199,7 @@ describe('uploading a component', () => {
|
|
|
199
199
|
`/r/smoke-test-components/matrix-asset-uri/1.0.0?_componentSet=${webPath}&_contentItemId=${contentItemId}`,
|
|
200
200
|
);
|
|
201
201
|
expect(response.status).toEqual(200);
|
|
202
|
-
expect(response.data).toEqual(`<div>Input: matrix-asset://canary.uat.matrix.squiz.cloud/
|
|
202
|
+
expect(response.data).toEqual(`<div>Input: matrix-asset://canary.uat.matrix.squiz.cloud/123</div>`);
|
|
203
203
|
});
|
|
204
204
|
});
|
|
205
205
|
|
|
@@ -19,7 +19,12 @@ export async function uploadComponentFolder(
|
|
|
19
19
|
const tmpDir = await fsp.mkdtemp(path.resolve(baseTempDir, 'cmp-upload'));
|
|
20
20
|
|
|
21
21
|
try {
|
|
22
|
-
|
|
22
|
+
const manifestService = new ManifestServiceForDev(folderPath, logger);
|
|
23
|
+
const manifestPath = path.join(folderPath, `manifest.json`);
|
|
24
|
+
const manifest = await manifestService.readManifest(manifestPath);
|
|
25
|
+
await manifestService.assertManifestIsValid(manifestPath, manifest.getModel());
|
|
26
|
+
|
|
27
|
+
await preUploadChecks(apiClient, componentServiceManagementUrl, manifest);
|
|
23
28
|
logger.info('Initial scanning');
|
|
24
29
|
const zip = await zipDirectory(folderPath, tmpDir);
|
|
25
30
|
|
|
@@ -39,28 +44,27 @@ export async function uploadComponentFolder(
|
|
|
39
44
|
apiClient.post(`/v1/upload-component/next/${initialUpload.id}`, {}, { baseURL: componentServiceManagementUrl }),
|
|
40
45
|
);
|
|
41
46
|
|
|
42
|
-
if (result
|
|
43
|
-
let retriesAllowed =
|
|
44
|
-
while (retriesAllowed > 0
|
|
47
|
+
if (!isAxiosResponse(result)) {
|
|
48
|
+
let retriesAllowed = 12;
|
|
49
|
+
while (retriesAllowed > 0) {
|
|
45
50
|
logger.info(
|
|
46
51
|
`deployment id: ${initialUpload.id} status: ${color.yellow(
|
|
47
|
-
`
|
|
52
|
+
`unknown, retrying to check the upload status ${retriesAllowed} more times`,
|
|
48
53
|
)}`,
|
|
49
54
|
);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
);
|
|
55
|
+
if (await checkIfVersionExists(apiClient, componentServiceManagementUrl, manifest)) {
|
|
56
|
+
result = {
|
|
57
|
+
status: 'successful',
|
|
58
|
+
accessLink: 'unknown',
|
|
59
|
+
};
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
await new Promise((r) => setTimeout(r, 10000));
|
|
59
63
|
retriesAllowed--;
|
|
60
64
|
}
|
|
61
65
|
if (retriesAllowed === 0) {
|
|
62
|
-
logger.error(`deployment id: ${initialUpload.id} status: ${color.red('failed
|
|
63
|
-
throw new Error(
|
|
66
|
+
logger.error(`deployment id: ${initialUpload.id} status: ${color.red('failed to check the upload status')}`);
|
|
67
|
+
throw new Error(result.toString());
|
|
64
68
|
}
|
|
65
69
|
}
|
|
66
70
|
|
|
@@ -86,16 +90,9 @@ export async function uploadComponentFolder(
|
|
|
86
90
|
}
|
|
87
91
|
}
|
|
88
92
|
|
|
89
|
-
async function preUploadChecks(apiClient: AxiosInstance, managementURL: string,
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const result = await service.readManifest(manifestPath);
|
|
94
|
-
|
|
95
|
-
await service.assertManifestIsValid(manifestPath, result.getModel());
|
|
96
|
-
|
|
97
|
-
if (await checkIfVersionExists(apiClient, managementURL, result)) {
|
|
98
|
-
throw new Error(`Cannot upload component version, ${result.getName()} ${result.getVersion()} already exists`);
|
|
93
|
+
async function preUploadChecks(apiClient: AxiosInstance, managementURL: string, manifest: Manifest) {
|
|
94
|
+
if (await checkIfVersionExists(apiClient, managementURL, manifest)) {
|
|
95
|
+
throw new Error(`Cannot upload component version, ${manifest.getName()} ${manifest.getVersion()} already exists`);
|
|
99
96
|
}
|
|
100
97
|
}
|
|
101
98
|
|
|
@@ -185,3 +182,7 @@ function handleError(error: any): Error {
|
|
|
185
182
|
function isAxiosError(error: any): error is AxiosError {
|
|
186
183
|
return error && error.isAxiosError === true;
|
|
187
184
|
}
|
|
185
|
+
|
|
186
|
+
function isAxiosResponse(response: unknown): response is AxiosResponse {
|
|
187
|
+
return response instanceof Object && Object.prototype.hasOwnProperty.call(response, 'status');
|
|
188
|
+
}
|