@squiz/component-cli-lib 1.2.13-alpha.2 → 1.2.13-alpha.4

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 (32) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/build.js +23 -0
  3. package/lib/index.js +247 -8
  4. package/lib/index.js.map +7 -1
  5. package/lib/integration-tests/helper.d.ts +1 -1
  6. package/package.json +12 -10
  7. package/src/component-dev.ts +6 -1
  8. package/src/integration-tests/__components__/cmp-format-string/manifest.json +1 -1
  9. package/src/integration-tests/helper.ts +17 -12
  10. package/src/integration-tests/upload-and-render-component.integration.spec.ts +38 -24
  11. package/tsconfig.json +4 -2
  12. package/tsconfig.tsbuildinfo +1 -1
  13. package/lib/component-dev-folder-structures.integration.spec.js +0 -73
  14. package/lib/component-dev-folder-structures.integration.spec.js.map +0 -1
  15. package/lib/component-dev.integration.spec.js +0 -57
  16. package/lib/component-dev.integration.spec.js.map +0 -1
  17. package/lib/component-dev.js +0 -60
  18. package/lib/component-dev.js.map +0 -1
  19. package/lib/integration-tests/__components__/big-package/manifest.json +0 -35
  20. package/lib/integration-tests/__components__/cmp-format-string/manifest.json +0 -40
  21. package/lib/integration-tests/__components__/cmp-static-file-test/manifest.json +0 -39
  22. package/lib/integration-tests/__components__/invalid-manifest/manifest.json +0 -27
  23. package/lib/integration-tests/helper.js +0 -141
  24. package/lib/integration-tests/helper.js.map +0 -1
  25. package/lib/integration-tests/service-deployment.integration.spec.js +0 -51
  26. package/lib/integration-tests/service-deployment.integration.spec.js.map +0 -1
  27. package/lib/integration-tests/test-setup.js +0 -3
  28. package/lib/integration-tests/test-setup.js.map +0 -1
  29. package/lib/integration-tests/upload-and-render-component.integration.spec.js +0 -237
  30. package/lib/integration-tests/upload-and-render-component.integration.spec.js.map +0 -1
  31. package/lib/upload-component-folder.js +0 -117
  32. package/lib/upload-component-folder.js.map +0 -1
@@ -16,7 +16,7 @@ export declare const renderService: import("axios").AxiosInstance;
16
16
  export declare const contentService: import("axios").AxiosInstance;
17
17
  export declare const ci_buildVersion: string;
18
18
  export declare const ci_buildBranch: string;
19
- export declare function getTestComponents(): string[];
19
+ export declare function getTestComponents(): Promise<import("@squiz/component-lib").ManifestV1[]>;
20
20
  export declare function createFile(filePath: string, sizeInMB: number): Promise<void>;
21
21
  export declare function removeFile(filePath: string): void;
22
22
  export declare function deleteComponentSet(webPath: string): Promise<void>;
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@squiz/component-cli-lib",
3
- "version": "1.2.13-alpha.2",
3
+ "version": "1.2.13-alpha.4",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
7
- "compile": "tsc",
7
+ "compile": "node ./build.js && tsc",
8
8
  "lint": "eslint ./src --ext .ts",
9
9
  "test": "jest -c jest.config.ts",
10
10
  "test:integration": "jest -c jest.integration.config.ts",
@@ -13,12 +13,19 @@
13
13
  "author": "",
14
14
  "license": "ISC",
15
15
  "devDependencies": {
16
+ "@squiz/component-lib": "1.2.13-alpha.4",
17
+ "@squiz/component-web-api-lib": "1.2.13-alpha.4",
18
+ "@squiz/dx-common-lib": "1.2.13-alpha.4",
19
+ "@squiz/dx-json-schema-lib": "1.2.13-alpha.4",
20
+ "@squiz/dx-logger-lib": "1.2.13-alpha.4",
21
+ "@squiz/virus-scanner-lib": "1.2.13-alpha.4",
16
22
  "@types/cli-color": "2.0.2",
17
23
  "@types/express": "4.17.14",
18
24
  "@types/jest": "28.1.8",
19
25
  "@types/node": "17.0.27",
20
26
  "@types/supertest": "2.0.12",
21
27
  "dotenv": "16.0.3",
28
+ "esbuild": "0.16.17",
22
29
  "eslint": "8.22.0",
23
30
  "jest": "28.1.3",
24
31
  "ts-jest": "28.0.8",
@@ -27,18 +34,13 @@
27
34
  "typescript": "4.9.3"
28
35
  },
29
36
  "dependencies": {
30
- "@squiz/component-lib": "1.2.13-alpha.2",
31
- "@squiz/component-web-api-lib": "1.2.13-alpha.2",
32
- "@squiz/dx-common-lib": "1.2.13-alpha.2",
33
- "@squiz/dx-json-schema-lib": "1.2.13-alpha.2",
34
- "@squiz/dx-logger-lib": "1.2.13-alpha.2",
35
- "@squiz/render-runtime-lib": "1.2.13-alpha.2",
36
- "@squiz/virus-scanner-lib": "1.2.13-alpha.2",
37
+ "@squiz/render-runtime-lib": "1.2.13-alpha.4",
37
38
  "archiver": "5.3.1",
38
39
  "axios": "0.27.2",
39
40
  "cli-color": "^2.0.2",
41
+ "esbuild": "^0.17.0",
40
42
  "open": "^8.4.0",
41
43
  "supertest": "^6.2.3"
42
44
  },
43
- "gitHead": "f93643bf518d1d92d7ea3b44bd9114ca43358bf3"
45
+ "gitHead": "af8baa311cec5b438ccd989b261fd139149d9a0e"
44
46
  }
@@ -24,7 +24,11 @@ export function startDevelopmentRender(
24
24
  componentPath: string,
25
25
  options: { port: number; loggingFormat?: LoggerOptions['format']; noBrowser?: boolean },
26
26
  ) {
27
- const logger = getLogger({ name: 'component-dev', format: options.loggingFormat || 'human' });
27
+ const logger = getLogger({
28
+ name: 'component-dev',
29
+ format: options.loggingFormat || 'human',
30
+ silent: process.env.NODE_ENV === 'test',
31
+ });
28
32
  const dataMountPoint = path.resolve(process.cwd(), componentPath);
29
33
 
30
34
  const rootUrl = `http://localhost:${options.port}`;
@@ -34,6 +38,7 @@ export function startDevelopmentRender(
34
38
  dataMountPoint,
35
39
  shouldCacheResponses: false,
36
40
  workerTimeout: 5_000,
41
+ numOfWorkers: 2,
37
42
  },
38
43
  logger,
39
44
  );
@@ -5,7 +5,7 @@
5
5
  "version": "1.0.0",
6
6
  "mainFunction": "main",
7
7
  "displayName": "some-display-name",
8
- "namespace": "fixtures",
8
+ "namespace": "smoke-test-components",
9
9
  "description": "some-description",
10
10
  "functions": [
11
11
  {
@@ -1,14 +1,15 @@
1
1
  import axios from 'axios';
2
- import fs from 'fs';
3
2
  import path from 'path';
4
3
 
5
4
  import fsp from 'fs/promises';
6
5
  import { randomBytes } from 'crypto';
7
- import { ComponentSetWebModelForCreate } from '@squiz/component-lib';
6
+ import { ComponentSetWebModelForCreate, ManifestServiceForDev } from '@squiz/component-lib';
8
7
  import { parseEnvVarForVar } from '@squiz/dx-common-lib';
9
8
  import { ContentApi } from '@squiz/component-web-api-lib';
10
9
  import { config } from 'dotenv';
11
10
  import { execSync } from 'child_process';
11
+ import { getLogger } from '@squiz/dx-logger-lib';
12
+ import { JsonValidationService } from '@squiz/dx-json-schema-lib';
12
13
 
13
14
  config();
14
15
 
@@ -52,6 +53,13 @@ const ALL_PERMISSIONS_ROLE = {
52
53
 
53
54
  'COMPONENT_SET_ENVIRONMENT_READ',
54
55
  'COMPONENT_SET_ENVIRONMENT_WRITE',
56
+
57
+ 'CONTENT_SCHEMA_READ',
58
+ 'CONTENT_SCHEMA_WRITE',
59
+ 'CONTENT_ITEM_READ',
60
+ 'CONTENT_ITEM_WRITE',
61
+ 'SETTINGS_READ',
62
+ 'SETTINGS_WRITE',
55
63
  ],
56
64
  };
57
65
 
@@ -102,17 +110,14 @@ export const contentService = axios.create({
102
110
  export const ci_buildVersion = configObj.ci_buildVersion;
103
111
  export const ci_buildBranch = configObj.ci_buildBranch;
104
112
 
105
- export function getTestComponents(): string[] {
106
- const componets = [];
113
+ export async function getTestComponents() {
107
114
  const componentsDir = path.join(__dirname, '/__components__/');
108
- const files = fs.readdirSync(componentsDir);
109
- for (const file of files) {
110
- const stat = fs.statSync(path.join(componentsDir, file));
111
- if (stat.isDirectory() && file.substring(0, 4) === 'cmp-') {
112
- componets.push(file);
113
- }
114
- }
115
- return componets;
115
+ const manifestService = new ManifestServiceForDev(
116
+ componentsDir,
117
+ getLogger({ name: 'getTestComponents' }),
118
+ new JsonValidationService(),
119
+ );
120
+ return await manifestService.listAllComponentManifests();
116
121
  }
117
122
  export async function createFile(filePath: string, sizeInMB: number) {
118
123
  const content = randomBytes(sizeInMB * 1000000);
@@ -10,6 +10,7 @@ import configObj, {
10
10
  addContentItem,
11
11
  deleteContentItem,
12
12
  managementServiceRoot,
13
+ contentService,
13
14
  } from './helper';
14
15
  import color from 'cli-color';
15
16
  import path from 'path';
@@ -31,6 +32,7 @@ describe('uploading a component', () => {
31
32
  beforeAll(async () => {
32
33
  await fsp.rm(testFilesDir, { force: true, recursive: true });
33
34
  await fsp.mkdir(testFilesDir);
35
+ logger.silent = true;
34
36
  });
35
37
 
36
38
  afterAll(async () => {
@@ -38,16 +40,19 @@ describe('uploading a component', () => {
38
40
  await deleteComponentSet(webPath);
39
41
  await deleteContentItem(contentItemId);
40
42
 
41
- for (const componentName of getTestComponents()) {
42
- try {
43
- await managementService.delete(`/component/smoke-test-components/${componentName}`);
44
- } catch {
45
- // no op
46
- }
43
+ for (const manifest of await getTestComponents()) {
44
+ await managementService.delete(`/component/${manifest.getName()}`).catch(() => null);
45
+ await contentService
46
+ .delete(
47
+ `/content-schema/${manifest.getName()}/${manifest.getVersion()}/${
48
+ manifest.getComponentFunctionByName().name
49
+ }`,
50
+ )
51
+ .catch(() => null);
47
52
  }
48
-
49
53
  // clean up the test componnet files
50
54
  await fsp.rm(testFilesDir, { force: true, recursive: true });
55
+ logger.silent = false;
51
56
  });
52
57
 
53
58
  describe('Test isolated test cases', () => {
@@ -74,7 +79,9 @@ describe('uploading a component', () => {
74
79
  testFilesDir,
75
80
  );
76
81
  expect(mockConsoleError.mock.calls[0][0]).toEqual(
77
- color.red('failed validation: /name: pattern must match pattern "^[a-zA-Z0-9_\\-]+$"'),
82
+ color.red(
83
+ 'failed validation: Value in `#/name` should match `^[a-zA-Z0-9_\\-]+$`, but received `invalid-manifes@t`',
84
+ ),
78
85
  );
79
86
  });
80
87
 
@@ -101,12 +108,15 @@ describe('uploading a component', () => {
101
108
  beforeAll(async () => {
102
109
  await deleteComponentSet(webPath);
103
110
  await deleteContentItem(contentItemId);
104
- for (const componentName of getTestComponents()) {
105
- try {
106
- await managementService.delete(`/component/${componentName}`);
107
- } catch {
108
- // no op
109
- }
111
+ for (const manifest of await getTestComponents()) {
112
+ await managementService.delete(`/component/${manifest.getName()}`).catch(() => null);
113
+ await contentService
114
+ .delete(
115
+ `/content-schema/${manifest.getName()}/${manifest.getVersion()}/${
116
+ manifest.getComponentFunctionByName().name
117
+ }`,
118
+ )
119
+ .catch(() => null);
110
120
  }
111
121
  });
112
122
 
@@ -122,7 +132,8 @@ describe('uploading a component', () => {
122
132
  it('Should upload the component and return a valid url to preview', async () => {
123
133
  const componentPath = path.join(__dirname, '/__components__/cmp-format-string');
124
134
  await uploadComponentFolder(managementServiceRoot, configObj.managementServiceUrl, componentPath, testFilesDir);
125
- const uploadedComponent = '<a href="/r/fixtures/cmp-format-string/1.0.0?_previewKey=test-preview">1.0.0</a>';
135
+ const uploadedComponent =
136
+ '<a href="/r/smoke-test-components/cmp-format-string/1.0.0?_previewKey=test-preview">1.0.0</a>';
126
137
  const get = await supertest(configObj.renderServiceUrl).get('/');
127
138
  expect(get.status).toEqual(200);
128
139
  expect((get as any)?.res?.text).toContain(uploadedComponent);
@@ -136,20 +147,20 @@ describe('uploading a component', () => {
136
147
  headers: {},
137
148
  environmentVariables: {},
138
149
  components: {
139
- 'fixtures/cmp-format-string': [{ environmentVariables: {}, version: '1.0.0' }],
150
+ 'smoke-test-components/cmp-format-string': [{ environmentVariables: {}, version: '1.0.0' }],
140
151
  },
141
152
  componentVersionRules: {},
142
153
  };
143
154
  await addComponentSet(componentSet);
144
155
  await addContentItem({
145
156
  id: contentItemId,
146
- schemaName: 'fixtures/cmp-format-string/1.0.0/main',
157
+ schemaName: 'smoke-test-components/cmp-format-string/1.0.0/main',
147
158
  content: {
148
159
  text: 'from-content-item-service',
149
160
  },
150
161
  });
151
162
  const response = await renderService.get(
152
- `/r/fixtures/cmp-format-string/1.0.0/?_contentItemId=${contentItemId}&_componentSet=${webPath}`,
163
+ `/r/smoke-test-components/cmp-format-string/1.0.0/?_contentItemId=${contentItemId}&_componentSet=${webPath}`,
153
164
  );
154
165
  expect(response.status).toEqual(200);
155
166
  expect(response.data).toEqual(`<div>Input: from-content-item-service</div>`);
@@ -163,12 +174,15 @@ describe('uploading a component', () => {
163
174
  beforeAll(async () => {
164
175
  await deleteComponentSet(webPath);
165
176
  await deleteContentItem(contentItemId);
166
- for (const componentName of getTestComponents()) {
167
- try {
168
- await managementService.delete(`/component/${componentName}`);
169
- } catch {
170
- // no op
171
- }
177
+ for (const manifest of await getTestComponents()) {
178
+ await managementService.delete(`/component/${manifest.getName()}`).catch(() => null);
179
+ await contentService
180
+ .delete(
181
+ `/content-schema/${manifest.getName()}/${manifest.getVersion()}/${
182
+ manifest.getComponentFunctionByName().name
183
+ }`,
184
+ )
185
+ .catch(() => null);
172
186
  }
173
187
  });
174
188
 
package/tsconfig.json CHANGED
@@ -2,11 +2,13 @@
2
2
  "extends": "../../tsconfig.json",
3
3
 
4
4
  "compilerOptions": {
5
- "outDir": "lib/",
5
+ "outDir": "lib",
6
6
  "resolveJsonModule": true,
7
7
  "composite": true,
8
8
  "rootDir": "./src",
9
- "sourceMap": true
9
+ "sourceMap": true,
10
+ "declaration": true,
11
+ "emitDeclarationOnly": true
10
12
  },
11
13
 
12
14
  "references": [