@squiz/dxp-cli-next 5.6.0-develop.2 → 5.6.0-develop.4
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/cmp/init.js +40 -2
- package/lib/job-runner/job/uploadJob/uploadJob.spec.js +2 -2
- package/lib/job-runner/jobContext/listJobContexts.js +1 -1
- package/lib/job-runner/jobContext/listJobContexts.spec.js +2 -2
- package/lib/job-runner/jobExecution/beginJob/beginJob.js +8 -3
- package/lib/job-runner/jobExecution/beginJob/beginJob.spec.js +8 -7
- package/lib/job-runner/jobExecution/listJobExecutions/listJobExecutions.js +1 -1
- package/lib/job-runner/jobExecution/listJobExecutions/listJobExecutions.spec.js +2 -2
- package/lib/job-runner/jobExecution/terminateJob/terminateJob.js +5 -3
- package/lib/job-runner/jobExecution/terminateJob/terminateJob.spec.js +7 -6
- package/lib/job-runner/utils.d.ts +1 -0
- package/lib/job-runner/utils.js +32 -3
- package/lib/job-runner/utils.spec.js +20 -2
- package/package.json +2 -2
package/lib/cmp/init.js
CHANGED
|
@@ -8,6 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
11
22
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
23
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
24
|
};
|
|
@@ -16,6 +27,7 @@ const commander_1 = require("commander");
|
|
|
16
27
|
const cli_color_1 = __importDefault(require("cli-color"));
|
|
17
28
|
const component_cli_lib_1 = require("@squiz/component-cli-lib");
|
|
18
29
|
const child_process_1 = require("child_process");
|
|
30
|
+
const inquirer_1 = require("inquirer");
|
|
19
31
|
var componentTypes;
|
|
20
32
|
(function (componentTypes) {
|
|
21
33
|
componentTypes["basic"] = "basic";
|
|
@@ -29,7 +41,13 @@ const initCommand = new commander_1.Command()
|
|
|
29
41
|
.choices(['basic', 'advanced'])
|
|
30
42
|
.default('basic'))
|
|
31
43
|
.addOption(new commander_1.Option('-i, --install', 'Install dependencies after creating component').default(false))
|
|
32
|
-
.
|
|
44
|
+
.addOption(new commander_1.Option('--name <string>', 'Name of the component'))
|
|
45
|
+
.addOption(new commander_1.Option('--display-name <string>', 'Display name of the component'))
|
|
46
|
+
.addOption(new commander_1.Option('--description <string>', 'Description of the component'))
|
|
47
|
+
.addOption(new commander_1.Option('--namespace <string>', 'Namespace of the component'))
|
|
48
|
+
.addOption(new commander_1.Option('--ci', 'Skip user prompts').default(false))
|
|
49
|
+
.action((destination, _a) => __awaiter(void 0, void 0, void 0, function* () {
|
|
50
|
+
var { type: componentType, install, ci } = _a, prompts = __rest(_a, ["type", "install", "ci"]);
|
|
33
51
|
if (!componentType || componentTypeIsValid(componentType) === false) {
|
|
34
52
|
initCommand.error(cli_color_1.default.red('Invalid component type. Must be one of: basic, advanced'));
|
|
35
53
|
return;
|
|
@@ -38,9 +56,15 @@ const initCommand = new commander_1.Command()
|
|
|
38
56
|
initCommand.error(cli_color_1.default.red('Component type "basic" does not come with a package.json file, install is not a valid option'));
|
|
39
57
|
return;
|
|
40
58
|
}
|
|
59
|
+
if (!ci)
|
|
60
|
+
prompts = yield handleManifestPrompts(prompts);
|
|
41
61
|
console.log(`Creating ${componentType} component in ${destination}...`);
|
|
42
62
|
try {
|
|
43
|
-
yield (0, component_cli_lib_1.componentInit)({
|
|
63
|
+
yield (0, component_cli_lib_1.componentInit)({
|
|
64
|
+
componentType,
|
|
65
|
+
destination,
|
|
66
|
+
prompts,
|
|
67
|
+
});
|
|
44
68
|
if (install) {
|
|
45
69
|
console.log('Installing dependencies');
|
|
46
70
|
(0, child_process_1.execSync)('npm i', {
|
|
@@ -65,3 +89,17 @@ function componentTypeIsValid(componentType) {
|
|
|
65
89
|
return componentType === 'basic' || componentType == 'advanced';
|
|
66
90
|
}
|
|
67
91
|
exports.default = initCommand;
|
|
92
|
+
function handleManifestPrompts(existingPrompts) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
const promptKeys = ['name', 'displayName', 'description', 'namespace'];
|
|
95
|
+
const prompts = promptKeys
|
|
96
|
+
.filter(key => key in existingPrompts === false)
|
|
97
|
+
.map(key => ({
|
|
98
|
+
type: 'input',
|
|
99
|
+
name: key,
|
|
100
|
+
message: `What is the component ${key}?`,
|
|
101
|
+
}));
|
|
102
|
+
const response = yield (0, inquirer_1.prompt)(prompts);
|
|
103
|
+
return Object.assign(Object.assign({}, response), existingPrompts);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
@@ -21,7 +21,7 @@ describe('upload job', () => {
|
|
|
21
21
|
yield program.parseAsync([
|
|
22
22
|
'node',
|
|
23
23
|
'dxp-cli',
|
|
24
|
-
'./src/__tests__/
|
|
24
|
+
'./src/__tests__/job-runner/simple-job',
|
|
25
25
|
'-t',
|
|
26
26
|
'myTenant',
|
|
27
27
|
'-ou',
|
|
@@ -29,7 +29,7 @@ describe('upload job', () => {
|
|
|
29
29
|
]);
|
|
30
30
|
const opts = program.opts();
|
|
31
31
|
const args = program.args;
|
|
32
|
-
expect(args[0]).toEqual('./src/__tests__/
|
|
32
|
+
expect(args[0]).toEqual('./src/__tests__/job-runner/simple-job');
|
|
33
33
|
expect(opts.tenant).toEqual('myTenant');
|
|
34
34
|
expect(opts.overrideUrl).toEqual('http://localhost:9999');
|
|
35
35
|
expect(logSpy).toHaveBeenCalledTimes(4);
|
|
@@ -40,7 +40,7 @@ const createListJobContextsCommand = () => {
|
|
|
40
40
|
res.data.forEach((context) => {
|
|
41
41
|
console.log(`${chalk_1.default.green(chalk_1.default.bold(context.contextName))}: ${chalk_1.default.green(context.description)}`);
|
|
42
42
|
for (const [key, value] of Object.entries(context.environment)) {
|
|
43
|
-
console.log(`${chalk_1.default.bold(key)}: ${value}`);
|
|
43
|
+
console.log(`${chalk_1.default.bold(key)}: ${JSON.stringify(value)}`);
|
|
44
44
|
}
|
|
45
45
|
(0, utils_1.writeLineSeparator)();
|
|
46
46
|
});
|
|
@@ -57,8 +57,8 @@ describe('listJobContexts', () => {
|
|
|
57
57
|
expect(opts.overrideUrl).toEqual('http://localhost:9999');
|
|
58
58
|
expect(logSpy).toHaveBeenCalledTimes(9);
|
|
59
59
|
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.green(chalk_1.default.bold('dev'))}: ${chalk_1.default.green('dev context')}`);
|
|
60
|
-
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('something')}: cool`);
|
|
61
|
-
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('somethingElse')}: cooler`);
|
|
60
|
+
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('something')}: ${JSON.stringify('cool')}`);
|
|
61
|
+
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('somethingElse')}: ${JSON.stringify('cooler')}`);
|
|
62
62
|
expect(logSpy).toHaveBeenCalledWith(chalk_1.default.cyan('------------------------------'));
|
|
63
63
|
}));
|
|
64
64
|
});
|
|
@@ -22,29 +22,34 @@ const createBeginJobCommand = () => {
|
|
|
22
22
|
.name('beginJob')
|
|
23
23
|
.description('Add a job to the queue')
|
|
24
24
|
.addOption(new commander_1.Option('-t, --tenant <string>', 'Tenant ID to deploy to. If not provided will use configured tenant from login'))
|
|
25
|
+
.addOption(new commander_1.Option('-i, --inputFile <string>', 'Path to the .json input file for the job execution e.g. documents/inputs/myInput.json'))
|
|
25
26
|
.addArgument(new commander_1.Argument('<jobName>', 'Name of the job to pass to the request'))
|
|
26
27
|
.addArgument(new commander_1.Argument('<contextName>', 'Name of the job context to pass to the request'))
|
|
27
|
-
.addArgument(new commander_1.Argument('<inputSource>', 'Path to the .json input file for the job execution'))
|
|
28
28
|
.configureOutput({
|
|
29
29
|
outputError(str, write) {
|
|
30
30
|
write(chalk_1.default.red(str));
|
|
31
31
|
},
|
|
32
32
|
})
|
|
33
|
-
.action((jobName, contextName,
|
|
33
|
+
.action((jobName, contextName, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
34
|
yield (0, utils_1.throwErrorIfNotLoggedIn)(beginJobCommand);
|
|
35
35
|
const spinner = (0, ora_1.default)('Queueing job').start();
|
|
36
36
|
console.log('');
|
|
37
|
+
let input;
|
|
37
38
|
try {
|
|
39
|
+
if (options.inputFile) {
|
|
40
|
+
input = yield (0, utils_1.readInputFile)(options.inputFile);
|
|
41
|
+
}
|
|
38
42
|
const apiService = new ApiService_1.ApiService(utils_1.validateAxiosStatus);
|
|
39
43
|
const beginJobUrl = `${yield (0, utils_1.buildJobRunnerUrl)(options.tenant, options.overrideUrl)}/executions/begin`;
|
|
40
44
|
const res = yield apiService.client.post(beginJobUrl, {
|
|
41
45
|
jobName: jobName,
|
|
42
46
|
context: contextName,
|
|
47
|
+
input: input ? input : null,
|
|
43
48
|
});
|
|
44
49
|
spinner.succeed('Job queued successfully');
|
|
45
50
|
(0, utils_1.writeLineSeparator)();
|
|
46
51
|
for (const [key, value] of Object.entries(res.data)) {
|
|
47
|
-
console.log(`${chalk_1.default.bold([key])}: ${value}`);
|
|
52
|
+
console.log(`${chalk_1.default.bold([key])}: ${JSON.stringify(value)}`);
|
|
48
53
|
}
|
|
49
54
|
return;
|
|
50
55
|
}
|
|
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
const nock_1 = __importDefault(require("nock"));
|
|
16
16
|
const beginJob_1 = __importDefault(require("./beginJob"));
|
|
17
17
|
const chalk_1 = __importDefault(require("chalk"));
|
|
18
|
+
const path_1 = __importDefault(require("path"));
|
|
18
19
|
const logSpy = jest.spyOn(global.console, 'log');
|
|
19
20
|
describe('beginJob', () => {
|
|
20
21
|
it('correctly displays the console logs for beginning a job', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -37,7 +38,8 @@ describe('beginJob', () => {
|
|
|
37
38
|
'dxp-cli',
|
|
38
39
|
'simple-job',
|
|
39
40
|
'dev',
|
|
40
|
-
'
|
|
41
|
+
'-i',
|
|
42
|
+
path_1.default.join('./src/__tests__/job-runner/inputs/input.json'),
|
|
41
43
|
'-t',
|
|
42
44
|
'myTenant',
|
|
43
45
|
'-ou',
|
|
@@ -47,15 +49,14 @@ describe('beginJob', () => {
|
|
|
47
49
|
const args = program.args;
|
|
48
50
|
expect(args[0]).toEqual('simple-job');
|
|
49
51
|
expect(args[1]).toEqual('dev');
|
|
50
|
-
expect(
|
|
52
|
+
expect(opts.inputFile).toEqual(path_1.default.join('./src/__tests__/job-runner/inputs/input.json'));
|
|
51
53
|
expect(opts.tenant).toEqual('myTenant');
|
|
52
54
|
expect(opts.overrideUrl).toEqual('http://localhost:9999');
|
|
53
55
|
expect(logSpy).toHaveBeenCalledTimes(12);
|
|
54
|
-
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('status')}: queued`);
|
|
55
|
-
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('id')}: d0aab852-365e-42de-a642-eac11bb95ccc`);
|
|
56
|
-
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('jobName')}: simple-job`);
|
|
57
|
-
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('status')}: queued`);
|
|
58
|
-
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('timeQueued')}: 2023-06-23T01:36:44.792Z`);
|
|
59
56
|
expect(logSpy).toHaveBeenCalledWith(chalk_1.default.cyan('------------------------------'));
|
|
57
|
+
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('context')}: "dev"`);
|
|
58
|
+
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('id')}: "d0aab852-365e-42de-a642-eac11bb95ccc"`);
|
|
59
|
+
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('jobName')}: "simple-job"`);
|
|
60
|
+
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('timeQueued')}: "2023-06-23T01:36:44.792Z"`);
|
|
60
61
|
}));
|
|
61
62
|
});
|
|
@@ -39,7 +39,7 @@ const createListJobExecutionsCommand = () => {
|
|
|
39
39
|
(0, utils_1.writeLineSeparator)();
|
|
40
40
|
res.data.forEach((execution) => {
|
|
41
41
|
for (const [key, value] of Object.entries(execution)) {
|
|
42
|
-
console.log(`${chalk_1.default.bold([key])}: ${value}`);
|
|
42
|
+
console.log(`${chalk_1.default.bold([key])}: ${JSON.stringify(value)}`);
|
|
43
43
|
}
|
|
44
44
|
(0, utils_1.writeLineSeparator)();
|
|
45
45
|
});
|
|
@@ -59,8 +59,8 @@ describe('listJobExecutions', () => {
|
|
|
59
59
|
expect(opts.overrideUrl).toEqual('http://localhost:9999');
|
|
60
60
|
expect(logSpy).toHaveBeenCalled();
|
|
61
61
|
expect(logSpy).toHaveBeenCalledTimes(19);
|
|
62
|
-
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('status')}: successfully-completed`);
|
|
63
|
-
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('jobName')}: simple-job`);
|
|
62
|
+
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('status')}: ${JSON.stringify('successfully-completed')}`);
|
|
63
|
+
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('jobName')}: ${JSON.stringify('simple-job')}`);
|
|
64
64
|
expect(logSpy).toHaveBeenCalledWith(chalk_1.default.cyan('------------------------------'));
|
|
65
65
|
}));
|
|
66
66
|
});
|
|
@@ -25,12 +25,13 @@ const createTerminateJobCommand = () => {
|
|
|
25
25
|
.addOption(new commander_1.Option('-ou, --overrideUrl <string>', 'Developer option to override the entire job runner url with a custom value'))
|
|
26
26
|
.addArgument(new commander_1.Argument('<jobName>', 'Name of the job to pass to the request'))
|
|
27
27
|
.addArgument(new commander_1.Argument('<executionId>', 'Name of the job execution id to pass to the request'))
|
|
28
|
+
.addArgument(new commander_1.Argument('<reason>', 'Reason for job termination, eg "Cancelling due to mistake in inputs"'))
|
|
28
29
|
.configureOutput({
|
|
29
30
|
outputError(str, write) {
|
|
30
31
|
write(chalk_1.default.red(str));
|
|
31
32
|
},
|
|
32
33
|
})
|
|
33
|
-
.action((jobName, executionId, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
.action((jobName, executionId, reason, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
35
|
yield (0, utils_1.throwErrorIfNotLoggedIn)(terminateJobCommand);
|
|
35
36
|
const spinner = (0, ora_1.default)('Terminating job').start();
|
|
36
37
|
console.log('');
|
|
@@ -39,10 +40,11 @@ const createTerminateJobCommand = () => {
|
|
|
39
40
|
const terminateJobUrl = `${yield (0, utils_1.buildJobRunnerUrl)(options.tenant, options.overrideUrl)}/executions/terminate`;
|
|
40
41
|
const res = yield apiService.client.post(terminateJobUrl, {
|
|
41
42
|
jobName: jobName,
|
|
42
|
-
|
|
43
|
+
executionId: executionId,
|
|
44
|
+
reason: reason,
|
|
43
45
|
});
|
|
44
46
|
for (const [key, value] of Object.entries(res.data)) {
|
|
45
|
-
console.log(`${chalk_1.default.bold([key])}: ${value}`);
|
|
47
|
+
console.log(`${chalk_1.default.bold([key])}: ${JSON.stringify(value)}`);
|
|
46
48
|
}
|
|
47
49
|
spinner.succeed('Job terminated');
|
|
48
50
|
return;
|
|
@@ -37,6 +37,7 @@ describe('terminateJob', () => {
|
|
|
37
37
|
'dxp-cli',
|
|
38
38
|
'simple-job',
|
|
39
39
|
'907fc4e5-8b4a-4e47-bab0-e95e45385347',
|
|
40
|
+
'test termination',
|
|
40
41
|
'-t',
|
|
41
42
|
'myTenant',
|
|
42
43
|
'-ou',
|
|
@@ -49,11 +50,11 @@ describe('terminateJob', () => {
|
|
|
49
50
|
expect(opts.tenant).toEqual('myTenant');
|
|
50
51
|
expect(opts.overrideUrl).toEqual('http://localhost:9999');
|
|
51
52
|
expect(logSpy).toHaveBeenCalledTimes(11);
|
|
52
|
-
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('status')}: terminated`);
|
|
53
|
-
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('jobName')}: simple-job`);
|
|
54
|
-
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('id')}: simple-job-d6a418eb-dd63-4594-b299-07410ccd30d5`);
|
|
55
|
-
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('context')}: dev`);
|
|
56
|
-
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('timeFinished')}: 2023-06-23T01:49:09.433Z`);
|
|
57
|
-
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('version')}: 1.0.1`);
|
|
53
|
+
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('status')}: ${JSON.stringify('terminated')}`);
|
|
54
|
+
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('jobName')}: ${JSON.stringify('simple-job')}`);
|
|
55
|
+
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('id')}: ${JSON.stringify('simple-job-d6a418eb-dd63-4594-b299-07410ccd30d5')}`);
|
|
56
|
+
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('context')}: ${JSON.stringify('dev')}`);
|
|
57
|
+
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('timeFinished')}: ${JSON.stringify('2023-06-23T01:49:09.433Z')}`);
|
|
58
|
+
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('version')}: ${JSON.stringify('1.0.1')}`);
|
|
58
59
|
}));
|
|
59
60
|
});
|
|
@@ -2,5 +2,6 @@ import { Command } from 'commander';
|
|
|
2
2
|
export declare function handleCommandError(command: Command, error: Error): void;
|
|
3
3
|
export declare function throwErrorIfNotLoggedIn(command: Command): Promise<void>;
|
|
4
4
|
export declare function buildJobRunnerUrl(tenantID?: string, overrideUrl?: string): Promise<string>;
|
|
5
|
+
export declare function readInputFile(inputPath: string): Promise<any>;
|
|
5
6
|
export declare function writeLineSeparator(): void;
|
|
6
7
|
export declare function validateAxiosStatus(status: number): boolean;
|
package/lib/job-runner/utils.js
CHANGED
|
@@ -12,15 +12,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.validateAxiosStatus = exports.writeLineSeparator = exports.buildJobRunnerUrl = exports.throwErrorIfNotLoggedIn = exports.handleCommandError = void 0;
|
|
15
|
+
exports.validateAxiosStatus = exports.writeLineSeparator = exports.readInputFile = exports.buildJobRunnerUrl = exports.throwErrorIfNotLoggedIn = exports.handleCommandError = void 0;
|
|
16
|
+
const fs_1 = __importDefault(require("fs"));
|
|
16
17
|
const chalk_1 = __importDefault(require("chalk"));
|
|
17
18
|
const ApplicationConfig_1 = require("../ApplicationConfig");
|
|
18
19
|
const axios_1 = __importDefault(require("axios"));
|
|
19
20
|
const ApplicationStore_1 = require("../ApplicationStore");
|
|
20
21
|
function handleCommandError(command, error) {
|
|
21
|
-
var _a, _b;
|
|
22
|
+
var _a, _b, _c, _d;
|
|
22
23
|
if (axios_1.default.isAxiosError(error)) {
|
|
23
|
-
|
|
24
|
+
let message = `${error.message}`;
|
|
25
|
+
if ((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.message) {
|
|
26
|
+
message += `: ${error.response.data.message}`;
|
|
27
|
+
}
|
|
28
|
+
if ((_d = (_c = error.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.details) {
|
|
29
|
+
message += ` - ${error.response.data.details}`;
|
|
30
|
+
}
|
|
31
|
+
command.error(chalk_1.default.red(message));
|
|
24
32
|
}
|
|
25
33
|
else {
|
|
26
34
|
if (!!process.env.DEBUG && error.stack) {
|
|
@@ -55,6 +63,27 @@ function buildJobRunnerUrl(tenantID, overrideUrl) {
|
|
|
55
63
|
});
|
|
56
64
|
}
|
|
57
65
|
exports.buildJobRunnerUrl = buildJobRunnerUrl;
|
|
66
|
+
function readInputFile(inputPath) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
if (inputPath.endsWith('.json')) {
|
|
69
|
+
if (fs_1.default.existsSync(inputPath)) {
|
|
70
|
+
try {
|
|
71
|
+
return JSON.parse(fs_1.default.readFileSync(inputPath, { encoding: 'utf-8' }));
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
throw new Error(`Unable to read file ${inputPath} - ${e.message}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
throw new Error('Input could not be found');
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
throw new Error('Input must be a .json file');
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
exports.readInputFile = readInputFile;
|
|
58
87
|
function writeLineSeparator() {
|
|
59
88
|
console.log(chalk_1.default.cyan('------------------------------'));
|
|
60
89
|
}
|
|
@@ -16,6 +16,7 @@ const utils_1 = require("./utils");
|
|
|
16
16
|
const commander_1 = require("commander");
|
|
17
17
|
const axios_1 = require("axios");
|
|
18
18
|
const chalk_1 = __importDefault(require("chalk"));
|
|
19
|
+
const path_1 = __importDefault(require("path"));
|
|
19
20
|
const exitSpy = jest.spyOn(process, 'exit').mockImplementation(() => {
|
|
20
21
|
return undefined;
|
|
21
22
|
}); // prevent process exit on error
|
|
@@ -38,12 +39,13 @@ describe('handleCommandError', () => {
|
|
|
38
39
|
const command = new commander_1.Command();
|
|
39
40
|
const message = 'Something bad happened';
|
|
40
41
|
const responseMessage = 'I am an error response';
|
|
42
|
+
const errDetails = 'i am error details';
|
|
41
43
|
(0, utils_1.handleCommandError)(command, new axios_1.AxiosError(message, '500', undefined, undefined, {
|
|
42
|
-
data: { message: responseMessage },
|
|
44
|
+
data: { message: responseMessage, details: errDetails },
|
|
43
45
|
}));
|
|
44
46
|
expect(stderrSpy).toHaveBeenCalledTimes(1);
|
|
45
47
|
// read the mock call strings directly otherwise colours cause test failures with .toEqual()
|
|
46
|
-
expect(stderrSpy.mock.calls[0][0]).toContain(`${message}: ${responseMessage}`);
|
|
48
|
+
expect(stderrSpy.mock.calls[0][0]).toContain(`${message}: ${responseMessage} - ${errDetails}`);
|
|
47
49
|
}));
|
|
48
50
|
it('correctly displays the console logs for error without a message', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
51
|
const command = new commander_1.Command();
|
|
@@ -72,3 +74,19 @@ describe('buildJobRunnerUrl', () => {
|
|
|
72
74
|
expect(url).toBe('http://localhost:9999/someTenant');
|
|
73
75
|
}));
|
|
74
76
|
});
|
|
77
|
+
describe('readInputFile', () => {
|
|
78
|
+
it('correctly reads the file ', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
79
|
+
const res = yield (0, utils_1.readInputFile)(path_1.default.join('./src/__tests__/job-runner/inputs/input.json'));
|
|
80
|
+
expect(res).toStrictEqual({ something: 'amazing' });
|
|
81
|
+
}));
|
|
82
|
+
it('errors if file extension is not .json', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
83
|
+
yield expect((0, utils_1.readInputFile)(path_1.default.join('./src/__tests__/job-runner/simple-job/main.js'))).rejects.toThrow('Input must be a .json file');
|
|
84
|
+
}));
|
|
85
|
+
it('errors if file does not exist', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
86
|
+
yield expect((0, utils_1.readInputFile)(path_1.default.join('./src/__tests__/job-runner/simple-job/input.json'))).rejects.toThrow('Input could not be found');
|
|
87
|
+
}));
|
|
88
|
+
it('errors if file has json extension but cannot be parsed', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
89
|
+
const source = './src/__tests__/job-runner/inputs/badInput.json';
|
|
90
|
+
yield expect((0, utils_1.readInputFile)(path_1.default.join(source))).rejects.toThrow(`Unable to read file ${path_1.default.join(source)} - Unexpected token i in JSON at position 1`);
|
|
91
|
+
}));
|
|
92
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@squiz/dxp-cli-next",
|
|
3
|
-
"version": "5.6.0-develop.
|
|
3
|
+
"version": "5.6.0-develop.4",
|
|
4
4
|
"repository": {
|
|
5
5
|
"url": "https://gitlab.squiz.net/developer-experience/dxp-cli-next"
|
|
6
6
|
},
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"codecov"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@squiz/component-cli-lib": "^1.
|
|
42
|
+
"@squiz/component-cli-lib": "^1.40.1-alpha",
|
|
43
43
|
"axios": "1.1.3",
|
|
44
44
|
"cli-color": "2.0.3",
|
|
45
45
|
"commander": "9.4.0",
|