@ones-open/cli 0.0.8
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/LICENSE +201 -0
- package/bin/ones.js +4 -0
- package/dist/index.cjs +1889 -0
- package/dist/index.js +1888 -0
- package/dist/types/actions/build/index.d.ts +4 -0
- package/dist/types/actions/build/index.d.ts.map +1 -0
- package/dist/types/actions/build/normalize.d.ts +6 -0
- package/dist/types/actions/build/normalize.d.ts.map +1 -0
- package/dist/types/actions/build/regexp.d.ts +2 -0
- package/dist/types/actions/build/regexp.d.ts.map +1 -0
- package/dist/types/actions/dev/enums.d.ts +11 -0
- package/dist/types/actions/dev/enums.d.ts.map +1 -0
- package/dist/types/actions/dev/index.d.ts +4 -0
- package/dist/types/actions/dev/index.d.ts.map +1 -0
- package/dist/types/actions/dev/normalize.d.ts +6 -0
- package/dist/types/actions/dev/normalize.d.ts.map +1 -0
- package/dist/types/actions/dev/types.d.ts +10 -0
- package/dist/types/actions/dev/types.d.ts.map +1 -0
- package/dist/types/actions/disable/index.d.ts +4 -0
- package/dist/types/actions/disable/index.d.ts.map +1 -0
- package/dist/types/actions/disable/normalize.d.ts +6 -0
- package/dist/types/actions/disable/normalize.d.ts.map +1 -0
- package/dist/types/actions/enable/index.d.ts +4 -0
- package/dist/types/actions/enable/index.d.ts.map +1 -0
- package/dist/types/actions/enable/normalize.d.ts +6 -0
- package/dist/types/actions/enable/normalize.d.ts.map +1 -0
- package/dist/types/actions/index.d.ts +15 -0
- package/dist/types/actions/index.d.ts.map +1 -0
- package/dist/types/actions/install/index.d.ts +5 -0
- package/dist/types/actions/install/index.d.ts.map +1 -0
- package/dist/types/actions/install/install.d.ts +3 -0
- package/dist/types/actions/install/install.d.ts.map +1 -0
- package/dist/types/actions/install/normalize.d.ts +6 -0
- package/dist/types/actions/install/normalize.d.ts.map +1 -0
- package/dist/types/actions/legacy/index.d.ts +4 -0
- package/dist/types/actions/legacy/index.d.ts.map +1 -0
- package/dist/types/actions/legacy/normalize.d.ts +6 -0
- package/dist/types/actions/legacy/normalize.d.ts.map +1 -0
- package/dist/types/actions/login/consts.d.ts +2 -0
- package/dist/types/actions/login/consts.d.ts.map +1 -0
- package/dist/types/actions/login/index.d.ts +4 -0
- package/dist/types/actions/login/index.d.ts.map +1 -0
- package/dist/types/actions/login/normalize.d.ts +6 -0
- package/dist/types/actions/login/normalize.d.ts.map +1 -0
- package/dist/types/actions/login/regexp.d.ts +2 -0
- package/dist/types/actions/login/regexp.d.ts.map +1 -0
- package/dist/types/actions/logout/index.d.ts +4 -0
- package/dist/types/actions/logout/index.d.ts.map +1 -0
- package/dist/types/actions/logout/normalize.d.ts +6 -0
- package/dist/types/actions/logout/normalize.d.ts.map +1 -0
- package/dist/types/actions/tunnel/consts.d.ts +4 -0
- package/dist/types/actions/tunnel/consts.d.ts.map +1 -0
- package/dist/types/actions/tunnel/index.d.ts +7 -0
- package/dist/types/actions/tunnel/index.d.ts.map +1 -0
- package/dist/types/actions/tunnel/normalize.d.ts +6 -0
- package/dist/types/actions/tunnel/normalize.d.ts.map +1 -0
- package/dist/types/actions/tunnel/regexp.d.ts +2 -0
- package/dist/types/actions/tunnel/regexp.d.ts.map +1 -0
- package/dist/types/actions/tunnel/tunnel-client.d.ts +25 -0
- package/dist/types/actions/tunnel/tunnel-client.d.ts.map +1 -0
- package/dist/types/actions/tunnel/tunnel.d.ts +3 -0
- package/dist/types/actions/tunnel/tunnel.d.ts.map +1 -0
- package/dist/types/actions/tunnel/types.d.ts +31 -0
- package/dist/types/actions/tunnel/types.d.ts.map +1 -0
- package/dist/types/actions/tunnel/utils.d.ts +7 -0
- package/dist/types/actions/tunnel/utils.d.ts.map +1 -0
- package/dist/types/actions/uninstall/index.d.ts +4 -0
- package/dist/types/actions/uninstall/index.d.ts.map +1 -0
- package/dist/types/actions/uninstall/normalize.d.ts +6 -0
- package/dist/types/actions/uninstall/normalize.d.ts.map +1 -0
- package/dist/types/actions/whoami/index.d.ts +4 -0
- package/dist/types/actions/whoami/index.d.ts.map +1 -0
- package/dist/types/actions/whoami/normalize.d.ts +6 -0
- package/dist/types/actions/whoami/normalize.d.ts.map +1 -0
- package/dist/types/cli/index.d.ts +2 -0
- package/dist/types/cli/index.d.ts.map +1 -0
- package/dist/types/command/app/index.d.ts +4 -0
- package/dist/types/command/app/index.d.ts.map +1 -0
- package/dist/types/command/build/index.d.ts +10 -0
- package/dist/types/command/build/index.d.ts.map +1 -0
- package/dist/types/command/dev/index.d.ts +11 -0
- package/dist/types/command/dev/index.d.ts.map +1 -0
- package/dist/types/command/disable/index.d.ts +8 -0
- package/dist/types/command/disable/index.d.ts.map +1 -0
- package/dist/types/command/enable/index.d.ts +8 -0
- package/dist/types/command/enable/index.d.ts.map +1 -0
- package/dist/types/command/index.d.ts +16 -0
- package/dist/types/command/index.d.ts.map +1 -0
- package/dist/types/command/install/index.d.ts +8 -0
- package/dist/types/command/install/index.d.ts.map +1 -0
- package/dist/types/command/legacy/index.d.ts +8 -0
- package/dist/types/command/legacy/index.d.ts.map +1 -0
- package/dist/types/command/login/index.d.ts +8 -0
- package/dist/types/command/login/index.d.ts.map +1 -0
- package/dist/types/command/logout/index.d.ts +8 -0
- package/dist/types/command/logout/index.d.ts.map +1 -0
- package/dist/types/command/tunnel/index.d.ts +9 -0
- package/dist/types/command/tunnel/index.d.ts.map +1 -0
- package/dist/types/command/uninstall/index.d.ts +8 -0
- package/dist/types/command/uninstall/index.d.ts.map +1 -0
- package/dist/types/command/whoami/index.d.ts +8 -0
- package/dist/types/command/whoami/index.d.ts.map +1 -0
- package/dist/types/common/base/index.d.ts +5 -0
- package/dist/types/common/base/index.d.ts.map +1 -0
- package/dist/types/common/base/utils.d.ts +7 -0
- package/dist/types/common/base/utils.d.ts.map +1 -0
- package/dist/types/common/command/index.d.ts +6 -0
- package/dist/types/common/command/index.d.ts.map +1 -0
- package/dist/types/common/command/types.d.ts +2 -0
- package/dist/types/common/command/types.d.ts.map +1 -0
- package/dist/types/common/command/utils.d.ts +2 -0
- package/dist/types/common/command/utils.d.ts.map +1 -0
- package/dist/types/common/config/consts.d.ts +5 -0
- package/dist/types/common/config/consts.d.ts.map +1 -0
- package/dist/types/common/config/index.d.ts +7 -0
- package/dist/types/common/config/index.d.ts.map +1 -0
- package/dist/types/common/config/types.d.ts +8 -0
- package/dist/types/common/config/types.d.ts.map +1 -0
- package/dist/types/common/config/utils.d.ts +3 -0
- package/dist/types/common/config/utils.d.ts.map +1 -0
- package/dist/types/common/context/index.d.ts +6 -0
- package/dist/types/common/context/index.d.ts.map +1 -0
- package/dist/types/common/context/types.d.ts +2 -0
- package/dist/types/common/context/types.d.ts.map +1 -0
- package/dist/types/common/context/utils.d.ts +2 -0
- package/dist/types/common/context/utils.d.ts.map +1 -0
- package/dist/types/common/error/enums.d.ts +20 -0
- package/dist/types/common/error/enums.d.ts.map +1 -0
- package/dist/types/common/error/index.d.ts +7 -0
- package/dist/types/common/error/index.d.ts.map +1 -0
- package/dist/types/common/error/types.d.ts +2 -0
- package/dist/types/common/error/types.d.ts.map +1 -0
- package/dist/types/common/error/utils.d.ts +2 -0
- package/dist/types/common/error/utils.d.ts.map +1 -0
- package/dist/types/common/locales/en/index.d.ts +41 -0
- package/dist/types/common/locales/en/index.d.ts.map +1 -0
- package/dist/types/common/locales/index.d.ts +6 -0
- package/dist/types/common/locales/index.d.ts.map +1 -0
- package/dist/types/common/locales/types.d.ts +4 -0
- package/dist/types/common/locales/types.d.ts.map +1 -0
- package/dist/types/common/locales/utils.d.ts +6 -0
- package/dist/types/common/locales/utils.d.ts.map +1 -0
- package/dist/types/common/package/index.d.ts +7 -0
- package/dist/types/common/package/index.d.ts.map +1 -0
- package/dist/types/common/package/schema.d.ts +3 -0
- package/dist/types/common/package/schema.d.ts.map +1 -0
- package/dist/types/common/package/types.d.ts +2 -0
- package/dist/types/common/package/types.d.ts.map +1 -0
- package/dist/types/common/package/utils.d.ts +16 -0
- package/dist/types/common/package/utils.d.ts.map +1 -0
- package/dist/types/common/public/consts.d.ts +2 -0
- package/dist/types/common/public/consts.d.ts.map +1 -0
- package/dist/types/common/public/index.d.ts +6 -0
- package/dist/types/common/public/index.d.ts.map +1 -0
- package/dist/types/common/public/utils.d.ts +2 -0
- package/dist/types/common/public/utils.d.ts.map +1 -0
- package/dist/types/common/request/consts.d.ts +16 -0
- package/dist/types/common/request/consts.d.ts.map +1 -0
- package/dist/types/common/request/fetch.d.ts +13 -0
- package/dist/types/common/request/fetch.d.ts.map +1 -0
- package/dist/types/common/request/index.d.ts +8 -0
- package/dist/types/common/request/index.d.ts.map +1 -0
- package/dist/types/common/request/types.d.ts +98 -0
- package/dist/types/common/request/types.d.ts.map +1 -0
- package/dist/types/common/request/utils.d.ts +11 -0
- package/dist/types/common/request/utils.d.ts.map +1 -0
- package/dist/types/common/store/index.d.ts +6 -0
- package/dist/types/common/store/index.d.ts.map +1 -0
- package/dist/types/common/store/schema.d.ts +75 -0
- package/dist/types/common/store/schema.d.ts.map +1 -0
- package/dist/types/common/store/utils.d.ts +13 -0
- package/dist/types/common/store/utils.d.ts.map +1 -0
- 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/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +83 -0
- package/public/callback.html +65 -0
- package/public/logo.svg +4 -0
- 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.js
ADDED
|
@@ -0,0 +1,1888 @@
|
|
|
1
|
+
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import { ErrorCode as ErrorCode$1, AppPackageJSONSchema, throwError, AppManifestJSONSchema, getPublicPath, PUBLIC_FILENAME, AppRcJSONSchema, AppManifestStrictJSONSchema, getCommandOptions, HostedTokenScope, addCommandUsage, addCommandOutput, $create as $create$1, setContext } from "create-ones-app";
|
|
4
|
+
import { dirname, join, resolve, basename } from "node:path";
|
|
5
|
+
import { spawnSync, spawn } from "node:child_process";
|
|
6
|
+
import { readFileSync, createWriteStream } from "node:fs";
|
|
7
|
+
import fse from "fs-extra";
|
|
8
|
+
import archiver from "archiver";
|
|
9
|
+
import { get, merge, random, noop } from "lodash-es";
|
|
10
|
+
import process$1, { cwd } from "node:process";
|
|
11
|
+
import { fileURLToPath } from "node:url";
|
|
12
|
+
import { cosmiconfig } from "cosmiconfig";
|
|
13
|
+
import getPort from "get-port";
|
|
14
|
+
import envPaths from "env-paths";
|
|
15
|
+
import { z } from "zod";
|
|
16
|
+
import axios from "axios";
|
|
17
|
+
import _reduceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/reduce";
|
|
18
|
+
import ora from "ora";
|
|
19
|
+
import WebSocket from "ws";
|
|
20
|
+
import http from "node:http";
|
|
21
|
+
import open from "open";
|
|
22
|
+
import { v4 } from "uuid";
|
|
23
|
+
import PKCEChallenge from "pkce-challenge";
|
|
24
|
+
const en = {
|
|
25
|
+
"desc.ones": "ONES CLI/{env}",
|
|
26
|
+
"desc.build": "Build your ONES App",
|
|
27
|
+
"desc.build.output": "Specify the output file path",
|
|
28
|
+
"desc.build.command": "Specify the build command",
|
|
29
|
+
"desc.dev": "Start your local development server and connect to ONES",
|
|
30
|
+
"desc.dev.install": "Install your ONES App after the server is ready",
|
|
31
|
+
"desc.dev.command": "Specify the dev command",
|
|
32
|
+
"desc.dev.clearStorage": "Clear development storage namespace before applying hosted storage",
|
|
33
|
+
"desc.tunnel": "Start a tunnel to connect your local server with ONES",
|
|
34
|
+
"desc.tunnel.port": "Specify the port number for tunnel",
|
|
35
|
+
"desc.login": "Log in to your ONES account",
|
|
36
|
+
"desc.login.baseUrl": "Specify the ONES URL for login",
|
|
37
|
+
"desc.logout": "Log out of your ONES account",
|
|
38
|
+
"desc.whoami": "Display the account information of the logged in user",
|
|
39
|
+
"desc.app": "Manage app installations",
|
|
40
|
+
"desc.install": "Install your ONES App",
|
|
41
|
+
"desc.enable": "Enable your ONES App",
|
|
42
|
+
"desc.disable": "Disable your ONES App",
|
|
43
|
+
"desc.uninstall": "Uninstall your ONES App",
|
|
44
|
+
"desc.legacy": "Legacy command",
|
|
45
|
+
"desc.legacy.create": "Create a new ONES plugin",
|
|
46
|
+
"desc.legacy.create.projectPath": "Specify the project path",
|
|
47
|
+
"error.login.missingBaseURL": "Missing base URL",
|
|
48
|
+
"error.login.incorrectBaseURL": "Incorrect base URL",
|
|
49
|
+
"error.tunnel.missingPort": "Missing port",
|
|
50
|
+
"error.tunnel.incorrectPort": "Incorrect port",
|
|
51
|
+
"error.schema.app.package.parseError": "App package JSON parse error",
|
|
52
|
+
"error.schema.app.manifest.parseError": 'App "opkx.json" JSON parse error',
|
|
53
|
+
"error.schema.app.manifest.validateError": 'App "opkx.json" JSON validation failed: "{err}". Please check this issue, or upgrade your ONES CLI to the latest version if the problem persists.',
|
|
54
|
+
"error.build.scriptNotFound": 'Npm "build" script not found',
|
|
55
|
+
"error.build.incorrectCommand": "Incorrect build command",
|
|
56
|
+
"error.dev.scriptNotFound": 'Npm "dev" script not found',
|
|
57
|
+
"error.dev.incorrectCommand": "Incorrect dev command",
|
|
58
|
+
"error.store.permission": 'Permission denied, please check the file permission with "{filePath}"',
|
|
59
|
+
"error.hostedToken.requestFailed": "Failed to request hosted token",
|
|
60
|
+
"error.hostedToken.empty": "Hosted token is empty",
|
|
61
|
+
"error.legacy.create.missingProjectPath": "Project path is required"
|
|
62
|
+
};
|
|
63
|
+
const map = {
|
|
64
|
+
en
|
|
65
|
+
};
|
|
66
|
+
const getCurrentLanguageList = () => {
|
|
67
|
+
return ["en"];
|
|
68
|
+
};
|
|
69
|
+
const translate = (key, params) => {
|
|
70
|
+
const list = getCurrentLanguageList();
|
|
71
|
+
for (let index = 0; index < list.length; index++) {
|
|
72
|
+
const language = list[index];
|
|
73
|
+
let value = get(map[language], key);
|
|
74
|
+
if (value) {
|
|
75
|
+
if (params && typeof value === "string") {
|
|
76
|
+
value = value.replace(/\{(\w+)\}/g, (match, paramKey) => {
|
|
77
|
+
var _params$paramKey;
|
|
78
|
+
const result = (_params$paramKey = params === null || params === void 0 ? void 0 : params[paramKey]) !== null && _params$paramKey !== void 0 ? _params$paramKey : match;
|
|
79
|
+
return String(result);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return value;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return key;
|
|
86
|
+
};
|
|
87
|
+
const i18n = {
|
|
88
|
+
t: translate
|
|
89
|
+
};
|
|
90
|
+
var ErrorCode = ((ErrorCode2) => {
|
|
91
|
+
ErrorCode2[ErrorCode2["UNKNOWN_ERROR"] = ErrorCode$1.UNKNOWN_ERROR] = "UNKNOWN_ERROR";
|
|
92
|
+
ErrorCode2[ErrorCode2["COMMAND_ERROR"] = ErrorCode$1.COMMAND_ERROR] = "COMMAND_ERROR";
|
|
93
|
+
ErrorCode2[ErrorCode2["TEMPLATE_NOT_FOUND"] = ErrorCode$1.TEMPLATE_NOT_FOUND] = "TEMPLATE_NOT_FOUND";
|
|
94
|
+
ErrorCode2[ErrorCode2["MISSING_PROJECT_PATH"] = ErrorCode$1.MISSING_PROJECT_PATH] = "MISSING_PROJECT_PATH";
|
|
95
|
+
ErrorCode2["MISSING_BASE_URL"] = "E04";
|
|
96
|
+
ErrorCode2["MISSING_PORT"] = "E05";
|
|
97
|
+
ErrorCode2["INCORRECT_BASE_URL"] = "E06";
|
|
98
|
+
ErrorCode2["INCORRECT_PORT"] = "E07";
|
|
99
|
+
ErrorCode2["APP_PACKAGE_JSON_PARSE_ERROR"] = "E08";
|
|
100
|
+
ErrorCode2["APP_MANIFEST_JSON_PARSE_ERROR"] = "E09";
|
|
101
|
+
ErrorCode2["BUILD_SCRIPT_NOT_FOUND"] = "E10";
|
|
102
|
+
ErrorCode2["DEV_SCRIPT_NOT_FOUND"] = "E11";
|
|
103
|
+
ErrorCode2["STORE_PERMISSION"] = "E12";
|
|
104
|
+
ErrorCode2["HOSTED_TOKEN_REQUEST_FAILED"] = "E13";
|
|
105
|
+
ErrorCode2["HOSTED_TOKEN_EMPTY"] = "E14";
|
|
106
|
+
ErrorCode2["INCORRECT_DEV_COMMAND"] = "E15";
|
|
107
|
+
ErrorCode2["INCORRECT_BUILD_COMMAND"] = "E16";
|
|
108
|
+
return ErrorCode2;
|
|
109
|
+
})(ErrorCode || {});
|
|
110
|
+
const getPackageJSONPath = () => {
|
|
111
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
112
|
+
return join(__dirname, "../package.json");
|
|
113
|
+
};
|
|
114
|
+
const getPackageJSON = () => {
|
|
115
|
+
const path = getPackageJSONPath();
|
|
116
|
+
try {
|
|
117
|
+
const string = readFileSync(path, {
|
|
118
|
+
encoding: "utf8"
|
|
119
|
+
});
|
|
120
|
+
return JSON.parse(string);
|
|
121
|
+
} catch (error) {
|
|
122
|
+
return {};
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
const getAppWorkspacePath = () => {
|
|
126
|
+
return join(cwd());
|
|
127
|
+
};
|
|
128
|
+
const getAppPackageJSONPath = () => {
|
|
129
|
+
return join(cwd(), "./package.json");
|
|
130
|
+
};
|
|
131
|
+
const getAppPackageJSON = () => {
|
|
132
|
+
const path = getAppPackageJSONPath();
|
|
133
|
+
try {
|
|
134
|
+
const string = readFileSync(path, {
|
|
135
|
+
encoding: "utf8"
|
|
136
|
+
});
|
|
137
|
+
const json = JSON.parse(string);
|
|
138
|
+
return AppPackageJSONSchema.parse(json);
|
|
139
|
+
} catch (error) {
|
|
140
|
+
const details = error instanceof Error ? error.message : String(error);
|
|
141
|
+
return throwError(ErrorCode.APP_PACKAGE_JSON_PARSE_ERROR, `${i18n.t("error.schema.app.package.parseError")}: ${details}`);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
const getAppManifestJSONPath = () => {
|
|
145
|
+
return join(cwd(), PUBLIC_FILENAME.MANIFEST);
|
|
146
|
+
};
|
|
147
|
+
const getAppManifestJSON = () => {
|
|
148
|
+
const path = getAppManifestJSONPath();
|
|
149
|
+
try {
|
|
150
|
+
const string = readFileSync(path, {
|
|
151
|
+
encoding: "utf8"
|
|
152
|
+
});
|
|
153
|
+
const json = JSON.parse(string);
|
|
154
|
+
AppManifestJSONSchema.parse(json);
|
|
155
|
+
return json;
|
|
156
|
+
} catch (error) {
|
|
157
|
+
const details = error instanceof Error ? error.message : String(error);
|
|
158
|
+
return throwError(ErrorCode.APP_MANIFEST_JSON_PARSE_ERROR, `${i18n.t("error.schema.app.manifest.parseError")}: ${details}`);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
const validateAppManifestJSON = () => {
|
|
162
|
+
const appManifestJSON = getAppManifestJSON();
|
|
163
|
+
try {
|
|
164
|
+
AppManifestStrictJSONSchema.parse(appManifestJSON);
|
|
165
|
+
} catch (error) {
|
|
166
|
+
const details = error instanceof Error ? error.message : String(error);
|
|
167
|
+
return throwError(ErrorCode.APP_MANIFEST_JSON_PARSE_ERROR, `${i18n.t("error.schema.app.manifest.validateError", {
|
|
168
|
+
err: details
|
|
169
|
+
})}`);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
const defaultDevCommand = ["npm", "run", "dev"];
|
|
173
|
+
const defaultBuildCommand = ["npm", "run", "build"];
|
|
174
|
+
const defaultAppRcJSON = {
|
|
175
|
+
dev: {
|
|
176
|
+
command: defaultDevCommand
|
|
177
|
+
},
|
|
178
|
+
build: {
|
|
179
|
+
command: defaultBuildCommand
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
let storeAppRcJSON = null;
|
|
183
|
+
const getAppRcJSON = async () => {
|
|
184
|
+
if (storeAppRcJSON)
|
|
185
|
+
;
|
|
186
|
+
else {
|
|
187
|
+
try {
|
|
188
|
+
const path = join(getPublicPath(), PUBLIC_FILENAME.RC);
|
|
189
|
+
const string = readFileSync(path, {
|
|
190
|
+
encoding: "utf8"
|
|
191
|
+
});
|
|
192
|
+
const json = JSON.parse(string);
|
|
193
|
+
storeAppRcJSON = AppRcJSONSchema.parse(json);
|
|
194
|
+
} catch (error) {
|
|
195
|
+
storeAppRcJSON = {};
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
const templateAppRcJSON = storeAppRcJSON || {};
|
|
199
|
+
let currentAppRcJSON;
|
|
200
|
+
const explorer = cosmiconfig("ones");
|
|
201
|
+
try {
|
|
202
|
+
const result = await explorer.search();
|
|
203
|
+
const json = result === null || result === void 0 ? void 0 : result.config;
|
|
204
|
+
currentAppRcJSON = AppRcJSONSchema.parse(json);
|
|
205
|
+
} catch (error) {
|
|
206
|
+
currentAppRcJSON = {};
|
|
207
|
+
}
|
|
208
|
+
return merge(defaultAppRcJSON, templateAppRcJSON, currentAppRcJSON);
|
|
209
|
+
};
|
|
210
|
+
const isOPKXFilename = /\.opkx$/;
|
|
211
|
+
const defaultOutputPath = "";
|
|
212
|
+
const normalize$a = async (options) => {
|
|
213
|
+
var _options$output, _options$command;
|
|
214
|
+
let output = resolve(cwd(), (_options$output = options.output) !== null && _options$output !== void 0 ? _options$output : defaultOutputPath);
|
|
215
|
+
const command = (_options$command = options.command) !== null && _options$command !== void 0 ? _options$command : "";
|
|
216
|
+
if (isOPKXFilename.test(output))
|
|
217
|
+
;
|
|
218
|
+
else {
|
|
219
|
+
const appManifestJSON = getAppManifestJSON();
|
|
220
|
+
const defaultOutputFilename = `${appManifestJSON.app.name}.opkx`;
|
|
221
|
+
output = resolve(output, defaultOutputFilename);
|
|
222
|
+
}
|
|
223
|
+
validateAppManifestJSON();
|
|
224
|
+
return {
|
|
225
|
+
output,
|
|
226
|
+
command
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
const {
|
|
230
|
+
existsSync,
|
|
231
|
+
ensureDirSync
|
|
232
|
+
} = fse;
|
|
233
|
+
const build = async function() {
|
|
234
|
+
var _appRcJSON$dev, _defaultAppRcJSON$dev, _appRcJSON$build$comm, _appRcJSON$build, _currentCommand$, _appRcJSON$build$comp, _appRcJSON$build2;
|
|
235
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
236
|
+
args[_key] = arguments[_key];
|
|
237
|
+
}
|
|
238
|
+
const {
|
|
239
|
+
options
|
|
240
|
+
} = getCommandOptions(args, buildCommandArguments);
|
|
241
|
+
const normalizedOptions = await normalize$a(options);
|
|
242
|
+
const appManifestJSON = getAppManifestJSON();
|
|
243
|
+
const appRcJSON = await getAppRcJSON();
|
|
244
|
+
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]) || "";
|
|
245
|
+
if (!correctCommand) {
|
|
246
|
+
return throwError(ErrorCode.INCORRECT_BUILD_COMMAND, i18n.t("error.build.incorrectCommand"));
|
|
247
|
+
}
|
|
248
|
+
const currentCommand = normalizedOptions.command ? normalizedOptions.command.split(" ") : (_appRcJSON$build$comm = (_appRcJSON$build = appRcJSON.build) === null || _appRcJSON$build === void 0 ? void 0 : _appRcJSON$build.command) !== null && _appRcJSON$build$comm !== void 0 ? _appRcJSON$build$comm : [];
|
|
249
|
+
const firstCommand = (_currentCommand$ = currentCommand[0]) !== null && _currentCommand$ !== void 0 ? _currentCommand$ : "";
|
|
250
|
+
const currentCommandString = currentCommand.join(" ");
|
|
251
|
+
const defaultBuildCommandString = defaultBuildCommand.join(" ");
|
|
252
|
+
let shouldBuild = false;
|
|
253
|
+
if (firstCommand === "npm") {
|
|
254
|
+
const appPackageJSONPath = getAppPackageJSONPath();
|
|
255
|
+
const isExists = existsSync(appPackageJSONPath);
|
|
256
|
+
if (isExists) {
|
|
257
|
+
shouldBuild = true;
|
|
258
|
+
const appPackageJSON = getAppPackageJSON();
|
|
259
|
+
if (currentCommandString === defaultBuildCommandString) {
|
|
260
|
+
var _appPackageJSON$scrip;
|
|
261
|
+
if ((_appPackageJSON$scrip = appPackageJSON.scripts) !== null && _appPackageJSON$scrip !== void 0 && _appPackageJSON$scrip.build)
|
|
262
|
+
;
|
|
263
|
+
else {
|
|
264
|
+
return throwError(ErrorCode.BUILD_SCRIPT_NOT_FOUND, i18n.t("error.build.scriptNotFound"));
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
} else {
|
|
269
|
+
shouldBuild = true;
|
|
270
|
+
}
|
|
271
|
+
if (shouldBuild) {
|
|
272
|
+
const buildResult = spawnSync(firstCommand, currentCommand.slice(1), {
|
|
273
|
+
cwd: getAppWorkspacePath(),
|
|
274
|
+
stdio: "inherit",
|
|
275
|
+
env: {
|
|
276
|
+
...process.env,
|
|
277
|
+
NODE_ENV: "production"
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
if (buildResult.status !== 0 || buildResult.signal) {
|
|
281
|
+
var _buildResult$status;
|
|
282
|
+
process.exit((_buildResult$status = buildResult.status) !== null && _buildResult$status !== void 0 ? _buildResult$status : 1);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
const appName = appManifestJSON.app.name;
|
|
286
|
+
const outputPath = normalizedOptions.output;
|
|
287
|
+
const outputDir = dirname(outputPath);
|
|
288
|
+
const outputFilename = basename(outputPath);
|
|
289
|
+
ensureDirSync(outputDir);
|
|
290
|
+
const outputStream = createWriteStream(outputPath);
|
|
291
|
+
const files = (_appRcJSON$build$comp = (_appRcJSON$build2 = appRcJSON.build) === null || _appRcJSON$build2 === void 0 || (_appRcJSON$build2 = _appRcJSON$build2.compress) === null || _appRcJSON$build2 === void 0 ? void 0 : _appRcJSON$build2.files) !== null && _appRcJSON$build$comp !== void 0 ? _appRcJSON$build$comp : [];
|
|
292
|
+
const archive = archiver("zip", {
|
|
293
|
+
zlib: {
|
|
294
|
+
level: 9
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
archive.on("error", (err) => {
|
|
298
|
+
throw err;
|
|
299
|
+
});
|
|
300
|
+
archive.on("warning", (err) => {
|
|
301
|
+
throw err;
|
|
302
|
+
});
|
|
303
|
+
archive.on("progress", (progress) => {
|
|
304
|
+
const {
|
|
305
|
+
entries,
|
|
306
|
+
fs
|
|
307
|
+
} = progress;
|
|
308
|
+
const entriesStr = entries.total > 0 ? ` ${entries.processed}/${entries.total} files` : "";
|
|
309
|
+
const bytesStr = fs.totalBytes > 0 ? ` ${(fs.processedBytes / 1024).toFixed(1)}/${(fs.totalBytes / 1024).toFixed(1)} KB` : "";
|
|
310
|
+
process.stdout.write(`\rCompressing:${entriesStr}${bytesStr} `);
|
|
311
|
+
});
|
|
312
|
+
archive.on("finish", () => {
|
|
313
|
+
process.stdout.write("\n");
|
|
314
|
+
console.log("");
|
|
315
|
+
console.log("Files in archive: ", PUBLIC_FILENAME.MANIFEST, files);
|
|
316
|
+
console.log(`App "${appName}" built successfully!`);
|
|
317
|
+
console.log(`OPKX "${outputFilename}" created successfully!`);
|
|
318
|
+
console.log(`Output file: ${outputPath}`);
|
|
319
|
+
});
|
|
320
|
+
archive.pipe(outputStream);
|
|
321
|
+
files.forEach((file) => {
|
|
322
|
+
archive.glob(file, {
|
|
323
|
+
cwd: getAppWorkspacePath()
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
archive.file(join(getAppWorkspacePath(), PUBLIC_FILENAME.MANIFEST), {
|
|
327
|
+
name: PUBLIC_FILENAME.MANIFEST
|
|
328
|
+
});
|
|
329
|
+
archive.finalize();
|
|
330
|
+
};
|
|
331
|
+
const minPortNumber = 1;
|
|
332
|
+
const maxPortNumber = 65535;
|
|
333
|
+
const randomPortRangeStartNumber = 1e4;
|
|
334
|
+
const randomPortRangeEndNumber = maxPortNumber;
|
|
335
|
+
const loginRandomPort = random(randomPortRangeStartNumber, randomPortRangeEndNumber);
|
|
336
|
+
const config = {
|
|
337
|
+
defaultPort: {
|
|
338
|
+
login: loginRandomPort,
|
|
339
|
+
hosted: 8201,
|
|
340
|
+
devWebServer: 8202
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
const getConfig = () => config;
|
|
344
|
+
const StoreONESTokenJSONSchema = z.object({
|
|
345
|
+
token_type: z.string().optional(),
|
|
346
|
+
expires_in: z.number().optional(),
|
|
347
|
+
expires_at: z.number().optional(),
|
|
348
|
+
access_token: z.string().optional(),
|
|
349
|
+
refresh_token: z.string().optional()
|
|
350
|
+
});
|
|
351
|
+
const StoreJSONSchema = z.object({
|
|
352
|
+
version: z.string().optional(),
|
|
353
|
+
timestamp: z.number().optional(),
|
|
354
|
+
base_url: z.string().optional(),
|
|
355
|
+
region_url: z.string().optional(),
|
|
356
|
+
host_token: z.string().optional(),
|
|
357
|
+
ones_token: StoreONESTokenJSONSchema.optional()
|
|
358
|
+
});
|
|
359
|
+
const {
|
|
360
|
+
ensureFile,
|
|
361
|
+
readJSON,
|
|
362
|
+
writeJSON
|
|
363
|
+
} = fse;
|
|
364
|
+
const name = "@ones-open/cli";
|
|
365
|
+
const paths = envPaths(name);
|
|
366
|
+
const storeDir = paths.config;
|
|
367
|
+
const storePath = join(storeDir, "config.json");
|
|
368
|
+
const getStore = async () => {
|
|
369
|
+
let json = {};
|
|
370
|
+
try {
|
|
371
|
+
await ensureFile(storePath);
|
|
372
|
+
json = await readJSON(storePath, {
|
|
373
|
+
encoding: "utf8"
|
|
374
|
+
});
|
|
375
|
+
} catch (error) {
|
|
376
|
+
const $error = error;
|
|
377
|
+
if ($error.code === "EPERM" || $error.code === "EACCES") {
|
|
378
|
+
return throwError(ErrorCode.STORE_PERMISSION, i18n.t("error.store.permission", {
|
|
379
|
+
filePath: storePath
|
|
380
|
+
}));
|
|
381
|
+
}
|
|
382
|
+
if ($error instanceof SyntaxError) {
|
|
383
|
+
return {};
|
|
384
|
+
}
|
|
385
|
+
throw error;
|
|
386
|
+
}
|
|
387
|
+
try {
|
|
388
|
+
return StoreJSONSchema.parse(json);
|
|
389
|
+
} catch (error) {
|
|
390
|
+
return {};
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
const setStore = async (store) => {
|
|
394
|
+
try {
|
|
395
|
+
await ensureFile(storePath);
|
|
396
|
+
const version2 = `${getPackageJSON().version}`;
|
|
397
|
+
const timestamp = Date.now();
|
|
398
|
+
return await writeJSON(storePath, {
|
|
399
|
+
...store,
|
|
400
|
+
version: version2,
|
|
401
|
+
timestamp
|
|
402
|
+
}, {
|
|
403
|
+
encoding: "utf8"
|
|
404
|
+
});
|
|
405
|
+
} catch (error) {
|
|
406
|
+
const $error = error;
|
|
407
|
+
if ($error.code === "EPERM" || $error.code === "EACCES") {
|
|
408
|
+
return throwError(ErrorCode.STORE_PERMISSION, i18n.t("error.store.permission", {
|
|
409
|
+
filePath: storePath
|
|
410
|
+
}));
|
|
411
|
+
}
|
|
412
|
+
throw error;
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
const mergeStore = async (store) => {
|
|
416
|
+
const currentStore = await getStore();
|
|
417
|
+
return setStore({
|
|
418
|
+
...currentStore,
|
|
419
|
+
...store
|
|
420
|
+
});
|
|
421
|
+
};
|
|
422
|
+
const getBaseURL = async () => {
|
|
423
|
+
var _store$base_url;
|
|
424
|
+
const store = await getStore();
|
|
425
|
+
return (_store$base_url = store.base_url) !== null && _store$base_url !== void 0 ? _store$base_url : "";
|
|
426
|
+
};
|
|
427
|
+
const getRegionURL = async () => {
|
|
428
|
+
var _store$region_url;
|
|
429
|
+
const store = await getStore();
|
|
430
|
+
return (_store$region_url = store.region_url) !== null && _store$region_url !== void 0 ? _store$region_url : "";
|
|
431
|
+
};
|
|
432
|
+
const getONESToken = async () => {
|
|
433
|
+
var _store$ones_token;
|
|
434
|
+
const store = await getStore();
|
|
435
|
+
return (_store$ones_token = store.ones_token) !== null && _store$ones_token !== void 0 ? _store$ones_token : {};
|
|
436
|
+
};
|
|
437
|
+
const setONESToken = async (token) => {
|
|
438
|
+
return mergeStore({
|
|
439
|
+
ones_token: token
|
|
440
|
+
});
|
|
441
|
+
};
|
|
442
|
+
const getHostToken = async () => {
|
|
443
|
+
var _store$host_token;
|
|
444
|
+
const store = await getStore();
|
|
445
|
+
return (_store$host_token = store.host_token) !== null && _store$host_token !== void 0 ? _store$host_token : "";
|
|
446
|
+
};
|
|
447
|
+
const setHostToken = async (token) => {
|
|
448
|
+
return mergeStore({
|
|
449
|
+
host_token: token
|
|
450
|
+
});
|
|
451
|
+
};
|
|
452
|
+
const API = {
|
|
453
|
+
TOKEN_INFO: "/project/api/project/auth/token_info",
|
|
454
|
+
HOSTED_TOKEN: "/platform/runtime_manager/hosted_token",
|
|
455
|
+
HOSTED_ABILITY_STORAGE_DEV_DECLARE: "/platform/runtime_manager/hosted_ability/storage/:appID/dev_declare",
|
|
456
|
+
APP_LIST: "/platform/api/app/list",
|
|
457
|
+
APP_INSTALL: "/platform/api/app/install",
|
|
458
|
+
APP_UPGRADE: "/platform/api/app/:installation_id/upgrade",
|
|
459
|
+
APP_UNINSTALL: "/platform/api/app/:installation_id/uninstall",
|
|
460
|
+
APP_ENABLE: "/platform/api/app/:installation_id/enable",
|
|
461
|
+
APP_DISABLE: "/platform/api/app/:installation_id/disable",
|
|
462
|
+
OAUTH_TOKEN: "/identity/oauth/token",
|
|
463
|
+
REFRESH_TOKEN: "/identity/oauth/token"
|
|
464
|
+
};
|
|
465
|
+
const REQUEST_TIMEOUT = 1e4;
|
|
466
|
+
const OAUTH_TOKEN_CLIENT_ID = "ones.v1.cli";
|
|
467
|
+
const getPath = (path, map2) => {
|
|
468
|
+
var _context;
|
|
469
|
+
return _reduceInstanceProperty(_context = path.split("/")).call(_context, (base, part) => {
|
|
470
|
+
if (/^:/.test(part)) {
|
|
471
|
+
return `${base}/${map2[part.slice(1)]}`;
|
|
472
|
+
}
|
|
473
|
+
return `${base}/${part}`;
|
|
474
|
+
}, "").slice(1);
|
|
475
|
+
};
|
|
476
|
+
const consoleUnauthorizedMessage = () => {
|
|
477
|
+
console.log("Not logged in");
|
|
478
|
+
console.log('Login with "ones login" command');
|
|
479
|
+
process.exit(1);
|
|
480
|
+
};
|
|
481
|
+
const consoleAppNotInstalledMessage = () => {
|
|
482
|
+
console.log("App not installed");
|
|
483
|
+
process.exit(1);
|
|
484
|
+
};
|
|
485
|
+
const getURL = async (path, pathMap, queryMap) => {
|
|
486
|
+
const base = await getRegionURL();
|
|
487
|
+
if (base) {
|
|
488
|
+
const query = new URLSearchParams(queryMap !== null && queryMap !== void 0 ? queryMap : {}).toString();
|
|
489
|
+
return `${base}${getPath(path, pathMap !== null && pathMap !== void 0 ? pathMap : {})}${query ? `?${query}` : ""}`;
|
|
490
|
+
}
|
|
491
|
+
consoleUnauthorizedMessage();
|
|
492
|
+
};
|
|
493
|
+
const getHostedFetchHeaders = async (value) => {
|
|
494
|
+
const hostedToken = await getHostToken();
|
|
495
|
+
if (hostedToken) {
|
|
496
|
+
return merge({
|
|
497
|
+
Authorization: `Bearer ${hostedToken}`
|
|
498
|
+
}, value);
|
|
499
|
+
}
|
|
500
|
+
consoleUnauthorizedMessage();
|
|
501
|
+
process.exit(1);
|
|
502
|
+
};
|
|
503
|
+
const getAvailableONESTokeAccessToken = async () => {
|
|
504
|
+
var _token$expires_at, _token$access_token, _token$refresh_token;
|
|
505
|
+
const token = await getONESToken();
|
|
506
|
+
const now = Date.now();
|
|
507
|
+
const base = await getBaseURL();
|
|
508
|
+
const tokenExpiresAt = (_token$expires_at = token === null || token === void 0 ? void 0 : token.expires_at) !== null && _token$expires_at !== void 0 ? _token$expires_at : 0;
|
|
509
|
+
const tokenAccessToken = (_token$access_token = token === null || token === void 0 ? void 0 : token.access_token) !== null && _token$access_token !== void 0 ? _token$access_token : "";
|
|
510
|
+
const tokenRefreshToken = (_token$refresh_token = token === null || token === void 0 ? void 0 : token.refresh_token) !== null && _token$refresh_token !== void 0 ? _token$refresh_token : "";
|
|
511
|
+
if (tokenAccessToken && tokenExpiresAt > now) {
|
|
512
|
+
return tokenAccessToken;
|
|
513
|
+
}
|
|
514
|
+
if (tokenRefreshToken && base) {
|
|
515
|
+
var _data$token_type, _data$expires_in, _data$access_token, _data$refresh_token;
|
|
516
|
+
const uri = new URL(base);
|
|
517
|
+
uri.pathname = API.REFRESH_TOKEN;
|
|
518
|
+
const data = await axios({
|
|
519
|
+
url: `${uri}`,
|
|
520
|
+
method: "POST",
|
|
521
|
+
data: {
|
|
522
|
+
grant_type: "refresh_token",
|
|
523
|
+
refresh_token: tokenRefreshToken,
|
|
524
|
+
client_id: OAUTH_TOKEN_CLIENT_ID
|
|
525
|
+
},
|
|
526
|
+
headers: {
|
|
527
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
528
|
+
},
|
|
529
|
+
timeout: REQUEST_TIMEOUT
|
|
530
|
+
}).then((response) => {
|
|
531
|
+
return response.data;
|
|
532
|
+
}).catch(() => {
|
|
533
|
+
return {};
|
|
534
|
+
});
|
|
535
|
+
const tokenType = (_data$token_type = data.token_type) !== null && _data$token_type !== void 0 ? _data$token_type : "";
|
|
536
|
+
const expiresIn = (_data$expires_in = data.expires_in) !== null && _data$expires_in !== void 0 ? _data$expires_in : 0;
|
|
537
|
+
const accessToken = (_data$access_token = data.access_token) !== null && _data$access_token !== void 0 ? _data$access_token : "";
|
|
538
|
+
const refreshToken = (_data$refresh_token = data.refresh_token) !== null && _data$refresh_token !== void 0 ? _data$refresh_token : "";
|
|
539
|
+
const expiresAt = Date.now() + expiresIn * 1e3;
|
|
540
|
+
const isValid = [tokenType, expiresIn, accessToken, refreshToken].every(Boolean);
|
|
541
|
+
if (isValid) {
|
|
542
|
+
await setONESToken({
|
|
543
|
+
token_type: tokenType,
|
|
544
|
+
expires_in: expiresIn,
|
|
545
|
+
expires_at: expiresAt,
|
|
546
|
+
access_token: accessToken,
|
|
547
|
+
refresh_token: refreshToken
|
|
548
|
+
});
|
|
549
|
+
return accessToken;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
return "";
|
|
553
|
+
};
|
|
554
|
+
const getHeaders = async (value) => {
|
|
555
|
+
const token = await getAvailableONESTokeAccessToken();
|
|
556
|
+
if (token) {
|
|
557
|
+
return merge({
|
|
558
|
+
Authorization: `Bearer ${token}`
|
|
559
|
+
}, value);
|
|
560
|
+
}
|
|
561
|
+
consoleUnauthorizedMessage();
|
|
562
|
+
process.exit(1);
|
|
563
|
+
};
|
|
564
|
+
const handleError = (error) => {
|
|
565
|
+
var _error$response, _error$response2;
|
|
566
|
+
if (((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.status) === 401) {
|
|
567
|
+
console.log(error.response.statusText);
|
|
568
|
+
consoleUnauthorizedMessage();
|
|
569
|
+
process.exit(1);
|
|
570
|
+
}
|
|
571
|
+
if ((_error$response2 = error.response) !== null && _error$response2 !== void 0 && _error$response2.data) {
|
|
572
|
+
try {
|
|
573
|
+
const message = JSON.stringify(error.response.data, null, 2);
|
|
574
|
+
console.error(message);
|
|
575
|
+
process.exit(1);
|
|
576
|
+
} catch (error2) {
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
console.error(error);
|
|
580
|
+
return {};
|
|
581
|
+
};
|
|
582
|
+
const startWaiting = () => {
|
|
583
|
+
const time = 3e3;
|
|
584
|
+
let spinner = null;
|
|
585
|
+
const sid = setTimeout(() => {
|
|
586
|
+
spinner = ora("Waiting for response...");
|
|
587
|
+
spinner.start();
|
|
588
|
+
}, time);
|
|
589
|
+
const cancelWaiting = () => {
|
|
590
|
+
clearTimeout(sid);
|
|
591
|
+
if (spinner) {
|
|
592
|
+
spinner.stop();
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
return cancelWaiting;
|
|
596
|
+
};
|
|
597
|
+
const fetchAppBase = async (params) => {
|
|
598
|
+
var _params$url;
|
|
599
|
+
const url = await getURL((_params$url = params.url) !== null && _params$url !== void 0 ? _params$url : "", params.pathMap, params.queryMap);
|
|
600
|
+
const headers = await getHeaders(params.headers);
|
|
601
|
+
const response = await axios({
|
|
602
|
+
...params,
|
|
603
|
+
url,
|
|
604
|
+
headers,
|
|
605
|
+
timeout: REQUEST_TIMEOUT
|
|
606
|
+
});
|
|
607
|
+
return response.data;
|
|
608
|
+
};
|
|
609
|
+
const fetchHostedAbilityBase = async (params) => {
|
|
610
|
+
var _params$url2;
|
|
611
|
+
const url = await getURL((_params$url2 = params.url) !== null && _params$url2 !== void 0 ? _params$url2 : "", params.pathMap, params.queryMap);
|
|
612
|
+
const headers = await getHostedFetchHeaders(params.headers);
|
|
613
|
+
const response = await axios({
|
|
614
|
+
...params,
|
|
615
|
+
url,
|
|
616
|
+
headers,
|
|
617
|
+
timeout: REQUEST_TIMEOUT
|
|
618
|
+
});
|
|
619
|
+
return response.data;
|
|
620
|
+
};
|
|
621
|
+
const fetchAppList = async (appID) => {
|
|
622
|
+
return await fetchAppBase({
|
|
623
|
+
url: API.APP_LIST,
|
|
624
|
+
method: "GET",
|
|
625
|
+
queryMap: {
|
|
626
|
+
app_id: appID
|
|
627
|
+
}
|
|
628
|
+
}).catch(handleError);
|
|
629
|
+
};
|
|
630
|
+
const fetchTokenInfo = async () => {
|
|
631
|
+
return await fetchAppBase({
|
|
632
|
+
url: API.TOKEN_INFO,
|
|
633
|
+
method: "GET"
|
|
634
|
+
}).catch(handleError);
|
|
635
|
+
};
|
|
636
|
+
const fetchHostedToken = async (data) => {
|
|
637
|
+
return await fetchAppBase({
|
|
638
|
+
url: API.HOSTED_TOKEN,
|
|
639
|
+
method: "POST",
|
|
640
|
+
data
|
|
641
|
+
}).catch(handleError);
|
|
642
|
+
};
|
|
643
|
+
const fetchHostedAbilityStorageDevDeclare = async (appID, data) => {
|
|
644
|
+
return await fetchHostedAbilityBase({
|
|
645
|
+
url: API.HOSTED_ABILITY_STORAGE_DEV_DECLARE,
|
|
646
|
+
method: "POST",
|
|
647
|
+
pathMap: {
|
|
648
|
+
appID
|
|
649
|
+
},
|
|
650
|
+
data
|
|
651
|
+
}).catch(handleError);
|
|
652
|
+
};
|
|
653
|
+
const fetchAppInstall = async (data) => {
|
|
654
|
+
var _appList$data$0$insta, _appList$data;
|
|
655
|
+
const appID = getAppManifestJSON().app.id;
|
|
656
|
+
const appList = await fetchAppList(appID);
|
|
657
|
+
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 : "";
|
|
658
|
+
if (installationID) {
|
|
659
|
+
return await fetchAppBase({
|
|
660
|
+
url: API.APP_UPGRADE,
|
|
661
|
+
method: "POST",
|
|
662
|
+
pathMap: {
|
|
663
|
+
installation_id: installationID
|
|
664
|
+
},
|
|
665
|
+
data
|
|
666
|
+
}).catch(handleError);
|
|
667
|
+
}
|
|
668
|
+
return await fetchAppBase({
|
|
669
|
+
url: API.APP_INSTALL,
|
|
670
|
+
method: "POST",
|
|
671
|
+
data
|
|
672
|
+
}).catch(handleError);
|
|
673
|
+
};
|
|
674
|
+
const fetchAppUninstall = async () => {
|
|
675
|
+
var _appList$data$0$insta2, _appList$data2;
|
|
676
|
+
const appID = getAppManifestJSON().app.id;
|
|
677
|
+
const appList = await fetchAppList(appID);
|
|
678
|
+
const installationID = (_appList$data$0$insta2 = (_appList$data2 = appList.data) === null || _appList$data2 === void 0 || (_appList$data2 = _appList$data2[0]) === null || _appList$data2 === void 0 ? void 0 : _appList$data2.installation_id) !== null && _appList$data$0$insta2 !== void 0 ? _appList$data$0$insta2 : "";
|
|
679
|
+
if (installationID) {
|
|
680
|
+
return await fetchAppBase({
|
|
681
|
+
url: API.APP_UNINSTALL,
|
|
682
|
+
method: "POST",
|
|
683
|
+
pathMap: {
|
|
684
|
+
installation_id: installationID
|
|
685
|
+
}
|
|
686
|
+
}).catch(handleError);
|
|
687
|
+
}
|
|
688
|
+
consoleAppNotInstalledMessage();
|
|
689
|
+
process.exit(1);
|
|
690
|
+
};
|
|
691
|
+
const fetchAppEnable = async () => {
|
|
692
|
+
var _appList$data$0$insta3, _appList$data3;
|
|
693
|
+
const appID = getAppManifestJSON().app.id;
|
|
694
|
+
const appList = await fetchAppList(appID);
|
|
695
|
+
const installationID = (_appList$data$0$insta3 = (_appList$data3 = appList.data) === null || _appList$data3 === void 0 || (_appList$data3 = _appList$data3[0]) === null || _appList$data3 === void 0 ? void 0 : _appList$data3.installation_id) !== null && _appList$data$0$insta3 !== void 0 ? _appList$data$0$insta3 : "";
|
|
696
|
+
if (installationID) {
|
|
697
|
+
return await fetchAppBase({
|
|
698
|
+
url: API.APP_ENABLE,
|
|
699
|
+
method: "POST",
|
|
700
|
+
pathMap: {
|
|
701
|
+
installation_id: installationID
|
|
702
|
+
}
|
|
703
|
+
}).catch(handleError);
|
|
704
|
+
}
|
|
705
|
+
consoleAppNotInstalledMessage();
|
|
706
|
+
process.exit(1);
|
|
707
|
+
};
|
|
708
|
+
const fetchAppDisable = async () => {
|
|
709
|
+
var _appList$data$0$insta4, _appList$data4;
|
|
710
|
+
const appID = getAppManifestJSON().app.id;
|
|
711
|
+
const appList = await fetchAppList(appID);
|
|
712
|
+
const installationID = (_appList$data$0$insta4 = (_appList$data4 = appList.data) === null || _appList$data4 === void 0 || (_appList$data4 = _appList$data4[0]) === null || _appList$data4 === void 0 ? void 0 : _appList$data4.installation_id) !== null && _appList$data$0$insta4 !== void 0 ? _appList$data$0$insta4 : "";
|
|
713
|
+
if (installationID) {
|
|
714
|
+
return await fetchAppBase({
|
|
715
|
+
url: API.APP_DISABLE,
|
|
716
|
+
method: "POST",
|
|
717
|
+
pathMap: {
|
|
718
|
+
installation_id: installationID
|
|
719
|
+
}
|
|
720
|
+
}).catch(handleError);
|
|
721
|
+
}
|
|
722
|
+
consoleAppNotInstalledMessage();
|
|
723
|
+
process.exit(1);
|
|
724
|
+
};
|
|
725
|
+
const checkTokenInfo = async () => {
|
|
726
|
+
let boolean = true;
|
|
727
|
+
const regionURL = await getRegionURL().catch(() => "");
|
|
728
|
+
const token = await getAvailableONESTokeAccessToken().catch(() => "");
|
|
729
|
+
if (token && regionURL) {
|
|
730
|
+
await fetchAppBase({
|
|
731
|
+
url: API.APP_LIST,
|
|
732
|
+
method: "GET"
|
|
733
|
+
}).catch(() => {
|
|
734
|
+
boolean = false;
|
|
735
|
+
});
|
|
736
|
+
} else {
|
|
737
|
+
boolean = false;
|
|
738
|
+
}
|
|
739
|
+
return boolean;
|
|
740
|
+
};
|
|
741
|
+
const isPortNumber = /^[1-9]\d{0,4}$/;
|
|
742
|
+
const normalize$9 = async (options) => {
|
|
743
|
+
var _options$clearStorage;
|
|
744
|
+
const portInput = options.port;
|
|
745
|
+
if (portInput)
|
|
746
|
+
;
|
|
747
|
+
else {
|
|
748
|
+
return throwError(ErrorCode.MISSING_PORT, i18n.t("error.tunnel.missingPort"));
|
|
749
|
+
}
|
|
750
|
+
const portString = String(portInput);
|
|
751
|
+
const portNumber = Number(portString);
|
|
752
|
+
if (isPortNumber.test(portString))
|
|
753
|
+
;
|
|
754
|
+
else {
|
|
755
|
+
return throwError(ErrorCode.INCORRECT_PORT, i18n.t("error.tunnel.incorrectPort"));
|
|
756
|
+
}
|
|
757
|
+
if (portNumber < minPortNumber || portNumber > maxPortNumber) {
|
|
758
|
+
return throwError(ErrorCode.INCORRECT_PORT, i18n.t("error.tunnel.incorrectPort"));
|
|
759
|
+
}
|
|
760
|
+
const port = portString;
|
|
761
|
+
validateAppManifestJSON();
|
|
762
|
+
return {
|
|
763
|
+
port,
|
|
764
|
+
clearStorage: (_options$clearStorage = options.clearStorage) !== null && _options$clearStorage !== void 0 ? _options$clearStorage : false
|
|
765
|
+
};
|
|
766
|
+
};
|
|
767
|
+
const getTunnelContext = async () => {
|
|
768
|
+
var _appManifestJSON$app$, _appManifestJSON$app, _store$region_url, _store$ones_token$acc, _store$ones_token;
|
|
769
|
+
const appManifestJSON = getAppManifestJSON();
|
|
770
|
+
const appID = (_appManifestJSON$app$ = (_appManifestJSON$app = appManifestJSON.app) === null || _appManifestJSON$app === void 0 ? void 0 : _appManifestJSON$app.id) !== null && _appManifestJSON$app$ !== void 0 ? _appManifestJSON$app$ : "";
|
|
771
|
+
const store = await getStore();
|
|
772
|
+
const regionURL = (_store$region_url = store.region_url) !== null && _store$region_url !== void 0 ? _store$region_url : "";
|
|
773
|
+
const onesTokenAccessToken = (_store$ones_token$acc = (_store$ones_token = store.ones_token) === null || _store$ones_token === void 0 ? void 0 : _store$ones_token.access_token) !== null && _store$ones_token$acc !== void 0 ? _store$ones_token$acc : "";
|
|
774
|
+
if (appID && regionURL && onesTokenAccessToken) {
|
|
775
|
+
return {
|
|
776
|
+
appID,
|
|
777
|
+
regionURL,
|
|
778
|
+
appManifestJSON
|
|
779
|
+
};
|
|
780
|
+
}
|
|
781
|
+
consoleUnauthorizedMessage();
|
|
782
|
+
process.exit(1);
|
|
783
|
+
};
|
|
784
|
+
const getStorageTokenScopes = (ones2) => {
|
|
785
|
+
const storage = ones2 === null || ones2 === void 0 ? void 0 : ones2.storage;
|
|
786
|
+
if (!storage) {
|
|
787
|
+
return [];
|
|
788
|
+
}
|
|
789
|
+
const scopes = /* @__PURE__ */ new Set();
|
|
790
|
+
if (Array.isArray(storage.entities) && storage.entities.length > 0) {
|
|
791
|
+
scopes.add(HostedTokenScope.STORAGE_ENTITY);
|
|
792
|
+
}
|
|
793
|
+
if (storage.object !== void 0 && storage.object !== null && storage.object !== false) {
|
|
794
|
+
scopes.add(HostedTokenScope.STORAGE_OBJECT);
|
|
795
|
+
}
|
|
796
|
+
return Array.from(scopes);
|
|
797
|
+
};
|
|
798
|
+
const getRelayScope = () => {
|
|
799
|
+
return HostedTokenScope.RELAY;
|
|
800
|
+
};
|
|
801
|
+
const buildTunnelUrl = async () => {
|
|
802
|
+
const {
|
|
803
|
+
appID,
|
|
804
|
+
regionURL
|
|
805
|
+
} = await getTunnelContext();
|
|
806
|
+
const url = new URL(regionURL);
|
|
807
|
+
url.pathname = `/platform/app/relay/dispatch/${appID}`;
|
|
808
|
+
return url.toString();
|
|
809
|
+
};
|
|
810
|
+
const MANIFEST_PATH = "/manifest";
|
|
811
|
+
const ONES_CLI_INTERNAL_MANIFEST_PATH = "/__ones_cli_internal_manifest__";
|
|
812
|
+
const MAX_RELAY_BODY_BYTES = 64 * 1024 * 1024;
|
|
813
|
+
class TunnelClient {
|
|
814
|
+
constructor(localPort, baseUrl, appID, hostedToken) {
|
|
815
|
+
let enableInternalManifestRoute = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : true;
|
|
816
|
+
let replaceExisting = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : true;
|
|
817
|
+
this.ws = null;
|
|
818
|
+
this.localPort = localPort;
|
|
819
|
+
this.baseUrl = baseUrl;
|
|
820
|
+
this.appID = appID;
|
|
821
|
+
this.hostedToken = hostedToken;
|
|
822
|
+
this.enableInternalManifestRoute = enableInternalManifestRoute;
|
|
823
|
+
this.replaceExisting = replaceExisting;
|
|
824
|
+
}
|
|
825
|
+
async connect() {
|
|
826
|
+
const proxyUrl = this.buildProxyUrl();
|
|
827
|
+
this.ws = new WebSocket(proxyUrl, {
|
|
828
|
+
headers: {
|
|
829
|
+
Authorization: `Bearer ${this.hostedToken}`
|
|
830
|
+
},
|
|
831
|
+
maxPayload: MAX_RELAY_BODY_BYTES
|
|
832
|
+
});
|
|
833
|
+
this.ws.on("message", async (data) => {
|
|
834
|
+
const message = this.parseMessage(data);
|
|
835
|
+
if (!message) {
|
|
836
|
+
return;
|
|
837
|
+
}
|
|
838
|
+
await this.handleMessage(message);
|
|
839
|
+
});
|
|
840
|
+
this.ws.on("ping", (data) => {
|
|
841
|
+
var _this$ws;
|
|
842
|
+
(_this$ws = this.ws) === null || _this$ws === void 0 || _this$ws.pong(data);
|
|
843
|
+
});
|
|
844
|
+
this.ws.on("error", (error) => {
|
|
845
|
+
console.error("WebSocket error:", error);
|
|
846
|
+
});
|
|
847
|
+
return new Promise((resolve2, reject) => {
|
|
848
|
+
var _this$ws2, _this$ws3;
|
|
849
|
+
(_this$ws2 = this.ws) === null || _this$ws2 === void 0 || _this$ws2.on("open", () => resolve2());
|
|
850
|
+
(_this$ws3 = this.ws) === null || _this$ws3 === void 0 || _this$ws3.on("error", reject);
|
|
851
|
+
});
|
|
852
|
+
}
|
|
853
|
+
close() {
|
|
854
|
+
var _this$ws4;
|
|
855
|
+
(_this$ws4 = this.ws) === null || _this$ws4 === void 0 || _this$ws4.close();
|
|
856
|
+
}
|
|
857
|
+
buildProxyUrl() {
|
|
858
|
+
const url = new URL("/platform/app/relay/", this.baseUrl);
|
|
859
|
+
url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
|
|
860
|
+
url.searchParams.set("app_id", this.appID);
|
|
861
|
+
url.searchParams.set("replace_existing", String(this.replaceExisting));
|
|
862
|
+
return url.toString();
|
|
863
|
+
}
|
|
864
|
+
parseMessage(data) {
|
|
865
|
+
const buffer = this.toBuffer(data);
|
|
866
|
+
if (!buffer) {
|
|
867
|
+
return null;
|
|
868
|
+
}
|
|
869
|
+
if (buffer.length >= 4) {
|
|
870
|
+
const binary = this.parseBinaryEnvelope(buffer);
|
|
871
|
+
if (binary) {
|
|
872
|
+
return binary;
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
return this.parseJSONEnvelope(buffer.toString());
|
|
876
|
+
}
|
|
877
|
+
async handleMessage(message) {
|
|
878
|
+
const request = this.getRequestPayload(message);
|
|
879
|
+
if (!request) {
|
|
880
|
+
return;
|
|
881
|
+
}
|
|
882
|
+
if (this.enableInternalManifestRoute && request.path === ONES_CLI_INTERNAL_MANIFEST_PATH) {
|
|
883
|
+
const appManifest = getAppManifestJSON().app;
|
|
884
|
+
const baseURL = await buildTunnelUrl();
|
|
885
|
+
const reply = {
|
|
886
|
+
id: message.id,
|
|
887
|
+
payload: {
|
|
888
|
+
status: 200,
|
|
889
|
+
headers: {
|
|
890
|
+
"content-type": ["application/json"]
|
|
891
|
+
},
|
|
892
|
+
body: {
|
|
893
|
+
...appManifest,
|
|
894
|
+
base_url: baseURL
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
};
|
|
898
|
+
this.sendBinaryEnvelope(reply);
|
|
899
|
+
return;
|
|
900
|
+
}
|
|
901
|
+
try {
|
|
902
|
+
const response = await this.forwardRequest(request);
|
|
903
|
+
const reply = {
|
|
904
|
+
id: message.id,
|
|
905
|
+
payload: response
|
|
906
|
+
};
|
|
907
|
+
this.sendBinaryEnvelope(reply);
|
|
908
|
+
} catch (error) {
|
|
909
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
910
|
+
console.error("Error forwarding request:", errorMessage);
|
|
911
|
+
const reply = {
|
|
912
|
+
id: message.id,
|
|
913
|
+
payload: {
|
|
914
|
+
status: 500,
|
|
915
|
+
headers: {
|
|
916
|
+
"x-agent-error": [errorMessage]
|
|
917
|
+
},
|
|
918
|
+
body: errorMessage
|
|
919
|
+
}
|
|
920
|
+
};
|
|
921
|
+
this.sendBinaryEnvelope(reply);
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
getRequestPayload(message) {
|
|
925
|
+
const payload = message.payload;
|
|
926
|
+
if (!(payload !== null && payload !== void 0 && payload.method) || !(payload !== null && payload !== void 0 && payload.path)) {
|
|
927
|
+
return null;
|
|
928
|
+
}
|
|
929
|
+
return payload;
|
|
930
|
+
}
|
|
931
|
+
async forwardRequest(payload) {
|
|
932
|
+
const url = new URL(payload.path, `http://127.0.0.1:${this.localPort}`);
|
|
933
|
+
if (payload.query) {
|
|
934
|
+
Object.entries(payload.query).forEach((_ref) => {
|
|
935
|
+
let [key, value] = _ref;
|
|
936
|
+
if (Array.isArray(value)) {
|
|
937
|
+
value.forEach((item) => {
|
|
938
|
+
url.searchParams.append(key, item);
|
|
939
|
+
});
|
|
940
|
+
return;
|
|
941
|
+
}
|
|
942
|
+
url.searchParams.append(key, value);
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
const response = await axios.request({
|
|
946
|
+
url: url.toString(),
|
|
947
|
+
method: payload.method,
|
|
948
|
+
headers: payload.headers,
|
|
949
|
+
data: payload.body,
|
|
950
|
+
responseType: "arraybuffer",
|
|
951
|
+
validateStatus: () => true,
|
|
952
|
+
maxBodyLength: MAX_RELAY_BODY_BYTES,
|
|
953
|
+
maxContentLength: MAX_RELAY_BODY_BYTES
|
|
954
|
+
});
|
|
955
|
+
const responseBytes = Buffer.from(response.data);
|
|
956
|
+
return {
|
|
957
|
+
status: response.status,
|
|
958
|
+
headers: this.collectHeaders(response.headers),
|
|
959
|
+
body: responseBytes
|
|
960
|
+
};
|
|
961
|
+
}
|
|
962
|
+
collectHeaders(headers) {
|
|
963
|
+
const collected = {};
|
|
964
|
+
Object.entries(headers).forEach((_ref2) => {
|
|
965
|
+
let [key, value] = _ref2;
|
|
966
|
+
if (Array.isArray(value)) {
|
|
967
|
+
collected[key] = value.map((item) => String(item));
|
|
968
|
+
return;
|
|
969
|
+
}
|
|
970
|
+
if (value !== void 0 && value !== null) {
|
|
971
|
+
collected[key] = [String(value)];
|
|
972
|
+
}
|
|
973
|
+
});
|
|
974
|
+
return collected;
|
|
975
|
+
}
|
|
976
|
+
sendBinaryEnvelope(envelope) {
|
|
977
|
+
var _this$ws5;
|
|
978
|
+
const encoded = this.encodeBinaryEnvelope(envelope);
|
|
979
|
+
(_this$ws5 = this.ws) === null || _this$ws5 === void 0 || _this$ws5.send(encoded);
|
|
980
|
+
}
|
|
981
|
+
encodeBinaryEnvelope(envelope) {
|
|
982
|
+
var _envelope$payload;
|
|
983
|
+
const payload = (_envelope$payload = envelope.payload) !== null && _envelope$payload !== void 0 ? _envelope$payload : {};
|
|
984
|
+
const body = this.toBodyBuffer(payload.body);
|
|
985
|
+
if (body.length > MAX_RELAY_BODY_BYTES) {
|
|
986
|
+
throw new Error("relay body too large");
|
|
987
|
+
}
|
|
988
|
+
const metaPayload = {
|
|
989
|
+
...payload
|
|
990
|
+
};
|
|
991
|
+
delete metaPayload.body;
|
|
992
|
+
const meta = Buffer.from(JSON.stringify({
|
|
993
|
+
id: envelope.id,
|
|
994
|
+
payload: metaPayload
|
|
995
|
+
}), "utf8");
|
|
996
|
+
const header = Buffer.allocUnsafe(4);
|
|
997
|
+
header.writeUInt32BE(meta.length, 0);
|
|
998
|
+
return Buffer.concat([header, meta, body]);
|
|
999
|
+
}
|
|
1000
|
+
toBodyBuffer(body) {
|
|
1001
|
+
if (body === void 0 || body === null) {
|
|
1002
|
+
return Buffer.alloc(0);
|
|
1003
|
+
}
|
|
1004
|
+
if (Buffer.isBuffer(body)) {
|
|
1005
|
+
return body;
|
|
1006
|
+
}
|
|
1007
|
+
if (body instanceof ArrayBuffer) {
|
|
1008
|
+
return Buffer.from(body);
|
|
1009
|
+
}
|
|
1010
|
+
if (ArrayBuffer.isView(body)) {
|
|
1011
|
+
return Buffer.from(body.buffer, body.byteOffset, body.byteLength);
|
|
1012
|
+
}
|
|
1013
|
+
if (typeof body === "string") {
|
|
1014
|
+
return Buffer.from(body, "utf8");
|
|
1015
|
+
}
|
|
1016
|
+
return Buffer.from(JSON.stringify(body), "utf8");
|
|
1017
|
+
}
|
|
1018
|
+
parseBinaryEnvelope(buffer) {
|
|
1019
|
+
const metaLength = buffer.readUInt32BE(0);
|
|
1020
|
+
if (metaLength <= 0 || 4 + metaLength > buffer.length) {
|
|
1021
|
+
return null;
|
|
1022
|
+
}
|
|
1023
|
+
const metaRaw = buffer.subarray(4, 4 + metaLength).toString("utf8");
|
|
1024
|
+
try {
|
|
1025
|
+
const envelope = JSON.parse(metaRaw);
|
|
1026
|
+
if (!(envelope !== null && envelope !== void 0 && envelope.payload)) {
|
|
1027
|
+
return envelope;
|
|
1028
|
+
}
|
|
1029
|
+
const body = buffer.subarray(4 + metaLength);
|
|
1030
|
+
if (body.length > MAX_RELAY_BODY_BYTES) {
|
|
1031
|
+
console.error("Binary tunnel body exceeds size limit");
|
|
1032
|
+
return null;
|
|
1033
|
+
}
|
|
1034
|
+
const payload = envelope.payload;
|
|
1035
|
+
payload.body = body;
|
|
1036
|
+
return envelope;
|
|
1037
|
+
} catch (error) {
|
|
1038
|
+
console.error("Invalid binary tunnel message:", error);
|
|
1039
|
+
return null;
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
parseJSONEnvelope(payload) {
|
|
1043
|
+
try {
|
|
1044
|
+
const message = JSON.parse(payload);
|
|
1045
|
+
if (!message) {
|
|
1046
|
+
return null;
|
|
1047
|
+
}
|
|
1048
|
+
return message;
|
|
1049
|
+
} catch (error) {
|
|
1050
|
+
console.error("Invalid tunnel message:", error);
|
|
1051
|
+
return null;
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
toBuffer(data) {
|
|
1055
|
+
if (Buffer.isBuffer(data)) {
|
|
1056
|
+
return data;
|
|
1057
|
+
}
|
|
1058
|
+
if (Array.isArray(data)) {
|
|
1059
|
+
return Buffer.concat(data);
|
|
1060
|
+
}
|
|
1061
|
+
if (data instanceof ArrayBuffer) {
|
|
1062
|
+
return Buffer.from(data);
|
|
1063
|
+
}
|
|
1064
|
+
return null;
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
const invokeTunnel = async function(port) {
|
|
1068
|
+
var _options$rebuildWhenE, _options$enableIntern, _options$clearStorage, _hostedTokenResponse$, _appManifestJSON$ones, _appManifestJSON$ones2;
|
|
1069
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1070
|
+
const {
|
|
1071
|
+
appManifestJSON,
|
|
1072
|
+
appID,
|
|
1073
|
+
regionURL
|
|
1074
|
+
} = await getTunnelContext();
|
|
1075
|
+
const rebuildWhenExists = (_options$rebuildWhenE = options.rebuildWhenExists) !== null && _options$rebuildWhenE !== void 0 ? _options$rebuildWhenE : true;
|
|
1076
|
+
const enableInternalManifestRoute = (_options$enableIntern = options.enableInternalManifestRoute) !== null && _options$enableIntern !== void 0 ? _options$enableIntern : true;
|
|
1077
|
+
const storageScopes = getStorageTokenScopes(appManifestJSON.ones);
|
|
1078
|
+
const scopes = Array.from(/* @__PURE__ */ new Set([...storageScopes, getRelayScope()]));
|
|
1079
|
+
const hostedTokenResponse = await fetchHostedToken({
|
|
1080
|
+
app_id: appID,
|
|
1081
|
+
scopes,
|
|
1082
|
+
clear_storage: (_options$clearStorage = options.clearStorageForDev) !== null && _options$clearStorage !== void 0 ? _options$clearStorage : false
|
|
1083
|
+
});
|
|
1084
|
+
const hostedToken = hostedTokenResponse === null || hostedTokenResponse === void 0 || (_hostedTokenResponse$ = hostedTokenResponse.data) === null || _hostedTokenResponse$ === void 0 ? void 0 : _hostedTokenResponse$.hosted_token;
|
|
1085
|
+
if (!hostedToken) {
|
|
1086
|
+
return throwError(ErrorCode.HOSTED_TOKEN_EMPTY, i18n.t("error.hostedToken.empty"));
|
|
1087
|
+
}
|
|
1088
|
+
await setHostToken(hostedToken);
|
|
1089
|
+
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 : [];
|
|
1090
|
+
if (entities.length > 0) {
|
|
1091
|
+
await fetchHostedAbilityStorageDevDeclare(appID, {
|
|
1092
|
+
opkx_content: appManifestJSON
|
|
1093
|
+
});
|
|
1094
|
+
}
|
|
1095
|
+
const client = new TunnelClient(port, regionURL, appID, hostedToken, enableInternalManifestRoute, rebuildWhenExists);
|
|
1096
|
+
await client.connect();
|
|
1097
|
+
};
|
|
1098
|
+
const tunnel = async function() {
|
|
1099
|
+
var _normalizedOptions$cl;
|
|
1100
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1101
|
+
args[_key] = arguments[_key];
|
|
1102
|
+
}
|
|
1103
|
+
const {
|
|
1104
|
+
options
|
|
1105
|
+
} = getCommandOptions(args, tunnelCommandArguments);
|
|
1106
|
+
const normalizedOptions = await normalize$9(options);
|
|
1107
|
+
const port = Number(normalizedOptions.port);
|
|
1108
|
+
const cancelWaiting = startWaiting();
|
|
1109
|
+
await invokeTunnel(port, {
|
|
1110
|
+
enableInternalManifestRoute: false,
|
|
1111
|
+
rebuildWhenExists: true,
|
|
1112
|
+
clearStorageForDev: (_normalizedOptions$cl = normalizedOptions.clearStorage) !== null && _normalizedOptions$cl !== void 0 ? _normalizedOptions$cl : false
|
|
1113
|
+
});
|
|
1114
|
+
cancelWaiting();
|
|
1115
|
+
const tunnelUrl = await buildTunnelUrl();
|
|
1116
|
+
console.log(`Relay endpoint: ${tunnelUrl}`);
|
|
1117
|
+
};
|
|
1118
|
+
const normalize$8 = async (options) => {
|
|
1119
|
+
noop(options);
|
|
1120
|
+
return {};
|
|
1121
|
+
};
|
|
1122
|
+
const displayAppDetail = async (installationID) => {
|
|
1123
|
+
var _tokenInfo$org$uuid, _tokenInfo$org, _tokenInfo$teams$0$uu, _tokenInfo$teams, _tokenInfo$org$visibi, _tokenInfo$org2;
|
|
1124
|
+
const tokenInfo = await fetchTokenInfo();
|
|
1125
|
+
const orgUUID = (_tokenInfo$org$uuid = (_tokenInfo$org = tokenInfo.org) === null || _tokenInfo$org === void 0 ? void 0 : _tokenInfo$org.uuid) !== null && _tokenInfo$org$uuid !== void 0 ? _tokenInfo$org$uuid : "";
|
|
1126
|
+
const teamUUID = (_tokenInfo$teams$0$uu = (_tokenInfo$teams = tokenInfo.teams) === null || _tokenInfo$teams === void 0 || (_tokenInfo$teams = _tokenInfo$teams[0]) === null || _tokenInfo$teams === void 0 ? void 0 : _tokenInfo$teams.uuid) !== null && _tokenInfo$teams$0$uu !== void 0 ? _tokenInfo$teams$0$uu : "";
|
|
1127
|
+
const isOrgVisible = (_tokenInfo$org$visibi = (_tokenInfo$org2 = tokenInfo.org) === null || _tokenInfo$org2 === void 0 ? void 0 : _tokenInfo$org2.visibility) !== null && _tokenInfo$org$visibi !== void 0 ? _tokenInfo$org$visibi : false;
|
|
1128
|
+
const baseURL = await getBaseURL();
|
|
1129
|
+
if (isOrgVisible && orgUUID) {
|
|
1130
|
+
const url = `${baseURL}project/#/org/${orgUUID}/setting/app_manager/platform_app/${installationID}`;
|
|
1131
|
+
console.log(`See App detail: ${url}`);
|
|
1132
|
+
}
|
|
1133
|
+
if (!isOrgVisible && teamUUID) {
|
|
1134
|
+
const url = `${baseURL}project/#/team/${teamUUID}/team_setting/app_manager/platform_app/${installationID}`;
|
|
1135
|
+
console.log(`See App detail: ${url}`);
|
|
1136
|
+
}
|
|
1137
|
+
};
|
|
1138
|
+
const invokeInstall = async (manifestUrl) => {
|
|
1139
|
+
const {
|
|
1140
|
+
app
|
|
1141
|
+
} = getAppManifestJSON();
|
|
1142
|
+
const appName = app.name;
|
|
1143
|
+
const appID = app.id;
|
|
1144
|
+
const cancelWaiting = startWaiting();
|
|
1145
|
+
const result = await fetchAppInstall({
|
|
1146
|
+
manifest_url: manifestUrl,
|
|
1147
|
+
options: {
|
|
1148
|
+
enable: true
|
|
1149
|
+
}
|
|
1150
|
+
});
|
|
1151
|
+
cancelWaiting();
|
|
1152
|
+
if (result.code === "OK") {
|
|
1153
|
+
var _appList$data$0$insta, _appList$data;
|
|
1154
|
+
console.log(`App "${appName}" installed successfully!`);
|
|
1155
|
+
const appList = await fetchAppList(appID);
|
|
1156
|
+
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
|
+
if (installationID) {
|
|
1158
|
+
await displayAppDetail(installationID);
|
|
1159
|
+
}
|
|
1160
|
+
return true;
|
|
1161
|
+
} else {
|
|
1162
|
+
console.log(`App "${appName}" installed failed!`);
|
|
1163
|
+
console.error(JSON.stringify(result, null, 2));
|
|
1164
|
+
}
|
|
1165
|
+
return false;
|
|
1166
|
+
};
|
|
1167
|
+
const getManifestUrl = async () => {
|
|
1168
|
+
const tunnelUrl = await buildTunnelUrl();
|
|
1169
|
+
const customManifestUrl = `${tunnelUrl}${MANIFEST_PATH}`;
|
|
1170
|
+
const internalManifestUrl = `${tunnelUrl}${ONES_CLI_INTERNAL_MANIFEST_PATH}`;
|
|
1171
|
+
const internalResult = await axios.get(internalManifestUrl, {
|
|
1172
|
+
timeout: REQUEST_TIMEOUT
|
|
1173
|
+
}).then((response) => {
|
|
1174
|
+
if (response.status === 200) {
|
|
1175
|
+
return internalManifestUrl;
|
|
1176
|
+
}
|
|
1177
|
+
return null;
|
|
1178
|
+
}).catch(noop);
|
|
1179
|
+
if (internalResult) {
|
|
1180
|
+
return internalResult;
|
|
1181
|
+
}
|
|
1182
|
+
const customResult = await axios.get(customManifestUrl, {
|
|
1183
|
+
timeout: REQUEST_TIMEOUT
|
|
1184
|
+
}).then((response) => {
|
|
1185
|
+
if (response.status === 200) {
|
|
1186
|
+
return customManifestUrl;
|
|
1187
|
+
}
|
|
1188
|
+
return null;
|
|
1189
|
+
}).catch(noop);
|
|
1190
|
+
if (customResult) {
|
|
1191
|
+
return customResult;
|
|
1192
|
+
}
|
|
1193
|
+
return null;
|
|
1194
|
+
};
|
|
1195
|
+
const install = async function() {
|
|
1196
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1197
|
+
args[_key] = arguments[_key];
|
|
1198
|
+
}
|
|
1199
|
+
const {
|
|
1200
|
+
options
|
|
1201
|
+
} = getCommandOptions(args, installCommandArguments);
|
|
1202
|
+
const normalizedOptions = await normalize$8(options);
|
|
1203
|
+
noop(normalizedOptions);
|
|
1204
|
+
const {
|
|
1205
|
+
app
|
|
1206
|
+
} = getAppManifestJSON();
|
|
1207
|
+
const appName = app.name;
|
|
1208
|
+
const manifestUrl = await getManifestUrl();
|
|
1209
|
+
if (!manifestUrl) {
|
|
1210
|
+
console.log(`App "${appName}" server not available!`);
|
|
1211
|
+
console.log('Use "ones dev" command or "ones tunnel" command to start the server first');
|
|
1212
|
+
process.exit(1);
|
|
1213
|
+
}
|
|
1214
|
+
await invokeInstall(manifestUrl);
|
|
1215
|
+
};
|
|
1216
|
+
var InstallOptions = /* @__PURE__ */ ((InstallOptions2) => {
|
|
1217
|
+
InstallOptions2["AUTO"] = "auto";
|
|
1218
|
+
InstallOptions2["TRUE"] = "true";
|
|
1219
|
+
InstallOptions2["FALSE"] = "false";
|
|
1220
|
+
return InstallOptions2;
|
|
1221
|
+
})(InstallOptions || {});
|
|
1222
|
+
var DevCommandScripts = /* @__PURE__ */ ((DevCommandScripts2) => {
|
|
1223
|
+
DevCommandScripts2["Concurrently"] = "concurrently";
|
|
1224
|
+
DevCommandScripts2["Nest"] = "nest";
|
|
1225
|
+
DevCommandScripts2["Vite"] = "vite";
|
|
1226
|
+
return DevCommandScripts2;
|
|
1227
|
+
})(DevCommandScripts || {});
|
|
1228
|
+
const defaultInstall = InstallOptions.AUTO;
|
|
1229
|
+
const normalize$7 = async (options) => {
|
|
1230
|
+
var _options$install, _options$command, _options$clearStorage;
|
|
1231
|
+
let install2 = (_options$install = options.install) !== null && _options$install !== void 0 ? _options$install : defaultInstall;
|
|
1232
|
+
const command = (_options$command = options.command) !== null && _options$command !== void 0 ? _options$command : "";
|
|
1233
|
+
const clearStorageString = `${(_options$clearStorage = options.clearStorage) !== null && _options$clearStorage !== void 0 ? _options$clearStorage : "false"}`;
|
|
1234
|
+
switch (true) {
|
|
1235
|
+
case install2 === InstallOptions.AUTO:
|
|
1236
|
+
break;
|
|
1237
|
+
case install2 === InstallOptions.FALSE:
|
|
1238
|
+
break;
|
|
1239
|
+
default:
|
|
1240
|
+
install2 = InstallOptions.TRUE;
|
|
1241
|
+
break;
|
|
1242
|
+
}
|
|
1243
|
+
validateAppManifestJSON();
|
|
1244
|
+
return {
|
|
1245
|
+
install: install2,
|
|
1246
|
+
command,
|
|
1247
|
+
clearStorage: clearStorageString === "false" ? false : true
|
|
1248
|
+
};
|
|
1249
|
+
};
|
|
1250
|
+
const IDLE_MS = 2e3;
|
|
1251
|
+
const dev = async function() {
|
|
1252
|
+
var _appRcJSON$dev, _defaultAppRcJSON$dev, _appRcJSON$dev$comman, _appRcJSON$dev2, _currentCommand$;
|
|
1253
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1254
|
+
args[_key] = arguments[_key];
|
|
1255
|
+
}
|
|
1256
|
+
const {
|
|
1257
|
+
options
|
|
1258
|
+
} = getCommandOptions(args, devCommandArguments);
|
|
1259
|
+
const normalizedOptions = await normalize$7(options);
|
|
1260
|
+
const appRcJSON = await getAppRcJSON();
|
|
1261
|
+
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
|
+
if (!correctCommand) {
|
|
1263
|
+
return throwError(ErrorCode.INCORRECT_DEV_COMMAND, i18n.t("error.dev.incorrectCommand"));
|
|
1264
|
+
}
|
|
1265
|
+
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 : [];
|
|
1266
|
+
const firstCommand = (_currentCommand$ = currentCommand[0]) !== null && _currentCommand$ !== void 0 ? _currentCommand$ : "";
|
|
1267
|
+
const currentCommandString = currentCommand.join(" ");
|
|
1268
|
+
const defaultDevCommandString = defaultDevCommand.join(" ");
|
|
1269
|
+
let templateCommand = false;
|
|
1270
|
+
if (firstCommand === "npm") {
|
|
1271
|
+
const appPackageJSON = getAppPackageJSON();
|
|
1272
|
+
if (currentCommandString === defaultDevCommandString) {
|
|
1273
|
+
var _appPackageJSON$scrip;
|
|
1274
|
+
if ((_appPackageJSON$scrip = appPackageJSON.scripts) !== null && _appPackageJSON$scrip !== void 0 && _appPackageJSON$scrip.dev) {
|
|
1275
|
+
var _appPackageJSON$scrip2, _appPackageJSON$scrip3, _appPackageJSON$scrip4;
|
|
1276
|
+
const dev2 = (_appPackageJSON$scrip2 = appPackageJSON.scripts.dev) !== null && _appPackageJSON$scrip2 !== void 0 ? _appPackageJSON$scrip2 : "";
|
|
1277
|
+
const devWeb = (_appPackageJSON$scrip3 = appPackageJSON.scripts["dev:web"]) !== null && _appPackageJSON$scrip3 !== void 0 ? _appPackageJSON$scrip3 : "";
|
|
1278
|
+
const devBackend = (_appPackageJSON$scrip4 = appPackageJSON.scripts["dev:backend"]) !== null && _appPackageJSON$scrip4 !== void 0 ? _appPackageJSON$scrip4 : "";
|
|
1279
|
+
const hasConcurrently = _includesInstanceProperty(dev2).call(dev2, DevCommandScripts.Concurrently);
|
|
1280
|
+
const hasNest = _includesInstanceProperty(devBackend).call(devBackend, DevCommandScripts.Nest);
|
|
1281
|
+
const hasVite = _includesInstanceProperty(devWeb).call(devWeb, DevCommandScripts.Vite);
|
|
1282
|
+
templateCommand = hasConcurrently && hasNest && hasVite;
|
|
1283
|
+
} else {
|
|
1284
|
+
return throwError(ErrorCode.DEV_SCRIPT_NOT_FOUND, i18n.t("error.dev.scriptNotFound"));
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
const appManifestJSON = getAppManifestJSON();
|
|
1289
|
+
const {
|
|
1290
|
+
app
|
|
1291
|
+
} = appManifestJSON;
|
|
1292
|
+
const appID = app.id;
|
|
1293
|
+
const config2 = getConfig();
|
|
1294
|
+
const ONES_HOSTED_PORT = await getPort({
|
|
1295
|
+
port: config2.defaultPort.hosted
|
|
1296
|
+
});
|
|
1297
|
+
const ONES_DEV_WEB_SERVER_PORT = await getPort({
|
|
1298
|
+
port: config2.defaultPort.devWebServer
|
|
1299
|
+
});
|
|
1300
|
+
const env2 = {
|
|
1301
|
+
...process.env,
|
|
1302
|
+
NODE_ENV: "development",
|
|
1303
|
+
ONES_HOSTED_PORT: `${ONES_HOSTED_PORT}`,
|
|
1304
|
+
ONES_DEV_WEB_SERVER_PORT: `${ONES_DEV_WEB_SERVER_PORT}`,
|
|
1305
|
+
ONES_HOSTED_TOKEN: "",
|
|
1306
|
+
ONES_HOSTED_APP_ID: "",
|
|
1307
|
+
ONES_HOSTED_BASE_URL: ""
|
|
1308
|
+
};
|
|
1309
|
+
const cancelWaiting = startWaiting();
|
|
1310
|
+
let enableTunnel = true;
|
|
1311
|
+
if (normalizedOptions.install === InstallOptions.TRUE)
|
|
1312
|
+
;
|
|
1313
|
+
else {
|
|
1314
|
+
enableTunnel = await checkTokenInfo();
|
|
1315
|
+
}
|
|
1316
|
+
if (enableTunnel) {
|
|
1317
|
+
var _normalizedOptions$cl;
|
|
1318
|
+
await invokeTunnel(ONES_HOSTED_PORT, {
|
|
1319
|
+
enableInternalManifestRoute: true,
|
|
1320
|
+
rebuildWhenExists: true,
|
|
1321
|
+
clearStorageForDev: (_normalizedOptions$cl = normalizedOptions.clearStorage) !== null && _normalizedOptions$cl !== void 0 ? _normalizedOptions$cl : false
|
|
1322
|
+
});
|
|
1323
|
+
const regionURL = await getRegionURL();
|
|
1324
|
+
const ONES_HOSTED_TOKEN = await getHostToken();
|
|
1325
|
+
const ONES_HOSTED_APP_ID = appID;
|
|
1326
|
+
const ONES_HOSTED_BASE_URL = `${regionURL}/platform/runtime_manager`;
|
|
1327
|
+
env2.ONES_HOSTED_TOKEN = ONES_HOSTED_TOKEN;
|
|
1328
|
+
env2.ONES_HOSTED_APP_ID = ONES_HOSTED_APP_ID;
|
|
1329
|
+
env2.ONES_HOSTED_BASE_URL = ONES_HOSTED_BASE_URL;
|
|
1330
|
+
} else {
|
|
1331
|
+
console.log("Not logged in or token invalid, skipping tunnel connection...");
|
|
1332
|
+
}
|
|
1333
|
+
cancelWaiting();
|
|
1334
|
+
const onReady = async () => {
|
|
1335
|
+
const appName = app.name;
|
|
1336
|
+
let manifestUrl = "";
|
|
1337
|
+
console.log("");
|
|
1338
|
+
console.log(`Local: http://localhost:${ONES_HOSTED_PORT}`);
|
|
1339
|
+
if (enableTunnel) {
|
|
1340
|
+
const tunnelUrl = await buildTunnelUrl();
|
|
1341
|
+
console.log(`URL: ${tunnelUrl}`);
|
|
1342
|
+
manifestUrl = `${tunnelUrl}${ONES_CLI_INTERNAL_MANIFEST_PATH}`;
|
|
1343
|
+
}
|
|
1344
|
+
console.log(`App "${appName}" server is ready!`);
|
|
1345
|
+
console.log("");
|
|
1346
|
+
if (enableTunnel) {
|
|
1347
|
+
switch (normalizedOptions.install) {
|
|
1348
|
+
case InstallOptions.TRUE:
|
|
1349
|
+
await invokeInstall(manifestUrl);
|
|
1350
|
+
break;
|
|
1351
|
+
case InstallOptions.AUTO:
|
|
1352
|
+
{
|
|
1353
|
+
var _appList$data$0$insta, _appList$data;
|
|
1354
|
+
const appList = await fetchAppList(appID);
|
|
1355
|
+
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 : "";
|
|
1356
|
+
if (installationID) {
|
|
1357
|
+
await displayAppDetail(installationID);
|
|
1358
|
+
} else {
|
|
1359
|
+
await invokeInstall(manifestUrl);
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
break;
|
|
1363
|
+
case InstallOptions.FALSE:
|
|
1364
|
+
break;
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
};
|
|
1368
|
+
const cwd2 = getAppWorkspacePath();
|
|
1369
|
+
const child = spawn(firstCommand, currentCommand.slice(1), {
|
|
1370
|
+
cwd: cwd2,
|
|
1371
|
+
stdio: ["inherit", "pipe", "pipe"],
|
|
1372
|
+
env: env2,
|
|
1373
|
+
shell: true
|
|
1374
|
+
});
|
|
1375
|
+
const createReadyStatusPipes = (onReady2) => {
|
|
1376
|
+
let readyTimer = null;
|
|
1377
|
+
let summaryPrinted = false;
|
|
1378
|
+
const scheduleReady = () => {
|
|
1379
|
+
if (summaryPrinted)
|
|
1380
|
+
return;
|
|
1381
|
+
if (readyTimer)
|
|
1382
|
+
clearTimeout(readyTimer);
|
|
1383
|
+
readyTimer = setTimeout(() => {
|
|
1384
|
+
readyTimer = null;
|
|
1385
|
+
if (!summaryPrinted) {
|
|
1386
|
+
summaryPrinted = true;
|
|
1387
|
+
onReady2();
|
|
1388
|
+
}
|
|
1389
|
+
}, IDLE_MS);
|
|
1390
|
+
};
|
|
1391
|
+
const pipe2 = (stream, isStderr) => {
|
|
1392
|
+
const write = (chunk) => {
|
|
1393
|
+
if (isStderr)
|
|
1394
|
+
process.stderr.write(chunk);
|
|
1395
|
+
else
|
|
1396
|
+
process.stdout.write(chunk);
|
|
1397
|
+
};
|
|
1398
|
+
if (templateCommand) {
|
|
1399
|
+
stream.on("data", (chunk) => {
|
|
1400
|
+
const str = typeof chunk === "string" ? chunk : chunk.toString();
|
|
1401
|
+
write(str);
|
|
1402
|
+
if (str.startsWith("[backend]") || str.startsWith("[web]")) {
|
|
1403
|
+
scheduleReady();
|
|
1404
|
+
}
|
|
1405
|
+
});
|
|
1406
|
+
} else {
|
|
1407
|
+
scheduleReady();
|
|
1408
|
+
stream.on("data", (chunk) => {
|
|
1409
|
+
const str = typeof chunk === "string" ? chunk : chunk.toString();
|
|
1410
|
+
write(str);
|
|
1411
|
+
scheduleReady();
|
|
1412
|
+
});
|
|
1413
|
+
}
|
|
1414
|
+
};
|
|
1415
|
+
return pipe2;
|
|
1416
|
+
};
|
|
1417
|
+
const pipe = createReadyStatusPipes(onReady);
|
|
1418
|
+
if (child.stdout)
|
|
1419
|
+
pipe(child.stdout, false);
|
|
1420
|
+
if (child.stderr)
|
|
1421
|
+
pipe(child.stderr, true);
|
|
1422
|
+
let signalHandled = false;
|
|
1423
|
+
const onSignal = (signal) => {
|
|
1424
|
+
if (signalHandled)
|
|
1425
|
+
return;
|
|
1426
|
+
signalHandled = true;
|
|
1427
|
+
child.kill(signal);
|
|
1428
|
+
};
|
|
1429
|
+
process.on("SIGINT", onSignal);
|
|
1430
|
+
process.on("SIGTERM", onSignal);
|
|
1431
|
+
await new Promise((resolve2) => {
|
|
1432
|
+
child.on("exit", () => {
|
|
1433
|
+
process.off("SIGINT", onSignal);
|
|
1434
|
+
process.off("SIGTERM", onSignal);
|
|
1435
|
+
resolve2();
|
|
1436
|
+
});
|
|
1437
|
+
});
|
|
1438
|
+
process.exit(0);
|
|
1439
|
+
};
|
|
1440
|
+
function createPromise() {
|
|
1441
|
+
let resolve2;
|
|
1442
|
+
let reject;
|
|
1443
|
+
const promise = new Promise((res, rej) => {
|
|
1444
|
+
resolve2 = res;
|
|
1445
|
+
reject = rej;
|
|
1446
|
+
});
|
|
1447
|
+
return {
|
|
1448
|
+
promise,
|
|
1449
|
+
resolve: resolve2,
|
|
1450
|
+
reject
|
|
1451
|
+
};
|
|
1452
|
+
}
|
|
1453
|
+
const sleep = (number) => {
|
|
1454
|
+
return new Promise((resolve2) => {
|
|
1455
|
+
setTimeout(resolve2, number);
|
|
1456
|
+
});
|
|
1457
|
+
};
|
|
1458
|
+
const isURL = /^https?:\/\//;
|
|
1459
|
+
const HostBlackList = ["ones.cn", "www.ones.cn", "ones.com", "www.ones.com"];
|
|
1460
|
+
const normalize$6 = async (options) => {
|
|
1461
|
+
const baseURLInput = options.baseURL;
|
|
1462
|
+
if (baseURLInput)
|
|
1463
|
+
;
|
|
1464
|
+
else {
|
|
1465
|
+
return throwError(ErrorCode.MISSING_BASE_URL, i18n.t("error.login.missingBaseURL"));
|
|
1466
|
+
}
|
|
1467
|
+
if (isURL.test(baseURLInput))
|
|
1468
|
+
;
|
|
1469
|
+
else {
|
|
1470
|
+
return throwError(ErrorCode.INCORRECT_BASE_URL, i18n.t("error.login.incorrectBaseURL"));
|
|
1471
|
+
}
|
|
1472
|
+
let baseURL = "";
|
|
1473
|
+
try {
|
|
1474
|
+
const url = new URL(baseURLInput);
|
|
1475
|
+
const host = url.hostname;
|
|
1476
|
+
if (_includesInstanceProperty(HostBlackList).call(HostBlackList, host)) {
|
|
1477
|
+
return throwError(ErrorCode.INCORRECT_BASE_URL, i18n.t("error.login.incorrectBaseURL"));
|
|
1478
|
+
}
|
|
1479
|
+
url.pathname = "";
|
|
1480
|
+
url.search = "";
|
|
1481
|
+
url.hash = "";
|
|
1482
|
+
baseURL = url.toString();
|
|
1483
|
+
} catch (error) {
|
|
1484
|
+
return throwError(ErrorCode.INCORRECT_BASE_URL, i18n.t("error.login.incorrectBaseURL"));
|
|
1485
|
+
}
|
|
1486
|
+
return {
|
|
1487
|
+
baseURL
|
|
1488
|
+
};
|
|
1489
|
+
};
|
|
1490
|
+
const pkceChallenge = PKCEChallenge;
|
|
1491
|
+
const login = async function() {
|
|
1492
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1493
|
+
args[_key] = arguments[_key];
|
|
1494
|
+
}
|
|
1495
|
+
const {
|
|
1496
|
+
options
|
|
1497
|
+
} = getCommandOptions(args, loginCommandArguments);
|
|
1498
|
+
const normalizedOptions = await normalize$6(options);
|
|
1499
|
+
const {
|
|
1500
|
+
code_verifier,
|
|
1501
|
+
code_challenge
|
|
1502
|
+
} = await pkceChallenge.default();
|
|
1503
|
+
const base = normalizedOptions.baseURL;
|
|
1504
|
+
const path = "identity/authorize";
|
|
1505
|
+
const config2 = getConfig();
|
|
1506
|
+
const port = await getPort({
|
|
1507
|
+
port: config2.defaultPort.login
|
|
1508
|
+
});
|
|
1509
|
+
const uuid = v4();
|
|
1510
|
+
const search = new URLSearchParams();
|
|
1511
|
+
const redirect_uri = `http://localhost:${port}/callback`;
|
|
1512
|
+
search.set("response_type", "code");
|
|
1513
|
+
search.set("client_id", OAUTH_TOKEN_CLIENT_ID);
|
|
1514
|
+
search.set("redirect_uri", redirect_uri);
|
|
1515
|
+
search.set("scope", "openid offline_access");
|
|
1516
|
+
search.set("state", uuid);
|
|
1517
|
+
search.set("code_challenge", code_challenge);
|
|
1518
|
+
search.set("code_challenge_method", "S256");
|
|
1519
|
+
const url = `${base}${path}?${search}`;
|
|
1520
|
+
const waitingText = "Waiting for authorization...";
|
|
1521
|
+
const {
|
|
1522
|
+
promise,
|
|
1523
|
+
resolve: resolve2
|
|
1524
|
+
} = createPromise();
|
|
1525
|
+
const server = http.createServer((req, res) => {
|
|
1526
|
+
var _req$url$split$, _req$url, _req$url$split$2, _req$url2;
|
|
1527
|
+
const path2 = (_req$url$split$ = (_req$url = req.url) === null || _req$url === void 0 ? void 0 : _req$url.split("?")[0]) !== null && _req$url$split$ !== void 0 ? _req$url$split$ : "";
|
|
1528
|
+
const query = (_req$url$split$2 = (_req$url2 = req.url) === null || _req$url2 === void 0 ? void 0 : _req$url2.split("?")[1]) !== null && _req$url$split$2 !== void 0 ? _req$url$split$2 : "";
|
|
1529
|
+
const search2 = new URLSearchParams(query);
|
|
1530
|
+
if (path2 === "/callback") {
|
|
1531
|
+
var _search2$get, _search2$get2;
|
|
1532
|
+
const code = (_search2$get = search2.get("code")) !== null && _search2$get !== void 0 ? _search2$get : "";
|
|
1533
|
+
const state = (_search2$get2 = search2.get("state")) !== null && _search2$get2 !== void 0 ? _search2$get2 : "";
|
|
1534
|
+
if (state === uuid) {
|
|
1535
|
+
const uri = new URL(base);
|
|
1536
|
+
uri.pathname = API.OAUTH_TOKEN;
|
|
1537
|
+
let errorMessage = "";
|
|
1538
|
+
axios({
|
|
1539
|
+
url: `${uri}`,
|
|
1540
|
+
method: "POST",
|
|
1541
|
+
data: {
|
|
1542
|
+
code,
|
|
1543
|
+
code_verifier,
|
|
1544
|
+
redirect_uri,
|
|
1545
|
+
client_id: OAUTH_TOKEN_CLIENT_ID,
|
|
1546
|
+
grant_type: "authorization_code"
|
|
1547
|
+
},
|
|
1548
|
+
headers: {
|
|
1549
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
1550
|
+
},
|
|
1551
|
+
timeout: REQUEST_TIMEOUT
|
|
1552
|
+
}).then((response) => {
|
|
1553
|
+
return response.data;
|
|
1554
|
+
}).catch((error) => {
|
|
1555
|
+
errorMessage = `${error}`;
|
|
1556
|
+
return {};
|
|
1557
|
+
}).then((data) => {
|
|
1558
|
+
var _data$token_type, _data$expires_in, _data$access_token, _data$refresh_token;
|
|
1559
|
+
const tokenType = (_data$token_type = data.token_type) !== null && _data$token_type !== void 0 ? _data$token_type : "";
|
|
1560
|
+
const expiresIn = (_data$expires_in = data.expires_in) !== null && _data$expires_in !== void 0 ? _data$expires_in : 0;
|
|
1561
|
+
const expiresAt = Date.now() + expiresIn * 1e3;
|
|
1562
|
+
const accessToken = (_data$access_token = data.access_token) !== null && _data$access_token !== void 0 ? _data$access_token : "";
|
|
1563
|
+
const refreshToken = (_data$refresh_token = data.refresh_token) !== null && _data$refresh_token !== void 0 ? _data$refresh_token : "";
|
|
1564
|
+
const isValid = [tokenType, expiresIn, accessToken].every(Boolean);
|
|
1565
|
+
if (isValid) {
|
|
1566
|
+
const token = {
|
|
1567
|
+
token_type: tokenType,
|
|
1568
|
+
expires_in: expiresIn,
|
|
1569
|
+
expires_at: expiresAt,
|
|
1570
|
+
access_token: accessToken,
|
|
1571
|
+
refresh_token: refreshToken
|
|
1572
|
+
};
|
|
1573
|
+
resolve2({
|
|
1574
|
+
base_url: base,
|
|
1575
|
+
ones_token: token,
|
|
1576
|
+
region_url: base
|
|
1577
|
+
});
|
|
1578
|
+
const successURL = `${base}identity/consent/success`;
|
|
1579
|
+
res.writeHead(302, {
|
|
1580
|
+
Location: successURL
|
|
1581
|
+
});
|
|
1582
|
+
res.end();
|
|
1583
|
+
return;
|
|
1584
|
+
}
|
|
1585
|
+
const errorURL = `${base}identity/consent/success?error=${errorMessage}`;
|
|
1586
|
+
res.writeHead(302, {
|
|
1587
|
+
Location: errorURL
|
|
1588
|
+
});
|
|
1589
|
+
res.end();
|
|
1590
|
+
});
|
|
1591
|
+
return;
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
res.writeHead(200, {
|
|
1595
|
+
"Content-Type": "text/html"
|
|
1596
|
+
});
|
|
1597
|
+
res.end(waitingText);
|
|
1598
|
+
});
|
|
1599
|
+
server.listen(port);
|
|
1600
|
+
promise.then(async (store) => {
|
|
1601
|
+
await sleep(100);
|
|
1602
|
+
try {
|
|
1603
|
+
server.closeAllConnections();
|
|
1604
|
+
} catch (error) {
|
|
1605
|
+
}
|
|
1606
|
+
try {
|
|
1607
|
+
server.close();
|
|
1608
|
+
} catch (error) {
|
|
1609
|
+
}
|
|
1610
|
+
if (store) {
|
|
1611
|
+
var _store$base_url, _store$ones_token, _store$region_url;
|
|
1612
|
+
await mergeStore({
|
|
1613
|
+
base_url: (_store$base_url = store.base_url) !== null && _store$base_url !== void 0 ? _store$base_url : "",
|
|
1614
|
+
ones_token: (_store$ones_token = store.ones_token) !== null && _store$ones_token !== void 0 ? _store$ones_token : {},
|
|
1615
|
+
region_url: (_store$region_url = store.region_url) !== null && _store$region_url !== void 0 ? _store$region_url : ""
|
|
1616
|
+
});
|
|
1617
|
+
console.log("Logged in successfully!");
|
|
1618
|
+
} else {
|
|
1619
|
+
console.log("Login canceled!");
|
|
1620
|
+
}
|
|
1621
|
+
}).finally(() => {
|
|
1622
|
+
process$1.exit(0);
|
|
1623
|
+
});
|
|
1624
|
+
console.log("Logging into your ONES account...");
|
|
1625
|
+
console.log(`Opening ${url}`);
|
|
1626
|
+
const spinner = ora({
|
|
1627
|
+
text: waitingText,
|
|
1628
|
+
discardStdin: false
|
|
1629
|
+
});
|
|
1630
|
+
spinner.start();
|
|
1631
|
+
let exited = false;
|
|
1632
|
+
const handleExit = () => {
|
|
1633
|
+
spinner.stop();
|
|
1634
|
+
if (exited)
|
|
1635
|
+
return;
|
|
1636
|
+
exited = true;
|
|
1637
|
+
console.log("Exiting...");
|
|
1638
|
+
resolve2(null);
|
|
1639
|
+
sleep(3e3).then(() => {
|
|
1640
|
+
process$1.exit(0);
|
|
1641
|
+
});
|
|
1642
|
+
};
|
|
1643
|
+
process$1.on("SIGINT", handleExit);
|
|
1644
|
+
process$1.on("SIGTERM", handleExit);
|
|
1645
|
+
try {
|
|
1646
|
+
await open(url);
|
|
1647
|
+
} catch (error) {
|
|
1648
|
+
return throwError(ErrorCode.INCORRECT_BASE_URL, i18n.t("error.login.incorrectBaseURL"));
|
|
1649
|
+
}
|
|
1650
|
+
};
|
|
1651
|
+
const normalize$5 = async (options) => {
|
|
1652
|
+
noop(options);
|
|
1653
|
+
return {};
|
|
1654
|
+
};
|
|
1655
|
+
const logout = async function() {
|
|
1656
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1657
|
+
args[_key] = arguments[_key];
|
|
1658
|
+
}
|
|
1659
|
+
const {
|
|
1660
|
+
options
|
|
1661
|
+
} = getCommandOptions(args, logoutCommandArguments);
|
|
1662
|
+
const normalizedOptions = await normalize$5(options);
|
|
1663
|
+
noop(normalizedOptions);
|
|
1664
|
+
await setStore({});
|
|
1665
|
+
console.log("Logged out successfully!");
|
|
1666
|
+
};
|
|
1667
|
+
const normalize$4 = async (options) => {
|
|
1668
|
+
noop(options);
|
|
1669
|
+
return {};
|
|
1670
|
+
};
|
|
1671
|
+
const whoami = async function() {
|
|
1672
|
+
var _tokenInfo$user, _tokenInfo$user2;
|
|
1673
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1674
|
+
args[_key] = arguments[_key];
|
|
1675
|
+
}
|
|
1676
|
+
const {
|
|
1677
|
+
options
|
|
1678
|
+
} = getCommandOptions(args, whoamiCommandArguments);
|
|
1679
|
+
const normalizedOptions = await normalize$4(options);
|
|
1680
|
+
noop(normalizedOptions);
|
|
1681
|
+
const baseURL = await getBaseURL();
|
|
1682
|
+
const cancelWaiting = startWaiting();
|
|
1683
|
+
const tokenInfo = await fetchTokenInfo();
|
|
1684
|
+
cancelWaiting();
|
|
1685
|
+
const name2 = (_tokenInfo$user = tokenInfo.user) === null || _tokenInfo$user === void 0 ? void 0 : _tokenInfo$user.name;
|
|
1686
|
+
const email = (_tokenInfo$user2 = tokenInfo.user) === null || _tokenInfo$user2 === void 0 ? void 0 : _tokenInfo$user2.email;
|
|
1687
|
+
if (name2 && email) {
|
|
1688
|
+
console.log(`User: ${name2}`);
|
|
1689
|
+
console.log(`Email: ${email}`);
|
|
1690
|
+
console.log(`ONES: ${baseURL}`);
|
|
1691
|
+
} else {
|
|
1692
|
+
consoleUnauthorizedMessage();
|
|
1693
|
+
}
|
|
1694
|
+
};
|
|
1695
|
+
const normalize$3 = async (options) => {
|
|
1696
|
+
noop(options);
|
|
1697
|
+
return {};
|
|
1698
|
+
};
|
|
1699
|
+
const enable = async function() {
|
|
1700
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1701
|
+
args[_key] = arguments[_key];
|
|
1702
|
+
}
|
|
1703
|
+
const {
|
|
1704
|
+
options
|
|
1705
|
+
} = getCommandOptions(args, enableCommandArguments);
|
|
1706
|
+
const normalizedOptions = await normalize$3(options);
|
|
1707
|
+
noop(normalizedOptions);
|
|
1708
|
+
const appName = getAppManifestJSON().app.name;
|
|
1709
|
+
const cancelWaiting = startWaiting();
|
|
1710
|
+
const result = await fetchAppEnable();
|
|
1711
|
+
cancelWaiting();
|
|
1712
|
+
if (result.code === "OK") {
|
|
1713
|
+
console.log(`App "${appName}" enabled successfully!`);
|
|
1714
|
+
} else {
|
|
1715
|
+
console.log(`App "${appName}" enabled failed!`);
|
|
1716
|
+
console.error(JSON.stringify(result, null, 2));
|
|
1717
|
+
}
|
|
1718
|
+
};
|
|
1719
|
+
const normalize$2 = async (options) => {
|
|
1720
|
+
noop(options);
|
|
1721
|
+
return {};
|
|
1722
|
+
};
|
|
1723
|
+
const disable = async function() {
|
|
1724
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1725
|
+
args[_key] = arguments[_key];
|
|
1726
|
+
}
|
|
1727
|
+
const {
|
|
1728
|
+
options
|
|
1729
|
+
} = getCommandOptions(args, disableCommandArguments);
|
|
1730
|
+
const normalizedOptions = await normalize$2(options);
|
|
1731
|
+
noop(normalizedOptions);
|
|
1732
|
+
const appName = getAppManifestJSON().app.name;
|
|
1733
|
+
const cancelWaiting = startWaiting();
|
|
1734
|
+
const result = await fetchAppDisable();
|
|
1735
|
+
cancelWaiting();
|
|
1736
|
+
if (result.code === "OK") {
|
|
1737
|
+
console.log(`App "${appName}" disabled successfully!`);
|
|
1738
|
+
} else {
|
|
1739
|
+
console.log(`App "${appName}" disabled failed!`);
|
|
1740
|
+
console.error(JSON.stringify(result, null, 2));
|
|
1741
|
+
}
|
|
1742
|
+
};
|
|
1743
|
+
const normalize$1 = async (options) => {
|
|
1744
|
+
noop(options);
|
|
1745
|
+
return {};
|
|
1746
|
+
};
|
|
1747
|
+
const uninstall = async function() {
|
|
1748
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1749
|
+
args[_key] = arguments[_key];
|
|
1750
|
+
}
|
|
1751
|
+
const {
|
|
1752
|
+
options
|
|
1753
|
+
} = getCommandOptions(args, uninstallCommandArguments);
|
|
1754
|
+
const normalizedOptions = await normalize$1(options);
|
|
1755
|
+
noop(normalizedOptions);
|
|
1756
|
+
const appName = getAppManifestJSON().app.name;
|
|
1757
|
+
const cancelWaiting = startWaiting();
|
|
1758
|
+
const result = await fetchAppUninstall();
|
|
1759
|
+
cancelWaiting();
|
|
1760
|
+
if (result.code === "OK") {
|
|
1761
|
+
console.log(`App "${appName}" uninstalled successfully!`);
|
|
1762
|
+
} else {
|
|
1763
|
+
console.log(`App "${appName}" uninstalled failed!`);
|
|
1764
|
+
console.error(JSON.stringify(result, null, 2));
|
|
1765
|
+
}
|
|
1766
|
+
};
|
|
1767
|
+
const getTemplatePath = () => {
|
|
1768
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
1769
|
+
return join(__dirname, "../template");
|
|
1770
|
+
};
|
|
1771
|
+
const getTemplateLegacy = () => {
|
|
1772
|
+
return "legacy";
|
|
1773
|
+
};
|
|
1774
|
+
const normalize = async (options) => {
|
|
1775
|
+
const projectPathInput = options.projectPath;
|
|
1776
|
+
if (projectPathInput)
|
|
1777
|
+
;
|
|
1778
|
+
else {
|
|
1779
|
+
return throwError(ErrorCode.MISSING_PROJECT_PATH, i18n.t("error.legacy.create.missingProjectPath"));
|
|
1780
|
+
}
|
|
1781
|
+
const projectPath = resolve(cwd(), projectPathInput);
|
|
1782
|
+
return {
|
|
1783
|
+
projectPath
|
|
1784
|
+
};
|
|
1785
|
+
};
|
|
1786
|
+
const {
|
|
1787
|
+
copy,
|
|
1788
|
+
moveSync
|
|
1789
|
+
} = fse;
|
|
1790
|
+
const legacy = async function() {
|
|
1791
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1792
|
+
args[_key] = arguments[_key];
|
|
1793
|
+
}
|
|
1794
|
+
const {
|
|
1795
|
+
options
|
|
1796
|
+
} = getCommandOptions(args, legacyCommandArguments);
|
|
1797
|
+
const normalizedOptions = await normalize(options);
|
|
1798
|
+
const {
|
|
1799
|
+
projectPath
|
|
1800
|
+
} = normalizedOptions;
|
|
1801
|
+
const templatePath = join(getTemplatePath(), getTemplateLegacy());
|
|
1802
|
+
await copy(templatePath, projectPath);
|
|
1803
|
+
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"]];
|
|
1804
|
+
rename.forEach((_ref) => {
|
|
1805
|
+
let [from, to] = _ref;
|
|
1806
|
+
moveSync(join(projectPath, from), join(projectPath, to), {
|
|
1807
|
+
overwrite: true
|
|
1808
|
+
});
|
|
1809
|
+
});
|
|
1810
|
+
console.log("Plugin created successfully!");
|
|
1811
|
+
};
|
|
1812
|
+
const buildCommandArguments = [];
|
|
1813
|
+
const $build = new Command("build").description(i18n.t("desc.build")).option("-o, --output [file-path]", i18n.t("desc.build.output")).option("-c, --command [string]", i18n.t("desc.build.command")).action(build);
|
|
1814
|
+
addCommandUsage($build);
|
|
1815
|
+
addCommandOutput($build);
|
|
1816
|
+
const devCommandArguments = [];
|
|
1817
|
+
const $dev = new 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, --clear-storage [boolean]", i18n.t("desc.dev.clearStorage")).action(dev);
|
|
1818
|
+
addCommandUsage($dev);
|
|
1819
|
+
addCommandOutput($dev);
|
|
1820
|
+
const tunnelCommandArguments = ["port"];
|
|
1821
|
+
const $tunnel = new Command("tunnel").description(i18n.t("desc.tunnel")).argument("<port>", i18n.t("desc.tunnel.port")).option("-s, --clear-storage [boolean]", i18n.t("desc.dev.clearStorage")).action(tunnel);
|
|
1822
|
+
addCommandUsage($tunnel);
|
|
1823
|
+
addCommandOutput($tunnel);
|
|
1824
|
+
const loginCommandArguments = ["baseURL"];
|
|
1825
|
+
const $login = new Command("login").description(i18n.t("desc.login")).argument("<base-url>", i18n.t("desc.login.baseUrl")).action(login);
|
|
1826
|
+
addCommandUsage($login);
|
|
1827
|
+
addCommandOutput($login);
|
|
1828
|
+
const logoutCommandArguments = [];
|
|
1829
|
+
const $logout = new Command("logout").description(i18n.t("desc.logout")).action(logout);
|
|
1830
|
+
addCommandUsage($logout);
|
|
1831
|
+
addCommandOutput($logout);
|
|
1832
|
+
const whoamiCommandArguments = [];
|
|
1833
|
+
const $whoami = new Command("whoami").description(i18n.t("desc.whoami")).action(whoami);
|
|
1834
|
+
addCommandUsage($whoami);
|
|
1835
|
+
addCommandOutput($whoami);
|
|
1836
|
+
const installCommandArguments = [];
|
|
1837
|
+
const $install = new Command("install").description(i18n.t("desc.install")).action(install);
|
|
1838
|
+
addCommandUsage($install);
|
|
1839
|
+
addCommandOutput($install);
|
|
1840
|
+
const enableCommandArguments = [];
|
|
1841
|
+
const $enable = new Command("enable").description(i18n.t("desc.enable")).action(enable);
|
|
1842
|
+
addCommandUsage($enable);
|
|
1843
|
+
addCommandOutput($enable);
|
|
1844
|
+
const disableCommandArguments = [];
|
|
1845
|
+
const $disable = new Command("disable").description(i18n.t("desc.disable")).action(disable);
|
|
1846
|
+
addCommandUsage($disable);
|
|
1847
|
+
addCommandOutput($disable);
|
|
1848
|
+
const uninstallCommandArguments = [];
|
|
1849
|
+
const $uninstall = new Command("uninstall").description(i18n.t("desc.uninstall")).action(uninstall);
|
|
1850
|
+
addCommandUsage($uninstall);
|
|
1851
|
+
addCommandOutput($uninstall);
|
|
1852
|
+
const $app = new Command("app").description(i18n.t("desc.app"));
|
|
1853
|
+
$app.addCommand($install).addCommand($enable).addCommand($disable).addCommand($uninstall);
|
|
1854
|
+
addCommandUsage($app);
|
|
1855
|
+
addCommandOutput($app);
|
|
1856
|
+
const legacyCommandArguments = ["projectPath"];
|
|
1857
|
+
const $create = new Command("create").description(i18n.t("desc.legacy.create")).argument("<project-path>", i18n.t("desc.legacy.create.projectPath")).action(legacy);
|
|
1858
|
+
addCommandUsage($create);
|
|
1859
|
+
addCommandOutput($create);
|
|
1860
|
+
const $legacy = new Command("legacy").description(i18n.t("desc.legacy"));
|
|
1861
|
+
$legacy.addCommand($create);
|
|
1862
|
+
addCommandUsage($legacy);
|
|
1863
|
+
addCommandOutput($legacy);
|
|
1864
|
+
const ones = new Command("ones");
|
|
1865
|
+
const version = `${getPackageJSON().version}`;
|
|
1866
|
+
const env = `${version} Node/${process.version}`;
|
|
1867
|
+
ones.description(i18n.t("desc.ones", {
|
|
1868
|
+
env
|
|
1869
|
+
})).addCommand($create$1).addCommand($build).addCommand($dev).addCommand($tunnel).addCommand($app).addCommand($login).addCommand($logout).addCommand($whoami).addCommand($legacy).configureHelp({
|
|
1870
|
+
visibleCommands: (cmd) => {
|
|
1871
|
+
const blackList = ["legacy"];
|
|
1872
|
+
return cmd.commands.filter((command) => !_includesInstanceProperty(blackList).call(blackList, command.name()));
|
|
1873
|
+
},
|
|
1874
|
+
subcommandTerm: (subcommand) => {
|
|
1875
|
+
return `${subcommand.name()} ${subcommand.usage()}`.trim();
|
|
1876
|
+
}
|
|
1877
|
+
});
|
|
1878
|
+
addCommandOutput(ones);
|
|
1879
|
+
const runCommandONES = async () => {
|
|
1880
|
+
const command = ones;
|
|
1881
|
+
setContext("command", command);
|
|
1882
|
+
const version2 = `${getPackageJSON().version}`;
|
|
1883
|
+
command.version(version2, "-v, --version");
|
|
1884
|
+
await command.parse();
|
|
1885
|
+
};
|
|
1886
|
+
export {
|
|
1887
|
+
runCommandONES
|
|
1888
|
+
};
|