@squiz/component-cli-lib 1.2.11 → 1.2.13-alpha.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/.env.example +9 -0
- package/.gitlab-ci.yml +2 -3
- package/CHANGELOG.md +14 -414
- package/jest.config.ts +9 -1
- package/jest.integration.config.ts +7 -2
- package/lib/component-dev-folder-structures.integration.spec.js +9 -9
- package/lib/component-dev-folder-structures.integration.spec.js.map +1 -1
- package/lib/component-dev.integration.spec.js +5 -5
- package/lib/component-dev.integration.spec.js.map +1 -1
- package/lib/component-dev.js +16 -9
- package/lib/component-dev.js.map +1 -1
- package/lib/integration-tests/__components__/cmp-format-string/manifest.json +40 -0
- package/lib/integration-tests/helper.d.ts +1 -0
- package/lib/integration-tests/helper.js +47 -1
- package/lib/integration-tests/helper.js.map +1 -1
- package/lib/integration-tests/upload-and-render-component.integration.spec.js +66 -12
- package/lib/integration-tests/upload-and-render-component.integration.spec.js.map +1 -1
- package/lib/upload-component-folder.d.ts +2 -1
- package/lib/upload-component-folder.js +20 -34
- package/lib/upload-component-folder.js.map +1 -1
- package/package.json +13 -12
- package/src/component-dev-folder-structures.integration.spec.ts +15 -9
- package/src/component-dev.integration.spec.ts +5 -5
- package/src/component-dev.ts +28 -16
- package/src/integration-tests/__components__/cmp-format-string/main.js +7 -0
- package/src/integration-tests/__components__/cmp-format-string/manifest.json +41 -0
- package/src/integration-tests/__components__/cmp-static-file-test/main.js +1 -5
- package/src/integration-tests/__components__/invalid-manifest/main.js +0 -4
- package/src/integration-tests/__components__/invalid-upload/main.js +0 -4
- package/src/integration-tests/helper.ts +54 -0
- package/src/integration-tests/upload-and-render-component.integration.spec.ts +82 -21
- package/src/upload-component-folder.ts +31 -39
- package/tsconfig.json +3 -2
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -9,28 +9,22 @@ const dx_common_lib_1 = require("@squiz/dx-common-lib");
|
|
|
9
9
|
const component_lib_1 = require("@squiz/component-lib");
|
|
10
10
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
11
11
|
const path_1 = __importDefault(require("path"));
|
|
12
|
-
const axios_1 = __importDefault(require("axios"));
|
|
13
12
|
const cli_color_1 = __importDefault(require("cli-color"));
|
|
14
13
|
const dx_logger_lib_1 = require("@squiz/dx-logger-lib");
|
|
14
|
+
const dx_json_schema_lib_1 = require("@squiz/dx-json-schema-lib");
|
|
15
15
|
exports.logger = (0, dx_logger_lib_1.getLogger)({ name: 'upload-component', format: 'human' });
|
|
16
|
-
async function uploadComponentFolder(
|
|
16
|
+
async function uploadComponentFolder(apiClient, componentServiceManagementUrl, folderPath, baseTempDir = '') {
|
|
17
17
|
const tmpDir = await promises_1.default.mkdtemp(path_1.default.resolve(baseTempDir, 'cmp-upload'));
|
|
18
18
|
try {
|
|
19
|
-
|
|
20
|
-
baseURL: componentServiceManagementUrl,
|
|
21
|
-
headers: {
|
|
22
|
-
'content-type': 'application/json',
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
await preUploadChecks(folderPath, componentRenderServiceUrl);
|
|
19
|
+
await preUploadChecks(apiClient, componentServiceManagementUrl, folderPath);
|
|
26
20
|
exports.logger.info('Initial scanning');
|
|
27
21
|
const zip = await (0, dx_common_lib_1.zipDirectory)(folderPath, tmpDir);
|
|
28
|
-
const initialUpload = await handleResponse(
|
|
22
|
+
const initialUpload = await handleResponse(apiClient.post('/v1/upload-component', {}, { baseURL: componentServiceManagementUrl }));
|
|
29
23
|
exports.logger.info(`deployment id: ${initialUpload.id} status: transferring`);
|
|
30
24
|
await (0, virus_scanner_lib_1.uploadFile)(initialUpload, zip);
|
|
31
|
-
await watchAndWaitForUploadAndScanComplete(initialUpload.id
|
|
25
|
+
await watchAndWaitForUploadAndScanComplete(apiClient, componentServiceManagementUrl, initialUpload.id);
|
|
32
26
|
exports.logger.info(`deployment id: ${initialUpload.id} status: deploying component folder`);
|
|
33
|
-
const result = await handleResponse(
|
|
27
|
+
const result = await handleResponse(apiClient.post(`/v1/upload-component/next/${initialUpload.id}`, {}, { baseURL: componentServiceManagementUrl }));
|
|
34
28
|
await promises_1.default.rm(tmpDir, { force: true, recursive: true });
|
|
35
29
|
if (result.status === 'successful') {
|
|
36
30
|
exports.logger.info(`deployment id: ${initialUpload.id} status: ${cli_color_1.default.green('success')}`);
|
|
@@ -51,38 +45,30 @@ async function uploadComponentFolder(folderPath, componentServiceManagementUrl,
|
|
|
51
45
|
}
|
|
52
46
|
}
|
|
53
47
|
exports.uploadComponentFolder = uploadComponentFolder;
|
|
54
|
-
async function preUploadChecks(
|
|
55
|
-
const service = new component_lib_1.ManifestServiceForDev(folderPath, exports.logger);
|
|
48
|
+
async function preUploadChecks(apiClient, managementURL, folderPath) {
|
|
49
|
+
const service = new component_lib_1.ManifestServiceForDev(folderPath, exports.logger, new dx_json_schema_lib_1.JsonValidationService());
|
|
56
50
|
const manifestPath = path_1.default.join(folderPath, `manifest.json`);
|
|
57
51
|
const result = await service.readManifest(manifestPath);
|
|
58
52
|
await service.assertManifestIsValid(manifestPath, result.getModel());
|
|
59
|
-
if (await checkIfVersionExists(
|
|
53
|
+
if (await checkIfVersionExists(apiClient, managementURL, result)) {
|
|
60
54
|
throw new Error(`Cannot upload component version, ${result.getName()} ${result.getVersion()} already exists`);
|
|
61
55
|
}
|
|
62
56
|
}
|
|
63
|
-
async function checkIfVersionExists(
|
|
64
|
-
const
|
|
65
|
-
|
|
57
|
+
async function checkIfVersionExists(apiClient, managementURL, inputManifest) {
|
|
58
|
+
const response = await apiClient.get(`/v1/component/${inputManifest.getName()}/${inputManifest.getVersion()}`, {
|
|
59
|
+
validateStatus: null,
|
|
60
|
+
baseURL: managementURL,
|
|
66
61
|
});
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (response.status === 200) {
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
throw new Error(`Unexpected response code ${response.status}`);
|
|
62
|
+
if (response.status === 200) {
|
|
63
|
+
return true;
|
|
73
64
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const { response } = error;
|
|
77
|
-
if ((response === null || response === void 0 ? void 0 : response.status) === 404) {
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
throw error;
|
|
65
|
+
else if (response.status === 404) {
|
|
66
|
+
return false;
|
|
82
67
|
}
|
|
68
|
+
throw new Error(`Unexpected response code ${response.status}`);
|
|
83
69
|
}
|
|
84
|
-
async function watchAndWaitForUploadAndScanComplete(
|
|
85
|
-
const poll = () => handleResponse(
|
|
70
|
+
async function watchAndWaitForUploadAndScanComplete(apiClient, managementURL, id) {
|
|
71
|
+
const poll = () => handleResponse(apiClient.get('/v1/upload-component/status/' + id, { baseURL: managementURL }));
|
|
86
72
|
return new Promise((resolve, reject) => {
|
|
87
73
|
const recurse = () => poll().then(async (req) => {
|
|
88
74
|
if (req.status == 'Success') {
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AAExB,0DAA8B;AAC9B,wDAAyD;AACzD,kEAAkE;AAErD,QAAA,MAAM,GAAW,IAAA,yBAAS,EAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;AAEhF,KAAK,UAAU,qBAAqB,CACzC,SAAwB,EACxB,6BAAqC,EACrC,UAAkB,EAClB,cAAsB,EAAE;IAExB,MAAM,MAAM,GAAG,MAAM,kBAAG,CAAC,OAAO,CAAC,cAAI,CAAC,OAAO,CAAC,WAAW,EA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U,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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@squiz/component-cli-lib",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.13-alpha.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -8,36 +8,37 @@
|
|
|
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",
|
|
11
|
-
"clean": "rimraf \".tsbuildinfo\" \"./lib\""
|
|
11
|
+
"clean": "rimraf \"tsconfig.tsbuildinfo\" \"./lib\""
|
|
12
12
|
},
|
|
13
13
|
"author": "",
|
|
14
14
|
"license": "ISC",
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@types/cli-color": "2.0.2",
|
|
17
|
-
"@types/express": "4.17.
|
|
17
|
+
"@types/express": "4.17.14",
|
|
18
18
|
"@types/jest": "28.1.8",
|
|
19
19
|
"@types/node": "17.0.27",
|
|
20
20
|
"@types/supertest": "2.0.12",
|
|
21
|
-
"dotenv": "16.0.
|
|
21
|
+
"dotenv": "16.0.3",
|
|
22
22
|
"eslint": "8.22.0",
|
|
23
23
|
"jest": "28.1.3",
|
|
24
24
|
"ts-jest": "28.0.8",
|
|
25
25
|
"ts-loader": "9.3.1",
|
|
26
26
|
"ts-node": "10.9.1",
|
|
27
|
-
"typescript": "4.
|
|
27
|
+
"typescript": "4.9.3"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@squiz/component-lib": "1.2.
|
|
31
|
-
"@squiz/component-web-api-lib": "1.2.
|
|
32
|
-
"@squiz/dx-common-lib": "1.2.
|
|
33
|
-
"@squiz/dx-
|
|
34
|
-
"@squiz/
|
|
35
|
-
"@squiz/
|
|
30
|
+
"@squiz/component-lib": "1.2.13-alpha.0",
|
|
31
|
+
"@squiz/component-web-api-lib": "1.2.13-alpha.0",
|
|
32
|
+
"@squiz/dx-common-lib": "1.2.13-alpha.0",
|
|
33
|
+
"@squiz/dx-json-schema-lib": "1.2.13-alpha.0",
|
|
34
|
+
"@squiz/dx-logger-lib": "1.2.13-alpha.0",
|
|
35
|
+
"@squiz/render-runtime-lib": "1.2.13-alpha.0",
|
|
36
|
+
"@squiz/virus-scanner-lib": "1.2.13-alpha.0",
|
|
36
37
|
"archiver": "5.3.1",
|
|
37
38
|
"axios": "0.27.2",
|
|
38
39
|
"cli-color": "^2.0.2",
|
|
39
40
|
"open": "^8.4.0",
|
|
40
41
|
"supertest": "^6.2.3"
|
|
41
42
|
},
|
|
42
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "811fbf59292dd00a2051036f1115cba5781828dd"
|
|
43
44
|
}
|
|
@@ -13,7 +13,7 @@ describe('component-dev', () => {
|
|
|
13
13
|
let server: Server;
|
|
14
14
|
let request: supertest.SuperTest<supertest.Test>;
|
|
15
15
|
beforeAll(async () => {
|
|
16
|
-
server = startDevelopmentRender(TestHelpers.getTestComponentFolder(), { port: 0 });
|
|
16
|
+
server = startDevelopmentRender(TestHelpers.getTestComponentFolder(), { port: 0, noBrowser: true });
|
|
17
17
|
request = supertest(server);
|
|
18
18
|
});
|
|
19
19
|
|
|
@@ -22,8 +22,10 @@ describe('component-dev', () => {
|
|
|
22
22
|
});
|
|
23
23
|
|
|
24
24
|
it('should find the component', async () => {
|
|
25
|
-
const response = await request.get(
|
|
26
|
-
|
|
25
|
+
const response = await request.get(
|
|
26
|
+
`/r/unit-test-components/test-component/1.0.0?_componentSet=set&something=hello`,
|
|
27
|
+
);
|
|
28
|
+
expect(response.text).toEqual('<div>hello - {"_componentSet":"set","something":"hello"}</div>');
|
|
27
29
|
});
|
|
28
30
|
});
|
|
29
31
|
|
|
@@ -45,7 +47,7 @@ describe('component-dev', () => {
|
|
|
45
47
|
fixtureDirectory = createdFixtureDirectory;
|
|
46
48
|
componentName = createdName;
|
|
47
49
|
|
|
48
|
-
server = startDevelopmentRender(fixtureDirectory, { port: 0 });
|
|
50
|
+
server = startDevelopmentRender(fixtureDirectory, { port: 0, noBrowser: true });
|
|
49
51
|
request = supertest(server);
|
|
50
52
|
});
|
|
51
53
|
afterAll(async () => {
|
|
@@ -57,12 +59,14 @@ describe('component-dev', () => {
|
|
|
57
59
|
});
|
|
58
60
|
|
|
59
61
|
it('should handle recursing folders to find the component', async () => {
|
|
60
|
-
const response = await request.get(`/r/
|
|
62
|
+
const response = await request.get(`/r/some-namespace/${componentName}/${version}?_componentSet=set`);
|
|
61
63
|
expect(response.text).toEqual('<h1>Hello World</h1>');
|
|
62
|
-
});
|
|
64
|
+
}, 30_000);
|
|
63
65
|
|
|
64
66
|
it('should handle serving static files from single component directory', async () => {
|
|
65
|
-
const response = await request.get(
|
|
67
|
+
const response = await request.get(
|
|
68
|
+
`/s/some-namespace/${componentName}/${version}/static.txt?_componentSet=set-x`,
|
|
69
|
+
);
|
|
66
70
|
expect(response.text).toEqual('hello');
|
|
67
71
|
});
|
|
68
72
|
});
|
|
@@ -78,8 +82,10 @@ describe('component-dev', () => {
|
|
|
78
82
|
server.close();
|
|
79
83
|
});
|
|
80
84
|
it('should find the component', async () => {
|
|
81
|
-
const response = await request.get(
|
|
82
|
-
|
|
85
|
+
const response = await request.get(
|
|
86
|
+
`/r/unit-test-components/test-component/1.0.0?_componentSet=set&something=hello`,
|
|
87
|
+
);
|
|
88
|
+
expect(response.text).toEqual('<div>hello - {"_componentSet":"set","something":"hello"}</div>');
|
|
83
89
|
});
|
|
84
90
|
});
|
|
85
91
|
});
|
|
@@ -11,7 +11,7 @@ describe('component-dev', () => {
|
|
|
11
11
|
let request: supertest.SuperTest<supertest.Test>;
|
|
12
12
|
|
|
13
13
|
beforeAll(async () => {
|
|
14
|
-
server = startDevelopmentRender(TestHelpers.getTestComponentFolder(), { port: 0 });
|
|
14
|
+
server = startDevelopmentRender(TestHelpers.getTestComponentFolder(), { port: 0, noBrowser: true });
|
|
15
15
|
request = supertest(server);
|
|
16
16
|
});
|
|
17
17
|
|
|
@@ -21,7 +21,7 @@ describe('component-dev', () => {
|
|
|
21
21
|
|
|
22
22
|
it('should fail validation when requesting a function with a missing entry file', async () => {
|
|
23
23
|
const response = await request.get(
|
|
24
|
-
'/r/
|
|
24
|
+
'/r/unit-test-components/test-component/1.0.3/non-existent-entry-file?_componentSet=set&something=not-used',
|
|
25
25
|
);
|
|
26
26
|
|
|
27
27
|
expect(response.body).toEqual({
|
|
@@ -31,7 +31,7 @@ describe('component-dev', () => {
|
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
describe('definition routes', () => {
|
|
34
|
-
const server = startDevelopmentRender(TestHelpers.getTestComponentFolder(), { port: 0 });
|
|
34
|
+
const server = startDevelopmentRender(TestHelpers.getTestComponentFolder(), { port: 0, noBrowser: true });
|
|
35
35
|
const request = () => supertest(server);
|
|
36
36
|
routeTests.definition(request, 'http://localhost:0');
|
|
37
37
|
afterAll(() => {
|
|
@@ -40,7 +40,7 @@ describe('component-dev', () => {
|
|
|
40
40
|
});
|
|
41
41
|
|
|
42
42
|
describe('static routes', () => {
|
|
43
|
-
const server = startDevelopmentRender(TestHelpers.getTestComponentFolder(), { port: 0 });
|
|
43
|
+
const server = startDevelopmentRender(TestHelpers.getTestComponentFolder(), { port: 0, noBrowser: true });
|
|
44
44
|
const request = () => supertest(server);
|
|
45
45
|
routeTests.static(request);
|
|
46
46
|
afterAll(() => {
|
|
@@ -49,7 +49,7 @@ describe('component-dev', () => {
|
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
describe('render routes', () => {
|
|
52
|
-
const server = startDevelopmentRender(TestHelpers.getTestComponentFolder(), { port: 0 });
|
|
52
|
+
const server = startDevelopmentRender(TestHelpers.getTestComponentFolder(), { port: 0, noBrowser: true });
|
|
53
53
|
const request = () => supertest(server);
|
|
54
54
|
routeTests.render(request, 'http://localhost:0');
|
|
55
55
|
afterAll(() => {
|
package/src/component-dev.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
ComponentPreviewService,
|
|
3
3
|
ComponentRunnerServiceWithWorkers,
|
|
4
|
+
RenderInputService,
|
|
4
5
|
setupRenderRuntimeServer,
|
|
5
6
|
} from '@squiz/render-runtime-lib';
|
|
6
7
|
import { getLogger, LoggerOptions } from '@squiz/dx-logger-lib';
|
|
7
8
|
import path from 'path';
|
|
8
9
|
import { ComponentFunctionService, ComponentSetServiceForLocalDev, ManifestServiceForDev } from '@squiz/component-lib';
|
|
9
10
|
import open from 'open';
|
|
11
|
+
import { DevelopmentApiKeyService } from '@squiz/dx-common-lib';
|
|
12
|
+
import { JsonValidationService } from '@squiz/dx-json-schema-lib';
|
|
10
13
|
|
|
11
14
|
/**
|
|
12
15
|
* startDevelopmentRender starts a dev-mode render stack for any
|
|
@@ -22,9 +25,10 @@ export function startDevelopmentRender(
|
|
|
22
25
|
options: { port: number; loggingFormat?: LoggerOptions['format']; noBrowser?: boolean },
|
|
23
26
|
) {
|
|
24
27
|
const logger = getLogger({ name: 'component-dev', format: options.loggingFormat || 'human' });
|
|
25
|
-
const rootUrl = `http://localhost:${options.port}`;
|
|
26
28
|
const dataMountPoint = path.resolve(process.cwd(), componentPath);
|
|
27
29
|
|
|
30
|
+
const rootUrl = `http://localhost:${options.port}`;
|
|
31
|
+
|
|
28
32
|
const componentRunnerService = new ComponentRunnerServiceWithWorkers(
|
|
29
33
|
{
|
|
30
34
|
dataMountPoint,
|
|
@@ -33,23 +37,31 @@ export function startDevelopmentRender(
|
|
|
33
37
|
},
|
|
34
38
|
logger,
|
|
35
39
|
);
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
},
|
|
48
|
-
{ rootUrl },
|
|
40
|
+
const jsonValidationService = new JsonValidationService();
|
|
41
|
+
const componentFunctionService = new ComponentFunctionService(rootUrl, jsonValidationService);
|
|
42
|
+
const componentSetService = new ComponentSetServiceForLocalDev(logger);
|
|
43
|
+
const manifestService = new ManifestServiceForDev(dataMountPoint, logger, jsonValidationService);
|
|
44
|
+
const contentItemService = undefined;
|
|
45
|
+
const renderInputService = new RenderInputService(
|
|
46
|
+
componentSetService,
|
|
47
|
+
manifestService,
|
|
48
|
+
componentFunctionService,
|
|
49
|
+
contentItemService,
|
|
50
|
+
rootUrl,
|
|
49
51
|
);
|
|
52
|
+
const webServer = setupRenderRuntimeServer({
|
|
53
|
+
logger,
|
|
54
|
+
componentRunnerService,
|
|
55
|
+
componentFunctionService,
|
|
56
|
+
componentPreviewService: new ComponentPreviewService(),
|
|
57
|
+
componentSetService,
|
|
58
|
+
manifestService,
|
|
59
|
+
renderInputService,
|
|
60
|
+
apiKeyService: new DevelopmentApiKeyService(),
|
|
61
|
+
});
|
|
50
62
|
|
|
51
63
|
const server = webServer.listen(options.port, () => {
|
|
52
|
-
logger.info(`Component development webserver started on port ${
|
|
64
|
+
logger.info(`Component development webserver started on port ${rootUrl}`);
|
|
53
65
|
});
|
|
54
66
|
|
|
55
67
|
if (options?.noBrowser !== true) {
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://localhost:3000/schemas/v1.json#",
|
|
3
|
+
|
|
4
|
+
"name": "cmp-format-string",
|
|
5
|
+
"version": "1.0.0",
|
|
6
|
+
"mainFunction": "main",
|
|
7
|
+
"displayName": "some-display-name",
|
|
8
|
+
"namespace": "fixtures",
|
|
9
|
+
"description": "some-description",
|
|
10
|
+
"functions": [
|
|
11
|
+
{
|
|
12
|
+
"name": "main",
|
|
13
|
+
"entry": "main.js",
|
|
14
|
+
"input": {
|
|
15
|
+
"type": "object",
|
|
16
|
+
"properties": {
|
|
17
|
+
"text": {
|
|
18
|
+
"type": "string",
|
|
19
|
+
"format": "multi-line"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"required": ["text"]
|
|
23
|
+
},
|
|
24
|
+
"output": { "responseType": "html" }
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"previews": {
|
|
28
|
+
"test-preview": {
|
|
29
|
+
"functionData": {
|
|
30
|
+
"main": {
|
|
31
|
+
"inputData": {
|
|
32
|
+
"type": "inline",
|
|
33
|
+
"value": {
|
|
34
|
+
"text": "this is a test"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @param {object} input
|
|
3
|
-
* @param {ComponentInfo} info
|
|
4
|
-
*/
|
|
5
1
|
module.exports = async function (input, info) {
|
|
6
2
|
return (
|
|
7
3
|
`<div>Input: ${input.something}</div>` +
|
|
8
|
-
`<div>${info.
|
|
4
|
+
`<div>${info.componentName} ${info.version} ${info.ctx.getStaticResourceUrl('birthday-cake.png')}</div>`
|
|
9
5
|
);
|
|
10
6
|
};
|
|
@@ -8,6 +8,7 @@ import { ComponentSetWebModelForCreate } from '@squiz/component-lib';
|
|
|
8
8
|
import { parseEnvVarForVar } from '@squiz/dx-common-lib';
|
|
9
9
|
import { ContentApi } from '@squiz/component-web-api-lib';
|
|
10
10
|
import { config } from 'dotenv';
|
|
11
|
+
import { execSync } from 'child_process';
|
|
11
12
|
|
|
12
13
|
config();
|
|
13
14
|
|
|
@@ -27,22 +28,75 @@ const configObj: Config = {
|
|
|
27
28
|
ci_buildBranch: parseEnvVarForVar('CI_COMMIT_REF_NAME'),
|
|
28
29
|
};
|
|
29
30
|
|
|
31
|
+
if (!configObj.ci_buildVersion) {
|
|
32
|
+
configObj.ci_buildVersion = execSync('git rev-parse --short HEAD', { encoding: 'utf-8' }).trim();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (!configObj.ci_buildBranch) {
|
|
36
|
+
configObj.ci_buildBranch = execSync('git branch --show-current', { encoding: 'utf-8' }).trim();
|
|
37
|
+
}
|
|
38
|
+
|
|
30
39
|
export default configObj;
|
|
31
40
|
|
|
41
|
+
const DXP_SERVICE_NAME = 'dxpComponents';
|
|
42
|
+
const ALL_PERMISSIONS_ROLE = {
|
|
43
|
+
privileges: [
|
|
44
|
+
'COMPONENT_DEPLOY',
|
|
45
|
+
'COMPONENT_DELETE',
|
|
46
|
+
'COMPONENT_READ',
|
|
47
|
+
'COMPONENT_SET_RULES_READ',
|
|
48
|
+
'COMPONENT_SET_RULES_WRITE',
|
|
49
|
+
|
|
50
|
+
'COMPONENT_SET_READ',
|
|
51
|
+
'COMPONENT_SET_WRITE',
|
|
52
|
+
|
|
53
|
+
'COMPONENT_SET_ENVIRONMENT_READ',
|
|
54
|
+
'COMPONENT_SET_ENVIRONMENT_WRITE',
|
|
55
|
+
],
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const validToken = {
|
|
59
|
+
organisationId: 'aa',
|
|
60
|
+
permission: '',
|
|
61
|
+
tenant: 'zz',
|
|
62
|
+
tenantId: 'zz',
|
|
63
|
+
userId: 'zz',
|
|
64
|
+
|
|
65
|
+
service: {
|
|
66
|
+
[DXP_SERVICE_NAME]: {
|
|
67
|
+
privileges: ALL_PERMISSIONS_ROLE.privileges,
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const authToken = `Bearer xxx.${Buffer.from(JSON.stringify(validToken)).toString('base64')}.zzz`;
|
|
73
|
+
|
|
32
74
|
export const managementService = axios.create({
|
|
33
75
|
baseURL: configObj.managementServiceUrl + '/v1',
|
|
76
|
+
headers: {
|
|
77
|
+
authorization: authToken,
|
|
78
|
+
},
|
|
34
79
|
});
|
|
35
80
|
|
|
36
81
|
export const managementServiceRoot = axios.create({
|
|
37
82
|
baseURL: configObj.managementServiceUrl,
|
|
83
|
+
headers: {
|
|
84
|
+
authorization: authToken,
|
|
85
|
+
},
|
|
38
86
|
});
|
|
39
87
|
|
|
40
88
|
export const renderService = axios.create({
|
|
41
89
|
baseURL: configObj.renderServiceUrl,
|
|
90
|
+
headers: {
|
|
91
|
+
authorization: authToken,
|
|
92
|
+
},
|
|
42
93
|
});
|
|
43
94
|
|
|
44
95
|
export const contentService = axios.create({
|
|
45
96
|
baseURL: configObj.contentServiceUrl,
|
|
97
|
+
headers: {
|
|
98
|
+
authorization: authToken,
|
|
99
|
+
},
|
|
46
100
|
});
|
|
47
101
|
|
|
48
102
|
export const ci_buildVersion = configObj.ci_buildVersion;
|