@dcl/sdk-commands 7.1.4-4619170473.commit-d3a4f9f → 7.1.4-4619276636.commit-e2c17cb
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/build/index.d.ts +2 -0
- package/dist/commands/build/index.js +24 -10
- package/dist/commands/export-static/index.d.ts +5 -0
- package/dist/commands/export-static/index.js +58 -44
- package/dist/commands/start/index.js +32 -25
- package/dist/commands/start/server/endpoints.d.ts +2 -1
- package/dist/commands/start/server/endpoints.js +7 -7
- package/dist/commands/start/server/file-watch-notifier.js +3 -0
- package/dist/commands/start/server/routes.d.ts +2 -1
- package/dist/commands/start/server/routes.js +2 -2
- package/dist/components/fs.js +1 -0
- package/dist/index.js +1 -1
- package/dist/logic/beautiful-logs.d.ts +7 -0
- package/dist/logic/beautiful-logs.js +20 -1
- package/dist/logic/bundle.d.ts +3 -2
- package/dist/logic/bundle.js +5 -8
- package/dist/logic/dcl-ignore.js +2 -1
- package/dist/logic/project-validations.d.ts +12 -7
- package/dist/logic/project-validations.js +23 -17
- package/dist/logic/workspace-validations.d.ts +27 -0
- package/dist/logic/workspace-validations.js +122 -0
- package/package.json +3 -3
@@ -1,4 +1,5 @@
|
|
1
1
|
import { CliComponents } from '../../components';
|
2
|
+
import { SceneProject } from '../../logic/project-validations';
|
2
3
|
interface Options {
|
3
4
|
args: typeof args;
|
4
5
|
components: Pick<CliComponents, 'fs' | 'logger' | 'analytics' | 'spawner'>;
|
@@ -19,4 +20,5 @@ export declare const args: import("arg").Result<{
|
|
19
20
|
}>;
|
20
21
|
export declare function help(): string;
|
21
22
|
export declare function main(options: Options): Promise<void>;
|
23
|
+
export declare function buildScene(options: Options, project: SceneProject): Promise<void>;
|
22
24
|
export {};
|
@@ -1,12 +1,17 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.main = exports.help = exports.args = void 0;
|
4
|
-
const path_1 = require("path");
|
6
|
+
exports.buildScene = exports.main = exports.help = exports.args = void 0;
|
7
|
+
const path_1 = __importDefault(require("path"));
|
5
8
|
const args_1 = require("../../logic/args");
|
6
9
|
const project_validations_1 = require("../../logic/project-validations");
|
7
10
|
const scene_validations_1 = require("../../logic/scene-validations");
|
8
11
|
const project_files_1 = require("../../logic/project-files");
|
9
12
|
const bundle_1 = require("../../logic/bundle");
|
13
|
+
const beautiful_logs_1 = require("../../logic/beautiful-logs");
|
14
|
+
const workspace_validations_1 = require("../../logic/workspace-validations");
|
10
15
|
exports.args = (0, args_1.getArgs)({
|
11
16
|
'--watch': Boolean,
|
12
17
|
'-w': '--watch',
|
@@ -34,26 +39,35 @@ function help() {
|
|
34
39
|
}
|
35
40
|
exports.help = help;
|
36
41
|
async function main(options) {
|
37
|
-
const workingDirectory =
|
38
|
-
await (0,
|
39
|
-
const
|
42
|
+
const workingDirectory = path_1.default.resolve(process.cwd(), options.args['--dir'] || '.');
|
43
|
+
const workspace = await (0, workspace_validations_1.getValidWorkspace)(options.components, workingDirectory);
|
44
|
+
for (const project of workspace.projects) {
|
45
|
+
(0, beautiful_logs_1.printCurrentProjectStarting)(options.components.logger, project, workspace);
|
46
|
+
if (project.kind === 'scene') {
|
47
|
+
await buildScene(options, project);
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}
|
51
|
+
exports.main = main;
|
52
|
+
async function buildScene(options, project) {
|
53
|
+
const shouldInstallDeps = await (0, project_validations_1.needsDependencies)(options.components, project.workingDirectory);
|
40
54
|
if (shouldInstallDeps && !options.args['--skip-install']) {
|
41
|
-
await (0, project_validations_1.installDependencies)(options.components, workingDirectory);
|
55
|
+
await (0, project_validations_1.installDependencies)(options.components, project.workingDirectory);
|
42
56
|
}
|
43
57
|
const watch = !!options.args['--watch'];
|
44
58
|
const { sceneJson } = await (0, bundle_1.bundleProject)(options.components, {
|
45
|
-
workingDirectory,
|
59
|
+
workingDirectory: project.workingDirectory,
|
46
60
|
watch,
|
47
61
|
single: options.args['--single'],
|
48
62
|
production: !!options.args['--production'],
|
49
63
|
emitDeclaration: !!options.args['--emitDeclaration']
|
50
|
-
});
|
64
|
+
}, project.scene);
|
51
65
|
const coords = (0, scene_validations_1.getBaseCoords)(sceneJson);
|
52
66
|
options.components.analytics.track('Build scene', {
|
53
|
-
projectHash: await (0, project_files_1.b64HashingFunction)(workingDirectory),
|
67
|
+
projectHash: await (0, project_files_1.b64HashingFunction)(project.workingDirectory),
|
54
68
|
coords,
|
55
69
|
isWorkspace: false,
|
56
70
|
args: (0, args_1.getArgsUsed)(options.args)
|
57
71
|
});
|
58
72
|
}
|
59
|
-
exports.
|
73
|
+
exports.buildScene = buildScene;
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { CliComponents } from '../../components';
|
2
|
+
import { SceneProject } from '../../logic/project-validations';
|
2
3
|
interface Options {
|
3
4
|
args: typeof args;
|
4
5
|
components: Pick<CliComponents, 'fetch' | 'fs' | 'logger' | 'analytics' | 'config'>;
|
@@ -16,6 +17,10 @@ export declare const args: import("arg").Result<{
|
|
16
17
|
}>;
|
17
18
|
export declare function help(): Promise<string>;
|
18
19
|
export declare function main(options: Options): Promise<{
|
20
|
+
scenesUrn: string[];
|
21
|
+
destination: string;
|
22
|
+
}>;
|
23
|
+
export declare function prepareSceneFiles(options: Options, project: SceneProject, outputDirectory: string): Promise<{
|
19
24
|
urn: string;
|
20
25
|
entityId: string;
|
21
26
|
destination: string;
|
@@ -1,10 +1,12 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.main = exports.help = exports.args = void 0;
|
4
|
-
const path_1 = require("path");
|
6
|
+
exports.prepareSceneFiles = exports.main = exports.help = exports.args = void 0;
|
7
|
+
const path_1 = __importDefault(require("path"));
|
5
8
|
const args_1 = require("../../logic/args");
|
6
9
|
const hashing_1 = require("@dcl/hashing");
|
7
|
-
const project_validations_1 = require("../../logic/project-validations");
|
8
10
|
const project_files_1 = require("../../logic/project-files");
|
9
11
|
const error_1 = require("../../logic/error");
|
10
12
|
const schemas_1 = require("@dcl/schemas");
|
@@ -12,6 +14,7 @@ const log_1 = require("../../components/log");
|
|
12
14
|
const beautiful_logs_1 = require("../../logic/beautiful-logs");
|
13
15
|
const realm_1 = require("../../logic/realm");
|
14
16
|
const scene_validations_1 = require("../../logic/scene-validations");
|
17
|
+
const workspace_validations_1 = require("../../logic/workspace-validations");
|
15
18
|
exports.args = (0, args_1.getArgs)({
|
16
19
|
'--dir': String,
|
17
20
|
'--destination': String,
|
@@ -40,11 +43,11 @@ async function help() {
|
|
40
43
|
exports.help = help;
|
41
44
|
async function main(options) {
|
42
45
|
const { fs, logger } = options.components;
|
43
|
-
const
|
44
|
-
const
|
46
|
+
const workingDirectory = path_1.default.resolve(process.cwd(), options.args['--dir'] || '.');
|
47
|
+
const outputDirectory = path_1.default.resolve(process.cwd(), options.args['--destination'] || '.');
|
45
48
|
const willCreateRealm = !!exports.args['--realmName'];
|
46
49
|
let currentStep = 1;
|
47
|
-
const maxSteps =
|
50
|
+
const maxSteps = 1 + (willCreateRealm ? 1 : 0);
|
48
51
|
if (willCreateRealm && !exports.args['--baseUrl']) {
|
49
52
|
throw new error_1.CliError(`--baseUrl is mandatory when --realmName is provided`);
|
50
53
|
}
|
@@ -52,21 +55,52 @@ async function main(options) {
|
|
52
55
|
throw new error_1.CliError(`--realmName has invalid characters`);
|
53
56
|
}
|
54
57
|
(0, beautiful_logs_1.printProgressStep)(logger, 'Reading project files...', currentStep++, maxSteps);
|
55
|
-
await fs.mkdir(
|
56
|
-
if (!(await fs.directoryExists(
|
57
|
-
throw new error_1.CliError(`The destination path ${
|
58
|
+
await fs.mkdir(outputDirectory, { recursive: true });
|
59
|
+
if (!(await fs.directoryExists(outputDirectory))) {
|
60
|
+
throw new error_1.CliError(`The destination path ${outputDirectory} is not a directory`);
|
58
61
|
}
|
59
|
-
const
|
60
|
-
const
|
61
|
-
|
62
|
+
const scenesUrn = [];
|
63
|
+
const workspace = await (0, workspace_validations_1.getValidWorkspace)(options.components, workingDirectory);
|
64
|
+
for (const project of workspace.projects) {
|
65
|
+
(0, beautiful_logs_1.printCurrentProjectStarting)(options.components.logger, project, workspace);
|
66
|
+
if (project.kind === 'scene') {
|
67
|
+
const result = await prepareSceneFiles(options, project, outputDirectory);
|
68
|
+
scenesUrn.push(result.urn);
|
69
|
+
}
|
70
|
+
}
|
71
|
+
if (willCreateRealm) {
|
72
|
+
// prepare the realm object
|
73
|
+
(0, beautiful_logs_1.printProgressStep)(logger, 'Creating realm file...', currentStep++, maxSteps);
|
74
|
+
const realm = await (0, realm_1.createStaticRealm)(options.components);
|
75
|
+
const realmName = exports.args['--realmName'];
|
76
|
+
realm.configurations.scenesUrn = scenesUrn;
|
77
|
+
realm.configurations.realmName = realmName;
|
78
|
+
// write the realm file
|
79
|
+
const realmDirectory = path_1.default.join(outputDirectory, realmName);
|
80
|
+
await fs.mkdir(realmDirectory, { recursive: true });
|
81
|
+
if (!(await fs.directoryExists(realmDirectory))) {
|
82
|
+
throw new error_1.CliError(`The destination path ${realmDirectory} is not a directory`);
|
83
|
+
}
|
84
|
+
const dst = path_1.default.join(realmDirectory, 'about');
|
85
|
+
await fs.writeFile(dst, JSON.stringify(realm, null, 2));
|
86
|
+
(0, beautiful_logs_1.printProgressInfo)(logger, `> ${realmName}/about -> [REALM FILE]`);
|
87
|
+
}
|
88
|
+
(0, beautiful_logs_1.printSuccess)(logger, `Export finished!`, `=> The entity URN are:${log_1.colors.bold(scenesUrn.map(($) => '\n - ' + $).join(''))}`);
|
89
|
+
return { scenesUrn, destination: outputDirectory };
|
90
|
+
}
|
91
|
+
exports.main = main;
|
92
|
+
async function prepareSceneFiles(options, project, outputDirectory) {
|
93
|
+
const { fs, logger } = options.components;
|
94
|
+
const filesToExport = await (0, project_files_1.getProjectContentMappings)(options.components, project.workingDirectory, async (file) => {
|
95
|
+
return await (0, hashing_1.hashV1)(fs.createReadStream(path_1.default.resolve(project.workingDirectory, file)));
|
62
96
|
});
|
63
|
-
(0, beautiful_logs_1.
|
97
|
+
(0, beautiful_logs_1.printProgressInfo)(logger, 'Copying files...');
|
64
98
|
for (const { file, hash } of filesToExport) {
|
65
|
-
const src =
|
66
|
-
const dst =
|
67
|
-
if (src.startsWith(
|
99
|
+
const src = path_1.default.resolve(project.workingDirectory, file);
|
100
|
+
const dst = path_1.default.resolve(outputDirectory, hash);
|
101
|
+
if (src.startsWith(outputDirectory))
|
68
102
|
continue;
|
69
|
-
(0, beautiful_logs_1.printProgressInfo)(logger, `> ${hash} -> ${file}`);
|
103
|
+
(0, beautiful_logs_1.printProgressInfo)(logger, `> ${hash} -> ${log_1.colors.reset(file)}`);
|
70
104
|
if (!(await fs.fileExists(dst))) {
|
71
105
|
const content = await fs.readFile(src);
|
72
106
|
await fs.writeFile(dst, content);
|
@@ -83,13 +117,13 @@ async function main(options) {
|
|
83
117
|
metadata: project.scene,
|
84
118
|
version: 'v3'
|
85
119
|
};
|
86
|
-
(0, beautiful_logs_1.
|
120
|
+
(0, beautiful_logs_1.printProgressInfo)(logger, 'Generating files...');
|
87
121
|
// create the entity file and get the entityId
|
88
122
|
const entityRaw = Buffer.from(JSON.stringify(entity), 'utf8');
|
89
123
|
const entityId = await (0, hashing_1.hashV1)(entityRaw);
|
90
|
-
const dst =
|
124
|
+
const dst = path_1.default.resolve(outputDirectory, entityId);
|
91
125
|
await fs.writeFile(dst, entityRaw);
|
92
|
-
(0, beautiful_logs_1.printProgressInfo)(logger, `> ${entityId} -> [ENTITY FILE]`);
|
126
|
+
(0, beautiful_logs_1.printProgressInfo)(logger, `> ${entityId} -> ${log_1.colors.reset('[ENTITY FILE]')}`);
|
93
127
|
let urn = `urn:decentraland:entity:${entityId}`;
|
94
128
|
if (exports.args['--baseUrl']) {
|
95
129
|
urn += '?baseUrl=' + exports.args['--baseUrl'];
|
@@ -97,31 +131,11 @@ async function main(options) {
|
|
97
131
|
if (!urn.endsWith('/'))
|
98
132
|
urn += '/';
|
99
133
|
}
|
100
|
-
if (willCreateRealm) {
|
101
|
-
// prepare the realm object
|
102
|
-
(0, beautiful_logs_1.printProgressStep)(logger, 'Creating realm file...', currentStep++, maxSteps);
|
103
|
-
const realm = await (0, realm_1.createStaticRealm)(options.components);
|
104
|
-
const realmName = exports.args['--realmName'];
|
105
|
-
realm.configurations.scenesUrn = [urn];
|
106
|
-
realm.configurations.realmName = realmName;
|
107
|
-
// write the realm file
|
108
|
-
const realmDirectory = (0, path_1.resolve)(destDirectory, realmName);
|
109
|
-
await fs.mkdir(realmDirectory, { recursive: true });
|
110
|
-
if (!(await fs.directoryExists(realmDirectory))) {
|
111
|
-
throw new error_1.CliError(`The destination path ${realmDirectory} is not a directory`);
|
112
|
-
}
|
113
|
-
const dst = (0, path_1.resolve)(realmDirectory, 'about');
|
114
|
-
await fs.writeFile(dst, JSON.stringify(realm, null, 2));
|
115
|
-
(0, beautiful_logs_1.printProgressInfo)(logger, `> ${realmName}/about -> [REALM FILE]`);
|
116
|
-
}
|
117
|
-
(0, beautiful_logs_1.printSuccess)(logger, `Export finished!`, `=> The entity URN is ${log_1.colors.bold(urn)}`);
|
118
|
-
const sceneJson = await (0, scene_validations_1.getValidSceneJson)(options.components, projectRoot);
|
119
|
-
const coords = (0, scene_validations_1.getBaseCoords)(sceneJson);
|
120
134
|
options.components.analytics.track('Export static', {
|
121
|
-
projectHash: await (0, project_files_1.b64HashingFunction)(
|
122
|
-
coords,
|
135
|
+
projectHash: await (0, project_files_1.b64HashingFunction)(project.workingDirectory),
|
136
|
+
coords: (0, scene_validations_1.getBaseCoords)(project.scene),
|
123
137
|
args: (0, args_1.getArgsUsed)(options.args)
|
124
138
|
});
|
125
|
-
return { urn, entityId, destination:
|
139
|
+
return { urn, entityId, destination: outputDirectory };
|
126
140
|
}
|
127
|
-
exports.
|
141
|
+
exports.prepareSceneFiles = prepareSceneFiles;
|
@@ -32,9 +32,7 @@ const path = __importStar(require("path"));
|
|
32
32
|
const open_1 = __importDefault(require("open"));
|
33
33
|
const build_1 = require("../build");
|
34
34
|
const args_1 = require("../../logic/args");
|
35
|
-
const project_validations_1 = require("../../logic/project-validations");
|
36
35
|
const scene_validations_1 = require("../../logic/scene-validations");
|
37
|
-
const error_1 = require("../../logic/error");
|
38
36
|
const get_free_port_1 = require("../../logic/get-free-port");
|
39
37
|
const metrics_1 = require("@well-known-components/metrics");
|
40
38
|
const interfaces_1 = require("@well-known-components/interfaces");
|
@@ -50,6 +48,8 @@ const ws_1 = require("./server/ws");
|
|
50
48
|
const project_files_1 = require("../../logic/project-files");
|
51
49
|
const rpc_1 = require("./data-layer/rpc");
|
52
50
|
const exit_signal_1 = require("../../components/exit-signal");
|
51
|
+
const workspace_validations_1 = require("../../logic/workspace-validations");
|
52
|
+
const beautiful_logs_1 = require("../../logic/beautiful-logs");
|
53
53
|
exports.args = (0, args_1.getArgs)({
|
54
54
|
'--dir': String,
|
55
55
|
'--help': Boolean,
|
@@ -98,7 +98,8 @@ async function help() {
|
|
98
98
|
}
|
99
99
|
exports.help = help;
|
100
100
|
async function main(options) {
|
101
|
-
|
101
|
+
let baseCoords = { x: 0, y: 0 };
|
102
|
+
const workingDirectory = path.resolve(process.cwd(), options.args['--dir'] || '.');
|
102
103
|
const isCi = exports.args['--ci'] || process.env.CI || false;
|
103
104
|
const debug = !exports.args['--no-debug'] && !isCi;
|
104
105
|
const openBrowser = !exports.args['--no-browser'] && !isCi;
|
@@ -108,20 +109,30 @@ async function main(options) {
|
|
108
109
|
const enableWeb3 = exports.args['--web3'];
|
109
110
|
// TODO: FIX this hardcoded values ?
|
110
111
|
const hasPortableExperience = false;
|
111
|
-
|
112
|
-
if
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
112
|
+
const workspace = await (0, workspace_validations_1.getValidWorkspace)(options.components, workingDirectory);
|
113
|
+
/* istanbul ignore if */
|
114
|
+
if (workspace.projects.length > 1)
|
115
|
+
(0, beautiful_logs_1.printWarning)(options.components.logger, 'Support for multiple projects is still experimental.');
|
116
|
+
for (const project of workspace.projects) {
|
117
|
+
(0, beautiful_logs_1.printCurrentProjectStarting)(options.components.logger, project, workspace);
|
118
|
+
// first run `npm run build`, this can be disabled with --skip-build
|
119
|
+
// then start the embedded compiler, this can be disabled with --no-watch
|
120
|
+
if (watch) {
|
121
|
+
await (0, build_1.buildScene)({ ...options, args: { '--dir': project.workingDirectory, '--watch': true, _: [] } }, project);
|
122
|
+
}
|
123
|
+
else if (!skipBuild) {
|
124
|
+
await (0, build_1.buildScene)({ ...options, args: { '--dir': project.workingDirectory, '--watch': false, _: [] } }, project);
|
125
|
+
}
|
126
|
+
// track the event
|
127
|
+
baseCoords = (0, scene_validations_1.getBaseCoords)(project.scene);
|
128
|
+
options.components.analytics.track('Preview started', {
|
129
|
+
projectHash: await (0, project_files_1.b64HashingFunction)(project.workingDirectory),
|
130
|
+
coords: baseCoords,
|
131
|
+
isWorkspace: false,
|
132
|
+
args: (0, args_1.getArgsUsed)(options.args)
|
133
|
+
});
|
124
134
|
}
|
135
|
+
(0, beautiful_logs_1.printProgressInfo)(options.components.logger, 'Starting preview server');
|
125
136
|
const port = await (0, get_free_port_1.getPort)(options.args['--port']);
|
126
137
|
const program = await interfaces_1.Lifecycle.run({
|
127
138
|
async initComponents() {
|
@@ -156,20 +167,16 @@ async function main(options) {
|
|
156
167
|
async main({ components, startComponents }) {
|
157
168
|
// TODO: dataLayerRpc should be an optional component
|
158
169
|
const dataLayer = withDataLayer ? await (0, rpc_1.createDataLayer)(components) : undefined;
|
159
|
-
await (0, routes_1.wireRouter)(components,
|
170
|
+
await (0, routes_1.wireRouter)(components, workspace, dataLayer);
|
160
171
|
if (watch) {
|
161
|
-
|
172
|
+
for (const project of workspace.projects) {
|
173
|
+
await (0, file_watch_notifier_1.wireFileWatcherToWebSockets)(components, project.workingDirectory);
|
174
|
+
}
|
162
175
|
}
|
163
176
|
await startComponents();
|
164
177
|
const networkInterfaces = os.networkInterfaces();
|
165
178
|
const availableURLs = [];
|
166
|
-
components.
|
167
|
-
projectHash: await (0, project_files_1.b64HashingFunction)(projectRoot),
|
168
|
-
coords: baseCoords,
|
169
|
-
isWorkspace: false,
|
170
|
-
args: (0, args_1.getArgsUsed)(options.args)
|
171
|
-
});
|
172
|
-
components.logger.log(`Preview server is now running!`);
|
179
|
+
(0, beautiful_logs_1.printProgressInfo)(options.components.logger, 'Preview server is now running!');
|
173
180
|
components.logger.log('Available on:\n');
|
174
181
|
Object.keys(networkInterfaces).forEach((dev) => {
|
175
182
|
;
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { Router } from '@well-known-components/http-server';
|
2
2
|
import { PreviewComponents } from '../types';
|
3
3
|
import { CliComponents } from '../../../components';
|
4
|
-
|
4
|
+
import { Workspace } from '../../../logic/workspace-validations';
|
5
|
+
export declare function setupEcs6Endpoints(components: CliComponents, router: Router<PreviewComponents>, workspace: Workspace): Promise<void>;
|
@@ -34,14 +34,14 @@ const config_1 = require("../../../logic/config");
|
|
34
34
|
function smartWearableNameToId(name) {
|
35
35
|
return name.toLocaleLowerCase().replace(/ /g, '-');
|
36
36
|
}
|
37
|
-
async function setupEcs6Endpoints(components,
|
37
|
+
async function setupEcs6Endpoints(components, router, workspace) {
|
38
38
|
const catalystUrl = new URL(await (0, config_1.getCatalystBaseUrl)(components));
|
39
|
-
const baseFolders =
|
39
|
+
const baseFolders = workspace.projects.map(($) => $.workingDirectory);
|
40
40
|
// handle old preview scene.json
|
41
41
|
router.get('/scene.json', async () => {
|
42
42
|
return {
|
43
43
|
headers: { 'content-type': 'application/json' },
|
44
|
-
body: components.fs.createReadStream(path.join(
|
44
|
+
body: components.fs.createReadStream(path.join(baseFolders[0], 'scene.json'))
|
45
45
|
};
|
46
46
|
});
|
47
47
|
router.get('/lambdas/explore/realms', async (ctx) => {
|
@@ -134,7 +134,7 @@ async function setupEcs6Endpoints(components, dir, router) {
|
|
134
134
|
});
|
135
135
|
return res;
|
136
136
|
});
|
137
|
-
serveStatic(components,
|
137
|
+
serveStatic(components, workspace, router);
|
138
138
|
// TODO: get workspace scenes & wearables...
|
139
139
|
await serveFolders(components, router, baseFolders);
|
140
140
|
}
|
@@ -283,12 +283,12 @@ async function getSceneJson(components, projectRoots, pointers) {
|
|
283
283
|
}
|
284
284
|
return resultEntities;
|
285
285
|
}
|
286
|
-
function serveStatic(components,
|
286
|
+
function serveStatic(components, workspace, router) {
|
287
287
|
const sdkPath = path.dirname(require.resolve('@dcl/sdk/package.json', {
|
288
|
-
paths: [
|
288
|
+
paths: [workspace.rootWorkingDirectory, ...workspace.projects.map(($) => $.workingDirectory)]
|
289
289
|
}));
|
290
290
|
const dclExplorerJsonPath = path.dirname(require.resolve('@dcl/explorer/package.json', {
|
291
|
-
paths: [
|
291
|
+
paths: [workspace.rootWorkingDirectory, ...workspace.projects.map(($) => $.workingDirectory), sdkPath]
|
292
292
|
}));
|
293
293
|
const dclKernelDefaultProfilePath = path.resolve(dclExplorerJsonPath, 'default-profile');
|
294
294
|
const dclKernelImagesDecentralandConnect = path.resolve(dclExplorerJsonPath, 'images', 'decentraland-connect');
|
@@ -30,6 +30,9 @@ async function wireFileWatcherToWebSockets(components, projectRoot) {
|
|
30
30
|
});
|
31
31
|
}
|
32
32
|
exports.wireFileWatcherToWebSockets = wireFileWatcherToWebSockets;
|
33
|
+
/*
|
34
|
+
* IMPORTANT: this is a legacy protocol and needs to be revisited for SDK7
|
35
|
+
*/
|
33
36
|
function updateScene(dir, clients) {
|
34
37
|
for (const client of clients) {
|
35
38
|
if (client.readyState === ws_1.WebSocket.OPEN) {
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { Workspace } from '../../../logic/workspace-validations';
|
1
2
|
import { DataLayer } from '../data-layer/rpc';
|
2
3
|
import { PreviewComponents } from '../types';
|
3
|
-
export declare function wireRouter(components: PreviewComponents,
|
4
|
+
export declare function wireRouter(components: PreviewComponents, workspace: Workspace, dataLayer?: DataLayer): Promise<void>;
|
@@ -6,7 +6,7 @@ const ws_1 = require("@well-known-components/http-server/dist/ws");
|
|
6
6
|
const ws_2 = require("../data-layer/ws");
|
7
7
|
const endpoints_1 = require("./endpoints");
|
8
8
|
const realm_1 = require("./realm");
|
9
|
-
async function wireRouter(components,
|
9
|
+
async function wireRouter(components, workspace, dataLayer) {
|
10
10
|
const router = new http_server_1.Router();
|
11
11
|
const sceneUpdateClients = new Set();
|
12
12
|
if (dataLayer) {
|
@@ -24,7 +24,7 @@ async function wireRouter(components, dir, dataLayer) {
|
|
24
24
|
return next();
|
25
25
|
});
|
26
26
|
(0, realm_1.setupRealmAndComms)(components, router);
|
27
|
-
await (0, endpoints_1.setupEcs6Endpoints)(components,
|
27
|
+
await (0, endpoints_1.setupEcs6Endpoints)(components, router, workspace);
|
28
28
|
components.server.setContext(components);
|
29
29
|
components.server.use(router.allowedMethods());
|
30
30
|
components.server.use(router.middleware());
|
package/dist/components/fs.js
CHANGED
package/dist/index.js
CHANGED
@@ -62,7 +62,7 @@ main().catch(function handleError(err) {
|
|
62
62
|
// log with console to show stacktrace and debug information
|
63
63
|
// eslint-disable-next-line no-console
|
64
64
|
console.error(err);
|
65
|
-
(0, log_1.writeToStderr)(`Developer: All errors thrown must be an instance of "CliError"`);
|
65
|
+
(0, log_1.writeToStderr)(`Developer: All errors thrown must be an instance of "CliError"` + err.stack);
|
66
66
|
}
|
67
67
|
// set an exit code but not finish the program immediately to close any pending work
|
68
68
|
process.exit(process.exitCode ?? 1);
|
@@ -1,5 +1,12 @@
|
|
1
1
|
import { ILoggerComponent } from '@well-known-components/interfaces';
|
2
|
+
import { ProjectUnion } from './project-validations';
|
3
|
+
import { Workspace } from './workspace-validations';
|
2
4
|
export declare function printProgressStep(logger: ILoggerComponent.ILogger, log: string, currentStep: number, maxStep: number): void;
|
3
5
|
export declare function printProgressInfo(logger: ILoggerComponent.ILogger, log: string): void;
|
6
|
+
/**
|
7
|
+
* If there are more than one project, we print the current project as "progress info"
|
8
|
+
*/
|
9
|
+
export declare function printCurrentProjectStarting(logger: ILoggerComponent.ILogger, project: ProjectUnion, workspace: Workspace): void;
|
4
10
|
export declare function printCommand(logger: ILoggerComponent.ILogger, commandName: string): void;
|
11
|
+
export declare function printWarning(logger: ILoggerComponent.ILogger, warning: string): void;
|
5
12
|
export declare function printSuccess(logger: ILoggerComponent.ILogger, operationSuccessfulMessage: string, summary: string): void;
|
@@ -1,6 +1,10 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.printSuccess = exports.printCommand = exports.printProgressInfo = exports.printProgressStep = void 0;
|
6
|
+
exports.printSuccess = exports.printWarning = exports.printCommand = exports.printCurrentProjectStarting = exports.printProgressInfo = exports.printProgressStep = void 0;
|
7
|
+
const path_1 = __importDefault(require("path"));
|
4
8
|
const log_1 = require("../components/log");
|
5
9
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
6
10
|
const { name, version } = require('../../package.json');
|
@@ -12,10 +16,25 @@ function printProgressInfo(logger, log) {
|
|
12
16
|
logger.log(log_1.colors.dim(log));
|
13
17
|
}
|
14
18
|
exports.printProgressInfo = printProgressInfo;
|
19
|
+
/**
|
20
|
+
* If there are more than one project, we print the current project as "progress info"
|
21
|
+
*/
|
22
|
+
function printCurrentProjectStarting(logger, project, workspace) {
|
23
|
+
if (workspace.projects.length > 1) {
|
24
|
+
const relativePath = path_1.default.relative(workspace.rootWorkingDirectory, project.workingDirectory);
|
25
|
+
const progress = log_1.colors.dim(`[${workspace.projects.indexOf(project) + 1}/${workspace.projects.length}]`);
|
26
|
+
logger.log(log_1.colors.cyan(`in ${relativePath} ${progress}`));
|
27
|
+
}
|
28
|
+
}
|
29
|
+
exports.printCurrentProjectStarting = printCurrentProjectStarting;
|
15
30
|
function printCommand(logger, commandName) {
|
16
31
|
logger.log(log_1.colors.bold(`${name} ${commandName} v${version}`));
|
17
32
|
}
|
18
33
|
exports.printCommand = printCommand;
|
34
|
+
function printWarning(logger, warning) {
|
35
|
+
logger.log(log_1.colors.bgBlack(log_1.colors.yellow(log_1.colors.bold(`⚠️ WARNING!`) + ' ' + warning)));
|
36
|
+
}
|
37
|
+
exports.printWarning = printWarning;
|
19
38
|
function printSuccess(logger, operationSuccessfulMessage, summary) {
|
20
39
|
// print a space before the success callout
|
21
40
|
logger.log('');
|
package/dist/logic/bundle.d.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import esbuild from 'esbuild';
|
2
2
|
import { CliComponents } from '../components';
|
3
|
+
import { Scene } from '@dcl/schemas';
|
3
4
|
export type BundleComponents = Pick<CliComponents, 'logger' | 'fs'>;
|
4
5
|
export type SceneJson = {
|
5
6
|
main: string;
|
@@ -12,7 +13,7 @@ export type CompileOptions = {
|
|
12
13
|
workingDirectory: string;
|
13
14
|
emitDeclaration: boolean;
|
14
15
|
};
|
15
|
-
export declare function bundleProject(components: BundleComponents, options: CompileOptions): Promise<{
|
16
|
+
export declare function bundleProject(components: BundleComponents, options: CompileOptions, sceneJson: Scene): Promise<{
|
16
17
|
context: esbuild.BuildContext<{
|
17
18
|
entryPoints: string[];
|
18
19
|
bundle: true;
|
@@ -48,5 +49,5 @@ export declare function bundleProject(components: BundleComponents, options: Com
|
|
48
49
|
hashbang: false;
|
49
50
|
};
|
50
51
|
}>;
|
51
|
-
sceneJson:
|
52
|
+
sceneJson: Scene;
|
52
53
|
}>;
|
package/dist/logic/bundle.js
CHANGED
@@ -11,17 +11,14 @@ const esbuild_1 = __importDefault(require("esbuild"));
|
|
11
11
|
const child_process_1 = __importDefault(require("child_process"));
|
12
12
|
const fp_future_1 = require("fp-future");
|
13
13
|
const error_1 = require("./error");
|
14
|
-
const scene_validations_1 = require("./scene-validations");
|
15
14
|
const path_1 = require("path");
|
16
15
|
const beautiful_logs_1 = require("./beautiful-logs");
|
17
16
|
const log_1 = require("../components/log");
|
18
17
|
const url_1 = require("url");
|
19
18
|
const glob_1 = require("glob");
|
20
|
-
const MAX_STEP =
|
21
|
-
async function bundleProject(components, options) {
|
22
|
-
const sceneJson = await (0, scene_validations_1.getValidSceneJson)(components, options.workingDirectory);
|
19
|
+
const MAX_STEP = 2;
|
20
|
+
async function bundleProject(components, options, sceneJson) {
|
23
21
|
const tsconfig = (0, path_1.join)(options.workingDirectory, 'tsconfig.json');
|
24
|
-
(0, beautiful_logs_1.printProgressStep)(components.logger, `Validating project structure`, 1, MAX_STEP);
|
25
22
|
if (!options.single && !sceneJson.main) {
|
26
23
|
throw new error_1.CliError('scene.json .main must be present');
|
27
24
|
}
|
@@ -31,12 +28,12 @@ async function bundleProject(components, options) {
|
|
31
28
|
if (!(await components.fs.fileExists(tsconfig))) {
|
32
29
|
throw new error_1.CliError(`File ${tsconfig} must exist to compile the Typescript project`);
|
33
30
|
}
|
34
|
-
const input = (0, glob_1.globSync)(options.single ?? 'src/index.ts');
|
31
|
+
const input = (0, glob_1.globSync)(options.single ?? 'src/index.ts', { cwd: options.workingDirectory, absolute: true });
|
35
32
|
if (!input.length)
|
36
33
|
throw new error_1.CliError(`There are no input files to build: ${options.single ?? 'src/index.ts'}`);
|
37
34
|
const output = !options.single ? sceneJson.main : options.single.replace(/\.ts$/, '.js');
|
38
35
|
const outfile = (0, path_1.join)(options.workingDirectory, output);
|
39
|
-
(0, beautiful_logs_1.printProgressStep)(components.logger, `Bundling file ${log_1.colors.bold(input.join(','))}`,
|
36
|
+
(0, beautiful_logs_1.printProgressStep)(components.logger, `Bundling file ${log_1.colors.bold(input.join(','))}`, 1, MAX_STEP);
|
40
37
|
const context = await esbuild_1.default.context({
|
41
38
|
entryPoints: input,
|
42
39
|
bundle: true,
|
@@ -105,7 +102,7 @@ function runTypeChecker(components, options) {
|
|
105
102
|
];
|
106
103
|
if (options.watch)
|
107
104
|
args.push('--watch');
|
108
|
-
(0, beautiful_logs_1.printProgressStep)(components.logger, `Running type checker`,
|
105
|
+
(0, beautiful_logs_1.printProgressStep)(components.logger, `Running type checker`, 2, MAX_STEP);
|
109
106
|
const ts = child_process_1.default.spawn('node', args, { env: process.env, cwd: options.workingDirectory });
|
110
107
|
const typeCheckerFuture = (0, fp_future_1.future)();
|
111
108
|
ts.on('close', (code) => {
|
package/dist/logic/dcl-ignore.js
CHANGED
@@ -28,7 +28,8 @@ exports.defaultDclIgnore = [
|
|
28
28
|
];
|
29
29
|
async function getDCLIgnoreFileContents(components, dir) {
|
30
30
|
try {
|
31
|
-
return components.fs.readFile(path_1.default.resolve(dir, '.dclignore'), 'utf8');
|
31
|
+
return await components.fs.readFile(path_1.default.resolve(dir, '.dclignore'), 'utf8');
|
32
|
+
// ^^^^^ never remove that await.
|
32
33
|
}
|
33
34
|
catch (e) { }
|
34
35
|
return null;
|
@@ -1,14 +1,19 @@
|
|
1
1
|
import { Scene } from '@dcl/schemas';
|
2
2
|
import { CliComponents } from '../components';
|
3
|
+
export type BaseProject = {
|
4
|
+
workingDirectory: string;
|
5
|
+
};
|
6
|
+
export type SceneProject = {
|
7
|
+
kind: 'scene';
|
8
|
+
scene: Scene;
|
9
|
+
} & BaseProject;
|
10
|
+
export type ProjectUnion = SceneProject;
|
3
11
|
/**
|
4
|
-
* Asserts that the
|
12
|
+
* Asserts that the workingDirectory is a valid project
|
5
13
|
*/
|
6
|
-
export declare function assertValidProjectFolder(components: Pick<CliComponents, 'fs' | 'logger'>,
|
7
|
-
|
8
|
-
|
9
|
-
export declare function needsDependencies(components: Pick<CliComponents, 'fs'>, dir: string): Promise<boolean>;
|
10
|
-
export declare const npm: string;
|
11
|
-
export declare function installDependencies(components: Pick<CliComponents, 'logger' | 'spawner'>, directory: string): Promise<void>;
|
14
|
+
export declare function assertValidProjectFolder(components: Pick<CliComponents, 'fs' | 'logger'>, workingDirectory: string): Promise<ProjectUnion>;
|
15
|
+
export declare function needsDependencies(components: Pick<CliComponents, 'fs'>, workingDirectory: string): Promise<boolean>;
|
16
|
+
export declare function installDependencies(components: Pick<CliComponents, 'logger' | 'spawner' | 'fs'>, workingDirectory: string): Promise<void>;
|
12
17
|
/**
|
13
18
|
* Run NPM commands
|
14
19
|
*/
|
@@ -1,24 +1,30 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.npmRun = exports.installDependencies = exports.
|
4
|
-
const path_1 = require("path");
|
6
|
+
exports.npmRun = exports.installDependencies = exports.needsDependencies = exports.assertValidProjectFolder = void 0;
|
7
|
+
const path_1 = __importDefault(require("path"));
|
8
|
+
const log_1 = require("../components/log");
|
9
|
+
const beautiful_logs_1 = require("./beautiful-logs");
|
5
10
|
const error_1 = require("./error");
|
6
11
|
const scene_validations_1 = require("./scene-validations");
|
7
12
|
/**
|
8
|
-
* Asserts that the
|
13
|
+
* Asserts that the workingDirectory is a valid project
|
9
14
|
*/
|
10
|
-
async function assertValidProjectFolder(components,
|
15
|
+
async function assertValidProjectFolder(components, workingDirectory) {
|
11
16
|
// no validations for now, only check that it exists
|
12
|
-
if (!(await components.fs.fileExists(
|
17
|
+
if (!(await components.fs.fileExists(path_1.default.resolve(workingDirectory, 'package.json'))))
|
13
18
|
throw new error_1.CliError(`The project root doesn't have a package.json file`);
|
14
19
|
// now we will iterate over different file to evaluate the project kind
|
15
20
|
switch (true) {
|
16
|
-
// case wearable
|
17
|
-
case
|
18
|
-
|
21
|
+
// TODO: case wearable
|
22
|
+
// case scene
|
23
|
+
case await components.fs.fileExists((0, scene_validations_1.getSceneFilePath)(workingDirectory)): {
|
24
|
+
return { kind: 'scene', scene: await (0, scene_validations_1.getValidSceneJson)(components, workingDirectory), workingDirectory };
|
19
25
|
}
|
20
26
|
default: {
|
21
|
-
throw new error_1.CliError(`UnknownProjectKind: the kind of project of the folder ${
|
27
|
+
throw new error_1.CliError(`UnknownProjectKind: the kind of project of the folder ${workingDirectory} cannot be identified`);
|
22
28
|
}
|
23
29
|
}
|
24
30
|
}
|
@@ -26,23 +32,23 @@ exports.assertValidProjectFolder = assertValidProjectFolder;
|
|
26
32
|
/*
|
27
33
|
* Returns true if the project contains an empty node_modules folder
|
28
34
|
*/
|
29
|
-
async function needsDependencies(components,
|
30
|
-
const nodeModulesPath =
|
35
|
+
async function needsDependencies(components, workingDirectory) {
|
36
|
+
const nodeModulesPath = path_1.default.join(workingDirectory, 'node_modules');
|
31
37
|
const hasNodeModulesFolder = await components.fs.directoryExists(nodeModulesPath);
|
32
38
|
const isNodeModulesEmpty = hasNodeModulesFolder && (await components.fs.readdir(nodeModulesPath)).length === 0;
|
33
39
|
return !hasNodeModulesFolder || isNodeModulesEmpty;
|
34
40
|
}
|
35
41
|
exports.needsDependencies = needsDependencies;
|
36
42
|
/* istanbul ignore next */
|
37
|
-
|
43
|
+
const npmBin = /^win/.test(process.platform) ? 'npm.cmd' : 'npm';
|
38
44
|
/*
|
39
45
|
* Runs "npm install" for desired project
|
40
46
|
*/
|
41
|
-
async function installDependencies(components,
|
42
|
-
components.logger
|
47
|
+
async function installDependencies(components, workingDirectory) {
|
48
|
+
(0, beautiful_logs_1.printProgressInfo)(components.logger, 'Installing dependencies...');
|
43
49
|
// TODO: test in windows
|
44
|
-
await components.spawner.exec(
|
45
|
-
components.logger.
|
50
|
+
await components.spawner.exec(workingDirectory, npmBin, ['install']);
|
51
|
+
(0, beautiful_logs_1.printProgressInfo)(components.logger, log_1.colors.white('✅ Installing dependencies...'));
|
46
52
|
}
|
47
53
|
exports.installDependencies = installDependencies;
|
48
54
|
/**
|
@@ -50,6 +56,6 @@ exports.installDependencies = installDependencies;
|
|
50
56
|
*/
|
51
57
|
async function npmRun(components, cwd, command, ...args) {
|
52
58
|
// TODO: test in windows
|
53
|
-
await components.spawner.exec(cwd,
|
59
|
+
await components.spawner.exec(cwd, npmBin, ['run', command, '--silent', '--', ...args], { env: process.env });
|
54
60
|
}
|
55
61
|
exports.npmRun = npmRun;
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import { JSONSchema, ValidateFunction } from '@dcl/schemas';
|
2
|
+
import { CliComponents } from '../components';
|
3
|
+
import { ProjectUnion } from './project-validations';
|
4
|
+
export type WorkspaceJson = {
|
5
|
+
folders: Array<{
|
6
|
+
path: string;
|
7
|
+
}>;
|
8
|
+
};
|
9
|
+
export declare namespace WorkspaceJson {
|
10
|
+
const schema: JSONSchema<WorkspaceJson>;
|
11
|
+
const validate: ValidateFunction<WorkspaceJson>;
|
12
|
+
}
|
13
|
+
export type Workspace = {
|
14
|
+
rootWorkingDirectory: string;
|
15
|
+
projects: Array<ProjectUnion>;
|
16
|
+
};
|
17
|
+
/**
|
18
|
+
* Composes the path to the `dcl-workspace.json` file based on the provided path.
|
19
|
+
* @param projectRoot The path to the directory containing the file.
|
20
|
+
*/
|
21
|
+
export declare function getWorkspaceFilePath(projectRoot: string): string;
|
22
|
+
export declare function assertValidWorkspace(workspace: WorkspaceJson): void;
|
23
|
+
export declare function workspaceFromFolders(components: Pick<CliComponents, 'fs' | 'logger'>, workingDirectory: string, folders: string[]): Promise<Workspace>;
|
24
|
+
/**
|
25
|
+
* Returns a workspace by loading the workspace file or generating a single-folder workspace on the fly.
|
26
|
+
*/
|
27
|
+
export declare function getValidWorkspace(components: Pick<CliComponents, 'fs' | 'logger'>, projectRoot: string): Promise<Workspace>;
|
@@ -0,0 +1,122 @@
|
|
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.getValidWorkspace = exports.workspaceFromFolders = exports.assertValidWorkspace = exports.getWorkspaceFilePath = exports.WorkspaceJson = void 0;
|
27
|
+
const path_1 = __importStar(require("path"));
|
28
|
+
const schemas_1 = require("@dcl/schemas");
|
29
|
+
const error_1 = require("./error");
|
30
|
+
const project_validations_1 = require("./project-validations");
|
31
|
+
var WorkspaceJson;
|
32
|
+
(function (WorkspaceJson) {
|
33
|
+
WorkspaceJson.schema = {
|
34
|
+
type: 'object',
|
35
|
+
additionalProperties: true,
|
36
|
+
properties: {
|
37
|
+
folders: {
|
38
|
+
type: 'array',
|
39
|
+
minItems: 1,
|
40
|
+
items: {
|
41
|
+
type: 'object',
|
42
|
+
properties: {
|
43
|
+
path: {
|
44
|
+
type: 'string'
|
45
|
+
}
|
46
|
+
},
|
47
|
+
required: ['path'],
|
48
|
+
additionalProperties: true
|
49
|
+
}
|
50
|
+
}
|
51
|
+
},
|
52
|
+
required: ['folders']
|
53
|
+
};
|
54
|
+
WorkspaceJson.validate = (0, schemas_1.generateLazyValidator)(WorkspaceJson.schema);
|
55
|
+
})(WorkspaceJson = exports.WorkspaceJson || (exports.WorkspaceJson = {}));
|
56
|
+
// this is "overridable" by env var to test integrations like ".code-workspace" instead
|
57
|
+
const WORKSPACE_FILE = process.env.WORKSPACE_FILE || 'dcl-workspace.json';
|
58
|
+
/**
|
59
|
+
* Composes the path to the `dcl-workspace.json` file based on the provided path.
|
60
|
+
* @param projectRoot The path to the directory containing the file.
|
61
|
+
*/
|
62
|
+
function getWorkspaceFilePath(projectRoot) {
|
63
|
+
return (0, path_1.resolve)(projectRoot, WORKSPACE_FILE);
|
64
|
+
}
|
65
|
+
exports.getWorkspaceFilePath = getWorkspaceFilePath;
|
66
|
+
/* istanbul ignore next */
|
67
|
+
function assertValidWorkspace(workspace) {
|
68
|
+
if (!WorkspaceJson.validate(workspace)) {
|
69
|
+
const errors = [];
|
70
|
+
/* istanbul ignore if */
|
71
|
+
if (WorkspaceJson.validate.errors) {
|
72
|
+
for (const error of WorkspaceJson.validate.errors) {
|
73
|
+
errors.push(`Error validating ${WORKSPACE_FILE}: ${error.message}`);
|
74
|
+
}
|
75
|
+
}
|
76
|
+
/* istanbul ignore next */
|
77
|
+
throw new error_1.CliError(`Invalid ${WORKSPACE_FILE} file:\n${errors.join('\n')}`);
|
78
|
+
}
|
79
|
+
}
|
80
|
+
exports.assertValidWorkspace = assertValidWorkspace;
|
81
|
+
// This function takes a list of folders and returns a workspace containing the projects in the folders.
|
82
|
+
// The working directory of each project is the absolute path of the folder.
|
83
|
+
// The root working directory of the workspace is the absolute path of the working directory.
|
84
|
+
async function workspaceFromFolders(components, workingDirectory, folders) {
|
85
|
+
const ret = {
|
86
|
+
rootWorkingDirectory: workingDirectory,
|
87
|
+
projects: []
|
88
|
+
};
|
89
|
+
for (const folder of folders) {
|
90
|
+
const wd = path_1.default.resolve(workingDirectory, folder);
|
91
|
+
const project = await (0, project_validations_1.assertValidProjectFolder)(components, wd);
|
92
|
+
ret.projects.push(project);
|
93
|
+
}
|
94
|
+
return ret;
|
95
|
+
}
|
96
|
+
exports.workspaceFromFolders = workspaceFromFolders;
|
97
|
+
/**
|
98
|
+
* Returns a workspace by loading the workspace file or generating a single-folder workspace on the fly.
|
99
|
+
*/
|
100
|
+
async function getValidWorkspace(components, projectRoot) {
|
101
|
+
const workingDirectory = path_1.default.resolve(projectRoot);
|
102
|
+
const workspaceFile = getWorkspaceFilePath(workingDirectory);
|
103
|
+
if (await components.fs.fileExists(workspaceFile)) {
|
104
|
+
// either we load a workspace
|
105
|
+
try {
|
106
|
+
const workspaceJsonRaw = await components.fs.readFile(workspaceFile, 'utf8');
|
107
|
+
const workspaceJson = JSON.parse(workspaceJsonRaw);
|
108
|
+
// assert valid data structure
|
109
|
+
assertValidWorkspace(workspaceJson);
|
110
|
+
return await workspaceFromFolders(components, workingDirectory, workspaceJson.folders.map((f) => f.path));
|
111
|
+
}
|
112
|
+
catch (err) {
|
113
|
+
/* istanbul ignore next */
|
114
|
+
throw new error_1.CliError(`Error reading the ${getWorkspaceFilePath(workingDirectory)} file: ${err.message}`);
|
115
|
+
}
|
116
|
+
}
|
117
|
+
else {
|
118
|
+
// or generate a single-folder workspace on the fly
|
119
|
+
return await workspaceFromFolders(components, workingDirectory, ['.']);
|
120
|
+
}
|
121
|
+
}
|
122
|
+
exports.getValidWorkspace = getValidWorkspace;
|
package/package.json
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
{
|
2
2
|
"name": "@dcl/sdk-commands",
|
3
3
|
"description": "",
|
4
|
-
"version": "7.1.4-
|
4
|
+
"version": "7.1.4-4619276636.commit-e2c17cb",
|
5
5
|
"author": "Decentraland",
|
6
6
|
"bin": {
|
7
7
|
"sdk-commands": "./dist/index.js"
|
8
8
|
},
|
9
9
|
"dependencies": {
|
10
10
|
"@dcl/hashing": "1.1.3",
|
11
|
-
"@dcl/inspector": "7.1.4-
|
11
|
+
"@dcl/inspector": "7.1.4-4619276636.commit-e2c17cb",
|
12
12
|
"@dcl/linker-dapp": "0.7.0",
|
13
13
|
"@dcl/mini-comms": "1.0.1-20230216163137.commit-a4c75be",
|
14
14
|
"@dcl/protocol": "1.0.0-4597420155.commit-e877adc",
|
@@ -60,5 +60,5 @@
|
|
60
60
|
"displayName": "SDK",
|
61
61
|
"tsconfig": "./tsconfig.json"
|
62
62
|
},
|
63
|
-
"commit": "
|
63
|
+
"commit": "e2c17cba10c6b7e6f69dd012ea03ecc6d245fd01"
|
64
64
|
}
|