@dcl/sdk-commands 7.1.4-4619276636.commit-e2c17cb → 7.1.4-4622328580.commit-fe88e6c
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 +5 -8
- package/dist/commands/build/index.js +5 -6
- package/dist/commands/deploy/index.d.ts +5 -8
- package/dist/commands/deploy/index.js +5 -6
- package/dist/commands/deploy/linker-dapp/api.js +1 -1
- package/dist/commands/export-static/index.d.ts +6 -8
- package/dist/commands/export-static/index.js +32 -26
- package/dist/commands/init/index.d.ts +4 -7
- package/dist/commands/init/index.js +2 -2
- package/dist/commands/start/index.d.ts +5 -8
- package/dist/commands/start/index.js +15 -16
- package/dist/commands/start/server/endpoints.js +8 -6
- package/dist/components/analytics.d.ts +0 -7
- package/dist/index.d.ts +1 -6
- package/dist/index.js +7 -40
- package/dist/logic/args.d.ts +2 -8
- package/dist/logic/args.js +15 -14
- package/dist/logic/beautiful-logs.d.ts +1 -0
- package/dist/logic/beautiful-logs.js +6 -2
- package/dist/logic/bundle.js +9 -1
- package/dist/logic/commands.js +6 -4
- package/dist/logic/dcl-ignore.js +0 -1
- package/dist/logic/get-free-port.d.ts +1 -1
- package/dist/logic/get-free-port.js +2 -2
- package/dist/logic/project-files.d.ts +15 -3
- package/dist/logic/project-files.js +28 -14
- package/dist/logic/workspace-validations.js +0 -1
- package/dist/run-command.d.ts +7 -0
- package/dist/run-command.js +73 -0
- package/package.json +3 -3
@@ -1,14 +1,11 @@
|
|
1
1
|
import { CliComponents } from '../../components';
|
2
2
|
import { SceneProject } from '../../logic/project-validations';
|
3
|
+
import { Result } from 'arg';
|
3
4
|
interface Options {
|
4
|
-
args: typeof args
|
5
|
+
args: Result<typeof args>;
|
5
6
|
components: Pick<CliComponents, 'fs' | 'logger' | 'analytics' | 'spawner'>;
|
6
7
|
}
|
7
|
-
export declare const args:
|
8
|
-
'--help': BooleanConstructor;
|
9
|
-
'--json': BooleanConstructor;
|
10
|
-
'-h': string;
|
11
|
-
} & {
|
8
|
+
export declare const args: {
|
12
9
|
'--watch': BooleanConstructor;
|
13
10
|
'-w': string;
|
14
11
|
'--production': BooleanConstructor;
|
@@ -17,8 +14,8 @@ export declare const args: import("arg").Result<{
|
|
17
14
|
'-p': string;
|
18
15
|
'--skip-install': BooleanConstructor;
|
19
16
|
'--dir': StringConstructor;
|
20
|
-
}
|
21
|
-
export declare function help():
|
17
|
+
};
|
18
|
+
export declare function help(options: Options): void;
|
22
19
|
export declare function main(options: Options): Promise<void>;
|
23
20
|
export declare function buildScene(options: Options, project: SceneProject): Promise<void>;
|
24
21
|
export {};
|
@@ -12,7 +12,7 @@ const project_files_1 = require("../../logic/project-files");
|
|
12
12
|
const bundle_1 = require("../../logic/bundle");
|
13
13
|
const beautiful_logs_1 = require("../../logic/beautiful-logs");
|
14
14
|
const workspace_validations_1 = require("../../logic/workspace-validations");
|
15
|
-
exports.args = (0, args_1.
|
15
|
+
exports.args = (0, args_1.declareArgs)({
|
16
16
|
'--watch': Boolean,
|
17
17
|
'-w': '--watch',
|
18
18
|
'--production': Boolean,
|
@@ -22,8 +22,8 @@ exports.args = (0, args_1.getArgs)({
|
|
22
22
|
'--skip-install': Boolean,
|
23
23
|
'--dir': String
|
24
24
|
});
|
25
|
-
function help() {
|
26
|
-
|
25
|
+
function help(options) {
|
26
|
+
options.components.logger.log(`
|
27
27
|
Usage: 'sdk-commands build [options]'
|
28
28
|
Options:'
|
29
29
|
-h, --help Displays complete help
|
@@ -35,7 +35,7 @@ function help() {
|
|
35
35
|
Example:
|
36
36
|
- Build your scene:
|
37
37
|
'$ sdk-commands build'
|
38
|
-
|
38
|
+
`);
|
39
39
|
}
|
40
40
|
exports.help = help;
|
41
41
|
async function main(options) {
|
@@ -66,8 +66,7 @@ async function buildScene(options, project) {
|
|
66
66
|
options.components.analytics.track('Build scene', {
|
67
67
|
projectHash: await (0, project_files_1.b64HashingFunction)(project.workingDirectory),
|
68
68
|
coords,
|
69
|
-
isWorkspace: false
|
70
|
-
args: (0, args_1.getArgsUsed)(options.args)
|
69
|
+
isWorkspace: false
|
71
70
|
});
|
72
71
|
}
|
73
72
|
exports.buildScene = buildScene;
|
@@ -1,13 +1,10 @@
|
|
1
1
|
import { CliComponents } from '../../components';
|
2
|
+
import { Result } from 'arg';
|
2
3
|
interface Options {
|
3
|
-
args: typeof args
|
4
|
+
args: Result<typeof args>;
|
4
5
|
components: CliComponents;
|
5
6
|
}
|
6
|
-
export declare const args:
|
7
|
-
'--help': BooleanConstructor;
|
8
|
-
'--json': BooleanConstructor;
|
9
|
-
'-h': string;
|
10
|
-
} & {
|
7
|
+
export declare const args: {
|
11
8
|
'--dir': StringConstructor;
|
12
9
|
'--help': BooleanConstructor;
|
13
10
|
'-h': string;
|
@@ -25,7 +22,7 @@ export declare const args: import("arg").Result<{
|
|
25
22
|
'-b': string;
|
26
23
|
'--port': NumberConstructor;
|
27
24
|
'-p': string;
|
28
|
-
}
|
29
|
-
export declare function help():
|
25
|
+
};
|
26
|
+
export declare function help(options: Options): void;
|
30
27
|
export declare function main(options: Options): Promise<void>;
|
31
28
|
export {};
|
@@ -15,7 +15,7 @@ const error_1 = require("../../logic/error");
|
|
15
15
|
const beautiful_logs_1 = require("../../logic/beautiful-logs");
|
16
16
|
const account_1 = require("../../logic/account");
|
17
17
|
const project_files_1 = require("../../logic/project-files");
|
18
|
-
exports.args = (0, args_1.
|
18
|
+
exports.args = (0, args_1.declareArgs)({
|
19
19
|
'--dir': String,
|
20
20
|
'--help': Boolean,
|
21
21
|
'-h': '--help',
|
@@ -34,8 +34,8 @@ exports.args = (0, args_1.getArgs)({
|
|
34
34
|
'--port': Number,
|
35
35
|
'-p': '--port'
|
36
36
|
});
|
37
|
-
function help() {
|
38
|
-
|
37
|
+
function help(options) {
|
38
|
+
options.components.logger.log(`
|
39
39
|
Usage: 'sdk-commands build [options]'
|
40
40
|
Options:
|
41
41
|
-h, --help Displays complete help
|
@@ -52,7 +52,7 @@ function help() {
|
|
52
52
|
$ sdk-commands deploy
|
53
53
|
- Deploy your scene to a specific content server:
|
54
54
|
$ sdk-commands deploy --target my-favorite-catalyst-server.org:2323
|
55
|
-
|
55
|
+
`);
|
56
56
|
}
|
57
57
|
exports.help = help;
|
58
58
|
async function main(options) {
|
@@ -69,8 +69,7 @@ async function main(options) {
|
|
69
69
|
const trackProps = {
|
70
70
|
projectHash: await (0, project_files_1.b64HashingFunction)(projectRoot),
|
71
71
|
coords,
|
72
|
-
isWorld
|
73
|
-
args: (0, args_1.getArgsUsed)(options.args)
|
72
|
+
isWorld
|
74
73
|
};
|
75
74
|
const packageJson = await (0, project_files_1.getPackageJson)(options.components, projectRoot);
|
76
75
|
const dependencies = Array.from(new Set([...Object.keys(packageJson.dependencies || {}), ...Object.keys(packageJson.devDependencies || {})]));
|
@@ -18,7 +18,7 @@ const routes_1 = require("./routes");
|
|
18
18
|
const config_1 = require("../../../logic/config");
|
19
19
|
function runLinkerApp(cliComponents, scene, files, port, rootCID, { isHttps, skipValidations, openBrowser }) {
|
20
20
|
return new Promise(async (resolve) => {
|
21
|
-
const resolvedPort = await (0, get_free_port_1.getPort)(port
|
21
|
+
const resolvedPort = await (0, get_free_port_1.getPort)(port);
|
22
22
|
const sceneInfo = await getSceneInfo(cliComponents, scene, rootCID, skipValidations);
|
23
23
|
const protocol = isHttps ? 'https' : 'http';
|
24
24
|
const queryParams = querystring_1.default.stringify(sceneInfo);
|
@@ -1,24 +1,22 @@
|
|
1
1
|
import { CliComponents } from '../../components';
|
2
2
|
import { SceneProject } from '../../logic/project-validations';
|
3
|
+
import { Result } from 'arg';
|
3
4
|
interface Options {
|
4
|
-
args: typeof args
|
5
|
+
args: Result<typeof args>;
|
5
6
|
components: Pick<CliComponents, 'fetch' | 'fs' | 'logger' | 'analytics' | 'config'>;
|
6
7
|
}
|
7
|
-
export declare const args:
|
8
|
-
'--help': BooleanConstructor;
|
9
|
-
'--json': BooleanConstructor;
|
10
|
-
'-h': string;
|
11
|
-
} & {
|
8
|
+
export declare const args: {
|
12
9
|
'--dir': StringConstructor;
|
13
10
|
'--destination': StringConstructor;
|
14
11
|
'--timestamp': StringConstructor;
|
15
12
|
'--realmName': StringConstructor;
|
16
13
|
'--baseUrl': StringConstructor;
|
17
|
-
}
|
18
|
-
export declare function help(): Promise<
|
14
|
+
};
|
15
|
+
export declare function help(options: Options): Promise<void>;
|
19
16
|
export declare function main(options: Options): Promise<{
|
20
17
|
scenesUrn: string[];
|
21
18
|
destination: string;
|
19
|
+
entities: string[];
|
22
20
|
}>;
|
23
21
|
export declare function prepareSceneFiles(options: Options, project: SceneProject, outputDirectory: string): Promise<{
|
24
22
|
urn: string;
|
@@ -15,15 +15,15 @@ const beautiful_logs_1 = require("../../logic/beautiful-logs");
|
|
15
15
|
const realm_1 = require("../../logic/realm");
|
16
16
|
const scene_validations_1 = require("../../logic/scene-validations");
|
17
17
|
const workspace_validations_1 = require("../../logic/workspace-validations");
|
18
|
-
exports.args = (0, args_1.
|
18
|
+
exports.args = (0, args_1.declareArgs)({
|
19
19
|
'--dir': String,
|
20
20
|
'--destination': String,
|
21
21
|
'--timestamp': String,
|
22
22
|
'--realmName': String,
|
23
23
|
'--baseUrl': String
|
24
24
|
});
|
25
|
-
async function help() {
|
26
|
-
|
25
|
+
async function help(options) {
|
26
|
+
options.components.logger.log(`
|
27
27
|
Usage:
|
28
28
|
sdk-commands export-static --dir <directory> --destination <directory>
|
29
29
|
|
@@ -38,103 +38,109 @@ async function help() {
|
|
38
38
|
--timestamp <timestamp> A date to use in the deployable entity. Defaults to now()
|
39
39
|
--realmName <name> Creates a /<name>/about endpoint to expose the current deployment as a realm. Requires --baseUrl
|
40
40
|
--baseUrl <baseUrl> It is the public URL in which the --destination directory will be avaiable
|
41
|
-
|
41
|
+
`);
|
42
42
|
}
|
43
43
|
exports.help = help;
|
44
44
|
async function main(options) {
|
45
45
|
const { fs, logger } = options.components;
|
46
46
|
const workingDirectory = path_1.default.resolve(process.cwd(), options.args['--dir'] || '.');
|
47
47
|
const outputDirectory = path_1.default.resolve(process.cwd(), options.args['--destination'] || '.');
|
48
|
-
const willCreateRealm = !!
|
48
|
+
const willCreateRealm = !!options.args['--realmName'];
|
49
49
|
let currentStep = 1;
|
50
50
|
const maxSteps = 1 + (willCreateRealm ? 1 : 0);
|
51
|
-
|
51
|
+
/* istanbul ignore if */
|
52
|
+
if (willCreateRealm && !options.args['--baseUrl']) {
|
52
53
|
throw new error_1.CliError(`--baseUrl is mandatory when --realmName is provided`);
|
53
54
|
}
|
54
|
-
|
55
|
+
/* istanbul ignore if */
|
56
|
+
if (willCreateRealm && !/^[a-z][a-z0-9-/]*$/i.test(options.args['--realmName'])) {
|
55
57
|
throw new error_1.CliError(`--realmName has invalid characters`);
|
56
58
|
}
|
57
|
-
(0, beautiful_logs_1.printProgressStep)(logger, 'Reading project files...', currentStep++, maxSteps);
|
58
59
|
await fs.mkdir(outputDirectory, { recursive: true });
|
60
|
+
/* istanbul ignore if */
|
59
61
|
if (!(await fs.directoryExists(outputDirectory))) {
|
60
62
|
throw new error_1.CliError(`The destination path ${outputDirectory} is not a directory`);
|
61
63
|
}
|
62
64
|
const scenesUrn = [];
|
65
|
+
const entities = [];
|
63
66
|
const workspace = await (0, workspace_validations_1.getValidWorkspace)(options.components, workingDirectory);
|
67
|
+
(0, beautiful_logs_1.printProgressStep)(logger, `Exporting ${workspace.projects.length} project(s)`, currentStep++, maxSteps);
|
64
68
|
for (const project of workspace.projects) {
|
65
69
|
(0, beautiful_logs_1.printCurrentProjectStarting)(options.components.logger, project, workspace);
|
66
70
|
if (project.kind === 'scene') {
|
67
71
|
const result = await prepareSceneFiles(options, project, outputDirectory);
|
68
72
|
scenesUrn.push(result.urn);
|
73
|
+
entities.push(result.entityId);
|
69
74
|
}
|
70
75
|
}
|
71
76
|
if (willCreateRealm) {
|
72
77
|
// prepare the realm object
|
73
78
|
(0, beautiful_logs_1.printProgressStep)(logger, 'Creating realm file...', currentStep++, maxSteps);
|
74
79
|
const realm = await (0, realm_1.createStaticRealm)(options.components);
|
75
|
-
const realmName =
|
80
|
+
const realmName = options.args['--realmName'];
|
76
81
|
realm.configurations.scenesUrn = scenesUrn;
|
77
82
|
realm.configurations.realmName = realmName;
|
78
83
|
// write the realm file
|
79
84
|
const realmDirectory = path_1.default.join(outputDirectory, realmName);
|
80
85
|
await fs.mkdir(realmDirectory, { recursive: true });
|
86
|
+
/* istanbul ignore if */
|
81
87
|
if (!(await fs.directoryExists(realmDirectory))) {
|
82
88
|
throw new error_1.CliError(`The destination path ${realmDirectory} is not a directory`);
|
83
89
|
}
|
84
90
|
const dst = path_1.default.join(realmDirectory, 'about');
|
85
91
|
await fs.writeFile(dst, JSON.stringify(realm, null, 2));
|
86
|
-
(0, beautiful_logs_1.printProgressInfo)(logger, `> ${realmName}/about
|
92
|
+
(0, beautiful_logs_1.printProgressInfo)(logger, `> ${realmName}/about ← [REALM FILE]`);
|
87
93
|
}
|
88
94
|
(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 };
|
95
|
+
return { scenesUrn, destination: outputDirectory, entities };
|
90
96
|
}
|
91
97
|
exports.main = main;
|
92
98
|
async function prepareSceneFiles(options, project, outputDirectory) {
|
93
99
|
const { fs, logger } = options.components;
|
94
|
-
const filesToExport = await (0, project_files_1.
|
100
|
+
const filesToExport = await (0, project_files_1.getProjectPublishableFilesWithHashes)(options.components, project.workingDirectory, async (file) => {
|
95
101
|
return await (0, hashing_1.hashV1)(fs.createReadStream(path_1.default.resolve(project.workingDirectory, file)));
|
96
102
|
});
|
97
|
-
(0, beautiful_logs_1.
|
98
|
-
for (const {
|
99
|
-
const src = path_1.default.resolve(project.workingDirectory, file);
|
103
|
+
(0, beautiful_logs_1.printStep)(logger, 'Exporting static project');
|
104
|
+
for (const { absolutePath, hash } of filesToExport) {
|
100
105
|
const dst = path_1.default.resolve(outputDirectory, hash);
|
101
|
-
if
|
106
|
+
/* istanbul ignore if */
|
107
|
+
if (absolutePath.startsWith(outputDirectory)) {
|
108
|
+
(0, beautiful_logs_1.printWarning)(options.components.logger, `The file ${absolutePath} was omitted because it overwrites an input directory`);
|
102
109
|
continue;
|
103
|
-
|
110
|
+
}
|
111
|
+
(0, beautiful_logs_1.printProgressInfo)(logger, `> ${hash} ← ${log_1.colors.reset(absolutePath)}`);
|
104
112
|
if (!(await fs.fileExists(dst))) {
|
105
|
-
const content = await fs.readFile(
|
113
|
+
const content = await fs.readFile(absolutePath);
|
106
114
|
await fs.writeFile(dst, content);
|
107
115
|
}
|
108
116
|
}
|
109
117
|
// entity with ID are the deployed ones, when we generate the entity the ID is not
|
110
118
|
// available because it is the result of hashing the following structure
|
111
119
|
const entity = {
|
112
|
-
content: filesToExport,
|
120
|
+
content: (0, project_files_1.projectFilesToContentMappings)(project.workingDirectory, filesToExport),
|
113
121
|
pointers: [],
|
114
|
-
timestamp:
|
122
|
+
timestamp: options.args['--timestamp'] ? new Date(options.args['--timestamp']).getTime() : Date.now(),
|
115
123
|
type: schemas_1.EntityType.SCENE,
|
116
124
|
// for now, the only valid export is for scenes
|
117
125
|
metadata: project.scene,
|
118
126
|
version: 'v3'
|
119
127
|
};
|
120
|
-
(0, beautiful_logs_1.printProgressInfo)(logger, 'Generating files...');
|
121
128
|
// create the entity file and get the entityId
|
122
129
|
const entityRaw = Buffer.from(JSON.stringify(entity), 'utf8');
|
123
130
|
const entityId = await (0, hashing_1.hashV1)(entityRaw);
|
124
131
|
const dst = path_1.default.resolve(outputDirectory, entityId);
|
125
132
|
await fs.writeFile(dst, entityRaw);
|
126
|
-
(0, beautiful_logs_1.
|
133
|
+
(0, beautiful_logs_1.printStep)(logger, `> ${entityId} ← ${log_1.colors.reset('[ENTITY FILE]')}`);
|
127
134
|
let urn = `urn:decentraland:entity:${entityId}`;
|
128
|
-
if (
|
129
|
-
urn += '?baseUrl=' +
|
135
|
+
if (options.args['--baseUrl']) {
|
136
|
+
urn += '?baseUrl=' + options.args['--baseUrl'];
|
130
137
|
// baseUrl must end with /
|
131
138
|
if (!urn.endsWith('/'))
|
132
139
|
urn += '/';
|
133
140
|
}
|
134
141
|
options.components.analytics.track('Export static', {
|
135
142
|
projectHash: await (0, project_files_1.b64HashingFunction)(project.workingDirectory),
|
136
|
-
coords: (0, scene_validations_1.getBaseCoords)(project.scene)
|
137
|
-
args: (0, args_1.getArgsUsed)(options.args)
|
143
|
+
coords: (0, scene_validations_1.getBaseCoords)(project.scene)
|
138
144
|
});
|
139
145
|
return { urn, entityId, destination: outputDirectory };
|
140
146
|
}
|
@@ -1,18 +1,15 @@
|
|
1
1
|
import { CliComponents } from '../../components';
|
2
|
+
import { Result } from 'arg';
|
2
3
|
interface Options {
|
3
|
-
args: typeof args
|
4
|
+
args: Result<typeof args>;
|
4
5
|
components: Pick<CliComponents, 'fetch' | 'fs' | 'logger' | 'analytics' | 'spawner'>;
|
5
6
|
}
|
6
|
-
export declare const args:
|
7
|
-
'--help': BooleanConstructor;
|
8
|
-
'--json': BooleanConstructor;
|
9
|
-
'-h': string;
|
10
|
-
} & {
|
7
|
+
export declare const args: {
|
11
8
|
'--yes': BooleanConstructor;
|
12
9
|
'-y': string;
|
13
10
|
'--dir': StringConstructor;
|
14
11
|
'--skip-install': BooleanConstructor;
|
15
|
-
}
|
12
|
+
};
|
16
13
|
export declare function help(): Promise<void>;
|
17
14
|
export declare function main(options: Options): Promise<void>;
|
18
15
|
export {};
|
@@ -7,7 +7,7 @@ const error_1 = require("../../logic/error");
|
|
7
7
|
const fs_1 = require("../../logic/fs");
|
8
8
|
const repos_1 = require("./repos");
|
9
9
|
const project_validations_1 = require("../../logic/project-validations");
|
10
|
-
exports.args = (0, args_1.
|
10
|
+
exports.args = (0, args_1.declareArgs)({
|
11
11
|
'--yes': Boolean,
|
12
12
|
'-y': '--yes',
|
13
13
|
'--dir': String,
|
@@ -34,7 +34,7 @@ async function main(options) {
|
|
34
34
|
if (shouldInstallDeps && !options.args['--skip-install']) {
|
35
35
|
await (0, project_validations_1.installDependencies)(options.components, dir);
|
36
36
|
}
|
37
|
-
options.components.analytics.track('Scene created', { projectType: scene, url
|
37
|
+
options.components.analytics.track('Scene created', { projectType: scene, url });
|
38
38
|
}
|
39
39
|
exports.main = main;
|
40
40
|
const moveFilesFromDir = async (components, dir, folder) => {
|
@@ -1,13 +1,10 @@
|
|
1
1
|
import { CliComponents } from '../../components';
|
2
|
+
import { Result } from 'arg';
|
2
3
|
interface Options {
|
3
|
-
args: typeof args
|
4
|
+
args: Result<typeof args>;
|
4
5
|
components: Pick<CliComponents, 'fetch' | 'fs' | 'logger' | 'analytics' | 'spawner'>;
|
5
6
|
}
|
6
|
-
export declare const args:
|
7
|
-
'--help': BooleanConstructor;
|
8
|
-
'--json': BooleanConstructor;
|
9
|
-
'-h': string;
|
10
|
-
} & {
|
7
|
+
export declare const args: {
|
11
8
|
'--dir': StringConstructor;
|
12
9
|
'--help': BooleanConstructor;
|
13
10
|
'--port': NumberConstructor;
|
@@ -25,7 +22,7 @@ export declare const args: import("arg").Result<{
|
|
25
22
|
'--skip-build': BooleanConstructor;
|
26
23
|
'--desktop-client': BooleanConstructor;
|
27
24
|
'--data-layer': BooleanConstructor;
|
28
|
-
}
|
29
|
-
export declare function help(): Promise<
|
25
|
+
};
|
26
|
+
export declare function help(options: Options): Promise<void>;
|
30
27
|
export declare function main(options: Options): Promise<void>;
|
31
28
|
export {};
|
@@ -50,7 +50,7 @@ const rpc_1 = require("./data-layer/rpc");
|
|
50
50
|
const exit_signal_1 = require("../../components/exit-signal");
|
51
51
|
const workspace_validations_1 = require("../../logic/workspace-validations");
|
52
52
|
const beautiful_logs_1 = require("../../logic/beautiful-logs");
|
53
|
-
exports.args = (0, args_1.
|
53
|
+
exports.args = (0, args_1.declareArgs)({
|
54
54
|
'--dir': String,
|
55
55
|
'--help': Boolean,
|
56
56
|
'--port': Number,
|
@@ -69,8 +69,8 @@ exports.args = (0, args_1.getArgs)({
|
|
69
69
|
'--desktop-client': Boolean,
|
70
70
|
'--data-layer': Boolean
|
71
71
|
});
|
72
|
-
async function help() {
|
73
|
-
|
72
|
+
async function help(options) {
|
73
|
+
options.components.logger.log(`
|
74
74
|
Usage: sdk-commands start [options]
|
75
75
|
|
76
76
|
Options:
|
@@ -94,19 +94,19 @@ async function help() {
|
|
94
94
|
- Start a local development server for a Decentraland Scene at a docker container
|
95
95
|
|
96
96
|
$ sdk-commands start --ci
|
97
|
-
|
97
|
+
`);
|
98
98
|
}
|
99
99
|
exports.help = help;
|
100
100
|
async function main(options) {
|
101
101
|
let baseCoords = { x: 0, y: 0 };
|
102
102
|
const workingDirectory = path.resolve(process.cwd(), options.args['--dir'] || '.');
|
103
|
-
const isCi =
|
104
|
-
const debug = !
|
105
|
-
const openBrowser = !
|
106
|
-
const skipBuild =
|
107
|
-
const watch = !
|
108
|
-
const withDataLayer =
|
109
|
-
const enableWeb3 =
|
103
|
+
const isCi = options.args['--ci'] || process.env.CI || false;
|
104
|
+
const debug = !options.args['--no-debug'] && !isCi;
|
105
|
+
const openBrowser = !options.args['--no-browser'] && !isCi;
|
106
|
+
const skipBuild = options.args['--skip-build'];
|
107
|
+
const watch = !options.args['--no-watch'];
|
108
|
+
const withDataLayer = options.args['--data-layer'];
|
109
|
+
const enableWeb3 = options.args['--web3'];
|
110
110
|
// TODO: FIX this hardcoded values ?
|
111
111
|
const hasPortableExperience = false;
|
112
112
|
const workspace = await (0, workspace_validations_1.getValidWorkspace)(options.components, workingDirectory);
|
@@ -128,12 +128,11 @@ async function main(options) {
|
|
128
128
|
options.components.analytics.track('Preview started', {
|
129
129
|
projectHash: await (0, project_files_1.b64HashingFunction)(project.workingDirectory),
|
130
130
|
coords: baseCoords,
|
131
|
-
isWorkspace: false
|
132
|
-
args: (0, args_1.getArgsUsed)(options.args)
|
131
|
+
isWorkspace: false
|
133
132
|
});
|
134
133
|
}
|
135
134
|
(0, beautiful_logs_1.printProgressInfo)(options.components.logger, 'Starting preview server');
|
136
|
-
const port = await (0, get_free_port_1.getPort)(options.args['--port']);
|
135
|
+
const port = await (0, get_free_port_1.getPort)(options.args['--port'] || 0);
|
137
136
|
const program = await interfaces_1.Lifecycle.run({
|
138
137
|
async initComponents() {
|
139
138
|
const metrics = (0, metrics_1.createTestMetricsComponent)(rooms_1.roomsMetrics);
|
@@ -200,7 +199,7 @@ async function main(options) {
|
|
200
199
|
for (const addr of sortedURLs) {
|
201
200
|
components.logger.log(` ${addr}`);
|
202
201
|
}
|
203
|
-
if (
|
202
|
+
if (options.args['--desktop-client']) {
|
204
203
|
components.logger.log('\n Desktop client:\n');
|
205
204
|
for (const addr of sortedURLs) {
|
206
205
|
const searchParams = new URLSearchParams();
|
@@ -211,7 +210,7 @@ async function main(options) {
|
|
211
210
|
components.logger.log('\n Details:\n');
|
212
211
|
components.logger.log('\nPress CTRL+C to exit\n');
|
213
212
|
// Open preferably localhost/127.0.0.1
|
214
|
-
if (openBrowser && sortedURLs.length && !
|
213
|
+
if (openBrowser && sortedURLs.length && !options.args['--desktop-client']) {
|
215
214
|
try {
|
216
215
|
await (0, open_1.default)(sortedURLs[0]);
|
217
216
|
}
|
@@ -233,14 +233,15 @@ async function serveWearable(components, wearableJsonPath, baseUrl) {
|
|
233
233
|
components.logger.error(`Unable to validate wearable.json properly, please check it.` + errors);
|
234
234
|
throw new Error(`Invalid wearable.json (${wearableJsonPath})`);
|
235
235
|
}
|
236
|
-
const
|
237
|
-
const
|
238
|
-
const
|
236
|
+
const projectFiles = await (0, project_files_1.getProjectPublishableFilesWithHashes)(components, wearableDir, project_files_1.b64HashingFunction);
|
237
|
+
const contentFiles = (0, project_files_1.projectFilesToContentMappings)(wearableDir, projectFiles);
|
238
|
+
const thumbnailFiltered = contentFiles.filter(($) => $.file === 'thumbnail.png');
|
239
|
+
const thumbnail = thumbnailFiltered.length > 0 && thumbnailFiltered[0].hash && `${baseUrl}/${thumbnailFiltered[0].hash}`;
|
239
240
|
const wearableId = 'urn:8dc2d7ad-97e3-44d0-ba89-e8305d795a6a';
|
240
241
|
const representations = wearableJson.data.representations.map((representation) => ({
|
241
242
|
...representation,
|
242
243
|
mainFile: `male/${representation.mainFile}`,
|
243
|
-
contents:
|
244
|
+
contents: contentFiles.map(($) => ({
|
244
245
|
key: `male/${$?.file}`,
|
245
246
|
url: `${baseUrl}/${$?.hash}`,
|
246
247
|
hash: $?.hash
|
@@ -380,7 +381,8 @@ async function fakeEntityV3FromFolder(components, projectRoot, hashingFunction)
|
|
380
381
|
const pointers = new Set();
|
381
382
|
pointers.add(base);
|
382
383
|
parcels.forEach(($) => pointers.add($));
|
383
|
-
const
|
384
|
+
const projectFiles = await (0, project_files_1.getProjectPublishableFilesWithHashes)(components, projectRoot, hashingFunction);
|
385
|
+
const contentFiles = (0, project_files_1.projectFilesToContentMappings)(projectRoot, projectFiles);
|
384
386
|
return {
|
385
387
|
version: 'v3',
|
386
388
|
type: schemas_1.EntityType.SCENE,
|
@@ -388,7 +390,7 @@ async function fakeEntityV3FromFolder(components, projectRoot, hashingFunction)
|
|
388
390
|
pointers: Array.from(pointers),
|
389
391
|
timestamp: Date.now(),
|
390
392
|
metadata: sceneJson,
|
391
|
-
content:
|
393
|
+
content: contentFiles
|
392
394
|
};
|
393
395
|
}
|
394
396
|
return null;
|
@@ -8,7 +8,6 @@ export type Events = {
|
|
8
8
|
'Scene created': {
|
9
9
|
projectType: string;
|
10
10
|
url: string;
|
11
|
-
args: Record<string, unknown>;
|
12
11
|
};
|
13
12
|
'Preview started': {
|
14
13
|
projectHash: string;
|
@@ -17,7 +16,6 @@ export type Events = {
|
|
17
16
|
y: number;
|
18
17
|
};
|
19
18
|
isWorkspace: boolean;
|
20
|
-
args: Record<string, unknown>;
|
21
19
|
};
|
22
20
|
'Build scene': {
|
23
21
|
projectHash: string;
|
@@ -26,7 +24,6 @@ export type Events = {
|
|
26
24
|
y: number;
|
27
25
|
};
|
28
26
|
isWorkspace: boolean;
|
29
|
-
args: Record<string, unknown>;
|
30
27
|
};
|
31
28
|
'Export static': {
|
32
29
|
projectHash: string;
|
@@ -34,7 +31,6 @@ export type Events = {
|
|
34
31
|
x: number;
|
35
32
|
y: number;
|
36
33
|
};
|
37
|
-
args: Record<string, unknown>;
|
38
34
|
};
|
39
35
|
'Scene deploy started': {
|
40
36
|
projectHash: string;
|
@@ -43,7 +39,6 @@ export type Events = {
|
|
43
39
|
y: number;
|
44
40
|
};
|
45
41
|
isWorld: boolean;
|
46
|
-
args: Record<string, unknown>;
|
47
42
|
};
|
48
43
|
'Scene deploy success': {
|
49
44
|
projectHash: string;
|
@@ -52,7 +47,6 @@ export type Events = {
|
|
52
47
|
y: number;
|
53
48
|
};
|
54
49
|
isWorld: boolean;
|
55
|
-
args: Record<string, unknown>;
|
56
50
|
dependencies: string[];
|
57
51
|
};
|
58
52
|
'Scene deploy failure': {
|
@@ -62,7 +56,6 @@ export type Events = {
|
|
62
56
|
y: number;
|
63
57
|
};
|
64
58
|
isWorld: boolean;
|
65
|
-
args: Record<string, unknown>;
|
66
59
|
error: string;
|
67
60
|
};
|
68
61
|
};
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
@@ -2,54 +2,21 @@
|
|
2
2
|
"use strict";
|
3
3
|
/* istanbul ignore file */
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
5
|
-
const args_1 = require("./logic/args");
|
6
5
|
const error_1 = require("./logic/error");
|
7
|
-
const commands_1 = require("./logic/commands");
|
8
6
|
const components_1 = require("./components");
|
9
|
-
const beautiful_logs_1 = require("./logic/beautiful-logs");
|
10
7
|
const log_1 = require("./components/log");
|
11
|
-
const
|
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
|
-
};
|
8
|
+
const run_command_1 = require("./run-command");
|
22
9
|
async function main() {
|
23
|
-
const helpMessage = (commands) => `Here is the list of commands:\n${listCommandsStr(commands)}`;
|
24
|
-
const args = (0, args_1.getArgs)();
|
25
10
|
const command = process.argv[2];
|
26
|
-
const needsHelp = args['--help'];
|
27
11
|
const components = await (0, components_1.initComponents)();
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
return;
|
33
|
-
}
|
34
|
-
throw new error_1.CliError(`Command ${command} is invalid. ${helpMessage(commands)}`);
|
12
|
+
try {
|
13
|
+
// pass on a list of arguments after the command itself
|
14
|
+
const argv = process.argv.slice(3);
|
15
|
+
await (0, run_command_1.runSdkCommand)(components, command, argv);
|
35
16
|
}
|
36
|
-
|
37
|
-
|
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
|
-
}
|
17
|
+
finally {
|
18
|
+
await components.analytics.stop();
|
51
19
|
}
|
52
|
-
await components.analytics.stop();
|
53
20
|
// rollup watcher leaves many open FSWatcher even in build mode. we must call
|
54
21
|
// process.exit at this point to prevent the program halting forever
|
55
22
|
process.exit(process.exitCode || 0);
|
package/dist/logic/args.d.ts
CHANGED
@@ -2,11 +2,5 @@ import { Result } from 'arg';
|
|
2
2
|
export type Args = {
|
3
3
|
[key: string]: string | StringConstructor | NumberConstructor | BooleanConstructor;
|
4
4
|
};
|
5
|
-
export declare
|
6
|
-
|
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>;
|
12
|
-
export declare function getArgsUsed(value: Result<typeof DEFAULT_ARGS>): Record<string, unknown>;
|
5
|
+
export declare function parseArgs<T extends Args>(argv: string[], args: T): Result<T>;
|
6
|
+
export declare function declareArgs<T extends Args>(args: T): T;
|
package/dist/logic/args.js
CHANGED
@@ -3,21 +3,22 @@ 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.
|
6
|
+
exports.declareArgs = exports.parseArgs = void 0;
|
7
7
|
const arg_1 = __importDefault(require("arg"));
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
8
|
+
const error_1 = require("./error");
|
9
|
+
function parseArgs(argv, args) {
|
10
|
+
try {
|
11
|
+
return (0, arg_1.default)({ '--json': Boolean, '-h': '--help', '--help': Boolean, ...args }, { permissive: false, argv });
|
12
|
+
}
|
13
|
+
catch (err) {
|
14
|
+
if (err.name === 'ArgError')
|
15
|
+
throw new error_1.CliError(`Argument error: ` + err.message);
|
16
|
+
/* istanbul ignore next */
|
17
|
+
throw err;
|
18
|
+
}
|
17
19
|
}
|
18
|
-
exports.
|
19
|
-
function
|
20
|
-
const { _, ...args } = value;
|
20
|
+
exports.parseArgs = parseArgs;
|
21
|
+
function declareArgs(args) {
|
21
22
|
return args;
|
22
23
|
}
|
23
|
-
exports.
|
24
|
+
exports.declareArgs = declareArgs;
|
@@ -3,6 +3,7 @@ import { ProjectUnion } from './project-validations';
|
|
3
3
|
import { Workspace } from './workspace-validations';
|
4
4
|
export declare function printProgressStep(logger: ILoggerComponent.ILogger, log: string, currentStep: number, maxStep: number): void;
|
5
5
|
export declare function printProgressInfo(logger: ILoggerComponent.ILogger, log: string): void;
|
6
|
+
export declare function printStep(logger: ILoggerComponent.ILogger, log: string): void;
|
6
7
|
/**
|
7
8
|
* If there are more than one project, we print the current project as "progress info"
|
8
9
|
*/
|
@@ -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.printSuccess = exports.printWarning = exports.printCommand = exports.printCurrentProjectStarting = exports.printProgressInfo = exports.printProgressStep = void 0;
|
6
|
+
exports.printSuccess = exports.printWarning = exports.printCommand = exports.printCurrentProjectStarting = exports.printStep = exports.printProgressInfo = exports.printProgressStep = void 0;
|
7
7
|
const path_1 = __importDefault(require("path"));
|
8
8
|
const log_1 = require("../components/log");
|
9
9
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
@@ -16,6 +16,10 @@ function printProgressInfo(logger, log) {
|
|
16
16
|
logger.log(log_1.colors.dim(log));
|
17
17
|
}
|
18
18
|
exports.printProgressInfo = printProgressInfo;
|
19
|
+
function printStep(logger, log) {
|
20
|
+
logger.log(log);
|
21
|
+
}
|
22
|
+
exports.printStep = printStep;
|
19
23
|
/**
|
20
24
|
* If there are more than one project, we print the current project as "progress info"
|
21
25
|
*/
|
@@ -23,7 +27,7 @@ function printCurrentProjectStarting(logger, project, workspace) {
|
|
23
27
|
if (workspace.projects.length > 1) {
|
24
28
|
const relativePath = path_1.default.relative(workspace.rootWorkingDirectory, project.workingDirectory);
|
25
29
|
const progress = log_1.colors.dim(`[${workspace.projects.indexOf(project) + 1}/${workspace.projects.length}]`);
|
26
|
-
logger.log(log_1.colors.cyan(
|
30
|
+
logger.log(log_1.colors.cyan(`\n${progress} in ${relativePath}:`));
|
27
31
|
}
|
28
32
|
}
|
29
33
|
exports.printCurrentProjectStarting = printCurrentProjectStarting;
|
package/dist/logic/bundle.js
CHANGED
@@ -6,7 +6,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
6
|
};
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
8
8
|
exports.bundleProject = void 0;
|
9
|
-
/* istanbul ignore file */
|
10
9
|
const esbuild_1 = __importDefault(require("esbuild"));
|
11
10
|
const child_process_1 = __importDefault(require("child_process"));
|
12
11
|
const fp_future_1 = require("fp-future");
|
@@ -19,16 +18,20 @@ const glob_1 = require("glob");
|
|
19
18
|
const MAX_STEP = 2;
|
20
19
|
async function bundleProject(components, options, sceneJson) {
|
21
20
|
const tsconfig = (0, path_1.join)(options.workingDirectory, 'tsconfig.json');
|
21
|
+
/* istanbul ignore if */
|
22
22
|
if (!options.single && !sceneJson.main) {
|
23
23
|
throw new error_1.CliError('scene.json .main must be present');
|
24
24
|
}
|
25
|
+
/* istanbul ignore if */
|
25
26
|
if (sceneJson.runtimeVersion !== '7') {
|
26
27
|
throw new error_1.CliError('scene.json `"runtimeVersion": "7"` must be present');
|
27
28
|
}
|
29
|
+
/* istanbul ignore if */
|
28
30
|
if (!(await components.fs.fileExists(tsconfig))) {
|
29
31
|
throw new error_1.CliError(`File ${tsconfig} must exist to compile the Typescript project`);
|
30
32
|
}
|
31
33
|
const input = (0, glob_1.globSync)(options.single ?? 'src/index.ts', { cwd: options.workingDirectory, absolute: true });
|
34
|
+
/* istanbul ignore if */
|
32
35
|
if (!input.length)
|
33
36
|
throw new error_1.CliError(`There are no input files to build: ${options.single ?? 'src/index.ts'}`);
|
34
37
|
const output = !options.single ? sceneJson.main : options.single.replace(/\.ts$/, '.js');
|
@@ -70,6 +73,7 @@ async function bundleProject(components, options, sceneJson) {
|
|
70
73
|
hashbang: false
|
71
74
|
}
|
72
75
|
});
|
76
|
+
/* istanbul ignore if */
|
73
77
|
if (options.watch) {
|
74
78
|
await context.watch({});
|
75
79
|
(0, beautiful_logs_1.printProgressInfo)(components.logger, `Bundle saved ${log_1.colors.bold(output)}`);
|
@@ -82,6 +86,7 @@ async function bundleProject(components, options, sceneJson) {
|
|
82
86
|
.join(',') || outfile)}`);
|
83
87
|
}
|
84
88
|
catch (err) {
|
89
|
+
/* istanbul ignore next */
|
85
90
|
throw new error_1.CliError(err.toString());
|
86
91
|
}
|
87
92
|
await context.dispose();
|
@@ -100,12 +105,14 @@ function runTypeChecker(components, options) {
|
|
100
105
|
'--preserveWatchOutput',
|
101
106
|
options.emitDeclaration ? '--emitDeclarationOnly' : '--noEmit'
|
102
107
|
];
|
108
|
+
/* istanbul ignore if */
|
103
109
|
if (options.watch)
|
104
110
|
args.push('--watch');
|
105
111
|
(0, beautiful_logs_1.printProgressStep)(components.logger, `Running type checker`, 2, MAX_STEP);
|
106
112
|
const ts = child_process_1.default.spawn('node', args, { env: process.env, cwd: options.workingDirectory });
|
107
113
|
const typeCheckerFuture = (0, fp_future_1.future)();
|
108
114
|
ts.on('close', (code) => {
|
115
|
+
/* istanbul ignore else */
|
109
116
|
if (code === 0) {
|
110
117
|
(0, beautiful_logs_1.printProgressInfo)(components.logger, `Type checking completed without errors`);
|
111
118
|
}
|
@@ -117,6 +124,7 @@ function runTypeChecker(components, options) {
|
|
117
124
|
});
|
118
125
|
ts.stdout.pipe(process.stdout);
|
119
126
|
ts.stderr.pipe(process.stderr);
|
127
|
+
/* istanbul ignore if */
|
120
128
|
if (options.watch) {
|
121
129
|
typeCheckerFuture.resolve(-1);
|
122
130
|
}
|
package/dist/logic/commands.js
CHANGED
@@ -8,12 +8,14 @@ async function getCommands({ fs }) {
|
|
8
8
|
const commandDirs = await fs.readdir(exports.COMMANDS_PATH);
|
9
9
|
const commands = commandDirs.map(async (dir) => {
|
10
10
|
const path = (0, path_1.resolve)(exports.COMMANDS_PATH, dir);
|
11
|
-
|
12
|
-
if (!statDir.isDirectory()) {
|
11
|
+
if (!(await fs.directoryExists(path))) {
|
13
12
|
throw new error_1.CliError('Developer: All commands must be inside a folder');
|
14
13
|
}
|
15
|
-
|
16
|
-
|
14
|
+
try {
|
15
|
+
require.resolve(`${path}`);
|
16
|
+
}
|
17
|
+
catch {
|
18
|
+
/* istanbul ignore next */
|
17
19
|
throw new error_1.CliError('Developer: All commands must have an "index.js" file inside');
|
18
20
|
}
|
19
21
|
return dir;
|
package/dist/logic/dcl-ignore.js
CHANGED
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
exports.getDCLIgnorePatterns = exports.getDCLIgnoreFileContents = exports.defaultDclIgnore = void 0;
|
7
|
-
/* istanbul ignore file */
|
8
7
|
const path_1 = __importDefault(require("path"));
|
9
8
|
exports.defaultDclIgnore = [
|
10
9
|
'.*',
|
@@ -1 +1 @@
|
|
1
|
-
export declare function getPort(port
|
1
|
+
export declare function getPort(port: number, failoverPort?: number): Promise<number>;
|
@@ -5,8 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
exports.getPort = void 0;
|
7
7
|
const portfinder_1 = __importDefault(require("portfinder"));
|
8
|
-
async function getPort(port
|
9
|
-
let resolvedPort = port && Number.isInteger(port) ? port : 0;
|
8
|
+
async function getPort(port, failoverPort = 2044) {
|
9
|
+
let resolvedPort = port && Number.isInteger(port) ? +port : 0;
|
10
10
|
if (!resolvedPort) {
|
11
11
|
try {
|
12
12
|
resolvedPort = await portfinder_1.default.getPortPromise({ port: resolvedPort });
|
@@ -1,5 +1,9 @@
|
|
1
1
|
import { ContentMapping } from '@dcl/schemas/dist/misc/content-mapping';
|
2
2
|
import { CliComponents } from '../components';
|
3
|
+
export type ProjectFile = {
|
4
|
+
absolutePath: string;
|
5
|
+
hash: string;
|
6
|
+
};
|
3
7
|
/**
|
4
8
|
* Returns an array of the publishable files for a given folder.
|
5
9
|
*
|
@@ -9,13 +13,21 @@ export declare function getPublishableFiles(components: Pick<CliComponents, 'fs'
|
|
9
13
|
* This function converts paths to decentraland-compatible paths.
|
10
14
|
* - From windows separators to unix separators.
|
11
15
|
* - All to lowercase
|
12
|
-
*
|
13
16
|
*/
|
14
|
-
export declare function normalizeDecentralandFilename(filename: string): string;
|
17
|
+
export declare function normalizeDecentralandFilename(projectRoot: string, filename: string): string;
|
18
|
+
/**
|
19
|
+
* This function normalizes the content mappings of a project to be used by the
|
20
|
+
* Decentraland file system
|
21
|
+
*/
|
22
|
+
export declare function projectFilesToContentMappings(projectRoot: string, files: ProjectFile[]): ContentMapping[];
|
15
23
|
/**
|
16
24
|
* Returns the content mappings for a specific project folder.
|
25
|
+
* NOTE: the result of this function IS NOT NORMALIZED. Paths sould be normalized
|
26
|
+
* with normalizeDecentralandFilename before usage
|
27
|
+
*
|
28
|
+
* TODO: Unit test this function
|
17
29
|
*/
|
18
|
-
export declare function
|
30
|
+
export declare function getProjectPublishableFilesWithHashes(components: Pick<CliComponents, 'fs'>, projectRoot: string, hashingFunction: (filePath: string) => Promise<string>): Promise<ProjectFile[]>;
|
19
31
|
export declare const b64HashingFunction: (str: string) => Promise<string>;
|
20
32
|
interface PackageJson {
|
21
33
|
dependencies: Record<string, string>;
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
27
|
};
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
29
|
-
exports.getPackageJson = exports.b64HashingFunction = exports.
|
29
|
+
exports.getPackageJson = exports.b64HashingFunction = exports.getProjectPublishableFilesWithHashes = exports.projectFilesToContentMappings = exports.normalizeDecentralandFilename = exports.getPublishableFiles = void 0;
|
30
30
|
const dcl_ignore_1 = require("./dcl-ignore");
|
31
31
|
const glob_1 = require("glob");
|
32
32
|
const ignore_1 = __importDefault(require("ignore"));
|
@@ -36,7 +36,6 @@ const error_1 = require("./error");
|
|
36
36
|
* Returns an array of the publishable files for a given folder.
|
37
37
|
*
|
38
38
|
*/
|
39
|
-
/* istanbul ignore next */
|
40
39
|
async function getPublishableFiles(components, projectRoot) {
|
41
40
|
const ignorePatterns = await (0, dcl_ignore_1.getDCLIgnorePatterns)(components, projectRoot);
|
42
41
|
const ig = (0, ignore_1.default)().add(ignorePatterns);
|
@@ -54,20 +53,36 @@ exports.getPublishableFiles = getPublishableFiles;
|
|
54
53
|
* This function converts paths to decentraland-compatible paths.
|
55
54
|
* - From windows separators to unix separators.
|
56
55
|
* - All to lowercase
|
57
|
-
*
|
58
56
|
*/
|
59
|
-
|
60
|
-
|
61
|
-
|
57
|
+
function normalizeDecentralandFilename(projectRoot, filename) {
|
58
|
+
const newAbsolute = path_1.default.resolve(projectRoot, filename);
|
59
|
+
const relativePath = path_1.default.relative(projectRoot, newAbsolute);
|
60
|
+
// 1. win->unix style
|
61
|
+
// 2. remove heading /
|
62
|
+
return relativePath.replace(/(\\)/g, '/').replace(/^\/+/, '').toLowerCase();
|
62
63
|
}
|
63
64
|
exports.normalizeDecentralandFilename = normalizeDecentralandFilename;
|
65
|
+
/**
|
66
|
+
* This function normalizes the content mappings of a project to be used by the
|
67
|
+
* Decentraland file system
|
68
|
+
*/
|
69
|
+
function projectFilesToContentMappings(projectRoot, files) {
|
70
|
+
return files.map((file) => {
|
71
|
+
return {
|
72
|
+
file: normalizeDecentralandFilename(projectRoot, file.absolutePath),
|
73
|
+
hash: file.hash
|
74
|
+
};
|
75
|
+
});
|
76
|
+
}
|
77
|
+
exports.projectFilesToContentMappings = projectFilesToContentMappings;
|
64
78
|
/**
|
65
79
|
* Returns the content mappings for a specific project folder.
|
80
|
+
* NOTE: the result of this function IS NOT NORMALIZED. Paths sould be normalized
|
81
|
+
* with normalizeDecentralandFilename before usage
|
82
|
+
*
|
83
|
+
* TODO: Unit test this function
|
66
84
|
*/
|
67
|
-
|
68
|
-
async function getProjectContentMappings(components, projectRoot,
|
69
|
-
/* istanbul ignore next */
|
70
|
-
hashingFunction) {
|
85
|
+
async function getProjectPublishableFilesWithHashes(components, projectRoot, hashingFunction) {
|
71
86
|
const projectFiles = await getPublishableFiles(components, projectRoot);
|
72
87
|
const ret = [];
|
73
88
|
const usedFilenames = new Set();
|
@@ -76,21 +91,20 @@ hashingFunction) {
|
|
76
91
|
/* istanbul ignore if */
|
77
92
|
if (!(await components.fs.fileExists(absolutePath)))
|
78
93
|
continue;
|
79
|
-
|
80
|
-
const normalizedFile = normalizeDecentralandFilename(file).replace(/^\/+/, '');
|
94
|
+
const normalizedFile = normalizeDecentralandFilename(projectRoot, file);
|
81
95
|
/* istanbul ignore if */
|
82
96
|
if (usedFilenames.has(normalizedFile)) {
|
83
97
|
throw new error_1.CliError(`DuplicatedFilenameError: the file ${file} exists with a different casing. Please manually remove one occurrence`);
|
84
98
|
}
|
85
99
|
usedFilenames.add(normalizedFile);
|
86
100
|
ret.push({
|
87
|
-
|
101
|
+
absolutePath,
|
88
102
|
hash: await hashingFunction(absolutePath)
|
89
103
|
});
|
90
104
|
}
|
91
105
|
return ret;
|
92
106
|
}
|
93
|
-
exports.
|
107
|
+
exports.getProjectPublishableFilesWithHashes = getProjectPublishableFilesWithHashes;
|
94
108
|
const b64HashingFunction = async (str) => 'b64-' + Buffer.from(str).toString('base64');
|
95
109
|
exports.b64HashingFunction = b64HashingFunction;
|
96
110
|
/* istanbul ignore next */
|
@@ -67,7 +67,6 @@ exports.getWorkspaceFilePath = getWorkspaceFilePath;
|
|
67
67
|
function assertValidWorkspace(workspace) {
|
68
68
|
if (!WorkspaceJson.validate(workspace)) {
|
69
69
|
const errors = [];
|
70
|
-
/* istanbul ignore if */
|
71
70
|
if (WorkspaceJson.validate.errors) {
|
72
71
|
for (const error of WorkspaceJson.validate.errors) {
|
73
72
|
errors.push(`Error validating ${WORKSPACE_FILE}: ${error.message}`);
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { CliComponents } from './components';
|
2
|
+
import { parseArgs } from './logic/args';
|
3
|
+
export interface Options {
|
4
|
+
args: ReturnType<typeof parseArgs>;
|
5
|
+
components: CliComponents;
|
6
|
+
}
|
7
|
+
export declare function runSdkCommand(components: CliComponents, command: string, argv: string[]): Promise<any>;
|
@@ -0,0 +1,73 @@
|
|
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.runSdkCommand = void 0;
|
27
|
+
const args_1 = require("./logic/args");
|
28
|
+
const beautiful_logs_1 = require("./logic/beautiful-logs");
|
29
|
+
const commands_1 = require("./logic/commands");
|
30
|
+
const error_1 = require("./logic/error");
|
31
|
+
const listCommandsStr = (commands) => commands.map(($) => `\t *sdk-commands ${$} \n`).join('');
|
32
|
+
/* istanbul ignore next */
|
33
|
+
function asserValidCommand(fns) {
|
34
|
+
const { help, main } = fns;
|
35
|
+
if (!help || !main) {
|
36
|
+
throw new error_1.CliError(`Command does not follow implementation rules:
|
37
|
+
* Requires a "help" function
|
38
|
+
* Requires a "main" function
|
39
|
+
`);
|
40
|
+
}
|
41
|
+
return true;
|
42
|
+
}
|
43
|
+
async function runSdkCommand(components, command, argv) {
|
44
|
+
const helpMessage = (commands) => `Here is the list of commands:\n${listCommandsStr(commands)}`;
|
45
|
+
const needsHelp = argv.includes('--help') || argv.includes('-h');
|
46
|
+
const needsJson = argv.includes('--json');
|
47
|
+
const commands = await (0, commands_1.getCommands)(components);
|
48
|
+
if (!commands.includes(command)) {
|
49
|
+
if (needsHelp) {
|
50
|
+
components.logger.log(helpMessage(commands));
|
51
|
+
return;
|
52
|
+
}
|
53
|
+
/* istanbul ignore next */
|
54
|
+
throw new error_1.CliError(`Command ${command} is invalid. ${helpMessage(commands)}`);
|
55
|
+
}
|
56
|
+
const cmd = await Promise.resolve(`${`./commands/${command}`}`).then(s => __importStar(require(s)));
|
57
|
+
if (asserValidCommand(cmd)) {
|
58
|
+
const options = { args: (0, args_1.parseArgs)(argv, cmd.args), components };
|
59
|
+
if (needsHelp) {
|
60
|
+
await cmd.help(options);
|
61
|
+
}
|
62
|
+
else {
|
63
|
+
(0, beautiful_logs_1.printCommand)(components.logger, command);
|
64
|
+
const ret = await cmd.main(options);
|
65
|
+
// print the result of the evaluation as json in the standard output
|
66
|
+
if (needsJson) {
|
67
|
+
process.stdout.write(JSON.stringify(ret, null, 2));
|
68
|
+
}
|
69
|
+
return ret;
|
70
|
+
}
|
71
|
+
}
|
72
|
+
}
|
73
|
+
exports.runSdkCommand = runSdkCommand;
|
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-4622328580.commit-fe88e6c",
|
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-4622328580.commit-fe88e6c",
|
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": "fe88e6c95b93e2eddcf1c3ace0dd3abeba5219e7"
|
64
64
|
}
|