@squiz/component-cli-lib 1.2.1-alpha.106 → 1.2.1-alpha.17
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/CHANGELOG.md +0 -730
- package/jest.config.ts +3 -8
- package/lib/index.d.ts +1 -2
- package/lib/index.js +79 -5
- package/lib/index.js.map +1 -1
- package/lib/{component-dev.spec.d.ts → test.d.ts} +0 -0
- package/lib/test.js +12 -0
- package/lib/test.js.map +1 -0
- package/lib/utils/zipDirectory.d.ts +1 -0
- package/lib/utils/zipDirectory.js +32 -0
- package/lib/utils/zipDirectory.js.map +1 -0
- package/package.json +16 -22
- package/src/index.ts +90 -2
- package/src/test.ts +9 -0
- package/src/utils/zipDirectory.ts +31 -0
- package/tsconfig.json +1 -6
- package/tsconfig.tsbuildinfo +1 -1
- package/.gitlab-ci.yml +0 -118
- package/jest.integration.config.ts +0 -17
- package/lib/component-dev.d.ts +0 -13
- package/lib/component-dev.js +0 -40
- package/lib/component-dev.js.map +0 -1
- package/lib/component-dev.spec.js +0 -91
- package/lib/component-dev.spec.js.map +0 -1
- package/lib/integration-tests/__components__/big-package/manifest.json +0 -32
- package/lib/integration-tests/__components__/cmp-static-file-test/manifest.json +0 -36
- package/lib/integration-tests/__components__/invalid-manifest/manifest.json +0 -24
- package/lib/integration-tests/helper.d.ts +0 -18
- package/lib/integration-tests/helper.js +0 -70
- package/lib/integration-tests/helper.js.map +0 -1
- package/lib/integration-tests/service-deployment.spec.d.ts +0 -1
- package/lib/integration-tests/service-deployment.spec.js +0 -16
- package/lib/integration-tests/service-deployment.spec.js.map +0 -1
- package/lib/integration-tests/test-setup.d.ts +0 -0
- package/lib/integration-tests/test-setup.js +0 -3
- package/lib/integration-tests/test-setup.js.map +0 -1
- package/lib/integration-tests/upload-and-render-component.spec.d.ts +0 -1
- package/lib/integration-tests/upload-and-render-component.spec.js +0 -136
- package/lib/integration-tests/upload-and-render-component.spec.js.map +0 -1
- package/lib/upload-component-folder.d.ts +0 -3
- package/lib/upload-component-folder.js +0 -128
- package/lib/upload-component-folder.js.map +0 -1
- package/src/component-dev.spec.ts +0 -111
- package/src/component-dev.ts +0 -34
- package/src/integration-tests/__components__/big-package/manifest.json +0 -33
- package/src/integration-tests/__components__/big-package/render-json.js +0 -5
- package/src/integration-tests/__components__/cmp-static-file-test/main.js +0 -10
- package/src/integration-tests/__components__/cmp-static-file-test/manifest.json +0 -40
- package/src/integration-tests/__components__/cmp-static-file-test/public/static-library-file.js +0 -1
- package/src/integration-tests/__components__/invalid-manifest/main.js +0 -7
- package/src/integration-tests/__components__/invalid-manifest/manifest.json +0 -26
- package/src/integration-tests/__components__/invalid-upload/main.js +0 -7
- package/src/integration-tests/helper.ts +0 -75
- package/src/integration-tests/service-deployment.spec.ts +0 -21
- package/src/integration-tests/test-setup.ts +0 -1
- package/src/integration-tests/upload-and-render-component.spec.ts +0 -141
- package/src/upload-component-folder.ts +0 -137
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
const index_1 = require("../index");
|
|
30
|
-
const helper_1 = __importStar(require("./helper"));
|
|
31
|
-
const cli_color_1 = __importDefault(require("cli-color"));
|
|
32
|
-
const path_1 = __importDefault(require("path"));
|
|
33
|
-
const supertest_1 = __importDefault(require("supertest"));
|
|
34
|
-
const upload_component_folder_1 = require("../upload-component-folder");
|
|
35
|
-
const mockConsoleError = jest.fn();
|
|
36
|
-
const mockConsoleLog = jest.fn();
|
|
37
|
-
const orgConsoleError = console.error;
|
|
38
|
-
const webPath = 'set';
|
|
39
|
-
afterAll(async () => {
|
|
40
|
-
// clean up the component added by the test
|
|
41
|
-
await (0, helper_1.deleteComponentSet)(webPath);
|
|
42
|
-
for (const componentName of (0, helper_1.getTestComponents)()) {
|
|
43
|
-
try {
|
|
44
|
-
await helper_1.managementService.delete(`/component/${componentName}`);
|
|
45
|
-
}
|
|
46
|
-
catch {
|
|
47
|
-
// no op
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
describe('Test isolated test cases', () => {
|
|
52
|
-
beforeEach(() => {
|
|
53
|
-
jest.spyOn(upload_component_folder_1.logger, 'error').mockImplementation(mockConsoleError);
|
|
54
|
-
jest.spyOn(upload_component_folder_1.logger, 'info').mockImplementation(mockConsoleLog);
|
|
55
|
-
});
|
|
56
|
-
it('Should fail uploading a component without manifest.json', async () => {
|
|
57
|
-
mockConsoleError.mockClear();
|
|
58
|
-
const componentPath = path_1.default.join(__dirname, '/__components__/invalid-upload');
|
|
59
|
-
await (0, index_1.uploadComponentFolder)(componentPath, helper_1.default.managementServiceUrl, helper_1.default.renderServiceUrl);
|
|
60
|
-
expect(mockConsoleError.mock.calls[0][0]).toEqual(cli_color_1.default.red('manifest could not be found'));
|
|
61
|
-
});
|
|
62
|
-
it('Should fail uploading a component that has invalid manifest.json', async () => {
|
|
63
|
-
mockConsoleError.mockClear();
|
|
64
|
-
const componentPath = path_1.default.join(__dirname, '/__components__/invalid-manifest');
|
|
65
|
-
await (0, index_1.uploadComponentFolder)(componentPath, helper_1.default.managementServiceUrl, helper_1.default.renderServiceUrl);
|
|
66
|
-
expect(mockConsoleError.mock.calls[0][0]).toEqual(cli_color_1.default.red('/name: pattern must match pattern "^[a-zA-Z0-9_\\-]+$"'));
|
|
67
|
-
});
|
|
68
|
-
it('Should fail uploading the component that has size more than 100MB', async () => {
|
|
69
|
-
mockConsoleError.mockClear();
|
|
70
|
-
const componentPath = path_1.default.join(__dirname, '/__components__/big-package');
|
|
71
|
-
const filePath = `${componentPath}/105mb-file`;
|
|
72
|
-
await (0, helper_1.createFile)(filePath, 105); // Higher limit has been used because compression reduces the size if you use closer to 100MB
|
|
73
|
-
await (0, index_1.uploadComponentFolder)(componentPath, helper_1.default.managementServiceUrl, helper_1.default.renderServiceUrl);
|
|
74
|
-
expect(mockConsoleError.mock.calls[0][0]).toEqual(cli_color_1.default.red(['File size exceeds the maximum limit of 100MB'].join('')));
|
|
75
|
-
(0, helper_1.removeFile)(filePath);
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
describe('Deploy basic component having a static file', () => {
|
|
79
|
-
// component to deploy for this test
|
|
80
|
-
const componentPath = path_1.default.join(__dirname, '/__components__/cmp-static-file-test');
|
|
81
|
-
beforeAll(async () => {
|
|
82
|
-
await (0, helper_1.deleteComponentSet)(webPath);
|
|
83
|
-
for (const componentName of (0, helper_1.getTestComponents)()) {
|
|
84
|
-
try {
|
|
85
|
-
await helper_1.managementService.delete(`/component/${componentName}`);
|
|
86
|
-
}
|
|
87
|
-
catch {
|
|
88
|
-
// no op
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
beforeEach(() => {
|
|
93
|
-
console.error = mockConsoleError;
|
|
94
|
-
console.log = mockConsoleLog;
|
|
95
|
-
});
|
|
96
|
-
afterEach(() => {
|
|
97
|
-
console.error = orgConsoleError;
|
|
98
|
-
});
|
|
99
|
-
it('Should upload the component and return a valid url to preview', async () => {
|
|
100
|
-
var _a, _b;
|
|
101
|
-
mockConsoleLog.mockClear();
|
|
102
|
-
console.log(helper_1.default.managementServiceUrl, helper_1.default.renderServiceUrl);
|
|
103
|
-
await (0, index_1.uploadComponentFolder)(componentPath, helper_1.default.managementServiceUrl, helper_1.default.renderServiceUrl);
|
|
104
|
-
const url = ((_a = /uploaded location: (.*)/.exec(mockConsoleLog.mock.lastCall)) === null || _a === void 0 ? void 0 : _a[1]) || '';
|
|
105
|
-
const uploadedComponent = '<a href="/r/set/cmp-static-file-test/1.0.0">1.0.0</a>';
|
|
106
|
-
const get = await (0, supertest_1.default)(url).get('/');
|
|
107
|
-
expect(get.status).toEqual(200);
|
|
108
|
-
expect((_b = get === null || get === void 0 ? void 0 : get.res) === null || _b === void 0 ? void 0 : _b.text).toContain(uploadedComponent);
|
|
109
|
-
});
|
|
110
|
-
it('Should fail upload the component with same version', async () => {
|
|
111
|
-
mockConsoleError.mockClear();
|
|
112
|
-
await (0, index_1.uploadComponentFolder)(componentPath, helper_1.default.managementServiceUrl, helper_1.default.renderServiceUrl);
|
|
113
|
-
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'));
|
|
114
|
-
});
|
|
115
|
-
it('Should render component', async () => {
|
|
116
|
-
const componentSet = {
|
|
117
|
-
webPath,
|
|
118
|
-
displayName: 'Set',
|
|
119
|
-
description: 'Set description',
|
|
120
|
-
headers: {},
|
|
121
|
-
envVars: {},
|
|
122
|
-
components: {
|
|
123
|
-
'cmp-static-file-test': [{ envVars: {}, version: '1.0.0' }],
|
|
124
|
-
},
|
|
125
|
-
};
|
|
126
|
-
await (0, helper_1.addComponentSet)(componentSet);
|
|
127
|
-
const response = await helper_1.renderService.get('/r/set/cmp-static-file-test/1.0.0/?something=hello');
|
|
128
|
-
expect(response.status).toEqual(200);
|
|
129
|
-
expect(response.data).toEqual([
|
|
130
|
-
'<div>Input: hello</div>',
|
|
131
|
-
'<div>cmp-static-file-test 1.0.0 ',
|
|
132
|
-
`${helper_1.default.renderServiceUrl}/s/cmp-static-file-test/1.0.0/birthday-cake.png</div>`,
|
|
133
|
-
].join(''));
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
//# sourceMappingURL=upload-and-render-component.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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;AAGpD,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;AAEtB,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,cAAc,aAAa,EAAE,CAAC,CAAC;SAC/D;QAAC,MAAM;YACN,QAA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C,CAAC,CAAC,CAAC,OAAO,CAC/C,mBAAK,CAAC,GAAG,CAAC,4EAA4E,CAAC,CACxF,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yBAAyB,EAAE,KAAK,IAAI,EAAE;QACvC,MAAM,YAAY,GAAyB;YACzC,OAAO;YACP,WAAW,EAAE,KAAK;YAClB,WAAW,EAAE,iBAAiB;YAC9B,OAAO,EAAE,EAAE;YACX,OAAO,EAAE,EAAE;YACX,UAAU,EAAE;gBACV,sBAAsB,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;aAC5D;SACF,CAAC;QAEF,MAAM,IAAA,wBAAe,EAAC,YAAY,CAAC,CAAC;QAEpC,MAAM,QAAQ,GAAG,MAAM,sBAAa,CAAC,GAAG,CAAC,oDAAoD,CAAC,CAAC;QAC/F,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,kCAAkC;YAClC,GAAG,gBAAS,CAAC,gBAAgB,uDAAuD;SACrF,CAAC,IAAI,CAAC,EAAE,CAAC,CACX,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.uploadComponentFolder = exports.logger = void 0;
|
|
7
|
-
const virus_scanner_lib_1 = require("@squiz/virus-scanner-lib");
|
|
8
|
-
const component_lib_1 = require("@squiz/component-lib");
|
|
9
|
-
const dx_common_lib_1 = require("@squiz/dx-common-lib");
|
|
10
|
-
const promises_1 = __importDefault(require("fs/promises"));
|
|
11
|
-
const path_1 = __importDefault(require("path"));
|
|
12
|
-
const axios_1 = __importDefault(require("axios"));
|
|
13
|
-
const cli_color_1 = __importDefault(require("cli-color"));
|
|
14
|
-
const dx_logger_lib_1 = require("@squiz/dx-logger-lib");
|
|
15
|
-
exports.logger = (0, dx_logger_lib_1.getLogger)({ name: 'upload-component', format: 'human' });
|
|
16
|
-
async function uploadComponentFolder(folderPath, componentServiceManagementUrl, componentRenderServiceUrl) {
|
|
17
|
-
const tmpDir = path_1.default.resolve(await promises_1.default.mkdtemp('cmp-upload'));
|
|
18
|
-
try {
|
|
19
|
-
const axiosInstance = axios_1.default.create({
|
|
20
|
-
baseURL: componentServiceManagementUrl,
|
|
21
|
-
headers: {
|
|
22
|
-
'content-type': 'application/json',
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
await preUploadChecks(folderPath, componentRenderServiceUrl);
|
|
26
|
-
exports.logger.info('Initial scanning');
|
|
27
|
-
const zip = await (0, dx_common_lib_1.zipDirectory)(folderPath, tmpDir);
|
|
28
|
-
const initialUpload = await handleResponse(axiosInstance.post('upload-component'));
|
|
29
|
-
exports.logger.info(`deployment id: ${initialUpload.id} status: transferring`);
|
|
30
|
-
await (0, virus_scanner_lib_1.uploadFile)(initialUpload, zip);
|
|
31
|
-
await watchAndWaitForUploadAndScanComplete(initialUpload.id, axiosInstance);
|
|
32
|
-
exports.logger.info(`deployment id: ${initialUpload.id} status: deploying component folder`);
|
|
33
|
-
const result = await handleResponse(axiosInstance.post(`upload-component/next/${initialUpload.id}`));
|
|
34
|
-
await promises_1.default.rm(tmpDir, { force: true, recursive: true });
|
|
35
|
-
if (result.status === 'successful') {
|
|
36
|
-
exports.logger.info(`deployment id: ${initialUpload.id} status: ${cli_color_1.default.green('success')}`);
|
|
37
|
-
exports.logger.info(`uploaded location: ${result.accessLink}`);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
exports.logger.error('failed for an unknown reason', cli_color_1.default.red(result));
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
catch (e) {
|
|
44
|
-
await promises_1.default.rm(tmpDir, { force: true, recursive: true });
|
|
45
|
-
if (e instanceof Error) {
|
|
46
|
-
exports.logger.error(cli_color_1.default.red(e.message));
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
throw e;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
exports.uploadComponentFolder = uploadComponentFolder;
|
|
54
|
-
async function preUploadChecks(folderPath, renderService) {
|
|
55
|
-
const result = await (0, component_lib_1.loadManifest)(path_1.default.join(folderPath, `manifest.json`));
|
|
56
|
-
if (await checkIfVersionExists(result, renderService)) {
|
|
57
|
-
throw new Error(`Cannot upload component version, ${result.name} ${result.version} already exists`);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
async function checkIfVersionExists(inputManifest, renderService) {
|
|
61
|
-
const axiosInstance = axios_1.default.create({
|
|
62
|
-
baseURL: renderService,
|
|
63
|
-
});
|
|
64
|
-
try {
|
|
65
|
-
const response = await axiosInstance.get(`d/${inputManifest.name}/${inputManifest.version}/manifest.json`);
|
|
66
|
-
if (response.status === 200) {
|
|
67
|
-
return true;
|
|
68
|
-
}
|
|
69
|
-
throw new Error(`Unexpected response code ${response.status}`);
|
|
70
|
-
}
|
|
71
|
-
catch (error) {
|
|
72
|
-
if (isAxiosError(error)) {
|
|
73
|
-
const { response } = error;
|
|
74
|
-
if ((response === null || response === void 0 ? void 0 : response.status) === 404) {
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
throw error;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
async function watchAndWaitForUploadAndScanComplete(id, axiosInstance) {
|
|
82
|
-
const poll = () => handleResponse(axiosInstance.get('upload-component/status/' + id));
|
|
83
|
-
return new Promise((resolve, reject) => {
|
|
84
|
-
const recurse = () => poll().then(async (req) => {
|
|
85
|
-
if (req.status == 'Success') {
|
|
86
|
-
resolve();
|
|
87
|
-
}
|
|
88
|
-
else if (req.status == 'Flagged') {
|
|
89
|
-
reject(new Error('upload has been flagged as a virus'));
|
|
90
|
-
}
|
|
91
|
-
else if (req.status == 'Error') {
|
|
92
|
-
reject(new Error('there has been an error'));
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
setTimeout(async () => {
|
|
96
|
-
await recurse();
|
|
97
|
-
}, 1000);
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
recurse();
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
async function handleResponse(axiosInstance) {
|
|
104
|
-
try {
|
|
105
|
-
const response = await axiosInstance;
|
|
106
|
-
return response.data;
|
|
107
|
-
}
|
|
108
|
-
catch (error) {
|
|
109
|
-
throw handleError(error);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
function handleError(error) {
|
|
113
|
-
const { response } = error;
|
|
114
|
-
if (!response || !isAxiosError(error)) {
|
|
115
|
-
return error;
|
|
116
|
-
}
|
|
117
|
-
const message = response.data.message;
|
|
118
|
-
if (message) {
|
|
119
|
-
return new Error(`Unexpected response code ${response.status}. message: ${message}`);
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
return new Error(`Unexpected response code ${response.status}.`);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
function isAxiosError(error) {
|
|
126
|
-
return error && error.isAxiosError === true;
|
|
127
|
-
}
|
|
128
|
-
//# sourceMappingURL=upload-component-folder.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"upload-component-folder.js","sourceRoot":"","sources":["../src/upload-component-folder.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAkE;AAClE,wDAAoD;AACpD,wDAAoD;AAEpD,2DAA8B;AAC9B,gDAAwB;AACxB,kDAAwE;AACxE,0DAA8B;AAC9B,wDAAyD;AAE5C,QAAA,MAAM,GAAW,IAAA,yBAAS,EAAC,EAAE,I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AC,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"}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import fsp from 'fs/promises';
|
|
3
|
-
|
|
4
|
-
import { routeTests, TestHelpers } from '@squiz/render-runtime-lib';
|
|
5
|
-
import { startDevelopmentRender } from './component-dev';
|
|
6
|
-
import supertest from 'supertest';
|
|
7
|
-
|
|
8
|
-
jest.setTimeout(20_000);
|
|
9
|
-
|
|
10
|
-
describe('component-dev', () => {
|
|
11
|
-
describe('production style folder structure', () => {
|
|
12
|
-
let doStopStack: Awaited<ReturnType<typeof startDevelopmentRender>>;
|
|
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
|
-
|
|
35
|
-
beforeAll(async () => {
|
|
36
|
-
const {
|
|
37
|
-
fixtureDirectory: ceratedFixtureDirectory,
|
|
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 });
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
afterAll(async () => {
|
|
50
|
-
await doStopStack();
|
|
51
|
-
await fsp.rm(path.join(fixtureDirectory, componentName), { force: true, recursive: true });
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('should handle recursing folders to find the component', async () => {
|
|
55
|
-
const testServer = TestHelpers.getTestServer();
|
|
56
|
-
const response = await testServer.get(`/r/set/${componentName}/${version}/`);
|
|
57
|
-
expect(response.text).toEqual('<h1>Hello World</h1>');
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('should handle serving static files from single component directory', async () => {
|
|
61
|
-
const testServer = TestHelpers.getTestServer();
|
|
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,
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
afterAll(async () => {
|
|
82
|
-
await stopServer();
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
describe('definition routes', () => {
|
|
86
|
-
routeTests.definition(url, url);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
describe('static routes', () => {
|
|
90
|
-
routeTests.static(url);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
describe('render routes', () => {
|
|
94
|
-
routeTests.render(url, url);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
describe('GET /r/set/test-component/1.0.1', () => {
|
|
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
|
-
});
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
});
|
package/src/component-dev.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { startRenderStack, stopRenderStack } from '@squiz/render-runtime-lib';
|
|
2
|
-
import { getLogger } from '@squiz/dx-logger-lib';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* startDevelopmentRender starts a dev-mode render stack for any
|
|
7
|
-
* local directory. This should start an express server on a random unused port
|
|
8
|
-
* which can be accessed for viewing the component in development.
|
|
9
|
-
*
|
|
10
|
-
* @param {string} componentPath - The directory with the component to be rendered
|
|
11
|
-
* @param {object} options - Additional configuration for the dev stack
|
|
12
|
-
* @returns a function to stop the render stack
|
|
13
|
-
*/
|
|
14
|
-
export async function startDevelopmentRender(componentPath: string, options: { port: number; previewFile?: string }) {
|
|
15
|
-
const logger = getLogger({ name: 'component-dev', format: 'human' });
|
|
16
|
-
await startRenderStack({
|
|
17
|
-
logger: logger,
|
|
18
|
-
webserver: {
|
|
19
|
-
port: options.port,
|
|
20
|
-
rootUrl: `http://localhost:${options.port}`,
|
|
21
|
-
shouldRunMigrations: false,
|
|
22
|
-
},
|
|
23
|
-
componentRunner: {
|
|
24
|
-
// Considering the component path will be passed in from CLI
|
|
25
|
-
// We need to generate the path from the calling directory
|
|
26
|
-
dataMountPoint: path.resolve(process.cwd(), componentPath),
|
|
27
|
-
localDevMode: true,
|
|
28
|
-
previewFile: options.previewFile,
|
|
29
|
-
workerTimeout: 20_000,
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
return () => stopRenderStack();
|
|
34
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "http://localhost:3000/schemas/v1.json#",
|
|
3
|
-
|
|
4
|
-
"name": "big-package",
|
|
5
|
-
"version": "1.0.2",
|
|
6
|
-
"main-function": "render-json",
|
|
7
|
-
"functions": [
|
|
8
|
-
{
|
|
9
|
-
"name": "render-json",
|
|
10
|
-
"entry": "render-json.js",
|
|
11
|
-
"input": {
|
|
12
|
-
"type": "object",
|
|
13
|
-
"properties": {
|
|
14
|
-
"something": {
|
|
15
|
-
"type": "string"
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
"required": ["something"]
|
|
19
|
-
},
|
|
20
|
-
"output": {
|
|
21
|
-
"response-type": "json",
|
|
22
|
-
"definition": {
|
|
23
|
-
"properties": {
|
|
24
|
-
"my-prop": {
|
|
25
|
-
"type": "string"
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
"required": ["my-prop"]
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
]
|
|
33
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @param {object} input
|
|
3
|
-
* @param {ComponentInfo} info
|
|
4
|
-
*/
|
|
5
|
-
module.exports = async function (input, info) {
|
|
6
|
-
return (
|
|
7
|
-
`<div>Input: ${input.something}</div>` +
|
|
8
|
-
`<div>${info.ctx.componentName} ${info.ctx.version} ${info.ctx.getStaticResourceUrl('birthday-cake.png')}</div>`
|
|
9
|
-
);
|
|
10
|
-
};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "http://localhost:3000/schemas/v1.json#",
|
|
3
|
-
|
|
4
|
-
"name": "cmp-static-file-test",
|
|
5
|
-
"version": "1.0.0",
|
|
6
|
-
"main-function": "main",
|
|
7
|
-
|
|
8
|
-
"functions": [
|
|
9
|
-
{
|
|
10
|
-
"entry": "main.js",
|
|
11
|
-
"name": "main",
|
|
12
|
-
"input": {
|
|
13
|
-
"type": "object",
|
|
14
|
-
"properties": {
|
|
15
|
-
"something": {
|
|
16
|
-
"type": "string"
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
"required": ["something"]
|
|
20
|
-
},
|
|
21
|
-
"output": {
|
|
22
|
-
"response-type": "html",
|
|
23
|
-
|
|
24
|
-
"static-files": [
|
|
25
|
-
{
|
|
26
|
-
"location": "header",
|
|
27
|
-
"file": {
|
|
28
|
-
"filepath": "static-library-file.js",
|
|
29
|
-
"type": "js"
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
]
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
],
|
|
36
|
-
|
|
37
|
-
"static-files": {
|
|
38
|
-
"location-root": "public"
|
|
39
|
-
}
|
|
40
|
-
}
|
package/src/integration-tests/__components__/cmp-static-file-test/public/static-library-file.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const name = 'foo';
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "http://localhost:3000/schemas/v1.json#",
|
|
3
|
-
|
|
4
|
-
"name": "invalid-manifes@t",
|
|
5
|
-
"version": "1.0.0",
|
|
6
|
-
"main-function": "main",
|
|
7
|
-
|
|
8
|
-
"functions": [
|
|
9
|
-
{
|
|
10
|
-
"entry": "main.js",
|
|
11
|
-
"name": "main",
|
|
12
|
-
"input": {
|
|
13
|
-
"type": "object",
|
|
14
|
-
"properties": {
|
|
15
|
-
"something": {
|
|
16
|
-
"type": "string"
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
"required": ["something"]
|
|
20
|
-
},
|
|
21
|
-
"output": {
|
|
22
|
-
"response-type": "html"
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
]
|
|
26
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
|
|
5
|
-
import fsp from 'fs/promises';
|
|
6
|
-
import { randomBytes } from 'crypto';
|
|
7
|
-
import { ComponentSetWebModel } from '@squiz/component-lib';
|
|
8
|
-
import { parseEnvVarForVar } from '@squiz/dx-common-lib';
|
|
9
|
-
import { config } from 'dotenv';
|
|
10
|
-
|
|
11
|
-
config();
|
|
12
|
-
|
|
13
|
-
interface Config {
|
|
14
|
-
managementServiceUrl: string;
|
|
15
|
-
renderServiceUrl: string;
|
|
16
|
-
ci_buildVersion: string;
|
|
17
|
-
ci_buildBranch: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const configObj: Config = {
|
|
21
|
-
managementServiceUrl: parseEnvVarForVar('COMPONENT_MANAGEMENT_SERVICE_URL').replace(/\/+$/, ''),
|
|
22
|
-
renderServiceUrl: parseEnvVarForVar('COMPONENT_RENDER_SERVICE_URL').replace(/\/+$/, ''),
|
|
23
|
-
ci_buildVersion: parseEnvVarForVar('CI_COMMIT_SHORT_SHA'),
|
|
24
|
-
ci_buildBranch: parseEnvVarForVar('CI_COMMIT_REF_NAME'),
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export default configObj;
|
|
28
|
-
|
|
29
|
-
export const managementService = axios.create({
|
|
30
|
-
baseURL: configObj.managementServiceUrl,
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
export const renderService = axios.create({
|
|
34
|
-
baseURL: configObj.renderServiceUrl,
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
export const ci_buildVersion = configObj.ci_buildVersion;
|
|
38
|
-
export const ci_buildBranch = configObj.ci_buildBranch;
|
|
39
|
-
|
|
40
|
-
export function getTestComponents(): string[] {
|
|
41
|
-
const componets = [];
|
|
42
|
-
const componentsDir = path.join(__dirname, '/__components__/');
|
|
43
|
-
const files = fs.readdirSync(componentsDir);
|
|
44
|
-
for (const file of files) {
|
|
45
|
-
const stat = fs.statSync(path.join(componentsDir, file));
|
|
46
|
-
if (stat.isDirectory() && file.substring(0, 4) === 'cmp-') {
|
|
47
|
-
componets.push(file);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return componets;
|
|
51
|
-
}
|
|
52
|
-
export async function createFile(filePath: string, sizeInMB: number) {
|
|
53
|
-
const content = randomBytes(sizeInMB * 1000000);
|
|
54
|
-
await fsp.writeFile(`${filePath}`, content);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function removeFile(filePath: string) {
|
|
58
|
-
fsp.unlink(filePath);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export async function deleteComponentSet(webPath: string) {
|
|
62
|
-
try {
|
|
63
|
-
await managementService.delete(`/component-set/${webPath}`);
|
|
64
|
-
} catch (error) {
|
|
65
|
-
// no ops
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export async function addComponentSet(componentSet: ComponentSetWebModel) {
|
|
70
|
-
try {
|
|
71
|
-
await managementService.post(`/component-set`, componentSet);
|
|
72
|
-
} catch (error) {
|
|
73
|
-
//no ops
|
|
74
|
-
}
|
|
75
|
-
}
|