@squiz/component-cli-lib 1.2.1-alpha.99 → 1.2.3
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/.gitlab-ci.yml +42 -27
- package/CHANGELOG.md +88 -0
- package/jest.config.ts +3 -0
- package/jest.integration.config.ts +4 -0
- package/lib/component-dev-folder-structures.spec.d.ts +1 -0
- package/lib/component-dev-folder-structures.spec.js +58 -0
- package/lib/component-dev-folder-structures.spec.js.map +1 -0
- package/lib/component-dev.d.ts +4 -1
- package/lib/component-dev.js +24 -18
- package/lib/component-dev.js.map +1 -1
- package/lib/component-dev.spec.js +28 -65
- package/lib/component-dev.spec.js.map +1 -1
- package/lib/integration-tests/__components__/big-package/manifest.json +5 -2
- package/lib/integration-tests/__components__/cmp-static-file-test/manifest.json +8 -5
- package/lib/integration-tests/__components__/invalid-manifest/manifest.json +5 -2
- package/lib/integration-tests/helper.d.ts +6 -0
- package/lib/integration-tests/helper.js +31 -6
- package/lib/integration-tests/helper.js.map +1 -1
- package/lib/integration-tests/service-deployment.spec.js +36 -1
- package/lib/integration-tests/service-deployment.spec.js.map +1 -1
- package/lib/integration-tests/upload-and-render-component.spec.js +38 -17
- package/lib/integration-tests/upload-and-render-component.spec.js.map +1 -1
- package/lib/upload-component-folder.d.ts +1 -1
- package/lib/upload-component-folder.js +10 -6
- package/lib/upload-component-folder.js.map +1 -1
- package/package.json +10 -10
- package/src/component-dev-folder-structures.spec.ts +69 -0
- package/src/component-dev.spec.ts +31 -83
- package/src/component-dev.ts +40 -18
- package/src/integration-tests/__components__/big-package/manifest.json +5 -2
- package/src/integration-tests/__components__/cmp-static-file-test/manifest.json +8 -6
- package/src/integration-tests/__components__/invalid-manifest/manifest.json +5 -2
- package/src/integration-tests/helper.ts +28 -1
- package/src/integration-tests/service-deployment.spec.ts +51 -2
- package/src/integration-tests/upload-and-render-component.spec.ts +78 -17
- package/src/upload-component-folder.ts +16 -7
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -3,28 +3,35 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.removeFile = exports.createFile = exports.getTestComponents = exports.ci_buildBranch = exports.ci_buildVersion = exports.renderService = exports.managementService = void 0;
|
|
6
|
+
exports.addComponentSet = exports.deleteComponentSet = exports.removeFile = exports.createFile = exports.getTestComponents = exports.ci_buildBranch = exports.ci_buildVersion = exports.contentService = exports.renderService = exports.managementServiceRoot = exports.managementService = void 0;
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
10
10
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
11
11
|
const crypto_1 = require("crypto");
|
|
12
|
-
const
|
|
12
|
+
const dx_common_lib_1 = require("@squiz/dx-common-lib");
|
|
13
13
|
const dotenv_1 = require("dotenv");
|
|
14
14
|
(0, dotenv_1.config)();
|
|
15
15
|
const configObj = {
|
|
16
|
-
managementServiceUrl: (0,
|
|
17
|
-
renderServiceUrl: (0,
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
managementServiceUrl: (0, dx_common_lib_1.parseEnvVarForVar)('COMPONENT_MANAGEMENT_SERVICE_URL').replace(/\/+$/, ''),
|
|
17
|
+
renderServiceUrl: (0, dx_common_lib_1.parseEnvVarForVar)('COMPONENT_RENDER_SERVICE_URL').replace(/\/+$/, ''),
|
|
18
|
+
contentServiceUrl: (0, dx_common_lib_1.parseEnvVarForVar)('CONTENT_API_URL').replace(/\/+$/, ''),
|
|
19
|
+
ci_buildVersion: (0, dx_common_lib_1.parseEnvVarForVar)('CI_COMMIT_SHORT_SHA'),
|
|
20
|
+
ci_buildBranch: (0, dx_common_lib_1.parseEnvVarForVar)('CI_COMMIT_REF_NAME'),
|
|
20
21
|
};
|
|
21
22
|
exports.default = configObj;
|
|
22
23
|
exports.managementService = axios_1.default.create({
|
|
24
|
+
baseURL: configObj.managementServiceUrl + '/v1',
|
|
25
|
+
});
|
|
26
|
+
exports.managementServiceRoot = axios_1.default.create({
|
|
23
27
|
baseURL: configObj.managementServiceUrl,
|
|
24
28
|
});
|
|
25
29
|
exports.renderService = axios_1.default.create({
|
|
26
30
|
baseURL: configObj.renderServiceUrl,
|
|
27
31
|
});
|
|
32
|
+
exports.contentService = axios_1.default.create({
|
|
33
|
+
baseURL: configObj.contentServiceUrl,
|
|
34
|
+
});
|
|
28
35
|
exports.ci_buildVersion = configObj.ci_buildVersion;
|
|
29
36
|
exports.ci_buildBranch = configObj.ci_buildBranch;
|
|
30
37
|
function getTestComponents() {
|
|
@@ -49,4 +56,22 @@ function removeFile(filePath) {
|
|
|
49
56
|
promises_1.default.unlink(filePath);
|
|
50
57
|
}
|
|
51
58
|
exports.removeFile = removeFile;
|
|
59
|
+
async function deleteComponentSet(webPath) {
|
|
60
|
+
try {
|
|
61
|
+
await exports.managementService.delete(`/component-set/${webPath}`);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
// no ops
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.deleteComponentSet = deleteComponentSet;
|
|
68
|
+
async function addComponentSet(componentSet) {
|
|
69
|
+
try {
|
|
70
|
+
await exports.managementService.post(`/component-set`, componentSet);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
//no ops
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.addComponentSet = addComponentSet;
|
|
52
77
|
//# sourceMappingURL=helper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../../src/integration-tests/helper.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,4CAAoB;AACpB,gDAAwB;AAExB,2DAA8B;AAC9B,mCAAqC;
|
|
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AE;QACd,QAAQ;KACT;AACH,CAAC;AAND,0CAMC"}
|
|
@@ -3,14 +3,49 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const helper_1 = require("./helper");
|
|
4
4
|
describe('Verify latest services deployments', () => {
|
|
5
5
|
it('Should have latest Management API service', async () => {
|
|
6
|
-
const response = (await helper_1.
|
|
6
|
+
const response = (await helper_1.managementServiceRoot.get('/health')).data;
|
|
7
7
|
expect(response.buildVersion).toBe(helper_1.ci_buildVersion);
|
|
8
8
|
expect(response.buildBranch).toBe(helper_1.ci_buildBranch);
|
|
9
9
|
});
|
|
10
|
+
it('Should return 200 for Management API docs', async () => {
|
|
11
|
+
const req = await helper_1.managementService.get('/docs');
|
|
12
|
+
expect(req.status).toBe(200);
|
|
13
|
+
expect(req.headers['content-type']).toEqual('text/html; charset=utf-8');
|
|
14
|
+
});
|
|
15
|
+
it('Should return 200 for Management API docs.json', async () => {
|
|
16
|
+
const req = await helper_1.managementService.get('/docs.json');
|
|
17
|
+
expect(req.status).toBe(200);
|
|
18
|
+
expect(req.headers['content-type']).toEqual('application/json; charset=UTF-8');
|
|
19
|
+
});
|
|
10
20
|
it('Should have latest Render Runtime service', async () => {
|
|
11
21
|
const response = (await helper_1.renderService.get('/health')).data;
|
|
12
22
|
expect(response.buildVersion).toBe(helper_1.ci_buildVersion);
|
|
13
23
|
expect(response.buildBranch).toBe(helper_1.ci_buildBranch);
|
|
14
24
|
});
|
|
25
|
+
it('Should return 200 for Render Runtime API docs', async () => {
|
|
26
|
+
const req = await helper_1.renderService.get('/docs');
|
|
27
|
+
expect(req.status).toBe(200);
|
|
28
|
+
expect(req.headers['content-type']).toEqual('text/html; charset=utf-8');
|
|
29
|
+
});
|
|
30
|
+
it('Should return 200 for Render Runtime API docs.json', async () => {
|
|
31
|
+
const req = await helper_1.renderService.get('/docs.json');
|
|
32
|
+
expect(req.status).toBe(200);
|
|
33
|
+
expect(req.headers['content-type']).toEqual('application/json; charset=UTF-8');
|
|
34
|
+
});
|
|
35
|
+
it('Should have latest Content API service', async () => {
|
|
36
|
+
const response = (await helper_1.contentService.get('/health')).data;
|
|
37
|
+
expect(response.buildVersion).toBe(helper_1.ci_buildVersion);
|
|
38
|
+
expect(response.buildBranch).toBe(helper_1.ci_buildBranch);
|
|
39
|
+
});
|
|
40
|
+
it('Should return 200 for Content API docs', async () => {
|
|
41
|
+
const req = await helper_1.contentService.get('/docs');
|
|
42
|
+
expect(req.status).toBe(200);
|
|
43
|
+
expect(req.headers['content-type']).toEqual('text/html; charset=utf-8');
|
|
44
|
+
});
|
|
45
|
+
it('Should return 200 for Content API docs.json', async () => {
|
|
46
|
+
const req = await helper_1.contentService.get('/docs.json');
|
|
47
|
+
expect(req.status).toBe(200);
|
|
48
|
+
expect(req.headers['content-type']).toEqual('application/json; charset=UTF-8');
|
|
49
|
+
});
|
|
15
50
|
});
|
|
16
51
|
//# sourceMappingURL=service-deployment.spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service-deployment.spec.js","sourceRoot":"","sources":["../../src/integration-tests/service-deployment.spec.ts"],"names":[],"mappings":";;AAAA,
|
|
1
|
+
{"version":3,"file":"service-deployment.spec.js","sourceRoot":"","sources":["../../src/integration-tests/service-deployment.spec.ts"],"names":[],"mappings":";;AAAA,qCAOkB;AAQlB,QAAQ,CAAC,oCAAoC,EAAE,GAAG,EAAE;IAClD,EAAE,CAAC,2CAA2C,EAAE,KAAK,IAAI,EAAE;QACzD,MAAM,QAAQ,GAAe,CAAC,MAAM,8BAAqB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;QAC/E,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,wBAAe,CAAC,CAAC;QACpD,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,uBAAc,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2CAA2C,EA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C,GAAG,CAAC,CAAC;QAC7B,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC,iCAAiC,CAAC,CAAC;IACjF,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -32,19 +32,29 @@ const cli_color_1 = __importDefault(require("cli-color"));
|
|
|
32
32
|
const path_1 = __importDefault(require("path"));
|
|
33
33
|
const supertest_1 = __importDefault(require("supertest"));
|
|
34
34
|
const upload_component_folder_1 = require("../upload-component-folder");
|
|
35
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
35
36
|
const mockConsoleError = jest.fn();
|
|
36
37
|
const mockConsoleLog = jest.fn();
|
|
37
38
|
const orgConsoleError = console.error;
|
|
39
|
+
const webPath = 'set';
|
|
40
|
+
const testFilesDir = path_1.default.resolve(__dirname, 'test-files');
|
|
41
|
+
beforeAll(async () => {
|
|
42
|
+
await promises_1.default.rm(testFilesDir, { force: true, recursive: true });
|
|
43
|
+
await promises_1.default.mkdir(testFilesDir);
|
|
44
|
+
});
|
|
38
45
|
afterAll(async () => {
|
|
39
46
|
// clean up the component added by the test
|
|
47
|
+
await (0, helper_1.deleteComponentSet)(webPath);
|
|
40
48
|
for (const componentName of (0, helper_1.getTestComponents)()) {
|
|
41
49
|
try {
|
|
42
|
-
await helper_1.managementService.delete(`/component/${componentName}`);
|
|
50
|
+
await helper_1.managementService.delete(`/component/smoke-test-components/${componentName}`);
|
|
43
51
|
}
|
|
44
52
|
catch {
|
|
45
53
|
// no op
|
|
46
54
|
}
|
|
47
55
|
}
|
|
56
|
+
// clean up the test componnet files
|
|
57
|
+
await promises_1.default.rm(testFilesDir, { force: true, recursive: true });
|
|
48
58
|
});
|
|
49
59
|
describe('Test isolated test cases', () => {
|
|
50
60
|
beforeEach(() => {
|
|
@@ -54,21 +64,21 @@ describe('Test isolated test cases', () => {
|
|
|
54
64
|
it('Should fail uploading a component without manifest.json', async () => {
|
|
55
65
|
mockConsoleError.mockClear();
|
|
56
66
|
const componentPath = path_1.default.join(__dirname, '/__components__/invalid-upload');
|
|
57
|
-
await (0, index_1.uploadComponentFolder)(componentPath, helper_1.default.managementServiceUrl, helper_1.default.renderServiceUrl);
|
|
67
|
+
await (0, index_1.uploadComponentFolder)(componentPath, helper_1.default.managementServiceUrl + '/v1', helper_1.default.renderServiceUrl, testFilesDir);
|
|
58
68
|
expect(mockConsoleError.mock.calls[0][0]).toEqual(cli_color_1.default.red('manifest could not be found'));
|
|
59
69
|
});
|
|
60
70
|
it('Should fail uploading a component that has invalid manifest.json', async () => {
|
|
61
71
|
mockConsoleError.mockClear();
|
|
62
72
|
const componentPath = path_1.default.join(__dirname, '/__components__/invalid-manifest');
|
|
63
|
-
await (0, index_1.uploadComponentFolder)(componentPath, helper_1.default.managementServiceUrl, helper_1.default.renderServiceUrl);
|
|
64
|
-
expect(mockConsoleError.mock.calls[0][0]).toEqual(cli_color_1.default.red('/name
|
|
73
|
+
await (0, index_1.uploadComponentFolder)(componentPath, helper_1.default.managementServiceUrl + '/v1', helper_1.default.renderServiceUrl, testFilesDir);
|
|
74
|
+
expect(mockConsoleError.mock.calls[0][0]).toEqual(cli_color_1.default.red('failed validation: /name pattern must match pattern "^[a-zA-Z0-9_\\-]+$"'));
|
|
65
75
|
});
|
|
66
76
|
it('Should fail uploading the component that has size more than 100MB', async () => {
|
|
67
77
|
mockConsoleError.mockClear();
|
|
68
78
|
const componentPath = path_1.default.join(__dirname, '/__components__/big-package');
|
|
69
79
|
const filePath = `${componentPath}/105mb-file`;
|
|
70
80
|
await (0, helper_1.createFile)(filePath, 105); // Higher limit has been used because compression reduces the size if you use closer to 100MB
|
|
71
|
-
await (0, index_1.uploadComponentFolder)(componentPath, helper_1.default.managementServiceUrl, helper_1.default.renderServiceUrl);
|
|
81
|
+
await (0, index_1.uploadComponentFolder)(componentPath, helper_1.default.managementServiceUrl + '/v1', helper_1.default.renderServiceUrl, testFilesDir);
|
|
72
82
|
expect(mockConsoleError.mock.calls[0][0]).toEqual(cli_color_1.default.red(['File size exceeds the maximum limit of 100MB'].join('')));
|
|
73
83
|
(0, helper_1.removeFile)(filePath);
|
|
74
84
|
});
|
|
@@ -77,6 +87,7 @@ describe('Deploy basic component having a static file', () => {
|
|
|
77
87
|
// component to deploy for this test
|
|
78
88
|
const componentPath = path_1.default.join(__dirname, '/__components__/cmp-static-file-test');
|
|
79
89
|
beforeAll(async () => {
|
|
90
|
+
await (0, helper_1.deleteComponentSet)(webPath);
|
|
80
91
|
for (const componentName of (0, helper_1.getTestComponents)()) {
|
|
81
92
|
try {
|
|
82
93
|
await helper_1.managementService.delete(`/component/${componentName}`);
|
|
@@ -94,27 +105,37 @@ describe('Deploy basic component having a static file', () => {
|
|
|
94
105
|
console.error = orgConsoleError;
|
|
95
106
|
});
|
|
96
107
|
it('Should upload the component and return a valid url to preview', async () => {
|
|
97
|
-
var _a
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
const uploadedComponent = '<a href="/r/set/cmp-static-file-test/1.0.0">1.0.0</a>';
|
|
102
|
-
const get = await (0, supertest_1.default)(url).get('/');
|
|
108
|
+
var _a;
|
|
109
|
+
await (0, index_1.uploadComponentFolder)(componentPath, helper_1.default.managementServiceUrl + '/v1', helper_1.default.renderServiceUrl, testFilesDir);
|
|
110
|
+
const uploadedComponent = '<a href="/r/set/smoke-test-components/cmp-static-file-test/1.0.0">1.0.0</a>';
|
|
111
|
+
const get = await (0, supertest_1.default)(helper_1.default.renderServiceUrl).get('/');
|
|
103
112
|
expect(get.status).toEqual(200);
|
|
104
|
-
expect((
|
|
113
|
+
expect((_a = get === null || get === void 0 ? void 0 : get.res) === null || _a === void 0 ? void 0 : _a.text).toContain(uploadedComponent);
|
|
105
114
|
});
|
|
106
115
|
it('Should fail upload the component with same version', async () => {
|
|
107
116
|
mockConsoleError.mockClear();
|
|
108
|
-
await (0, index_1.uploadComponentFolder)(componentPath, helper_1.default.managementServiceUrl, helper_1.default.renderServiceUrl);
|
|
109
|
-
expect(mockConsoleError.mock.calls[0][0]).toEqual(cli_color_1.default.red('Cannot upload component version, cmp-static-file-test 1.0.0 already exists'));
|
|
117
|
+
await (0, index_1.uploadComponentFolder)(componentPath, helper_1.default.managementServiceUrl + '/v1', helper_1.default.renderServiceUrl, testFilesDir);
|
|
118
|
+
expect(mockConsoleError.mock.calls[0][0]).toEqual(cli_color_1.default.red('Cannot upload component version, smoke-test-components/cmp-static-file-test 1.0.0 already exists'));
|
|
110
119
|
});
|
|
111
120
|
it('Should render component', async () => {
|
|
112
|
-
const
|
|
121
|
+
const componentSet = {
|
|
122
|
+
webPath,
|
|
123
|
+
displayName: 'Set',
|
|
124
|
+
description: 'Set description',
|
|
125
|
+
headers: {},
|
|
126
|
+
environmentVariables: {},
|
|
127
|
+
components: {
|
|
128
|
+
'smoke-test-components/cmp-static-file-test': [{ environmentVariables: {}, version: '1.0.0' }],
|
|
129
|
+
},
|
|
130
|
+
componentVersionRules: {},
|
|
131
|
+
};
|
|
132
|
+
await (0, helper_1.addComponentSet)(componentSet);
|
|
133
|
+
const response = await helper_1.renderService.get('/r/set/smoke-test-components/cmp-static-file-test/1.0.0/?something=hello');
|
|
113
134
|
expect(response.status).toEqual(200);
|
|
114
135
|
expect(response.data).toEqual([
|
|
115
136
|
'<div>Input: hello</div>',
|
|
116
|
-
'<div>cmp-static-file-test 1.0.0 ',
|
|
117
|
-
`${helper_1.default.renderServiceUrl}/s/cmp-static-file-test/1.0.0/birthday-cake.png</div>`,
|
|
137
|
+
'<div>smoke-test-components/cmp-static-file-test 1.0.0 ',
|
|
138
|
+
`${helper_1.default.renderServiceUrl}/s/smoke-test-components/cmp-static-file-test/1.0.0/birthday-cake.png</div>`,
|
|
118
139
|
].join(''));
|
|
119
140
|
});
|
|
120
141
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload-and-render-component.spec.js","sourceRoot":"","sources":["../../src/integration-tests/upload-and-render-component.spec.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oCAAiD;AACjD,
|
|
1
|
+
{"version":3,"file":"upload-and-render-component.spec.js","sourceRoot":"","sources":["../../src/integration-tests/upload-and-render-component.spec.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oCAAiD;AACjD,mDAQkB;AAClB,0DAA8B;AAC9B,gDAAwB;AACxB,0DAAkC;AAClC,wEAAoD;AAEpD,2DAA8B;AAE9B,MAAM,gBAAgB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AACnC,MAAM,cAAc,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAEjC,MAAM,eAAe,GAAG,OAAO,CAAC,KAAK,CAAC;AACtC,MAAM,OAAO,GAAG,KAAK,CAAC;AACtB,MAAM,YAAY,GAAG,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;AAE3D,SAAS,CAAC,KAAK,IAAI,EAAE;IACnB,MAAM,kBAAG,CAAC,EAAE,CAAC,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7D,MAAM,kBAAG,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;AAChC,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,KAAK,IAAI,EAAE;IAClB,2CAA2C;IAC3C,MAAM,IAAA,2BAAkB,EAAC,OAAO,CAAC,CAAC;IAElC,KAAK,MAAM,aAAa,IAAI,IAAA,0BAAiB,GAAE,EAAE;QAC/C,IAAI;YACF,MAAM,0BAAiB,CAAC,MAAM,CAAC,oCAAoC,aAAa,EAAE,CAAC,CAAC;SACrF;QAAC,MAAM;YACN,QAAQ;SACT;KACF;IAED,oCAAoC;IACpC,MAAM,kBAAG,CAAC,EAAE,CAAC,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AAC/D,CA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vC,MAAM,YAAY,GAAyB;YACzC,OAAO;YACP,WAAW,EAAE,KAAK;YAClB,WAAW,EAAE,iBAAiB;YAC9B,OAAO,EAAE,EAAE;YACX,oBAAoB,EAAE,EAAE;YACxB,UAAU,EAAE;gBACV,4CAA4C,EAAE,CAAC,EAAE,oBAAoB,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;aAC/F;YACD,qBAAqB,EAAE,EAAE;SAC1B,CAAC;QAEF,MAAM,IAAA,wBAAe,EAAC,YAAY,CAAC,CAAC;QAEpC,MAAM,QAAQ,GAAG,MAAM,sBAAa,CAAC,GAAG,CACtC,0EAA0E,CAC3E,CAAC;QACF,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACrC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,CAC3B;YACE,yBAAyB;YACzB,wDAAwD;YACxD,GAAG,gBAAS,CAAC,gBAAgB,6EAA6E;SAC3G,CAAC,IAAI,CAAC,EAAE,CAAC,CACX,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Logger } from '@squiz/dx-logger-lib';
|
|
2
2
|
export declare const logger: Logger;
|
|
3
|
-
export declare function uploadComponentFolder(folderPath: string, componentServiceManagementUrl: string, componentRenderServiceUrl: string): Promise<void>;
|
|
3
|
+
export declare function uploadComponentFolder(folderPath: string, componentServiceManagementUrl: string, componentRenderServiceUrl: string, baseTempDir?: string): Promise<void>;
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.uploadComponentFolder = exports.logger = void 0;
|
|
7
7
|
const virus_scanner_lib_1 = require("@squiz/virus-scanner-lib");
|
|
8
|
+
const dx_common_lib_1 = require("@squiz/dx-common-lib");
|
|
8
9
|
const component_lib_1 = require("@squiz/component-lib");
|
|
9
10
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
10
11
|
const path_1 = __importDefault(require("path"));
|
|
@@ -12,8 +13,8 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
12
13
|
const cli_color_1 = __importDefault(require("cli-color"));
|
|
13
14
|
const dx_logger_lib_1 = require("@squiz/dx-logger-lib");
|
|
14
15
|
exports.logger = (0, dx_logger_lib_1.getLogger)({ name: 'upload-component', format: 'human' });
|
|
15
|
-
async function uploadComponentFolder(folderPath, componentServiceManagementUrl, componentRenderServiceUrl) {
|
|
16
|
-
const tmpDir =
|
|
16
|
+
async function uploadComponentFolder(folderPath, componentServiceManagementUrl, componentRenderServiceUrl, baseTempDir = '') {
|
|
17
|
+
const tmpDir = await promises_1.default.mkdtemp(path_1.default.resolve(baseTempDir, 'cmp-upload'));
|
|
17
18
|
try {
|
|
18
19
|
const axiosInstance = axios_1.default.create({
|
|
19
20
|
baseURL: componentServiceManagementUrl,
|
|
@@ -23,7 +24,7 @@ async function uploadComponentFolder(folderPath, componentServiceManagementUrl,
|
|
|
23
24
|
});
|
|
24
25
|
await preUploadChecks(folderPath, componentRenderServiceUrl);
|
|
25
26
|
exports.logger.info('Initial scanning');
|
|
26
|
-
const zip = await (0,
|
|
27
|
+
const zip = await (0, dx_common_lib_1.zipDirectory)(folderPath, tmpDir);
|
|
27
28
|
const initialUpload = await handleResponse(axiosInstance.post('upload-component'));
|
|
28
29
|
exports.logger.info(`deployment id: ${initialUpload.id} status: transferring`);
|
|
29
30
|
await (0, virus_scanner_lib_1.uploadFile)(initialUpload, zip);
|
|
@@ -51,9 +52,12 @@ async function uploadComponentFolder(folderPath, componentServiceManagementUrl,
|
|
|
51
52
|
}
|
|
52
53
|
exports.uploadComponentFolder = uploadComponentFolder;
|
|
53
54
|
async function preUploadChecks(folderPath, renderService) {
|
|
54
|
-
const
|
|
55
|
+
const service = new component_lib_1.ManifestServiceForDev(folderPath, exports.logger);
|
|
56
|
+
const manifestPath = path_1.default.join(folderPath, `manifest.json`);
|
|
57
|
+
const result = await service.readManifest(manifestPath);
|
|
58
|
+
await service.assertManifestIsValid(manifestPath, result.getModel());
|
|
55
59
|
if (await checkIfVersionExists(result, renderService)) {
|
|
56
|
-
throw new Error(`Cannot upload component version, ${result.
|
|
60
|
+
throw new Error(`Cannot upload component version, ${result.getName()} ${result.getVersion()} already exists`);
|
|
57
61
|
}
|
|
58
62
|
}
|
|
59
63
|
async function checkIfVersionExists(inputManifest, renderService) {
|
|
@@ -61,7 +65,7 @@ async function checkIfVersionExists(inputManifest, renderService) {
|
|
|
61
65
|
baseURL: renderService,
|
|
62
66
|
});
|
|
63
67
|
try {
|
|
64
|
-
const response = await axiosInstance.get(`d/${inputManifest.
|
|
68
|
+
const response = await axiosInstance.get(`d/${inputManifest.getName()}/${inputManifest.getVersion()}/manifest.json`);
|
|
65
69
|
if (response.status === 200) {
|
|
66
70
|
return true;
|
|
67
71
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload-component-folder.js","sourceRoot":"","sources":["../src/upload-component-folder.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAkE;
|
|
1
|
+
{"version":3,"file":"upload-component-folder.js","sourceRoot":"","sources":["../src/upload-component-folder.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAkE;AAElE,wDAAoD;AACpD,wDAAuE;AACvE,2DAA8B;AAC9B,gDAAwB;AACxB,kDAAwE;AACxE,0DAA8B;AAC9B,wDAAyD;AAE5C,QAAA,MAAM,GAAW,IAAA,yBAAS,EAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;AAEhF,KAAK,UAAU,qBAAqB,CACzC,UAAkB,EAClB,6BAAqC,EACrC,yBAAiC,EACjC,cAAsB,EAAE;IAExB,MAAM,MAAM,GAAG,MAAM,kBAAG,CAAC,OAAO,CAAC,cAAI,CAAC,OAAO,CAAC,WAAW,EA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AAC,EAAE,IAAI,CAAC,CAAC;aACV;QACH,CAAC,CAAC,CAAC;QAEL,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC,CAAC;AACL,CAAC;AAED,KAAK,UAAU,cAAc,CAAI,aAAwC;IACvE,IAAI;QACF,MAAM,QAAQ,GAAG,MAAM,aAAa,CAAC;QACrC,OAAO,QAAQ,CAAC,IAAI,CAAC;KACtB;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,WAAW,CAAC,KAAK,CAAC,CAAC;KAC1B;AACH,CAAC;AAED,SAAS,WAAW,CAAC,KAAU;IAC7B,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAC3B,IAAI,CAAC,QAAQ,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE;QACrC,OAAO,KAAK,CAAC;KACd;IACD,MAAM,OAAO,GAAI,QAAQ,CAAC,IAAY,CAAC,OAAO,CAAC;IAC/C,IAAI,OAAO,EAAE;QACX,OAAO,IAAI,KAAK,CAAC,4BAA4B,QAAQ,CAAC,MAAM,cAAc,OAAO,EAAE,CAAC,CAAC;KACtF;SAAM;QACL,OAAO,IAAI,KAAK,CAAC,4BAA4B,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;KAClE;AACH,CAAC;AAED,SAAS,YAAY,CAAC,KAAU;IAC9B,OAAO,KAAK,IAAI,KAAK,CAAC,YAAY,KAAK,IAAI,CAAC;AAC9C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@squiz/component-cli-lib",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"start": "node ./lib/index.js",
|
|
8
7
|
"compile": "tsc",
|
|
9
8
|
"lint": "eslint ./src --ext .ts",
|
|
10
9
|
"test": "jest -c jest.config.ts",
|
|
@@ -16,26 +15,27 @@
|
|
|
16
15
|
"devDependencies": {
|
|
17
16
|
"@types/cli-color": "2.0.2",
|
|
18
17
|
"@types/express": "4.17.13",
|
|
19
|
-
"@types/jest": "28.1.
|
|
18
|
+
"@types/jest": "28.1.8",
|
|
20
19
|
"@types/node": "17.0.27",
|
|
21
20
|
"@types/supertest": "2.0.12",
|
|
22
|
-
"dotenv": "16.0.
|
|
21
|
+
"dotenv": "16.0.2",
|
|
23
22
|
"eslint": "8.22.0",
|
|
24
23
|
"jest": "28.1.3",
|
|
25
|
-
"ts-jest": "28.0.
|
|
24
|
+
"ts-jest": "28.0.8",
|
|
26
25
|
"ts-loader": "9.3.1",
|
|
27
26
|
"ts-node": "10.9.1",
|
|
28
27
|
"typescript": "4.7.4"
|
|
29
28
|
},
|
|
30
29
|
"dependencies": {
|
|
31
|
-
"@squiz/component-lib": "^1.2.
|
|
32
|
-
"@squiz/dx-
|
|
33
|
-
"@squiz/
|
|
34
|
-
"@squiz/
|
|
30
|
+
"@squiz/component-lib": "^1.2.3",
|
|
31
|
+
"@squiz/dx-common-lib": "^1.2.2",
|
|
32
|
+
"@squiz/dx-logger-lib": "^1.2.2",
|
|
33
|
+
"@squiz/render-runtime-lib": "^1.2.3",
|
|
34
|
+
"@squiz/virus-scanner-lib": "^1.2.2",
|
|
35
35
|
"archiver": "5.3.1",
|
|
36
36
|
"axios": "0.27.2",
|
|
37
37
|
"cli-color": "^2.0.2",
|
|
38
38
|
"supertest": "^6.2.3"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "192eda353845eafa027e98bddc806896127a6408"
|
|
41
41
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import supertest from 'supertest';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import fsp from 'fs/promises';
|
|
4
|
+
|
|
5
|
+
import { TestHelpers } from '@squiz/render-runtime-lib';
|
|
6
|
+
import { startDevelopmentRender } from './component-dev';
|
|
7
|
+
import { Server } from 'http';
|
|
8
|
+
|
|
9
|
+
jest.setTimeout(20_000);
|
|
10
|
+
|
|
11
|
+
describe('component-dev', () => {
|
|
12
|
+
describe('production style folder structure', () => {
|
|
13
|
+
let server: Server;
|
|
14
|
+
let request: supertest.SuperTest<supertest.Test>;
|
|
15
|
+
beforeAll(async () => {
|
|
16
|
+
server = startDevelopmentRender(TestHelpers.getTestComponentFolder(), { port: 0 });
|
|
17
|
+
request = supertest(server);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
afterAll(async () => {
|
|
21
|
+
server.close();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should find the component', async () => {
|
|
25
|
+
const response = await request.get(`/r/set/unit-test-components/test-component/1.0.0?something=hello`);
|
|
26
|
+
expect(response.text).toEqual('<h1>hello</h1>');
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe('local developer style folders', () => {
|
|
31
|
+
let version: string;
|
|
32
|
+
let componentName: string;
|
|
33
|
+
let fixtureDirectory: string;
|
|
34
|
+
let server: Server;
|
|
35
|
+
let request: supertest.SuperTest<supertest.Test>;
|
|
36
|
+
|
|
37
|
+
beforeAll(async () => {
|
|
38
|
+
const {
|
|
39
|
+
fixtureDirectory: createdFixtureDirectory,
|
|
40
|
+
version: createdVersion,
|
|
41
|
+
componentName: createdName,
|
|
42
|
+
} = await TestHelpers.ComponentFixture.setupFullComponentDirectory('<h1>Hello World</h1>');
|
|
43
|
+
|
|
44
|
+
version = createdVersion;
|
|
45
|
+
fixtureDirectory = createdFixtureDirectory;
|
|
46
|
+
componentName = createdName;
|
|
47
|
+
|
|
48
|
+
server = startDevelopmentRender(fixtureDirectory, { port: 0 });
|
|
49
|
+
request = supertest(server);
|
|
50
|
+
});
|
|
51
|
+
afterAll(async () => {
|
|
52
|
+
server.close();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
afterAll(async () => {
|
|
56
|
+
await fsp.rm(path.join(fixtureDirectory, componentName), { force: true, recursive: true });
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('should handle recursing folders to find the component', async () => {
|
|
60
|
+
const response = await request.get(`/r/set/some-namespace/${componentName}/${version}/`);
|
|
61
|
+
expect(response.text).toEqual('<h1>Hello World</h1>');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('should handle serving static files from single component directory', async () => {
|
|
65
|
+
const response = await request.get(`/s/some-namespace/${componentName}/${version}/static.txt`);
|
|
66
|
+
expect(response.text).toEqual('hello');
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -1,110 +1,58 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import fsp from 'fs/promises';
|
|
3
|
-
|
|
4
1
|
import { routeTests, TestHelpers } from '@squiz/render-runtime-lib';
|
|
5
2
|
import { startDevelopmentRender } from './component-dev';
|
|
6
3
|
import supertest from 'supertest';
|
|
4
|
+
import { Server } from 'http';
|
|
7
5
|
|
|
8
6
|
jest.setTimeout(20_000);
|
|
9
7
|
|
|
10
8
|
describe('component-dev', () => {
|
|
11
|
-
describe('
|
|
12
|
-
let
|
|
13
|
-
|
|
14
|
-
beforeAll(async () => {
|
|
15
|
-
doStopStack = await startDevelopmentRender(path.join(__dirname, '../../../test-components'), { port: 0 });
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
afterAll(async () => {
|
|
19
|
-
await doStopStack();
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('should find the component', async () => {
|
|
23
|
-
const testServer = TestHelpers.getTestServer();
|
|
24
|
-
const response = await testServer.get(`/r/set/test-component/1.0.0?something=hello`);
|
|
25
|
-
expect(response.text).toEqual('<h1>hello</h1>');
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
describe('local developer style folders', () => {
|
|
30
|
-
let doStopStack: Awaited<ReturnType<typeof startDevelopmentRender>>;
|
|
31
|
-
let version: string;
|
|
32
|
-
let componentName: string;
|
|
33
|
-
let fixtureDirectory: string;
|
|
34
|
-
|
|
9
|
+
describe('accessing local dev routes', () => {
|
|
10
|
+
let server: Server;
|
|
11
|
+
let request: supertest.SuperTest<supertest.Test>;
|
|
35
12
|
beforeAll(async () => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
version: createdVersion,
|
|
39
|
-
componentName: createdName,
|
|
40
|
-
} = await TestHelpers.ComponentFixture.setupFullComponentDirectory('<h1>Hello World</h1>');
|
|
41
|
-
|
|
42
|
-
version = createdVersion;
|
|
43
|
-
fixtureDirectory = ceratedFixtureDirectory;
|
|
44
|
-
componentName = createdName;
|
|
45
|
-
|
|
46
|
-
doStopStack = await startDevelopmentRender(fixtureDirectory, { port: 0 });
|
|
13
|
+
server = startDevelopmentRender(TestHelpers.getTestComponentFolder(), { port: 0 });
|
|
14
|
+
request = supertest(server);
|
|
47
15
|
});
|
|
48
16
|
|
|
49
17
|
afterAll(async () => {
|
|
50
|
-
|
|
51
|
-
await fsp.rm(path.join(fixtureDirectory, componentName), { force: true, recursive: true });
|
|
18
|
+
server.close();
|
|
52
19
|
});
|
|
53
20
|
|
|
54
|
-
it('should
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
});
|
|
21
|
+
it('should fail validation when requesting a function with a missing entry file', async () => {
|
|
22
|
+
const response = await request.get(
|
|
23
|
+
'/r/set/unit-test-components/test-component/1.0.3/non-existent-entry-file?something=not-used',
|
|
24
|
+
);
|
|
59
25
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const response = await testServer.get(`/s/${componentName}/${version}/static.txt`);
|
|
63
|
-
expect(response.text).toEqual('hello');
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
describe('accessing local dev routes', () => {
|
|
68
|
-
let stopServer: Awaited<ReturnType<typeof startDevelopmentRender>>;
|
|
69
|
-
const port = 3006;
|
|
70
|
-
const url = `http://localhost:${port}`;
|
|
71
|
-
const request = supertest(url);
|
|
72
|
-
|
|
73
|
-
beforeAll(async () => {
|
|
74
|
-
const compDir = path.join(__dirname, '../', '../../test-components');
|
|
75
|
-
|
|
76
|
-
stopServer = await startDevelopmentRender(compDir, {
|
|
77
|
-
port: port,
|
|
26
|
+
expect(response.body).toEqual({
|
|
27
|
+
message: '"main\'s" entry file "missing-entry-file.js" is inaccessible',
|
|
78
28
|
});
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
afterAll(async () => {
|
|
82
|
-
await stopServer();
|
|
29
|
+
expect(response.statusCode).toEqual(500);
|
|
83
30
|
});
|
|
84
31
|
|
|
85
32
|
describe('definition routes', () => {
|
|
86
|
-
|
|
33
|
+
const server = startDevelopmentRender(TestHelpers.getTestComponentFolder(), { port: 0 });
|
|
34
|
+
const request = () => supertest(server);
|
|
35
|
+
routeTests.definition(request, 'http://localhost:0');
|
|
36
|
+
afterAll(() => {
|
|
37
|
+
server.close();
|
|
38
|
+
});
|
|
87
39
|
});
|
|
88
40
|
|
|
89
41
|
describe('static routes', () => {
|
|
90
|
-
|
|
42
|
+
const server = startDevelopmentRender(TestHelpers.getTestComponentFolder(), { port: 0 });
|
|
43
|
+
const request = () => supertest(server);
|
|
44
|
+
routeTests.static(request);
|
|
45
|
+
afterAll(() => {
|
|
46
|
+
server.close();
|
|
47
|
+
});
|
|
91
48
|
});
|
|
92
49
|
|
|
93
50
|
describe('render routes', () => {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
// this scenario is different to the 'production' tests
|
|
100
|
-
// this is should 500 in prod and 404 locally
|
|
101
|
-
it('should fail validation if trying to render a component with an invalid schema', async () => {
|
|
102
|
-
const response = await request.get('/r/set/test-component/1.0.1?something=not-used');
|
|
103
|
-
|
|
104
|
-
expect(response.statusCode).toEqual(404);
|
|
105
|
-
expect(response.body).toEqual({
|
|
106
|
-
message: 'manifest could not be found',
|
|
107
|
-
});
|
|
51
|
+
const server = startDevelopmentRender(TestHelpers.getTestComponentFolder(), { port: 0 });
|
|
52
|
+
const request = () => supertest(server);
|
|
53
|
+
routeTests.render(request, 'http://localhost:0');
|
|
54
|
+
afterAll(() => {
|
|
55
|
+
server.close();
|
|
108
56
|
});
|
|
109
57
|
});
|
|
110
58
|
});
|