@ones-open/cli 1.0.1-7400.1962 → 1.0.1-8465.1987
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 +210 -66
- package/dist/index.js +212 -68
- package/dist/types/actions/disable/index.d.ts.map +1 -1
- package/dist/types/actions/enable/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.map +1 -1
- package/dist/types/actions/legacy/index.d.ts.map +1 -1
- package/dist/types/actions/legacy/normalize.d.ts.map +1 -1
- package/dist/types/actions/login/index.d.ts.map +1 -1
- package/dist/types/actions/tunnel/index.d.ts.map +1 -1
- package/dist/types/actions/tunnel/normalize.d.ts.map +1 -1
- package/dist/types/actions/tunnel/tunnel-client.d.ts.map +1 -1
- package/dist/types/actions/tunnel/tunnel.d.ts.map +1 -1
- package/dist/types/actions/tunnel/types.d.ts +1 -0
- package/dist/types/actions/tunnel/types.d.ts.map +1 -1
- package/dist/types/actions/tunnel/utils.d.ts +1 -1
- package/dist/types/actions/tunnel/utils.d.ts.map +1 -1
- package/dist/types/actions/uninstall/index.d.ts.map +1 -1
- package/dist/types/actions/whoami/index.d.ts.map +1 -1
- package/dist/types/command/dev/index.d.ts +1 -0
- package/dist/types/command/dev/index.d.ts.map +1 -1
- package/dist/types/command/legacy/index.d.ts +1 -1
- package/dist/types/command/legacy/index.d.ts.map +1 -1
- package/dist/types/command/tunnel/index.d.ts +1 -0
- package/dist/types/command/tunnel/index.d.ts.map +1 -1
- package/dist/types/common/error/utils.d.ts +1 -0
- package/dist/types/common/error/utils.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.map +1 -1
- package/dist/types/common/request/consts.d.ts +1 -1
- 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 +9 -3
- package/dist/types/common/request/types.d.ts.map +1 -1
- package/dist/types/common/request/utils.d.ts +2 -0
- package/dist/types/common/request/utils.d.ts.map +1 -1
- package/dist/types/common/template/index.d.ts +5 -0
- package/dist/types/common/template/index.d.ts.map +1 -0
- package/dist/types/common/template/utils.d.ts +3 -0
- package/dist/types/common/template/utils.d.ts.map +1 -0
- package/package.json +6 -3
- package/template/legacy/README.md +13 -0
- package/template/legacy/_backend_npmrc +5 -0
- package/template/legacy/_backend_tsconfig.json +23 -0
- package/template/legacy/_eslintignore +2 -0
- package/template/legacy/_eslintrc.js +97 -0
- package/template/legacy/_gitignore +21 -0
- package/template/legacy/_gitlab-ci.yml +3 -0
- package/template/legacy/_husky_pre-commit +1 -0
- package/template/legacy/_npmrc +5 -0
- package/template/legacy/_prettierignore +15 -0
- package/template/legacy/_prettierrc +6 -0
- package/template/legacy/_web_npmrc +5 -0
- package/template/legacy/_web_tsconfig.json +20 -0
- package/template/legacy/backend/package.json +10 -0
- package/template/legacy/backend/src/index.ts +139 -0
- package/template/legacy/backend/src/ones.d.ts +6 -0
- package/template/legacy/config/ci-deploy.yaml +11 -0
- package/template/legacy/config/local.yaml +30 -0
- package/template/legacy/config/plugin.yaml +25 -0
- package/template/legacy/config/upgrade.yaml +8 -0
- package/template/legacy/op.config.mjs +4 -0
- package/template/legacy/package-lock.json +17446 -0
- package/template/legacy/package.json +73 -0
- package/template/legacy/web/browserslist +4 -0
- package/template/legacy/web/package.json +29 -0
- package/template/legacy/web/public/logo.svg +5 -0
- package/template/legacy/workspace/plugin.sql +2 -0
package/dist/index.cjs
CHANGED
|
@@ -9,6 +9,7 @@ const node_fs = require("node:fs");
|
|
|
9
9
|
const fse = require("fs-extra");
|
|
10
10
|
const archiver = require("archiver");
|
|
11
11
|
const lodashEs = require("lodash-es");
|
|
12
|
+
const chalk = require("chalk");
|
|
12
13
|
const process$1 = require("node:process");
|
|
13
14
|
const node_url = require("node:url");
|
|
14
15
|
const cosmiconfig = require("cosmiconfig");
|
|
@@ -17,9 +18,9 @@ const envPaths = require("env-paths");
|
|
|
17
18
|
const zod = require("zod");
|
|
18
19
|
const axios = require("axios");
|
|
19
20
|
const _reduceInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/reduce");
|
|
21
|
+
const ora = require("ora");
|
|
20
22
|
const WebSocket = require("ws");
|
|
21
23
|
const http = require("node:http");
|
|
22
|
-
const ora = require("ora");
|
|
23
24
|
const open = require("open");
|
|
24
25
|
const uuid = require("uuid");
|
|
25
26
|
var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
|
|
@@ -30,6 +31,7 @@ const en = {
|
|
|
30
31
|
"desc.dev": "Start your local development server and connect to ONES",
|
|
31
32
|
"desc.dev.install": "Install your ONES App after the server is ready",
|
|
32
33
|
"desc.dev.command": "Specify the dev command",
|
|
34
|
+
"desc.dev.useStorage": "Use hosted storage ability",
|
|
33
35
|
"desc.tunnel": "Start a tunnel to connect your local server with ONES",
|
|
34
36
|
"desc.tunnel.port": "Specify the port number for tunnel",
|
|
35
37
|
"desc.login": "Log in to your ONES account",
|
|
@@ -42,6 +44,8 @@ const en = {
|
|
|
42
44
|
"desc.disable": "Disable your ONES App",
|
|
43
45
|
"desc.uninstall": "Uninstall your ONES App",
|
|
44
46
|
"desc.legacy": "Legacy command",
|
|
47
|
+
"desc.legacy.create": "Create a new ONES plugin",
|
|
48
|
+
"desc.legacy.create.projectPath": "Specify the project path",
|
|
45
49
|
"error.login.missingBaseURL": "Missing base URL",
|
|
46
50
|
"error.login.incorrectBaseURL": "Incorrect base URL",
|
|
47
51
|
"error.tunnel.missingPort": "Missing port",
|
|
@@ -53,7 +57,8 @@ const en = {
|
|
|
53
57
|
"error.dev.incorrectCommand": "Incorrect dev command",
|
|
54
58
|
"error.store.permission": 'Permission denied, please check the file permission with "{filePath}"',
|
|
55
59
|
"error.hostedToken.requestFailed": "Failed to request hosted token",
|
|
56
|
-
"error.hostedToken.empty": "Hosted token is empty"
|
|
60
|
+
"error.hostedToken.empty": "Hosted token is empty",
|
|
61
|
+
"error.legacy.create.missingProjectPath": "Project path is required"
|
|
57
62
|
};
|
|
58
63
|
const map = {
|
|
59
64
|
en
|
|
@@ -82,6 +87,10 @@ const translate = (key, params) => {
|
|
|
82
87
|
const i18n = {
|
|
83
88
|
t: translate
|
|
84
89
|
};
|
|
90
|
+
const throwWarning = (code, message) => {
|
|
91
|
+
const text = `${message.trim().replace(/\s+$/, "")}[${code}]`;
|
|
92
|
+
console.warn(chalk.yellow(text));
|
|
93
|
+
};
|
|
85
94
|
var ErrorCode = ((ErrorCode2) => {
|
|
86
95
|
ErrorCode2[ErrorCode2["UNKNOWN_ERROR"] = createOnesApp.ErrorCode.UNKNOWN_ERROR] = "UNKNOWN_ERROR";
|
|
87
96
|
ErrorCode2[ErrorCode2["COMMAND_ERROR"] = createOnesApp.ErrorCode.COMMAND_ERROR] = "COMMAND_ERROR";
|
|
@@ -142,17 +151,32 @@ const getAppPackageJSON = () => {
|
|
|
142
151
|
const getAppManifestJSONPath = () => {
|
|
143
152
|
return node_path.join(process$1.cwd(), createOnesApp.PUBLIC_FILENAME.MANIFEST);
|
|
144
153
|
};
|
|
154
|
+
let cacheAppManifestJSON = null;
|
|
155
|
+
let hasWarnedAppManifestParseError = false;
|
|
145
156
|
const getAppManifestJSON = () => {
|
|
157
|
+
if (cacheAppManifestJSON) {
|
|
158
|
+
return cacheAppManifestJSON;
|
|
159
|
+
}
|
|
146
160
|
const path = getAppManifestJSONPath();
|
|
161
|
+
let json;
|
|
147
162
|
try {
|
|
148
163
|
const string = node_fs.readFileSync(path, {
|
|
149
164
|
encoding: "utf8"
|
|
150
165
|
});
|
|
151
|
-
|
|
152
|
-
|
|
166
|
+
json = JSON.parse(string);
|
|
167
|
+
cacheAppManifestJSON = createOnesApp.AppManifestJSONSchema.parse(json);
|
|
168
|
+
return cacheAppManifestJSON;
|
|
153
169
|
} catch (error) {
|
|
154
170
|
const details = error instanceof Error ? error.message : String(error);
|
|
155
|
-
|
|
171
|
+
if (json === void 0) {
|
|
172
|
+
return createOnesApp.throwError(ErrorCode.APP_MANIFEST_JSON_PARSE_ERROR, `${i18n.t("error.schema.app.manifest.parseError")}: ${details}`);
|
|
173
|
+
}
|
|
174
|
+
if (!hasWarnedAppManifestParseError) {
|
|
175
|
+
throwWarning(ErrorCode.APP_MANIFEST_JSON_PARSE_ERROR, `${i18n.t("error.schema.app.manifest.parseError")}: ${details}. Please check for this error or upgrade your ONES CLI to the latest version.`);
|
|
176
|
+
hasWarnedAppManifestParseError = true;
|
|
177
|
+
}
|
|
178
|
+
cacheAppManifestJSON = json;
|
|
179
|
+
return cacheAppManifestJSON;
|
|
156
180
|
}
|
|
157
181
|
};
|
|
158
182
|
const defaultDevCommand = ["npm", "run", "dev"];
|
|
@@ -287,7 +311,7 @@ const build = async function() {
|
|
|
287
311
|
cwd: getAppWorkspacePath()
|
|
288
312
|
});
|
|
289
313
|
});
|
|
290
|
-
archive.file(createOnesApp.PUBLIC_FILENAME.MANIFEST, {
|
|
314
|
+
archive.file(node_path.join(getAppWorkspacePath(), createOnesApp.PUBLIC_FILENAME.MANIFEST), {
|
|
291
315
|
name: createOnesApp.PUBLIC_FILENAME.MANIFEST
|
|
292
316
|
});
|
|
293
317
|
archive.finalize();
|
|
@@ -414,15 +438,15 @@ const setHostToken = async (token) => {
|
|
|
414
438
|
const API = {
|
|
415
439
|
TOKEN_INFO: "/project/api/project/auth/token_info",
|
|
416
440
|
HOSTED_TOKEN: "/platform/runtime_manager/hosted_token",
|
|
417
|
-
HOSTED_ABILITY_STORAGE_DEV_DECLARE: "/platform/runtime_manager/hosted_ability/storage/dev_declare",
|
|
441
|
+
HOSTED_ABILITY_STORAGE_DEV_DECLARE: "/platform/runtime_manager/hosted_ability/storage/:appID/dev_declare",
|
|
418
442
|
APP_LIST: "/platform/api/app/list",
|
|
419
443
|
APP_INSTALL: "/platform/api/app/install",
|
|
420
|
-
APP_UPGRADE: "/platform/api/app/upgrade",
|
|
444
|
+
APP_UPGRADE: "/platform/api/app/:installation_id/upgrade",
|
|
421
445
|
APP_UNINSTALL: "/platform/api/app/:installation_id/uninstall",
|
|
422
446
|
APP_ENABLE: "/platform/api/app/:installation_id/enable",
|
|
423
447
|
APP_DISABLE: "/platform/api/app/:installation_id/disable"
|
|
424
448
|
};
|
|
425
|
-
const REQUEST_TIMEOUT =
|
|
449
|
+
const REQUEST_TIMEOUT = 5e3;
|
|
426
450
|
const getPath = (path, map2) => {
|
|
427
451
|
var _context;
|
|
428
452
|
return _reduceInstanceProperty(_context = path.split("/")).call(_context, (base, part) => {
|
|
@@ -449,6 +473,16 @@ const getURL = async (path, pathMap, queryMap) => {
|
|
|
449
473
|
}
|
|
450
474
|
consoleUnauthorizedMessage();
|
|
451
475
|
};
|
|
476
|
+
const getHostedFetchHeaders = async (value) => {
|
|
477
|
+
const hostedToken = await getHostToken();
|
|
478
|
+
if (hostedToken) {
|
|
479
|
+
return lodashEs.merge({
|
|
480
|
+
Authorization: `Bearer ${hostedToken}`
|
|
481
|
+
}, value);
|
|
482
|
+
}
|
|
483
|
+
consoleUnauthorizedMessage();
|
|
484
|
+
process.exit(1);
|
|
485
|
+
};
|
|
452
486
|
const getHeaders = async (value) => {
|
|
453
487
|
const token = await getONESToken();
|
|
454
488
|
if (token) {
|
|
@@ -477,6 +511,21 @@ const handleError = (error) => {
|
|
|
477
511
|
console.error(error);
|
|
478
512
|
return {};
|
|
479
513
|
};
|
|
514
|
+
const startWaiting = () => {
|
|
515
|
+
const time = 3e3;
|
|
516
|
+
let spinner = null;
|
|
517
|
+
const sid = setTimeout(() => {
|
|
518
|
+
spinner = ora("Waiting for response...");
|
|
519
|
+
spinner.start();
|
|
520
|
+
}, time);
|
|
521
|
+
const cancelWaiting = () => {
|
|
522
|
+
clearTimeout(sid);
|
|
523
|
+
if (spinner) {
|
|
524
|
+
spinner.stop();
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
return cancelWaiting;
|
|
528
|
+
};
|
|
480
529
|
const fetchAppBase = async (params) => {
|
|
481
530
|
var _params$url;
|
|
482
531
|
const url = await getURL((_params$url = params.url) !== null && _params$url !== void 0 ? _params$url : "", params.pathMap, params.queryMap);
|
|
@@ -489,6 +538,18 @@ const fetchAppBase = async (params) => {
|
|
|
489
538
|
});
|
|
490
539
|
return response.data;
|
|
491
540
|
};
|
|
541
|
+
const fetchHostedAbilityBase = async (params) => {
|
|
542
|
+
var _params$url2;
|
|
543
|
+
const url = await getURL((_params$url2 = params.url) !== null && _params$url2 !== void 0 ? _params$url2 : "", params.pathMap, params.queryMap);
|
|
544
|
+
const headers = await getHostedFetchHeaders(params.headers);
|
|
545
|
+
const response = await axios({
|
|
546
|
+
...params,
|
|
547
|
+
url,
|
|
548
|
+
headers,
|
|
549
|
+
timeout: REQUEST_TIMEOUT
|
|
550
|
+
});
|
|
551
|
+
return response.data;
|
|
552
|
+
};
|
|
492
553
|
const fetchAppList = async (appID) => {
|
|
493
554
|
return await fetchAppBase({
|
|
494
555
|
url: API.APP_LIST,
|
|
@@ -511,10 +572,13 @@ const fetchHostedToken = async (data) => {
|
|
|
511
572
|
data
|
|
512
573
|
}).catch(handleError);
|
|
513
574
|
};
|
|
514
|
-
const fetchHostedAbilityStorageDevDeclare = async (data) => {
|
|
515
|
-
return await
|
|
575
|
+
const fetchHostedAbilityStorageDevDeclare = async (appID, data) => {
|
|
576
|
+
return await fetchHostedAbilityBase({
|
|
516
577
|
url: API.HOSTED_ABILITY_STORAGE_DEV_DECLARE,
|
|
517
578
|
method: "POST",
|
|
579
|
+
pathMap: {
|
|
580
|
+
appID
|
|
581
|
+
},
|
|
518
582
|
data
|
|
519
583
|
}).catch(handleError);
|
|
520
584
|
};
|
|
@@ -523,9 +587,18 @@ const fetchAppInstall = async (data) => {
|
|
|
523
587
|
const appID = getAppManifestJSON().app.id;
|
|
524
588
|
const appList = await fetchAppList(appID);
|
|
525
589
|
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 : "";
|
|
526
|
-
|
|
590
|
+
if (installationID) {
|
|
591
|
+
return await fetchAppBase({
|
|
592
|
+
url: API.APP_UPGRADE,
|
|
593
|
+
method: "POST",
|
|
594
|
+
pathMap: {
|
|
595
|
+
installation_id: installationID
|
|
596
|
+
},
|
|
597
|
+
data
|
|
598
|
+
}).catch(handleError);
|
|
599
|
+
}
|
|
527
600
|
return await fetchAppBase({
|
|
528
|
-
url,
|
|
601
|
+
url: API.APP_INSTALL,
|
|
529
602
|
method: "POST",
|
|
530
603
|
data
|
|
531
604
|
}).catch(handleError);
|
|
@@ -606,6 +679,7 @@ const MANIFEST_PATH = "/manifest";
|
|
|
606
679
|
const ONES_CLI_INTERNAL_MANIFEST_PATH = "/__ones_cli_internal_manifest__";
|
|
607
680
|
const MAX_RELAY_BODY_BYTES = 64 * 1024 * 1024;
|
|
608
681
|
const normalize$9 = async (options) => {
|
|
682
|
+
var _options$useStorage;
|
|
609
683
|
const portInput = options.port;
|
|
610
684
|
if (portInput)
|
|
611
685
|
;
|
|
@@ -624,7 +698,8 @@ const normalize$9 = async (options) => {
|
|
|
624
698
|
}
|
|
625
699
|
const port = portString;
|
|
626
700
|
return {
|
|
627
|
-
port
|
|
701
|
+
port,
|
|
702
|
+
useStorage: (_options$useStorage = options.useStorage) !== null && _options$useStorage !== void 0 ? _options$useStorage : false
|
|
628
703
|
};
|
|
629
704
|
};
|
|
630
705
|
const getTunnelContext = async () => {
|
|
@@ -646,7 +721,7 @@ const getTunnelContext = async () => {
|
|
|
646
721
|
consoleUnauthorizedMessage();
|
|
647
722
|
process.exit(1);
|
|
648
723
|
};
|
|
649
|
-
const
|
|
724
|
+
const getStorageTokenScopes = (ones2) => {
|
|
650
725
|
const storage = ones2 === null || ones2 === void 0 ? void 0 : ones2.storage;
|
|
651
726
|
if (!storage) {
|
|
652
727
|
return [];
|
|
@@ -768,14 +843,16 @@ class TunnelClient {
|
|
|
768
843
|
};
|
|
769
844
|
this.sendBinaryEnvelope(reply);
|
|
770
845
|
} catch (error) {
|
|
846
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
847
|
+
console.error("Error forwarding request:", errorMessage);
|
|
771
848
|
const reply = {
|
|
772
849
|
id: message.id,
|
|
773
850
|
payload: {
|
|
774
851
|
status: 500,
|
|
775
852
|
headers: {
|
|
776
|
-
"x-agent-error": [
|
|
853
|
+
"x-agent-error": [errorMessage]
|
|
777
854
|
},
|
|
778
|
-
body:
|
|
855
|
+
body: errorMessage
|
|
779
856
|
}
|
|
780
857
|
};
|
|
781
858
|
this.sendBinaryEnvelope(reply);
|
|
@@ -925,7 +1002,7 @@ class TunnelClient {
|
|
|
925
1002
|
}
|
|
926
1003
|
}
|
|
927
1004
|
const invokeTunnel = async function(port) {
|
|
928
|
-
var _options$rebuildWhenE, _options$enableIntern, _hostedTokenResponse
|
|
1005
|
+
var _options$rebuildWhenE, _options$enableIntern, _options$useStorageFo, _hostedTokenResponse$, _appManifestJSON$ones, _appManifestJSON$ones2;
|
|
929
1006
|
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
930
1007
|
const {
|
|
931
1008
|
appManifestJSON,
|
|
@@ -934,21 +1011,29 @@ const invokeTunnel = async function(port) {
|
|
|
934
1011
|
} = await getTunnelContext();
|
|
935
1012
|
const rebuildWhenExists = (_options$rebuildWhenE = options.rebuildWhenExists) !== null && _options$rebuildWhenE !== void 0 ? _options$rebuildWhenE : true;
|
|
936
1013
|
const enableInternalManifestRoute = (_options$enableIntern = options.enableInternalManifestRoute) !== null && _options$enableIntern !== void 0 ? _options$enableIntern : true;
|
|
937
|
-
const storageScopes =
|
|
1014
|
+
const storageScopes = getStorageTokenScopes(appManifestJSON.ones);
|
|
938
1015
|
const scopes = Array.from(/* @__PURE__ */ new Set([...storageScopes, getRelayScope()]));
|
|
939
1016
|
const hostedTokenResponse = await fetchHostedToken({
|
|
940
1017
|
app_id: appID,
|
|
941
|
-
scopes
|
|
1018
|
+
scopes,
|
|
1019
|
+
confirm_for_dev: (_options$useStorageFo = options.useStorageForDev) !== null && _options$useStorageFo !== void 0 ? _options$useStorageFo : false
|
|
942
1020
|
});
|
|
943
1021
|
const hostedToken = hostedTokenResponse === null || hostedTokenResponse === void 0 || (_hostedTokenResponse$ = hostedTokenResponse.data) === null || _hostedTokenResponse$ === void 0 ? void 0 : _hostedTokenResponse$.hosted_token;
|
|
944
1022
|
if (!hostedToken) {
|
|
945
1023
|
return createOnesApp.throwError(ErrorCode.HOSTED_TOKEN_EMPTY, i18n.t("error.hostedToken.empty"));
|
|
946
1024
|
}
|
|
947
1025
|
await setHostToken(hostedToken);
|
|
1026
|
+
const entities = (_appManifestJSON$ones = (_appManifestJSON$ones2 = appManifestJSON.ones) === null || _appManifestJSON$ones2 === void 0 || (_appManifestJSON$ones2 = _appManifestJSON$ones2.storage) === null || _appManifestJSON$ones2 === void 0 ? void 0 : _appManifestJSON$ones2.entities) !== null && _appManifestJSON$ones !== void 0 ? _appManifestJSON$ones : [];
|
|
1027
|
+
if (entities.length > 0) {
|
|
1028
|
+
await fetchHostedAbilityStorageDevDeclare(appID, {
|
|
1029
|
+
opkx_content: appManifestJSON
|
|
1030
|
+
});
|
|
1031
|
+
}
|
|
948
1032
|
const client = new TunnelClient(port, regionURL, appID, hostedToken, enableInternalManifestRoute, rebuildWhenExists);
|
|
949
1033
|
await client.connect();
|
|
950
1034
|
};
|
|
951
1035
|
const tunnel = async function() {
|
|
1036
|
+
var _normalizedOptions$us;
|
|
952
1037
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
953
1038
|
args[_key] = arguments[_key];
|
|
954
1039
|
}
|
|
@@ -957,12 +1042,15 @@ const tunnel = async function() {
|
|
|
957
1042
|
} = createOnesApp.getCommandOptions(args, tunnelCommandArguments);
|
|
958
1043
|
const normalizedOptions = await normalize$9(options);
|
|
959
1044
|
const port = Number(normalizedOptions.port);
|
|
1045
|
+
const cancelWaiting = startWaiting();
|
|
960
1046
|
await invokeTunnel(port, {
|
|
961
1047
|
enableInternalManifestRoute: false,
|
|
962
|
-
rebuildWhenExists: true
|
|
1048
|
+
rebuildWhenExists: true,
|
|
1049
|
+
useStorageForDev: (_normalizedOptions$us = normalizedOptions.useStorage) !== null && _normalizedOptions$us !== void 0 ? _normalizedOptions$us : false
|
|
963
1050
|
});
|
|
964
|
-
|
|
965
|
-
|
|
1051
|
+
cancelWaiting();
|
|
1052
|
+
const tunnelUrl = await buildTunnelUrl();
|
|
1053
|
+
console.log(`Relay endpoint: ${tunnelUrl}`);
|
|
966
1054
|
};
|
|
967
1055
|
const normalize$8 = async (options) => {
|
|
968
1056
|
lodashEs.noop(options);
|
|
@@ -990,12 +1078,14 @@ const invokeInstall = async (manifestUrl) => {
|
|
|
990
1078
|
} = getAppManifestJSON();
|
|
991
1079
|
const appName = app.name;
|
|
992
1080
|
const appID = app.id;
|
|
1081
|
+
const cancelWaiting = startWaiting();
|
|
993
1082
|
const result = await fetchAppInstall({
|
|
994
1083
|
manifest_url: manifestUrl,
|
|
995
1084
|
options: {
|
|
996
1085
|
enable: true
|
|
997
1086
|
}
|
|
998
1087
|
});
|
|
1088
|
+
cancelWaiting();
|
|
999
1089
|
if (result.code === "OK") {
|
|
1000
1090
|
var _appList$data$0$insta, _appList$data;
|
|
1001
1091
|
console.log(`App "${appName}" installed successfully!`);
|
|
@@ -1012,10 +1102,12 @@ const invokeInstall = async (manifestUrl) => {
|
|
|
1012
1102
|
return false;
|
|
1013
1103
|
};
|
|
1014
1104
|
const getManifestUrl = async () => {
|
|
1015
|
-
const
|
|
1016
|
-
const customManifestUrl = `${
|
|
1017
|
-
const internalManifestUrl = `${
|
|
1018
|
-
const internalResult = await axios.get(internalManifestUrl
|
|
1105
|
+
const tunnelUrl = await buildTunnelUrl();
|
|
1106
|
+
const customManifestUrl = `${tunnelUrl}${MANIFEST_PATH}`;
|
|
1107
|
+
const internalManifestUrl = `${tunnelUrl}${ONES_CLI_INTERNAL_MANIFEST_PATH}`;
|
|
1108
|
+
const internalResult = await axios.get(internalManifestUrl, {
|
|
1109
|
+
timeout: REQUEST_TIMEOUT
|
|
1110
|
+
}).then((response) => {
|
|
1019
1111
|
if (response.status === 200) {
|
|
1020
1112
|
return internalManifestUrl;
|
|
1021
1113
|
}
|
|
@@ -1024,7 +1116,9 @@ const getManifestUrl = async () => {
|
|
|
1024
1116
|
if (internalResult) {
|
|
1025
1117
|
return internalResult;
|
|
1026
1118
|
}
|
|
1027
|
-
const customResult = await axios.get(customManifestUrl
|
|
1119
|
+
const customResult = await axios.get(customManifestUrl, {
|
|
1120
|
+
timeout: REQUEST_TIMEOUT
|
|
1121
|
+
}).then((response) => {
|
|
1028
1122
|
if (response.status === 200) {
|
|
1029
1123
|
return customManifestUrl;
|
|
1030
1124
|
}
|
|
@@ -1070,22 +1164,22 @@ var InstallOptions = /* @__PURE__ */ ((InstallOptions2) => {
|
|
|
1070
1164
|
})(InstallOptions || {});
|
|
1071
1165
|
const defaultInstall = InstallOptions.AUTO;
|
|
1072
1166
|
const normalize$7 = async (options) => {
|
|
1073
|
-
var _options$install, _options$command;
|
|
1167
|
+
var _options$install, _options$command, _options$useStorage;
|
|
1074
1168
|
let install2 = (_options$install = options.install) !== null && _options$install !== void 0 ? _options$install : defaultInstall;
|
|
1075
1169
|
const command = (_options$command = options.command) !== null && _options$command !== void 0 ? _options$command : "";
|
|
1076
1170
|
switch (true) {
|
|
1077
1171
|
case install2 === InstallOptions.AUTO:
|
|
1078
1172
|
break;
|
|
1079
|
-
case
|
|
1080
|
-
install2 = InstallOptions.TRUE;
|
|
1173
|
+
case install2 === InstallOptions.FALSE:
|
|
1081
1174
|
break;
|
|
1082
1175
|
default:
|
|
1083
|
-
install2 = InstallOptions.
|
|
1176
|
+
install2 = InstallOptions.TRUE;
|
|
1084
1177
|
break;
|
|
1085
1178
|
}
|
|
1086
1179
|
return {
|
|
1087
1180
|
install: install2,
|
|
1088
|
-
command
|
|
1181
|
+
command,
|
|
1182
|
+
useStorage: (_options$useStorage = options.useStorage) !== null && _options$useStorage !== void 0 ? _options$useStorage : false
|
|
1089
1183
|
};
|
|
1090
1184
|
};
|
|
1091
1185
|
const IDLE_MS = 2e3;
|
|
@@ -1132,7 +1226,6 @@ const dev = async function() {
|
|
|
1132
1226
|
} = createOnesApp.getCommandOptions(args, devCommandArguments);
|
|
1133
1227
|
const normalizedOptions = await normalize$7(options);
|
|
1134
1228
|
const appRcJSON = await getAppRcJSON();
|
|
1135
|
-
const appPackageJSON = getAppPackageJSON();
|
|
1136
1229
|
const firstCommand = 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]) || "";
|
|
1137
1230
|
if (!firstCommand) {
|
|
1138
1231
|
return createOnesApp.throwError(ErrorCode.INCORRECT_DEV_COMMAND, i18n.t("error.dev.incorrectCommand"));
|
|
@@ -1140,22 +1233,18 @@ const dev = async function() {
|
|
|
1140
1233
|
const currentCommand = normalizedOptions.command ? normalizedOptions.command.split(" ") : (_appRcJSON$dev$comman = (_appRcJSON$dev2 = appRcJSON.dev) === null || _appRcJSON$dev2 === void 0 ? void 0 : _appRcJSON$dev2.command) !== null && _appRcJSON$dev$comman !== void 0 ? _appRcJSON$dev$comman : [];
|
|
1141
1234
|
const currentCommandString = currentCommand.join(" ");
|
|
1142
1235
|
const defaultDevCommandString = defaultDevCommand.join(" ");
|
|
1143
|
-
if (
|
|
1144
|
-
|
|
1145
|
-
if (
|
|
1146
|
-
|
|
1236
|
+
if (firstCommand === "npm") {
|
|
1237
|
+
const appPackageJSON = getAppPackageJSON();
|
|
1238
|
+
if (currentCommandString === defaultDevCommandString) {
|
|
1239
|
+
var _appPackageJSON$scrip;
|
|
1240
|
+
if (!((_appPackageJSON$scrip = appPackageJSON.scripts) !== null && _appPackageJSON$scrip !== void 0 && _appPackageJSON$scrip.dev)) {
|
|
1241
|
+
return createOnesApp.throwError(ErrorCode.DEV_SCRIPT_NOT_FOUND, i18n.t("error.dev.scriptNotFound"));
|
|
1242
|
+
}
|
|
1147
1243
|
}
|
|
1148
1244
|
}
|
|
1149
|
-
let enableTunnel = true;
|
|
1150
|
-
if (normalizedOptions.install === InstallOptions.TRUE)
|
|
1151
|
-
;
|
|
1152
|
-
else {
|
|
1153
|
-
enableTunnel = await checkTokenInfo();
|
|
1154
|
-
}
|
|
1155
1245
|
const appManifestJSON = getAppManifestJSON();
|
|
1156
1246
|
const {
|
|
1157
|
-
app
|
|
1158
|
-
ones: ones2
|
|
1247
|
+
app
|
|
1159
1248
|
} = appManifestJSON;
|
|
1160
1249
|
const appID = app.id;
|
|
1161
1250
|
const config2 = getConfig();
|
|
@@ -1174,11 +1263,19 @@ const dev = async function() {
|
|
|
1174
1263
|
ONES_HOSTED_APP_ID: "",
|
|
1175
1264
|
ONES_HOSTED_BASE_URL: ""
|
|
1176
1265
|
};
|
|
1266
|
+
const cancelWaiting = startWaiting();
|
|
1267
|
+
let enableTunnel = true;
|
|
1268
|
+
if (normalizedOptions.install === InstallOptions.TRUE)
|
|
1269
|
+
;
|
|
1270
|
+
else {
|
|
1271
|
+
enableTunnel = await checkTokenInfo();
|
|
1272
|
+
}
|
|
1177
1273
|
if (enableTunnel) {
|
|
1178
|
-
var
|
|
1274
|
+
var _normalizedOptions$us;
|
|
1179
1275
|
await invokeTunnel(ONES_HOSTED_PORT, {
|
|
1180
1276
|
enableInternalManifestRoute: true,
|
|
1181
|
-
rebuildWhenExists: true
|
|
1277
|
+
rebuildWhenExists: true,
|
|
1278
|
+
useStorageForDev: (_normalizedOptions$us = normalizedOptions.useStorage) !== null && _normalizedOptions$us !== void 0 ? _normalizedOptions$us : false
|
|
1182
1279
|
});
|
|
1183
1280
|
const regionURL = await getRegionURL();
|
|
1184
1281
|
const ONES_HOSTED_TOKEN = await getHostToken();
|
|
@@ -1187,24 +1284,19 @@ const dev = async function() {
|
|
|
1187
1284
|
env2.ONES_HOSTED_TOKEN = ONES_HOSTED_TOKEN;
|
|
1188
1285
|
env2.ONES_HOSTED_APP_ID = ONES_HOSTED_APP_ID;
|
|
1189
1286
|
env2.ONES_HOSTED_BASE_URL = ONES_HOSTED_BASE_URL;
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
await fetchHostedAbilityStorageDevDeclare({
|
|
1193
|
-
app_id: appID,
|
|
1194
|
-
cleanup_legacy: false,
|
|
1195
|
-
opkx_content: appManifestJSON
|
|
1196
|
-
});
|
|
1197
|
-
}
|
|
1287
|
+
} else {
|
|
1288
|
+
console.log("Not logged in or session expired, skipping tunnel connection...");
|
|
1198
1289
|
}
|
|
1290
|
+
cancelWaiting();
|
|
1199
1291
|
const onReady = async () => {
|
|
1200
1292
|
const appName = app.name;
|
|
1201
1293
|
let manifestUrl = "";
|
|
1202
1294
|
console.log("");
|
|
1203
1295
|
console.log(`Local: http://localhost:${ONES_HOSTED_PORT}`);
|
|
1204
1296
|
if (enableTunnel) {
|
|
1205
|
-
const
|
|
1206
|
-
console.log(`URL: ${
|
|
1207
|
-
manifestUrl = `${
|
|
1297
|
+
const tunnelUrl = await buildTunnelUrl();
|
|
1298
|
+
console.log(`URL: ${tunnelUrl}`);
|
|
1299
|
+
manifestUrl = `${tunnelUrl}${ONES_CLI_INTERNAL_MANIFEST_PATH}`;
|
|
1208
1300
|
}
|
|
1209
1301
|
console.log("Docs site: https://open.ones.com");
|
|
1210
1302
|
console.log(`App "${appName}" server is ready!`);
|
|
@@ -1397,6 +1489,15 @@ const login = async function() {
|
|
|
1397
1489
|
}
|
|
1398
1490
|
process$1.exit(0);
|
|
1399
1491
|
});
|
|
1492
|
+
let exited = false;
|
|
1493
|
+
const handleExit = () => {
|
|
1494
|
+
if (exited)
|
|
1495
|
+
return;
|
|
1496
|
+
exited = true;
|
|
1497
|
+
resolve(null);
|
|
1498
|
+
};
|
|
1499
|
+
process$1.on("SIGINT", handleExit);
|
|
1500
|
+
process$1.on("SIGTERM", handleExit);
|
|
1400
1501
|
console.log("Logging into your ONES account...");
|
|
1401
1502
|
console.log(`Opening ${url}`);
|
|
1402
1503
|
ora("Waiting for authorization...").start();
|
|
@@ -1433,7 +1534,9 @@ const whoami = async function() {
|
|
|
1433
1534
|
const normalizedOptions = await normalize$4(options);
|
|
1434
1535
|
lodashEs.noop(normalizedOptions);
|
|
1435
1536
|
const baseURL = await getBaseURL();
|
|
1537
|
+
const cancelWaiting = startWaiting();
|
|
1436
1538
|
const tokenInfo = await fetchTokenInfo();
|
|
1539
|
+
cancelWaiting();
|
|
1437
1540
|
const name2 = (_tokenInfo$user = tokenInfo.user) === null || _tokenInfo$user === void 0 ? void 0 : _tokenInfo$user.name;
|
|
1438
1541
|
const email = (_tokenInfo$user2 = tokenInfo.user) === null || _tokenInfo$user2 === void 0 ? void 0 : _tokenInfo$user2.email;
|
|
1439
1542
|
if (name2 && email) {
|
|
@@ -1458,7 +1561,9 @@ const enable = async function() {
|
|
|
1458
1561
|
const normalizedOptions = await normalize$3(options);
|
|
1459
1562
|
lodashEs.noop(normalizedOptions);
|
|
1460
1563
|
const appName = getAppManifestJSON().app.name;
|
|
1564
|
+
const cancelWaiting = startWaiting();
|
|
1461
1565
|
const result = await fetchAppEnable();
|
|
1566
|
+
cancelWaiting();
|
|
1462
1567
|
if (result.code === "OK") {
|
|
1463
1568
|
console.log(`App "${appName}" enabled successfully!`);
|
|
1464
1569
|
} else {
|
|
@@ -1480,7 +1585,9 @@ const disable = async function() {
|
|
|
1480
1585
|
const normalizedOptions = await normalize$2(options);
|
|
1481
1586
|
lodashEs.noop(normalizedOptions);
|
|
1482
1587
|
const appName = getAppManifestJSON().app.name;
|
|
1588
|
+
const cancelWaiting = startWaiting();
|
|
1483
1589
|
const result = await fetchAppDisable();
|
|
1590
|
+
cancelWaiting();
|
|
1484
1591
|
if (result.code === "OK") {
|
|
1485
1592
|
console.log(`App "${appName}" disabled successfully!`);
|
|
1486
1593
|
} else {
|
|
@@ -1502,7 +1609,9 @@ const uninstall = async function() {
|
|
|
1502
1609
|
const normalizedOptions = await normalize$1(options);
|
|
1503
1610
|
lodashEs.noop(normalizedOptions);
|
|
1504
1611
|
const appName = getAppManifestJSON().app.name;
|
|
1612
|
+
const cancelWaiting = startWaiting();
|
|
1505
1613
|
const result = await fetchAppUninstall();
|
|
1614
|
+
cancelWaiting();
|
|
1506
1615
|
if (result.code === "OK") {
|
|
1507
1616
|
console.log(`App "${appName}" uninstalled successfully!`);
|
|
1508
1617
|
} else {
|
|
@@ -1510,10 +1619,29 @@ const uninstall = async function() {
|
|
|
1510
1619
|
console.error(JSON.stringify(result, null, 2));
|
|
1511
1620
|
}
|
|
1512
1621
|
};
|
|
1622
|
+
const getTemplatePath = () => {
|
|
1623
|
+
const __dirname = node_path.dirname(node_url.fileURLToPath(typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("index.cjs", document.baseURI).href));
|
|
1624
|
+
return node_path.join(__dirname, "../template");
|
|
1625
|
+
};
|
|
1626
|
+
const getTemplateLegacy = () => {
|
|
1627
|
+
return "legacy";
|
|
1628
|
+
};
|
|
1513
1629
|
const normalize = async (options) => {
|
|
1514
|
-
|
|
1515
|
-
|
|
1630
|
+
const projectPathInput = options.projectPath;
|
|
1631
|
+
if (projectPathInput)
|
|
1632
|
+
;
|
|
1633
|
+
else {
|
|
1634
|
+
return createOnesApp.throwError(ErrorCode.MISSING_PROJECT_PATH, i18n.t("error.legacy.create.missingProjectPath"));
|
|
1635
|
+
}
|
|
1636
|
+
const projectPath = node_path.resolve(process$1.cwd(), projectPathInput);
|
|
1637
|
+
return {
|
|
1638
|
+
projectPath
|
|
1639
|
+
};
|
|
1516
1640
|
};
|
|
1641
|
+
const {
|
|
1642
|
+
copy,
|
|
1643
|
+
moveSync
|
|
1644
|
+
} = fse;
|
|
1517
1645
|
const legacy = async function() {
|
|
1518
1646
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1519
1647
|
args[_key] = arguments[_key];
|
|
@@ -1522,18 +1650,30 @@ const legacy = async function() {
|
|
|
1522
1650
|
options
|
|
1523
1651
|
} = createOnesApp.getCommandOptions(args, legacyCommandArguments);
|
|
1524
1652
|
const normalizedOptions = await normalize(options);
|
|
1525
|
-
|
|
1653
|
+
const {
|
|
1654
|
+
projectPath
|
|
1655
|
+
} = normalizedOptions;
|
|
1656
|
+
const templatePath = node_path.join(getTemplatePath(), getTemplateLegacy());
|
|
1657
|
+
await copy(templatePath, projectPath);
|
|
1658
|
+
const rename = [["_eslintignore", ".eslintignore"], ["_eslintrc.js", ".eslintrc.js"], ["_gitignore", ".gitignore"], ["_gitlab-ci.yml", ".gitlab-ci.yml"], ["_npmrc", ".npmrc"], ["_prettierignore", ".prettierignore"], ["_prettierrc", ".prettierrc"], ["_backend_npmrc", "backend/.npmrc"], ["_backend_tsconfig.json", "backend/tsconfig.json"], ["_web_npmrc", "web/.npmrc"], ["_web_tsconfig.json", "web/tsconfig.json"], ["_husky_pre-commit", ".husky/pre-commit"]];
|
|
1659
|
+
rename.forEach((_ref) => {
|
|
1660
|
+
let [from, to] = _ref;
|
|
1661
|
+
moveSync(node_path.join(projectPath, from), node_path.join(projectPath, to), {
|
|
1662
|
+
overwrite: true
|
|
1663
|
+
});
|
|
1664
|
+
});
|
|
1665
|
+
console.log("Plugin created successfully!");
|
|
1526
1666
|
};
|
|
1527
1667
|
const buildCommandArguments = [];
|
|
1528
1668
|
const $build = new commander.Command("build").description(i18n.t("desc.build")).option("-o, --output [file-path]", i18n.t("desc.build.output")).action(build);
|
|
1529
1669
|
createOnesApp.addCommandUsage($build);
|
|
1530
1670
|
createOnesApp.addCommandOutput($build);
|
|
1531
1671
|
const devCommandArguments = [];
|
|
1532
|
-
const $dev = new commander.Command("dev").description(i18n.t("desc.dev")).option("-i, --install [boolean]", i18n.t("desc.dev.install")).option("-c, --command [string]", i18n.t("desc.dev.command")).action(dev);
|
|
1672
|
+
const $dev = new commander.Command("dev").description(i18n.t("desc.dev")).option("-i, --install [boolean]", i18n.t("desc.dev.install")).option("-c, --command [string]", i18n.t("desc.dev.command")).option("-s, --use-storage [boolean]", i18n.t("desc.dev.useStorage")).action(dev);
|
|
1533
1673
|
createOnesApp.addCommandUsage($dev);
|
|
1534
1674
|
createOnesApp.addCommandOutput($dev);
|
|
1535
1675
|
const tunnelCommandArguments = ["port"];
|
|
1536
|
-
const $tunnel = new commander.Command("tunnel").description(i18n.t("desc.tunnel")).argument("<port>", i18n.t("desc.tunnel.port")).action(tunnel);
|
|
1676
|
+
const $tunnel = new commander.Command("tunnel").description(i18n.t("desc.tunnel")).argument("<port>", i18n.t("desc.tunnel.port")).option("-s, --use-storage [boolean]", i18n.t("desc.dev.useStorage")).action(tunnel);
|
|
1537
1677
|
createOnesApp.addCommandUsage($tunnel);
|
|
1538
1678
|
createOnesApp.addCommandOutput($tunnel);
|
|
1539
1679
|
const loginCommandArguments = ["baseURL"];
|
|
@@ -1568,8 +1708,12 @@ const $app = new commander.Command("app").description(i18n.t("desc.app"));
|
|
|
1568
1708
|
$app.addCommand($install).addCommand($enable).addCommand($disable).addCommand($uninstall);
|
|
1569
1709
|
createOnesApp.addCommandUsage($app);
|
|
1570
1710
|
createOnesApp.addCommandOutput($app);
|
|
1571
|
-
const legacyCommandArguments = [];
|
|
1572
|
-
const $
|
|
1711
|
+
const legacyCommandArguments = ["projectPath"];
|
|
1712
|
+
const $create = new commander.Command("create").description(i18n.t("desc.legacy.create")).argument("<project-path>", i18n.t("desc.legacy.create.projectPath")).action(legacy);
|
|
1713
|
+
createOnesApp.addCommandUsage($create);
|
|
1714
|
+
createOnesApp.addCommandOutput($create);
|
|
1715
|
+
const $legacy = new commander.Command("legacy").description(i18n.t("desc.legacy"));
|
|
1716
|
+
$legacy.addCommand($create);
|
|
1573
1717
|
createOnesApp.addCommandUsage($legacy);
|
|
1574
1718
|
createOnesApp.addCommandOutput($legacy);
|
|
1575
1719
|
const ones = new commander.Command("ones");
|