@squiz/dxp-cli-next 4.1.0-develop.1 → 4.1.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/auth/login.js +61 -6
- package/lib/cmp/deploy.js +3 -0
- package/package.json +3 -1
package/lib/auth/login.js
CHANGED
|
@@ -8,18 +8,21 @@ 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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
const cli_color_1 = require("cli-color");
|
|
13
16
|
const commander_1 = require("commander");
|
|
14
17
|
const ApiService_1 = require("../ApiService");
|
|
15
18
|
const ApplicationStore_1 = require("../ApplicationStore");
|
|
16
|
-
|
|
19
|
+
const prompt_1 = __importDefault(require("prompt"));
|
|
17
20
|
const PRODUCTION_URL = 'https://dxp.squiz.cloud';
|
|
18
21
|
const loginCommand = new commander_1.Command('login')
|
|
19
22
|
.name('login')
|
|
20
23
|
.description('Login to the DXP platform')
|
|
21
|
-
.
|
|
22
|
-
.
|
|
24
|
+
.addOption(new commander_1.Option('--username <username>', 'Optionally provide username through CLI, or environment variable. If this option is omitted you will be prompted for input in interactive mode').env('DXP_USERNAME'))
|
|
25
|
+
.addOption(new commander_1.Option('--password <password>', 'Optionally provide password through CLI, or environment variable. If this option is omitted you will be prompted for input in interactive mode').env('DXP_PASSWORD'))
|
|
23
26
|
.addOption(new commander_1.Option('--dxp-base-url <baseURL>', 'dxp cloud base url e.g. "https://develop-apps-dxp-console.dev.dxp.squiz.cloud/"')
|
|
24
27
|
.env('DXP_BASE_URL')
|
|
25
28
|
.default(PRODUCTION_URL))
|
|
@@ -30,10 +33,62 @@ const loginCommand = new commander_1.Command('login')
|
|
|
30
33
|
write((0, cli_color_1.red)(str));
|
|
31
34
|
},
|
|
32
35
|
})
|
|
33
|
-
.action((
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
.action((options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
const credentials = yield getLoginCredentials(options.username, options.password);
|
|
38
|
+
if (credentials == false) {
|
|
39
|
+
console.log(''); // needed to not screw up line endings in terminal
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
return handleLoginRequest(credentials, options);
|
|
43
|
+
}));
|
|
36
44
|
exports.default = loginCommand;
|
|
45
|
+
function getLoginCredentials(optionalUsername, optionalPassword) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
const prompts = [];
|
|
48
|
+
let username = '';
|
|
49
|
+
let password = '';
|
|
50
|
+
if (!optionalUsername) {
|
|
51
|
+
prompts.push({
|
|
52
|
+
name: 'username',
|
|
53
|
+
description: 'Username: ',
|
|
54
|
+
required: true,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
username = optionalUsername;
|
|
59
|
+
}
|
|
60
|
+
if (!optionalPassword) {
|
|
61
|
+
prompts.push({
|
|
62
|
+
name: 'password',
|
|
63
|
+
description: 'Password: ',
|
|
64
|
+
hidden: true,
|
|
65
|
+
replace: '*',
|
|
66
|
+
required: true,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
password = optionalPassword;
|
|
71
|
+
}
|
|
72
|
+
let result;
|
|
73
|
+
try {
|
|
74
|
+
prompt_1.default.start({ message: ' ', delimiter: ' ' });
|
|
75
|
+
result = yield prompt_1.default.get(prompts);
|
|
76
|
+
}
|
|
77
|
+
catch (e) {
|
|
78
|
+
if (e instanceof Error && e.message === 'canceled') {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
throw e;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (result.username)
|
|
86
|
+
username = result.username;
|
|
87
|
+
if (result.password)
|
|
88
|
+
password = result.password;
|
|
89
|
+
return { username, password };
|
|
90
|
+
});
|
|
91
|
+
}
|
|
37
92
|
function handleLoginRequest(login, options) {
|
|
38
93
|
return __awaiter(this, void 0, void 0, function* () {
|
|
39
94
|
const apiService = new ApiService_1.ApiService();
|
package/lib/cmp/deploy.js
CHANGED
|
@@ -25,6 +25,9 @@ const deployCommand = new commander_1.Command()
|
|
|
25
25
|
.addOption(new commander_1.Option('-t, --tenant <string>', 'Tenant ID to deploy to. If not provided will use configured tenant from login'))
|
|
26
26
|
.action((source, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
27
|
var _a, _b;
|
|
28
|
+
if (process.env.COMPONENT_SERVICE_URL !== undefined) {
|
|
29
|
+
console.log(`NOTICE: COMPONENT_SERVICE_URL is set and will deploy to ${process.env.COMPONENT_SERVICE_URL}`);
|
|
30
|
+
}
|
|
28
31
|
if (!options.componentServiceUrl &&
|
|
29
32
|
!(yield (0, ApplicationStore_1.getApplicationFile)(ApplicationStore_1.STORE_FILES.sessionCookie))) {
|
|
30
33
|
deployCommand.error(cli_color_1.default.red('You must login to deploy components. See `dxp-next auth login`'));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@squiz/dxp-cli-next",
|
|
3
|
-
"version": "4.1.0-develop.
|
|
3
|
+
"version": "4.1.0-develop.3",
|
|
4
4
|
"repository": {
|
|
5
5
|
"url": "https://gitlab.squiz.net/developer-experience/dxp-cli-next"
|
|
6
6
|
},
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"cli-color": "2.0.3",
|
|
46
46
|
"commander": "9.4.0",
|
|
47
47
|
"env-paths": "2.2.1",
|
|
48
|
+
"prompt": "^1.3.0",
|
|
48
49
|
"tough-cookie": "4.1.2",
|
|
49
50
|
"update-notifier": "5.1.0"
|
|
50
51
|
},
|
|
@@ -55,6 +56,7 @@
|
|
|
55
56
|
"@types/cli-color": "2.0.2",
|
|
56
57
|
"@types/jest": "28.1.6",
|
|
57
58
|
"@types/node": "17.0.45",
|
|
59
|
+
"@types/prompt": "^1.1.4",
|
|
58
60
|
"@types/tough-cookie": "4.0.2",
|
|
59
61
|
"@types/update-notifier": "5.1.0",
|
|
60
62
|
"@typescript-eslint/eslint-plugin": "5.30.7",
|