@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,61 @@
1
+ import { Scene } from '@dcl/schemas'
2
+ import { resolve } from 'path'
3
+ import { CliComponents } from '../components'
4
+ import { CliError } from './error'
5
+ import { exec } from './exec'
6
+ import { validateSceneJson } from './scene-validations'
7
+
8
+ /**
9
+ * Asserts that the projectRoot is a valid project
10
+ */
11
+ export async function assertValidProjectFolder(
12
+ components: Pick<CliComponents, 'fs' | 'logger'>,
13
+ projectRoot: string
14
+ ): Promise<{ scene: Scene }> {
15
+ // no validations for now, only check that it exists
16
+ if (!(await components.fs.fileExists(resolve(projectRoot, 'package.json'))))
17
+ throw new CliError(`The project root doesn't have a package.json file`)
18
+
19
+ // now we will iterate over different file to evaluate the project kind
20
+ switch (true) {
21
+ // case wearable
22
+ case await components.fs.fileExists(resolve(projectRoot, 'scene.json')): {
23
+ return { scene: await validateSceneJson(components, projectRoot) }
24
+ }
25
+ default: {
26
+ throw new CliError(`UnknownProjectKind: the kind of project of the folder ${projectRoot} cannot be identified`)
27
+ }
28
+ }
29
+ }
30
+
31
+ /*
32
+ * Returns true if the project contains an empty node_modules folder
33
+ */
34
+ export async function needsDependencies(components: Pick<CliComponents, 'fs'>, dir: string): Promise<boolean> {
35
+ const nodeModulesPath = resolve(dir, 'node_modules')
36
+ const hasNodeModulesFolder = await components.fs.directoryExists(nodeModulesPath)
37
+ const isNodeModulesEmpty = hasNodeModulesFolder && (await components.fs.readdir(nodeModulesPath)).length === 0
38
+
39
+ return !hasNodeModulesFolder || isNodeModulesEmpty
40
+ }
41
+
42
+ /* istanbul ignore next */
43
+ export const npm = /^win/.test(process.platform) ? 'npm.cmd' : 'npm'
44
+
45
+ /*
46
+ * Runs "npm install" for desired project
47
+ */
48
+ export async function installDependencies(components: Pick<CliComponents, 'logger'>, directory: string): Promise<void> {
49
+ components.logger.info('Installing dependencies...')
50
+ // TODO: test in windows
51
+ await exec(directory, npm, ['install'])
52
+ components.logger.log('Installing dependencies... ✅')
53
+ }
54
+
55
+ /**
56
+ * Run NPM commands
57
+ */
58
+ export async function npmRun(cwd: string, command: string, ...args: string[]): Promise<void> {
59
+ // TODO: test in windows
60
+ await exec(cwd, npm, ['run', command, '--silent', '--', ...args], { env: process.env as any })
61
+ }
@@ -0,0 +1,28 @@
1
+ import { AboutResponse } from '@dcl/protocol/out-js/decentraland/bff/http_endpoints.gen'
2
+
3
+ export function createStaticRealm(): AboutResponse {
4
+ return {
5
+ acceptingUsers: true,
6
+ bff: { healthy: false, publicUrl: `https://peer.decentraland.org/bff` },
7
+ comms: {
8
+ healthy: true,
9
+ protocol: 'v3',
10
+ fixedAdapter: `offline:offline`
11
+ },
12
+ configurations: {
13
+ networkId: 0,
14
+ globalScenesUrn: [],
15
+ scenesUrn: [],
16
+ realmName: 'SdkStaticExport'
17
+ },
18
+ content: {
19
+ healthy: true,
20
+ publicUrl: `https://peer.decentraland.org/content`
21
+ },
22
+ lambdas: {
23
+ healthy: true,
24
+ publicUrl: `https://peer.decentraland.org/lambdas`
25
+ },
26
+ healthy: true
27
+ }
28
+ }
@@ -0,0 +1,73 @@
1
+ import { resolve } from 'path'
2
+ import { Scene } from '@dcl/schemas'
3
+ import { CliError } from './error'
4
+ import { getObject, inBounds, getBounds, areConnected } from './coordinates'
5
+ import { CliComponents } from '../components'
6
+
7
+ export const SCENE_FILE = 'scene.json'
8
+
9
+ /**
10
+ * Composes the path to the `scene.json` file based on the provided path.
11
+ * @param projectRoot The path to the directory containing the scene file.
12
+ */
13
+ export function getSceneFilePath(projectRoot: string): string {
14
+ return resolve(projectRoot, SCENE_FILE)
15
+ }
16
+
17
+ export function assertValidScene(scene: Scene) {
18
+ if (!Scene.validate(scene)) {
19
+ const errors: string[] = []
20
+ if (Scene.validate.errors) {
21
+ for (const error of Scene.validate.errors) {
22
+ errors.push(`Error validating scene.json: ${error.message}`)
23
+ }
24
+ }
25
+ throw new CliError('Invalid scene.json file:\n' + errors.join('\n'))
26
+ }
27
+
28
+ const parcelSet = new Set(scene.scene?.parcels)
29
+
30
+ if (parcelSet.size < scene.scene?.parcels?.length) {
31
+ throw new CliError(`There are duplicated parcels at scene.json.`)
32
+ }
33
+
34
+ if (!parcelSet.has(scene.scene?.base)) {
35
+ throw new CliError(`Your base parcel ${scene.scene?.base} should be included on parcels attribute at scene.json`)
36
+ }
37
+
38
+ const objParcels = scene.scene?.parcels?.map(getObject)
39
+ objParcels.forEach(({ x, y }) => {
40
+ if (inBounds(x, y)) {
41
+ return
42
+ }
43
+ const { minX, maxX } = getBounds()
44
+ throw new CliError(`Coordinates ${x},${y} are outside of allowed limits (from ${minX} to ${maxX})`)
45
+ })
46
+
47
+ if (!areConnected(objParcels)) {
48
+ throw new CliError('Parcels described on scene.json are not connected. They should be one next to each other')
49
+ }
50
+
51
+ if (!scene.main?.endsWith('.js')) {
52
+ throw new CliError(`Main scene format file (${scene.main}) is not a supported format`)
53
+ }
54
+
55
+ return scene
56
+ }
57
+
58
+ /**
59
+ * Fails the execution if one of the parcel data is invalid
60
+ */
61
+ export async function validateSceneJson(
62
+ components: Pick<CliComponents, 'fs' | 'logger'>,
63
+ projectRoot: string
64
+ ): Promise<Scene> {
65
+ try {
66
+ const sceneJsonRaw = await components.fs.readFile(getSceneFilePath(projectRoot), 'utf8')
67
+ const sceneJson = JSON.parse(sceneJsonRaw) as Scene
68
+
69
+ return assertValidScene(sceneJson)
70
+ } catch (err: any) {
71
+ throw new CliError(`Error reading the scene.json file: ${err.message}`)
72
+ }
73
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "commonjs",
5
+ "esModuleInterop": true,
6
+ "declaration": true,
7
+ "noUnusedLocals": true,
8
+ "stripInternal": true,
9
+ "skipLibCheck": true,
10
+ "forceConsistentCasingInFileNames": true,
11
+ "allowJs": true,
12
+ "resolveJsonModule": true,
13
+ "strict": true,
14
+ "types": [
15
+ "node",
16
+ ],
17
+ "lib": [
18
+ "es2020"
19
+ ],
20
+ "outDir": "./dist"
21
+ },
22
+ "include": [
23
+ "src"
24
+ ],
25
+ "exclude": [
26
+ "dist"
27
+ ]
28
+ }