@squiz/dxp-cli-next 5.15.0-develop.1 → 5.15.0-develop.2
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/porter/constants.d.ts +2 -0
- package/lib/porter/constants.js +2 -0
- package/lib/porter/index.js +3 -1
- package/lib/porter/port/abort/abort.d.ts +3 -0
- package/lib/porter/port/abort/abort.js +77 -0
- package/lib/porter/port/abort/abort.spec.d.ts +1 -0
- package/lib/porter/port/abort/abort.spec.js +182 -0
- package/lib/porter/port/get/get.d.ts +3 -0
- package/lib/porter/port/get/get.js +94 -0
- package/lib/porter/port/get/get.spec.d.ts +1 -0
- package/lib/porter/port/get/get.spec.js +255 -0
- package/lib/porter/port/portCommand.d.ts +3 -0
- package/lib/porter/port/portCommand.js +19 -0
- package/lib/porter/port/start/start.d.ts +3 -0
- package/lib/porter/port/start/start.js +79 -0
- package/lib/porter/port/start/start.spec.d.ts +1 -0
- package/lib/porter/port/start/start.spec.js +198 -0
- package/lib/porter/project/add/add.spec.js +39 -92
- package/lib/porter/project/get/get.js +4 -9
- package/lib/porter/project/get/get.spec.js +47 -83
- package/lib/porter/project/remove/remove.js +1 -6
- package/lib/porter/project/remove/remove.spec.js +42 -77
- package/lib/porter/utils/ErrorUtils/ErrorUtils.js +4 -1
- package/lib/porter/utils/ErrorUtils/ErrorUtils.spec.js +17 -2
- package/lib/porter/utils/GetProjectConfig/GetProjectConfig.js +2 -1
- package/lib/porter/utils/GetProjectConfig/GetProjectConfig.spec.js +4 -3
- package/lib/porter/utils/GetProjectName/GetProjectName.d.ts +4 -0
- package/lib/porter/utils/GetProjectName/GetProjectName.js +30 -0
- package/lib/porter/utils/GetProjectName/GetProjectName.spec.d.ts +1 -0
- package/lib/porter/utils/GetProjectName/GetProjectName.spec.js +91 -0
- package/lib/porter/utils/index.d.ts +1 -0
- package/lib/porter/utils/index.js +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,19 @@
|
|
|
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 abort_1 = __importDefault(require("./abort/abort"));
|
|
8
|
+
const get_1 = __importDefault(require("./get/get"));
|
|
9
|
+
const start_1 = __importDefault(require("./start/start"));
|
|
10
|
+
const createPortCommand = () => {
|
|
11
|
+
const portCommand = new commander_1.Command('port');
|
|
12
|
+
portCommand
|
|
13
|
+
.description('Porter port commands')
|
|
14
|
+
.addCommand((0, start_1.default)())
|
|
15
|
+
.addCommand((0, get_1.default)())
|
|
16
|
+
.addCommand((0, abort_1.default)());
|
|
17
|
+
return portCommand;
|
|
18
|
+
};
|
|
19
|
+
exports.default = createPortCommand;
|
|
@@ -0,0 +1,79 @@
|
|
|
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 promises_1 = __importDefault(require("fs/promises"));
|
|
18
|
+
const path_1 = __importDefault(require("path"));
|
|
19
|
+
const ora_1 = __importDefault(require("ora"));
|
|
20
|
+
const ApiService_1 = require("../../../ApiService");
|
|
21
|
+
const utils_1 = require("../../utils");
|
|
22
|
+
const createStartPortCommand = () => {
|
|
23
|
+
const getCommand = new commander_1.Command('startPort')
|
|
24
|
+
.description('Start porting a website using the local project configuration')
|
|
25
|
+
.configureOutput({
|
|
26
|
+
outputError(str, write) {
|
|
27
|
+
write(chalk_1.default.red(str));
|
|
28
|
+
},
|
|
29
|
+
})
|
|
30
|
+
.action((options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
|
+
yield (0, utils_1.throwErrorIfNotLoggedIn)(getCommand);
|
|
32
|
+
const baseUrl = yield (0, utils_1.buildPorterUrl)();
|
|
33
|
+
let projectName = '';
|
|
34
|
+
const spinner = (0, ora_1.default)();
|
|
35
|
+
try {
|
|
36
|
+
projectName = yield (0, utils_1.getProjectName)();
|
|
37
|
+
spinner.start('Starting port..');
|
|
38
|
+
const apiService = new ApiService_1.ApiService(utils_1.validateAxiosStatus, baseUrl);
|
|
39
|
+
// Read the stage directories for project configuration
|
|
40
|
+
const stageConfigDir = path_1.default.resolve('stage-configs');
|
|
41
|
+
const stageDirs = yield promises_1.default.readdir(stageConfigDir);
|
|
42
|
+
// Currently, skip component-transform and design-dedupe
|
|
43
|
+
const portSettings = {
|
|
44
|
+
'component-transform': { run: false },
|
|
45
|
+
'design-dedupe': { run: false },
|
|
46
|
+
};
|
|
47
|
+
// Read the config files for each stage, and construct the overall port settings
|
|
48
|
+
yield Promise.all(stageDirs.map((stage) => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
+
const stageConfigFile = path_1.default.resolve(stageConfigDir, stage, 'config.json');
|
|
50
|
+
const stageConfig = yield promises_1.default.readFile(stageConfigFile, {
|
|
51
|
+
encoding: 'utf-8',
|
|
52
|
+
});
|
|
53
|
+
const config = JSON.parse(stageConfig);
|
|
54
|
+
const updatedConfig = Object.assign(Object.assign({}, portSettings[stage]), config);
|
|
55
|
+
portSettings[stage] = updatedConfig;
|
|
56
|
+
})));
|
|
57
|
+
(0, utils_1.logDebug)(`Port settings to use: ${JSON.stringify(portSettings)}`);
|
|
58
|
+
const portRequest = {
|
|
59
|
+
['stage-settings']: portSettings,
|
|
60
|
+
};
|
|
61
|
+
const response = yield apiService.client.post(`/projects/${projectName}/ports`, portRequest);
|
|
62
|
+
const jsonResponse = response.data;
|
|
63
|
+
(0, utils_1.logDebug)(JSON.stringify(jsonResponse));
|
|
64
|
+
const { portid } = jsonResponse;
|
|
65
|
+
spinner.succeed();
|
|
66
|
+
console.log('');
|
|
67
|
+
console.log(`Website porting in progress with ID: ${portid}`);
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
(0, utils_1.logDebug)(`ERROR: ${error instanceof Error ? `${error.message}` : JSON.stringify(error)}`);
|
|
71
|
+
if (spinner.isSpinning) {
|
|
72
|
+
spinner.fail();
|
|
73
|
+
}
|
|
74
|
+
(0, utils_1.handleCommandError)(getCommand, error);
|
|
75
|
+
}
|
|
76
|
+
}));
|
|
77
|
+
return getCommand;
|
|
78
|
+
};
|
|
79
|
+
exports.default = createStartPortCommand;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,198 @@
|
|
|
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 ApiService = __importStar(require("../../../ApiService"));
|
|
37
|
+
const PorterUtils = __importStar(require("../../utils"));
|
|
38
|
+
const fsp = __importStar(require("fs/promises"));
|
|
39
|
+
// const logSpy = jest.spyOn(global.console, 'log');
|
|
40
|
+
jest.mock('../../utils');
|
|
41
|
+
jest.mock('fs/promises');
|
|
42
|
+
describe('startPort', () => {
|
|
43
|
+
let projectName;
|
|
44
|
+
let portId;
|
|
45
|
+
let baseUrl;
|
|
46
|
+
let mockHandleCommandError;
|
|
47
|
+
let mockHandleError;
|
|
48
|
+
let mockBuildPorterUrl;
|
|
49
|
+
let mockResponse;
|
|
50
|
+
let mockClient;
|
|
51
|
+
beforeEach(() => {
|
|
52
|
+
jest.resetAllMocks();
|
|
53
|
+
jest.clearAllMocks();
|
|
54
|
+
projectName = 'mock-project';
|
|
55
|
+
portId = '1234-5678-1234-5678';
|
|
56
|
+
baseUrl = 'mock-url';
|
|
57
|
+
mockHandleCommandError = jest.fn(() => Promise.resolve());
|
|
58
|
+
mockHandleError = jest.fn();
|
|
59
|
+
mockBuildPorterUrl = jest.fn(() => Promise.resolve(baseUrl));
|
|
60
|
+
mockResponse = {
|
|
61
|
+
data: {},
|
|
62
|
+
status: 200,
|
|
63
|
+
};
|
|
64
|
+
mockClient = {
|
|
65
|
+
post: jest.fn().mockImplementationOnce(() => mockResponse),
|
|
66
|
+
};
|
|
67
|
+
jest.spyOn(PorterUtils, 'throwErrorIfNotLoggedIn').mockImplementation();
|
|
68
|
+
jest
|
|
69
|
+
.spyOn(PorterUtils, 'buildPorterUrl')
|
|
70
|
+
.mockImplementationOnce(mockBuildPorterUrl);
|
|
71
|
+
jest
|
|
72
|
+
.spyOn(PorterUtils, 'getProjectName')
|
|
73
|
+
.mockImplementation(() => Promise.resolve(projectName));
|
|
74
|
+
jest
|
|
75
|
+
.spyOn(fsp, 'readdir')
|
|
76
|
+
.mockImplementationOnce(() => Promise.resolve([
|
|
77
|
+
'crawl',
|
|
78
|
+
'index',
|
|
79
|
+
'template-dedupe',
|
|
80
|
+
'validation',
|
|
81
|
+
'report',
|
|
82
|
+
]));
|
|
83
|
+
jest
|
|
84
|
+
.spyOn(fsp, 'readFile')
|
|
85
|
+
.mockImplementation(() => Promise.resolve(JSON.stringify({ run: true })));
|
|
86
|
+
jest
|
|
87
|
+
.spyOn(PorterUtils, 'handleCommandError')
|
|
88
|
+
.mockImplementationOnce(mockHandleCommandError);
|
|
89
|
+
jest
|
|
90
|
+
.spyOn(PorterUtils, 'handleError')
|
|
91
|
+
.mockImplementationOnce(mockHandleError);
|
|
92
|
+
jest.spyOn(process, 'exit').mockImplementation();
|
|
93
|
+
jest.spyOn(ApiService, 'ApiService').mockImplementationOnce(() => {
|
|
94
|
+
return {
|
|
95
|
+
client: mockClient,
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
it('should throw an error if not logged in', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
100
|
+
const mockError = new Error('Error not logged in');
|
|
101
|
+
jest
|
|
102
|
+
.spyOn(PorterUtils, 'throwErrorIfNotLoggedIn')
|
|
103
|
+
.mockImplementationOnce(() => {
|
|
104
|
+
throw mockError;
|
|
105
|
+
});
|
|
106
|
+
const { default: createStartCommand } = require('./start');
|
|
107
|
+
const program = createStartCommand();
|
|
108
|
+
yield expect(() => program.parseAsync(['port', 'startPort', portId])).rejects.toThrow(mockError);
|
|
109
|
+
const opts = program.opts();
|
|
110
|
+
expect(opts).toStrictEqual({});
|
|
111
|
+
expect(PorterUtils.buildPorterUrl).not.toHaveBeenCalled();
|
|
112
|
+
}));
|
|
113
|
+
it('should throw an error if project name could not be found', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
114
|
+
jest.spyOn(PorterUtils, 'getProjectName').mockImplementationOnce(() => {
|
|
115
|
+
throw new Error();
|
|
116
|
+
});
|
|
117
|
+
const { default: createStartCommand } = require('./start');
|
|
118
|
+
const program = createStartCommand();
|
|
119
|
+
yield program.parseAsync(['port', 'startPort', portId]);
|
|
120
|
+
expect(PorterUtils.buildPorterUrl).toHaveBeenCalled();
|
|
121
|
+
expect(mockClient.post).not.toHaveBeenCalled();
|
|
122
|
+
expect(PorterUtils.handleCommandError).toHaveBeenCalled();
|
|
123
|
+
}));
|
|
124
|
+
it('should handle errors reading stage config files', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
125
|
+
jest
|
|
126
|
+
.spyOn(fsp, 'readdir')
|
|
127
|
+
.mockReset()
|
|
128
|
+
.mockImplementationOnce(() => {
|
|
129
|
+
throw new Error('ENOENT: no such file or directory');
|
|
130
|
+
});
|
|
131
|
+
const { default: createStartCommand } = require('./start');
|
|
132
|
+
const program = createStartCommand();
|
|
133
|
+
yield program.parseAsync(['port', 'startPort', portId]);
|
|
134
|
+
expect(PorterUtils.buildPorterUrl).toHaveBeenCalled();
|
|
135
|
+
expect(mockClient.post).not.toHaveBeenCalled();
|
|
136
|
+
expect(PorterUtils.handleCommandError).toHaveBeenCalled();
|
|
137
|
+
}));
|
|
138
|
+
it('should handle 400 error from the porter service', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
139
|
+
mockClient.post = jest.fn(() => {
|
|
140
|
+
throw new axios_1.AxiosError('Bad request', '400', undefined, undefined, {
|
|
141
|
+
data: {
|
|
142
|
+
status: 400,
|
|
143
|
+
title: 'Bad request',
|
|
144
|
+
'invalid-params': [
|
|
145
|
+
{ name: 'crawl.run', reason: 'crawl.run is required in the body' },
|
|
146
|
+
],
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
const { default: createStartCommand } = require('./start');
|
|
151
|
+
const program = createStartCommand();
|
|
152
|
+
yield program.parseAsync(['port', 'startPort', portId]);
|
|
153
|
+
expect(PorterUtils.buildPorterUrl).toHaveBeenCalled();
|
|
154
|
+
expect(mockClient.post).toHaveBeenCalled();
|
|
155
|
+
expect(PorterUtils.handleCommandError).toHaveBeenCalled();
|
|
156
|
+
}));
|
|
157
|
+
it('should handle unexpected errors', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
158
|
+
mockClient.post = jest.fn(() => {
|
|
159
|
+
throw new axios_1.AxiosError('Internal server error', '500', undefined, undefined, {
|
|
160
|
+
data: { status: 500 },
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
const { default: createStartCommand } = require('./start');
|
|
164
|
+
const program = createStartCommand();
|
|
165
|
+
yield program.parseAsync(['port', 'startPort', portId]);
|
|
166
|
+
expect(PorterUtils.buildPorterUrl).toHaveBeenCalled();
|
|
167
|
+
expect(mockClient.post).toHaveBeenCalled();
|
|
168
|
+
expect(PorterUtils.handleError).not.toHaveBeenCalled();
|
|
169
|
+
expect(PorterUtils.handleCommandError).toHaveBeenCalled();
|
|
170
|
+
}));
|
|
171
|
+
it('should successfully start a website port and log to the console', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
172
|
+
const uuid = '1234-1234-1234-1234';
|
|
173
|
+
const mockPostResponse = {
|
|
174
|
+
portid: uuid,
|
|
175
|
+
};
|
|
176
|
+
mockResponse = {
|
|
177
|
+
data: mockPostResponse,
|
|
178
|
+
status: 200,
|
|
179
|
+
};
|
|
180
|
+
const { default: createStartCommand } = require('./start');
|
|
181
|
+
const program = createStartCommand();
|
|
182
|
+
yield program.parseAsync(['port', 'startPort', portId]);
|
|
183
|
+
expect(PorterUtils.buildPorterUrl).toHaveBeenCalled();
|
|
184
|
+
expect(mockClient.post).toHaveBeenCalledWith(`/projects/${projectName}/ports`, {
|
|
185
|
+
'stage-settings': {
|
|
186
|
+
crawl: { run: true },
|
|
187
|
+
index: { run: true },
|
|
188
|
+
'component-transform': { run: false },
|
|
189
|
+
'design-dedupe': { run: false },
|
|
190
|
+
'template-dedupe': { run: true },
|
|
191
|
+
validation: { run: true },
|
|
192
|
+
report: { run: true },
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
expect(PorterUtils.handleError).not.toHaveBeenCalled();
|
|
196
|
+
expect(PorterUtils.handleCommandError).not.toHaveBeenCalled();
|
|
197
|
+
}));
|
|
198
|
+
});
|
|
@@ -35,14 +35,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
35
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
const nock_1 = __importDefault(require("nock"));
|
|
39
38
|
const commander_1 = require("commander");
|
|
40
39
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
41
40
|
const axios_1 = require("axios");
|
|
42
41
|
const ApiService = __importStar(require("../../../ApiService"));
|
|
43
|
-
const
|
|
44
|
-
const ErrorUtils = __importStar(require("../../utils/ErrorUtils/ErrorUtils"));
|
|
45
|
-
const DoesPathExist = __importStar(require("../../utils/DoesPathExist/DoesPathExist"));
|
|
42
|
+
const PorterUtils = __importStar(require("../../utils"));
|
|
46
43
|
const mockCliVersion = '1.2.3';
|
|
47
44
|
jest.mock('../../../../package.json', () => {
|
|
48
45
|
return {
|
|
@@ -57,6 +54,7 @@ jest.mock('fs/promises', () => {
|
|
|
57
54
|
writeFile: jest.fn(),
|
|
58
55
|
};
|
|
59
56
|
});
|
|
57
|
+
jest.mock('../../utils');
|
|
60
58
|
describe('addProject', () => {
|
|
61
59
|
let projectName;
|
|
62
60
|
let projectPath;
|
|
@@ -69,7 +67,6 @@ describe('addProject', () => {
|
|
|
69
67
|
beforeEach(() => {
|
|
70
68
|
jest.resetAllMocks();
|
|
71
69
|
jest.clearAllMocks();
|
|
72
|
-
nock_1.default.restore();
|
|
73
70
|
projectName = 'porter-project';
|
|
74
71
|
projectPath = 'tmp/project-dir';
|
|
75
72
|
baseUrl = 'mock-url';
|
|
@@ -83,14 +80,18 @@ describe('addProject', () => {
|
|
|
83
80
|
mockClient = {
|
|
84
81
|
put: jest.fn().mockImplementationOnce(() => mockResponse),
|
|
85
82
|
};
|
|
83
|
+
jest.spyOn(PorterUtils, 'throwErrorIfNotLoggedIn').mockImplementation();
|
|
86
84
|
jest
|
|
87
|
-
.spyOn(
|
|
85
|
+
.spyOn(PorterUtils, 'doesPathExist')
|
|
86
|
+
.mockImplementationOnce(() => Promise.resolve(false));
|
|
87
|
+
jest
|
|
88
|
+
.spyOn(PorterUtils, 'buildPorterUrl')
|
|
88
89
|
.mockImplementationOnce(mockBuildPorterUrl);
|
|
89
90
|
jest
|
|
90
|
-
.spyOn(
|
|
91
|
+
.spyOn(PorterUtils, 'handleCommandError')
|
|
91
92
|
.mockImplementationOnce(mockHandleCommandError);
|
|
92
93
|
jest
|
|
93
|
-
.spyOn(
|
|
94
|
+
.spyOn(PorterUtils, 'handleError')
|
|
94
95
|
.mockImplementationOnce(mockHandleError);
|
|
95
96
|
jest.spyOn(process, 'exit').mockImplementation();
|
|
96
97
|
jest.spyOn(ApiService, 'ApiService').mockImplementationOnce(() => {
|
|
@@ -105,8 +106,6 @@ describe('addProject', () => {
|
|
|
105
106
|
const { default: createAddCommand } = require('./add');
|
|
106
107
|
const program = createAddCommand();
|
|
107
108
|
yield expect(() => program.parseAsync([
|
|
108
|
-
'dxp-next',
|
|
109
|
-
'porter',
|
|
110
109
|
'project',
|
|
111
110
|
'addProject',
|
|
112
111
|
'--project-name',
|
|
@@ -119,18 +118,13 @@ describe('addProject', () => {
|
|
|
119
118
|
it('should throw an error if not logged in', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
120
119
|
const mockError = new Error('Error not logged in');
|
|
121
120
|
jest
|
|
122
|
-
.spyOn(
|
|
121
|
+
.spyOn(PorterUtils, 'throwErrorIfNotLoggedIn')
|
|
123
122
|
.mockImplementationOnce(() => {
|
|
124
123
|
throw mockError;
|
|
125
124
|
});
|
|
126
|
-
(0, nock_1.default)('http://localhost:9999')
|
|
127
|
-
.get('/__dxp/au/porter/SquizRoot-0000/health')
|
|
128
|
-
.reply(401);
|
|
129
125
|
const { default: createAddCommand } = require('./add');
|
|
130
126
|
const program = createAddCommand();
|
|
131
127
|
yield expect(() => program.parseAsync([
|
|
132
|
-
'dxp-next',
|
|
133
|
-
'porter',
|
|
134
128
|
'project',
|
|
135
129
|
'addProject',
|
|
136
130
|
'--project-name',
|
|
@@ -141,23 +135,16 @@ describe('addProject', () => {
|
|
|
141
135
|
const opts = program.opts();
|
|
142
136
|
expect(opts.projectName).toEqual(projectName);
|
|
143
137
|
expect(opts.path).toEqual(projectPath);
|
|
144
|
-
expect(
|
|
138
|
+
expect(PorterUtils.buildPorterUrl).not.toHaveBeenCalled();
|
|
145
139
|
}));
|
|
146
140
|
it('should throw an error if project directory already exists', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
147
141
|
jest
|
|
148
|
-
.spyOn(
|
|
149
|
-
.
|
|
150
|
-
jest
|
|
151
|
-
.spyOn(DoesPathExist, 'doesPathExist')
|
|
142
|
+
.spyOn(PorterUtils, 'doesPathExist')
|
|
143
|
+
.mockReset()
|
|
152
144
|
.mockImplementationOnce(() => Promise.resolve(true));
|
|
153
|
-
(0, nock_1.default)('http://localhost:9999')
|
|
154
|
-
.get('/__dxp/au/porter/SquizRoot-0000/health')
|
|
155
|
-
.reply(200);
|
|
156
145
|
const { default: createAddCommand } = require('./add');
|
|
157
146
|
const program = createAddCommand();
|
|
158
147
|
yield program.parseAsync([
|
|
159
|
-
'dxp-next',
|
|
160
|
-
'porter',
|
|
161
148
|
'project',
|
|
162
149
|
'addProject',
|
|
163
150
|
'--project-name',
|
|
@@ -168,28 +155,18 @@ describe('addProject', () => {
|
|
|
168
155
|
const opts = program.opts();
|
|
169
156
|
expect(opts.projectName).toEqual(projectName);
|
|
170
157
|
expect(opts.path).toEqual(projectPath);
|
|
171
|
-
expect(
|
|
172
|
-
expect(
|
|
173
|
-
expect(
|
|
158
|
+
expect(PorterUtils.buildPorterUrl).toHaveBeenCalled();
|
|
159
|
+
expect(PorterUtils.doesPathExist).toHaveBeenCalled();
|
|
160
|
+
expect(mockClient.put).not.toHaveBeenCalled();
|
|
161
|
+
expect(PorterUtils.handleCommandError).toHaveBeenCalled();
|
|
174
162
|
}));
|
|
175
163
|
it('should throw an error if parent directory does not exist', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
176
|
-
jest
|
|
177
|
-
.spyOn(ErrorUtils, 'throwErrorIfNotLoggedIn')
|
|
178
|
-
.mockImplementationOnce(() => Promise.resolve(undefined));
|
|
179
|
-
jest
|
|
180
|
-
.spyOn(DoesPathExist, 'doesPathExist')
|
|
181
|
-
.mockImplementationOnce(() => Promise.resolve(false));
|
|
182
164
|
jest.spyOn(promises_1.default, 'access').mockImplementationOnce(() => {
|
|
183
165
|
throw new Error();
|
|
184
166
|
});
|
|
185
|
-
(0, nock_1.default)('http://localhost:9999')
|
|
186
|
-
.get('/__dxp/au/porter/SquizRoot-0000/health')
|
|
187
|
-
.reply(200);
|
|
188
167
|
const { default: createAddCommand } = require('./add');
|
|
189
168
|
const program = createAddCommand();
|
|
190
169
|
yield program.parseAsync([
|
|
191
|
-
'dxp-next',
|
|
192
|
-
'porter',
|
|
193
170
|
'project',
|
|
194
171
|
'addProject',
|
|
195
172
|
'--project-name',
|
|
@@ -200,31 +177,21 @@ describe('addProject', () => {
|
|
|
200
177
|
const opts = program.opts();
|
|
201
178
|
expect(opts.projectName).toEqual(projectName);
|
|
202
179
|
expect(opts.path).toEqual(projectPath);
|
|
203
|
-
expect(
|
|
204
|
-
expect(
|
|
180
|
+
expect(PorterUtils.buildPorterUrl).toHaveBeenCalled();
|
|
181
|
+
expect(PorterUtils.doesPathExist).toHaveBeenCalled();
|
|
205
182
|
expect(promises_1.default.access).toHaveBeenCalled();
|
|
206
|
-
expect(
|
|
183
|
+
expect(mockClient.put).not.toHaveBeenCalled();
|
|
184
|
+
expect(PorterUtils.handleCommandError).toHaveBeenCalled();
|
|
207
185
|
}));
|
|
208
186
|
it('should clean up the directory if project already exists', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
209
|
-
jest
|
|
210
|
-
.spyOn(ErrorUtils, 'throwErrorIfNotLoggedIn')
|
|
211
|
-
.mockImplementationOnce(() => Promise.resolve(undefined));
|
|
212
|
-
jest
|
|
213
|
-
.spyOn(DoesPathExist, 'doesPathExist')
|
|
214
|
-
.mockImplementationOnce(() => Promise.resolve(false));
|
|
215
187
|
mockClient.put = jest.fn(() => {
|
|
216
188
|
throw new axios_1.AxiosError('Project already exists', '409', undefined, undefined, {
|
|
217
189
|
data: { status: 409 },
|
|
218
190
|
});
|
|
219
191
|
});
|
|
220
|
-
(0, nock_1.default)('http://localhost:9999')
|
|
221
|
-
.get('/__dxp/au/porter/SquizRoot-0000/health')
|
|
222
|
-
.reply(200);
|
|
223
192
|
const { default: createAddCommand } = require('./add');
|
|
224
193
|
const program = createAddCommand();
|
|
225
194
|
yield program.parseAsync([
|
|
226
|
-
'dxp-next',
|
|
227
|
-
'porter',
|
|
228
195
|
'project',
|
|
229
196
|
'addProject',
|
|
230
197
|
'--project-name',
|
|
@@ -235,8 +202,8 @@ describe('addProject', () => {
|
|
|
235
202
|
const opts = program.opts();
|
|
236
203
|
expect(opts.projectName).toEqual(projectName);
|
|
237
204
|
expect(opts.path).toEqual(projectPath);
|
|
238
|
-
expect(
|
|
239
|
-
expect(
|
|
205
|
+
expect(PorterUtils.buildPorterUrl).toHaveBeenCalled();
|
|
206
|
+
expect(PorterUtils.doesPathExist).toHaveBeenCalled();
|
|
240
207
|
expect(promises_1.default.access).toHaveBeenCalled();
|
|
241
208
|
// Create project dir, create "stage-configs" directory, create directories for (crawl, index, template-dedupe, validation, report)
|
|
242
209
|
expect(promises_1.default.mkdir).toHaveBeenCalledTimes(7);
|
|
@@ -245,24 +212,13 @@ describe('addProject', () => {
|
|
|
245
212
|
expect(promises_1.default.writeFile).toHaveBeenNthCalledWith(1, expect.any(String), expect.stringContaining(mockCliVersion));
|
|
246
213
|
expect(mockClient.put).toHaveBeenCalled();
|
|
247
214
|
expect(promises_1.default.rm).toHaveBeenCalled();
|
|
248
|
-
expect(
|
|
249
|
-
expect(
|
|
215
|
+
expect(PorterUtils.handleError).toHaveBeenCalled();
|
|
216
|
+
expect(PorterUtils.handleCommandError).not.toHaveBeenCalled();
|
|
250
217
|
}));
|
|
251
218
|
it('should handle unexpected errors', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
252
|
-
jest
|
|
253
|
-
.spyOn(ErrorUtils, 'throwErrorIfNotLoggedIn')
|
|
254
|
-
.mockImplementationOnce(() => Promise.resolve(undefined));
|
|
255
|
-
jest
|
|
256
|
-
.spyOn(DoesPathExist, 'doesPathExist')
|
|
257
|
-
.mockImplementationOnce(() => Promise.resolve(false));
|
|
258
|
-
(0, nock_1.default)('http://localhost:9999')
|
|
259
|
-
.get('/__dxp/au/porter/SquizRoot-0000/health')
|
|
260
|
-
.reply(200);
|
|
261
219
|
const { default: createAddCommand } = require('./add');
|
|
262
220
|
const program = createAddCommand();
|
|
263
221
|
yield program.parseAsync([
|
|
264
|
-
'dxp-next',
|
|
265
|
-
'porter',
|
|
266
222
|
'project',
|
|
267
223
|
'addProject',
|
|
268
224
|
'--project-name',
|
|
@@ -273,8 +229,8 @@ describe('addProject', () => {
|
|
|
273
229
|
const opts = program.opts();
|
|
274
230
|
expect(opts.projectName).toEqual(projectName);
|
|
275
231
|
expect(opts.path).toEqual(projectPath);
|
|
276
|
-
expect(
|
|
277
|
-
expect(
|
|
232
|
+
expect(PorterUtils.buildPorterUrl).toHaveBeenCalled();
|
|
233
|
+
expect(PorterUtils.doesPathExist).toHaveBeenCalled();
|
|
278
234
|
expect(promises_1.default.access).toHaveBeenCalled();
|
|
279
235
|
// Create project dir, create "stage-configs" directory, create directories for (crawl, index, template-dedupe, validation, report)
|
|
280
236
|
expect(promises_1.default.mkdir).toHaveBeenCalledTimes(7);
|
|
@@ -282,26 +238,12 @@ describe('addProject', () => {
|
|
|
282
238
|
expect(promises_1.default.writeFile).toHaveBeenCalledTimes(6);
|
|
283
239
|
expect(promises_1.default.writeFile).toHaveBeenNthCalledWith(1, expect.any(String), expect.stringContaining(mockCliVersion));
|
|
284
240
|
expect(mockClient.put).toHaveBeenCalled();
|
|
285
|
-
expect(
|
|
241
|
+
expect(PorterUtils.handleCommandError).not.toHaveBeenCalled();
|
|
286
242
|
}));
|
|
287
243
|
it('should successfully initialise the project directory and the porter project', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
288
|
-
jest
|
|
289
|
-
.spyOn(ErrorUtils, 'throwErrorIfNotLoggedIn')
|
|
290
|
-
.mockImplementationOnce(() => Promise.resolve(undefined));
|
|
291
|
-
jest
|
|
292
|
-
.spyOn(DoesPathExist, 'doesPathExist')
|
|
293
|
-
.mockImplementationOnce(() => Promise.resolve(false));
|
|
294
|
-
jest.spyOn(promises_1.default, 'mkdir').mockImplementationOnce(() => {
|
|
295
|
-
throw new Error('mock error');
|
|
296
|
-
});
|
|
297
|
-
(0, nock_1.default)('http://localhost:9999')
|
|
298
|
-
.get('/__dxp/au/porter/SquizRoot-0000/health')
|
|
299
|
-
.reply(200);
|
|
300
244
|
const { default: createAddCommand } = require('./add');
|
|
301
245
|
const program = createAddCommand();
|
|
302
246
|
yield program.parseAsync([
|
|
303
|
-
'dxp-next',
|
|
304
|
-
'porter',
|
|
305
247
|
'project',
|
|
306
248
|
'addProject',
|
|
307
249
|
'--project-name',
|
|
@@ -312,12 +254,17 @@ describe('addProject', () => {
|
|
|
312
254
|
const opts = program.opts();
|
|
313
255
|
expect(opts.projectName).toEqual(projectName);
|
|
314
256
|
expect(opts.path).toEqual(projectPath);
|
|
315
|
-
expect(
|
|
316
|
-
expect(
|
|
257
|
+
expect(PorterUtils.buildPorterUrl).toHaveBeenCalled();
|
|
258
|
+
expect(PorterUtils.doesPathExist).toHaveBeenCalled();
|
|
317
259
|
expect(promises_1.default.access).toHaveBeenCalled();
|
|
318
|
-
|
|
319
|
-
expect(promises_1.default.
|
|
320
|
-
|
|
321
|
-
expect(
|
|
260
|
+
// Create project dir, create "stage-configs" directory, create directories for (crawl, index, template-dedupe, validation, report)
|
|
261
|
+
expect(promises_1.default.mkdir).toHaveBeenCalledTimes(7);
|
|
262
|
+
// Create project config.json as well as 5 example config.json (for each stage)
|
|
263
|
+
expect(promises_1.default.writeFile).toHaveBeenCalledTimes(6);
|
|
264
|
+
expect(promises_1.default.writeFile).toHaveBeenNthCalledWith(1, expect.any(String), expect.stringContaining(mockCliVersion));
|
|
265
|
+
expect(mockClient.put).toHaveBeenCalled();
|
|
266
|
+
expect(promises_1.default.rm).not.toHaveBeenCalled();
|
|
267
|
+
expect(PorterUtils.handleError).not.toHaveBeenCalled();
|
|
268
|
+
expect(PorterUtils.handleCommandError).not.toHaveBeenCalled();
|
|
322
269
|
}));
|
|
323
270
|
});
|
|
@@ -17,7 +17,6 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
17
17
|
const ora_1 = __importDefault(require("ora"));
|
|
18
18
|
const ApiService_1 = require("../../../ApiService");
|
|
19
19
|
const utils_1 = require("../../utils");
|
|
20
|
-
const constants_1 = require("../../constants");
|
|
21
20
|
const createGetProjectCommand = () => {
|
|
22
21
|
const getCommand = new commander_1.Command('getProject')
|
|
23
22
|
.description('Retrieves the project')
|
|
@@ -33,21 +32,17 @@ const createGetProjectCommand = () => {
|
|
|
33
32
|
let projectName = '';
|
|
34
33
|
const spinner = (0, ora_1.default)();
|
|
35
34
|
try {
|
|
36
|
-
|
|
37
|
-
projectName = projectConfig.projectName;
|
|
38
|
-
if (!projectName) {
|
|
39
|
-
throw new Error(constants_1.PORTER_ERRORS.projectNameMissing);
|
|
40
|
-
}
|
|
35
|
+
projectName = yield (0, utils_1.getProjectName)();
|
|
41
36
|
spinner.start('Retrieving project..');
|
|
42
37
|
const apiService = new ApiService_1.ApiService(utils_1.validateAxiosStatus, baseUrl);
|
|
43
38
|
const response = yield apiService.client.get(`/projects/${projectName}`);
|
|
44
39
|
const jsonResponse = response.data;
|
|
45
|
-
(0, utils_1.logDebug)(jsonResponse);
|
|
40
|
+
(0, utils_1.logDebug)(JSON.stringify(jsonResponse));
|
|
46
41
|
spinner.succeed();
|
|
47
42
|
console.log('');
|
|
48
43
|
console.log(`Project name: ${projectName}`);
|
|
49
|
-
console.log(`Download last port report: ${jsonResponse['report-link'] || 'Not generated'}`);
|
|
50
|
-
console.log(`Download last port artifacts: ${jsonResponse['artifacts-link'] || 'Not generated'}`);
|
|
44
|
+
console.log(`Download last port report: ${jsonResponse['last-report-link'] || 'Not generated'}`);
|
|
45
|
+
console.log(`Download last port artifacts: ${jsonResponse['last-artifacts-link'] || 'Not generated'}`);
|
|
51
46
|
}
|
|
52
47
|
catch (error) {
|
|
53
48
|
(0, utils_1.logDebug)(`ERROR: ${error instanceof Error ? `${error.message}` : JSON.stringify(error)}`);
|