@squiz/dxp-cli-next 5.14.0 → 5.15.0-develop.1

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.
Files changed (57) hide show
  1. package/README.md +1 -0
  2. package/lib/__tests__/integration/main.spec.js +3 -2
  3. package/lib/cdp/index.js +3 -1
  4. package/lib/cmp/deploy.js +49 -2
  5. package/lib/cmp/edge-components/compiler.d.ts +13 -0
  6. package/lib/cmp/edge-components/compiler.js +55 -0
  7. package/lib/cmp/utils/definitions.d.ts +12 -0
  8. package/lib/cmp/utils/definitions.js +76 -0
  9. package/lib/datastore/index.js +1 -1
  10. package/lib/dxp.js +2 -0
  11. package/lib/porter/constants.d.ts +6 -0
  12. package/lib/porter/constants.js +9 -0
  13. package/lib/porter/index.d.ts +3 -0
  14. package/lib/porter/index.js +12 -0
  15. package/lib/porter/project/add/add.d.ts +3 -0
  16. package/lib/porter/project/add/add.js +125 -0
  17. package/lib/porter/project/add/add.spec.d.ts +1 -0
  18. package/lib/porter/project/add/add.spec.js +323 -0
  19. package/lib/porter/project/get/get.d.ts +3 -0
  20. package/lib/porter/project/get/get.js +67 -0
  21. package/lib/porter/project/get/get.spec.d.ts +1 -0
  22. package/lib/porter/project/get/get.spec.js +221 -0
  23. package/lib/porter/project/projectCommand.d.ts +3 -0
  24. package/lib/porter/project/projectCommand.js +19 -0
  25. package/lib/porter/project/remove/remove.d.ts +3 -0
  26. package/lib/porter/project/remove/remove.js +71 -0
  27. package/lib/porter/project/remove/remove.spec.d.ts +1 -0
  28. package/lib/porter/project/remove/remove.spec.js +236 -0
  29. package/lib/porter/types.d.ts +5 -0
  30. package/lib/porter/types.js +2 -0
  31. package/lib/porter/utils/AuthUtils/CheckAuthorisation.d.ts +1 -0
  32. package/lib/porter/utils/AuthUtils/CheckAuthorisation.js +32 -0
  33. package/lib/porter/utils/AuthUtils/CheckAuthorisation.spec.d.ts +1 -0
  34. package/lib/porter/utils/AuthUtils/CheckAuthorisation.spec.js +77 -0
  35. package/lib/porter/utils/BuildPorterUrl/BuildPorterUrl.d.ts +1 -0
  36. package/lib/porter/utils/BuildPorterUrl/BuildPorterUrl.js +27 -0
  37. package/lib/porter/utils/BuildPorterUrl/BuildPorterUrl.spec.d.ts +1 -0
  38. package/lib/porter/utils/BuildPorterUrl/BuildPorterUrl.spec.js +59 -0
  39. package/lib/porter/utils/CoreUtils/CoreUtils.d.ts +2 -0
  40. package/lib/porter/utils/CoreUtils/CoreUtils.js +13 -0
  41. package/lib/porter/utils/CoreUtils/CoreUtils.spec.d.ts +1 -0
  42. package/lib/porter/utils/CoreUtils/CoreUtils.spec.js +36 -0
  43. package/lib/porter/utils/DoesPathExist/DoesPathExist.d.ts +1 -0
  44. package/lib/porter/utils/DoesPathExist/DoesPathExist.js +27 -0
  45. package/lib/porter/utils/DoesPathExist/DoesPathExist.spec.d.ts +1 -0
  46. package/lib/porter/utils/DoesPathExist/DoesPathExist.spec.js +40 -0
  47. package/lib/porter/utils/ErrorUtils/ErrorUtils.d.ts +4 -0
  48. package/lib/porter/utils/ErrorUtils/ErrorUtils.js +68 -0
  49. package/lib/porter/utils/ErrorUtils/ErrorUtils.spec.d.ts +1 -0
  50. package/lib/porter/utils/ErrorUtils/ErrorUtils.spec.js +175 -0
  51. package/lib/porter/utils/GetProjectConfig/GetProjectConfig.d.ts +2 -0
  52. package/lib/porter/utils/GetProjectConfig/GetProjectConfig.js +32 -0
  53. package/lib/porter/utils/GetProjectConfig/GetProjectConfig.spec.d.ts +1 -0
  54. package/lib/porter/utils/GetProjectConfig/GetProjectConfig.spec.js +49 -0
  55. package/lib/porter/utils/index.d.ts +6 -0
  56. package/lib/porter/utils/index.js +22 -0
  57. package/package.json +6 -3
@@ -0,0 +1,40 @@
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 promises_1 = __importDefault(require("fs/promises"));
16
+ const DoesPathExist_1 = require("./DoesPathExist");
17
+ jest.mock('fs/promises', () => {
18
+ return {
19
+ readdir: jest.fn(),
20
+ };
21
+ });
22
+ describe('doesPathExist', () => {
23
+ const projectPath = 'project-path';
24
+ it('should return false if path does not exist', () => __awaiter(void 0, void 0, void 0, function* () {
25
+ jest.spyOn(promises_1.default, 'readdir').mockImplementationOnce(() => {
26
+ throw new Error();
27
+ });
28
+ const pathExists = yield (0, DoesPathExist_1.doesPathExist)(projectPath);
29
+ expect(pathExists).toBe(false);
30
+ expect(promises_1.default.readdir).toHaveBeenCalled();
31
+ }));
32
+ it('should return true if path exists', () => __awaiter(void 0, void 0, void 0, function* () {
33
+ jest
34
+ .spyOn(promises_1.default, 'readdir')
35
+ .mockImplementationOnce(() => Promise.resolve([]));
36
+ const pathExists = yield (0, DoesPathExist_1.doesPathExist)(projectPath);
37
+ expect(pathExists).toBe(true);
38
+ expect(promises_1.default.readdir).toHaveBeenCalled();
39
+ }));
40
+ });
@@ -0,0 +1,4 @@
1
+ import { Command } from 'commander';
2
+ export declare function handleCommandError(command: Command, error: Error): undefined;
3
+ export declare function handleError(command: Command, errorMessage: string): void;
4
+ export declare function throwErrorIfNotLoggedIn(command: Command): Promise<undefined>;
@@ -0,0 +1,68 @@
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
+ exports.throwErrorIfNotLoggedIn = exports.handleError = exports.handleCommandError = void 0;
16
+ const axios_1 = __importDefault(require("axios"));
17
+ const chalk_1 = __importDefault(require("chalk"));
18
+ const ApplicationStore_1 = require("../../../ApplicationStore");
19
+ const CheckAuthorisation_1 = require("../AuthUtils/CheckAuthorisation");
20
+ function handleCommandError(command, error) {
21
+ if (!axios_1.default.isAxiosError(error)) {
22
+ if (!!process.env.DEBUG && error.stack) {
23
+ return command.error(error.stack);
24
+ }
25
+ if (error.message) {
26
+ return command.error(chalk_1.default.red(error.message));
27
+ }
28
+ return command.error(chalk_1.default.red('An unknown error occurred'));
29
+ }
30
+ if (!error.response) {
31
+ return command.error(chalk_1.default.red(error.message));
32
+ }
33
+ if (error.response.status === 401 || error.response.status === 403) {
34
+ const errorMessage = 'You must be logged in as a DXP super admin or Squiz support staff to use this service';
35
+ return command.error(chalk_1.default.red(errorMessage));
36
+ }
37
+ if (error.response.status >= 500) {
38
+ const errorMessage = `Action failed. Service responded with "${error.response.status}" response code`;
39
+ return command.error(chalk_1.default.red(errorMessage));
40
+ }
41
+ if (error.response.data) {
42
+ let errorMessage;
43
+ if (error.response.data['invalid-params']) {
44
+ errorMessage = JSON.stringify(error.response.data['invalid-params']);
45
+ }
46
+ else {
47
+ errorMessage = error.response.data.title;
48
+ }
49
+ return command.error(chalk_1.default.red(errorMessage));
50
+ }
51
+ }
52
+ exports.handleCommandError = handleCommandError;
53
+ function handleError(command, errorMessage) {
54
+ command.error(chalk_1.default.red(errorMessage));
55
+ }
56
+ exports.handleError = handleError;
57
+ function throwErrorIfNotLoggedIn(command) {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ if (!(yield (0, ApplicationStore_1.getApplicationFile)(ApplicationStore_1.STORE_FILES.sessionCookie))) {
60
+ return command.error(chalk_1.default.red('You must login to interact with the porter service. See `dxp-next auth login`'));
61
+ }
62
+ const isAuthorised = yield (0, CheckAuthorisation_1.checkAuthorisation)();
63
+ if (!isAuthorised) {
64
+ command.error(chalk_1.default.red('You must login to interact with the porter service. See `dxp-next auth login`'));
65
+ }
66
+ });
67
+ }
68
+ exports.throwErrorIfNotLoggedIn = throwErrorIfNotLoggedIn;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,175 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ const axios_1 = require("axios");
36
+ const commander_1 = require("commander");
37
+ const GetApplicationFile = __importStar(require("../../../ApplicationStore"));
38
+ const CheckAuthorisation = __importStar(require("../AuthUtils/CheckAuthorisation"));
39
+ const ErrorUtils_1 = require("./ErrorUtils");
40
+ describe('handleCommandError', () => {
41
+ let stderrSpy;
42
+ beforeEach(() => {
43
+ jest.resetAllMocks();
44
+ stderrSpy = jest.spyOn(process.stderr, 'write');
45
+ jest.spyOn(process, 'exit').mockImplementation();
46
+ });
47
+ it('correctly displays the console logs for command error', () => __awaiter(void 0, void 0, void 0, function* () {
48
+ process.env.DEBUG = 'true';
49
+ const command = new commander_1.Command();
50
+ const message = 'Something bad happened';
51
+ (0, ErrorUtils_1.handleCommandError)(command, new Error(message));
52
+ expect(stderrSpy).toHaveBeenCalledTimes(1);
53
+ // read the mock call strings directly otherwise colours cause test failures with .toEqual()
54
+ expect(stderrSpy.mock.calls[0][0]).toContain(message);
55
+ }));
56
+ it('correctly displays the console logs for command error', () => __awaiter(void 0, void 0, void 0, function* () {
57
+ delete process.env.DEBUG;
58
+ const command = new commander_1.Command();
59
+ const message = 'Something bad happened';
60
+ (0, ErrorUtils_1.handleCommandError)(command, new Error(message));
61
+ expect(stderrSpy).toHaveBeenCalledTimes(1);
62
+ // read the mock call strings directly otherwise colours cause test failures with .toEqual()
63
+ expect(stderrSpy.mock.calls[0][0]).toContain(message);
64
+ }));
65
+ it('correctly displays the console logs for error without a message', () => __awaiter(void 0, void 0, void 0, function* () {
66
+ const command = new commander_1.Command();
67
+ (0, ErrorUtils_1.handleCommandError)(command, new Error());
68
+ expect(stderrSpy).toHaveBeenCalledTimes(1);
69
+ // read the mock call strings directly otherwise colours cause test failures with .toEqual()
70
+ expect(stderrSpy.mock.calls[0][0]).toContain('An unknown error occurred');
71
+ }));
72
+ it('correctly displays the console logs for axios error without a proper response', () => __awaiter(void 0, void 0, void 0, function* () {
73
+ const command = new commander_1.Command();
74
+ const message = 'Something bad happened';
75
+ (0, ErrorUtils_1.handleCommandError)(command, new axios_1.AxiosError(message, '500', undefined, undefined, undefined));
76
+ expect(stderrSpy).toHaveBeenCalledTimes(1);
77
+ // read the mock call strings directly otherwise colours cause test failures with .toEqual()
78
+ expect(stderrSpy.mock.calls[0][0]).toContain(message);
79
+ }));
80
+ it('correctly displays the console logs for axios 500 error from the porter service', () => __awaiter(void 0, void 0, void 0, function* () {
81
+ const command = new commander_1.Command();
82
+ const message = 'Internal server error';
83
+ (0, ErrorUtils_1.handleCommandError)(command, new axios_1.AxiosError(message, '500', undefined, undefined, {
84
+ status: 500,
85
+ }));
86
+ expect(stderrSpy).toHaveBeenCalledTimes(1);
87
+ // read the mock call strings directly otherwise colours cause test failures with .toEqual()
88
+ expect(stderrSpy.mock.calls[0][0]).toContain('Action failed. Service responded with "500" response code');
89
+ }));
90
+ it.each([401, 403])('correctly displays the console logs for axios %s error from the porter service', (status) => __awaiter(void 0, void 0, void 0, function* () {
91
+ const command = new commander_1.Command();
92
+ const message = 'Unauthorized';
93
+ (0, ErrorUtils_1.handleCommandError)(command, new axios_1.AxiosError(message, `${status}`, undefined, undefined, {
94
+ status,
95
+ }));
96
+ expect(stderrSpy).toHaveBeenCalledTimes(1);
97
+ // read the mock call strings directly otherwise colours cause test failures with .toEqual()
98
+ expect(stderrSpy.mock.calls[0][0]).toContain('You must be logged in as a DXP super admin or Squiz support staff to use this service');
99
+ }));
100
+ it('correctly displays the console logs for axios errors from the porter service', () => __awaiter(void 0, void 0, void 0, function* () {
101
+ const command = new commander_1.Command();
102
+ const errorStatus = 400;
103
+ const errorTitle = 'Bad request';
104
+ const errorResponse = {
105
+ data: {
106
+ title: errorTitle,
107
+ 'invalid-params': [
108
+ {
109
+ name: 'name',
110
+ reason: 'reason',
111
+ },
112
+ ],
113
+ },
114
+ };
115
+ (0, ErrorUtils_1.handleCommandError)(command, new axios_1.AxiosError(errorTitle, `${errorStatus}`, undefined, undefined, errorResponse));
116
+ expect(stderrSpy).toHaveBeenCalledTimes(1);
117
+ // read the mock call strings directly otherwise colours cause test failures with .toEqual()
118
+ expect(stderrSpy.mock.calls[0][0]).toContain(JSON.stringify(errorResponse.data['invalid-params']));
119
+ }));
120
+ });
121
+ describe('handleError', () => {
122
+ let stderrSpy;
123
+ beforeEach(() => {
124
+ jest.resetAllMocks();
125
+ stderrSpy = jest.spyOn(process.stderr, 'write');
126
+ });
127
+ it('correctly displays the console logs for command error', () => __awaiter(void 0, void 0, void 0, function* () {
128
+ const command = new commander_1.Command();
129
+ const message = 'Something bad happened';
130
+ (0, ErrorUtils_1.handleError)(command, message);
131
+ expect(stderrSpy).toHaveBeenCalledTimes(1);
132
+ // read the mock call strings directly otherwise colours cause test failures with .toEqual()
133
+ expect(stderrSpy.mock.calls[0][0]).toContain(message);
134
+ }));
135
+ });
136
+ describe('throwErrorIfNotLoggedIn', () => {
137
+ let stderrSpy;
138
+ let command;
139
+ beforeEach(() => {
140
+ jest.resetAllMocks();
141
+ command = new commander_1.Command();
142
+ stderrSpy = jest.spyOn(process.stderr, 'write');
143
+ jest.spyOn(process, 'exit').mockImplementation();
144
+ });
145
+ it('should call the command error if cookie cannot be retrieved', () => __awaiter(void 0, void 0, void 0, function* () {
146
+ jest
147
+ .spyOn(GetApplicationFile, 'getApplicationFile')
148
+ .mockImplementationOnce(() => Promise.resolve(undefined));
149
+ yield (0, ErrorUtils_1.throwErrorIfNotLoggedIn)(command);
150
+ expect(stderrSpy.mock.calls[0][0]).toContain('You must login to interact with the porter service. See `dxp-next auth login');
151
+ expect(process.exit).toHaveBeenCalled();
152
+ }));
153
+ it('should call the command error if unauthorised', () => __awaiter(void 0, void 0, void 0, function* () {
154
+ jest
155
+ .spyOn(GetApplicationFile, 'getApplicationFile')
156
+ .mockImplementationOnce(() => Promise.resolve('cookie'));
157
+ jest
158
+ .spyOn(CheckAuthorisation, 'checkAuthorisation')
159
+ .mockImplementationOnce(() => Promise.resolve(false));
160
+ yield (0, ErrorUtils_1.throwErrorIfNotLoggedIn)(command);
161
+ expect(stderrSpy.mock.calls[0][0]).toContain('You must login to interact with the porter service. See `dxp-next auth login');
162
+ expect(process.exit).toHaveBeenCalled();
163
+ }));
164
+ it('should not call the command error if logged in', () => __awaiter(void 0, void 0, void 0, function* () {
165
+ jest
166
+ .spyOn(GetApplicationFile, 'getApplicationFile')
167
+ .mockImplementationOnce(() => Promise.resolve('cookie'));
168
+ jest
169
+ .spyOn(CheckAuthorisation, 'checkAuthorisation')
170
+ .mockImplementationOnce(() => Promise.resolve(true));
171
+ yield (0, ErrorUtils_1.throwErrorIfNotLoggedIn)(command);
172
+ expect(stderrSpy).not.toHaveBeenCalled();
173
+ expect(process.exit).not.toHaveBeenCalled();
174
+ }));
175
+ });
@@ -0,0 +1,2 @@
1
+ import { ProjectConfig } from '../../types';
2
+ export declare function getProjectConfig(): Promise<ProjectConfig>;
@@ -0,0 +1,32 @@
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
+ exports.getProjectConfig = void 0;
16
+ const path_1 = __importDefault(require("path"));
17
+ const promises_1 = __importDefault(require("fs/promises"));
18
+ const CoreUtils_1 = require("../CoreUtils/CoreUtils");
19
+ function getProjectConfig() {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ try {
22
+ const configFile = path_1.default.resolve('config.json');
23
+ const config = yield promises_1.default.readFile(configFile, { encoding: 'utf-8' });
24
+ return JSON.parse(config);
25
+ }
26
+ catch (err) {
27
+ (0, CoreUtils_1.logDebug)(err);
28
+ throw new Error('You must be within a porter project directory to use this command');
29
+ }
30
+ });
31
+ }
32
+ exports.getProjectConfig = getProjectConfig;
@@ -0,0 +1,49 @@
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 GetProjectConfig_1 = require("./GetProjectConfig");
16
+ const promises_1 = __importDefault(require("fs/promises"));
17
+ jest.mock('fs/promises', () => {
18
+ return {
19
+ readFile: jest.fn(),
20
+ };
21
+ });
22
+ describe('getProjectConfig', () => {
23
+ it('should throw an error if cannot config file does not exist', () => __awaiter(void 0, void 0, void 0, function* () {
24
+ jest.spyOn(promises_1.default, 'readFile').mockImplementationOnce(() => {
25
+ throw new Error('ENOENT');
26
+ });
27
+ yield expect((0, GetProjectConfig_1.getProjectConfig)()).rejects.toThrowError('You must be within a porter project directory to use this command');
28
+ expect(promises_1.default.readFile).toHaveBeenCalled();
29
+ }));
30
+ it('should throw an error if cannot parse config file', () => __awaiter(void 0, void 0, void 0, function* () {
31
+ jest
32
+ .spyOn(promises_1.default, 'readFile')
33
+ .mockImplementationOnce(() => Promise.resolve('invalid-json'));
34
+ yield expect((0, GetProjectConfig_1.getProjectConfig)()).rejects.toThrowError('You must be within a porter project directory to use this command');
35
+ expect(promises_1.default.readFile).toHaveBeenCalled();
36
+ }));
37
+ it('should return the project config json', () => __awaiter(void 0, void 0, void 0, function* () {
38
+ const projectConfig = {
39
+ service: 'dxp-porter',
40
+ projectName: 'name',
41
+ version: '0.1.0',
42
+ };
43
+ jest
44
+ .spyOn(promises_1.default, 'readFile')
45
+ .mockImplementationOnce(() => Promise.resolve(JSON.stringify(projectConfig)));
46
+ const parsedConfig = yield (0, GetProjectConfig_1.getProjectConfig)();
47
+ expect(parsedConfig).toStrictEqual(projectConfig);
48
+ }));
49
+ });
@@ -0,0 +1,6 @@
1
+ export * from './AuthUtils/CheckAuthorisation';
2
+ export * from './BuildPorterUrl/BuildPorterUrl';
3
+ export * from './CoreUtils/CoreUtils';
4
+ export * from './DoesPathExist/DoesPathExist';
5
+ export * from './ErrorUtils/ErrorUtils';
6
+ export * from './GetProjectConfig/GetProjectConfig';
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./AuthUtils/CheckAuthorisation"), exports);
18
+ __exportStar(require("./BuildPorterUrl/BuildPorterUrl"), exports);
19
+ __exportStar(require("./CoreUtils/CoreUtils"), exports);
20
+ __exportStar(require("./DoesPathExist/DoesPathExist"), exports);
21
+ __exportStar(require("./ErrorUtils/ErrorUtils"), exports);
22
+ __exportStar(require("./GetProjectConfig/GetProjectConfig"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squiz/dxp-cli-next",
3
- "version": "5.14.0",
3
+ "version": "5.15.0-develop.1",
4
4
  "repository": {
5
5
  "url": "https://gitlab.squiz.net/dxp/dxp-cli-next"
6
6
  },
@@ -41,18 +41,21 @@
41
41
  "dependencies": {
42
42
  "@apidevtools/swagger-parser": "10.1.0",
43
43
  "@squiz/component-cli-lib": "1.65.1",
44
+ "@squiz/dxp-porter-shared": "0.2.7",
44
45
  "axios": "1.1.3",
45
46
  "cli-color": "2.0.3",
46
47
  "commander": "9.4.0",
47
48
  "dotenv": "^16.3.1",
48
49
  "env-paths": "2.2.1",
50
+ "esbuild": "^0.21.4",
49
51
  "inquirer": "8.2.5",
50
52
  "opener": "1.5.2",
51
53
  "ora": "^5.4.1",
52
54
  "prompt": "^1.3.0",
53
55
  "tough-cookie": "4.1.2",
54
56
  "update-notifier": "5.1.0",
55
- "yaml": "^2.3.4"
57
+ "yaml": "^2.3.4",
58
+ "zod": "^3.23.8"
56
59
  },
57
60
  "devDependencies": {
58
61
  "@semantic-release/git": "10.0.1",
@@ -84,7 +87,7 @@
84
87
  "prettier": "2.7.1",
85
88
  "semantic-release": "19.0.3",
86
89
  "ts-jest": "28.0.7",
87
- "ts-node": "10.9.1",
90
+ "ts-node": "^10.9.1",
88
91
  "typescript": "4.7.4"
89
92
  },
90
93
  "config": {