@dcl/sdk-commands 7.0.0-4217957637.commit-a393ef7

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 (96) hide show
  1. package/LICENSE +201 -0
  2. package/dist/commands/build/index.d.ts +20 -0
  3. package/dist/commands/build/index.js +58 -0
  4. package/dist/commands/export-static/index.d.ts +23 -0
  5. package/dist/commands/export-static/index.js +119 -0
  6. package/dist/commands/init/index.d.ts +18 -0
  7. package/dist/commands/init/index.js +52 -0
  8. package/dist/commands/init/repos.d.ts +9 -0
  9. package/dist/commands/init/repos.js +11 -0
  10. package/dist/commands/start/index.d.ts +30 -0
  11. package/dist/commands/start/index.js +217 -0
  12. package/dist/commands/start/server/endpoints.d.ts +4 -0
  13. package/dist/commands/start/server/endpoints.js +399 -0
  14. package/dist/commands/start/server/file-watch-notifier.d.ts +8 -0
  15. package/dist/commands/start/server/file-watch-notifier.js +44 -0
  16. package/dist/commands/start/server/realm.d.ts +7 -0
  17. package/dist/commands/start/server/realm.js +57 -0
  18. package/dist/commands/start/server/routes.d.ts +2 -0
  19. package/dist/commands/start/server/routes.js +32 -0
  20. package/dist/commands/start/server/ws.d.ts +11 -0
  21. package/dist/commands/start/server/ws.js +19 -0
  22. package/dist/commands/start/types.d.ts +18 -0
  23. package/dist/commands/start/types.js +2 -0
  24. package/dist/components/eth.d.ts +2 -0
  25. package/dist/components/eth.js +5 -0
  26. package/dist/components/fetch.d.ts +5 -0
  27. package/dist/components/fetch.js +33 -0
  28. package/dist/components/fs.d.ts +20 -0
  29. package/dist/components/fs.js +71 -0
  30. package/dist/components/index.d.ts +9 -0
  31. package/dist/components/index.js +14 -0
  32. package/dist/components/log.d.ts +4 -0
  33. package/dist/components/log.js +47 -0
  34. package/dist/index.d.ts +7 -0
  35. package/dist/index.js +67 -0
  36. package/dist/logic/args.d.ts +11 -0
  37. package/dist/logic/args.js +18 -0
  38. package/dist/logic/beautiful-logs.d.ts +5 -0
  39. package/dist/logic/beautiful-logs.js +27 -0
  40. package/dist/logic/catalyst-requests.d.ts +5 -0
  41. package/dist/logic/catalyst-requests.js +23 -0
  42. package/dist/logic/commands.d.ts +3 -0
  43. package/dist/logic/commands.js +23 -0
  44. package/dist/logic/coordinates.d.ts +37 -0
  45. package/dist/logic/coordinates.js +83 -0
  46. package/dist/logic/dcl-ignore.d.ts +8 -0
  47. package/dist/logic/dcl-ignore.js +48 -0
  48. package/dist/logic/error.d.ts +2 -0
  49. package/dist/logic/error.js +6 -0
  50. package/dist/logic/exec.d.ts +8 -0
  51. package/dist/logic/exec.js +26 -0
  52. package/dist/logic/fs.d.ts +24 -0
  53. package/dist/logic/fs.js +41 -0
  54. package/dist/logic/get-free-port.d.ts +1 -0
  55. package/dist/logic/get-free-port.js +20 -0
  56. package/dist/logic/project-files.d.ts +16 -0
  57. package/dist/logic/project-files.js +62 -0
  58. package/dist/logic/project-validations.d.ts +15 -0
  59. package/dist/logic/project-validations.js +56 -0
  60. package/dist/logic/realm.d.ts +2 -0
  61. package/dist/logic/realm.js +30 -0
  62. package/dist/logic/scene-validations.d.ts +13 -0
  63. package/dist/logic/scene-validations.js +64 -0
  64. package/package.json +50 -0
  65. package/src/commands/build/index.ts +68 -0
  66. package/src/commands/export-static/index.ts +142 -0
  67. package/src/commands/init/index.ts +67 -0
  68. package/src/commands/init/repos.ts +17 -0
  69. package/src/commands/start/index.ts +213 -0
  70. package/src/commands/start/server/endpoints.ts +473 -0
  71. package/src/commands/start/server/file-watch-notifier.ts +45 -0
  72. package/src/commands/start/server/realm.ts +63 -0
  73. package/src/commands/start/server/routes.ts +36 -0
  74. package/src/commands/start/server/ws.ts +24 -0
  75. package/src/commands/start/types.ts +26 -0
  76. package/src/components/eth.ts +3 -0
  77. package/src/components/fetch.ts +11 -0
  78. package/src/components/fs.ts +62 -0
  79. package/src/components/index.ts +18 -0
  80. package/src/components/log.ts +48 -0
  81. package/src/index.ts +90 -0
  82. package/src/logic/args.ts +19 -0
  83. package/src/logic/beautiful-logs.ts +26 -0
  84. package/src/logic/catalyst-requests.ts +31 -0
  85. package/src/logic/commands.ts +28 -0
  86. package/src/logic/coordinates.ts +95 -0
  87. package/src/logic/dcl-ignore.ts +49 -0
  88. package/src/logic/error.ts +1 -0
  89. package/src/logic/exec.ts +36 -0
  90. package/src/logic/fs.ts +41 -0
  91. package/src/logic/get-free-port.ts +15 -0
  92. package/src/logic/project-files.ts +76 -0
  93. package/src/logic/project-validations.ts +61 -0
  94. package/src/logic/realm.ts +28 -0
  95. package/src/logic/scene-validations.ts +73 -0
  96. package/tsconfig.json +28 -0
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setupRealmAndComms = void 0;
4
+ const handle_linear_protocol_1 = require("@dcl/mini-comms/dist/logic/handle-linear-protocol");
5
+ const ws_1 = require("@well-known-components/http-server/dist/ws");
6
+ /**
7
+ * This module handles the BFF mock and communications server for the preview mode.
8
+ * It runs using @dcl/mini-comms implementing RFC-5
9
+ */
10
+ function setupRealmAndComms(components, router) {
11
+ router.get('/about', async (ctx) => {
12
+ const host = ctx.url.host;
13
+ const body = {
14
+ acceptingUsers: true,
15
+ bff: { healthy: false, publicUrl: host },
16
+ comms: {
17
+ healthy: true,
18
+ protocol: 'v3',
19
+ fixedAdapter: `ws-room:${ctx.url.protocol.replace(/^http/, 'ws')}//${host}/mini-comms/room-1`
20
+ },
21
+ configurations: {
22
+ networkId: 0,
23
+ globalScenesUrn: [],
24
+ scenesUrn: [],
25
+ realmName: 'LocalPreview'
26
+ },
27
+ content: {
28
+ healthy: true,
29
+ publicUrl: `${ctx.url.protocol}//${ctx.url.host}/content`
30
+ },
31
+ lambdas: {
32
+ healthy: true,
33
+ publicUrl: `${ctx.url.protocol}//${ctx.url.host}/lambdas`
34
+ },
35
+ healthy: true
36
+ };
37
+ return { body };
38
+ });
39
+ router.get('/mini-comms/:roomId', async (ctx) => {
40
+ return (0, ws_1.upgradeWebSocketResponse)((ws) => {
41
+ if (ws.protocol === 'rfc5' || ws.protocol === 'rfc4') {
42
+ ws.on('error', (error) => {
43
+ console.error(error);
44
+ ws.close();
45
+ });
46
+ ws.on('close', () => {
47
+ console.debug('Websocket closed');
48
+ });
49
+ (0, handle_linear_protocol_1.handleSocketLinearProtocol)(components, ws, ctx.params.roomId).catch((err) => {
50
+ console.info(err);
51
+ ws.close();
52
+ });
53
+ }
54
+ });
55
+ });
56
+ }
57
+ exports.setupRealmAndComms = setupRealmAndComms;
@@ -0,0 +1,2 @@
1
+ import { PreviewComponents } from '../types';
2
+ export declare function wireRouter(components: PreviewComponents, dir: string): Promise<void>;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.wireRouter = void 0;
4
+ const realm_1 = require("./realm");
5
+ const http_server_1 = require("@well-known-components/http-server");
6
+ const endpoints_1 = require("./endpoints");
7
+ const ws_1 = require("@well-known-components/http-server/dist/ws");
8
+ async function wireRouter(components, dir) {
9
+ const router = new http_server_1.Router();
10
+ const sceneUpdateClients = new Set();
11
+ router.get('/', async (ctx, next) => {
12
+ if (ctx.request.headers.get('upgrade') === 'websocket') {
13
+ return (0, ws_1.upgradeWebSocketResponse)((ws) => initWsConnection(ws, sceneUpdateClients));
14
+ }
15
+ return next();
16
+ });
17
+ (0, realm_1.setupRealmAndComms)(components, router);
18
+ (0, endpoints_1.setupEcs6Endpoints)(components, dir, router);
19
+ components.server.setContext(components);
20
+ components.server.use(router.allowedMethods());
21
+ components.server.use(router.middleware());
22
+ }
23
+ exports.wireRouter = wireRouter;
24
+ const initWsConnection = (ws, clients) => {
25
+ if (ws.readyState === ws.OPEN) {
26
+ clients.add(ws);
27
+ }
28
+ else {
29
+ ws.on('open', () => clients.add(ws));
30
+ }
31
+ ws.on('close', () => clients.delete(ws));
32
+ };
@@ -0,0 +1,11 @@
1
+ import { WebSocketServer } from 'ws';
2
+ import { PreviewComponents } from '../types';
3
+ import { IBaseComponent } from '@well-known-components/interfaces';
4
+ export type WebSocketComponent = IBaseComponent & {
5
+ ws: WebSocketServer;
6
+ };
7
+ /**
8
+ * Creates a ws-server component
9
+ * @public
10
+ */
11
+ export declare function createWsComponent(_: Pick<PreviewComponents, 'logs'>): Promise<WebSocketComponent>;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createWsComponent = void 0;
4
+ const ws_1 = require("ws");
5
+ /**
6
+ * Creates a ws-server component
7
+ * @public
8
+ */
9
+ async function createWsComponent(_) {
10
+ const ws = new ws_1.WebSocketServer({ noServer: true });
11
+ async function stop() {
12
+ ws.close();
13
+ }
14
+ return {
15
+ stop,
16
+ ws
17
+ };
18
+ }
19
+ exports.createWsComponent = createWsComponent;
@@ -0,0 +1,18 @@
1
+ import { ILoggerComponent, IMetricsComponent, IHttpServerComponent, IConfigComponent } from '@well-known-components/interfaces';
2
+ import { HTTPProvider } from 'eth-connect';
3
+ import { RoomComponent } from '@dcl/mini-comms/dist/adapters/rooms';
4
+ import { WebSocketComponent } from './server/ws';
5
+ import { CliComponents } from '../../components';
6
+ export type PreviewComponents = CliComponents & {
7
+ logs: ILoggerComponent;
8
+ server: IHttpServerComponent<PreviewComponents>;
9
+ config: IConfigComponent;
10
+ metrics: IMetricsComponent<any>;
11
+ ethereumProvider: HTTPProvider;
12
+ rooms: RoomComponent;
13
+ ws: WebSocketComponent;
14
+ signaler: ISignalerComponent;
15
+ };
16
+ export type ISignalerComponent = {
17
+ programClosed: Promise<void>;
18
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ import { HTTPProvider } from 'eth-connect';
2
+ export declare const providerInstance: HTTPProvider;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.providerInstance = void 0;
4
+ const eth_connect_1 = require("eth-connect");
5
+ exports.providerInstance = new eth_connect_1.HTTPProvider('https://rpc.decentraland.org/mainnet?project=sdk-commands');
@@ -0,0 +1,5 @@
1
+ import * as undici from 'undici';
2
+ export type IFetchComponent = {
3
+ fetch(url: string, init?: undici.RequestInit): Promise<undici.Response>;
4
+ };
5
+ export declare function createFetchComponent(): IFetchComponent;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.createFetchComponent = void 0;
27
+ const undici = __importStar(require("undici"));
28
+ function createFetchComponent() {
29
+ return {
30
+ fetch: undici.fetch
31
+ };
32
+ }
33
+ exports.createFetchComponent = createFetchComponent;
@@ -0,0 +1,20 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import * as fs from 'fs';
4
+ import * as fsPromises from 'fs/promises';
5
+ /**
6
+ * @public
7
+ *
8
+ * This may be moved to well-known-components in the future
9
+ */
10
+ export type IFileSystemComponent = Pick<typeof fs, 'createReadStream'> & Pick<typeof fs, 'createWriteStream'> & Pick<typeof fsPromises, 'access' | 'opendir' | 'stat' | 'unlink' | 'mkdir' | 'readFile' | 'writeFile' | 'rename' | 'rmdir'> & {
11
+ constants: Pick<typeof fs.constants, 'F_OK' | 'R_OK'>;
12
+ } & {
13
+ fileExists(path: string): Promise<boolean>;
14
+ directoryExists(path: string): Promise<boolean>;
15
+ readdir(path: string): Promise<string[]>;
16
+ };
17
+ /**
18
+ * @public
19
+ */
20
+ export declare function createFsComponent(): IFileSystemComponent;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.createFsComponent = void 0;
27
+ const fs = __importStar(require("fs"));
28
+ const fsPromises = __importStar(require("fs/promises"));
29
+ async function fileExists(path) {
30
+ try {
31
+ await fs.promises.access(path, fs.constants.F_OK | fs.constants.R_OK);
32
+ return true;
33
+ }
34
+ catch (error) {
35
+ return false;
36
+ }
37
+ }
38
+ async function directoryExists(path) {
39
+ try {
40
+ return (await fs.promises.lstat(path)).isDirectory();
41
+ }
42
+ catch (error) {
43
+ return false;
44
+ }
45
+ }
46
+ /**
47
+ * @public
48
+ */
49
+ function createFsComponent() {
50
+ return {
51
+ createReadStream: fs.createReadStream,
52
+ createWriteStream: fs.createWriteStream,
53
+ access: fsPromises.access,
54
+ writeFile: fsPromises.writeFile,
55
+ opendir: fsPromises.opendir,
56
+ stat: fsPromises.stat,
57
+ unlink: fsPromises.unlink,
58
+ mkdir: fsPromises.mkdir,
59
+ rmdir: fsPromises.rmdir,
60
+ readdir: fsPromises.readdir,
61
+ readFile: fsPromises.readFile,
62
+ constants: {
63
+ F_OK: fs.constants.F_OK,
64
+ R_OK: fs.constants.R_OK
65
+ },
66
+ rename: fsPromises.rename,
67
+ fileExists,
68
+ directoryExists
69
+ };
70
+ }
71
+ exports.createFsComponent = createFsComponent;
@@ -0,0 +1,9 @@
1
+ import { ILoggerComponent } from '@well-known-components/interfaces';
2
+ import { IFetchComponent } from './fetch';
3
+ import { IFileSystemComponent } from './fs';
4
+ export type CliComponents = {
5
+ fs: IFileSystemComponent;
6
+ fetch: IFetchComponent;
7
+ logger: ILoggerComponent.ILogger;
8
+ };
9
+ export declare function initComponents(): CliComponents;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initComponents = void 0;
4
+ const fetch_1 = require("./fetch");
5
+ const fs_1 = require("./fs");
6
+ const log_1 = require("./log");
7
+ function initComponents() {
8
+ return {
9
+ fs: (0, fs_1.createFsComponent)(),
10
+ fetch: (0, fetch_1.createFetchComponent)(),
11
+ logger: (0, log_1.createStdoutCliLogger)()
12
+ };
13
+ }
14
+ exports.initComponents = initComponents;
@@ -0,0 +1,4 @@
1
+ /// <reference types="colorette" />
2
+ import { ILoggerComponent } from '@well-known-components/interfaces';
3
+ export declare const colors: import("colorette").Colorette;
4
+ export declare function createStdoutCliLogger(): ILoggerComponent.ILogger;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createStdoutCliLogger = exports.colors = void 0;
4
+ const colorette_1 = require("colorette");
5
+ const error_1 = require("../logic/error");
6
+ /**
7
+ * This file imitates "cargo" logs. The words are aligned with the colon like this:
8
+ * V
9
+ * Error: some text provided as argumen
10
+ * Info: some text provided as argumen
11
+ * Success: some text provided as argumen
12
+ * Warning: some text provided as argumen
13
+ * ^
14
+ */
15
+ const stderr = (...parameters) => {
16
+ process.stderr.write(`${parameters.filter(($) => $ !== undefined).join('')}\n`);
17
+ };
18
+ // @see https://no-color.org
19
+ // @see https://www.npmjs.com/package/chalk
20
+ exports.colors = (0, colorette_1.createColors)({
21
+ useColor: process.env.FORCE_COLOR !== '0' && !process.env.NO_COLOR
22
+ });
23
+ function createStdoutCliLogger() {
24
+ return {
25
+ log(message, extra) {
26
+ stderr(message, extra && JSON.stringify(extra));
27
+ },
28
+ debug(message, extra) {
29
+ stderr(exports.colors.blueBright('debug: '), message, extra && JSON.stringify(extra));
30
+ },
31
+ error(error, extra) {
32
+ stderr(exports.colors.redBright('error: '), error, extra && JSON.stringify(extra));
33
+ /* istanbul ignore next */
34
+ if (!(error instanceof error_1.CliError) || process.env.DEBUG) {
35
+ // print the stacktrace if it is not a CliError
36
+ console.error(error);
37
+ }
38
+ },
39
+ info(message, extra) {
40
+ stderr(exports.colors.blueBright('info: '), message, extra && JSON.stringify(extra));
41
+ },
42
+ warn(message, extra) {
43
+ stderr(exports.colors.yellow('warning: '), message, extra && JSON.stringify(extra));
44
+ }
45
+ };
46
+ }
47
+ exports.createStdoutCliLogger = createStdoutCliLogger;
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ import { getArgs } from './logic/args';
3
+ import { CliComponents } from './components';
4
+ export interface Options {
5
+ args: ReturnType<typeof getArgs>;
6
+ components: CliComponents;
7
+ }
package/dist/index.js ADDED
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /* istanbul ignore file */
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ const args_1 = require("./logic/args");
6
+ const error_1 = require("./logic/error");
7
+ const commands_1 = require("./logic/commands");
8
+ const components_1 = require("./components");
9
+ const beautiful_logs_1 = require("./logic/beautiful-logs");
10
+ const log_1 = require("./components/log");
11
+ const listCommandsStr = (commands) => commands.map(($) => `\t *sdk-commands ${$} \n`).join('');
12
+ const commandFnsAreValid = (fns) => {
13
+ const { help, main } = fns;
14
+ if (!help || !main) {
15
+ throw new error_1.CliError(`Command does not follow implementation rules:
16
+ * Requires a "help" function
17
+ * Requires a "main" function
18
+ `);
19
+ }
20
+ return true;
21
+ };
22
+ async function main() {
23
+ const helpMessage = (commands) => `Here is the list of commands:\n${listCommandsStr(commands)}`;
24
+ const args = (0, args_1.getArgs)();
25
+ const command = process.argv[2];
26
+ const needsHelp = args['--help'];
27
+ const components = (0, components_1.initComponents)();
28
+ const commands = await (0, commands_1.getCommands)(components);
29
+ if (!commands.includes(command)) {
30
+ if (needsHelp) {
31
+ components.logger.info(helpMessage(commands));
32
+ return;
33
+ }
34
+ throw new error_1.CliError(`Command ${command} is invalid. ${helpMessage(commands)}`);
35
+ }
36
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
37
+ const cmd = require(`${commands_1.COMMANDS_PATH}/${command}`);
38
+ if (commandFnsAreValid(cmd)) {
39
+ const options = { args: cmd.args, components };
40
+ if (needsHelp) {
41
+ await cmd.help(options);
42
+ }
43
+ else {
44
+ (0, beautiful_logs_1.printCommand)(components.logger, command);
45
+ const ret = await cmd.main(options);
46
+ // print the result of the evaluation as json in the standard output
47
+ if (cmd.args['--json']) {
48
+ process.stdout.write(JSON.stringify(ret, null, 2));
49
+ }
50
+ }
51
+ }
52
+ // rollup watcher leaves many open FSWatcher even in build mode. we must call
53
+ // process.exit at this point to prevent the program halting forever
54
+ process.exit(process.exitCode || 0);
55
+ }
56
+ main().catch(function handleError(err) {
57
+ if (err instanceof error_1.CliError) {
58
+ console.error(log_1.colors.redBright('Error: ') + err.message);
59
+ }
60
+ else {
61
+ // log with console to show stacktrace and debug information
62
+ console.error(err);
63
+ console.warn(`Developer: All errors thrown must be an instance of "CliError"`);
64
+ }
65
+ // set an exit code but not finish the program immediately to close any pending work
66
+ process.exitCode = 1;
67
+ });
@@ -0,0 +1,11 @@
1
+ import { Result } from 'arg';
2
+ export type Args = {
3
+ [key: string]: string | StringConstructor | NumberConstructor | BooleanConstructor;
4
+ };
5
+ export declare const DEFAULT_ARGS: {
6
+ '--help': BooleanConstructor;
7
+ '--json': BooleanConstructor;
8
+ '-h': string;
9
+ };
10
+ export declare function getArgs(): Result<typeof DEFAULT_ARGS>;
11
+ export declare function getArgs<T extends Args>(args: T): Result<typeof DEFAULT_ARGS & T>;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getArgs = exports.DEFAULT_ARGS = void 0;
7
+ const arg_1 = __importDefault(require("arg"));
8
+ // updating to TS 4.9 will prevent losing types when
9
+ // enforcing type to be "Args" by using "satisfies Args"
10
+ exports.DEFAULT_ARGS = {
11
+ '--help': Boolean,
12
+ '--json': Boolean,
13
+ '-h': '--help'
14
+ };
15
+ function getArgs(args) {
16
+ return (0, arg_1.default)({ ...exports.DEFAULT_ARGS, ...args }, { permissive: true });
17
+ }
18
+ exports.getArgs = getArgs;
@@ -0,0 +1,5 @@
1
+ import { ILoggerComponent } from '@well-known-components/interfaces';
2
+ export declare function printProgressStep(logger: ILoggerComponent.ILogger, log: string, currentStep: number, maxStep: number): void;
3
+ export declare function printProgressInfo(logger: ILoggerComponent.ILogger, log: string): void;
4
+ export declare function printCommand(logger: ILoggerComponent.ILogger, commandName: string): void;
5
+ export declare function printSuccess(logger: ILoggerComponent.ILogger, operationSuccessfulMessage: string, summary: string): void;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.printSuccess = exports.printCommand = exports.printProgressInfo = exports.printProgressStep = void 0;
4
+ const log_1 = require("../components/log");
5
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
6
+ const { name, version } = require('../../package.json');
7
+ function printProgressStep(logger, log, currentStep, maxStep) {
8
+ logger.log(log_1.colors.dim(`[${currentStep}/${maxStep}]`) + ' ' + log);
9
+ }
10
+ exports.printProgressStep = printProgressStep;
11
+ function printProgressInfo(logger, log) {
12
+ logger.log(log_1.colors.dim(log));
13
+ }
14
+ exports.printProgressInfo = printProgressInfo;
15
+ function printCommand(logger, commandName) {
16
+ logger.log(log_1.colors.bold(`${name} ${commandName} v${version}`));
17
+ }
18
+ exports.printCommand = printCommand;
19
+ function printSuccess(logger, operationSuccessfulMessage, summary) {
20
+ // print a space before the success callout
21
+ logger.log('');
22
+ logger.log(log_1.colors.greenBright(operationSuccessfulMessage));
23
+ if (typeof summary === 'string') {
24
+ logger.log(summary);
25
+ }
26
+ }
27
+ exports.printSuccess = printSuccess;
@@ -0,0 +1,5 @@
1
+ import { Entity } from '@dcl/schemas';
2
+ export declare function fetchEntityByPointer(baseUrl: string, pointers: string[]): Promise<{
3
+ baseUrl: string;
4
+ deployments: Entity[];
5
+ }>;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchEntityByPointer = void 0;
4
+ const undici_1 = require("undici");
5
+ async function fetchEntityByPointer(baseUrl, pointers) {
6
+ if (pointers.length === 0)
7
+ return {
8
+ baseUrl,
9
+ deployments: []
10
+ };
11
+ const activeEntities = baseUrl + '/content/entities/active';
12
+ const response = await (0, undici_1.fetch)(activeEntities, {
13
+ method: 'post',
14
+ headers: { 'content-type': 'application/json', connection: 'close' },
15
+ body: JSON.stringify({ pointers })
16
+ });
17
+ const deployments = response.ok ? (await response.json()) : [];
18
+ return {
19
+ baseUrl,
20
+ deployments
21
+ };
22
+ }
23
+ exports.fetchEntityByPointer = fetchEntityByPointer;
@@ -0,0 +1,3 @@
1
+ import { CliComponents } from '../components';
2
+ export declare const COMMANDS_PATH: string;
3
+ export declare function getCommands({ fs }: Pick<CliComponents, 'fs'>): Promise<string[]>;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCommands = exports.COMMANDS_PATH = void 0;
4
+ const path_1 = require("path");
5
+ const error_1 = require("./error");
6
+ exports.COMMANDS_PATH = (0, path_1.resolve)(__dirname, '../commands');
7
+ async function getCommands({ fs }) {
8
+ const commandDirs = await fs.readdir(exports.COMMANDS_PATH);
9
+ const commands = commandDirs.map(async (dir) => {
10
+ const path = (0, path_1.resolve)(exports.COMMANDS_PATH, dir);
11
+ const statDir = await fs.stat(path);
12
+ if (!statDir.isDirectory()) {
13
+ throw new error_1.CliError('Developer: All commands must be inside a folder');
14
+ }
15
+ const statIndex = await fs.stat(`${path}/index.js`);
16
+ if (!statIndex.isFile()) {
17
+ throw new error_1.CliError('Developer: All commands must have an "index.js" file inside');
18
+ }
19
+ return dir;
20
+ });
21
+ return Promise.all(commands);
22
+ }
23
+ exports.getCommands = getCommands;
@@ -0,0 +1,37 @@
1
+ export interface IBounds {
2
+ minX: number;
3
+ minY: number;
4
+ maxX: number;
5
+ maxY: number;
6
+ }
7
+ export type Coords = {
8
+ x: number;
9
+ y: number;
10
+ };
11
+ /**
12
+ * Returns metaverse coordinates bounds.
13
+ * TODO: use functions from @dcl/schemas
14
+ */
15
+ export declare function getBounds(): IBounds;
16
+ /**
17
+ * Parses a string-based set of coordinates.
18
+ * - All spaces are removed
19
+ * - Leading zeroes are removed
20
+ * - `-0` is converted to `0`
21
+ * @param coordinates An string containing coordinates in the `x,y; x,y; ...` format
22
+ */
23
+ export declare function parse(coordinates: string): string[];
24
+ /**
25
+ * Converts a string-based set of coordinates to an object
26
+ * @param coords A string containing a set of coordinates
27
+ */
28
+ export declare function getObject(coords: string): Coords;
29
+ /**
30
+ * Returns true if the given coordinates are in metaverse bounds
31
+ */
32
+ export declare function inBounds(x: number, y: number): boolean;
33
+ /**
34
+ * Returns true if the given parcels array are connected
35
+ */
36
+ export declare function areConnected(parcels: Coords[]): boolean;
37
+ export declare function isEqual(p1: Coords, p2: Coords): boolean;