@dcl/sdk-commands 7.1.4-4544067675.commit-d749052 → 7.1.4-4544451404.commit-3e8cb7c

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 (55) hide show
  1. package/.dclrc +19 -0
  2. package/dist/commands/build/index.d.ts +3 -1
  3. package/dist/commands/build/index.js +13 -20
  4. package/dist/commands/deploy/index.js +4 -4
  5. package/dist/commands/deploy/linker-dapp/api.d.ts +1 -1
  6. package/dist/commands/deploy/linker-dapp/api.js +14 -17
  7. package/dist/commands/deploy/linker-dapp/routes.d.ts +1 -1
  8. package/dist/commands/deploy/linker-dapp/routes.js +2 -2
  9. package/dist/commands/export-static/index.d.ts +1 -1
  10. package/dist/commands/export-static/index.js +2 -2
  11. package/dist/commands/init/index.d.ts +1 -1
  12. package/dist/commands/init/index.js +1 -1
  13. package/dist/commands/start/data-layer/fs.d.ts +2 -1
  14. package/dist/commands/start/data-layer/fs.js +17 -15
  15. package/dist/commands/start/data-layer/rpc.d.ts +1 -1
  16. package/dist/commands/start/data-layer/rpc.js +3 -4
  17. package/dist/commands/start/data-layer/ws.js +1 -1
  18. package/dist/commands/start/index.d.ts +1 -1
  19. package/dist/commands/start/index.js +6 -14
  20. package/dist/commands/start/server/endpoints.d.ts +1 -1
  21. package/dist/commands/start/server/endpoints.js +7 -11
  22. package/dist/commands/start/server/routes.js +1 -1
  23. package/dist/commands/start/types.d.ts +1 -3
  24. package/dist/components/analytics.d.ts +6 -5
  25. package/dist/components/analytics.js +46 -51
  26. package/dist/components/config.d.ts +18 -0
  27. package/dist/components/config.js +56 -0
  28. package/dist/components/exit-signal.d.ts +5 -0
  29. package/dist/components/exit-signal.js +21 -0
  30. package/dist/components/fs.d.ts +1 -1
  31. package/dist/components/fs.js +1 -0
  32. package/dist/components/index.d.ts +4 -3
  33. package/dist/components/index.js +10 -6
  34. package/dist/index.js +1 -2
  35. package/dist/logic/bundle.d.ts +51 -0
  36. package/dist/logic/bundle.js +120 -0
  37. package/dist/logic/catalyst-requests.d.ts +16 -1
  38. package/dist/logic/catalyst-requests.js +28 -4
  39. package/dist/logic/config.d.ts +15 -7
  40. package/dist/logic/config.js +54 -28
  41. package/dist/logic/exec.d.ts +6 -1
  42. package/dist/logic/exec.js +25 -22
  43. package/dist/logic/fs.d.ts +1 -7
  44. package/dist/logic/fs.js +3 -22
  45. package/dist/logic/project-validations.d.ts +2 -2
  46. package/dist/logic/project-validations.js +4 -5
  47. package/dist/logic/realm.d.ts +2 -1
  48. package/dist/logic/realm.js +6 -4
  49. package/package.json +9 -5
  50. package/dist/commands/deploy/linker-dapp/catalyst-pointers.d.ts +0 -20
  51. package/dist/commands/deploy/linker-dapp/catalyst-pointers.js +0 -45
  52. package/dist/components/dcl-info-config.d.ts +0 -11
  53. package/dist/components/dcl-info-config.js +0 -79
  54. package/dist/logic/dcl-info.d.ts +0 -27
  55. package/dist/logic/dcl-info.js +0 -90
@@ -3,41 +3,67 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.removeEmptyKeys = exports.getEnvConfig = exports.getDCLInfoConfig = exports.getDclInfoPath = void 0;
6
+ exports.getEstateRegistry = exports.getLandRegistry = exports.getSegmentKey = exports.getCatalystBaseUrl = exports.isCI = exports.isEditor = exports.getInstalledPackageVersion = exports.getSdkCommandsVersion = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
- /* istanbul ignore next */
9
- const getDclInfoPath = () => path_1.default.resolve(process.env[process.platform === 'win32' ? 'USERPROFILE' : 'HOME'] ?? '', '.dclinfo');
10
- exports.getDclInfoPath = getDclInfoPath;
8
+ const config_1 = require("../components/config");
9
+ const fs_1 = require("./fs");
10
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
11
+ const { version: sdkCommandsVersion } = require('../../package.json');
12
+ /**
13
+ * Returns the version of the sdk-commands that is running
14
+ */
15
+ async function getSdkCommandsVersion() {
16
+ return sdkCommandsVersion;
17
+ }
18
+ exports.getSdkCommandsVersion = getSdkCommandsVersion;
11
19
  /**
12
- * Reads the contents of the `.dclinfo` file
20
+ * Returns the installed version of a certain package in the current working directory.
21
+ * Returns "unknown" if the package is not installed.
13
22
  */
14
- async function getDCLInfoConfig(components) {
23
+ async function getInstalledPackageVersion(components, packageName, workingDirectory) {
15
24
  try {
16
- const content = await components.fs.readFile((0, exports.getDclInfoPath)(), 'utf8');
17
- return JSON.parse(content);
25
+ const sdkPath = path_1.default.dirname(require.resolve(`${packageName}/package.json`, {
26
+ paths: [workingDirectory]
27
+ }));
28
+ const packageJson = await (0, fs_1.readJson)(components, path_1.default.resolve(sdkPath, 'package.json'));
29
+ return packageJson.version ?? /* istanbul ignore next */ 'unknown';
18
30
  }
19
31
  catch (e) {
20
- return {};
32
+ return 'unknown';
21
33
  }
22
34
  }
23
- exports.getDCLInfoConfig = getDCLInfoConfig;
35
+ exports.getInstalledPackageVersion = getInstalledPackageVersion;
24
36
  /**
25
- * Config that can be override via ENV variables
37
+ * Returns true if the Decentraland Editor is running.
38
+ * TODO: EDITOR is a unix reserved env var. Change it for something more specific.
26
39
  */
27
- function getEnvConfig() {
28
- const { SEGMENT_KEY, TRACK_STATS } = process.env;
29
- const envConfig = {
30
- segmentKey: SEGMENT_KEY,
31
- trackStats: TRACK_STATS !== undefined ? TRACK_STATS === 'true' : undefined
32
- };
33
- return removeEmptyKeys(envConfig);
34
- }
35
- exports.getEnvConfig = getEnvConfig;
36
- function removeEmptyKeys(obj) {
37
- const result = {};
38
- Object.keys(obj)
39
- .filter((k) => !!obj[k])
40
- .forEach((k) => (result[k] = obj[k]));
41
- return result;
42
- }
43
- exports.removeEmptyKeys = removeEmptyKeys;
40
+ function isEditor() {
41
+ return process.env.EDITOR === 'true';
42
+ }
43
+ exports.isEditor = isEditor;
44
+ function isCI() {
45
+ return process.env.CI === 'true' || process.argv.includes('--ci') || process.argv.includes('--c');
46
+ }
47
+ exports.isCI = isCI;
48
+ async function getCatalystBaseUrl(components) {
49
+ const url = (await (0, config_1.readStringConfig)(components, 'DCL_CATALYST')) ?? 'https://peer.decentraland.org';
50
+ return url.replace(/\/$/, '');
51
+ }
52
+ exports.getCatalystBaseUrl = getCatalystBaseUrl;
53
+ function getSegmentKey() {
54
+ const isProduction = !process.env.DEVELOPER_MODE;
55
+ return isProduction
56
+ ? /* istanbul ignore next */ 'sFdziRVDJo0taOnGzTZwafEL9nLIANZ3'
57
+ : 'mjCV5Dc4VAKXLJAH5g7LyHyW1jrIR3to';
58
+ }
59
+ exports.getSegmentKey = getSegmentKey;
60
+ /* istanbul ignore next */
61
+ async function getLandRegistry(components) {
62
+ return (0, config_1.requireStringConfig)(components, 'DCL_LAND_REGISTRY_ADDRESS');
63
+ }
64
+ exports.getLandRegistry = getLandRegistry;
65
+ /* istanbul ignore next */
66
+ async function getEstateRegistry(components) {
67
+ return (0, config_1.requireStringConfig)(components, 'DCL_ESTATE_REGISTRY_ADDRESS');
68
+ }
69
+ exports.getEstateRegistry = getEstateRegistry;
@@ -1,8 +1,13 @@
1
+ /// <reference types="node" />
2
+ import type { spawn } from 'child_process';
1
3
  interface Options {
2
4
  env: {
3
5
  [key: string]: string;
4
6
  };
5
7
  silent: boolean;
6
8
  }
7
- export declare function exec(cwd: string, command: string, args: string[], { env, silent }?: Partial<Options>): Promise<void>;
9
+ export type IProcessSpawnerComponent = {
10
+ exec(cwd: string, command: string, args: string[], options?: Partial<Options>): Promise<void>;
11
+ };
12
+ export declare function createProcessSpawnerComponent(spawnFn: typeof spawn): IProcessSpawnerComponent;
8
13
  export {};
@@ -1,26 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.exec = void 0;
4
- const child_process_1 = require("child_process");
5
- function exec(cwd, command, args, { env, silent } = {}) {
6
- return new Promise((resolve, reject) => {
7
- const child = (0, child_process_1.spawn)(command, args, {
8
- shell: true,
9
- cwd,
10
- env: { ...process.env, NODE_ENV: '', ...env }
11
- });
12
- if (!silent) {
13
- child.stdout.pipe(process.stdout);
14
- child.stderr.pipe(process.stderr);
3
+ exports.createProcessSpawnerComponent = void 0;
4
+ function createProcessSpawnerComponent(spawnFn) {
5
+ return {
6
+ exec(cwd, command, args, { env, silent } = {}) {
7
+ return new Promise((resolve, reject) => {
8
+ const child = spawnFn(command, args, {
9
+ shell: true,
10
+ cwd,
11
+ env: { ...process.env, NODE_ENV: '', ...env }
12
+ });
13
+ if (!silent) {
14
+ child.stdout.pipe(process.stdout);
15
+ child.stderr.pipe(process.stderr);
16
+ }
17
+ child.on('close', (code) => {
18
+ if (code !== 0) {
19
+ const _ = `${command} ${args.join(' ')}`;
20
+ reject(new Error(`Command "${_}" exited with code ${code}. Please try running the command manually`));
21
+ return;
22
+ }
23
+ resolve(undefined);
24
+ });
25
+ });
15
26
  }
16
- child.on('close', (code) => {
17
- if (code !== 0) {
18
- const _ = `${command} ${args.join(' ')}`;
19
- reject(new Error(`Command "${_}" exited with code ${code}. Please try running the command manually`));
20
- return;
21
- }
22
- resolve(undefined);
23
- });
24
- });
27
+ };
25
28
  }
26
- exports.exec = exec;
29
+ exports.createProcessSpawnerComponent = createProcessSpawnerComponent;
@@ -27,10 +27,4 @@ export declare function extract(path: string, dest: string): Promise<string>;
27
27
  * Reads a file and parses it's JSON content
28
28
  * @param path The path to the subject json file
29
29
  */
30
- export declare function readJSON<T>(components: Pick<CliComponents, 'fs'>, path: string): Promise<T>;
31
- /**
32
- * Merges the provided content with a json file
33
- * @param path The path to the subject json file
34
- * @param content The content to be applied (as a plain object)
35
- */
36
- export declare function writeJSON<T = unknown>(components: Pick<CliComponents, 'fs'>, path: string, content: Partial<T>): Promise<Partial<T>>;
30
+ export declare function readJson<T>(components: Pick<CliComponents, 'fs'>, path: string): Promise<T>;
package/dist/logic/fs.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.writeJSON = exports.readJSON = exports.extract = exports.download = exports.isDirectoryEmpty = void 0;
6
+ exports.readJson = exports.extract = exports.download = exports.isDirectoryEmpty = void 0;
7
7
  const extract_zip_1 = __importDefault(require("extract-zip"));
8
8
  const path_1 = require("path");
9
9
  /**
@@ -43,27 +43,8 @@ exports.extract = extract;
43
43
  * Reads a file and parses it's JSON content
44
44
  * @param path The path to the subject json file
45
45
  */
46
- async function readJSON(components, path) {
46
+ async function readJson(components, path) {
47
47
  const content = await components.fs.readFile(path, 'utf-8');
48
48
  return JSON.parse(content);
49
49
  }
50
- exports.readJSON = readJSON;
51
- /**
52
- * Merges the provided content with a json file
53
- * @param path The path to the subject json file
54
- * @param content The content to be applied (as a plain object)
55
- */
56
- async function writeJSON(components, path, content) {
57
- let currentFile;
58
- try {
59
- currentFile = await readJSON(components, path);
60
- }
61
- catch (e) {
62
- currentFile = {};
63
- }
64
- const newJson = { ...currentFile, ...content };
65
- const strContent = JSON.stringify(newJson, null, 2);
66
- await components.fs.writeFile(path, strContent);
67
- return newJson;
68
- }
69
- exports.writeJSON = writeJSON;
50
+ exports.readJson = readJson;
@@ -8,8 +8,8 @@ export declare function assertValidProjectFolder(components: Pick<CliComponents,
8
8
  }>;
9
9
  export declare function needsDependencies(components: Pick<CliComponents, 'fs'>, dir: string): Promise<boolean>;
10
10
  export declare const npm: string;
11
- export declare function installDependencies(components: Pick<CliComponents, 'logger'>, directory: string): Promise<void>;
11
+ export declare function installDependencies(components: Pick<CliComponents, 'logger' | 'spawner'>, directory: string): Promise<void>;
12
12
  /**
13
13
  * Run NPM commands
14
14
  */
15
- export declare function npmRun(cwd: string, command: string, ...args: string[]): Promise<void>;
15
+ export declare function npmRun(components: Pick<CliComponents, 'spawner'>, cwd: string, command: string, ...args: string[]): Promise<void>;
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.npmRun = exports.installDependencies = exports.npm = exports.needsDependencies = exports.assertValidProjectFolder = void 0;
4
4
  const path_1 = require("path");
5
5
  const error_1 = require("./error");
6
- const exec_1 = require("./exec");
7
6
  const scene_validations_1 = require("./scene-validations");
8
7
  /**
9
8
  * Asserts that the projectRoot is a valid project
@@ -42,15 +41,15 @@ exports.npm = /^win/.test(process.platform) ? 'npm.cmd' : 'npm';
42
41
  async function installDependencies(components, directory) {
43
42
  components.logger.info('Installing dependencies...');
44
43
  // TODO: test in windows
45
- await (0, exec_1.exec)(directory, exports.npm, ['install']);
46
- components.logger.log('Installing dependencies... ✅');
44
+ await components.spawner.exec(directory, exports.npm, ['install']);
45
+ components.logger.info('Installing dependencies... ✅');
47
46
  }
48
47
  exports.installDependencies = installDependencies;
49
48
  /**
50
49
  * Run NPM commands
51
50
  */
52
- async function npmRun(cwd, command, ...args) {
51
+ async function npmRun(components, cwd, command, ...args) {
53
52
  // TODO: test in windows
54
- await (0, exec_1.exec)(cwd, exports.npm, ['run', command, '--silent', '--', ...args], { env: process.env });
53
+ await components.spawner.exec(cwd, exports.npm, ['run', command, '--silent', '--', ...args], { env: process.env });
55
54
  }
56
55
  exports.npmRun = npmRun;
@@ -1,2 +1,3 @@
1
1
  import { AboutResponse } from '@dcl/protocol/out-js/decentraland/bff/http_endpoints.gen';
2
- export declare function createStaticRealm(): AboutResponse;
2
+ import { CliComponents } from '../components';
3
+ export declare function createStaticRealm(components: Pick<CliComponents, 'config'>): Promise<AboutResponse>;
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createStaticRealm = void 0;
4
- function createStaticRealm() {
4
+ const config_1 = require("./config");
5
+ async function createStaticRealm(components) {
6
+ const catalystUrl = await (0, config_1.getCatalystBaseUrl)(components);
5
7
  return {
6
8
  acceptingUsers: true,
7
- bff: { healthy: false, publicUrl: `https://peer.decentraland.org/bff` },
9
+ bff: { healthy: false, publicUrl: `${catalystUrl}/bff` },
8
10
  comms: {
9
11
  healthy: true,
10
12
  protocol: 'v3',
@@ -18,11 +20,11 @@ function createStaticRealm() {
18
20
  },
19
21
  content: {
20
22
  healthy: true,
21
- publicUrl: `https://peer.decentraland.org/content`
23
+ publicUrl: `${catalystUrl}/content`
22
24
  },
23
25
  lambdas: {
24
26
  healthy: true,
25
- publicUrl: `https://peer.decentraland.org/lambdas`
27
+ publicUrl: `${catalystUrl}/lambdas`
26
28
  },
27
29
  healthy: true
28
30
  };
package/package.json CHANGED
@@ -1,15 +1,14 @@
1
1
  {
2
2
  "name": "@dcl/sdk-commands",
3
3
  "description": "",
4
- "version": "7.1.4-4544067675.commit-d749052",
4
+ "version": "7.1.4-4544451404.commit-3e8cb7c",
5
5
  "author": "Decentraland",
6
6
  "bin": {
7
7
  "sdk-commands": "./dist/index.js"
8
8
  },
9
9
  "dependencies": {
10
- "@dcl/dcl-rollup": "7.1.4-4544067675.commit-d749052",
11
10
  "@dcl/hashing": "1.1.3",
12
- "@dcl/inspector": "7.1.4-4544067675.commit-d749052",
11
+ "@dcl/inspector": "7.1.4-4544451404.commit-3e8cb7c",
13
12
  "@dcl/linker-dapp": "0.7.0",
14
13
  "@dcl/mini-comms": "1.0.1-20230216163137.commit-a4c75be",
15
14
  "@dcl/protocol": "1.0.0-4493564897.commit-c858f8a",
@@ -24,11 +23,15 @@
24
23
  "chokidar": "^3.5.3",
25
24
  "colorette": "^2.0.19",
26
25
  "dcl-catalyst-client": "^14.0.9",
26
+ "esbuild": "^0.17.12",
27
27
  "extract-zip": "2.0.1",
28
+ "fp-future": "^1.0.1",
29
+ "glob": "^9.3.2",
28
30
  "ignore": "^5.2.4",
29
31
  "node-fetch": "^2.6.8",
30
32
  "open": "^8.4.0",
31
33
  "portfinder": "^1.0.32",
34
+ "typescript": "^5.0.2",
32
35
  "undici": "^5.19.1",
33
36
  "uuid": "^9.0.0"
34
37
  },
@@ -38,7 +41,8 @@
38
41
  "@types/ws": "^8.5.4"
39
42
  },
40
43
  "files": [
41
- "dist"
44
+ "dist",
45
+ ".dclrc"
42
46
  ],
43
47
  "keywords": [],
44
48
  "license": "Apache-2.0",
@@ -56,5 +60,5 @@
56
60
  "displayName": "SDK",
57
61
  "tsconfig": "./tsconfig.json"
58
62
  },
59
- "commit": "d749052392aba79929086ab20c4ddf78f08e415b"
63
+ "commit": "3e8cb7c03b36e30159963b1c5b4f3e4c906918ac"
60
64
  }
@@ -1,20 +0,0 @@
1
- import { Entity } from '@dcl/schemas';
2
- import { CliComponents } from '../../../components';
3
- export type DAOCatalyst = {
4
- baseUrl: string;
5
- owner: string;
6
- id: string;
7
- };
8
- type CatalystInfo = {
9
- url: string;
10
- timestamp: number;
11
- entityId: string;
12
- };
13
- export type Network = 'mainnet' | 'goerli';
14
- export declare function daoCatalysts({ fetch }: Pick<CliComponents, 'fetch'>, network?: Network): Promise<Array<DAOCatalyst>>;
15
- export declare function fetchEntityByPointer({ fetch }: Pick<CliComponents, 'fetch'>, baseUrl: string, pointers: string[]): Promise<{
16
- baseUrl: string;
17
- deployments: Entity[];
18
- }>;
19
- export declare function getPointers(components: Pick<CliComponents, 'fetch' | 'logger'>, pointer: string, network?: Network): Promise<CatalystInfo[]>;
20
- export {};
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPointers = exports.fetchEntityByPointer = exports.daoCatalysts = void 0;
4
- async function daoCatalysts({ fetch }, network = 'mainnet') {
5
- const tld = network === 'mainnet' ? 'org' : 'zone';
6
- const resp = await (await fetch.fetch(`https://peer.decentraland.${tld}/lambdas/contracts/servers`)).json();
7
- return resp;
8
- }
9
- exports.daoCatalysts = daoCatalysts;
10
- async function fetchEntityByPointer({ fetch }, baseUrl, pointers) {
11
- if (pointers.length === 0)
12
- return {
13
- baseUrl,
14
- deployments: []
15
- };
16
- const activeEntities = baseUrl + '/content/entities/active';
17
- const response = await fetch.fetch(activeEntities, {
18
- method: 'post',
19
- headers: { 'content-type': 'application/json', connection: 'close' },
20
- body: JSON.stringify({ pointers })
21
- });
22
- const deployments = response.ok ? (await response.json()) : [];
23
- return {
24
- baseUrl,
25
- deployments
26
- };
27
- }
28
- exports.fetchEntityByPointer = fetchEntityByPointer;
29
- async function getPointers(components, pointer, network = 'mainnet') {
30
- const catalysts = await daoCatalysts(components, network);
31
- const catalystInfo = [];
32
- for (const { baseUrl } of catalysts) {
33
- try {
34
- const result = await fetchEntityByPointer(components, baseUrl, [pointer]);
35
- const timestamp = result.deployments[0]?.timestamp;
36
- const entityId = result.deployments[0]?.id || '';
37
- catalystInfo.push({ timestamp, entityId, url: baseUrl });
38
- }
39
- catch (err) {
40
- components.logger.log('Error fetching catalyst pointers', err);
41
- }
42
- }
43
- return catalystInfo;
44
- }
45
- exports.getPointers = getPointers;
@@ -1,11 +0,0 @@
1
- import { CliComponents } from '.';
2
- import { DCLInfo } from '../logic/dcl-info';
3
- export type IDCLInfoConfigComponent = {
4
- get(): Promise<DCLInfo>;
5
- updateDCLInfo(value: Partial<DCLInfo>): Promise<Partial<DCLInfo>>;
6
- getVersion(): Promise<string>;
7
- isCI(): boolean;
8
- isEditor(): boolean;
9
- isProduction(): boolean;
10
- };
11
- export declare function createDCLInfoConfigComponent({ fs }: Pick<CliComponents, 'fs'>): Promise<IDCLInfoConfigComponent>;
@@ -1,79 +0,0 @@
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.createDCLInfoConfigComponent = void 0;
27
- const path_1 = __importStar(require("path"));
28
- const config_1 = require("../logic/config");
29
- const fs_1 = require("../logic/fs");
30
- async function createDCLInfoConfigComponent({ fs }) {
31
- function isProduction() {
32
- return process.env.NODE_ENV === 'production' || __filename.includes('node_modules');
33
- }
34
- const defaultConfig = {
35
- userId: '',
36
- trackStats: false,
37
- segmentKey: isProduction() ? 'sFdziRVDJo0taOnGzTZwafEL9nLIANZ3' : 'mjCV5Dc4VAKXLJAH5g7LyHyW1jrIR3to'
38
- };
39
- let dclInfoConfig;
40
- return {
41
- async get() {
42
- if (!dclInfoConfig) {
43
- dclInfoConfig = await (0, config_1.getDCLInfoConfig)({ fs });
44
- }
45
- const envConfig = (0, config_1.getEnvConfig)();
46
- const config = { ...defaultConfig, ...dclInfoConfig, ...envConfig };
47
- return config;
48
- },
49
- updateDCLInfo(value) {
50
- dclInfoConfig = { ...dclInfoConfig, ...value };
51
- return (0, fs_1.writeJSON)({ fs }, (0, config_1.getDclInfoPath)(), value);
52
- },
53
- async getVersion() {
54
- try {
55
- /* istanbul ignore next */
56
- const sdkPath = path_1.default.dirname(require.resolve('@dcl/sdk/package.json', {
57
- paths: [process.cwd()]
58
- }));
59
- /* istanbul ignore next */
60
- const packageJson = await (0, fs_1.readJSON)({ fs }, (0, path_1.resolve)(sdkPath, 'package.json'));
61
- /* istanbul ignore next */
62
- return packageJson.version ?? 'unknown';
63
- }
64
- catch (e) {
65
- return 'unknown';
66
- }
67
- },
68
- isEditor() {
69
- return process.env.EDITOR === 'true';
70
- },
71
- isCI() {
72
- return process.env.CI === 'true' || process.argv.includes('--ci') || process.argv.includes('--c');
73
- },
74
- isProduction() {
75
- return isProduction();
76
- }
77
- };
78
- }
79
- exports.createDCLInfoConfigComponent = createDCLInfoConfigComponent;
@@ -1,27 +0,0 @@
1
- import { CliComponents } from '../components';
2
- /**
3
- * Filter undefined keys from provided object
4
- */
5
- export declare function removeEmptyKeys(obj: Record<string, unknown>): Record<string, unknown>;
6
- export type DCLInfo = {
7
- userIdentified?: boolean;
8
- fileExists?: boolean;
9
- userId?: string;
10
- trackStats?: boolean;
11
- provider?: string;
12
- MANAToken?: string;
13
- LANDRegistry?: string;
14
- EstateRegistry?: string;
15
- catalystUrl?: string;
16
- dclApiUrl?: string;
17
- segmentKey?: string;
18
- };
19
- /**
20
- * Reads `.dclinfo` file and loads it in-memory to be sync-obtained with `getDCLInfo()` function
21
- */
22
- export declare function loadConfig(components: CliComponents): Promise<DCLInfo>;
23
- /**
24
- * Returns the contents of the `.dclinfo` file. It needs to be loaded first with `loadConfig()` function
25
- */
26
- export declare function getDCLInfo(): DCLInfo;
27
- export declare function getCustomConfig(): Partial<DCLInfo>;
@@ -1,90 +0,0 @@
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.getCustomConfig = exports.getDCLInfo = exports.loadConfig = exports.removeEmptyKeys = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- const os_1 = __importDefault(require("os"));
9
- /**
10
- * Filter undefined keys from provided object
11
- */
12
- function removeEmptyKeys(obj) {
13
- const result = {};
14
- Object.keys(obj)
15
- .filter((k) => !!obj[k])
16
- .forEach((k) => (result[k] = obj[k]));
17
- return result;
18
- }
19
- exports.removeEmptyKeys = removeEmptyKeys;
20
- let config;
21
- /**
22
- * Returns the path to the `.dclinfo` file located in the local HOME folder
23
- */
24
- function getDCLInfoPath() {
25
- return path_1.default.resolve(os_1.default.homedir(), '.dclinfo');
26
- }
27
- /**
28
- * Reads the contents of the `.dclinfo` file
29
- */
30
- async function readDCLInfo({ fs }) {
31
- const filePath = getDCLInfoPath();
32
- try {
33
- const file = await fs.readFile(filePath, 'utf-8');
34
- return JSON.parse(file);
35
- }
36
- catch (e) {
37
- return null;
38
- }
39
- }
40
- /**
41
- * Reads `.dclinfo` file and loads it in-memory to be sync-obtained with `getDCLInfo()` function
42
- */
43
- async function loadConfig(components) {
44
- config = (await readDCLInfo(components));
45
- return config;
46
- }
47
- exports.loadConfig = loadConfig;
48
- /**
49
- * Returns the contents of the `.dclinfo` file. It needs to be loaded first with `loadConfig()` function
50
- */
51
- function getDCLInfo() {
52
- return config;
53
- }
54
- exports.getDCLInfo = getDCLInfo;
55
- function getCustomConfig() {
56
- const envConfig = getEnvConfig();
57
- const dclInfoConfig = getDclInfoConfig();
58
- return { ...dclInfoConfig, ...envConfig };
59
- }
60
- exports.getCustomConfig = getCustomConfig;
61
- function getDclInfoConfig() {
62
- const dclInfo = getDCLInfo();
63
- const fileExists = !!dclInfo;
64
- if (!fileExists) {
65
- return { fileExists };
66
- }
67
- const dclInfoConfig = {
68
- fileExists,
69
- userId: dclInfo.userId,
70
- trackStats: !!dclInfo.trackStats,
71
- MANAToken: dclInfo.MANAToken,
72
- LANDRegistry: dclInfo.LANDRegistry,
73
- EstateRegistry: dclInfo.EstateRegistry,
74
- catalystUrl: dclInfo.catalystUrl,
75
- segmentKey: dclInfo.segmentKey
76
- };
77
- return removeEmptyKeys(dclInfoConfig);
78
- }
79
- function getEnvConfig() {
80
- const { RPC_URL, MANA_TOKEN, LAND_REGISTRY, ESTATE_REGISTRY, CONTENT_URL, SEGMENT_KEY } = process.env;
81
- const envConfig = {
82
- provider: RPC_URL,
83
- MANAToken: MANA_TOKEN,
84
- LANDRegistry: LAND_REGISTRY,
85
- EstateRegistry: ESTATE_REGISTRY,
86
- contentUrl: CONTENT_URL,
87
- segmentKey: SEGMENT_KEY
88
- };
89
- return removeEmptyKeys(envConfig);
90
- }