@player-tools/cli 0.4.2-next.1 → 0.5.0-next.0
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/dependency-versions/check.d.ts +18 -0
- package/dist/commands/dependency-versions/check.js +271 -0
- package/dist/commands/dsl/compile.d.ts +2 -2
- package/dist/commands/dsl/compile.js +136 -141
- package/dist/commands/dsl/validate.d.ts +12 -0
- package/dist/commands/dsl/validate.js +76 -0
- package/dist/commands/json/validate.d.ts +1 -1
- package/dist/commands/json/validate.js +62 -73
- package/dist/commands/xlr/compile.d.ts +1 -1
- package/dist/commands/xlr/compile.js +73 -79
- package/dist/commands/xlr/convert.d.ts +1 -1
- package/dist/commands/xlr/convert.js +59 -68
- package/dist/config.d.ts +2 -2
- package/dist/config.js +1 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.js +6 -18
- package/dist/plugins/LSPAssetsPlugin.d.ts +2 -2
- package/dist/plugins/LSPAssetsPlugin.js +3 -13
- package/dist/plugins/LSPPluginPlugin.d.ts +2 -2
- package/dist/plugins/LSPPluginPlugin.js +3 -13
- package/dist/plugins/LSPTransformsPlugin.d.ts +3 -3
- package/dist/plugins/LSPTransformsPlugin.js +3 -13
- package/dist/plugins/index.d.ts +9 -9
- package/dist/plugins/index.js +5 -17
- package/dist/utils/babel-register.js +8 -9
- package/dist/utils/base-command.d.ts +7 -7
- package/dist/utils/base-command.js +107 -136
- package/dist/utils/compilation-context.d.ts +2 -2
- package/dist/utils/compilation-context.js +3 -11
- package/dist/utils/compile-renderer.d.ts +2 -2
- package/dist/utils/compile-renderer.js +14 -16
- package/dist/utils/compiler-options.d.ts +3 -0
- package/dist/utils/compiler-options.js +16 -0
- package/dist/utils/diag-renderer.d.ts +2 -2
- package/dist/utils/diag-renderer.js +35 -36
- package/dist/utils/fs.js +4 -5
- package/dist/utils/task-runner.d.ts +4 -4
- package/dist/utils/task-runner.js +15 -22
- package/dist/utils/xlr/consts.js +9 -8
- package/dist/utils/xlr/visitors/file.d.ts +2 -2
- package/dist/utils/xlr/visitors/file.js +6 -7
- package/dist/utils/xlr/visitors/index.d.ts +3 -3
- package/dist/utils/xlr/visitors/index.js +5 -17
- package/dist/utils/xlr/visitors/plugin.d.ts +2 -2
- package/dist/utils/xlr/visitors/plugin.js +29 -37
- package/dist/utils/xlr/visitors/types.d.ts +2 -2
- package/dist/utils/xlr/visitors/types.js +1 -0
- package/package.json +46 -36
- package/oclif.manifest.json +0 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BaseCommand } from "../../utils/base-command";
|
|
2
|
+
/** A command to get @player-ui/@player-tools dependency versions and issue warnings/recommendations based on them */
|
|
3
|
+
export default class DependencyVersionsCheck extends BaseCommand {
|
|
4
|
+
static summary: string;
|
|
5
|
+
static description: string;
|
|
6
|
+
static flags: {
|
|
7
|
+
verbose: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
8
|
+
path: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
9
|
+
ignore: import("@oclif/core/lib/interfaces").OptionFlag<string[]>;
|
|
10
|
+
config: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
11
|
+
};
|
|
12
|
+
private getOptions;
|
|
13
|
+
run(): Promise<{
|
|
14
|
+
/** the status code */
|
|
15
|
+
exitCode: number;
|
|
16
|
+
}>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=check.d.ts.map
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const globby_1 = tslib_1.__importDefault(require("globby"));
|
|
5
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
6
|
+
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra")); // fse rather than fs makes unit testing easier with mocking
|
|
7
|
+
const easy_table_1 = tslib_1.__importDefault(require("easy-table"));
|
|
8
|
+
const child_process_1 = tslib_1.__importDefault(require("child_process"));
|
|
9
|
+
const core_1 = require("@oclif/core");
|
|
10
|
+
const base_command_1 = require("../../utils/base-command");
|
|
11
|
+
/** A command to get @player-ui/@player-tools dependency versions and issue warnings/recommendations based on them */
|
|
12
|
+
class DependencyVersionsCheck extends base_command_1.BaseCommand {
|
|
13
|
+
async getOptions() {
|
|
14
|
+
const { flags } = await this.parse(DependencyVersionsCheck);
|
|
15
|
+
return {
|
|
16
|
+
verbose: flags.verbose,
|
|
17
|
+
path: flags.path,
|
|
18
|
+
ignore: flags.ignore,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/* eslint-disable complexity */
|
|
22
|
+
async run() {
|
|
23
|
+
const results = {
|
|
24
|
+
exitCode: 0,
|
|
25
|
+
};
|
|
26
|
+
// Note: please do not easily change these exit codes, they are used for exit code detection in Jenkins pipeline(s)
|
|
27
|
+
const WARNING_EXIT_CODE = 1;
|
|
28
|
+
const NOT_RUN_AT_REPO_ROOT_EXIT_CODE = 2;
|
|
29
|
+
const chalkNegative = chalk_1.default.bgRed.white;
|
|
30
|
+
const chalkPositive = chalk_1.default.bgGreen;
|
|
31
|
+
const localGithubRepoRoot = child_process_1.default
|
|
32
|
+
.execSync("git rev-parse --show-toplevel")
|
|
33
|
+
.toString()
|
|
34
|
+
.trimEnd();
|
|
35
|
+
const currentDirectory = process.cwd();
|
|
36
|
+
if (localGithubRepoRoot !== currentDirectory) {
|
|
37
|
+
console.log(`${chalkNegative("ERROR:")} cannot run the CLI in ${currentDirectory}`);
|
|
38
|
+
console.log(`Please run the CLI in the root of the repository, ${localGithubRepoRoot}`);
|
|
39
|
+
results.exitCode = NOT_RUN_AT_REPO_ROOT_EXIT_CODE;
|
|
40
|
+
this.exit(results.exitCode);
|
|
41
|
+
return results;
|
|
42
|
+
}
|
|
43
|
+
const { verbose, path, ignore } = await this.getOptions();
|
|
44
|
+
console.log("Consider using the --help flag for more information about this command.");
|
|
45
|
+
if (!verbose) {
|
|
46
|
+
console.log("For more comprehensive logging, consider adding the -v flag.");
|
|
47
|
+
}
|
|
48
|
+
if (!path) {
|
|
49
|
+
console.log("For logging with full path to the dependency rather than with '➡', consider adding the -p flag.");
|
|
50
|
+
}
|
|
51
|
+
if (ignore) {
|
|
52
|
+
console.log("All output based on the versions/dependencies yielded after eliminating the patterns specified by the -i flag.");
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
console.log("To add string pattern(s) for files to exclude, consider adding them after the -i flag.");
|
|
56
|
+
}
|
|
57
|
+
console.log("Inspecting the @player-ui/@player-tools dependencies in the current repository...");
|
|
58
|
+
let packageJsons = globby_1.default.sync("**/node_modules/{@player,@player-language,@web-player}/*/package.json");
|
|
59
|
+
if (ignore) {
|
|
60
|
+
// It is necessary to filter here rather than to pass extra options to globSync.
|
|
61
|
+
// This is because we need want to filter based on partial matches of the file path string
|
|
62
|
+
// whereas any filtering of globSync itself is heavily based on the file path as part of the system
|
|
63
|
+
// and not the file as a simple string.
|
|
64
|
+
packageJsons = packageJsons.filter((packageJson) => {
|
|
65
|
+
return !ignore.some((patternToIgnore) => packageJson.includes(patternToIgnore));
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
// Initialize the maps storing the dependency versions mapping to the packages with that version
|
|
69
|
+
const versionToTopLevelDependencyMap = {};
|
|
70
|
+
const versionToNestedDependencyMap = {};
|
|
71
|
+
// Populate the dependency maps
|
|
72
|
+
for (const packageJsonFile of packageJsons) {
|
|
73
|
+
const { version } = JSON.parse(fs_extra_1.default.readFileSync(packageJsonFile, "utf8"));
|
|
74
|
+
// top-level dependencies only have `node_modules` occurring once in their path
|
|
75
|
+
const isTopLevelDependency = (packageJsonFile.match(/node_modules/g) || []).length === 1;
|
|
76
|
+
const mapToUpdate = isTopLevelDependency
|
|
77
|
+
? versionToTopLevelDependencyMap
|
|
78
|
+
: versionToNestedDependencyMap;
|
|
79
|
+
if (version in mapToUpdate) {
|
|
80
|
+
mapToUpdate[version].push(packageJsonFile);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
mapToUpdate[version] = [packageJsonFile];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const topLevelVersions = Object.keys(versionToTopLevelDependencyMap);
|
|
87
|
+
const nestedVersions = Object.keys(versionToNestedDependencyMap);
|
|
88
|
+
/**
|
|
89
|
+
* copied from https://www.npmjs.com/package/semver-compare?activeTab=code
|
|
90
|
+
* rather than yarn-installed since its short.
|
|
91
|
+
*
|
|
92
|
+
* @returns the result of comparison
|
|
93
|
+
*/
|
|
94
|
+
function cmp(a, b) {
|
|
95
|
+
const pa = a.split(".");
|
|
96
|
+
const pb = b.split(".");
|
|
97
|
+
for (let i = 0; i < 3; i++) {
|
|
98
|
+
const na = Number(pa[i]);
|
|
99
|
+
const nb = Number(pb[i]);
|
|
100
|
+
if (na > nb)
|
|
101
|
+
return 1;
|
|
102
|
+
if (nb > na)
|
|
103
|
+
return -1;
|
|
104
|
+
if (!isNaN(na) && isNaN(nb))
|
|
105
|
+
return 1;
|
|
106
|
+
if (isNaN(na) && !isNaN(nb))
|
|
107
|
+
return -1;
|
|
108
|
+
}
|
|
109
|
+
return 0;
|
|
110
|
+
}
|
|
111
|
+
const sortedTopLevelVersions = topLevelVersions.sort(cmp);
|
|
112
|
+
const sortedNestedVersions = nestedVersions.sort(cmp);
|
|
113
|
+
const topLevelDependenciesTable = new easy_table_1.default();
|
|
114
|
+
const nestedDependenciesTable = new easy_table_1.default();
|
|
115
|
+
const highestTopLevelVersion = sortedTopLevelVersions[sortedTopLevelVersions.length - 1];
|
|
116
|
+
const highestNestedVersion = sortedNestedVersions[sortedNestedVersions.length - 1];
|
|
117
|
+
const singleVersionsExist = topLevelVersions.length === 1 && nestedVersions.length === 1;
|
|
118
|
+
const singleVersionsMatch = singleVersionsExist && topLevelVersions[0] === nestedVersions[0];
|
|
119
|
+
const singleVersionsMismatch = singleVersionsExist && topLevelVersions[0] !== nestedVersions[0];
|
|
120
|
+
const topLevelVersionsExist = topLevelVersions.length > 0;
|
|
121
|
+
const nestedVersionsExist = nestedVersions.length > 0;
|
|
122
|
+
const multipleTopLevelVersionsDetected = topLevelVersions.length > 1;
|
|
123
|
+
const multipleNestedVersionsDetected = nestedVersions.length > 1;
|
|
124
|
+
/**
|
|
125
|
+
* Formats the path to the dependency
|
|
126
|
+
*
|
|
127
|
+
* @param fullPath
|
|
128
|
+
* @returns the formatted path with ➡ arrows for the CLI user to follow
|
|
129
|
+
*/
|
|
130
|
+
function formatDependencyPath(fullPath) {
|
|
131
|
+
const pathArrayWithoutNodeModules = fullPath.split("node_modules/");
|
|
132
|
+
let formattedPath = "";
|
|
133
|
+
for (let i = 0; i < pathArrayWithoutNodeModules.length; i++) {
|
|
134
|
+
if (pathArrayWithoutNodeModules[i] !== "") {
|
|
135
|
+
formattedPath += ` ➡ ${pathArrayWithoutNodeModules[i]}`;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
formattedPath = formattedPath.replace("/package.json", ""); // remove /package.json at the end
|
|
139
|
+
return formattedPath;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Prints the formatted dependencyTable
|
|
143
|
+
*
|
|
144
|
+
* @param printsTopLevelTable - whether to print the top-level table or not
|
|
145
|
+
*/
|
|
146
|
+
function printTable(versionToDependencyMap, sortedVersions, table) {
|
|
147
|
+
sortedVersions.forEach(function (version) {
|
|
148
|
+
const dependencies = versionToDependencyMap[version];
|
|
149
|
+
const msg = path
|
|
150
|
+
? "Path to dependency's package.json"
|
|
151
|
+
: "How to find dependency";
|
|
152
|
+
const firstDependency = path
|
|
153
|
+
? dependencies[0]
|
|
154
|
+
: formatDependencyPath(dependencies[0]);
|
|
155
|
+
table.cell("Version", version);
|
|
156
|
+
table.cell(msg, firstDependency);
|
|
157
|
+
table.newRow();
|
|
158
|
+
const maxNumberOfDepsToPrint = verbose
|
|
159
|
+
? dependencies.length
|
|
160
|
+
: Math.min(3, dependencies.length); // in non-verbose, print out at most 3 dependencies
|
|
161
|
+
const numberOfDepsNotPrintedInNonVerbose = dependencies.length - maxNumberOfDepsToPrint;
|
|
162
|
+
for (let i = 1; i < maxNumberOfDepsToPrint; i++) {
|
|
163
|
+
table.cell("Version", "");
|
|
164
|
+
const dependency = path
|
|
165
|
+
? dependencies[i]
|
|
166
|
+
: formatDependencyPath(dependencies[i]);
|
|
167
|
+
table.cell(msg, dependency);
|
|
168
|
+
table.newRow();
|
|
169
|
+
}
|
|
170
|
+
if (numberOfDepsNotPrintedInNonVerbose > 0) {
|
|
171
|
+
table.cell("Version", "");
|
|
172
|
+
const notPrintedMsg = `... ${numberOfDepsNotPrintedInNonVerbose} other dependencies not printed in non-verbose mode.`;
|
|
173
|
+
table.cell(msg, notPrintedMsg);
|
|
174
|
+
table.newRow();
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
console.log(table.toString());
|
|
178
|
+
}
|
|
179
|
+
if (topLevelVersionsExist) {
|
|
180
|
+
console.log("\nTOP-LEVEL @player-ui/@player-tools DEPENDENCIES:");
|
|
181
|
+
printTable(versionToTopLevelDependencyMap, sortedTopLevelVersions, topLevelDependenciesTable);
|
|
182
|
+
}
|
|
183
|
+
if (nestedVersionsExist) {
|
|
184
|
+
console.log("\nNESTED @player-ui/@player-tools DEPENDENCIES:");
|
|
185
|
+
printTable(versionToNestedDependencyMap, sortedNestedVersions, nestedDependenciesTable);
|
|
186
|
+
}
|
|
187
|
+
if ((!topLevelVersionsExist && nestedVersions.length === 1) ||
|
|
188
|
+
(!nestedVersionsExist && topLevelVersions.length === 1) ||
|
|
189
|
+
(!nestedVersionsExist && !topLevelVersionsExist) ||
|
|
190
|
+
singleVersionsMatch) {
|
|
191
|
+
if (singleVersionsMatch) {
|
|
192
|
+
console.log("Unique top-level and nested @player-ui/@player-tools versions match. ");
|
|
193
|
+
}
|
|
194
|
+
if (!topLevelVersionsExist && nestedVersions.length === 1) {
|
|
195
|
+
console.log(`No top-level @player-ui/@player-tools dependencies exist. Only a single nested @player-ui/@player-tools version exists, ${nestedVersions[0]}`);
|
|
196
|
+
}
|
|
197
|
+
if (!nestedVersionsExist && topLevelVersions.length === 1) {
|
|
198
|
+
console.log(`No nested @player-ui/@player-tools dependencies exist. Only a single top-level @player-ui/@player-tools version exists, ${topLevelVersions[0]}`);
|
|
199
|
+
}
|
|
200
|
+
if (!nestedVersionsExist && !topLevelVersionsExist) {
|
|
201
|
+
console.log("No @player-ui/@player-tools dependencies exist.");
|
|
202
|
+
}
|
|
203
|
+
console.log("There are no issues related to @player-ui/@player-tools dependency versioning. You are good to go! ");
|
|
204
|
+
this.exit(results.exitCode);
|
|
205
|
+
return results;
|
|
206
|
+
}
|
|
207
|
+
console.log(chalkNegative("WARNINGS:"));
|
|
208
|
+
if (multipleTopLevelVersionsDetected) {
|
|
209
|
+
console.log("- There are multiple top-level @player-ui/@player-tools dependency versions.");
|
|
210
|
+
}
|
|
211
|
+
if (multipleNestedVersionsDetected) {
|
|
212
|
+
console.log("- There are multiple nested @player-ui/@player-tools dependency versions.");
|
|
213
|
+
}
|
|
214
|
+
if (singleVersionsMismatch) {
|
|
215
|
+
console.log("- Mismatch between the top-level and the nested @player-ui/@player-tools dependency.");
|
|
216
|
+
}
|
|
217
|
+
console.log(chalkPositive("RECOMMENDATIONS:"));
|
|
218
|
+
if (multipleTopLevelVersionsDetected) {
|
|
219
|
+
console.log(`- Resolve all top-level @player-ui/@player-tools dependencies to the same version. Consider updating them to the latest player version you have, ${highestTopLevelVersion}. When all top-level @player-ui/@player-tools dependencies are resolved, run the current CLI again to obtain recommendations about nested @player-ui/@player-tools dependencies.`);
|
|
220
|
+
}
|
|
221
|
+
else if (highestTopLevelVersion && highestNestedVersion) {
|
|
222
|
+
// highestTopLevelVersion && highestNestedVersion defined means: single top-level version, one or more nested versions
|
|
223
|
+
if (cmp(highestTopLevelVersion, highestNestedVersion) >= 1) {
|
|
224
|
+
// when only a single top-level version is detected, it is simply the highest
|
|
225
|
+
console.log(`- The highest @player-ui/@player-tools version is ${highestTopLevelVersion} at the top level. Please add resolutions for all nested @player-ui/@player-tools versions to this version or bump the nested versions to it.`);
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
console.log(`- The highest @player-ui/@player-tools version is ${highestNestedVersion} at the nested level. Please bump the top-level version, ${highestTopLevelVersion}, to ${highestNestedVersion}.`);
|
|
229
|
+
if (multipleNestedVersionsDetected) {
|
|
230
|
+
console.log(`- Also, please add resolutions or bump the versions for nested @player-ui/@player-tools dependencies whose version is not ${highestNestedVersion}.`);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
else if (highestNestedVersion && multipleNestedVersionsDetected) {
|
|
235
|
+
// no top-level version defined, multiple nested versions
|
|
236
|
+
console.log(`- The highest @player-ui/@player-tools version is ${highestNestedVersion} at the nested level. Please add resolutions for all nested @player-ui/@player-tools versions to this version or bump the nested versions to it.`);
|
|
237
|
+
}
|
|
238
|
+
// Although no errors have occurred when the code reaches here, a non-zero exit code of WARNING_EXIT_CODE = 1 is still used to indicate
|
|
239
|
+
// the idea of "warnings" being issued due to dependency version discrepancies
|
|
240
|
+
results.exitCode = WARNING_EXIT_CODE;
|
|
241
|
+
this.exit(results.exitCode);
|
|
242
|
+
return results;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
DependencyVersionsCheck.summary = "Checks for @player-ui/@player-tools dependency version mismatches and issues warnings/solutions accordingly";
|
|
246
|
+
DependencyVersionsCheck.description = `Consider the following:
|
|
247
|
+
- The interpretation of TOP-LEVEL and NESTED dependencies is as follows:
|
|
248
|
+
a. TOP-LEVEL dependencies only have one 'node_modules' in their path
|
|
249
|
+
b. NESTED dependencies have more than one 'node_modules' in their path
|
|
250
|
+
- @player-ui/@player-tools dependencies are fetched not only from inside the 'node_modules' at the top of the repository in which it is run but also from 'node_modules' in sub-directories.
|
|
251
|
+
For example, if you have some 'node_modules' inside of a 'packages' folder that contains @player-ui/@player-tools dependencies, then these will also be fetched.
|
|
252
|
+
The display of such dependencies also depends on the first bullet point.
|
|
253
|
+
`;
|
|
254
|
+
DependencyVersionsCheck.flags = {
|
|
255
|
+
...base_command_1.BaseCommand.flags,
|
|
256
|
+
verbose: core_1.Flags.boolean({
|
|
257
|
+
char: "v",
|
|
258
|
+
description: "Give verbose description",
|
|
259
|
+
}),
|
|
260
|
+
path: core_1.Flags.boolean({
|
|
261
|
+
char: "p",
|
|
262
|
+
description: "Outputs full path to dependency",
|
|
263
|
+
}),
|
|
264
|
+
ignore: core_1.Flags.string({
|
|
265
|
+
char: "i",
|
|
266
|
+
description: "Ignore the specified pattern(s) when outputting results. Note multiple patterns can be passed",
|
|
267
|
+
multiple: true,
|
|
268
|
+
}),
|
|
269
|
+
};
|
|
270
|
+
exports.default = DependencyVersionsCheck;
|
|
271
|
+
//# sourceMappingURL=check.js.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { BaseCommand } from
|
|
1
|
+
import { BaseCommand } from "../../utils/base-command";
|
|
2
2
|
/** A command to compile player DSL content into JSON */
|
|
3
3
|
export default class DSLCompile extends BaseCommand {
|
|
4
4
|
static description: string;
|
|
5
5
|
static flags: {
|
|
6
6
|
input: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
7
7
|
output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
8
|
-
|
|
8
|
+
"skip-validation": import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
9
9
|
exp: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
10
10
|
config: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
11
11
|
};
|
|
@@ -1,164 +1,159 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
|
|
16
|
-
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
17
|
-
/* eslint-disable global-require */
|
|
18
|
-
/* eslint-disable import/no-dynamic-require */
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
19
4
|
const core_1 = require("@oclif/core");
|
|
20
|
-
const globby_1 = __importDefault(require("globby"));
|
|
21
|
-
const path_1 = __importDefault(require("path"));
|
|
5
|
+
const globby_1 = tslib_1.__importDefault(require("globby"));
|
|
6
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
22
7
|
const fs_1 = require("fs");
|
|
23
|
-
const mkdirp_1 = __importDefault(require("mkdirp"));
|
|
24
|
-
const log_symbols_1 = __importDefault(require("log-symbols"));
|
|
25
|
-
const figures_1 = __importDefault(require("figures"));
|
|
26
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const mkdirp_1 = tslib_1.__importDefault(require("mkdirp"));
|
|
9
|
+
const log_symbols_1 = tslib_1.__importDefault(require("log-symbols"));
|
|
10
|
+
const figures_1 = tslib_1.__importDefault(require("figures"));
|
|
11
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
27
12
|
const dsl_1 = require("@player-tools/dsl");
|
|
28
13
|
const base_command_1 = require("../../utils/base-command");
|
|
29
14
|
const fs_2 = require("../../utils/fs");
|
|
30
15
|
const babel_register_1 = require("../../utils/babel-register");
|
|
31
|
-
const validate_1 = __importDefault(require("../json/validate"));
|
|
16
|
+
const validate_1 = tslib_1.__importDefault(require("../json/validate"));
|
|
17
|
+
const validate_2 = tslib_1.__importDefault(require("./validate"));
|
|
32
18
|
/** A command to compile player DSL content into JSON */
|
|
33
19
|
class DSLCompile extends base_command_1.BaseCommand {
|
|
34
|
-
getOptions() {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
exp,
|
|
49
|
-
};
|
|
50
|
-
});
|
|
20
|
+
async getOptions() {
|
|
21
|
+
const { flags } = await this.parse(DSLCompile);
|
|
22
|
+
const config = await this.getPlayerConfig();
|
|
23
|
+
const input = flags.input ?? config.dsl?.src;
|
|
24
|
+
const { exp } = flags;
|
|
25
|
+
if (!input) {
|
|
26
|
+
throw new Error(`Input files are required for DSL compilation`);
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
input,
|
|
30
|
+
output: flags.output ?? config.dsl?.outDir ?? "_out",
|
|
31
|
+
skipValidation: flags["skip-validation"] ?? config.dsl?.skipValidation ?? false,
|
|
32
|
+
exp,
|
|
33
|
+
};
|
|
51
34
|
}
|
|
52
|
-
run() {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
35
|
+
async run() {
|
|
36
|
+
const { input, output, skipValidation, exp } = await this.getOptions();
|
|
37
|
+
const files = await (0, globby_1.default)((0, fs_2.convertToFileGlob)([input], "**/*.(tsx|jsx|js|ts)"), {
|
|
38
|
+
expandDirectories: true,
|
|
39
|
+
});
|
|
40
|
+
const results = {
|
|
41
|
+
exitCode: 0,
|
|
42
|
+
};
|
|
43
|
+
(0, babel_register_1.registerForPaths)();
|
|
44
|
+
this.debug("Found %i files to process", files.length);
|
|
45
|
+
if (!skipValidation) {
|
|
46
|
+
await validate_2.default.run(["-f", input]);
|
|
47
|
+
}
|
|
48
|
+
const context = await this.createCompilerContext();
|
|
49
|
+
/** Compile a file from the DSL format into JSON */
|
|
50
|
+
const compileFile = async (file) => {
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
52
|
+
const requiredModule = require(path_1.default.resolve(file));
|
|
53
|
+
const defaultExport = requiredModule.default;
|
|
54
|
+
if (!defaultExport) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const preProcessedValue = await context.dslCompiler.hooks.preProcessFlow.call(defaultExport);
|
|
58
|
+
const contentType = (await context.hooks.identifyContentType.call(file, preProcessedValue)) ||
|
|
59
|
+
(0, dsl_1.fingerprintContent)(preProcessedValue, file) ||
|
|
60
|
+
"unknown";
|
|
61
|
+
let relativePath = path_1.default.relative(input, file);
|
|
62
|
+
if (!relativePath) {
|
|
63
|
+
relativePath = path_1.default.basename(file);
|
|
64
|
+
}
|
|
65
|
+
const outputFile = path_1.default.join(output, path_1.default.format({
|
|
66
|
+
...path_1.default.parse(relativePath),
|
|
67
|
+
base: undefined,
|
|
68
|
+
ext: ".json",
|
|
69
|
+
}));
|
|
70
|
+
this.log(`${log_symbols_1.default.info} Compiling %s ${figures_1.default.arrowRight} %s as type %s`, (0, fs_2.normalizePath)(file), (0, fs_2.normalizePath)(outputFile), contentType);
|
|
71
|
+
const compileResult = await context.hooks.compileContent.call({ type: contentType }, preProcessedValue, file);
|
|
72
|
+
if (compileResult) {
|
|
73
|
+
const contentStr = JSON.stringify(compileResult.value, null, 2);
|
|
74
|
+
await (0, mkdirp_1.default)(path_1.default.dirname(outputFile));
|
|
75
|
+
await fs_1.promises.writeFile(outputFile, contentStr);
|
|
76
|
+
if (compileResult.sourceMap) {
|
|
77
|
+
await fs_1.promises.writeFile(`${outputFile}.map`, compileResult.sourceMap);
|
|
78
78
|
}
|
|
79
|
-
|
|
80
|
-
this.log(`${log_symbols_1.default.info} Compiling %s ${figures_1.default.arrowRight} %s as type %s`, (0, fs_2.normalizePath)(file), (0, fs_2.normalizePath)(outputFile), contentType);
|
|
81
|
-
const compileResult = yield context.hooks.compileContent.call({ type: contentType }, defaultExport, file);
|
|
82
|
-
if (compileResult) {
|
|
83
|
-
const contentStr = JSON.stringify(compileResult.value, null, 2);
|
|
84
|
-
yield (0, mkdirp_1.default)(path_1.default.dirname(outputFile));
|
|
85
|
-
yield fs_1.promises.writeFile(outputFile, contentStr);
|
|
86
|
-
if (compileResult.sourceMap) {
|
|
87
|
-
yield fs_1.promises.writeFile(`${outputFile}.map`, compileResult.sourceMap);
|
|
88
|
-
}
|
|
89
|
-
if (contentType) {
|
|
90
|
-
return {
|
|
91
|
-
contentType,
|
|
92
|
-
outputFile,
|
|
93
|
-
inputFile: file,
|
|
94
|
-
};
|
|
95
|
-
}
|
|
79
|
+
if (contentType) {
|
|
96
80
|
return {
|
|
97
81
|
contentType,
|
|
98
82
|
outputFile,
|
|
99
83
|
inputFile: file,
|
|
100
84
|
};
|
|
101
85
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const file = files[fIndex];
|
|
108
|
-
try {
|
|
109
|
-
const result = yield compileFile(file);
|
|
110
|
-
compilerResults.push({
|
|
111
|
-
output: result,
|
|
112
|
-
state: 'completed',
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
catch (e) {
|
|
116
|
-
results.exitCode = 100;
|
|
117
|
-
this.log('');
|
|
118
|
-
this.log(chalk_1.default.red(`${log_symbols_1.default.error} Error compiling ${file}: ${e.message}`));
|
|
119
|
-
this.debug(e);
|
|
120
|
-
compilerResults.push({
|
|
121
|
-
state: 'completed',
|
|
122
|
-
error: e,
|
|
123
|
-
});
|
|
124
|
-
}
|
|
86
|
+
return {
|
|
87
|
+
contentType,
|
|
88
|
+
outputFile,
|
|
89
|
+
inputFile: file,
|
|
90
|
+
};
|
|
125
91
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}),
|
|
139
|
-
...(exp ? ['--exp'] : []),
|
|
140
|
-
]);
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
console.log('No output to validate');
|
|
144
|
-
}
|
|
92
|
+
};
|
|
93
|
+
const compilerResults = [];
|
|
94
|
+
// This has to be done serially b/c of the way React logs messages to console.error
|
|
95
|
+
// Otherwise the errors in console will be randomly interspersed between update messages
|
|
96
|
+
for (let fIndex = 0; fIndex < files.length; fIndex += 1) {
|
|
97
|
+
const file = files[fIndex];
|
|
98
|
+
try {
|
|
99
|
+
const result = await compileFile(file);
|
|
100
|
+
compilerResults.push({
|
|
101
|
+
output: result,
|
|
102
|
+
state: "completed",
|
|
103
|
+
});
|
|
145
104
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
105
|
+
catch (e) {
|
|
106
|
+
results.exitCode = 100;
|
|
107
|
+
this.log("");
|
|
108
|
+
this.log(chalk_1.default.red(`${log_symbols_1.default.error} Error compiling ${file}: ${e.message}`));
|
|
109
|
+
this.debug(e);
|
|
110
|
+
compilerResults.push({
|
|
111
|
+
state: "completed",
|
|
112
|
+
error: e,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
await context.dslCompiler.hooks.onEnd.call({ output });
|
|
117
|
+
if (!skipValidation) {
|
|
118
|
+
console.log("");
|
|
119
|
+
const hasOutput = compilerResults.some((r) => r.output?.contentType === "flow");
|
|
120
|
+
if (hasOutput) {
|
|
121
|
+
await validate_1.default.run([
|
|
122
|
+
"-f",
|
|
123
|
+
...compilerResults
|
|
124
|
+
.filter((r) => r.output?.contentType === "flow")
|
|
125
|
+
.map((result) => {
|
|
126
|
+
return result.output?.outputFile ?? "";
|
|
127
|
+
}),
|
|
128
|
+
...(exp ? ["--exp"] : []),
|
|
129
|
+
]);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
console.log("No output to validate");
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
this.exit(results.exitCode);
|
|
136
|
+
return results;
|
|
149
137
|
}
|
|
150
138
|
}
|
|
151
|
-
|
|
152
|
-
DSLCompile.
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
description:
|
|
161
|
-
}),
|
|
162
|
-
|
|
139
|
+
DSLCompile.description = "Compile Player DSL files into JSON";
|
|
140
|
+
DSLCompile.flags = {
|
|
141
|
+
...base_command_1.BaseCommand.flags,
|
|
142
|
+
input: core_1.Flags.string({
|
|
143
|
+
char: "i",
|
|
144
|
+
description: "An input directory to compile.\nAny jsx/ts/tsx files will be loaded via babel-require automatically.",
|
|
145
|
+
}),
|
|
146
|
+
output: core_1.Flags.string({
|
|
147
|
+
char: "o",
|
|
148
|
+
description: "Output directory to write results to.",
|
|
149
|
+
}),
|
|
150
|
+
"skip-validation": core_1.Flags.boolean({
|
|
151
|
+
description: "Option to skip validating the generated JSON",
|
|
152
|
+
}),
|
|
153
|
+
exp: core_1.Flags.boolean({
|
|
154
|
+
description: "Use experimental language features",
|
|
163
155
|
default: false,
|
|
164
|
-
})
|
|
156
|
+
}),
|
|
157
|
+
};
|
|
158
|
+
exports.default = DSLCompile;
|
|
159
|
+
//# sourceMappingURL=compile.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseCommand } from "../../utils/base-command";
|
|
2
|
+
/** A command thay runs TS typechecker against source ts and tsx files */
|
|
3
|
+
export default class Validate extends BaseCommand {
|
|
4
|
+
static description: string;
|
|
5
|
+
static flags: {
|
|
6
|
+
files: import("@oclif/core/lib/interfaces").OptionFlag<string[]>;
|
|
7
|
+
config: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
8
|
+
};
|
|
9
|
+
private getOptions;
|
|
10
|
+
run(): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=validate.d.ts.map
|