@ones-open/cli 1.0.1-23321.1934 → 1.0.1-25822.1980

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.
Files changed (86) hide show
  1. package/dist/index.cjs +574 -258
  2. package/dist/index.js +576 -260
  3. package/dist/types/actions/build/index.d.ts.map +1 -1
  4. package/dist/types/actions/dev/index.d.ts.map +1 -1
  5. package/dist/types/actions/dev/normalize.d.ts.map +1 -1
  6. package/dist/types/actions/dev/types.d.ts +10 -0
  7. package/dist/types/actions/dev/types.d.ts.map +1 -0
  8. package/dist/types/actions/disable/index.d.ts.map +1 -1
  9. package/dist/types/actions/enable/index.d.ts.map +1 -1
  10. package/dist/types/actions/install/index.d.ts +1 -1
  11. package/dist/types/actions/install/index.d.ts.map +1 -1
  12. package/dist/types/actions/install/install.d.ts +2 -2
  13. package/dist/types/actions/install/install.d.ts.map +1 -1
  14. package/dist/types/actions/legacy/index.d.ts.map +1 -1
  15. package/dist/types/actions/legacy/normalize.d.ts.map +1 -1
  16. package/dist/types/actions/login/index.d.ts.map +1 -1
  17. package/dist/types/actions/tunnel/consts.d.ts +3 -0
  18. package/dist/types/actions/tunnel/consts.d.ts.map +1 -1
  19. package/dist/types/actions/tunnel/index.d.ts +3 -1
  20. package/dist/types/actions/tunnel/index.d.ts.map +1 -1
  21. package/dist/types/actions/tunnel/normalize.d.ts.map +1 -1
  22. package/dist/types/actions/tunnel/tunnel-client.d.ts.map +1 -1
  23. package/dist/types/actions/tunnel/tunnel.d.ts +1 -7
  24. package/dist/types/actions/tunnel/tunnel.d.ts.map +1 -1
  25. package/dist/types/actions/tunnel/types.d.ts +34 -0
  26. package/dist/types/actions/tunnel/types.d.ts.map +1 -0
  27. package/dist/types/actions/tunnel/utils.d.ts +7 -0
  28. package/dist/types/actions/tunnel/utils.d.ts.map +1 -0
  29. package/dist/types/actions/uninstall/index.d.ts.map +1 -1
  30. package/dist/types/actions/whoami/index.d.ts.map +1 -1
  31. package/dist/types/cli/index.d.ts.map +1 -1
  32. package/dist/types/command/dev/index.d.ts +2 -0
  33. package/dist/types/command/dev/index.d.ts.map +1 -1
  34. package/dist/types/command/legacy/index.d.ts +1 -1
  35. package/dist/types/command/legacy/index.d.ts.map +1 -1
  36. package/dist/types/command/tunnel/index.d.ts +1 -0
  37. package/dist/types/command/tunnel/index.d.ts.map +1 -1
  38. package/dist/types/common/config/types.d.ts +2 -1
  39. package/dist/types/common/config/types.d.ts.map +1 -1
  40. package/dist/types/common/config/utils.d.ts.map +1 -1
  41. package/dist/types/common/error/enums.d.ts +2 -1
  42. package/dist/types/common/error/enums.d.ts.map +1 -1
  43. package/dist/types/common/locales/en/index.d.ts +34 -28
  44. package/dist/types/common/locales/en/index.d.ts.map +1 -1
  45. package/dist/types/common/package/utils.d.ts +2 -0
  46. package/dist/types/common/package/utils.d.ts.map +1 -1
  47. package/dist/types/common/request/consts.d.ts +2 -0
  48. package/dist/types/common/request/consts.d.ts.map +1 -1
  49. package/dist/types/common/request/fetch.d.ts +4 -1
  50. package/dist/types/common/request/fetch.d.ts.map +1 -1
  51. package/dist/types/common/request/types.d.ts +18 -0
  52. package/dist/types/common/request/types.d.ts.map +1 -1
  53. package/dist/types/common/request/utils.d.ts +5 -2
  54. package/dist/types/common/request/utils.d.ts.map +1 -1
  55. package/dist/types/common/template/index.d.ts +5 -0
  56. package/dist/types/common/template/index.d.ts.map +1 -0
  57. package/dist/types/common/template/utils.d.ts +3 -0
  58. package/dist/types/common/template/utils.d.ts.map +1 -0
  59. package/package.json +6 -3
  60. package/template/legacy/README.md +13 -0
  61. package/template/legacy/_backend_npmrc +5 -0
  62. package/template/legacy/_backend_tsconfig.json +23 -0
  63. package/template/legacy/_eslintignore +2 -0
  64. package/template/legacy/_eslintrc.js +97 -0
  65. package/template/legacy/_gitignore +21 -0
  66. package/template/legacy/_gitlab-ci.yml +3 -0
  67. package/template/legacy/_husky_pre-commit +1 -0
  68. package/template/legacy/_npmrc +5 -0
  69. package/template/legacy/_prettierignore +15 -0
  70. package/template/legacy/_prettierrc +6 -0
  71. package/template/legacy/_web_npmrc +5 -0
  72. package/template/legacy/_web_tsconfig.json +20 -0
  73. package/template/legacy/backend/package.json +10 -0
  74. package/template/legacy/backend/src/index.ts +139 -0
  75. package/template/legacy/backend/src/ones.d.ts +6 -0
  76. package/template/legacy/config/ci-deploy.yaml +11 -0
  77. package/template/legacy/config/local.yaml +30 -0
  78. package/template/legacy/config/plugin.yaml +25 -0
  79. package/template/legacy/config/upgrade.yaml +8 -0
  80. package/template/legacy/op.config.mjs +4 -0
  81. package/template/legacy/package-lock.json +17446 -0
  82. package/template/legacy/package.json +73 -0
  83. package/template/legacy/web/browserslist +4 -0
  84. package/template/legacy/web/package.json +29 -0
  85. package/template/legacy/web/public/logo.svg +5 -0
  86. package/template/legacy/workspace/plugin.sql +2 -0
package/dist/index.cjs CHANGED
@@ -6,52 +6,58 @@ const createOnesApp = require("create-ones-app");
6
6
  const node_path = require("node:path");
7
7
  const node_child_process = require("node:child_process");
8
8
  const node_fs = require("node:fs");
9
+ const fse = require("fs-extra");
9
10
  const archiver = require("archiver");
10
11
  const lodashEs = require("lodash-es");
11
12
  const process$1 = require("node:process");
12
13
  const node_url = require("node:url");
13
14
  const cosmiconfig = require("cosmiconfig");
14
- const fse = require("fs-extra");
15
+ const getPort = require("get-port");
15
16
  const envPaths = require("env-paths");
16
17
  const zod = require("zod");
17
18
  const axios = require("axios");
18
19
  const _reduceInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/reduce");
20
+ const ora = require("ora");
19
21
  const WebSocket = require("ws");
20
22
  const http = require("node:http");
21
- const ora = require("ora");
22
23
  const open = require("open");
23
- const getPort = require("get-port");
24
24
  const uuid = require("uuid");
25
25
  var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
26
26
  const en = {
27
- "desc.ones": "cli for ones",
28
- "desc.build": "build the application",
29
- "desc.build.output": "specify the output file path",
30
- "desc.dev": "develop the application",
31
- "desc.dev.install": "whether to install the application",
32
- "desc.tunnel": "start a tunnel to the application",
33
- "desc.tunnel.port": "specify the port number for serve",
34
- "desc.login": "login to the environment",
35
- "desc.login.baseUrl": "specify the environment url for login",
36
- "desc.logout": "logout from the environment",
37
- "desc.whoami": "show the current user",
38
- "desc.app": "app command",
39
- "desc.install": "install the application",
40
- "desc.enable": "enable the application",
41
- "desc.disable": "disable the application",
42
- "desc.uninstall": "uninstall the application",
43
- "desc.legacy": "legacy command",
44
- "error.login.missingBaseURL": "missing base url",
45
- "error.login.incorrectBaseURL": "incorrect base url",
46
- "error.tunnel.missingPort": "missing port",
47
- "error.tunnel.incorrectPort": "incorrect port",
48
- "error.schema.app.package.parseError": "app package json parse error",
49
- "error.schema.app.manifest.parseError": "app manifest json parse error",
50
- "error.build.scriptNotFound": "build script not found",
51
- "error.dev.scriptNotFound": "dev script not found",
52
- "error.store.permission": 'permission denied, please check the file permission with "{filePath}"',
53
- "error.hostedToken.requestFailed": "failed to request hosted token",
54
- "error.hostedToken.empty": "hosted token is empty"
27
+ "desc.ones": "ONES CLI/{env}",
28
+ "desc.build": "Build your ONES App",
29
+ "desc.build.output": "Specify the output file path",
30
+ "desc.dev": "Start your local development server and connect to ONES",
31
+ "desc.dev.install": "Install your ONES App after the server is ready",
32
+ "desc.dev.command": "Specify the dev command",
33
+ "desc.dev.useStorage": "Use hosted storage ability",
34
+ "desc.tunnel": "Start a tunnel to connect your local server with ONES",
35
+ "desc.tunnel.port": "Specify the port number for tunnel",
36
+ "desc.login": "Log in to your ONES account",
37
+ "desc.login.baseUrl": "Specify the ONES URL for login",
38
+ "desc.logout": "Log out of your ONES account",
39
+ "desc.whoami": "Display the account information of the logged in user",
40
+ "desc.app": "Manage app installations",
41
+ "desc.install": "Install your ONES App",
42
+ "desc.enable": "Enable your ONES App",
43
+ "desc.disable": "Disable your ONES App",
44
+ "desc.uninstall": "Uninstall your ONES App",
45
+ "desc.legacy": "Legacy command",
46
+ "desc.legacy.create": "Create a new ONES plugin",
47
+ "desc.legacy.create.projectPath": "Specify the project path",
48
+ "error.login.missingBaseURL": "Missing base URL",
49
+ "error.login.incorrectBaseURL": "Incorrect base URL",
50
+ "error.tunnel.missingPort": "Missing port",
51
+ "error.tunnel.incorrectPort": "Incorrect port",
52
+ "error.schema.app.package.parseError": "App package JSON parse error",
53
+ "error.schema.app.manifest.parseError": 'App "opkx.json" JSON parse error',
54
+ "error.build.scriptNotFound": 'Npm "build" script not found',
55
+ "error.dev.scriptNotFound": 'Npm "dev" script not found',
56
+ "error.dev.incorrectCommand": "Incorrect dev command",
57
+ "error.store.permission": 'Permission denied, please check the file permission with "{filePath}"',
58
+ "error.hostedToken.requestFailed": "Failed to request hosted token",
59
+ "error.hostedToken.empty": "Hosted token is empty",
60
+ "error.legacy.create.missingProjectPath": "Project path is required"
55
61
  };
56
62
  const map = {
57
63
  en
@@ -96,6 +102,7 @@ var ErrorCode = ((ErrorCode2) => {
96
102
  ErrorCode2["STORE_PERMISSION"] = "E12";
97
103
  ErrorCode2["HOSTED_TOKEN_REQUEST_FAILED"] = "E13";
98
104
  ErrorCode2["HOSTED_TOKEN_EMPTY"] = "E14";
105
+ ErrorCode2["INCORRECT_DEV_COMMAND"] = "E15";
99
106
  return ErrorCode2;
100
107
  })(ErrorCode || {});
101
108
  const getPublicPath = () => {
@@ -132,8 +139,8 @@ const getAppPackageJSON = () => {
132
139
  const json = JSON.parse(string);
133
140
  return createOnesApp.AppPackageJSONSchema.parse(json);
134
141
  } catch (error) {
135
- console.error(error);
136
- return createOnesApp.throwError(ErrorCode.APP_PACKAGE_JSON_PARSE_ERROR, i18n.t("error.schema.app.package.parseError"));
142
+ const details = error instanceof Error ? error.message : String(error);
143
+ return createOnesApp.throwError(ErrorCode.APP_PACKAGE_JSON_PARSE_ERROR, `${i18n.t("error.schema.app.package.parseError")}: ${details}`);
137
144
  }
138
145
  };
139
146
  const getAppManifestJSONPath = () => {
@@ -148,13 +155,14 @@ const getAppManifestJSON = () => {
148
155
  const json = JSON.parse(string);
149
156
  return createOnesApp.AppManifestJSONSchema.parse(json);
150
157
  } catch (error) {
151
- console.error(error);
152
- return createOnesApp.throwError(ErrorCode.APP_MANIFEST_JSON_PARSE_ERROR, i18n.t("error.schema.app.manifest.parseError"));
158
+ const details = error instanceof Error ? error.message : String(error);
159
+ return createOnesApp.throwError(ErrorCode.APP_MANIFEST_JSON_PARSE_ERROR, `${i18n.t("error.schema.app.manifest.parseError")}: ${details}`);
153
160
  }
154
161
  };
162
+ const defaultDevCommand = ["npm", "run", "dev"];
155
163
  const defaultAppRcJSON = {
156
164
  dev: {
157
- command: ["npm run dev"]
165
+ command: defaultDevCommand
158
166
  }
159
167
  };
160
168
  let storeAppRcJSON = null;
@@ -205,8 +213,12 @@ const normalize$a = async (options) => {
205
213
  output
206
214
  };
207
215
  };
216
+ const {
217
+ existsSync,
218
+ ensureDirSync
219
+ } = fse;
208
220
  const build = async function() {
209
- var _appPackageJSON$scrip, _appRcJSON$build$comp, _appRcJSON$build;
221
+ var _appRcJSON$build$comp, _appRcJSON$build;
210
222
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
211
223
  args[_key] = arguments[_key];
212
224
  }
@@ -214,22 +226,37 @@ const build = async function() {
214
226
  options
215
227
  } = createOnesApp.getCommandOptions(args, buildCommandArguments);
216
228
  const normalizedOptions = await normalize$a(options);
217
- const appPackageJSON = getAppPackageJSON();
218
229
  const appManifestJSON = getAppManifestJSON();
219
230
  const appRcJSON = await getAppRcJSON();
220
- appManifestJSON.app.name;
221
- if ((_appPackageJSON$scrip = appPackageJSON.scripts) !== null && _appPackageJSON$scrip !== void 0 && _appPackageJSON$scrip.build) {
222
- node_child_process.spawnSync("npm", ["run", "build"], {
223
- cwd: getAppWorkspacePath(),
224
- stdio: "inherit",
225
- env: {
226
- ...process.env,
227
- NODE_ENV: "production"
231
+ const appPackageJSONPath = getAppPackageJSONPath();
232
+ const isExists = existsSync(appPackageJSONPath);
233
+ if (isExists) {
234
+ var _appPackageJSON$scrip;
235
+ const appPackageJSON = getAppPackageJSON();
236
+ if ((_appPackageJSON$scrip = appPackageJSON.scripts) !== null && _appPackageJSON$scrip !== void 0 && _appPackageJSON$scrip.build) {
237
+ const buildResult = node_child_process.spawnSync("npm", ["run", "build"], {
238
+ cwd: getAppWorkspacePath(),
239
+ stdio: "inherit",
240
+ env: {
241
+ ...process.env,
242
+ NODE_ENV: "production"
243
+ }
244
+ });
245
+ if (buildResult.status !== 0 || buildResult.signal) {
246
+ var _buildResult$status;
247
+ process.exit((_buildResult$status = buildResult.status) !== null && _buildResult$status !== void 0 ? _buildResult$status : 1);
228
248
  }
229
- });
230
- } else {
231
- return createOnesApp.throwError(ErrorCode.BUILD_SCRIPT_NOT_FOUND, i18n.t("error.build.scriptNotFound"));
249
+ } else {
250
+ return createOnesApp.throwError(ErrorCode.BUILD_SCRIPT_NOT_FOUND, i18n.t("error.build.scriptNotFound"));
251
+ }
232
252
  }
253
+ const appName = appManifestJSON.app.name;
254
+ const outputPath = normalizedOptions.output;
255
+ const outputDir = node_path.dirname(outputPath);
256
+ const outputFilename = node_path.basename(outputPath);
257
+ ensureDirSync(outputDir);
258
+ const outputStream = node_fs.createWriteStream(outputPath);
259
+ const files = (_appRcJSON$build$comp = (_appRcJSON$build = appRcJSON.build) === null || _appRcJSON$build === void 0 || (_appRcJSON$build = _appRcJSON$build.compress) === null || _appRcJSON$build === void 0 ? void 0 : _appRcJSON$build.files) !== null && _appRcJSON$build$comp !== void 0 ? _appRcJSON$build$comp : [];
233
260
  const archive = archiver("zip", {
234
261
  zlib: {
235
262
  level: 9
@@ -252,18 +279,19 @@ const build = async function() {
252
279
  });
253
280
  archive.on("finish", () => {
254
281
  process.stdout.write("\n");
255
- console.log(`Output file: ${normalizedOptions.output}`);
256
- console.log(`OPKX "${node_path.basename(normalizedOptions.output)}" created successfully!`);
282
+ console.log("");
283
+ console.log("Files in archive: ", createOnesApp.PUBLIC_FILENAME.MANIFEST, files);
284
+ console.log(`App "${appName}" built successfully!`);
285
+ console.log(`OPKX "${outputFilename}" created successfully!`);
286
+ console.log(`Output file: ${outputPath}`);
257
287
  });
258
- const outputStream = node_fs.createWriteStream(normalizedOptions.output);
259
288
  archive.pipe(outputStream);
260
- const files = (_appRcJSON$build$comp = (_appRcJSON$build = appRcJSON.build) === null || _appRcJSON$build === void 0 || (_appRcJSON$build = _appRcJSON$build.compress) === null || _appRcJSON$build === void 0 ? void 0 : _appRcJSON$build.files) !== null && _appRcJSON$build$comp !== void 0 ? _appRcJSON$build$comp : [];
261
289
  files.forEach((file) => {
262
290
  archive.glob(file, {
263
291
  cwd: getAppWorkspacePath()
264
292
  });
265
293
  });
266
- archive.file(createOnesApp.PUBLIC_FILENAME.MANIFEST, {
294
+ archive.file(node_path.join(getAppWorkspacePath(), createOnesApp.PUBLIC_FILENAME.MANIFEST), {
267
295
  name: createOnesApp.PUBLIC_FILENAME.MANIFEST
268
296
  });
269
297
  archive.finalize();
@@ -271,7 +299,8 @@ const build = async function() {
271
299
  const config = {
272
300
  defaultPort: {
273
301
  login: 8200,
274
- tunnel: 8201
302
+ hosted: 8201,
303
+ devWebServer: 8202
275
304
  }
276
305
  };
277
306
  const getConfig = () => config;
@@ -320,11 +349,11 @@ const getStore = async () => {
320
349
  const setStore = async (store) => {
321
350
  try {
322
351
  await ensureFile(storePath);
323
- const version = `${getPackageJSON().version}`;
352
+ const version2 = `${getPackageJSON().version}`;
324
353
  const timestamp = Date.now();
325
354
  return await writeJSON(storePath, {
326
355
  ...store,
327
- version,
356
+ version: version2,
328
357
  timestamp
329
358
  }, {
330
359
  encoding: "utf8"
@@ -381,9 +410,15 @@ const getHostToken = async () => {
381
410
  const store = await getStore();
382
411
  return (_store$host_token = store.host_token) !== null && _store$host_token !== void 0 ? _store$host_token : "";
383
412
  };
413
+ const setHostToken = async (token) => {
414
+ return mergeStore({
415
+ host_token: token
416
+ });
417
+ };
384
418
  const API = {
385
419
  TOKEN_INFO: "/project/api/project/auth/token_info",
386
420
  HOSTED_TOKEN: "/platform/runtime_manager/hosted_token",
421
+ HOSTED_ABILITY_STORAGE_DEV_DECLARE: "/platform/runtime_manager/hosted_ability/storage/:appID/dev_declare",
387
422
  APP_LIST: "/platform/api/app/list",
388
423
  APP_INSTALL: "/platform/api/app/install",
389
424
  APP_UPGRADE: "/platform/api/app/upgrade",
@@ -391,6 +426,7 @@ const API = {
391
426
  APP_ENABLE: "/platform/api/app/:installation_id/enable",
392
427
  APP_DISABLE: "/platform/api/app/:installation_id/disable"
393
428
  };
429
+ const REQUEST_TIMEOUT = 1e4;
394
430
  const getPath = (path, map2) => {
395
431
  var _context;
396
432
  return _reduceInstanceProperty(_context = path.split("/")).call(_context, (base, part) => {
@@ -403,6 +439,11 @@ const getPath = (path, map2) => {
403
439
  const consoleUnauthorizedMessage = () => {
404
440
  console.log("Not logged in");
405
441
  console.log('Login with "ones login" command');
442
+ process.exit(1);
443
+ };
444
+ const consoleAppNotInstalledMessage = () => {
445
+ console.log("App not installed");
446
+ process.exit(1);
406
447
  };
407
448
  const getURL = async (path, pathMap, queryMap) => {
408
449
  const base = await getRegionURL();
@@ -411,7 +452,16 @@ const getURL = async (path, pathMap, queryMap) => {
411
452
  return `${base}${getPath(path, pathMap !== null && pathMap !== void 0 ? pathMap : {})}${query ? `?${query}` : ""}`;
412
453
  }
413
454
  consoleUnauthorizedMessage();
414
- process$1.exit(1);
455
+ };
456
+ const getHostedFetchHeaders = async (value) => {
457
+ const hostedToken = await getHostToken();
458
+ if (hostedToken) {
459
+ return lodashEs.merge({
460
+ Authorization: `Bearer ${hostedToken}`
461
+ }, value);
462
+ }
463
+ consoleUnauthorizedMessage();
464
+ process.exit(1);
415
465
  };
416
466
  const getHeaders = async (value) => {
417
467
  const token = await getONESToken();
@@ -421,18 +471,41 @@ const getHeaders = async (value) => {
421
471
  }, value);
422
472
  }
423
473
  consoleUnauthorizedMessage();
424
- process$1.exit(1);
474
+ process.exit(1);
425
475
  };
426
476
  const handleError = (error) => {
427
- var _error$response;
477
+ var _error$response, _error$response2;
428
478
  if (((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.status) === 401) {
429
479
  console.log(error.response.statusText);
430
480
  consoleUnauthorizedMessage();
431
- } else {
432
- console.error(error);
481
+ process.exit(1);
482
+ }
483
+ if ((_error$response2 = error.response) !== null && _error$response2 !== void 0 && _error$response2.data) {
484
+ try {
485
+ const message = JSON.stringify(error.response.data, null, 2);
486
+ console.error(message);
487
+ process.exit(1);
488
+ } catch (error2) {
489
+ }
433
490
  }
491
+ console.error(error);
434
492
  return {};
435
493
  };
494
+ const startWaiting = () => {
495
+ const time = 3e3;
496
+ let spinner = null;
497
+ const sid = setTimeout(() => {
498
+ spinner = ora("Waiting for response...");
499
+ spinner.start();
500
+ }, time);
501
+ const cancelWaiting = () => {
502
+ clearTimeout(sid);
503
+ if (spinner) {
504
+ spinner.stop();
505
+ }
506
+ };
507
+ return cancelWaiting;
508
+ };
436
509
  const fetchAppBase = async (params) => {
437
510
  var _params$url;
438
511
  const url = await getURL((_params$url = params.url) !== null && _params$url !== void 0 ? _params$url : "", params.pathMap, params.queryMap);
@@ -440,7 +513,20 @@ const fetchAppBase = async (params) => {
440
513
  const response = await axios({
441
514
  ...params,
442
515
  url,
443
- headers
516
+ headers,
517
+ timeout: REQUEST_TIMEOUT
518
+ });
519
+ return response.data;
520
+ };
521
+ const fetchHostedAbilityBase = async (params) => {
522
+ var _params$url2;
523
+ const url = await getURL((_params$url2 = params.url) !== null && _params$url2 !== void 0 ? _params$url2 : "", params.pathMap, params.queryMap);
524
+ const headers = await getHostedFetchHeaders(params.headers);
525
+ const response = await axios({
526
+ ...params,
527
+ url,
528
+ headers,
529
+ timeout: REQUEST_TIMEOUT
444
530
  });
445
531
  return response.data;
446
532
  };
@@ -466,6 +552,16 @@ const fetchHostedToken = async (data) => {
466
552
  data
467
553
  }).catch(handleError);
468
554
  };
555
+ const fetchHostedAbilityStorageDevDeclare = async (appID, data) => {
556
+ return await fetchHostedAbilityBase({
557
+ url: API.HOSTED_ABILITY_STORAGE_DEV_DECLARE,
558
+ method: "POST",
559
+ pathMap: {
560
+ appID
561
+ },
562
+ data
563
+ }).catch(handleError);
564
+ };
469
565
  const fetchAppInstall = async (data) => {
470
566
  var _appList$data$0$insta, _appList$data;
471
567
  const appID = getAppManifestJSON().app.id;
@@ -483,44 +579,78 @@ const fetchAppUninstall = async () => {
483
579
  const appID = getAppManifestJSON().app.id;
484
580
  const appList = await fetchAppList(appID);
485
581
  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 : "";
486
- return await fetchAppBase({
487
- url: API.APP_UNINSTALL,
488
- method: "POST",
489
- pathMap: {
490
- installation_id: installationID
491
- }
492
- }).catch(handleError);
582
+ if (installationID) {
583
+ return await fetchAppBase({
584
+ url: API.APP_UNINSTALL,
585
+ method: "POST",
586
+ pathMap: {
587
+ installation_id: installationID
588
+ }
589
+ }).catch(handleError);
590
+ }
591
+ consoleAppNotInstalledMessage();
592
+ process.exit(1);
493
593
  };
494
594
  const fetchAppEnable = async () => {
495
595
  var _appList$data$0$insta3, _appList$data3;
496
596
  const appID = getAppManifestJSON().app.id;
497
597
  const appList = await fetchAppList(appID);
498
598
  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 : "";
499
- return await fetchAppBase({
500
- url: API.APP_ENABLE,
501
- method: "POST",
502
- pathMap: {
503
- installation_id: installationID
504
- }
505
- }).catch(handleError);
599
+ if (installationID) {
600
+ return await fetchAppBase({
601
+ url: API.APP_ENABLE,
602
+ method: "POST",
603
+ pathMap: {
604
+ installation_id: installationID
605
+ }
606
+ }).catch(handleError);
607
+ }
608
+ consoleAppNotInstalledMessage();
609
+ process.exit(1);
506
610
  };
507
611
  const fetchAppDisable = async () => {
508
612
  var _appList$data$0$insta4, _appList$data4;
509
613
  const appID = getAppManifestJSON().app.id;
510
614
  const appList = await fetchAppList(appID);
511
615
  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 : "";
512
- return await fetchAppBase({
513
- url: API.APP_DISABLE,
514
- method: "POST",
515
- pathMap: {
516
- installation_id: installationID
517
- }
518
- }).catch(handleError);
616
+ if (installationID) {
617
+ return await fetchAppBase({
618
+ url: API.APP_DISABLE,
619
+ method: "POST",
620
+ pathMap: {
621
+ installation_id: installationID
622
+ }
623
+ }).catch(handleError);
624
+ }
625
+ consoleAppNotInstalledMessage();
626
+ process.exit(1);
627
+ };
628
+ const checkTokenInfo = async () => {
629
+ var _store$ones_token, _store$region_url;
630
+ let boolean = true;
631
+ const store = await getStore();
632
+ const token = (_store$ones_token = store.ones_token) !== null && _store$ones_token !== void 0 ? _store$ones_token : "";
633
+ const regionURL = (_store$region_url = store.region_url) !== null && _store$region_url !== void 0 ? _store$region_url : "";
634
+ if (token && regionURL) {
635
+ await fetchAppBase({
636
+ url: API.TOKEN_INFO,
637
+ method: "GET"
638
+ }).catch(() => {
639
+ boolean = false;
640
+ });
641
+ } else {
642
+ boolean = false;
643
+ }
644
+ return boolean;
519
645
  };
520
646
  const isPortNumber = /^[1-9]\d{0,4}$/;
521
647
  const minPortNumber = 1;
522
648
  const maxPortNumber = 65535;
649
+ const MANIFEST_PATH = "/manifest";
650
+ const ONES_CLI_INTERNAL_MANIFEST_PATH = "/__ones_cli_internal_manifest__";
651
+ const MAX_RELAY_BODY_BYTES = 64 * 1024 * 1024;
523
652
  const normalize$9 = async (options) => {
653
+ var _options$useStorage;
524
654
  const portInput = options.port;
525
655
  if (portInput)
526
656
  ;
@@ -539,10 +669,55 @@ const normalize$9 = async (options) => {
539
669
  }
540
670
  const port = portString;
541
671
  return {
542
- port
672
+ port,
673
+ useStorage: (_options$useStorage = options.useStorage) !== null && _options$useStorage !== void 0 ? _options$useStorage : false
543
674
  };
544
675
  };
545
- const MAX_RELAY_BODY_BYTES = 64 * 1024 * 1024;
676
+ const getTunnelContext = async () => {
677
+ var _appManifestJSON$app$, _appManifestJSON$app, _store$region_url, _store$ones_token;
678
+ const appManifestJSON = getAppManifestJSON();
679
+ 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$ : "";
680
+ const store = await getStore();
681
+ const regionURL = (_store$region_url = store.region_url) !== null && _store$region_url !== void 0 ? _store$region_url : "";
682
+ const onesToken = (_store$ones_token = store.ones_token) !== null && _store$ones_token !== void 0 ? _store$ones_token : "";
683
+ if (appID && regionURL && onesToken) {
684
+ return {
685
+ appID,
686
+ regionURL,
687
+ onesToken,
688
+ store,
689
+ appManifestJSON
690
+ };
691
+ }
692
+ consoleUnauthorizedMessage();
693
+ process.exit(1);
694
+ };
695
+ const getStorageTokenScopes = (ones2) => {
696
+ const storage = ones2 === null || ones2 === void 0 ? void 0 : ones2.storage;
697
+ if (!storage) {
698
+ return [];
699
+ }
700
+ const scopes = /* @__PURE__ */ new Set();
701
+ if (Array.isArray(storage.entities) && storage.entities.length > 0) {
702
+ scopes.add(createOnesApp.HostedTokenScope.STORAGE_ENTITY);
703
+ }
704
+ if (storage.object !== void 0 && storage.object !== null && storage.object !== false) {
705
+ scopes.add(createOnesApp.HostedTokenScope.STORAGE_OBJECT);
706
+ }
707
+ return Array.from(scopes);
708
+ };
709
+ const getRelayScope = () => {
710
+ return createOnesApp.HostedTokenScope.RELAY;
711
+ };
712
+ const buildTunnelUrl = async () => {
713
+ const {
714
+ appID,
715
+ regionURL
716
+ } = await getTunnelContext();
717
+ const url = new URL(regionURL);
718
+ url.pathname = `/platform/app/relay/dispatch/${appID}`;
719
+ return url.toString();
720
+ };
546
721
  class TunnelClient {
547
722
  constructor(localPort, baseUrl, appID, hostedToken) {
548
723
  let enableInternalManifestRoute = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : true;
@@ -795,80 +970,39 @@ class TunnelClient {
795
970
  return null;
796
971
  }
797
972
  }
798
- const ONES_CLI_INTERNAL_MANIFEST_PATH = "/__ones_cli_internal_manifest__";
799
- const buildTunnelContext = async () => {
800
- var _appManifestJSON$app$, _appManifestJSON$app;
801
- const appManifestJSON = getAppManifestJSON();
802
- 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$ : "";
803
- if (!appID) {
804
- throw new Error("app id is empty");
805
- }
806
- const regionURL = await getRegionURL();
807
- if (!regionURL) {
808
- throw new Error("region url is empty");
809
- }
810
- return {
811
- appManifestJSON,
812
- appID,
813
- regionURL
814
- };
815
- };
816
- const getHostedTokenScopes = (ones2) => {
817
- const storage = ones2 === null || ones2 === void 0 ? void 0 : ones2.storage;
818
- if (!storage) {
819
- return [];
820
- }
821
- const scopes = /* @__PURE__ */ new Set();
822
- if (Array.isArray(storage.entities) && storage.entities.length > 0) {
823
- scopes.add(createOnesApp.HostedTokenScope.STORAGE_ENTITY);
824
- }
825
- if (storage.object !== void 0 && storage.object !== null && storage.object !== false) {
826
- scopes.add(createOnesApp.HostedTokenScope.STORAGE_OBJECT);
827
- }
828
- return Array.from(scopes);
829
- };
830
- const getRelayScope = () => {
831
- return createOnesApp.HostedTokenScope.RELAY;
832
- };
833
- const buildTunnelUrl = async () => {
834
- const {
835
- appID,
836
- regionURL
837
- } = await buildTunnelContext();
838
- const url = new URL(regionURL);
839
- return `${url.protocol}//${url.host}/platform/app/relay/dispatch/${appID}`;
840
- };
841
973
  const invokeTunnel = async function(port) {
842
- var _options$rebuildWhenE, _hostedTokenResponse$, _options$enableIntern;
974
+ var _options$rebuildWhenE, _options$enableIntern, _options$useStorageFo, _hostedTokenResponse$, _appManifestJSON$ones, _appManifestJSON$ones2;
843
975
  let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
844
976
  const {
845
977
  appManifestJSON,
846
978
  appID,
847
979
  regionURL
848
- } = await buildTunnelContext();
849
- const runnelUrl = await buildTunnelUrl();
980
+ } = await getTunnelContext();
850
981
  const rebuildWhenExists = (_options$rebuildWhenE = options.rebuildWhenExists) !== null && _options$rebuildWhenE !== void 0 ? _options$rebuildWhenE : true;
851
- const onesToken = await getONESToken();
852
- if (!onesToken) {
853
- consoleUnauthorizedMessage();
854
- process$1.exit(1);
855
- }
856
- const storageScopes = getHostedTokenScopes(appManifestJSON.ones);
982
+ const enableInternalManifestRoute = (_options$enableIntern = options.enableInternalManifestRoute) !== null && _options$enableIntern !== void 0 ? _options$enableIntern : true;
983
+ const storageScopes = getStorageTokenScopes(appManifestJSON.ones);
857
984
  const scopes = Array.from(/* @__PURE__ */ new Set([...storageScopes, getRelayScope()]));
858
985
  const hostedTokenResponse = await fetchHostedToken({
859
986
  app_id: appID,
860
- scopes
987
+ scopes,
988
+ confirm_for_dev: (_options$useStorageFo = options.useStorageForDev) !== null && _options$useStorageFo !== void 0 ? _options$useStorageFo : false
861
989
  });
862
990
  const hostedToken = hostedTokenResponse === null || hostedTokenResponse === void 0 || (_hostedTokenResponse$ = hostedTokenResponse.data) === null || _hostedTokenResponse$ === void 0 ? void 0 : _hostedTokenResponse$.hosted_token;
863
991
  if (!hostedToken) {
864
992
  return createOnesApp.throwError(ErrorCode.HOSTED_TOKEN_EMPTY, i18n.t("error.hostedToken.empty"));
865
993
  }
866
- process.env.ONES_HOSTED_TOKEN = hostedToken;
867
- const client = new TunnelClient(port, regionURL, appID, hostedToken, (_options$enableIntern = options.enableInternalManifestRoute) !== null && _options$enableIntern !== void 0 ? _options$enableIntern : true, rebuildWhenExists);
994
+ await setHostToken(hostedToken);
995
+ 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 : [];
996
+ if (entities.length > 0) {
997
+ await fetchHostedAbilityStorageDevDeclare(appID, {
998
+ opkx_content: appManifestJSON
999
+ });
1000
+ }
1001
+ const client = new TunnelClient(port, regionURL, appID, hostedToken, enableInternalManifestRoute, rebuildWhenExists);
868
1002
  await client.connect();
869
- console.log(`Relay endpoint: ${runnelUrl}`);
870
1003
  };
871
1004
  const tunnel = async function() {
1005
+ var _normalizedOptions$us;
872
1006
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
873
1007
  args[_key] = arguments[_key];
874
1008
  }
@@ -876,18 +1010,89 @@ const tunnel = async function() {
876
1010
  options
877
1011
  } = createOnesApp.getCommandOptions(args, tunnelCommandArguments);
878
1012
  const normalizedOptions = await normalize$9(options);
879
- await invokeTunnel(Number(normalizedOptions.port));
1013
+ const port = Number(normalizedOptions.port);
1014
+ const cancelWaiting = startWaiting();
1015
+ await invokeTunnel(port, {
1016
+ enableInternalManifestRoute: false,
1017
+ rebuildWhenExists: true,
1018
+ useStorageForDev: (_normalizedOptions$us = normalizedOptions.useStorage) !== null && _normalizedOptions$us !== void 0 ? _normalizedOptions$us : false
1019
+ });
1020
+ cancelWaiting();
1021
+ const tunnelUrl = await buildTunnelUrl();
1022
+ console.log(`Relay endpoint: ${tunnelUrl}`);
880
1023
  };
881
1024
  const normalize$8 = async (options) => {
882
1025
  lodashEs.noop(options);
883
1026
  return {};
884
1027
  };
885
- const invokeInstall = async () => {
886
- const runnelUrl = await buildTunnelUrl();
1028
+ const displayAppDetail = async (installationID) => {
1029
+ var _tokenInfo$org$uuid, _tokenInfo$org, _tokenInfo$teams$0$uu, _tokenInfo$teams, _tokenInfo$org$visibi, _tokenInfo$org2;
1030
+ const tokenInfo = await fetchTokenInfo();
1031
+ 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 : "";
1032
+ 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 : "";
1033
+ 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;
1034
+ const baseURL = await getBaseURL();
1035
+ if (isOrgVisible && orgUUID) {
1036
+ const url = `${baseURL}project/#/org/${orgUUID}/setting/app_manager/platform_app/${installationID}`;
1037
+ console.log(`See App detail: ${url}`);
1038
+ }
1039
+ if (!isOrgVisible && teamUUID) {
1040
+ const url = `${baseURL}project/#/team/${teamUUID}/team_setting/app_manager/platform_app/${installationID}`;
1041
+ console.log(`See App detail: ${url}`);
1042
+ }
1043
+ };
1044
+ const invokeInstall = async (manifestUrl) => {
1045
+ const {
1046
+ app
1047
+ } = getAppManifestJSON();
1048
+ const appName = app.name;
1049
+ const appID = app.id;
1050
+ const cancelWaiting = startWaiting();
887
1051
  const result = await fetchAppInstall({
888
- manifest_url: `${runnelUrl}${ONES_CLI_INTERNAL_MANIFEST_PATH}`
1052
+ manifest_url: manifestUrl,
1053
+ options: {
1054
+ enable: true
1055
+ }
889
1056
  });
890
- return result;
1057
+ cancelWaiting();
1058
+ if (result.code === "OK") {
1059
+ var _appList$data$0$insta, _appList$data;
1060
+ console.log(`App "${appName}" installed successfully!`);
1061
+ const appList = await fetchAppList(appID);
1062
+ 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 : "";
1063
+ if (installationID) {
1064
+ await displayAppDetail(installationID);
1065
+ }
1066
+ return true;
1067
+ } else {
1068
+ console.log(`App "${appName}" installed failed!`);
1069
+ console.error(JSON.stringify(result, null, 2));
1070
+ }
1071
+ return false;
1072
+ };
1073
+ const getManifestUrl = async () => {
1074
+ const tunnelUrl = await buildTunnelUrl();
1075
+ const customManifestUrl = `${tunnelUrl}${MANIFEST_PATH}`;
1076
+ const internalManifestUrl = `${tunnelUrl}${ONES_CLI_INTERNAL_MANIFEST_PATH}`;
1077
+ const internalResult = await axios.get(internalManifestUrl).then((response) => {
1078
+ if (response.status === 200) {
1079
+ return internalManifestUrl;
1080
+ }
1081
+ return null;
1082
+ }).catch(lodashEs.noop);
1083
+ if (internalResult) {
1084
+ return internalResult;
1085
+ }
1086
+ const customResult = await axios.get(customManifestUrl).then((response) => {
1087
+ if (response.status === 200) {
1088
+ return customManifestUrl;
1089
+ }
1090
+ return null;
1091
+ }).catch(lodashEs.noop);
1092
+ if (customResult) {
1093
+ return customResult;
1094
+ }
1095
+ return null;
891
1096
  };
892
1097
  const install = async function() {
893
1098
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
@@ -898,32 +1103,22 @@ const install = async function() {
898
1103
  } = createOnesApp.getCommandOptions(args, installCommandArguments);
899
1104
  const normalizedOptions = await normalize$8(options);
900
1105
  lodashEs.noop(normalizedOptions);
901
- await invokeTunnel(getConfig().defaultPort.tunnel);
902
- const result = await invokeInstall();
903
- if (result.code === "OK") {
904
- var _appList$data$0$insta, _appList$data;
905
- console.log("App installed successfully!");
906
- const appID = getAppManifestJSON().app.id;
907
- const appList = await fetchAppList(appID);
908
- 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 : "";
909
- if (installationID) {
910
- var _tokenInfo$org$uuid, _tokenInfo$org, _tokenInfo$teams$0$uu, _tokenInfo$teams, _tokenInfo$org$visibi, _tokenInfo$org2;
911
- const tokenInfo = await fetchTokenInfo();
912
- 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 : "";
913
- 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 : "";
914
- 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;
915
- const baseURL = await getBaseURL();
916
- if (isOrgVisible && orgUUID) {
917
- const url = `${baseURL}/project/#/org/${orgUUID}/setting/app_manager/platform_app/${installationID}`;
918
- console.log(`See App detail: ${url}`);
919
- }
920
- if (!isOrgVisible && teamUUID) {
921
- const url = `${baseURL}/project/#/team/${teamUUID}/team_setting/app_manager/platform_app/${installationID}`;
922
- console.log(`See App detail: ${url}`);
923
- }
924
- }
925
- } else {
926
- console.error(result);
1106
+ const {
1107
+ app
1108
+ } = getAppManifestJSON();
1109
+ const appName = app.name;
1110
+ const manifestUrl = await getManifestUrl();
1111
+ if (!manifestUrl) {
1112
+ console.log(`App "${appName}" server not available!`);
1113
+ console.log('Use "ones dev" command or "ones tunnel" command to start the server first');
1114
+ console.log("Visit https://open.ones.com for more information and help");
1115
+ process.exit(1);
1116
+ }
1117
+ const success = await invokeInstall(manifestUrl);
1118
+ if (success)
1119
+ ;
1120
+ else {
1121
+ console.log("Visit https://open.ones.com for more information and help");
927
1122
  }
928
1123
  };
929
1124
  var InstallOptions = /* @__PURE__ */ ((InstallOptions2) => {
@@ -934,8 +1129,9 @@ var InstallOptions = /* @__PURE__ */ ((InstallOptions2) => {
934
1129
  })(InstallOptions || {});
935
1130
  const defaultInstall = InstallOptions.AUTO;
936
1131
  const normalize$7 = async (options) => {
937
- var _options$install;
1132
+ var _options$install, _options$command, _options$useStorage;
938
1133
  let install2 = (_options$install = options.install) !== null && _options$install !== void 0 ? _options$install : defaultInstall;
1134
+ const command = (_options$command = options.command) !== null && _options$command !== void 0 ? _options$command : "";
939
1135
  switch (true) {
940
1136
  case install2 === InstallOptions.AUTO:
941
1137
  break;
@@ -947,25 +1143,29 @@ const normalize$7 = async (options) => {
947
1143
  break;
948
1144
  }
949
1145
  return {
950
- install: install2
1146
+ install: install2,
1147
+ command,
1148
+ useStorage: (_options$useStorage = options.useStorage) !== null && _options$useStorage !== void 0 ? _options$useStorage : false
951
1149
  };
952
1150
  };
953
- const isViteReady = (line) => /ready in|VITE\s+v[\d.]+.*ready/i.test(line);
954
- const isNestReady = (line) => /Found\s+0\s+errors\.\s*Watching|Nest application successfully started|listening on/i.test(line);
955
- function createDevOutputPipes(onBothReady) {
956
- const state = {
957
- viteReady: false,
958
- nestReady: false,
959
- summaryPrinted: false
960
- };
961
- const tryPrintSummary = () => {
962
- if (state.summaryPrinted || !state.viteReady || !state.nestReady)
1151
+ const IDLE_MS = 2e3;
1152
+ function createReadyStatusPipes(onReady) {
1153
+ let readyTimer = null;
1154
+ let summaryPrinted = false;
1155
+ const scheduleReady = () => {
1156
+ if (summaryPrinted)
963
1157
  return;
964
- state.summaryPrinted = true;
965
- onBothReady();
1158
+ if (readyTimer)
1159
+ clearTimeout(readyTimer);
1160
+ readyTimer = setTimeout(() => {
1161
+ readyTimer = null;
1162
+ if (!summaryPrinted) {
1163
+ summaryPrinted = true;
1164
+ onReady();
1165
+ }
1166
+ }, IDLE_MS);
966
1167
  };
967
1168
  const pipe = (stream, isStderr) => {
968
- let buffer = "";
969
1169
  const write = (chunk) => {
970
1170
  if (isStderr)
971
1171
  process.stderr.write(chunk);
@@ -973,29 +1173,17 @@ function createDevOutputPipes(onBothReady) {
973
1173
  process.stdout.write(chunk);
974
1174
  };
975
1175
  stream.on("data", (chunk) => {
976
- var _lines$pop;
977
1176
  const str = typeof chunk === "string" ? chunk : chunk.toString();
978
- buffer += str;
979
- const lines = buffer.split(/\r?\n/);
980
- buffer = (_lines$pop = lines.pop()) !== null && _lines$pop !== void 0 ? _lines$pop : "";
981
- for (const line of lines) {
982
- if (isViteReady(line))
983
- state.viteReady = true;
984
- if (isNestReady(line))
985
- state.nestReady = true;
986
- tryPrintSummary();
987
- write(line + "\n");
1177
+ write(str);
1178
+ if (str.startsWith("[backend]") || str.startsWith("[web]")) {
1179
+ scheduleReady();
988
1180
  }
989
1181
  });
990
- stream.on("end", () => {
991
- if (buffer)
992
- write(buffer + "\n");
993
- });
994
1182
  };
995
1183
  return pipe;
996
1184
  }
997
1185
  const dev = async function() {
998
- var _appPackageJSON$scrip;
1186
+ var _appRcJSON$dev, _defaultAppRcJSON$dev, _appRcJSON$dev$comman, _appRcJSON$dev2;
999
1187
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1000
1188
  args[_key] = arguments[_key];
1001
1189
  }
@@ -1003,51 +1191,116 @@ const dev = async function() {
1003
1191
  options
1004
1192
  } = createOnesApp.getCommandOptions(args, devCommandArguments);
1005
1193
  const normalizedOptions = await normalize$7(options);
1006
- const appPackageJSON = getAppPackageJSON();
1194
+ const appRcJSON = await getAppRcJSON();
1195
+ const firstCommand = normalizedOptions.command || ((_appRcJSON$dev = appRcJSON.dev) === null || _appRcJSON$dev === void 0 || (_appRcJSON$dev = _appRcJSON$dev.command) === null || _appRcJSON$dev === void 0 ? void 0 : _appRcJSON$dev[0]) || ((_defaultAppRcJSON$dev = defaultAppRcJSON.dev) === null || _defaultAppRcJSON$dev === void 0 || (_defaultAppRcJSON$dev = _defaultAppRcJSON$dev.command) === null || _defaultAppRcJSON$dev === void 0 ? void 0 : _defaultAppRcJSON$dev[0]) || "";
1196
+ if (!firstCommand) {
1197
+ return createOnesApp.throwError(ErrorCode.INCORRECT_DEV_COMMAND, i18n.t("error.dev.incorrectCommand"));
1198
+ }
1199
+ 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 : [];
1200
+ const currentCommandString = currentCommand.join(" ");
1201
+ const defaultDevCommandString = defaultDevCommand.join(" ");
1202
+ if (firstCommand === "npm") {
1203
+ const appPackageJSON = getAppPackageJSON();
1204
+ if (currentCommandString === defaultDevCommandString) {
1205
+ var _appPackageJSON$scrip;
1206
+ if (!((_appPackageJSON$scrip = appPackageJSON.scripts) !== null && _appPackageJSON$scrip !== void 0 && _appPackageJSON$scrip.dev)) {
1207
+ return createOnesApp.throwError(ErrorCode.DEV_SCRIPT_NOT_FOUND, i18n.t("error.dev.scriptNotFound"));
1208
+ }
1209
+ }
1210
+ }
1007
1211
  const appManifestJSON = getAppManifestJSON();
1008
- const appRcJSON = getAppRcJSON();
1009
- lodashEs.noop(appManifestJSON);
1010
- lodashEs.noop(appRcJSON);
1011
- if (!((_appPackageJSON$scrip = appPackageJSON.scripts) !== null && _appPackageJSON$scrip !== void 0 && _appPackageJSON$scrip.dev)) {
1012
- return createOnesApp.throwError(ErrorCode.DEV_SCRIPT_NOT_FOUND, i18n.t("error.dev.scriptNotFound"));
1013
- }
1014
- const ONES_HOSTED_TOKEN = await getHostToken();
1015
- const port = getConfig().defaultPort.tunnel;
1016
- const cwd = getAppWorkspacePath();
1017
- const env = {
1212
+ const {
1213
+ app
1214
+ } = appManifestJSON;
1215
+ const appID = app.id;
1216
+ const config2 = getConfig();
1217
+ const ONES_HOSTED_PORT = await getPort({
1218
+ port: config2.defaultPort.hosted
1219
+ });
1220
+ const ONES_DEV_WEB_SERVER_PORT = await getPort({
1221
+ port: config2.defaultPort.devWebServer
1222
+ });
1223
+ const env2 = {
1018
1224
  ...process.env,
1019
1225
  NODE_ENV: "development",
1020
- ONES_HOSTED_PORT: `${port}`,
1021
- ONES_HOSTED_TOKEN
1226
+ ONES_HOSTED_PORT: `${ONES_HOSTED_PORT}`,
1227
+ ONES_DEV_WEB_SERVER_PORT: `${ONES_DEV_WEB_SERVER_PORT}`,
1228
+ ONES_HOSTED_TOKEN: "",
1229
+ ONES_HOSTED_APP_ID: "",
1230
+ ONES_HOSTED_BASE_URL: ""
1022
1231
  };
1023
- const tunnelChild = node_child_process.spawn("ones", ["tunnel", String(port)], {
1024
- cwd,
1025
- stdio: "inherit"
1026
- });
1027
- const devChild = node_child_process.spawn("npm", ["run", "dev"], {
1028
- cwd,
1029
- stdio: ["inherit", "pipe", "pipe"],
1030
- env
1031
- });
1032
- const onBothReady = () => {
1232
+ const cancelWaiting = startWaiting();
1233
+ let enableTunnel = true;
1234
+ if (normalizedOptions.install === InstallOptions.TRUE)
1235
+ ;
1236
+ else {
1237
+ enableTunnel = await checkTokenInfo();
1238
+ }
1239
+ if (enableTunnel) {
1240
+ var _normalizedOptions$us;
1241
+ await invokeTunnel(ONES_HOSTED_PORT, {
1242
+ enableInternalManifestRoute: true,
1243
+ rebuildWhenExists: true,
1244
+ useStorageForDev: (_normalizedOptions$us = normalizedOptions.useStorage) !== null && _normalizedOptions$us !== void 0 ? _normalizedOptions$us : false
1245
+ });
1246
+ const regionURL = await getRegionURL();
1247
+ const ONES_HOSTED_TOKEN = await getHostToken();
1248
+ const ONES_HOSTED_APP_ID = appID;
1249
+ const ONES_HOSTED_BASE_URL = `${regionURL}/platform/runtime_manager`;
1250
+ env2.ONES_HOSTED_TOKEN = ONES_HOSTED_TOKEN;
1251
+ env2.ONES_HOSTED_APP_ID = ONES_HOSTED_APP_ID;
1252
+ env2.ONES_HOSTED_BASE_URL = ONES_HOSTED_BASE_URL;
1253
+ }
1254
+ cancelWaiting();
1255
+ const onReady = async () => {
1256
+ const appName = app.name;
1257
+ let manifestUrl = "";
1033
1258
  console.log("");
1034
- console.log("Services ready:");
1035
- console.log(`http://localhost:${port}`);
1259
+ console.log(`Local: http://localhost:${ONES_HOSTED_PORT}`);
1260
+ if (enableTunnel) {
1261
+ const tunnelUrl = await buildTunnelUrl();
1262
+ console.log(`URL: ${tunnelUrl}`);
1263
+ manifestUrl = `${tunnelUrl}${ONES_CLI_INTERNAL_MANIFEST_PATH}`;
1264
+ }
1265
+ console.log("Docs site: https://open.ones.com");
1266
+ console.log(`App "${appName}" server is ready!`);
1036
1267
  console.log("");
1037
- if (normalizedOptions.install === InstallOptions.TRUE) {
1038
- invokeInstall().catch((error) => {
1039
- console.error(error);
1040
- });
1268
+ if (enableTunnel) {
1269
+ switch (normalizedOptions.install) {
1270
+ case InstallOptions.TRUE:
1271
+ await invokeInstall(manifestUrl);
1272
+ break;
1273
+ case InstallOptions.AUTO:
1274
+ {
1275
+ var _appList$data$0$insta, _appList$data;
1276
+ const appList = await fetchAppList(appID);
1277
+ 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 : "";
1278
+ if (installationID) {
1279
+ await displayAppDetail(installationID);
1280
+ } else {
1281
+ await invokeInstall(manifestUrl);
1282
+ }
1283
+ }
1284
+ break;
1285
+ case InstallOptions.FALSE:
1286
+ break;
1287
+ }
1041
1288
  }
1042
1289
  };
1043
- const pipe = createDevOutputPipes(onBothReady);
1044
- if (devChild.stdout)
1045
- pipe(devChild.stdout, false);
1046
- if (devChild.stderr)
1047
- pipe(devChild.stderr, true);
1290
+ const cwd = getAppWorkspacePath();
1291
+ const child = node_child_process.spawn(firstCommand, currentCommand.slice(1), {
1292
+ cwd,
1293
+ stdio: ["inherit", "pipe", "pipe"],
1294
+ env: env2,
1295
+ shell: true
1296
+ });
1297
+ const pipe = createReadyStatusPipes(onReady);
1298
+ if (child.stdout)
1299
+ pipe(child.stdout, false);
1300
+ if (child.stderr)
1301
+ pipe(child.stderr, true);
1048
1302
  const cleanup = () => {
1049
- tunnelChild.kill();
1050
- devChild.kill();
1303
+ child.kill();
1051
1304
  };
1052
1305
  const onSignal = () => {
1053
1306
  cleanup();
@@ -1056,7 +1309,7 @@ const dev = async function() {
1056
1309
  process.on("SIGINT", onSignal);
1057
1310
  process.on("SIGTERM", onSignal);
1058
1311
  await new Promise((resolve) => {
1059
- devChild.on("exit", () => {
1312
+ child.on("exit", () => {
1060
1313
  cleanup();
1061
1314
  process.off("SIGINT", onSignal);
1062
1315
  process.off("SIGTERM", onSignal);
@@ -1200,6 +1453,15 @@ const login = async function() {
1200
1453
  }
1201
1454
  process$1.exit(0);
1202
1455
  });
1456
+ let exited = false;
1457
+ const handleExit = () => {
1458
+ if (exited)
1459
+ return;
1460
+ exited = true;
1461
+ resolve(null);
1462
+ };
1463
+ process$1.on("SIGINT", handleExit);
1464
+ process$1.on("SIGTERM", handleExit);
1203
1465
  console.log("Logging into your ONES account...");
1204
1466
  console.log(`Opening ${url}`);
1205
1467
  ora("Waiting for authorization...").start();
@@ -1236,11 +1498,14 @@ const whoami = async function() {
1236
1498
  const normalizedOptions = await normalize$4(options);
1237
1499
  lodashEs.noop(normalizedOptions);
1238
1500
  const baseURL = await getBaseURL();
1501
+ const cancelWaiting = startWaiting();
1239
1502
  const tokenInfo = await fetchTokenInfo();
1503
+ cancelWaiting();
1240
1504
  const name2 = (_tokenInfo$user = tokenInfo.user) === null || _tokenInfo$user === void 0 ? void 0 : _tokenInfo$user.name;
1241
1505
  const email = (_tokenInfo$user2 = tokenInfo.user) === null || _tokenInfo$user2 === void 0 ? void 0 : _tokenInfo$user2.email;
1242
1506
  if (name2 && email) {
1243
- console.log(`${name2} <${email}>`);
1507
+ console.log(`User: ${name2}`);
1508
+ console.log(`Email: ${email}`);
1244
1509
  console.log(`ONES: ${baseURL}`);
1245
1510
  } else {
1246
1511
  consoleUnauthorizedMessage();
@@ -1259,11 +1524,15 @@ const enable = async function() {
1259
1524
  } = createOnesApp.getCommandOptions(args, enableCommandArguments);
1260
1525
  const normalizedOptions = await normalize$3(options);
1261
1526
  lodashEs.noop(normalizedOptions);
1527
+ const appName = getAppManifestJSON().app.name;
1528
+ const cancelWaiting = startWaiting();
1262
1529
  const result = await fetchAppEnable();
1530
+ cancelWaiting();
1263
1531
  if (result.code === "OK") {
1264
- console.log("App enabled successfully!");
1532
+ console.log(`App "${appName}" enabled successfully!`);
1265
1533
  } else {
1266
- console.error(result);
1534
+ console.log(`App "${appName}" enabled failed!`);
1535
+ console.error(JSON.stringify(result, null, 2));
1267
1536
  }
1268
1537
  };
1269
1538
  const normalize$2 = async (options) => {
@@ -1279,11 +1548,15 @@ const disable = async function() {
1279
1548
  } = createOnesApp.getCommandOptions(args, disableCommandArguments);
1280
1549
  const normalizedOptions = await normalize$2(options);
1281
1550
  lodashEs.noop(normalizedOptions);
1551
+ const appName = getAppManifestJSON().app.name;
1552
+ const cancelWaiting = startWaiting();
1282
1553
  const result = await fetchAppDisable();
1554
+ cancelWaiting();
1283
1555
  if (result.code === "OK") {
1284
- console.log("App disabled successfully!");
1556
+ console.log(`App "${appName}" disabled successfully!`);
1285
1557
  } else {
1286
- console.error(result);
1558
+ console.log(`App "${appName}" disabled failed!`);
1559
+ console.error(JSON.stringify(result, null, 2));
1287
1560
  }
1288
1561
  };
1289
1562
  const normalize$1 = async (options) => {
@@ -1299,17 +1572,40 @@ const uninstall = async function() {
1299
1572
  } = createOnesApp.getCommandOptions(args, uninstallCommandArguments);
1300
1573
  const normalizedOptions = await normalize$1(options);
1301
1574
  lodashEs.noop(normalizedOptions);
1575
+ const appName = getAppManifestJSON().app.name;
1576
+ const cancelWaiting = startWaiting();
1302
1577
  const result = await fetchAppUninstall();
1578
+ cancelWaiting();
1303
1579
  if (result.code === "OK") {
1304
- console.log("App uninstalled successfully!");
1580
+ console.log(`App "${appName}" uninstalled successfully!`);
1305
1581
  } else {
1306
- console.error(result);
1582
+ console.log(`App "${appName}" uninstalled failed!`);
1583
+ console.error(JSON.stringify(result, null, 2));
1307
1584
  }
1308
1585
  };
1586
+ const getTemplatePath = () => {
1587
+ const __dirname = node_path.dirname(node_url.fileURLToPath(typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("index.cjs", document.baseURI).href));
1588
+ return node_path.join(__dirname, "../template");
1589
+ };
1590
+ const getTemplateLegacy = () => {
1591
+ return "legacy";
1592
+ };
1309
1593
  const normalize = async (options) => {
1310
- lodashEs.noop(options);
1311
- return {};
1594
+ const projectPathInput = options.projectPath;
1595
+ if (projectPathInput)
1596
+ ;
1597
+ else {
1598
+ return createOnesApp.throwError(ErrorCode.MISSING_PROJECT_PATH, i18n.t("error.legacy.create.missingProjectPath"));
1599
+ }
1600
+ const projectPath = node_path.resolve(process$1.cwd(), projectPathInput);
1601
+ return {
1602
+ projectPath
1603
+ };
1312
1604
  };
1605
+ const {
1606
+ copy,
1607
+ moveSync
1608
+ } = fse;
1313
1609
  const legacy = async function() {
1314
1610
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1315
1611
  args[_key] = arguments[_key];
@@ -1318,18 +1614,30 @@ const legacy = async function() {
1318
1614
  options
1319
1615
  } = createOnesApp.getCommandOptions(args, legacyCommandArguments);
1320
1616
  const normalizedOptions = await normalize(options);
1321
- console.log("legacy", normalizedOptions);
1617
+ const {
1618
+ projectPath
1619
+ } = normalizedOptions;
1620
+ const templatePath = node_path.join(getTemplatePath(), getTemplateLegacy());
1621
+ await copy(templatePath, projectPath);
1622
+ 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"]];
1623
+ rename.forEach((_ref) => {
1624
+ let [from, to] = _ref;
1625
+ moveSync(node_path.join(projectPath, from), node_path.join(projectPath, to), {
1626
+ overwrite: true
1627
+ });
1628
+ });
1629
+ console.log("Plugin created successfully!");
1322
1630
  };
1323
1631
  const buildCommandArguments = [];
1324
1632
  const $build = new commander.Command("build").description(i18n.t("desc.build")).option("-o, --output [file-path]", i18n.t("desc.build.output")).action(build);
1325
1633
  createOnesApp.addCommandUsage($build);
1326
1634
  createOnesApp.addCommandOutput($build);
1327
1635
  const devCommandArguments = [];
1328
- const $dev = new commander.Command("dev").description(i18n.t("desc.dev")).option("-i, --install [boolean]", i18n.t("desc.dev.install")).action(dev);
1636
+ const $dev = new commander.Command("dev").description(i18n.t("desc.dev")).option("-i, --install [boolean]", i18n.t("desc.dev.install")).option("-c, --command [string]", i18n.t("desc.dev.command")).option("-s, --use-storage [boolean]", i18n.t("desc.dev.useStorage")).action(dev);
1329
1637
  createOnesApp.addCommandUsage($dev);
1330
1638
  createOnesApp.addCommandOutput($dev);
1331
1639
  const tunnelCommandArguments = ["port"];
1332
- const $tunnel = new commander.Command("tunnel").description(i18n.t("desc.tunnel")).argument("<port>", i18n.t("desc.tunnel.port")).action(tunnel);
1640
+ const $tunnel = new commander.Command("tunnel").description(i18n.t("desc.tunnel")).argument("<port>", i18n.t("desc.tunnel.port")).option("-s, --use-storage [boolean]", i18n.t("desc.dev.useStorage")).action(tunnel);
1333
1641
  createOnesApp.addCommandUsage($tunnel);
1334
1642
  createOnesApp.addCommandOutput($tunnel);
1335
1643
  const loginCommandArguments = ["baseURL"];
@@ -1364,12 +1672,20 @@ const $app = new commander.Command("app").description(i18n.t("desc.app"));
1364
1672
  $app.addCommand($install).addCommand($enable).addCommand($disable).addCommand($uninstall);
1365
1673
  createOnesApp.addCommandUsage($app);
1366
1674
  createOnesApp.addCommandOutput($app);
1367
- const legacyCommandArguments = [];
1368
- const $legacy = new commander.Command("legacy").description(i18n.t("desc.legacy")).action(legacy);
1675
+ const legacyCommandArguments = ["projectPath"];
1676
+ const $create = new commander.Command("create").description(i18n.t("desc.legacy.create")).argument("<project-path>", i18n.t("desc.legacy.create.projectPath")).action(legacy);
1677
+ createOnesApp.addCommandUsage($create);
1678
+ createOnesApp.addCommandOutput($create);
1679
+ const $legacy = new commander.Command("legacy").description(i18n.t("desc.legacy"));
1680
+ $legacy.addCommand($create);
1369
1681
  createOnesApp.addCommandUsage($legacy);
1370
1682
  createOnesApp.addCommandOutput($legacy);
1371
1683
  const ones = new commander.Command("ones");
1372
- ones.description(i18n.t("desc.ones")).addCommand(createOnesApp.$create).addCommand($build).addCommand($dev).addCommand($tunnel).addCommand($app).addCommand($login).addCommand($logout).addCommand($whoami).addCommand($legacy).configureHelp({
1684
+ const version = `${getPackageJSON().version}`;
1685
+ const env = `${version} Node/${process.version}`;
1686
+ ones.description(i18n.t("desc.ones", {
1687
+ env
1688
+ })).addCommand(createOnesApp.$create).addCommand($build).addCommand($dev).addCommand($tunnel).addCommand($app).addCommand($login).addCommand($logout).addCommand($whoami).addCommand($legacy).configureHelp({
1373
1689
  visibleCommands: (cmd) => {
1374
1690
  const blackList = ["legacy"];
1375
1691
  return cmd.commands.filter((command) => !_includesInstanceProperty(blackList).call(blackList, command.name()));
@@ -1382,8 +1698,8 @@ createOnesApp.addCommandOutput(ones);
1382
1698
  const runCommandONES = async () => {
1383
1699
  const command = ones;
1384
1700
  createOnesApp.setContext("command", command);
1385
- const version = `${getPackageJSON().version}`;
1386
- command.version(version, "-v, --version");
1701
+ const version2 = `${getPackageJSON().version}`;
1702
+ command.version(version2, "-v, --version");
1387
1703
  await command.parse();
1388
1704
  };
1389
1705
  exports.runCommandONES = runCommandONES;