@squiz/component-cli-lib 1.69.0 → 1.70.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/lib/index.js +63 -63
- package/lib/index.js.map +2 -2
- package/package.json +9 -6
- package/.env.example +0 -11
- package/.gitlab-ci.yml +0 -141
- package/CHANGELOG.md +0 -656
- package/build.js +0 -28
- package/jest.config.ts +0 -28
- package/jest.integration.config.ts +0 -27
- package/job-runner-lib.tgz +0 -0
- package/localStart.ts +0 -11
- package/src/component-dev-folder-structures.integration.spec.ts +0 -91
- package/src/component-dev.integration.spec.ts +0 -71
- package/src/component-dev.ts +0 -102
- package/src/component-edge-dev.ts +0 -75
- package/src/component-init.spec.ts +0 -258
- package/src/component-init.ts +0 -81
- package/src/index.ts +0 -5
- package/src/integration-tests/__components__/big-package/manifest.json +0 -36
- package/src/integration-tests/__components__/big-package/render-json.js +0 -5
- package/src/integration-tests/__components__/cmp-format-string/main.js +0 -7
- package/src/integration-tests/__components__/cmp-format-string/manifest.json +0 -41
- package/src/integration-tests/__components__/cmp-no-api-key/main.js +0 -25
- package/src/integration-tests/__components__/cmp-no-api-key/manifest.json +0 -41
- package/src/integration-tests/__components__/cmp-property-order/main.js +0 -6
- package/src/integration-tests/__components__/cmp-property-order/manifest.json +0 -60
- package/src/integration-tests/__components__/cmp-static-file-test/main.js +0 -6
- package/src/integration-tests/__components__/cmp-static-file-test/manifest.json +0 -42
- 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 -3
- package/src/integration-tests/__components__/invalid-manifest/manifest.json +0 -29
- package/src/integration-tests/__components__/invalid-upload/main.js +0 -3
- package/src/integration-tests/__components__/matrix-asset-uri/main.js +0 -7
- package/src/integration-tests/__components__/matrix-asset-uri/manifest.json +0 -42
- package/src/integration-tests/__components__/test-page-render/main.js +0 -3
- package/src/integration-tests/__components__/test-page-render/manifest.json +0 -46
- package/src/integration-tests/__components__/test-page-render/public/static-library-script.js +0 -1
- package/src/integration-tests/__components__/test-page-render/public/static-library-styles.css +0 -3
- package/src/integration-tests/__jobs__/invalid-manifest/main.js +0 -3
- package/src/integration-tests/__jobs__/invalid-manifest/manifest.json +0 -28
- package/src/integration-tests/__jobs__/invalid-upload/main.js +0 -3
- package/src/integration-tests/__jobs__/simple-job/main.js +0 -3
- package/src/integration-tests/__jobs__/simple-job/manifest.json +0 -25
- package/src/integration-tests/helper.ts +0 -227
- package/src/integration-tests/service-deployment.integration.spec.ts +0 -74
- package/src/integration-tests/test-setup.ts +0 -1
- package/src/upload-component-folder.ts +0 -130
- package/src/upload-job.ts +0 -101
- package/src/utils.spec.ts +0 -370
- package/src/utils.ts +0 -149
- package/templates/advanced/build.js +0 -43
- package/templates/advanced/main.js +0 -3
- package/templates/advanced/manifest.json +0 -60
- package/templates/advanced/package-lock.json +0 -916
- package/templates/advanced/package.json +0 -11
- package/templates/advanced/previews/example.data.json +0 -1
- package/templates/advanced/previews/preview.html +0 -9
- package/templates/advanced/static/default.js +0 -1
- package/templates/advanced/static/default.scss +0 -1
- package/templates/basic/main.js +0 -3
- package/templates/basic/manifest.json +0 -62
- package/templates/basic/previews/example.data.json +0 -1
- package/templates/basic/previews/preview.html +0 -9
- package/templates/basic/static/default.css +0 -1
- package/templates/basic/static/default.js +0 -1
- package/tsconfig.json +0 -26
- package/tsconfig.tsbuildinfo +0 -1
package/jest.config.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { Config } from 'jest';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
process.env.DATA_MOUNT_POINT = path.join(__dirname, '..', '..', 'test-components');
|
|
5
|
-
process.env.SQUIZ_REGION = 'au';
|
|
6
|
-
process.env.DEPLOYMENT_ENVIRONMENT = 'dev';
|
|
7
|
-
|
|
8
|
-
// Sync object
|
|
9
|
-
const config: Config = {
|
|
10
|
-
preset: 'ts-jest',
|
|
11
|
-
testTimeout: 60_000,
|
|
12
|
-
testEnvironment: 'node',
|
|
13
|
-
passWithNoTests: true,
|
|
14
|
-
testPathIgnorePatterns: [
|
|
15
|
-
'<rootDir>/lib/',
|
|
16
|
-
'<rootDir>/src/integration-tests',
|
|
17
|
-
'<rootDir>/src/test.ts',
|
|
18
|
-
'.*\\.integration\\.spec\\.ts$',
|
|
19
|
-
],
|
|
20
|
-
maxWorkers: 1,
|
|
21
|
-
globals: {
|
|
22
|
-
'ts-jest': {
|
|
23
|
-
tsconfig: 'tsconfig.json',
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export default config;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { execSync } from 'child_process';
|
|
2
|
-
import type { Config } from 'jest';
|
|
3
|
-
import { defaultIntegrationConfig } from '../../jest.config';
|
|
4
|
-
import { config as dotEnvConfig } from 'dotenv';
|
|
5
|
-
dotEnvConfig();
|
|
6
|
-
|
|
7
|
-
process.env.CI_COMMIT_SHORT_SHA ??= execSync('git rev-parse --short=8 HEAD', { encoding: 'utf-8' }).trim();
|
|
8
|
-
process.env.CI_COMMIT_REF_NAME ??= execSync('git branch --show-current', { encoding: 'utf-8' }).trim();
|
|
9
|
-
process.env.SQUIZ_REGION = 'au';
|
|
10
|
-
process.env.DEPLOYMENT_ENVIRONMENT = 'dev';
|
|
11
|
-
process.env.TENANT_ID ??= 'my-tenant';
|
|
12
|
-
|
|
13
|
-
// Sync object
|
|
14
|
-
const config: Config = {
|
|
15
|
-
...defaultIntegrationConfig,
|
|
16
|
-
maxWorkers: 1,
|
|
17
|
-
|
|
18
|
-
setupFiles: ['./src/integration-tests/test-setup.ts'],
|
|
19
|
-
detectOpenHandles: true,
|
|
20
|
-
|
|
21
|
-
globals: {
|
|
22
|
-
BUILD_VERSION: process.env.CI_COMMIT_SHORT_SHA,
|
|
23
|
-
BUILD_BRANCH: process.env.CI_COMMIT_REF_NAME,
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export default config;
|
package/job-runner-lib.tgz
DELETED
|
Binary file
|
package/localStart.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { startDevelopmentRender } from './src';
|
|
3
|
-
|
|
4
|
-
async function startRender() {
|
|
5
|
-
const componentPath = path.resolve(process.cwd(), process.argv[2]);
|
|
6
|
-
|
|
7
|
-
console.log('Starting render for ' + componentPath);
|
|
8
|
-
const _server = startDevelopmentRender(componentPath, { port: 3101, loggingFormat: 'human' });
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
startRender();
|
|
@@ -1,91 +0,0 @@
|
|
|
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/test-helpers';
|
|
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, noBrowser: true });
|
|
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(
|
|
26
|
-
`/r/unit-test-components/test-component/1.0.10?_componentSet=set&something=hello`,
|
|
27
|
-
);
|
|
28
|
-
expect(response.text).toEqual('<div>hello - {}</div>');
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
describe('local developer style folders', () => {
|
|
33
|
-
let version: string;
|
|
34
|
-
let componentName: string;
|
|
35
|
-
let fixtureDirectory: string;
|
|
36
|
-
let server: Server;
|
|
37
|
-
let request: supertest.SuperTest<supertest.Test>;
|
|
38
|
-
|
|
39
|
-
beforeAll(async () => {
|
|
40
|
-
const {
|
|
41
|
-
fixtureDirectory: createdFixtureDirectory,
|
|
42
|
-
version: createdVersion,
|
|
43
|
-
componentName: createdName,
|
|
44
|
-
} = await TestHelpers.ComponentFixture.setupFullComponentDirectory('<h1>Hello World</h1>');
|
|
45
|
-
|
|
46
|
-
version = createdVersion;
|
|
47
|
-
fixtureDirectory = createdFixtureDirectory;
|
|
48
|
-
componentName = createdName;
|
|
49
|
-
|
|
50
|
-
server = startDevelopmentRender(fixtureDirectory, { port: 0, noBrowser: true });
|
|
51
|
-
request = supertest(server);
|
|
52
|
-
});
|
|
53
|
-
afterAll(async () => {
|
|
54
|
-
server.close();
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
afterAll(async () => {
|
|
58
|
-
await fsp.rm(path.join(fixtureDirectory, componentName), { force: true, recursive: true });
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('should handle recursing folders to find the component', async () => {
|
|
62
|
-
const response = await request.get(`/r/some-namespace/${componentName}/${version}?_componentSet=set`);
|
|
63
|
-
expect(response.text).toEqual('<h1>Hello World</h1>');
|
|
64
|
-
}, 30_000);
|
|
65
|
-
|
|
66
|
-
it('should handle serving static files from single component directory', async () => {
|
|
67
|
-
const response = await request.get(
|
|
68
|
-
`/s/some-namespace/${componentName}/${version}/static.txt?_componentSet=set-x`,
|
|
69
|
-
);
|
|
70
|
-
expect(response.text).toEqual('hello');
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
describe('It should pass a simple test and not launch the browser if the -nb flag is present', () => {
|
|
75
|
-
let server: Server;
|
|
76
|
-
let request: supertest.SuperTest<supertest.Test>;
|
|
77
|
-
beforeAll(async () => {
|
|
78
|
-
server = startDevelopmentRender(TestHelpers.getTestComponentFolder(), { port: 0, noBrowser: true });
|
|
79
|
-
request = supertest(server);
|
|
80
|
-
});
|
|
81
|
-
afterAll(async () => {
|
|
82
|
-
server.close();
|
|
83
|
-
});
|
|
84
|
-
it('should find the component', async () => {
|
|
85
|
-
const response = await request.get(
|
|
86
|
-
`/r/unit-test-components/test-component/1.0.10?_componentSet=set&something=hello`,
|
|
87
|
-
);
|
|
88
|
-
expect(response.text).toEqual('<div>hello - {}</div>');
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
});
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { routeTests, TestHelpers } from '@squiz/render-runtime-lib/test-helpers';
|
|
2
|
-
import { startDevelopmentRender } from './component-dev';
|
|
3
|
-
import supertest from 'supertest';
|
|
4
|
-
import { Server } from 'http';
|
|
5
|
-
|
|
6
|
-
jest.setTimeout(20_000);
|
|
7
|
-
|
|
8
|
-
describe('component-dev', () => {
|
|
9
|
-
describe('accessing local dev routes', () => {
|
|
10
|
-
let server: Server;
|
|
11
|
-
let request: supertest.SuperTest<supertest.Test>;
|
|
12
|
-
|
|
13
|
-
beforeAll(async () => {
|
|
14
|
-
server = startDevelopmentRender(TestHelpers.getTestComponentFolder(), { port: 0, noBrowser: true });
|
|
15
|
-
request = supertest(server);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
afterAll(async () => {
|
|
19
|
-
server.close();
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('should fail validation when requesting a function with a missing entry file', async () => {
|
|
23
|
-
const response = await request.get(
|
|
24
|
-
'/r/unit-test-components/test-component/1.0.3/main?_componentSet=set&something=not-used',
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
expect(response.body).toEqual({
|
|
28
|
-
message: '"main\'s" entry file "missing-entry-file.js" is inaccessible',
|
|
29
|
-
});
|
|
30
|
-
expect(response.statusCode).toEqual(500);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
describe('definition routes', () => {
|
|
34
|
-
routeTests.definition(() => request, 'http://localhost:0');
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
describe('static routes', () => {
|
|
38
|
-
routeTests.static(() => request);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
describe('render routes', () => {
|
|
42
|
-
routeTests.render(() => request, 'http://localhost:0');
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
describe('preview tests', () => {
|
|
46
|
-
routeTests.preview(() => request, 'http://localhost:0');
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
describe('development tests', () => {
|
|
50
|
-
routeTests.development(() => request, true);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
describe('user experience', () => {
|
|
54
|
-
describe('on navigation to a component without preview from home page it should still try and render by default', () => {
|
|
55
|
-
it('should successfully try to render a component with a dummy set', async () => {
|
|
56
|
-
const listingResponse = await request.get('/');
|
|
57
|
-
// Component with no preview
|
|
58
|
-
expect(listingResponse.text).toContain(
|
|
59
|
-
'/r/unit-test-components/test-component/1.0.10?_componentSet=local-development-only',
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
const renderResponse = await request.get(
|
|
63
|
-
'/r/unit-test-components/test-component/1.0.10?_componentSet=local-development-only',
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
expect(renderResponse.statusCode).toEqual(200);
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
});
|
package/src/component-dev.ts
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ComponentRootUrlResolver,
|
|
3
|
-
ComponentPreviewService,
|
|
4
|
-
ComponentRunnerServiceWithWorkers,
|
|
5
|
-
RenderInputService,
|
|
6
|
-
setupRenderRuntimeServer,
|
|
7
|
-
} from '@squiz/render-runtime-lib';
|
|
8
|
-
import { NodeSandbox } from '@squiz/runtime-sandbox-node';
|
|
9
|
-
import { getLogger, LoggerOptions } from '@squiz/dx-logger-lib';
|
|
10
|
-
import path from 'path';
|
|
11
|
-
import { ComponentFunctionService, ComponentSetServiceForLocalDev, ManifestServiceForDev } from '@squiz/component-lib';
|
|
12
|
-
import open from 'open';
|
|
13
|
-
import { DevelopmentApiKeyService } from '@squiz/dx-common-lib';
|
|
14
|
-
import { ComponentLogger } from '@squiz/component-logger-lib';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* startDevelopmentRender starts a dev-mode render stack for any
|
|
18
|
-
* local directory. This should start an express server on a random unused port
|
|
19
|
-
* which can be accessed for viewing the component in development.
|
|
20
|
-
* @param {string} componentPath - The directory with the component to be rendered
|
|
21
|
-
* @param {object} options - Additional configuration for the dev stack
|
|
22
|
-
* @returns a function to stop the render stack
|
|
23
|
-
*/
|
|
24
|
-
export function startDevelopmentRender(
|
|
25
|
-
componentPath: string,
|
|
26
|
-
options: { port: number; loggingFormat?: LoggerOptions['format']; noBrowser?: boolean },
|
|
27
|
-
) {
|
|
28
|
-
const logger = getLogger({
|
|
29
|
-
name: 'component-dev',
|
|
30
|
-
format: options.loggingFormat || 'human',
|
|
31
|
-
silent: process.env.NODE_ENV === 'test',
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
const devComponentLogger = new ComponentLogger({
|
|
35
|
-
enabled: false,
|
|
36
|
-
tenantId: 'dev-tenant-id',
|
|
37
|
-
logUrl: '',
|
|
38
|
-
key: '',
|
|
39
|
-
tags: 'tag-foo tag-foo2',
|
|
40
|
-
serviceName: 'component-dev',
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
const dataMountPoint = path.resolve(process.cwd(), componentPath);
|
|
44
|
-
|
|
45
|
-
const rootUrl = `http://localhost:${options.port}`;
|
|
46
|
-
const componentRootUrlResolver: ComponentRootUrlResolver = () => rootUrl;
|
|
47
|
-
|
|
48
|
-
const apiKeyService = new DevelopmentApiKeyService();
|
|
49
|
-
const sandbox = new NodeSandbox({
|
|
50
|
-
workerPool: {
|
|
51
|
-
shouldCacheResponses: false,
|
|
52
|
-
workerLimits: {
|
|
53
|
-
minWorkers: 2,
|
|
54
|
-
maxWorkers: 2,
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
});
|
|
58
|
-
const componentRunnerService = new ComponentRunnerServiceWithWorkers(sandbox, logger, devComponentLogger);
|
|
59
|
-
const componentFunctionService = new ComponentFunctionService();
|
|
60
|
-
const componentSetService = new ComponentSetServiceForLocalDev(logger);
|
|
61
|
-
const manifestService = new ManifestServiceForDev(dataMountPoint, logger);
|
|
62
|
-
const contentItemService = undefined;
|
|
63
|
-
const renderInputService = new RenderInputService(
|
|
64
|
-
apiKeyService,
|
|
65
|
-
componentSetService,
|
|
66
|
-
manifestService,
|
|
67
|
-
componentFunctionService,
|
|
68
|
-
contentItemService,
|
|
69
|
-
componentRootUrlResolver,
|
|
70
|
-
);
|
|
71
|
-
const webServer = setupRenderRuntimeServer(
|
|
72
|
-
{
|
|
73
|
-
logger,
|
|
74
|
-
componentRunnerService,
|
|
75
|
-
componentFunctionService,
|
|
76
|
-
componentPreviewService: new ComponentPreviewService(),
|
|
77
|
-
componentSetService,
|
|
78
|
-
manifestService,
|
|
79
|
-
renderInputService,
|
|
80
|
-
apiKeyService,
|
|
81
|
-
sandbox,
|
|
82
|
-
componentRootUrlResolver,
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
enableDevMode: true,
|
|
86
|
-
},
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
const server = webServer.listen(options.port, () => {
|
|
90
|
-
logger.info(`Component development webserver started on port ${rootUrl}`);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
if (options?.noBrowser !== true) {
|
|
94
|
-
open(rootUrl);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
server.on('close', async () => {
|
|
98
|
-
await componentRunnerService.stop();
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
return server;
|
|
102
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ComponentRootUrlResolver,
|
|
3
|
-
ComponentPreviewService,
|
|
4
|
-
RenderInputService,
|
|
5
|
-
setupRenderRuntimeServer,
|
|
6
|
-
DevelopmentComponentRunnerService,
|
|
7
|
-
} from '@squiz/edge-dev-render-runtime-lib';
|
|
8
|
-
import { getLogger, LoggerOptions } from '@squiz/dx-logger-lib';
|
|
9
|
-
import path from 'path';
|
|
10
|
-
import { ComponentFunctionService, ComponentSetServiceForLocalDev, ManifestServiceForDev } from '@squiz/component-lib';
|
|
11
|
-
import open from 'open';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* startDevelopmentRender starts a dev-mode render stack for any
|
|
15
|
-
* local directory. This should start an express server on a random unused port
|
|
16
|
-
* which can be accessed for viewing the component in development.
|
|
17
|
-
* @param {string} componentPath - The directory with the component to be rendered
|
|
18
|
-
* @param {object} options - Additional configuration for the dev stack
|
|
19
|
-
* @returns a function to stop the render stack
|
|
20
|
-
*/
|
|
21
|
-
export function startEdgeDevelopmentRender(
|
|
22
|
-
componentPath: string,
|
|
23
|
-
options: { port: number; loggingFormat?: LoggerOptions['format']; noBrowser?: boolean },
|
|
24
|
-
) {
|
|
25
|
-
const logger = getLogger({
|
|
26
|
-
name: 'component-dev',
|
|
27
|
-
format: options.loggingFormat || 'human',
|
|
28
|
-
silent: process.env.NODE_ENV === 'test',
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
const dataMountPoint = path.resolve(process.cwd(), componentPath);
|
|
32
|
-
|
|
33
|
-
const rootUrl = `http://localhost:${options.port}`;
|
|
34
|
-
const componentRootUrlResolver: ComponentRootUrlResolver = () => rootUrl;
|
|
35
|
-
|
|
36
|
-
const developmentComponentRunnerService = new DevelopmentComponentRunnerService();
|
|
37
|
-
const componentFunctionService = new ComponentFunctionService();
|
|
38
|
-
const componentSetService = new ComponentSetServiceForLocalDev(logger);
|
|
39
|
-
const manifestService = new ManifestServiceForDev(dataMountPoint, logger);
|
|
40
|
-
const renderInputService = new RenderInputService(
|
|
41
|
-
componentSetService,
|
|
42
|
-
manifestService,
|
|
43
|
-
componentFunctionService,
|
|
44
|
-
componentRootUrlResolver,
|
|
45
|
-
);
|
|
46
|
-
const webServer = setupRenderRuntimeServer(
|
|
47
|
-
{
|
|
48
|
-
logger,
|
|
49
|
-
developmentComponentRunnerService,
|
|
50
|
-
componentFunctionService,
|
|
51
|
-
componentPreviewService: new ComponentPreviewService(),
|
|
52
|
-
componentSetService,
|
|
53
|
-
manifestService,
|
|
54
|
-
renderInputService,
|
|
55
|
-
componentRootUrlResolver,
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
enableDevMode: true,
|
|
59
|
-
},
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
const server = webServer.listen(options.port, () => {
|
|
63
|
-
logger.info(`Edge Component development webserver started on port ${rootUrl}`);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
if (options?.noBrowser !== true) {
|
|
67
|
-
open(rootUrl);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
server.on('close', async () => {
|
|
71
|
-
// nothing to do
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
return server;
|
|
75
|
-
}
|
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
import componentInit from './component-init';
|
|
2
|
-
import fs from 'fs-extra';
|
|
3
|
-
import * as logger from '@squiz/dx-logger-lib';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
|
|
6
|
-
jest.mock('fs-extra');
|
|
7
|
-
jest.mock('path', () => {
|
|
8
|
-
return {
|
|
9
|
-
...jest.requireActual('path'),
|
|
10
|
-
};
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
const fsMocked = jest.mocked(fs);
|
|
14
|
-
|
|
15
|
-
beforeEach(() => {
|
|
16
|
-
jest.restoreAllMocks();
|
|
17
|
-
fsMocked.readJSON.mockResolvedValue({});
|
|
18
|
-
|
|
19
|
-
// Reset our process.env.NODE_ENV variable
|
|
20
|
-
process.env.NODE_ENV = 'test';
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
describe('componentInit', () => {
|
|
24
|
-
it('should setup a new logger instance with the correct options', async () => {
|
|
25
|
-
const loggerSpy = jest.spyOn(logger, 'getLogger');
|
|
26
|
-
|
|
27
|
-
// Mock the process.env.NODE_ENV variable to be "development"
|
|
28
|
-
process.env.NODE_ENV = 'development';
|
|
29
|
-
|
|
30
|
-
await componentInit({
|
|
31
|
-
componentType: 'basic',
|
|
32
|
-
destination: '',
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
expect(loggerSpy).toHaveBeenCalledWith({
|
|
36
|
-
name: 'component-dev',
|
|
37
|
-
format: 'human',
|
|
38
|
-
silent: false,
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('path.resolve should be called with __dirname to get the current script directory', async () => {
|
|
43
|
-
const pathResolveSpy = jest.spyOn(path, 'resolve');
|
|
44
|
-
|
|
45
|
-
await componentInit({
|
|
46
|
-
componentType: 'basic',
|
|
47
|
-
destination: '',
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
expect(pathResolveSpy).toHaveBeenCalledWith(__dirname);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('path.join should be called with the current script directory and the component type to get the source folder', async () => {
|
|
54
|
-
const pathJoinSpy = jest.spyOn(path, 'join');
|
|
55
|
-
|
|
56
|
-
jest
|
|
57
|
-
.spyOn(path, 'resolve')
|
|
58
|
-
.mockReturnValue('/Users/username/Projects/squiz/component-cli-lib/packages/component-cli-lib/src');
|
|
59
|
-
|
|
60
|
-
await componentInit({
|
|
61
|
-
componentType: 'basic',
|
|
62
|
-
destination: '',
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
expect(pathJoinSpy).toHaveBeenCalledWith(
|
|
66
|
-
'/Users/username/Projects/squiz/component-cli-lib/packages/component-cli-lib/src',
|
|
67
|
-
'templates',
|
|
68
|
-
'basic',
|
|
69
|
-
);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('path.resolve should be called with the destination folder to get the destination folder', async () => {
|
|
73
|
-
const pathResolveSpy = jest.spyOn(path, 'resolve');
|
|
74
|
-
|
|
75
|
-
jest.spyOn(path, 'resolve').mockReturnValue('/Users/username/Projects/squiz/new-component');
|
|
76
|
-
|
|
77
|
-
await componentInit({
|
|
78
|
-
componentType: 'basic',
|
|
79
|
-
destination: '/Users/username/Projects/squiz/new-component',
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
expect(pathResolveSpy).toHaveBeenCalledWith('/Users/username/Projects/squiz/new-component');
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('should fail if the destination folder already exists and there are files in it', async () => {
|
|
86
|
-
// Mock the current script directory
|
|
87
|
-
jest.spyOn(path, 'resolve').mockImplementationOnce(() => {
|
|
88
|
-
return '/Users/username/Projects/squiz/component-cli-lib/packages/component-cli-lib/src';
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
// Mock the destination folder
|
|
92
|
-
jest.spyOn(path, 'resolve').mockImplementationOnce(() => {
|
|
93
|
-
return '/Users/username/Projects/squiz/new-component';
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
// Mock the fs.pathExists function to return true
|
|
97
|
-
jest.spyOn(fs, 'pathExists').mockImplementationOnce(() => {
|
|
98
|
-
return Promise.resolve(true);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
// Mock the fs.readdirSync function to return an array of files
|
|
102
|
-
jest.spyOn(fs, 'readdir').mockImplementationOnce(() => {
|
|
103
|
-
return Promise.resolve(['file1.txt', 'file2.txt']);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
await expect(
|
|
107
|
-
componentInit({
|
|
108
|
-
componentType: 'basic',
|
|
109
|
-
destination: '/Users/username/Projects/squiz/new-component',
|
|
110
|
-
}),
|
|
111
|
-
).rejects.toThrowError('The destination folder already exists and is not empty.');
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('should create the destination folder if it does not exist', async () => {
|
|
115
|
-
// Mock the current script directory
|
|
116
|
-
jest.spyOn(path, 'resolve').mockImplementationOnce(() => {
|
|
117
|
-
return '/Users/username/Projects/squiz/component-cli-lib/packages/component-cli-lib/src';
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
// Mock the destination folder
|
|
121
|
-
jest.spyOn(path, 'resolve').mockImplementationOnce(() => {
|
|
122
|
-
return '/Users/username/Projects/squiz/new-component';
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
// Mock the fs.pathExists function to return false
|
|
126
|
-
jest.spyOn(fs, 'pathExists').mockImplementationOnce(() => {
|
|
127
|
-
return Promise.resolve(false);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
await componentInit({
|
|
131
|
-
componentType: 'basic',
|
|
132
|
-
destination: '/Users/username/Projects/squiz/new-component',
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
expect(fs.mkdirp).toHaveBeenCalledWith('/Users/username/Projects/squiz/new-component');
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it('should not fail if the destination folder already exists and there are no files in it', async () => {
|
|
139
|
-
// Mock the current script directory
|
|
140
|
-
jest.spyOn(path, 'resolve').mockImplementationOnce(() => {
|
|
141
|
-
return '/Users/username/Projects/squiz/component-cli-lib/packages/component-cli-lib/src';
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
// Mock the destination folder
|
|
145
|
-
jest.spyOn(path, 'resolve').mockImplementationOnce(() => {
|
|
146
|
-
return '/Users/username/Projects/squiz/new-component';
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
// Mock the fs.pathExists function to return true
|
|
150
|
-
jest.spyOn(fs, 'pathExists').mockImplementationOnce(() => {
|
|
151
|
-
return Promise.resolve(true);
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
// Mock the fs.readdir function to return an empty array
|
|
155
|
-
jest.spyOn(fs, 'readdir').mockImplementationOnce(() => {
|
|
156
|
-
return Promise.resolve([]);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
await expect(
|
|
160
|
-
componentInit({
|
|
161
|
-
componentType: 'basic',
|
|
162
|
-
destination: '/Users/username/Projects/squiz/new-component',
|
|
163
|
-
}),
|
|
164
|
-
).resolves.toBeUndefined();
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
it('fs.copy should be called with the source folder and the destination folder', async () => {
|
|
168
|
-
// Mock the fs.copy function
|
|
169
|
-
const fsCopySpy = jest.spyOn(fs, 'copy');
|
|
170
|
-
|
|
171
|
-
// Mock the current script directory
|
|
172
|
-
jest.spyOn(path, 'resolve').mockImplementationOnce(() => {
|
|
173
|
-
return '/Users/username/Projects/squiz/component-cli-lib/packages/component-cli-lib/src';
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
// Mock the source folder
|
|
177
|
-
jest.spyOn(path, 'join').mockImplementationOnce(() => {
|
|
178
|
-
return '/Users/username/Projects/squiz/component-cli-lib/packages/component-cli-lib/templates/basic';
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
// Mock the destination folder
|
|
182
|
-
jest.spyOn(path, 'resolve').mockImplementationOnce(() => {
|
|
183
|
-
return '/Users/username/Projects/squiz/new-component';
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
// Mock the fs.pathExists function to return true
|
|
187
|
-
jest.spyOn(fs, 'pathExists').mockImplementationOnce(() => {
|
|
188
|
-
return Promise.resolve(true);
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
// Mock the fs.readdir function to return an empty array
|
|
192
|
-
jest.spyOn(fs, 'readdir').mockImplementationOnce(() => {
|
|
193
|
-
return Promise.resolve([]);
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
await componentInit({
|
|
197
|
-
componentType: 'basic',
|
|
198
|
-
destination: '/Users/username/Projects/squiz/new-component',
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
expect(fsCopySpy).toHaveBeenCalledWith(
|
|
202
|
-
'/Users/username/Projects/squiz/component-cli-lib/packages/component-cli-lib/templates/basic',
|
|
203
|
-
'/Users/username/Projects/squiz/new-component',
|
|
204
|
-
);
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
describe('prompts', () => {
|
|
208
|
-
it('should default when no prompts provided', async () => {
|
|
209
|
-
await componentInit({ componentType: 'basic', destination: '' });
|
|
210
|
-
|
|
211
|
-
expect(fsMocked.writeJSON).toHaveBeenCalledWith(
|
|
212
|
-
expect.any(String),
|
|
213
|
-
expect.objectContaining({
|
|
214
|
-
name: 'default',
|
|
215
|
-
namespace: 'default-namespace',
|
|
216
|
-
displayName: 'Default',
|
|
217
|
-
}),
|
|
218
|
-
expect.objectContaining({ spaces: 2 }),
|
|
219
|
-
);
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
it('should overwrite default values with provided values', async () => {
|
|
223
|
-
await componentInit({
|
|
224
|
-
componentType: 'basic',
|
|
225
|
-
destination: '',
|
|
226
|
-
prompts: {
|
|
227
|
-
name: 'my-component',
|
|
228
|
-
namespace: 'my-namespace',
|
|
229
|
-
displayName: 'My Component',
|
|
230
|
-
},
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
expect(fsMocked.writeJSON).toHaveBeenCalledWith(
|
|
234
|
-
expect.any(String),
|
|
235
|
-
expect.objectContaining({
|
|
236
|
-
name: 'my-component',
|
|
237
|
-
namespace: 'my-namespace',
|
|
238
|
-
displayName: 'My Component',
|
|
239
|
-
}),
|
|
240
|
-
expect.objectContaining({ spaces: 2 }),
|
|
241
|
-
);
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
it('should read and write the destination manifest file', async () => {
|
|
245
|
-
await componentInit({
|
|
246
|
-
componentType: 'basic',
|
|
247
|
-
destination: '/Users/username/Projects/squiz/new-component',
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
expect(fsMocked.readJSON).toHaveBeenCalledWith('/Users/username/Projects/squiz/new-component/manifest.json');
|
|
251
|
-
expect(fsMocked.writeJSON).toHaveBeenCalledWith(
|
|
252
|
-
'/Users/username/Projects/squiz/new-component/manifest.json',
|
|
253
|
-
expect.any(Object),
|
|
254
|
-
expect.objectContaining({ spaces: 2 }),
|
|
255
|
-
);
|
|
256
|
-
});
|
|
257
|
-
});
|
|
258
|
-
});
|