@northflank/cli 0.8.0 → 0.8.3-beta.0
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/api-helpers.js +273 -1
- package/dist/cli.js +630 -1
- package/dist/command-overview.js +93 -1
- package/dist/console-format-helpers.js +113 -1
- package/dist/context/contextCommands.js +522 -1
- package/dist/defaults.js +10238 -1
- package/dist/exec/index.js +262 -1
- package/dist/inquirer-helper.js +1049 -1
- package/dist/login/browser-login.js +204 -0
- package/dist/pagination/inquirer-pagination-prompt.js +156 -0
- package/dist/port-forward/index.js +271 -1
- package/dist/utils.js +201 -1
- package/package.json +10 -5
package/dist/utils.js
CHANGED
|
@@ -1 +1,201 @@
|
|
|
1
|
-
|
|
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 __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.assertContextExisting = exports.isValidJSON = exports.asyncSequential = exports.retry = exports.getCommand = exports.success = exports.warning = exports.error = exports.checkUpdate = exports.customUserAgent = void 0;
|
|
43
|
+
var node_fetch_1 = __importDefault(require("node-fetch"));
|
|
44
|
+
var chalk_1 = __importDefault(require("chalk"));
|
|
45
|
+
var commander_1 = require("commander");
|
|
46
|
+
var pgk = require('../package.json');
|
|
47
|
+
exports.customUserAgent = "northflank-cli/".concat(pgk === null || pgk === void 0 ? void 0 : pgk.version);
|
|
48
|
+
/**
|
|
49
|
+
* Checks if there is a newer version of the package and prints a notice to the command line if this is the case.
|
|
50
|
+
*/
|
|
51
|
+
function checkUpdate(contextProvider) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
53
|
+
function addDays(date, days) {
|
|
54
|
+
var copy = new Date(Number(date));
|
|
55
|
+
copy.setDate(copy.getDate() + days);
|
|
56
|
+
return copy;
|
|
57
|
+
}
|
|
58
|
+
var currentVersion, name_1, packageVersionUrl, response, latestVersion, e_1;
|
|
59
|
+
return __generator(this, function (_a) {
|
|
60
|
+
switch (_a.label) {
|
|
61
|
+
case 0:
|
|
62
|
+
_a.trys.push([0, 4, , 5]);
|
|
63
|
+
if (addDays(contextProvider.getLastUpdateCheck(), 1) > new Date()) {
|
|
64
|
+
return [2 /*return*/];
|
|
65
|
+
}
|
|
66
|
+
currentVersion = pgk.version;
|
|
67
|
+
name_1 = pgk.name;
|
|
68
|
+
if (!currentVersion) {
|
|
69
|
+
return [2 /*return*/];
|
|
70
|
+
}
|
|
71
|
+
packageVersionUrl = "https://registry.npmjs.org/".concat(name_1, "/latest");
|
|
72
|
+
return [4 /*yield*/, (0, node_fetch_1.default)(packageVersionUrl, { method: 'GET', timeout: 5000 })];
|
|
73
|
+
case 1:
|
|
74
|
+
response = _a.sent();
|
|
75
|
+
return [4 /*yield*/, response.json()];
|
|
76
|
+
case 2:
|
|
77
|
+
latestVersion = (_a.sent()).version;
|
|
78
|
+
if (needsUpdate(currentVersion, latestVersion)) {
|
|
79
|
+
warning("** You're running on version ".concat(currentVersion, ", the latest version of the cli is ").concat(latestVersion, ".") +
|
|
80
|
+
" Consider updating using 'npm i ".concat(name_1, " -g' or 'yarn global add ").concat(name_1, "' **"));
|
|
81
|
+
}
|
|
82
|
+
return [4 /*yield*/, contextProvider.setLastUpdateCheck(new Date())];
|
|
83
|
+
case 3:
|
|
84
|
+
_a.sent();
|
|
85
|
+
return [3 /*break*/, 5];
|
|
86
|
+
case 4:
|
|
87
|
+
e_1 = _a.sent();
|
|
88
|
+
return [3 /*break*/, 5];
|
|
89
|
+
case 5: return [2 /*return*/];
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
exports.checkUpdate = checkUpdate;
|
|
95
|
+
/** @return true if currentVersion is smaller than latestVersion
|
|
96
|
+
*/
|
|
97
|
+
function needsUpdate(currentVersion, latestVersion) {
|
|
98
|
+
var regExStrip0 = /(\.0+)+$/;
|
|
99
|
+
var segmentsCurrent = currentVersion.replace(regExStrip0, '').split('.');
|
|
100
|
+
var segmentsLatest = latestVersion.replace(regExStrip0, '').split('.');
|
|
101
|
+
for (var i = 0; i < Math.min(segmentsCurrent.length, segmentsLatest.length); i += 1) {
|
|
102
|
+
var diff = parseInt(segmentsLatest[i], 10) - parseInt(segmentsCurrent[i], 10);
|
|
103
|
+
if (diff > 0) {
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
if (diff < 0) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return segmentsLatest.length > segmentsCurrent.length;
|
|
111
|
+
}
|
|
112
|
+
/** Printer helpers */
|
|
113
|
+
function error(msg) {
|
|
114
|
+
console.error(chalk_1.default.redBright("Failed: ".concat(msg)));
|
|
115
|
+
}
|
|
116
|
+
exports.error = error;
|
|
117
|
+
function warning(msg) {
|
|
118
|
+
console.error(chalk_1.default.yellow("".concat(msg)));
|
|
119
|
+
}
|
|
120
|
+
exports.warning = warning;
|
|
121
|
+
function success(msg) {
|
|
122
|
+
console.log(chalk_1.default.green("".concat(msg)));
|
|
123
|
+
}
|
|
124
|
+
exports.success = success;
|
|
125
|
+
function getCommand(withOptions) {
|
|
126
|
+
if (withOptions === void 0) { withOptions = false; }
|
|
127
|
+
var command = new commander_1.Command();
|
|
128
|
+
command.storeOptionsAsProperties(false);
|
|
129
|
+
command.allowUnknownOption(false);
|
|
130
|
+
command.allowExcessArguments(false);
|
|
131
|
+
command.enablePositionalOptions(true); // Avoid properties clash with --name option
|
|
132
|
+
if (withOptions) {
|
|
133
|
+
command.option('--verbose', 'Verbose output', false);
|
|
134
|
+
command.option('--quiet', 'No console output', false);
|
|
135
|
+
}
|
|
136
|
+
return command;
|
|
137
|
+
}
|
|
138
|
+
exports.getCommand = getCommand;
|
|
139
|
+
var retry = function (retries, retryDelay) {
|
|
140
|
+
if (retryDelay === void 0) { retryDelay = 50; }
|
|
141
|
+
return function (action) {
|
|
142
|
+
var retriesCounter = retries;
|
|
143
|
+
var retryRecursive = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
144
|
+
var e_2;
|
|
145
|
+
return __generator(this, function (_a) {
|
|
146
|
+
switch (_a.label) {
|
|
147
|
+
case 0:
|
|
148
|
+
_a.trys.push([0, 2, , 4]);
|
|
149
|
+
return [4 /*yield*/, action()];
|
|
150
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
151
|
+
case 2:
|
|
152
|
+
e_2 = _a.sent();
|
|
153
|
+
if (retriesCounter <= 0) {
|
|
154
|
+
throw e_2;
|
|
155
|
+
}
|
|
156
|
+
retriesCounter -= 1;
|
|
157
|
+
return [4 /*yield*/, new Promise(function (r) { return setTimeout(function () { return r(); }, retryDelay); })];
|
|
158
|
+
case 3:
|
|
159
|
+
_a.sent();
|
|
160
|
+
return [2 /*return*/, retryRecursive()];
|
|
161
|
+
case 4: return [2 /*return*/];
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}); };
|
|
165
|
+
return retryRecursive();
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
exports.retry = retry;
|
|
169
|
+
var asyncSequential = function (elements, op) { return __awaiter(void 0, void 0, void 0, function () {
|
|
170
|
+
var empty;
|
|
171
|
+
return __generator(this, function (_a) {
|
|
172
|
+
empty = Promise.resolve([]);
|
|
173
|
+
return [2 /*return*/, elements.reduce(function (prevPromise, element) {
|
|
174
|
+
return prevPromise.then(function (result) {
|
|
175
|
+
return op(element).then(function (r) {
|
|
176
|
+
result.push(r);
|
|
177
|
+
return result;
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
}, empty)];
|
|
181
|
+
});
|
|
182
|
+
}); };
|
|
183
|
+
exports.asyncSequential = asyncSequential;
|
|
184
|
+
function isValidJSON(str) {
|
|
185
|
+
try {
|
|
186
|
+
return JSON.parse(str);
|
|
187
|
+
}
|
|
188
|
+
catch (e) {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
exports.isValidJSON = isValidJSON;
|
|
193
|
+
function assertContextExisting(apiClient) {
|
|
194
|
+
if (apiClient.contextProvider.getCurrentContext() === undefined)
|
|
195
|
+
throw new Error("No CLI context present. Create context with 'northflank login'");
|
|
196
|
+
if (apiClient.contextProvider.getCurrentBaseUrl() === undefined)
|
|
197
|
+
throw new Error("No API URL present in context. Create new context with 'northflank login'");
|
|
198
|
+
if (apiClient.contextProvider.getCurrentToken() === undefined)
|
|
199
|
+
throw new Error("No token in CLI context. Add token with 'northflank set-token'");
|
|
200
|
+
}
|
|
201
|
+
exports.assertContextExisting = assertContextExisting;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@northflank/cli",
|
|
3
|
-
"version": "0.8.0",
|
|
3
|
+
"version": "0.8.3-beta.0",
|
|
4
4
|
"author": "Marco Suter",
|
|
5
5
|
"description": "Provides a command-line interface to the Northflank platform.",
|
|
6
6
|
"homepage": "https://www.northflank.com",
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
"build": "tsc",
|
|
12
12
|
"clin": "node dist/cli.js",
|
|
13
13
|
"cli": "babel-node --root-mode upward --ignore \"node_modules\" --extensions \".js,.ts\" src/cli.ts",
|
|
14
|
+
"inq-pag": "babel-node --root-mode upward --ignore \"node_modules\" --extensions \".js,.ts\" src/pagination/_dev/index.ts",
|
|
15
|
+
"gen-fig-spec": "babel-node --root-mode upward --ignore \"node_modules\" --extensions \".js,.ts\" src/_dev/gen-fig-spec.ts",
|
|
14
16
|
"lint": "eslint .",
|
|
15
17
|
"postinstall": "node postinstall.js"
|
|
16
18
|
},
|
|
@@ -24,17 +26,20 @@
|
|
|
24
26
|
"LICENSE"
|
|
25
27
|
],
|
|
26
28
|
"dependencies": {
|
|
27
|
-
"@northflank/js-client": "0.6.0",
|
|
28
|
-
"ajv": "
|
|
29
|
+
"@northflank/js-client": "0.6.3-beta.0",
|
|
30
|
+
"ajv": "8.6.3",
|
|
29
31
|
"chalk": "~4.1.0",
|
|
30
32
|
"columnify": "^1.5.4",
|
|
31
|
-
"commander": "
|
|
32
|
-
"inquirer": "
|
|
33
|
+
"commander": "8.2.0",
|
|
34
|
+
"inquirer": "7.3.3",
|
|
35
|
+
"inquirer-search-list": "^1.2.6",
|
|
33
36
|
"js-yaml": "^3.14.0",
|
|
34
37
|
"lodash": "^4.17.15",
|
|
38
|
+
"open": "^8.4.0",
|
|
35
39
|
"node-fetch": "2.6.7"
|
|
36
40
|
},
|
|
37
41
|
"devDependencies": {
|
|
42
|
+
"@fig/complete-commander": "^2.0.0",
|
|
38
43
|
"ts-node": "^8.10.2",
|
|
39
44
|
"typescript": "^4.0.3"
|
|
40
45
|
},
|