@squiz/component-cli-lib 1.39.1-alpha.23 → 1.39.1-alpha.24
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/.npm/_logs/{2023-06-29T00_07_12_723Z-debug-0.log → 2023-06-29T01_54_23_207Z-debug-0.log} +20 -20
- package/lib/component-init.d.ts +14 -5
- package/lib/index.d.ts +1 -1
- package/lib/index.js +54 -54
- package/lib/index.js.map +3 -3
- package/lib/templates/advanced/package-lock.json +916 -0
- package/lib/templates/advanced/package.json +2 -2
- package/package.json +9 -9
- package/src/component-init.spec.ts +55 -0
- package/src/component-init.ts +38 -5
- package/src/index.ts +1 -1
- package/templates/advanced/package-lock.json +916 -0
- package/templates/advanced/package.json +2 -2
- package/tsconfig.tsbuildinfo +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@squiz/component-cli-lib",
|
|
3
|
-
"version": "1.39.1-alpha.
|
|
3
|
+
"version": "1.39.1-alpha.24",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
"author": "",
|
|
14
14
|
"license": "ISC",
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"@squiz/component-lib": "1.39.1-alpha.
|
|
17
|
-
"@squiz/component-web-api-lib": "1.39.1-alpha.
|
|
18
|
-
"@squiz/dx-common-lib": "1.39.1-alpha.
|
|
19
|
-
"@squiz/dx-json-schema-lib": "1.39.1-alpha.
|
|
20
|
-
"@squiz/dx-logger-lib": "1.39.1-alpha.
|
|
21
|
-
"@squiz/virus-scanner-lib": "1.39.1-alpha.
|
|
16
|
+
"@squiz/component-lib": "1.39.1-alpha.24",
|
|
17
|
+
"@squiz/component-web-api-lib": "1.39.1-alpha.24",
|
|
18
|
+
"@squiz/dx-common-lib": "1.39.1-alpha.24",
|
|
19
|
+
"@squiz/dx-json-schema-lib": "1.39.1-alpha.24",
|
|
20
|
+
"@squiz/dx-logger-lib": "1.39.1-alpha.24",
|
|
21
|
+
"@squiz/virus-scanner-lib": "1.39.1-alpha.24",
|
|
22
22
|
"@types/cli-color": "2.0.2",
|
|
23
23
|
"@types/express": "4.17.17",
|
|
24
24
|
"@types/jest": "28.1.8",
|
|
@@ -32,12 +32,12 @@
|
|
|
32
32
|
"typescript": "4.9.4"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@squiz/render-runtime-lib": "1.39.1-alpha.
|
|
35
|
+
"@squiz/render-runtime-lib": "1.39.1-alpha.24",
|
|
36
36
|
"archiver": "5.3.1",
|
|
37
37
|
"axios": "1.3.2",
|
|
38
38
|
"cli-color": "^2.0.2",
|
|
39
39
|
"open": "^8.4.0",
|
|
40
40
|
"supertest": "^6.2.3"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "8e4a8fcb0500763656aff431e30309f206cc8223"
|
|
43
43
|
}
|
|
@@ -10,8 +10,11 @@ jest.mock('path', () => {
|
|
|
10
10
|
};
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
+
const fsMocked = jest.mocked(fs);
|
|
14
|
+
|
|
13
15
|
beforeEach(() => {
|
|
14
16
|
jest.resetAllMocks();
|
|
17
|
+
fsMocked.readJSON.mockResolvedValue({});
|
|
15
18
|
|
|
16
19
|
// Reset our process.env.NODE_ENV variable
|
|
17
20
|
process.env.NODE_ENV = 'test';
|
|
@@ -200,4 +203,56 @@ describe('componentInit', () => {
|
|
|
200
203
|
'/Users/username/Projects/squiz/new-component',
|
|
201
204
|
);
|
|
202
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
|
+
});
|
|
203
258
|
});
|
package/src/component-init.ts
CHANGED
|
@@ -2,17 +2,34 @@ import fse from 'fs-extra';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { getLogger, LoggerOptions } from '@squiz/dx-logger-lib';
|
|
4
4
|
|
|
5
|
+
export interface InitPrompts {
|
|
6
|
+
name: string;
|
|
7
|
+
displayName: string;
|
|
8
|
+
description: string;
|
|
9
|
+
namespace: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const DEFAULT_PROMPTS: InitPrompts = {
|
|
13
|
+
name: 'default',
|
|
14
|
+
displayName: 'Default',
|
|
15
|
+
description: 'Default component',
|
|
16
|
+
namespace: 'default-namespace',
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
interface InitOptions {
|
|
20
|
+
componentType: 'basic' | 'advanced';
|
|
21
|
+
destination: string;
|
|
22
|
+
loggingFormat?: LoggerOptions['format'];
|
|
23
|
+
prompts?: Partial<InitPrompts>;
|
|
24
|
+
}
|
|
25
|
+
|
|
5
26
|
/**
|
|
6
27
|
* componentInit initializes a new component
|
|
7
28
|
* @param {object} options - The options object
|
|
8
29
|
* @param {string} options.componentType - The type of component to initialize
|
|
9
30
|
* @returns {void}
|
|
10
31
|
*/
|
|
11
|
-
export default async function componentInit(options: {
|
|
12
|
-
componentType: 'basic' | 'advanced';
|
|
13
|
-
destination: string;
|
|
14
|
-
loggingFormat?: LoggerOptions['format'];
|
|
15
|
-
}) {
|
|
32
|
+
export default async function componentInit(options: InitOptions) {
|
|
16
33
|
const logger = getLogger({
|
|
17
34
|
name: 'component-dev',
|
|
18
35
|
format: options.loggingFormat || 'human',
|
|
@@ -43,6 +60,22 @@ export default async function componentInit(options: {
|
|
|
43
60
|
|
|
44
61
|
// Copy the contents of the source folder to the destination folder
|
|
45
62
|
await fse.copy(sourceFolder, destination);
|
|
63
|
+
await writeManifestVariables({ destination, prompts: Object.assign({}, DEFAULT_PROMPTS, options.prompts) });
|
|
46
64
|
|
|
47
65
|
logger.info('Component initialized!');
|
|
48
66
|
}
|
|
67
|
+
|
|
68
|
+
async function writeManifestVariables(options: { destination: string; prompts: InitPrompts }) {
|
|
69
|
+
const { destination, prompts } = options;
|
|
70
|
+
|
|
71
|
+
const manifestPath = path.resolve(destination, 'manifest.json');
|
|
72
|
+
|
|
73
|
+
const manifest = await fse.readJSON(manifestPath);
|
|
74
|
+
|
|
75
|
+
manifest.name = prompts.name;
|
|
76
|
+
manifest.displayName = prompts.displayName;
|
|
77
|
+
manifest.description = prompts.description;
|
|
78
|
+
manifest.namespace = prompts.namespace;
|
|
79
|
+
|
|
80
|
+
await fse.writeJSON(manifestPath, manifest, { spaces: 2 });
|
|
81
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { uploadComponentFolder } from './upload-component-folder';
|
|
2
2
|
export { startDevelopmentRender } from './component-dev';
|
|
3
|
-
export { default as componentInit } from './component-init';
|
|
3
|
+
export { default as componentInit, InitPrompts } from './component-init';
|
|
4
4
|
export { uploadJobFolder } from './upload-job';
|