dockup-cli 1.0.0 → 1.0.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/dist/commands/link.js +97 -33
- package/package.json +1 -1
package/dist/commands/link.js
CHANGED
|
@@ -1,4 +1,37 @@
|
|
|
1
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
@@ -6,10 +39,36 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
39
|
exports.link = link;
|
|
7
40
|
exports.unlink = unlink;
|
|
8
41
|
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
-
const inquirer_1 = __importDefault(require("inquirer"));
|
|
10
42
|
const ora_1 = __importDefault(require("ora"));
|
|
43
|
+
const readline = __importStar(require("readline"));
|
|
11
44
|
const config_1 = require("../lib/config");
|
|
12
45
|
const api_1 = require("../lib/api");
|
|
46
|
+
function createReadline() {
|
|
47
|
+
return readline.createInterface({
|
|
48
|
+
input: process.stdin,
|
|
49
|
+
output: process.stdout
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function askQuestion(rl, question) {
|
|
53
|
+
return new Promise((resolve) => {
|
|
54
|
+
rl.question(question, (answer) => {
|
|
55
|
+
resolve(answer.trim());
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function askConfirm(rl, question, defaultValue = false) {
|
|
60
|
+
return new Promise((resolve) => {
|
|
61
|
+
const hint = defaultValue ? '[Y/n]' : '[y/N]';
|
|
62
|
+
rl.question(`${question} ${hint}: `, (answer) => {
|
|
63
|
+
if (!answer.trim()) {
|
|
64
|
+
resolve(defaultValue);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
resolve(answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes');
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
}
|
|
13
72
|
async function link(target) {
|
|
14
73
|
if (!(0, config_1.isLoggedIn)()) {
|
|
15
74
|
console.log(chalk_1.default.red('Not logged in. Run `dockup login` first.'));
|
|
@@ -18,12 +77,9 @@ async function link(target) {
|
|
|
18
77
|
const existing = (0, config_1.getProjectConfig)();
|
|
19
78
|
if (existing) {
|
|
20
79
|
console.log(chalk_1.default.yellow(`Already linked to ${existing.projectName}/${existing.serviceName}`));
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
message: 'Do you want to relink to a different service?',
|
|
25
|
-
default: false
|
|
26
|
-
}]);
|
|
80
|
+
const rl = createReadline();
|
|
81
|
+
const confirm = await askConfirm(rl, 'Do you want to relink to a different service?', false);
|
|
82
|
+
rl.close();
|
|
27
83
|
if (!confirm) {
|
|
28
84
|
return;
|
|
29
85
|
}
|
|
@@ -63,16 +119,21 @@ async function link(target) {
|
|
|
63
119
|
console.log(chalk_1.default.yellow('No projects found. Create a project first at https://app.dockup.ai'));
|
|
64
120
|
process.exit(1);
|
|
65
121
|
}
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
122
|
+
// Display projects
|
|
123
|
+
console.log(chalk_1.default.bold('\nAvailable Projects:\n'));
|
|
124
|
+
projects.forEach((p, index) => {
|
|
125
|
+
console.log(` ${chalk_1.default.cyan(index + 1)}. ${p.name} ${chalk_1.default.dim(`(${p.slug})`)}`);
|
|
126
|
+
});
|
|
127
|
+
console.log();
|
|
128
|
+
const rl = createReadline();
|
|
129
|
+
const projectChoice = await askQuestion(rl, 'Select a project (number): ');
|
|
130
|
+
const projectIndex = parseInt(projectChoice) - 1;
|
|
131
|
+
if (isNaN(projectIndex) || projectIndex < 0 || projectIndex >= projects.length) {
|
|
132
|
+
rl.close();
|
|
133
|
+
console.log(chalk_1.default.red('Invalid selection'));
|
|
134
|
+
process.exit(1);
|
|
135
|
+
}
|
|
136
|
+
const selectedProject = projects[projectIndex];
|
|
76
137
|
projectSlug = selectedProject.slug;
|
|
77
138
|
projectName = selectedProject.name;
|
|
78
139
|
// Get services for the project
|
|
@@ -80,19 +141,25 @@ async function link(target) {
|
|
|
80
141
|
const services = await api_1.api.getServices(projectSlug);
|
|
81
142
|
spinner.stop();
|
|
82
143
|
if (services.length === 0) {
|
|
144
|
+
rl.close();
|
|
83
145
|
console.log(chalk_1.default.yellow('No services found in this project.'));
|
|
84
146
|
process.exit(1);
|
|
85
147
|
}
|
|
86
|
-
//
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
148
|
+
// Display services
|
|
149
|
+
console.log(chalk_1.default.bold('\nAvailable Services:\n'));
|
|
150
|
+
services.forEach((s, index) => {
|
|
151
|
+
const statusIcon = s.status === 'running' ? chalk_1.default.green('●') : chalk_1.default.red('●');
|
|
152
|
+
console.log(` ${chalk_1.default.cyan(index + 1)}. ${s.name} ${chalk_1.default.dim(`(${s.slug})`)} ${statusIcon}`);
|
|
153
|
+
});
|
|
154
|
+
console.log();
|
|
155
|
+
const serviceChoice = await askQuestion(rl, 'Select a service (number): ');
|
|
156
|
+
rl.close();
|
|
157
|
+
const serviceIndex = parseInt(serviceChoice) - 1;
|
|
158
|
+
if (isNaN(serviceIndex) || serviceIndex < 0 || serviceIndex >= services.length) {
|
|
159
|
+
console.log(chalk_1.default.red('Invalid selection'));
|
|
160
|
+
process.exit(1);
|
|
161
|
+
}
|
|
162
|
+
const selectedService = services[serviceIndex];
|
|
96
163
|
serviceSlug = selectedService.slug;
|
|
97
164
|
serviceName = selectedService.name;
|
|
98
165
|
}
|
|
@@ -121,12 +188,9 @@ async function unlink() {
|
|
|
121
188
|
console.log(chalk_1.default.yellow('Not linked to any service'));
|
|
122
189
|
return;
|
|
123
190
|
}
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
message: `Unlink from ${config.projectName}/${config.serviceName}?`,
|
|
128
|
-
default: false
|
|
129
|
-
}]);
|
|
191
|
+
const rl = createReadline();
|
|
192
|
+
const confirm = await askConfirm(rl, `Unlink from ${config.projectName}/${config.serviceName}?`, false);
|
|
193
|
+
rl.close();
|
|
130
194
|
if (!confirm) {
|
|
131
195
|
return;
|
|
132
196
|
}
|