@squiz/dxp-cli-next 5.6.0-develop.1 → 5.6.0-develop.10
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/ApiService.d.ts +1 -1
- package/lib/ApiService.js +5 -2
- package/lib/__tests__/integration/main.spec.js +17 -0
- package/lib/cmp/init.js +40 -2
- package/lib/dxp.js +4 -0
- package/lib/job-runner/index.d.ts +3 -0
- package/lib/job-runner/index.js +22 -0
- package/lib/job-runner/job/listJobs/listJobs.d.ts +3 -0
- package/lib/job-runner/job/listJobs/listJobs.js +64 -0
- package/lib/job-runner/job/listJobs/listJobs.spec.d.ts +1 -0
- package/lib/job-runner/job/listJobs/listJobs.spec.js +42 -0
- package/lib/job-runner/job/uploadJob/uploadJob.d.ts +3 -0
- package/lib/job-runner/job/uploadJob/uploadJob.js +52 -0
- package/lib/job-runner/job/uploadJob/uploadJob.spec.d.ts +1 -0
- package/lib/job-runner/job/uploadJob/uploadJob.spec.js +41 -0
- package/lib/job-runner/jobContext/listJobContexts.d.ts +3 -0
- package/lib/job-runner/jobContext/listJobContexts.js +71 -0
- package/lib/job-runner/jobContext/listJobContexts.spec.d.ts +1 -0
- package/lib/job-runner/jobContext/listJobContexts.spec.js +64 -0
- package/lib/job-runner/jobExecution/beginJob/beginJob.d.ts +3 -0
- package/lib/job-runner/jobExecution/beginJob/beginJob.js +66 -0
- package/lib/job-runner/jobExecution/beginJob/beginJob.spec.d.ts +1 -0
- package/lib/job-runner/jobExecution/beginJob/beginJob.spec.js +62 -0
- package/lib/job-runner/jobExecution/listJobExecutions/listJobExecutions.d.ts +3 -0
- package/lib/job-runner/jobExecution/listJobExecutions/listJobExecutions.js +65 -0
- package/lib/job-runner/jobExecution/listJobExecutions/listJobExecutions.spec.d.ts +1 -0
- package/lib/job-runner/jobExecution/listJobExecutions/listJobExecutions.spec.js +63 -0
- package/lib/job-runner/jobExecution/terminateJob/terminateJob.d.ts +3 -0
- package/lib/job-runner/jobExecution/terminateJob/terminateJob.js +62 -0
- package/lib/job-runner/jobExecution/terminateJob/terminateJob.spec.d.ts +1 -0
- package/lib/job-runner/jobExecution/terminateJob/terminateJob.spec.js +60 -0
- package/lib/job-runner/utils.d.ts +19 -0
- package/lib/job-runner/utils.js +144 -0
- package/lib/job-runner/utils.spec.d.ts +1 -0
- package/lib/job-runner/utils.spec.js +116 -0
- package/package.json +5 -2
package/lib/ApiService.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export declare const COOKIE_KEY = "dxp-sessionid";
|
|
|
7
7
|
*/
|
|
8
8
|
export declare class ApiService {
|
|
9
9
|
client: AxiosInstance;
|
|
10
|
-
constructor();
|
|
10
|
+
constructor(validateStatus?: (status: number) => boolean, baseUrl?: string);
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
13
|
* The API Service requestInterceptor will load the session cookie from
|
package/lib/ApiService.js
CHANGED
|
@@ -23,8 +23,11 @@ exports.COOKIE_KEY = 'dxp-sessionid';
|
|
|
23
23
|
* adding the session cookie to requests.
|
|
24
24
|
*/
|
|
25
25
|
class ApiService {
|
|
26
|
-
constructor() {
|
|
27
|
-
this.client = axios_1.default.create({
|
|
26
|
+
constructor(validateStatus, baseUrl) {
|
|
27
|
+
this.client = axios_1.default.create({
|
|
28
|
+
validateStatus: validateStatus,
|
|
29
|
+
baseURL: baseUrl,
|
|
30
|
+
});
|
|
28
31
|
this.client.interceptors.request.use(requestInterceptor);
|
|
29
32
|
this.client.interceptors.response.use(responseInterceptor);
|
|
30
33
|
}
|
|
@@ -4,9 +4,11 @@ const helpers_1 = require("../helpers");
|
|
|
4
4
|
describe('dxp', () => {
|
|
5
5
|
beforeEach(() => {
|
|
6
6
|
process.env.FEATURE_TD_ACTIVE = 'true';
|
|
7
|
+
process.env.ENABLE_JOB_RUNNER = 'true';
|
|
7
8
|
});
|
|
8
9
|
afterAll(() => {
|
|
9
10
|
process.env.FEATURE_TD_ACTIVE = undefined;
|
|
11
|
+
process.env.ENABLE_JOB_RUNNER = undefined;
|
|
10
12
|
});
|
|
11
13
|
it('should display the help contents', () => {
|
|
12
14
|
const { stdout } = (0, helpers_1.runCLI)(process.cwd(), ['--help']);
|
|
@@ -14,17 +16,32 @@ describe('dxp', () => {
|
|
|
14
16
|
});
|
|
15
17
|
it('should show all available commands', () => {
|
|
16
18
|
var _a;
|
|
19
|
+
process.env.ENABLE_JOB_RUNNER = 'true';
|
|
17
20
|
const { stdout } = (0, helpers_1.runCLI)(process.cwd(), ['--help']);
|
|
18
21
|
const commandsText = (_a = stdout
|
|
19
22
|
.match(/Commands\:(.*)/is)) === null || _a === void 0 ? void 0 : _a[1].split('\n').map(a => a.trim()).filter(a => !!a);
|
|
20
23
|
expect(commandsText).toEqual([
|
|
21
24
|
'auth Authenticate into the DXP CLI',
|
|
25
|
+
'job-runner Job Runner Service Commands',
|
|
22
26
|
'cmp Component Service Commands',
|
|
23
27
|
]);
|
|
24
28
|
});
|
|
25
29
|
it('if FEATURE_TD_ACTIVE not set to true, td command should not be visible', () => {
|
|
26
30
|
var _a;
|
|
27
31
|
process.env.FEATURE_TD_ACTIVE = undefined;
|
|
32
|
+
process.env.ENABLE_JOB_RUNNER = 'true';
|
|
33
|
+
const { stdout } = (0, helpers_1.runCLI)(process.cwd(), ['--help']);
|
|
34
|
+
const commandsText = (_a = stdout
|
|
35
|
+
.match(/Commands\:(.*)/is)) === null || _a === void 0 ? void 0 : _a[1].split('\n').map(a => a.trim()).filter(a => !!a);
|
|
36
|
+
expect(commandsText).toEqual([
|
|
37
|
+
'auth Authenticate into the DXP CLI',
|
|
38
|
+
'job-runner Job Runner Service Commands',
|
|
39
|
+
'cmp Component Service Commands',
|
|
40
|
+
]);
|
|
41
|
+
});
|
|
42
|
+
it('if ENABLE_JOB_RUNNER not set to true, job-runner command should not be visible', () => {
|
|
43
|
+
var _a;
|
|
44
|
+
process.env.ENABLE_JOB_RUNNER = undefined;
|
|
28
45
|
const { stdout } = (0, helpers_1.runCLI)(process.cwd(), ['--help']);
|
|
29
46
|
const commandsText = (_a = stdout
|
|
30
47
|
.match(/Commands\:(.*)/is)) === null || _a === void 0 ? void 0 : _a[1].split('\n').map(a => a.trim()).filter(a => !!a);
|
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
|
+
}
|
package/lib/dxp.js
CHANGED
|
@@ -14,6 +14,7 @@ validateNodeVersion();
|
|
|
14
14
|
const auth_1 = __importDefault(require("./auth"));
|
|
15
15
|
// import tdCommand from './td';
|
|
16
16
|
const cmp_1 = __importDefault(require("./cmp"));
|
|
17
|
+
const job_runner_1 = __importDefault(require("./job-runner"));
|
|
17
18
|
const program = new commander_1.default.Command();
|
|
18
19
|
const packageJson = require('../package.json');
|
|
19
20
|
const version = packageJson.version;
|
|
@@ -22,6 +23,9 @@ program
|
|
|
22
23
|
.version(version)
|
|
23
24
|
.description('dxp commands')
|
|
24
25
|
.addCommand(auth_1.default);
|
|
26
|
+
if (process.env.ENABLE_JOB_RUNNER === 'true') {
|
|
27
|
+
program.addCommand(job_runner_1.default);
|
|
28
|
+
}
|
|
25
29
|
// if (process.env.FEATURE_TD_ACTIVE === 'true') {
|
|
26
30
|
// program.addCommand(tdCommand);
|
|
27
31
|
// }
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
const commander_1 = require("commander");
|
|
7
|
+
const listJobs_1 = __importDefault(require("./job/listJobs/listJobs"));
|
|
8
|
+
const beginJob_1 = __importDefault(require("./jobExecution/beginJob/beginJob"));
|
|
9
|
+
const terminateJob_1 = __importDefault(require("./jobExecution/terminateJob/terminateJob"));
|
|
10
|
+
const listJobContexts_1 = __importDefault(require("./jobContext/listJobContexts"));
|
|
11
|
+
const listJobExecutions_1 = __importDefault(require("./jobExecution/listJobExecutions/listJobExecutions"));
|
|
12
|
+
const uploadJob_1 = __importDefault(require("./job/uploadJob/uploadJob"));
|
|
13
|
+
const jobRunnerCommand = new commander_1.Command('job-runner');
|
|
14
|
+
jobRunnerCommand
|
|
15
|
+
.description('Job Runner Service Commands')
|
|
16
|
+
.addCommand((0, uploadJob_1.default)())
|
|
17
|
+
.addCommand((0, beginJob_1.default)())
|
|
18
|
+
.addCommand((0, terminateJob_1.default)())
|
|
19
|
+
.addCommand((0, listJobs_1.default)())
|
|
20
|
+
.addCommand((0, listJobExecutions_1.default)())
|
|
21
|
+
.addCommand((0, listJobContexts_1.default)());
|
|
22
|
+
exports.default = jobRunnerCommand;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const commander_1 = require("commander");
|
|
16
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
17
|
+
const ora_1 = __importDefault(require("ora"));
|
|
18
|
+
const ApiService_1 = require("../../../ApiService");
|
|
19
|
+
const utils_1 = require("../../utils");
|
|
20
|
+
const createListJobsCommand = () => {
|
|
21
|
+
const listJobsCommand = new commander_1.Command('listJobs')
|
|
22
|
+
.name('listJobs')
|
|
23
|
+
.description('List all jobs')
|
|
24
|
+
.addOption(new commander_1.Option('-s, --size <string>', 'Pagination page size. Choices are tiny (5), small (20), medium (50), large (100). If not included, will default to small').choices(['tiny', 'small', 'medium', 'large']))
|
|
25
|
+
.addOption(new commander_1.Option('-b, --before <string>', 'Pagination page before token'))
|
|
26
|
+
.addOption(new commander_1.Option('-a, --after <string>', 'Pagination page after token'))
|
|
27
|
+
.addOption(new commander_1.Option('-t, --tenant <string>', 'Tenant ID to run against. If not provided will use configured tenant from login'))
|
|
28
|
+
.configureOutput({
|
|
29
|
+
outputError(str, write) {
|
|
30
|
+
write(chalk_1.default.red(str));
|
|
31
|
+
},
|
|
32
|
+
})
|
|
33
|
+
.action((options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
yield (0, utils_1.throwErrorIfNotLoggedIn)(listJobsCommand);
|
|
35
|
+
const spinner = (0, ora_1.default)('Retrieving jobs').start();
|
|
36
|
+
try {
|
|
37
|
+
const apiService = new ApiService_1.ApiService(utils_1.validateAxiosStatus);
|
|
38
|
+
let listJobsUrl = `${yield (0, utils_1.buildJobRunnerUrl)(options.tenant, options.overrideUrl)}/job/latest?`;
|
|
39
|
+
listJobsUrl = (0, utils_1.addPaginationToUrl)(listJobsUrl, {
|
|
40
|
+
before: options.before,
|
|
41
|
+
after: options.after,
|
|
42
|
+
size: options.size,
|
|
43
|
+
});
|
|
44
|
+
const res = yield apiService.client.get(listJobsUrl);
|
|
45
|
+
if (Array.isArray(res.data.data) && res.data.data.length > 0) {
|
|
46
|
+
spinner.succeed(`Retrieved ${res.data.data.length} jobs`);
|
|
47
|
+
yield (0, utils_1.logArrayResults)(res.data.data, res.data.links);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
spinner.succeed('No jobs found');
|
|
51
|
+
}
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
spinner.fail();
|
|
56
|
+
(0, utils_1.handleCommandError)(listJobsCommand, error);
|
|
57
|
+
}
|
|
58
|
+
}));
|
|
59
|
+
if (process.env.ENABLE_OVERRIDE_JOB_RUNNER_URL === 'true') {
|
|
60
|
+
listJobsCommand.addOption(new commander_1.Option('-ou, --overrideUrl <string>', 'Developer option to override the entire job runner url with a custom value'));
|
|
61
|
+
}
|
|
62
|
+
return listJobsCommand;
|
|
63
|
+
};
|
|
64
|
+
exports.default = createListJobsCommand;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const nock_1 = __importDefault(require("nock"));
|
|
16
|
+
const listJobs_1 = __importDefault(require("./listJobs"));
|
|
17
|
+
const logSpy = jest.spyOn(global.console, 'log');
|
|
18
|
+
describe('listJobs', () => {
|
|
19
|
+
it('correctly lists the job', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
process.env.ENABLE_OVERRIDE_JOB_RUNNER_URL = 'true';
|
|
21
|
+
(0, nock_1.default)('http://localhost:9999')
|
|
22
|
+
.get('/job/latest?&page[size]=5')
|
|
23
|
+
.reply(200, [{ name: 'simple-job', type: 'job', version: '1.0.0' }]);
|
|
24
|
+
const program = (0, listJobs_1.default)();
|
|
25
|
+
yield program.parseAsync([
|
|
26
|
+
'node',
|
|
27
|
+
'dxp-cli',
|
|
28
|
+
'job-runner',
|
|
29
|
+
'listJobs',
|
|
30
|
+
'-s',
|
|
31
|
+
'tiny',
|
|
32
|
+
'-t',
|
|
33
|
+
'myTenant',
|
|
34
|
+
'-ou',
|
|
35
|
+
'http://localhost:9999',
|
|
36
|
+
]);
|
|
37
|
+
const opts = program.opts();
|
|
38
|
+
expect(opts.tenant).toEqual('myTenant');
|
|
39
|
+
expect(opts.overrideUrl).toEqual('http://localhost:9999');
|
|
40
|
+
expect(opts.size).toEqual('tiny');
|
|
41
|
+
}));
|
|
42
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const commander_1 = require("commander");
|
|
16
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
17
|
+
const ora_1 = __importDefault(require("ora"));
|
|
18
|
+
const ApiService_1 = require("../../../ApiService");
|
|
19
|
+
const component_cli_lib_1 = require("@squiz/component-cli-lib");
|
|
20
|
+
const utils_1 = require("../../utils");
|
|
21
|
+
const createUploadJobCommand = () => {
|
|
22
|
+
const uploadJobCommand = new commander_1.Command('uploadJob')
|
|
23
|
+
.name('uploadJob')
|
|
24
|
+
.description('Upload a new job to the job-runner')
|
|
25
|
+
.addOption(new commander_1.Option('-t, --tenant <string>', 'Tenant ID to deploy to. If not provided will use configured tenant from login'))
|
|
26
|
+
.addArgument(new commander_1.Argument('<inputSource>', 'Path to the folder containing the job code .js files and the manifest.json file'))
|
|
27
|
+
.configureOutput({
|
|
28
|
+
outputError(str, write) {
|
|
29
|
+
write(chalk_1.default.red(str));
|
|
30
|
+
},
|
|
31
|
+
})
|
|
32
|
+
.action((inputSource, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
+
yield (0, utils_1.throwErrorIfNotLoggedIn)(uploadJobCommand);
|
|
34
|
+
const spinner = (0, ora_1.default)('Uploading job ').start();
|
|
35
|
+
try {
|
|
36
|
+
const apiService = new ApiService_1.ApiService(utils_1.validateAxiosStatus, yield (0, utils_1.buildJobRunnerUrl)(options.tenant, options.overrideUrl));
|
|
37
|
+
yield (0, component_cli_lib_1.uploadJobFolder)(apiService.client, inputSource);
|
|
38
|
+
spinner.succeed();
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
console.log(error);
|
|
43
|
+
spinner.fail();
|
|
44
|
+
(0, utils_1.handleCommandError)(uploadJobCommand, error);
|
|
45
|
+
}
|
|
46
|
+
}));
|
|
47
|
+
if (process.env.ENABLE_OVERRIDE_JOB_RUNNER_URL === 'true') {
|
|
48
|
+
uploadJobCommand.addOption(new commander_1.Option('-ou, --overrideUrl <string>', 'Developer option to override the entire job runner url with a custom value'));
|
|
49
|
+
}
|
|
50
|
+
return uploadJobCommand;
|
|
51
|
+
};
|
|
52
|
+
exports.default = createUploadJobCommand;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const uploadJob_1 = __importDefault(require("./uploadJob"));
|
|
16
|
+
const logSpy = jest.spyOn(global.console, 'log');
|
|
17
|
+
describe('upload job', () => {
|
|
18
|
+
it('correctly displays the console logs for uploading the job', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
process.env.ENABLE_OVERRIDE_JOB_RUNNER_URL = 'true';
|
|
20
|
+
const program = (0, uploadJob_1.default)();
|
|
21
|
+
yield program.parseAsync([
|
|
22
|
+
'node',
|
|
23
|
+
'dxp-cli',
|
|
24
|
+
'./src/__tests__/job-runner/simple-job',
|
|
25
|
+
'-t',
|
|
26
|
+
'myTenant',
|
|
27
|
+
'-ou',
|
|
28
|
+
'http://localhost:9999',
|
|
29
|
+
]);
|
|
30
|
+
const opts = program.opts();
|
|
31
|
+
const args = program.args;
|
|
32
|
+
expect(args[0]).toEqual('./src/__tests__/job-runner/simple-job');
|
|
33
|
+
expect(opts.tenant).toEqual('myTenant');
|
|
34
|
+
expect(opts.overrideUrl).toEqual('http://localhost:9999');
|
|
35
|
+
expect(logSpy).toHaveBeenCalledTimes(4);
|
|
36
|
+
expect(logSpy).toHaveBeenCalledWith('Initial scanning');
|
|
37
|
+
expect(logSpy).toHaveBeenCalledWith('deployment id: test-12345 status: transferring');
|
|
38
|
+
expect(logSpy).toHaveBeenCalledWith('deployment id: test-12345 status: deploying job folder');
|
|
39
|
+
expect(logSpy).toHaveBeenCalledWith('deployment id: test-12345 status: success');
|
|
40
|
+
}));
|
|
41
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const commander_1 = require("commander");
|
|
16
|
+
const ora_1 = __importDefault(require("ora"));
|
|
17
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
18
|
+
const ApiService_1 = require("../../ApiService");
|
|
19
|
+
const utils_1 = require("../utils");
|
|
20
|
+
const createListJobContextsCommand = () => {
|
|
21
|
+
const listJobContextsCommand = new commander_1.Command('listJobContexts')
|
|
22
|
+
.name('listJobContexts')
|
|
23
|
+
.description('List all job contexts')
|
|
24
|
+
.addOption(new commander_1.Option('-s, --size <string>', 'Pagination page size. Choices are tiny (5), small (20), medium (50), large (100). If not included, will default to small').choices(['tiny', 'small', 'medium', 'large']))
|
|
25
|
+
.addOption(new commander_1.Option('-b, --before <string>', 'Pagination page before token'))
|
|
26
|
+
.addOption(new commander_1.Option('-a, --after <string>', 'Pagination page after token'))
|
|
27
|
+
.addOption(new commander_1.Option('-t, --tenant <string>', 'Tenant ID to run against. If not provided will use configured tenant from login'))
|
|
28
|
+
.configureOutput({
|
|
29
|
+
outputError(str, write) {
|
|
30
|
+
write(chalk_1.default.red(str));
|
|
31
|
+
},
|
|
32
|
+
})
|
|
33
|
+
.action((options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
yield (0, utils_1.throwErrorIfNotLoggedIn)(listJobContextsCommand);
|
|
35
|
+
const spinner = (0, ora_1.default)('Retrieving job contexts\r\n').start();
|
|
36
|
+
try {
|
|
37
|
+
const apiService = new ApiService_1.ApiService(utils_1.validateAxiosStatus);
|
|
38
|
+
let listJobContextsUrl = `${yield (0, utils_1.buildJobRunnerUrl)(options.tenant, options.overrideUrl)}/job-context?`;
|
|
39
|
+
listJobContextsUrl = (0, utils_1.addPaginationToUrl)(listJobContextsUrl, {
|
|
40
|
+
before: options.before,
|
|
41
|
+
after: options.after,
|
|
42
|
+
size: options.size,
|
|
43
|
+
});
|
|
44
|
+
const res = yield apiService.client.get(listJobContextsUrl);
|
|
45
|
+
if (Array.isArray(res.data) && res.data.length > 0) {
|
|
46
|
+
spinner.succeed(`${res.data.length} contexts successfully retrieved`);
|
|
47
|
+
(0, utils_1.writeLineSeparator)();
|
|
48
|
+
res.data.forEach((context) => {
|
|
49
|
+
console.log(`${chalk_1.default.green(chalk_1.default.bold(context.contextName))}: ${chalk_1.default.green(context.description)}`);
|
|
50
|
+
for (const [key, value] of Object.entries(context.environment)) {
|
|
51
|
+
console.log(`${chalk_1.default.bold(key)}: ${JSON.stringify(value)}`);
|
|
52
|
+
}
|
|
53
|
+
(0, utils_1.writeLineSeparator)();
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
spinner.succeed('No job contexts found');
|
|
58
|
+
}
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
spinner.fail();
|
|
63
|
+
(0, utils_1.handleCommandError)(listJobContextsCommand, error);
|
|
64
|
+
}
|
|
65
|
+
}));
|
|
66
|
+
if (process.env.ENABLE_OVERRIDE_JOB_RUNNER_URL === 'true') {
|
|
67
|
+
listJobContextsCommand.addOption(new commander_1.Option('-ou, --overrideUrl <string>', 'Developer option to override the entire job runner url with a custom value'));
|
|
68
|
+
}
|
|
69
|
+
return listJobContextsCommand;
|
|
70
|
+
};
|
|
71
|
+
exports.default = createListJobContextsCommand;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const nock_1 = __importDefault(require("nock"));
|
|
16
|
+
const listJobContexts_1 = __importDefault(require("./listJobContexts"));
|
|
17
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
18
|
+
const logSpy = jest.spyOn(global.console, 'log');
|
|
19
|
+
describe('listJobContexts', () => {
|
|
20
|
+
process.env.ENABLE_OVERRIDE_JOB_RUNNER_URL = 'true';
|
|
21
|
+
it('correctly lists the job contexts', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
+
(0, nock_1.default)('http://localhost:9999')
|
|
23
|
+
.get('/job-context?')
|
|
24
|
+
.reply(200, [
|
|
25
|
+
{
|
|
26
|
+
contextName: 'dev',
|
|
27
|
+
type: 'context',
|
|
28
|
+
description: 'dev context',
|
|
29
|
+
environment: {
|
|
30
|
+
baz: '12345',
|
|
31
|
+
foo: 'bar',
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
contextName: 'stage',
|
|
36
|
+
type: 'context',
|
|
37
|
+
description: 'staging context',
|
|
38
|
+
environment: {
|
|
39
|
+
something: 'cool',
|
|
40
|
+
somethingElse: 'cooler',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
]);
|
|
44
|
+
const program = (0, listJobContexts_1.default)();
|
|
45
|
+
yield program.parseAsync([
|
|
46
|
+
'node',
|
|
47
|
+
'dxp-cli',
|
|
48
|
+
'job-runner',
|
|
49
|
+
'listJobContexts',
|
|
50
|
+
'-t',
|
|
51
|
+
'myTenant',
|
|
52
|
+
'-ou',
|
|
53
|
+
'http://localhost:9999',
|
|
54
|
+
]);
|
|
55
|
+
const opts = program.opts();
|
|
56
|
+
expect(opts.tenant).toEqual('myTenant');
|
|
57
|
+
expect(opts.overrideUrl).toEqual('http://localhost:9999');
|
|
58
|
+
expect(logSpy).toHaveBeenCalledTimes(9);
|
|
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')}: ${JSON.stringify('cool')}`);
|
|
61
|
+
expect(logSpy).toHaveBeenCalledWith(`${chalk_1.default.bold('somethingElse')}: ${JSON.stringify('cooler')}`);
|
|
62
|
+
expect(logSpy).toHaveBeenCalledWith(chalk_1.default.cyan('------------------------------'));
|
|
63
|
+
}));
|
|
64
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const commander_1 = require("commander");
|
|
16
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
17
|
+
const ora_1 = __importDefault(require("ora"));
|
|
18
|
+
const ApiService_1 = require("../../../ApiService");
|
|
19
|
+
const utils_1 = require("../../utils");
|
|
20
|
+
const createBeginJobCommand = () => {
|
|
21
|
+
const beginJobCommand = new commander_1.Command('beginJob')
|
|
22
|
+
.name('beginJob')
|
|
23
|
+
.description('Add a job to the queue')
|
|
24
|
+
.addOption(new commander_1.Option('-t, --tenant <string>', 'Tenant ID to run against. 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'))
|
|
26
|
+
.addArgument(new commander_1.Argument('<jobName>', 'Name of the job to pass to the request'))
|
|
27
|
+
.addArgument(new commander_1.Argument('<contextName>', 'Name of the job context to pass to the request'))
|
|
28
|
+
.configureOutput({
|
|
29
|
+
outputError(str, write) {
|
|
30
|
+
write(chalk_1.default.red(str));
|
|
31
|
+
},
|
|
32
|
+
})
|
|
33
|
+
.action((jobName, contextName, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
yield (0, utils_1.throwErrorIfNotLoggedIn)(beginJobCommand);
|
|
35
|
+
const spinner = (0, ora_1.default)('Queueing job').start();
|
|
36
|
+
console.log('');
|
|
37
|
+
let input;
|
|
38
|
+
try {
|
|
39
|
+
if (options.inputFile) {
|
|
40
|
+
input = yield (0, utils_1.readInputFile)(options.inputFile);
|
|
41
|
+
}
|
|
42
|
+
const apiService = new ApiService_1.ApiService(utils_1.validateAxiosStatus);
|
|
43
|
+
const beginJobUrl = `${yield (0, utils_1.buildJobRunnerUrl)(options.tenant, options.overrideUrl)}/executions/begin`;
|
|
44
|
+
const res = yield apiService.client.post(beginJobUrl, {
|
|
45
|
+
jobName: jobName,
|
|
46
|
+
context: contextName,
|
|
47
|
+
input: input ? input : null,
|
|
48
|
+
});
|
|
49
|
+
spinner.succeed('Job queued successfully');
|
|
50
|
+
(0, utils_1.writeLineSeparator)();
|
|
51
|
+
for (const [key, value] of Object.entries(res.data)) {
|
|
52
|
+
console.log(`${chalk_1.default.bold([key])}: ${JSON.stringify(value)}`);
|
|
53
|
+
}
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
spinner.fail();
|
|
58
|
+
(0, utils_1.handleCommandError)(beginJobCommand, error);
|
|
59
|
+
}
|
|
60
|
+
}));
|
|
61
|
+
if (process.env.ENABLE_OVERRIDE_JOB_RUNNER_URL === 'true') {
|
|
62
|
+
beginJobCommand.addOption(new commander_1.Option('-ou, --overrideUrl <string>', 'Developer option to override the entire job runner url with a custom value'));
|
|
63
|
+
}
|
|
64
|
+
return beginJobCommand;
|
|
65
|
+
};
|
|
66
|
+
exports.default = createBeginJobCommand;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|