@ones-open/cli 0.0.10 → 0.0.12-21205.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.
- package/dist/index.cjs +327 -85
- package/dist/index.js +327 -85
- package/dist/types/actions/app/resolve.d.ts +10 -0
- package/dist/types/actions/app/resolve.d.ts.map +1 -0
- package/dist/types/actions/dev/index.d.ts.map +1 -1
- package/dist/types/actions/disable/index.d.ts.map +1 -1
- package/dist/types/actions/disable/normalize.d.ts.map +1 -1
- package/dist/types/actions/enable/index.d.ts.map +1 -1
- package/dist/types/actions/enable/normalize.d.ts.map +1 -1
- package/dist/types/actions/index.d.ts +1 -0
- package/dist/types/actions/index.d.ts.map +1 -1
- package/dist/types/actions/install/index.d.ts.map +1 -1
- package/dist/types/actions/install/install.d.ts +2 -1
- package/dist/types/actions/install/install.d.ts.map +1 -1
- package/dist/types/actions/install/normalize.d.ts.map +1 -1
- package/dist/types/actions/logs/index.d.ts +4 -0
- package/dist/types/actions/logs/index.d.ts.map +1 -0
- package/dist/types/actions/logs/normalize.d.ts +11 -0
- package/dist/types/actions/logs/normalize.d.ts.map +1 -0
- package/dist/types/actions/uninstall/index.d.ts.map +1 -1
- package/dist/types/actions/uninstall/normalize.d.ts.map +1 -1
- package/dist/types/command/app/index.d.ts.map +1 -1
- package/dist/types/command/disable/index.d.ts +1 -1
- package/dist/types/command/disable/index.d.ts.map +1 -1
- package/dist/types/command/enable/index.d.ts +1 -1
- package/dist/types/command/enable/index.d.ts.map +1 -1
- package/dist/types/command/index.d.ts +1 -0
- package/dist/types/command/index.d.ts.map +1 -1
- package/dist/types/command/install/index.d.ts +1 -1
- package/dist/types/command/install/index.d.ts.map +1 -1
- package/dist/types/command/logs/index.d.ts +10 -0
- package/dist/types/command/logs/index.d.ts.map +1 -0
- package/dist/types/command/uninstall/index.d.ts +1 -1
- package/dist/types/command/uninstall/index.d.ts.map +1 -1
- package/dist/types/common/locales/en/index.d.ts +4 -0
- package/dist/types/common/locales/en/index.d.ts.map +1 -1
- package/dist/types/common/package/utils.d.ts +1 -0
- package/dist/types/common/package/utils.d.ts.map +1 -1
- package/dist/types/common/request/consts.d.ts +1 -0
- package/dist/types/common/request/consts.d.ts.map +1 -1
- package/dist/types/common/request/fetch.d.ts +2 -1
- package/dist/types/common/request/fetch.d.ts.map +1 -1
- package/dist/types/common/request/types.d.ts +20 -7
- package/dist/types/common/request/types.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -10,6 +10,7 @@ import { get, merge, random, noop } from "lodash-es";
|
|
|
10
10
|
import process$1, { cwd } from "node:process";
|
|
11
11
|
import { fileURLToPath } from "node:url";
|
|
12
12
|
import { cosmiconfig } from "cosmiconfig";
|
|
13
|
+
import { createConnection } from "node:net";
|
|
13
14
|
import getPort from "get-port";
|
|
14
15
|
import envPaths from "env-paths";
|
|
15
16
|
import { z } from "zod";
|
|
@@ -41,6 +42,10 @@ const en = {
|
|
|
41
42
|
"desc.enable": "Enable your ONES App",
|
|
42
43
|
"desc.disable": "Disable your ONES App",
|
|
43
44
|
"desc.uninstall": "Uninstall your ONES App",
|
|
45
|
+
"desc.app.appId": "Specify app id",
|
|
46
|
+
"desc.logs": "View runtime logs for your ONES App",
|
|
47
|
+
"desc.logs.fromOpkxJson": "Read app id from local opkx.json when app id is not provided",
|
|
48
|
+
"desc.logs.tail": "Specify latest log lines to fetch (default 100)",
|
|
44
49
|
"desc.legacy": "Legacy command",
|
|
45
50
|
"desc.legacy.create": "Create a new ONES plugin",
|
|
46
51
|
"desc.legacy.create.projectPath": "Specify the project path",
|
|
@@ -158,6 +163,18 @@ const getAppManifestJSON = () => {
|
|
|
158
163
|
return throwError(ErrorCode.APP_MANIFEST_JSON_PARSE_ERROR, `${i18n.t("error.schema.app.manifest.parseError")}: ${details}`);
|
|
159
164
|
}
|
|
160
165
|
};
|
|
166
|
+
const tryGetAppManifestJSON = function() {
|
|
167
|
+
let path = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : getAppManifestJSONPath();
|
|
168
|
+
try {
|
|
169
|
+
const string = readFileSync(path, {
|
|
170
|
+
encoding: "utf8"
|
|
171
|
+
});
|
|
172
|
+
const json = JSON.parse(string);
|
|
173
|
+
return AppManifestJSONSchema.parse(json);
|
|
174
|
+
} catch (error) {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
};
|
|
161
178
|
const validateAppManifestJSON = () => {
|
|
162
179
|
const appManifestJSON = getAppManifestJSON();
|
|
163
180
|
try {
|
|
@@ -209,7 +226,7 @@ const getAppRcJSON = async () => {
|
|
|
209
226
|
};
|
|
210
227
|
const isOPKXFilename = /\.opkx$/;
|
|
211
228
|
const defaultOutputPath = "";
|
|
212
|
-
const normalize$
|
|
229
|
+
const normalize$b = async (options) => {
|
|
213
230
|
var _options$output, _options$command;
|
|
214
231
|
let output = resolve(cwd(), (_options$output = options.output) !== null && _options$output !== void 0 ? _options$output : defaultOutputPath);
|
|
215
232
|
const command = (_options$command = options.command) !== null && _options$command !== void 0 ? _options$command : "";
|
|
@@ -238,7 +255,7 @@ const build = async function() {
|
|
|
238
255
|
const {
|
|
239
256
|
options
|
|
240
257
|
} = getCommandOptions(args, buildCommandArguments);
|
|
241
|
-
const normalizedOptions = await normalize$
|
|
258
|
+
const normalizedOptions = await normalize$b(options);
|
|
242
259
|
const appManifestJSON = getAppManifestJSON();
|
|
243
260
|
const appRcJSON = await getAppRcJSON();
|
|
244
261
|
const correctCommand = normalizedOptions.command || ((_appRcJSON$dev = appRcJSON.dev) === null || _appRcJSON$dev === void 0 || (_appRcJSON$dev = _appRcJSON$dev.command) === null || _appRcJSON$dev === void 0 ? void 0 : _appRcJSON$dev[0]) || ((_defaultAppRcJSON$dev = defaultAppRcJSON.dev) === null || _defaultAppRcJSON$dev === void 0 || (_defaultAppRcJSON$dev = _defaultAppRcJSON$dev.command) === null || _defaultAppRcJSON$dev === void 0 ? void 0 : _defaultAppRcJSON$dev[0]) || "";
|
|
@@ -460,6 +477,7 @@ const API = {
|
|
|
460
477
|
APP_ENABLE: "/platform/api/app/:installation_id/enable",
|
|
461
478
|
APP_DISABLE: "/platform/api/app/:installation_id/disable",
|
|
462
479
|
OAUTH_TOKEN: "/identity/oauth/token",
|
|
480
|
+
APP_RUNTIME_LOGS: "/platform/runtime_manager/app/runtime/logs",
|
|
463
481
|
REFRESH_TOKEN: "/identity/oauth/token"
|
|
464
482
|
};
|
|
465
483
|
const REQUEST_TIMEOUT = 1e4;
|
|
@@ -650,12 +668,36 @@ const fetchHostedAbilityStorageDevDeclare = async (appID, data) => {
|
|
|
650
668
|
data
|
|
651
669
|
}).catch(handleError);
|
|
652
670
|
};
|
|
653
|
-
const
|
|
654
|
-
var _appList$data$
|
|
655
|
-
const appID = getAppManifestJSON().app.id;
|
|
671
|
+
const getAppInstallation = async (appID) => {
|
|
672
|
+
var _appList$data$, _appList$data, _appData$installation, _appData$app_env;
|
|
656
673
|
const appList = await fetchAppList(appID);
|
|
657
|
-
const
|
|
674
|
+
const appData = (_appList$data$ = (_appList$data = appList.data) === null || _appList$data === void 0 ? void 0 : _appList$data[0]) !== null && _appList$data$ !== void 0 ? _appList$data$ : {};
|
|
675
|
+
return {
|
|
676
|
+
installationID: (_appData$installation = appData.installation_id) !== null && _appData$installation !== void 0 ? _appData$installation : "",
|
|
677
|
+
appEnv: (_appData$app_env = appData.app_env) !== null && _appData$app_env !== void 0 ? _appData$app_env : "development"
|
|
678
|
+
};
|
|
679
|
+
};
|
|
680
|
+
const consoleProductionNotAllowedMessage = (operation) => {
|
|
681
|
+
console.log(`Cannot run "${operation}" in "production" environment`);
|
|
682
|
+
process.exit(1);
|
|
683
|
+
};
|
|
684
|
+
const getDisplayAppEnv = (appEnv) => {
|
|
685
|
+
return appEnv === "production" ? "production" : "development";
|
|
686
|
+
};
|
|
687
|
+
const consoleAppEnvMessage = (operation, appEnv) => {
|
|
688
|
+
console.log(`Operating "${operation}" in "${appEnv}" environment`);
|
|
689
|
+
};
|
|
690
|
+
const fetchAppInstall = async (appID, data) => {
|
|
691
|
+
const {
|
|
692
|
+
installationID,
|
|
693
|
+
appEnv
|
|
694
|
+
} = await getAppInstallation(appID);
|
|
658
695
|
if (installationID) {
|
|
696
|
+
if (appEnv === "production") {
|
|
697
|
+
consoleProductionNotAllowedMessage("install");
|
|
698
|
+
}
|
|
699
|
+
const displayAppEnv = getDisplayAppEnv(appEnv);
|
|
700
|
+
consoleAppEnvMessage("install", displayAppEnv);
|
|
659
701
|
return await fetchAppBase({
|
|
660
702
|
url: API.APP_UPGRADE,
|
|
661
703
|
method: "POST",
|
|
@@ -665,18 +707,24 @@ const fetchAppInstall = async (data) => {
|
|
|
665
707
|
data
|
|
666
708
|
}).catch(handleError);
|
|
667
709
|
}
|
|
710
|
+
consoleAppEnvMessage("install", "development");
|
|
668
711
|
return await fetchAppBase({
|
|
669
712
|
url: API.APP_INSTALL,
|
|
670
713
|
method: "POST",
|
|
671
714
|
data
|
|
672
715
|
}).catch(handleError);
|
|
673
716
|
};
|
|
674
|
-
const fetchAppUninstall = async () => {
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
717
|
+
const fetchAppUninstall = async (appID) => {
|
|
718
|
+
const {
|
|
719
|
+
installationID,
|
|
720
|
+
appEnv
|
|
721
|
+
} = await getAppInstallation(appID);
|
|
679
722
|
if (installationID) {
|
|
723
|
+
if (appEnv === "production") {
|
|
724
|
+
consoleProductionNotAllowedMessage("uninstall");
|
|
725
|
+
}
|
|
726
|
+
const displayAppEnv = getDisplayAppEnv(appEnv);
|
|
727
|
+
consoleAppEnvMessage("uninstall", displayAppEnv);
|
|
680
728
|
return await fetchAppBase({
|
|
681
729
|
url: API.APP_UNINSTALL,
|
|
682
730
|
method: "POST",
|
|
@@ -688,12 +736,14 @@ const fetchAppUninstall = async () => {
|
|
|
688
736
|
consoleAppNotInstalledMessage();
|
|
689
737
|
process.exit(1);
|
|
690
738
|
};
|
|
691
|
-
const fetchAppEnable = async () => {
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
739
|
+
const fetchAppEnable = async (appID) => {
|
|
740
|
+
const {
|
|
741
|
+
installationID,
|
|
742
|
+
appEnv
|
|
743
|
+
} = await getAppInstallation(appID);
|
|
696
744
|
if (installationID) {
|
|
745
|
+
const displayAppEnv = getDisplayAppEnv(appEnv);
|
|
746
|
+
consoleAppEnvMessage("enable", displayAppEnv);
|
|
697
747
|
return await fetchAppBase({
|
|
698
748
|
url: API.APP_ENABLE,
|
|
699
749
|
method: "POST",
|
|
@@ -705,12 +755,14 @@ const fetchAppEnable = async () => {
|
|
|
705
755
|
consoleAppNotInstalledMessage();
|
|
706
756
|
process.exit(1);
|
|
707
757
|
};
|
|
708
|
-
const fetchAppDisable = async () => {
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
758
|
+
const fetchAppDisable = async (appID) => {
|
|
759
|
+
const {
|
|
760
|
+
installationID,
|
|
761
|
+
appEnv
|
|
762
|
+
} = await getAppInstallation(appID);
|
|
713
763
|
if (installationID) {
|
|
764
|
+
const displayAppEnv = getDisplayAppEnv(appEnv);
|
|
765
|
+
consoleAppEnvMessage("disable", displayAppEnv);
|
|
714
766
|
return await fetchAppBase({
|
|
715
767
|
url: API.APP_DISABLE,
|
|
716
768
|
method: "POST",
|
|
@@ -722,6 +774,13 @@ const fetchAppDisable = async () => {
|
|
|
722
774
|
consoleAppNotInstalledMessage();
|
|
723
775
|
process.exit(1);
|
|
724
776
|
};
|
|
777
|
+
const fetchAppRuntimeLogs = async (data) => {
|
|
778
|
+
return await fetchAppBase({
|
|
779
|
+
url: API.APP_RUNTIME_LOGS,
|
|
780
|
+
method: "POST",
|
|
781
|
+
data
|
|
782
|
+
}).catch(handleError);
|
|
783
|
+
};
|
|
725
784
|
const checkTokenInfo = async () => {
|
|
726
785
|
let boolean = true;
|
|
727
786
|
const regionURL = await getRegionURL().catch(() => "");
|
|
@@ -738,8 +797,28 @@ const checkTokenInfo = async () => {
|
|
|
738
797
|
}
|
|
739
798
|
return boolean;
|
|
740
799
|
};
|
|
800
|
+
const resolveAppInfo = (input) => {
|
|
801
|
+
var _input$appID;
|
|
802
|
+
const appIDFromArgument = (_input$appID = input.appID) !== null && _input$appID !== void 0 ? _input$appID : "";
|
|
803
|
+
if (appIDFromArgument) {
|
|
804
|
+
return {
|
|
805
|
+
appID: appIDFromArgument,
|
|
806
|
+
appName: appIDFromArgument
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
const appManifestPath = input.opkxPath ? resolve(cwd(), input.opkxPath) : getAppManifestJSONPath();
|
|
810
|
+
const appManifestJSON = tryGetAppManifestJSON(appManifestPath);
|
|
811
|
+
if (appManifestJSON) {
|
|
812
|
+
return {
|
|
813
|
+
appID: appManifestJSON.app.id,
|
|
814
|
+
appName: appManifestJSON.app.name
|
|
815
|
+
};
|
|
816
|
+
}
|
|
817
|
+
console.log('Cannot read local "opkx.json". Please ensure "opkx.json" exists in the current directory, or provide an app ID.');
|
|
818
|
+
process.exit(1);
|
|
819
|
+
};
|
|
741
820
|
const isPortNumber = /^[1-9]\d{0,4}$/;
|
|
742
|
-
const normalize$
|
|
821
|
+
const normalize$a = async (options) => {
|
|
743
822
|
var _options$clearStorage;
|
|
744
823
|
const portInput = options.port;
|
|
745
824
|
if (portInput)
|
|
@@ -1103,7 +1182,7 @@ const tunnel = async function() {
|
|
|
1103
1182
|
const {
|
|
1104
1183
|
options
|
|
1105
1184
|
} = getCommandOptions(args, tunnelCommandArguments);
|
|
1106
|
-
const normalizedOptions = await normalize$
|
|
1185
|
+
const normalizedOptions = await normalize$a(options);
|
|
1107
1186
|
const port = Number(normalizedOptions.port);
|
|
1108
1187
|
const cancelWaiting = startWaiting();
|
|
1109
1188
|
await invokeTunnel(port, {
|
|
@@ -1115,9 +1194,12 @@ const tunnel = async function() {
|
|
|
1115
1194
|
const tunnelUrl = await buildTunnelUrl();
|
|
1116
1195
|
console.log(`Relay endpoint: ${tunnelUrl}`);
|
|
1117
1196
|
};
|
|
1118
|
-
const normalize$
|
|
1197
|
+
const normalize$9 = async (options) => {
|
|
1198
|
+
var _options$appID;
|
|
1119
1199
|
noop(options);
|
|
1120
|
-
return {
|
|
1200
|
+
return {
|
|
1201
|
+
appID: (_options$appID = options.appID) !== null && _options$appID !== void 0 ? _options$appID : ""
|
|
1202
|
+
};
|
|
1121
1203
|
};
|
|
1122
1204
|
const displayAppDetail = async (installationID) => {
|
|
1123
1205
|
var _tokenInfo$org$uuid, _tokenInfo$org, _tokenInfo$teams$0$uu, _tokenInfo$teams, _tokenInfo$org$visibi, _tokenInfo$org2;
|
|
@@ -1135,14 +1217,10 @@ const displayAppDetail = async (installationID) => {
|
|
|
1135
1217
|
console.log(`See App detail: ${url}`);
|
|
1136
1218
|
}
|
|
1137
1219
|
};
|
|
1138
|
-
const invokeInstall = async (manifestUrl) => {
|
|
1139
|
-
const
|
|
1140
|
-
app
|
|
1141
|
-
} = getAppManifestJSON();
|
|
1142
|
-
const appName = app.name;
|
|
1143
|
-
const appID = app.id;
|
|
1220
|
+
const invokeInstall = async (manifestUrl, appInfo) => {
|
|
1221
|
+
const appID = appInfo.appID;
|
|
1144
1222
|
const cancelWaiting = startWaiting();
|
|
1145
|
-
const result = await fetchAppInstall({
|
|
1223
|
+
const result = await fetchAppInstall(appID, {
|
|
1146
1224
|
manifest_url: manifestUrl,
|
|
1147
1225
|
options: {
|
|
1148
1226
|
enable: true
|
|
@@ -1151,7 +1229,7 @@ const invokeInstall = async (manifestUrl) => {
|
|
|
1151
1229
|
cancelWaiting();
|
|
1152
1230
|
if (result.code === "OK") {
|
|
1153
1231
|
var _appList$data$0$insta, _appList$data;
|
|
1154
|
-
console.log(`App "${
|
|
1232
|
+
console.log(`App "${appID}" installed successfully!`);
|
|
1155
1233
|
const appList = await fetchAppList(appID);
|
|
1156
1234
|
const installationID = (_appList$data$0$insta = (_appList$data = appList.data) === null || _appList$data === void 0 || (_appList$data = _appList$data[0]) === null || _appList$data === void 0 ? void 0 : _appList$data.installation_id) !== null && _appList$data$0$insta !== void 0 ? _appList$data$0$insta : "";
|
|
1157
1235
|
if (installationID) {
|
|
@@ -1159,7 +1237,7 @@ const invokeInstall = async (manifestUrl) => {
|
|
|
1159
1237
|
}
|
|
1160
1238
|
return true;
|
|
1161
1239
|
} else {
|
|
1162
|
-
console.log(`App "${
|
|
1240
|
+
console.log(`App "${appID}" installed failed!`);
|
|
1163
1241
|
console.error(JSON.stringify(result, null, 2));
|
|
1164
1242
|
}
|
|
1165
1243
|
return false;
|
|
@@ -1199,19 +1277,19 @@ const install = async function() {
|
|
|
1199
1277
|
const {
|
|
1200
1278
|
options
|
|
1201
1279
|
} = getCommandOptions(args, installCommandArguments);
|
|
1202
|
-
const normalizedOptions = await normalize$
|
|
1280
|
+
const normalizedOptions = await normalize$9(options);
|
|
1203
1281
|
noop(normalizedOptions);
|
|
1204
|
-
const {
|
|
1205
|
-
|
|
1206
|
-
}
|
|
1207
|
-
const
|
|
1282
|
+
const appInfo = resolveAppInfo({
|
|
1283
|
+
appID: options.appID
|
|
1284
|
+
});
|
|
1285
|
+
const appID = appInfo.appID;
|
|
1208
1286
|
const manifestUrl = await getManifestUrl();
|
|
1209
1287
|
if (!manifestUrl) {
|
|
1210
|
-
console.log(`App "${
|
|
1288
|
+
console.log(`App "${appID}" server not available!`);
|
|
1211
1289
|
console.log('Use "ones dev" command or "ones tunnel" command to start the server first');
|
|
1212
1290
|
process.exit(1);
|
|
1213
1291
|
}
|
|
1214
|
-
await invokeInstall(manifestUrl);
|
|
1292
|
+
await invokeInstall(manifestUrl, appInfo);
|
|
1215
1293
|
};
|
|
1216
1294
|
var InstallOptions = /* @__PURE__ */ ((InstallOptions2) => {
|
|
1217
1295
|
InstallOptions2["AUTO"] = "auto";
|
|
@@ -1226,7 +1304,7 @@ var DevCommandScripts = /* @__PURE__ */ ((DevCommandScripts2) => {
|
|
|
1226
1304
|
return DevCommandScripts2;
|
|
1227
1305
|
})(DevCommandScripts || {});
|
|
1228
1306
|
const defaultInstall = InstallOptions.AUTO;
|
|
1229
|
-
const normalize$
|
|
1307
|
+
const normalize$8 = async (options) => {
|
|
1230
1308
|
var _options$install, _options$command, _options$clearStorage;
|
|
1231
1309
|
let install2 = (_options$install = options.install) !== null && _options$install !== void 0 ? _options$install : defaultInstall;
|
|
1232
1310
|
const command = (_options$command = options.command) !== null && _options$command !== void 0 ? _options$command : "";
|
|
@@ -1248,6 +1326,47 @@ const normalize$7 = async (options) => {
|
|
|
1248
1326
|
};
|
|
1249
1327
|
};
|
|
1250
1328
|
const IDLE_MS = 2e3;
|
|
1329
|
+
const WAIT_PORT_TIMEOUT_MS = 12e4;
|
|
1330
|
+
const WAIT_PORT_INTERVAL_MS = 500;
|
|
1331
|
+
const WAIT_PORT_CONNECT_TIMEOUT_MS = 1e3;
|
|
1332
|
+
const sleep$1 = (ms) => {
|
|
1333
|
+
return new Promise((resolve2) => {
|
|
1334
|
+
setTimeout(resolve2, ms);
|
|
1335
|
+
});
|
|
1336
|
+
};
|
|
1337
|
+
const canConnectPort = (port) => {
|
|
1338
|
+
return new Promise((resolve2) => {
|
|
1339
|
+
let settled = false;
|
|
1340
|
+
const socket = createConnection({
|
|
1341
|
+
host: "127.0.0.1",
|
|
1342
|
+
port
|
|
1343
|
+
});
|
|
1344
|
+
const done = (result) => {
|
|
1345
|
+
if (settled)
|
|
1346
|
+
return;
|
|
1347
|
+
settled = true;
|
|
1348
|
+
socket.removeAllListeners();
|
|
1349
|
+
socket.destroy();
|
|
1350
|
+
resolve2(result);
|
|
1351
|
+
};
|
|
1352
|
+
socket.setTimeout(WAIT_PORT_CONNECT_TIMEOUT_MS);
|
|
1353
|
+
socket.on("connect", () => done(true));
|
|
1354
|
+
socket.on("timeout", () => done(false));
|
|
1355
|
+
socket.on("error", () => done(false));
|
|
1356
|
+
});
|
|
1357
|
+
};
|
|
1358
|
+
const waitForPortReady = async function(port) {
|
|
1359
|
+
let timeoutMs = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : WAIT_PORT_TIMEOUT_MS;
|
|
1360
|
+
const startedAt = Date.now();
|
|
1361
|
+
while (Date.now() - startedAt < timeoutMs) {
|
|
1362
|
+
const connected = await canConnectPort(port);
|
|
1363
|
+
if (connected) {
|
|
1364
|
+
return true;
|
|
1365
|
+
}
|
|
1366
|
+
await sleep$1(WAIT_PORT_INTERVAL_MS);
|
|
1367
|
+
}
|
|
1368
|
+
return false;
|
|
1369
|
+
};
|
|
1251
1370
|
const dev = async function() {
|
|
1252
1371
|
var _appRcJSON$dev, _defaultAppRcJSON$dev, _appRcJSON$dev$comman, _appRcJSON$dev2, _currentCommand$;
|
|
1253
1372
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
@@ -1256,7 +1375,7 @@ const dev = async function() {
|
|
|
1256
1375
|
const {
|
|
1257
1376
|
options
|
|
1258
1377
|
} = getCommandOptions(args, devCommandArguments);
|
|
1259
|
-
const normalizedOptions = await normalize$
|
|
1378
|
+
const normalizedOptions = await normalize$8(options);
|
|
1260
1379
|
const appRcJSON = await getAppRcJSON();
|
|
1261
1380
|
const correctCommand = normalizedOptions.command || ((_appRcJSON$dev = appRcJSON.dev) === null || _appRcJSON$dev === void 0 || (_appRcJSON$dev = _appRcJSON$dev.command) === null || _appRcJSON$dev === void 0 ? void 0 : _appRcJSON$dev[0]) || ((_defaultAppRcJSON$dev = defaultAppRcJSON.dev) === null || _defaultAppRcJSON$dev === void 0 || (_defaultAppRcJSON$dev = _defaultAppRcJSON$dev.command) === null || _defaultAppRcJSON$dev === void 0 ? void 0 : _defaultAppRcJSON$dev[0]) || "";
|
|
1262
1381
|
if (!correctCommand) {
|
|
@@ -1290,6 +1409,10 @@ const dev = async function() {
|
|
|
1290
1409
|
app
|
|
1291
1410
|
} = appManifestJSON;
|
|
1292
1411
|
const appID = app.id;
|
|
1412
|
+
const appInfo = {
|
|
1413
|
+
appID: app.id,
|
|
1414
|
+
appName: app.name
|
|
1415
|
+
};
|
|
1293
1416
|
const config2 = getConfig();
|
|
1294
1417
|
const ONES_HOSTED_PORT = await getPort({
|
|
1295
1418
|
port: config2.defaultPort.hosted
|
|
@@ -1346,7 +1469,7 @@ const dev = async function() {
|
|
|
1346
1469
|
if (enableTunnel) {
|
|
1347
1470
|
switch (normalizedOptions.install) {
|
|
1348
1471
|
case InstallOptions.TRUE:
|
|
1349
|
-
await invokeInstall(manifestUrl);
|
|
1472
|
+
await invokeInstall(manifestUrl, appInfo);
|
|
1350
1473
|
break;
|
|
1351
1474
|
case InstallOptions.AUTO:
|
|
1352
1475
|
{
|
|
@@ -1356,7 +1479,7 @@ const dev = async function() {
|
|
|
1356
1479
|
if (installationID) {
|
|
1357
1480
|
await displayAppDetail(installationID);
|
|
1358
1481
|
} else {
|
|
1359
|
-
await invokeInstall(manifestUrl);
|
|
1482
|
+
await invokeInstall(manifestUrl, appInfo);
|
|
1360
1483
|
}
|
|
1361
1484
|
}
|
|
1362
1485
|
break;
|
|
@@ -1375,6 +1498,28 @@ const dev = async function() {
|
|
|
1375
1498
|
const createReadyStatusPipes = (onReady2) => {
|
|
1376
1499
|
let readyTimer = null;
|
|
1377
1500
|
let summaryPrinted = false;
|
|
1501
|
+
let readyInProgress = false;
|
|
1502
|
+
const printReady = async () => {
|
|
1503
|
+
if (summaryPrinted || readyInProgress) {
|
|
1504
|
+
return;
|
|
1505
|
+
}
|
|
1506
|
+
readyInProgress = true;
|
|
1507
|
+
try {
|
|
1508
|
+
if (templateCommand) {
|
|
1509
|
+
const ready = await waitForPortReady(ONES_HOSTED_PORT);
|
|
1510
|
+
if (!ready) {
|
|
1511
|
+
console.error(`Timed out waiting for local app server to listen on port ${ONES_HOSTED_PORT}.`);
|
|
1512
|
+
return;
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
if (!summaryPrinted) {
|
|
1516
|
+
summaryPrinted = true;
|
|
1517
|
+
await onReady2();
|
|
1518
|
+
}
|
|
1519
|
+
} finally {
|
|
1520
|
+
readyInProgress = false;
|
|
1521
|
+
}
|
|
1522
|
+
};
|
|
1378
1523
|
const scheduleReady = () => {
|
|
1379
1524
|
if (summaryPrinted)
|
|
1380
1525
|
return;
|
|
@@ -1382,10 +1527,9 @@ const dev = async function() {
|
|
|
1382
1527
|
clearTimeout(readyTimer);
|
|
1383
1528
|
readyTimer = setTimeout(() => {
|
|
1384
1529
|
readyTimer = null;
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
}
|
|
1530
|
+
printReady().catch((error) => {
|
|
1531
|
+
console.error(error);
|
|
1532
|
+
});
|
|
1389
1533
|
}, IDLE_MS);
|
|
1390
1534
|
};
|
|
1391
1535
|
const pipe2 = (stream, isStderr) => {
|
|
@@ -1457,7 +1601,7 @@ const sleep = (number) => {
|
|
|
1457
1601
|
};
|
|
1458
1602
|
const isURL = /^https?:\/\//;
|
|
1459
1603
|
const HostBlackList = ["ones.cn", "www.ones.cn", "ones.com", "www.ones.com"];
|
|
1460
|
-
const normalize$
|
|
1604
|
+
const normalize$7 = async (options) => {
|
|
1461
1605
|
const baseURLInput = options.baseURL;
|
|
1462
1606
|
if (baseURLInput)
|
|
1463
1607
|
;
|
|
@@ -1495,7 +1639,7 @@ const login = async function() {
|
|
|
1495
1639
|
const {
|
|
1496
1640
|
options
|
|
1497
1641
|
} = getCommandOptions(args, loginCommandArguments);
|
|
1498
|
-
const normalizedOptions = await normalize$
|
|
1642
|
+
const normalizedOptions = await normalize$7(options);
|
|
1499
1643
|
const {
|
|
1500
1644
|
code_verifier,
|
|
1501
1645
|
code_challenge
|
|
@@ -1648,7 +1792,7 @@ const login = async function() {
|
|
|
1648
1792
|
return throwError(ErrorCode.INCORRECT_BASE_URL, i18n.t("error.login.incorrectBaseURL"));
|
|
1649
1793
|
}
|
|
1650
1794
|
};
|
|
1651
|
-
const normalize$
|
|
1795
|
+
const normalize$6 = async (options) => {
|
|
1652
1796
|
noop(options);
|
|
1653
1797
|
return {};
|
|
1654
1798
|
};
|
|
@@ -1659,12 +1803,12 @@ const logout = async function() {
|
|
|
1659
1803
|
const {
|
|
1660
1804
|
options
|
|
1661
1805
|
} = getCommandOptions(args, logoutCommandArguments);
|
|
1662
|
-
const normalizedOptions = await normalize$
|
|
1806
|
+
const normalizedOptions = await normalize$6(options);
|
|
1663
1807
|
noop(normalizedOptions);
|
|
1664
1808
|
await setStore({});
|
|
1665
1809
|
console.log("Logged out successfully!");
|
|
1666
1810
|
};
|
|
1667
|
-
const normalize$
|
|
1811
|
+
const normalize$5 = async (options) => {
|
|
1668
1812
|
noop(options);
|
|
1669
1813
|
return {};
|
|
1670
1814
|
};
|
|
@@ -1676,7 +1820,7 @@ const whoami = async function() {
|
|
|
1676
1820
|
const {
|
|
1677
1821
|
options
|
|
1678
1822
|
} = getCommandOptions(args, whoamiCommandArguments);
|
|
1679
|
-
const normalizedOptions = await normalize$
|
|
1823
|
+
const normalizedOptions = await normalize$5(options);
|
|
1680
1824
|
noop(normalizedOptions);
|
|
1681
1825
|
const baseURL = await getBaseURL();
|
|
1682
1826
|
const cancelWaiting = startWaiting();
|
|
@@ -1692,9 +1836,12 @@ const whoami = async function() {
|
|
|
1692
1836
|
consoleUnauthorizedMessage();
|
|
1693
1837
|
}
|
|
1694
1838
|
};
|
|
1695
|
-
const normalize$
|
|
1839
|
+
const normalize$4 = async (options) => {
|
|
1840
|
+
var _options$appID;
|
|
1696
1841
|
noop(options);
|
|
1697
|
-
return {
|
|
1842
|
+
return {
|
|
1843
|
+
appID: (_options$appID = options.appID) !== null && _options$appID !== void 0 ? _options$appID : ""
|
|
1844
|
+
};
|
|
1698
1845
|
};
|
|
1699
1846
|
const enable = async function() {
|
|
1700
1847
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
@@ -1703,22 +1850,28 @@ const enable = async function() {
|
|
|
1703
1850
|
const {
|
|
1704
1851
|
options
|
|
1705
1852
|
} = getCommandOptions(args, enableCommandArguments);
|
|
1706
|
-
const normalizedOptions = await normalize$
|
|
1853
|
+
const normalizedOptions = await normalize$4(options);
|
|
1707
1854
|
noop(normalizedOptions);
|
|
1708
|
-
const
|
|
1855
|
+
const appInfo = resolveAppInfo({
|
|
1856
|
+
appID: options.appID
|
|
1857
|
+
});
|
|
1858
|
+
const appID = appInfo.appID;
|
|
1709
1859
|
const cancelWaiting = startWaiting();
|
|
1710
|
-
const result = await fetchAppEnable();
|
|
1860
|
+
const result = await fetchAppEnable(appID);
|
|
1711
1861
|
cancelWaiting();
|
|
1712
1862
|
if (result.code === "OK") {
|
|
1713
|
-
console.log(`App "${
|
|
1863
|
+
console.log(`App "${appID}" enabled successfully!`);
|
|
1714
1864
|
} else {
|
|
1715
|
-
console.log(`App "${
|
|
1865
|
+
console.log(`App "${appID}" enabled failed!`);
|
|
1716
1866
|
console.error(JSON.stringify(result, null, 2));
|
|
1717
1867
|
}
|
|
1718
1868
|
};
|
|
1719
|
-
const normalize$
|
|
1869
|
+
const normalize$3 = async (options) => {
|
|
1870
|
+
var _options$appID;
|
|
1720
1871
|
noop(options);
|
|
1721
|
-
return {
|
|
1872
|
+
return {
|
|
1873
|
+
appID: (_options$appID = options.appID) !== null && _options$appID !== void 0 ? _options$appID : ""
|
|
1874
|
+
};
|
|
1722
1875
|
};
|
|
1723
1876
|
const disable = async function() {
|
|
1724
1877
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
@@ -1727,22 +1880,28 @@ const disable = async function() {
|
|
|
1727
1880
|
const {
|
|
1728
1881
|
options
|
|
1729
1882
|
} = getCommandOptions(args, disableCommandArguments);
|
|
1730
|
-
const normalizedOptions = await normalize$
|
|
1883
|
+
const normalizedOptions = await normalize$3(options);
|
|
1731
1884
|
noop(normalizedOptions);
|
|
1732
|
-
const
|
|
1885
|
+
const appInfo = resolveAppInfo({
|
|
1886
|
+
appID: options.appID
|
|
1887
|
+
});
|
|
1888
|
+
const appID = appInfo.appID;
|
|
1733
1889
|
const cancelWaiting = startWaiting();
|
|
1734
|
-
const result = await fetchAppDisable();
|
|
1890
|
+
const result = await fetchAppDisable(appID);
|
|
1735
1891
|
cancelWaiting();
|
|
1736
1892
|
if (result.code === "OK") {
|
|
1737
|
-
console.log(`App "${
|
|
1893
|
+
console.log(`App "${appID}" disabled successfully!`);
|
|
1738
1894
|
} else {
|
|
1739
|
-
console.log(`App "${
|
|
1895
|
+
console.log(`App "${appID}" disabled failed!`);
|
|
1740
1896
|
console.error(JSON.stringify(result, null, 2));
|
|
1741
1897
|
}
|
|
1742
1898
|
};
|
|
1743
|
-
const normalize$
|
|
1899
|
+
const normalize$2 = async (options) => {
|
|
1900
|
+
var _options$appID;
|
|
1744
1901
|
noop(options);
|
|
1745
|
-
return {
|
|
1902
|
+
return {
|
|
1903
|
+
appID: (_options$appID = options.appID) !== null && _options$appID !== void 0 ? _options$appID : ""
|
|
1904
|
+
};
|
|
1746
1905
|
};
|
|
1747
1906
|
const uninstall = async function() {
|
|
1748
1907
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
@@ -1751,18 +1910,97 @@ const uninstall = async function() {
|
|
|
1751
1910
|
const {
|
|
1752
1911
|
options
|
|
1753
1912
|
} = getCommandOptions(args, uninstallCommandArguments);
|
|
1754
|
-
const normalizedOptions = await normalize$
|
|
1913
|
+
const normalizedOptions = await normalize$2(options);
|
|
1755
1914
|
noop(normalizedOptions);
|
|
1756
|
-
const
|
|
1915
|
+
const appInfo = resolveAppInfo({
|
|
1916
|
+
appID: options.appID
|
|
1917
|
+
});
|
|
1918
|
+
const appID = appInfo.appID;
|
|
1757
1919
|
const cancelWaiting = startWaiting();
|
|
1758
|
-
const result = await fetchAppUninstall();
|
|
1920
|
+
const result = await fetchAppUninstall(appID);
|
|
1759
1921
|
cancelWaiting();
|
|
1760
1922
|
if (result.code === "OK") {
|
|
1761
|
-
console.log(`App "${
|
|
1923
|
+
console.log(`App "${appID}" uninstalled successfully!`);
|
|
1762
1924
|
} else {
|
|
1763
|
-
console.log(`App "${
|
|
1925
|
+
console.log(`App "${appID}" uninstalled failed!`);
|
|
1926
|
+
console.error(JSON.stringify(result, null, 2));
|
|
1927
|
+
}
|
|
1928
|
+
};
|
|
1929
|
+
const defaultTail = 100;
|
|
1930
|
+
const normalize$1 = async (options) => {
|
|
1931
|
+
var _options$appID, _options$fromOpkxJson, _options$tail;
|
|
1932
|
+
const appID = (_options$appID = options.appID) !== null && _options$appID !== void 0 ? _options$appID : "";
|
|
1933
|
+
const fromOpkxJSON = (_options$fromOpkxJson = options.fromOpkxJson) !== null && _options$fromOpkxJson !== void 0 ? _options$fromOpkxJson : false;
|
|
1934
|
+
if (!appID && !fromOpkxJSON) {
|
|
1935
|
+
console.log('App id is required, use "ones app logs <app-id>" or "--from-opkx-json"');
|
|
1936
|
+
process.exit(1);
|
|
1937
|
+
}
|
|
1938
|
+
const appInfo = appID ? resolveAppInfo({
|
|
1939
|
+
appID
|
|
1940
|
+
}) : resolveAppInfo({});
|
|
1941
|
+
const tailString = (_options$tail = options.tail) !== null && _options$tail !== void 0 ? _options$tail : `${defaultTail}`;
|
|
1942
|
+
const tail = Number(tailString);
|
|
1943
|
+
if (!Number.isInteger(tail) || tail <= 0) {
|
|
1944
|
+
console.log("Tail should be a positive integer");
|
|
1945
|
+
process.exit(1);
|
|
1946
|
+
}
|
|
1947
|
+
return {
|
|
1948
|
+
appID: appInfo.appID,
|
|
1949
|
+
appName: appInfo.appName,
|
|
1950
|
+
tail
|
|
1951
|
+
};
|
|
1952
|
+
};
|
|
1953
|
+
const displayLogs = (data) => {
|
|
1954
|
+
if (Array.isArray(data)) {
|
|
1955
|
+
data.forEach((line) => {
|
|
1956
|
+
if (typeof line === "string") {
|
|
1957
|
+
console.log(line);
|
|
1958
|
+
} else {
|
|
1959
|
+
console.log(JSON.stringify(line, null, 2));
|
|
1960
|
+
}
|
|
1961
|
+
});
|
|
1962
|
+
return;
|
|
1963
|
+
}
|
|
1964
|
+
if (typeof data === "string") {
|
|
1965
|
+
console.log(data);
|
|
1966
|
+
return;
|
|
1967
|
+
}
|
|
1968
|
+
console.log(JSON.stringify(data !== null && data !== void 0 ? data : {}, null, 2));
|
|
1969
|
+
};
|
|
1970
|
+
const logs = async function() {
|
|
1971
|
+
var _appList$data;
|
|
1972
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1973
|
+
args[_key] = arguments[_key];
|
|
1974
|
+
}
|
|
1975
|
+
const {
|
|
1976
|
+
options
|
|
1977
|
+
} = getCommandOptions(args, logsCommandArguments);
|
|
1978
|
+
const normalizedOptions = await normalize$1(options);
|
|
1979
|
+
const {
|
|
1980
|
+
appID,
|
|
1981
|
+
tail
|
|
1982
|
+
} = normalizedOptions;
|
|
1983
|
+
const cancelWaiting = startWaiting();
|
|
1984
|
+
const appList = await fetchAppList(appID);
|
|
1985
|
+
const productionInstallation = (_appList$data = appList.data) === null || _appList$data === void 0 ? void 0 : _appList$data.find((item) => {
|
|
1986
|
+
return item.installation_id && item.app_env === "production";
|
|
1987
|
+
});
|
|
1988
|
+
if (!productionInstallation) {
|
|
1989
|
+
cancelWaiting();
|
|
1990
|
+
console.log(`App "${appID}" is not installed in production environment`);
|
|
1991
|
+
process.exit(1);
|
|
1992
|
+
}
|
|
1993
|
+
const result = await fetchAppRuntimeLogs({
|
|
1994
|
+
app_id: appID,
|
|
1995
|
+
tail
|
|
1996
|
+
});
|
|
1997
|
+
cancelWaiting();
|
|
1998
|
+
if (result.code && result.code !== "OK") {
|
|
1999
|
+
console.log(`App "${appID}" fetch logs failed!`);
|
|
1764
2000
|
console.error(JSON.stringify(result, null, 2));
|
|
2001
|
+
return;
|
|
1765
2002
|
}
|
|
2003
|
+
displayLogs(result.data);
|
|
1766
2004
|
};
|
|
1767
2005
|
const getTemplatePath = () => {
|
|
1768
2006
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
@@ -1833,24 +2071,28 @@ const whoamiCommandArguments = [];
|
|
|
1833
2071
|
const $whoami = new Command("whoami").description(i18n.t("desc.whoami")).action(whoami);
|
|
1834
2072
|
addCommandUsage($whoami);
|
|
1835
2073
|
addCommandOutput($whoami);
|
|
1836
|
-
const installCommandArguments = [];
|
|
1837
|
-
const $install = new Command("install").description(i18n.t("desc.install")).action(install);
|
|
2074
|
+
const installCommandArguments = ["appID"];
|
|
2075
|
+
const $install = new Command("install").description(i18n.t("desc.install")).argument("[app-id]", i18n.t("desc.app.appId")).action(install);
|
|
1838
2076
|
addCommandUsage($install);
|
|
1839
2077
|
addCommandOutput($install);
|
|
1840
|
-
const enableCommandArguments = [];
|
|
1841
|
-
const $enable = new Command("enable").description(i18n.t("desc.enable")).action(enable);
|
|
2078
|
+
const enableCommandArguments = ["appID"];
|
|
2079
|
+
const $enable = new Command("enable").description(i18n.t("desc.enable")).argument("[app-id]", i18n.t("desc.app.appId")).action(enable);
|
|
1842
2080
|
addCommandUsage($enable);
|
|
1843
2081
|
addCommandOutput($enable);
|
|
1844
|
-
const disableCommandArguments = [];
|
|
1845
|
-
const $disable = new Command("disable").description(i18n.t("desc.disable")).action(disable);
|
|
2082
|
+
const disableCommandArguments = ["appID"];
|
|
2083
|
+
const $disable = new Command("disable").description(i18n.t("desc.disable")).argument("[app-id]", i18n.t("desc.app.appId")).action(disable);
|
|
1846
2084
|
addCommandUsage($disable);
|
|
1847
2085
|
addCommandOutput($disable);
|
|
1848
|
-
const uninstallCommandArguments = [];
|
|
1849
|
-
const $uninstall = new Command("uninstall").description(i18n.t("desc.uninstall")).action(uninstall);
|
|
2086
|
+
const uninstallCommandArguments = ["appID"];
|
|
2087
|
+
const $uninstall = new Command("uninstall").description(i18n.t("desc.uninstall")).argument("[app-id]", i18n.t("desc.app.appId")).action(uninstall);
|
|
1850
2088
|
addCommandUsage($uninstall);
|
|
1851
2089
|
addCommandOutput($uninstall);
|
|
2090
|
+
const logsCommandArguments = ["appID"];
|
|
2091
|
+
const $logs = new Command("logs").description(i18n.t("desc.logs")).argument("[app-id]", i18n.t("desc.app.appId")).option("--from-opkx-json", i18n.t("desc.logs.fromOpkxJson")).option("-t, --tail [number]", i18n.t("desc.logs.tail")).action(logs);
|
|
2092
|
+
addCommandUsage($logs);
|
|
2093
|
+
addCommandOutput($logs);
|
|
1852
2094
|
const $app = new Command("app").description(i18n.t("desc.app"));
|
|
1853
|
-
$app.addCommand($install).addCommand($enable).addCommand($disable).addCommand($uninstall);
|
|
2095
|
+
$app.addCommand($install).addCommand($enable).addCommand($disable).addCommand($uninstall).addCommand($logs);
|
|
1854
2096
|
addCommandUsage($app);
|
|
1855
2097
|
addCommandOutput($app);
|
|
1856
2098
|
const legacyCommandArguments = ["projectPath"];
|