@squiz/dxp-cli-next 5.6.0-develop.2 → 5.6.0-develop.3

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 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
- .action((destination, { type: componentType, install }) => __awaiter(void 0, void 0, void 0, function* () {
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)({ componentType, destination });
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
+ }
@@ -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,7 +40,8 @@ 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
- id: executionId,
43
+ executionId: executionId,
44
+ reason: reason,
43
45
  });
44
46
  for (const [key, value] of Object.entries(res.data)) {
45
47
  console.log(`${chalk_1.default.bold([key])}: ${value}`);
@@ -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',
@@ -18,9 +18,16 @@ const ApplicationConfig_1 = require("../ApplicationConfig");
18
18
  const axios_1 = __importDefault(require("axios"));
19
19
  const ApplicationStore_1 = require("../ApplicationStore");
20
20
  function handleCommandError(command, error) {
21
- var _a, _b;
21
+ var _a, _b, _c, _d;
22
22
  if (axios_1.default.isAxiosError(error)) {
23
- command.error(chalk_1.default.red(`${error.message}: ${(_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.message}`));
23
+ let message = `${error.message}`;
24
+ if ((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.message) {
25
+ message += `: ${error.response.data.message}`;
26
+ }
27
+ if ((_d = (_c = error.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.details) {
28
+ message += ` - ${error.response.data.details}`;
29
+ }
30
+ command.error(chalk_1.default.red(message));
24
31
  }
25
32
  else {
26
33
  if (!!process.env.DEBUG && error.stack) {
@@ -38,12 +38,13 @@ describe('handleCommandError', () => {
38
38
  const command = new commander_1.Command();
39
39
  const message = 'Something bad happened';
40
40
  const responseMessage = 'I am an error response';
41
+ const errDetails = 'i am error details';
41
42
  (0, utils_1.handleCommandError)(command, new axios_1.AxiosError(message, '500', undefined, undefined, {
42
- data: { message: responseMessage },
43
+ data: { message: responseMessage, details: errDetails },
43
44
  }));
44
45
  expect(stderrSpy).toHaveBeenCalledTimes(1);
45
46
  // read the mock call strings directly otherwise colours cause test failures with .toEqual()
46
- expect(stderrSpy.mock.calls[0][0]).toContain(`${message}: ${responseMessage}`);
47
+ expect(stderrSpy.mock.calls[0][0]).toContain(`${message}: ${responseMessage} - ${errDetails}`);
47
48
  }));
48
49
  it('correctly displays the console logs for error without a message', () => __awaiter(void 0, void 0, void 0, function* () {
49
50
  const command = new commander_1.Command();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squiz/dxp-cli-next",
3
- "version": "5.6.0-develop.2",
3
+ "version": "5.6.0-develop.3",
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.39.1-alpha.7",
42
+ "@squiz/component-cli-lib": "^1.39.1-alpha.24",
43
43
  "axios": "1.1.3",
44
44
  "cli-color": "2.0.3",
45
45
  "commander": "9.4.0",