@player-cli/cli 0.0.2--canary.6.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +82 -0
  2. package/bin/dev +17 -0
  3. package/bin/run +11 -0
  4. package/dist/commands/dependency-versions/check.d.ts +19 -0
  5. package/dist/commands/dependency-versions/check.js +270 -0
  6. package/dist/commands/dsl/compile.d.ts +20 -0
  7. package/dist/commands/dsl/compile.js +173 -0
  8. package/dist/commands/dsl/validate.d.ts +15 -0
  9. package/dist/commands/dsl/validate.js +142 -0
  10. package/dist/commands/json/validate.d.ts +18 -0
  11. package/dist/commands/json/validate.js +91 -0
  12. package/dist/commands/xlr/compile.d.ts +24 -0
  13. package/dist/commands/xlr/compile.js +153 -0
  14. package/dist/commands/xlr/convert.d.ts +20 -0
  15. package/dist/commands/xlr/convert.js +77 -0
  16. package/dist/config.d.ts +39 -0
  17. package/dist/config.js +3 -0
  18. package/dist/index.d.ts +7 -0
  19. package/dist/index.js +12 -0
  20. package/dist/plugins/LSPAssetsPlugin.d.ts +50 -0
  21. package/dist/plugins/LSPAssetsPlugin.js +47 -0
  22. package/dist/plugins/LSPPluginPlugin.d.ts +11 -0
  23. package/dist/plugins/LSPPluginPlugin.js +22 -0
  24. package/dist/plugins/LSPTransformsPlugin.d.ts +12 -0
  25. package/dist/plugins/LSPTransformsPlugin.js +17 -0
  26. package/dist/plugins/index.d.ts +33 -0
  27. package/dist/plugins/index.js +7 -0
  28. package/dist/utils/babel-register.d.ts +3 -0
  29. package/dist/utils/babel-register.js +19 -0
  30. package/dist/utils/base-command.d.ts +26 -0
  31. package/dist/utils/base-command.js +155 -0
  32. package/dist/utils/compilation-context.d.ts +53 -0
  33. package/dist/utils/compilation-context.js +57 -0
  34. package/dist/utils/compile-renderer.d.ts +13 -0
  35. package/dist/utils/compile-renderer.js +42 -0
  36. package/dist/utils/compiler-options.d.ts +3 -0
  37. package/dist/utils/compiler-options.js +16 -0
  38. package/dist/utils/diag-renderer.d.ts +31 -0
  39. package/dist/utils/diag-renderer.js +224 -0
  40. package/dist/utils/fs.d.ts +9 -0
  41. package/dist/utils/fs.js +39 -0
  42. package/dist/utils/log-levels.d.ts +11 -0
  43. package/dist/utils/log-levels.js +21 -0
  44. package/dist/utils/task-runner.d.ts +59 -0
  45. package/dist/utils/task-runner.js +59 -0
  46. package/dist/utils/xlr/consts.d.ts +7 -0
  47. package/dist/utils/xlr/consts.js +18 -0
  48. package/dist/utils/xlr/visitors/file.d.ts +5 -0
  49. package/dist/utils/xlr/visitors/file.js +25 -0
  50. package/dist/utils/xlr/visitors/index.d.ts +4 -0
  51. package/dist/utils/xlr/visitors/index.js +7 -0
  52. package/dist/utils/xlr/visitors/plugin.d.ts +5 -0
  53. package/dist/utils/xlr/visitors/plugin.js +167 -0
  54. package/dist/utils/xlr/visitors/types.d.ts +13 -0
  55. package/dist/utils/xlr/visitors/types.js +3 -0
  56. package/package.json +58 -0
@@ -0,0 +1,142 @@
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 log_symbols_1 = tslib_1.__importDefault(require("log-symbols"));
6
+ const fs_1 = require("fs");
7
+ const path_1 = tslib_1.__importDefault(require("path"));
8
+ const ts = tslib_1.__importStar(require("typescript"));
9
+ const core_1 = require("@oclif/core");
10
+ const base_command_1 = require("../../utils/base-command");
11
+ const fs_2 = require("../../utils/fs");
12
+ const compiler_options_1 = require("../../utils/compiler-options");
13
+ /** A command thay runs TS typechecker against source ts and tsx files */
14
+ class Validate extends base_command_1.BaseCommand {
15
+ static description = "Validate TSX files before they get compiled";
16
+ static flags = {
17
+ ...base_command_1.BaseCommand.flags,
18
+ files: core_1.Flags.string({
19
+ char: "f",
20
+ description: "A list of files or globs to validate",
21
+ multiple: true,
22
+ }),
23
+ severity: core_1.Flags.string({
24
+ char: "s",
25
+ description: "Setting the validation severity to 'warn' will change the validation step into a warning-only, not halting the process with code 1. That exposes an intermediate option between the default behaviour, where it will fail on errors, and skipping validation.",
26
+ options: ["error", "warn"],
27
+ default: "error",
28
+ }),
29
+ };
30
+ async getOptions() {
31
+ const { flags } = await this.parse(Validate);
32
+ const config = await this.getPlayerConfig();
33
+ const files = flags.files && flags.files.length > 0 ? flags.files : config.dsl?.src;
34
+ if (!files) {
35
+ throw new Error("DSL TSC typechecking requires a file list");
36
+ }
37
+ return {
38
+ inputFiles: Array.isArray(files) ? files : [files],
39
+ severity: flags.severity,
40
+ };
41
+ }
42
+ getTSConfig(filePath) {
43
+ const configFileLocation = ts.findConfigFile(filePath ?? ".", (fName) => {
44
+ return (0, fs_1.existsSync)(fName);
45
+ });
46
+ if (!configFileLocation) {
47
+ this.debug(`No TSConfig found`);
48
+ return;
49
+ }
50
+ const configContent = ts.readConfigFile(configFileLocation, (p) => {
51
+ return (0, fs_1.readFileSync)(p, "utf-8");
52
+ });
53
+ if (configContent.error) {
54
+ this.warn(ts.flattenDiagnosticMessageText(configContent.error.messageText, "\n"));
55
+ return;
56
+ }
57
+ const basePath = path_1.default.dirname(configFileLocation);
58
+ const parsedConfigContent = ts.parseJsonConfigFileContent(configContent.config, ts.sys, basePath);
59
+ if (parsedConfigContent.errors.length > 0) {
60
+ throw new Error(`Error while parsing tsconfig: ${parsedConfigContent.errors
61
+ .map((d) => {
62
+ return ts.flattenDiagnosticMessageText(d.messageText, "\n");
63
+ })
64
+ .join("\n\n")}`);
65
+ }
66
+ return parsedConfigContent.options;
67
+ }
68
+ async run() {
69
+ const { inputFiles, severity } = await this.getOptions();
70
+ const files = await (0, globby_1.default)((0, fs_2.convertToFileGlob)(inputFiles, "**/*.(tsx|jsx|js|ts)"), {
71
+ expandDirectories: true,
72
+ });
73
+ const TSConfig = this.getTSConfig() ?? compiler_options_1.DEFAULT_COMPILER_OPTIONS;
74
+ const program = ts.createProgram(files, TSConfig);
75
+ const allDiagnostics = ts.getPreEmitDiagnostics(program);
76
+ const groupedDiagnostics = allDiagnostics.reduce((acc, diagnostic) => {
77
+ const fileName = diagnostic.file?.fileName;
78
+ const category = diagnostic.category;
79
+ if (fileName && files.includes(fileName)) {
80
+ if (!acc[category][fileName]) {
81
+ acc[category][fileName] = [];
82
+ }
83
+ acc[category][fileName].push(diagnostic);
84
+ }
85
+ return acc;
86
+ }, {
87
+ [ts.DiagnosticCategory.Error]: {},
88
+ [ts.DiagnosticCategory.Warning]: {},
89
+ [ts.DiagnosticCategory.Message]: {},
90
+ [ts.DiagnosticCategory.Suggestion]: {},
91
+ });
92
+ const diagnosticCategories = [
93
+ ts.DiagnosticCategory.Error,
94
+ ts.DiagnosticCategory.Warning,
95
+ ts.DiagnosticCategory.Message,
96
+ ts.DiagnosticCategory.Suggestion,
97
+ ];
98
+ diagnosticCategories.forEach((category) => {
99
+ const diagnosticsList = Object.keys(groupedDiagnostics[category]);
100
+ diagnosticsList.forEach((diagnosticGroup) => {
101
+ this.log(`${diagnosticGroup}`);
102
+ groupedDiagnostics[category][diagnosticGroup].forEach((diagnostic) => {
103
+ if (diagnostic.file) {
104
+ const { line, character } = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start ?? 0);
105
+ const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
106
+ let logSymbol = log_symbols_1.default.info;
107
+ switch (category) {
108
+ case ts.DiagnosticCategory.Error:
109
+ logSymbol = log_symbols_1.default.error;
110
+ break;
111
+ case ts.DiagnosticCategory.Warning:
112
+ logSymbol = log_symbols_1.default.warning;
113
+ break;
114
+ case ts.DiagnosticCategory.Message:
115
+ logSymbol = log_symbols_1.default.info;
116
+ break;
117
+ case ts.DiagnosticCategory.Suggestion:
118
+ logSymbol = log_symbols_1.default.info;
119
+ break;
120
+ }
121
+ this.log(` ${logSymbol} (${line + 1},${character + 1}): ${message}`);
122
+ }
123
+ else {
124
+ this.log(ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
125
+ }
126
+ });
127
+ });
128
+ });
129
+ const errorsCount = Object.keys(groupedDiagnostics[ts.DiagnosticCategory.Error]).length;
130
+ if (errorsCount) {
131
+ this.log(`Type or syntax errors found in ${errorsCount} file${errorsCount > 1 ? "s" : ""}, exiting program`);
132
+ if (severity === "error") {
133
+ this.exit(1);
134
+ }
135
+ }
136
+ else {
137
+ this.log(`${log_symbols_1.default.success} No TSX types or errors found.`);
138
+ }
139
+ }
140
+ }
141
+ exports.default = Validate;
142
+ //# sourceMappingURL=validate.js.map
@@ -0,0 +1,18 @@
1
+ import { BaseCommand } from "../../utils/base-command";
2
+ /** A command to validate JSON content */
3
+ export default class Validate extends BaseCommand {
4
+ static description: string;
5
+ static flags: {
6
+ files: import("@oclif/core/lib/interfaces").OptionFlag<string[]>;
7
+ exp: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
8
+ severity: import("@oclif/core/lib/interfaces").OptionFlag<string>;
9
+ config: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
10
+ loglevel: import("@oclif/core/lib/interfaces").OptionFlag<string>;
11
+ };
12
+ private getOptions;
13
+ run(): Promise<{
14
+ /** the status code */
15
+ exitCode: number;
16
+ }>;
17
+ }
18
+ //# sourceMappingURL=validate.d.ts.map
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const core_1 = require("@oclif/core");
5
+ const globby_1 = tslib_1.__importDefault(require("globby"));
6
+ const fs_1 = require("fs");
7
+ const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
8
+ const vscode_languageserver_types_1 = require("vscode-languageserver-types");
9
+ const base_command_1 = require("../../utils/base-command");
10
+ const diag_renderer_1 = require("../../utils/diag-renderer");
11
+ const fs_2 = require("../../utils/fs");
12
+ const task_runner_1 = require("../../utils/task-runner");
13
+ const log_levels_1 = require("../../utils/log-levels");
14
+ /** A command to validate JSON content */
15
+ class Validate extends base_command_1.BaseCommand {
16
+ static description = "Validate Player JSON content";
17
+ static flags = {
18
+ ...base_command_1.BaseCommand.flags,
19
+ files: core_1.Flags.string({
20
+ char: "f",
21
+ description: "A list of files or globs to validate",
22
+ multiple: true,
23
+ }),
24
+ exp: core_1.Flags.boolean({
25
+ description: "Use experimental language features",
26
+ default: false,
27
+ }),
28
+ severity: core_1.Flags.string({
29
+ char: "s",
30
+ description: "The severity of validation issues",
31
+ options: ["error", "warn"],
32
+ default: "error",
33
+ }),
34
+ };
35
+ async getOptions() {
36
+ const { flags } = await this.parse(Validate);
37
+ const config = await this.getPlayerConfig();
38
+ const files = flags.files && flags.files.length > 0 ? flags.files : config.json?.src;
39
+ const { exp } = flags;
40
+ if (!files) {
41
+ throw new Error("JSON validation requires a file list");
42
+ }
43
+ return {
44
+ files: Array.isArray(files) ? files : [files],
45
+ exp,
46
+ severity: flags.severity,
47
+ loglevel: flags.loglevel,
48
+ };
49
+ }
50
+ async run() {
51
+ const { files: inputFiles, exp, severity, loglevel, } = await this.getOptions();
52
+ const expandedFilesList = (0, fs_2.convertToFileGlob)(inputFiles, "**/*.json");
53
+ this.debug("Searching for files using: %o", expandedFilesList);
54
+ const files = await (0, globby_1.default)(expandedFilesList, {
55
+ expandDirectories: true,
56
+ });
57
+ this.debug("Found %i files to process", files.length);
58
+ const results = {
59
+ exitCode: 0,
60
+ };
61
+ const lsp = await this.createLanguageService(exp);
62
+ const taskRunner = (0, task_runner_1.createTaskRunner)({
63
+ renderer: diag_renderer_1.validationRenderer,
64
+ tasks: files.map((f) => ({
65
+ data: {
66
+ file: f,
67
+ },
68
+ run: async () => {
69
+ const contents = await fs_1.promises.readFile(f, "utf-8");
70
+ const validations = (await lsp.validateTextDocument(vscode_languageserver_textdocument_1.TextDocument.create(`file://${f}`, "json", 1, contents))) ?? [];
71
+ return validations;
72
+ },
73
+ })),
74
+ loglevel: (0, log_levels_1.stringToLogLevel)(loglevel),
75
+ });
76
+ const taskResults = await taskRunner.run();
77
+ if (severity !== "error") {
78
+ taskResults.forEach((t) => {
79
+ if (t.error ||
80
+ t.output.some((d) => d.severity === vscode_languageserver_types_1.DiagnosticSeverity.Error)) {
81
+ results.exitCode = 100;
82
+ }
83
+ });
84
+ }
85
+ this.debug("finished");
86
+ this.exit(results.exitCode);
87
+ return results;
88
+ }
89
+ }
90
+ exports.default = Validate;
91
+ //# sourceMappingURL=validate.js.map
@@ -0,0 +1,24 @@
1
+ import { BaseCommand } from "../../utils/base-command";
2
+ /**
3
+ * Exports TS Interfaces/Types to XLR format
4
+ */
5
+ export default class XLRCompile extends BaseCommand {
6
+ static description: string;
7
+ static flags: {
8
+ input: import("@oclif/core/lib/interfaces").OptionFlag<string>;
9
+ output: import("@oclif/core/lib/interfaces").OptionFlag<string>;
10
+ mode: import("@oclif/core/lib/interfaces").OptionFlag<string>;
11
+ config: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
12
+ loglevel: import("@oclif/core/lib/interfaces").OptionFlag<string>;
13
+ };
14
+ private getOptions;
15
+ run(): Promise<{
16
+ /** the status code */
17
+ exitCode: number;
18
+ }>;
19
+ /** Serializes ES6 Maps */
20
+ private replacer;
21
+ /** Generate extension manifest/description files from an Enhanced Player Plugin */
22
+ private processTypes;
23
+ }
24
+ //# sourceMappingURL=compile.d.ts.map
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const core_1 = require("@oclif/core");
5
+ const typescript_1 = tslib_1.__importDefault(require("typescript"));
6
+ const fs_1 = tslib_1.__importDefault(require("fs"));
7
+ const path_1 = tslib_1.__importDefault(require("path"));
8
+ const globby_1 = tslib_1.__importDefault(require("globby"));
9
+ const log_symbols_1 = tslib_1.__importDefault(require("log-symbols"));
10
+ const xlr_converters_1 = require("@player-tools/xlr-converters");
11
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
12
+ const base_command_1 = require("../../utils/base-command");
13
+ const visitors_1 = require("../../utils/xlr/visitors");
14
+ const consts_1 = require("../../utils/xlr/consts");
15
+ /**
16
+ * Exports TS Interfaces/Types to XLR format
17
+ */
18
+ class XLRCompile extends base_command_1.BaseCommand {
19
+ static description = "Compiles typescript files to XLRs format";
20
+ static flags = {
21
+ ...base_command_1.BaseCommand.flags,
22
+ input: core_1.Flags.string({
23
+ char: "i",
24
+ description: "An input directory to search for types to export",
25
+ default: "./src",
26
+ }),
27
+ output: core_1.Flags.string({
28
+ char: "o",
29
+ description: "Output directory to write results to.",
30
+ default: "./dist",
31
+ }),
32
+ mode: core_1.Flags.enum({
33
+ char: "m",
34
+ description: "Search strategy for types to export: plugin (default, looks for exported EnchancedPlayerPlugin classes) or type (all exported types)",
35
+ options: ["plugin", "types"],
36
+ default: "plugin",
37
+ }),
38
+ };
39
+ async getOptions() {
40
+ const { flags } = await this.parse(XLRCompile);
41
+ const config = await this.getPlayerConfig();
42
+ const input = config.xlr?.input ?? flags.input;
43
+ const output = config.xlr?.output ?? flags.output;
44
+ const modeValue = config.xlr?.mode ?? flags.mode;
45
+ return {
46
+ inputPath: input,
47
+ outputDir: path_1.default.join(output, "xlr"),
48
+ mode: modeValue === "plugin" ? consts_1.Mode.PLUGIN : consts_1.Mode.TYPES,
49
+ };
50
+ }
51
+ async run() {
52
+ const { inputPath, outputDir, mode } = await this.getOptions();
53
+ const inputFiles = globby_1.default.sync([
54
+ `${inputPath}/**/*.ts`,
55
+ `${inputPath}/**/*.tsx`,
56
+ ]);
57
+ try {
58
+ this.processTypes(inputFiles, outputDir, {}, mode);
59
+ }
60
+ catch (e) {
61
+ console.log("");
62
+ console.log(chalk_1.default.red(`${log_symbols_1.default.error} Error compiling XLRs: ${e.message}`));
63
+ console.log(chalk_1.default.red(`${e.stack}`));
64
+ this.exit(1);
65
+ }
66
+ return { exitCode: 0 };
67
+ }
68
+ /** Serializes ES6 Maps */
69
+ replacer(key, value) {
70
+ if (value instanceof Map) {
71
+ return Object.fromEntries(value.entries());
72
+ }
73
+ return value;
74
+ }
75
+ /** Generate extension manifest/description files from an Enhanced Player Plugin */
76
+ processTypes(fileNames, outputDirectory, options, mode = consts_1.Mode.PLUGIN) {
77
+ // Build a program using the set of root file names in fileNames
78
+ const program = typescript_1.default.createProgram(fileNames, options);
79
+ fs_1.default.mkdirSync(outputDirectory, { recursive: true });
80
+ // Get the checker, we will use it to find more about classes
81
+ const checker = program.getTypeChecker();
82
+ const converter = new xlr_converters_1.TsConverter(checker, consts_1.customPrimitives);
83
+ let capabilities;
84
+ // Visit every sourceFile in the program
85
+ program.getSourceFiles().forEach((sourceFile) => {
86
+ if (!sourceFile.isDeclarationFile) {
87
+ // Walk the tree to search for classes
88
+ let generatedCapabilites;
89
+ if (mode === consts_1.Mode.PLUGIN) {
90
+ generatedCapabilites = (0, visitors_1.pluginVisitor)({
91
+ sourceFile,
92
+ converter,
93
+ checker,
94
+ outputDirectory,
95
+ });
96
+ }
97
+ else if (mode === consts_1.Mode.TYPES) {
98
+ generatedCapabilites = (0, visitors_1.fileVisitor)({
99
+ sourceFile,
100
+ converter,
101
+ checker,
102
+ outputDirectory,
103
+ });
104
+ }
105
+ else {
106
+ throw new Error(`Error: Option ${mode} not recognized. Valid options are: plugin or type`);
107
+ }
108
+ if (generatedCapabilites) {
109
+ generatedCapabilites = {
110
+ ...generatedCapabilites,
111
+ };
112
+ if (consts_1.customPrimitives) {
113
+ generatedCapabilites = {
114
+ ...generatedCapabilites,
115
+ customPrimitives: consts_1.customPrimitives,
116
+ };
117
+ }
118
+ capabilities = generatedCapabilites;
119
+ }
120
+ }
121
+ });
122
+ if (!capabilities) {
123
+ throw new Error("Error: Unable to parse any XLRs in package");
124
+ }
125
+ // print out the manifest files
126
+ const jsonManifest = JSON.stringify(capabilities, this.replacer, 4);
127
+ fs_1.default.writeFileSync(path_1.default.join(outputDirectory, "manifest.json"), jsonManifest);
128
+ const tsManifestFile = `${[...(capabilities.capabilities?.values() ?? [])]
129
+ .flat(2)
130
+ .map((capability) => {
131
+ return `const ${capability} = require("./${capability}.json")`;
132
+ })
133
+ .join("\n")}
134
+
135
+ module.exports = {
136
+ "pluginName": "${capabilities.pluginName}",
137
+ "capabilities": {
138
+ ${[...(capabilities.capabilities?.entries() ?? [])]
139
+ .map(([capabilityName, provides]) => {
140
+ return `"${capabilityName}":[${provides.join(",")}],`;
141
+ })
142
+ .join("\n\t\t")}
143
+ },
144
+ "customPrimitives": [
145
+ ${[capabilities.customPrimitives?.map((i) => `"${i}"`).join(",") ?? ""]}
146
+ ]
147
+ }
148
+ `;
149
+ fs_1.default.writeFileSync(path_1.default.join(outputDirectory, "manifest.js"), tsManifestFile);
150
+ }
151
+ }
152
+ exports.default = XLRCompile;
153
+ //# sourceMappingURL=compile.js.map
@@ -0,0 +1,20 @@
1
+ import { BaseCommand } from "../../utils/base-command";
2
+ /**
3
+ * Converts XLRs into a specific language
4
+ */
5
+ export default class XLRConvert extends BaseCommand {
6
+ static description: string;
7
+ static flags: {
8
+ input: import("@oclif/core/lib/interfaces").OptionFlag<string>;
9
+ output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
10
+ lang: import("@oclif/core/lib/interfaces").OptionFlag<string>;
11
+ config: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
12
+ loglevel: import("@oclif/core/lib/interfaces").OptionFlag<string>;
13
+ };
14
+ private getOptions;
15
+ run(): Promise<{
16
+ /** the status code */
17
+ exitCode: number;
18
+ }>;
19
+ }
20
+ //# sourceMappingURL=convert.d.ts.map
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const core_1 = require("@oclif/core");
5
+ const path_1 = tslib_1.__importDefault(require("path"));
6
+ const fs_1 = tslib_1.__importDefault(require("fs"));
7
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
8
+ const xlr_sdk_1 = require("@player-tools/xlr-sdk");
9
+ const log_symbols_1 = tslib_1.__importDefault(require("log-symbols"));
10
+ const base_command_1 = require("../../utils/base-command");
11
+ const PlayerImportMap = new Map([
12
+ [
13
+ "@player-ui/types",
14
+ ["Expression", "Asset", "Binding", "AssetWrapper", "Schema.DataType"],
15
+ ],
16
+ ]);
17
+ /**
18
+ * Converts XLRs into a specific language
19
+ */
20
+ class XLRConvert extends base_command_1.BaseCommand {
21
+ static description = "Exports XLRs files to a specific language";
22
+ static flags = {
23
+ ...base_command_1.BaseCommand.flags,
24
+ input: core_1.Flags.string({
25
+ char: "i",
26
+ description: "An input directory to search for types to export",
27
+ default: "./dist",
28
+ }),
29
+ output: core_1.Flags.string({
30
+ char: "o",
31
+ description: "Output directory to write results to.",
32
+ }),
33
+ lang: core_1.Flags.enum({
34
+ char: "l",
35
+ description: "Search strategy for types to export: plugin (default, looks for exported EnchancedPlayerPlugin classes) or type (all exported types)",
36
+ options: ["TypeScript"],
37
+ }),
38
+ };
39
+ async getOptions() {
40
+ const { flags } = await this.parse(XLRConvert);
41
+ const { input, output } = flags;
42
+ if (!output) {
43
+ throw new Error(`Need to specify location to export to`);
44
+ }
45
+ const language = flags.lang;
46
+ if (!language) {
47
+ throw new Error(`Need to specifiy lanauge to export to`);
48
+ }
49
+ return {
50
+ inputPath: input,
51
+ outputDir: path_1.default.join(output, language),
52
+ language,
53
+ };
54
+ }
55
+ async run() {
56
+ const { inputPath, outputDir, language } = await this.getOptions();
57
+ try {
58
+ if (!fs_1.default.existsSync(outputDir)) {
59
+ fs_1.default.mkdirSync(outputDir, { recursive: true });
60
+ }
61
+ const sdk = new xlr_sdk_1.XLRSDK();
62
+ sdk.loadDefinitionsFromDisk(inputPath);
63
+ const files = sdk.exportRegistry(language, PlayerImportMap);
64
+ files.forEach(([filename, fileContents]) => {
65
+ fs_1.default.writeFileSync(path_1.default.join(outputDir, filename), fileContents, {});
66
+ });
67
+ }
68
+ catch (e) {
69
+ console.log("");
70
+ console.log(chalk_1.default.red(`${log_symbols_1.default.error} Error exporting XLRs: ${e.message}`));
71
+ this.exit(1);
72
+ }
73
+ return { exitCode: 0 };
74
+ }
75
+ }
76
+ exports.default = XLRConvert;
77
+ //# sourceMappingURL=convert.js.map
@@ -0,0 +1,39 @@
1
+ import type { PlayerCLIPlugin } from "./plugins";
2
+ export interface PlayerConfigFileShape {
3
+ /** A base config to inherit defaults from */
4
+ extends?: string | PlayerConfigFileShape;
5
+ /** A list of plugins to apply */
6
+ plugins?: Array<string | [string, any] | PlayerCLIPlugin>;
7
+ /** A list of presets to apply */
8
+ presets?: Array<PlayerConfigFileShape | string>;
9
+ }
10
+ export interface PlayerConfigResolvedShape {
11
+ /** Options related to the DSL and compilation */
12
+ dsl?: {
13
+ /** An input directory for compilation */
14
+ src?: string;
15
+ /** An output directory to use */
16
+ outDir?: string;
17
+ /** Flag to omit validating the resulting JSON */
18
+ skipValidation?: boolean;
19
+ };
20
+ /** Options related to JSON and validation */
21
+ json?: {
22
+ /** An input file, directory, glob, or list of any of the above to use as inputs for validation */
23
+ src?: string | string[];
24
+ };
25
+ /** Options related to XLR compilation step */
26
+ xlr?: {
27
+ /** Path to start searching for types to import/export */
28
+ input?: string;
29
+ /** Where to write the resulting files */
30
+ output?: string;
31
+ /** When converting to XLR, what strategy to use */
32
+ mode?: "plugin" | "types";
33
+ };
34
+ /** Flattened list of plugins */
35
+ plugins: Array<PlayerCLIPlugin>;
36
+ /** Catch for any other things that may be in the config for plugged in functionality */
37
+ [key: string]: any;
38
+ }
39
+ //# sourceMappingURL=config.d.ts.map
package/dist/config.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1,7 @@
1
+ export { run } from "@oclif/core";
2
+ export * from "./config";
3
+ export * from "./plugins";
4
+ export * from "./utils/base-command";
5
+ export * from "./utils/compilation-context";
6
+ export * from "./utils/log-levels";
7
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.run = void 0;
4
+ const tslib_1 = require("tslib");
5
+ var core_1 = require("@oclif/core");
6
+ Object.defineProperty(exports, "run", { enumerable: true, get: function () { return core_1.run; } });
7
+ tslib_1.__exportStar(require("./config"), exports);
8
+ tslib_1.__exportStar(require("./plugins"), exports);
9
+ tslib_1.__exportStar(require("./utils/base-command"), exports);
10
+ tslib_1.__exportStar(require("./utils/compilation-context"), exports);
11
+ tslib_1.__exportStar(require("./utils/log-levels"), exports);
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,50 @@
1
+ import type { PlayerLanguageService } from "@player-tools/json-language-service";
2
+ import type { PlayerCLIPlugin } from "./index";
3
+ import { TSManifest } from "@player-tools/xlr";
4
+ /** Loads XLRs into the LSP via the manifest.js file */
5
+ export interface LSPAssetsPluginModuleConfig {
6
+ type: "module";
7
+ /** Result of module import/require of xlr manifest.js file */
8
+ manifest: TSManifest;
9
+ }
10
+ /** Loads XLRs to the LSP by specifying a filesystem location */
11
+ export interface LSPAssetsPluginManifestConfig {
12
+ type: "manifest";
13
+ /** Path to dist folder for XLR enabled plugins */
14
+ path: string;
15
+ }
16
+ /**
17
+ * Legacy type for providing XLR manifest paths that assumes its a manifest
18
+ * @deprecated
19
+ * */
20
+ export interface LSPAssetsPluginLegacyConfig {
21
+ type?: undefined;
22
+ path: string;
23
+ }
24
+ export type LSPAssetPluginConfigTypes = LSPAssetsPluginModuleConfig | LSPAssetsPluginManifestConfig | LSPAssetsPluginLegacyConfig;
25
+ export type LSPAssetsPluginConfig = LSPAssetPluginConfigTypes & {
26
+ /** Provides experimental language features */
27
+ exp?: boolean;
28
+ };
29
+ /**
30
+ * Handles setting the assets when loading the LSP
31
+ *
32
+ * {
33
+ * "plugins": [
34
+ * [
35
+ * "@cli/lsp-assets-plugin",
36
+ * {
37
+ * "path": "<url> or <path>"
38
+ * }
39
+ * ]
40
+ * ]
41
+ * }
42
+ *
43
+ */
44
+ export declare class LSPAssetsPlugin implements PlayerCLIPlugin {
45
+ private config;
46
+ constructor(config: LSPAssetsPluginConfig | Array<LSPAssetsPluginConfig>);
47
+ onCreateLanguageService(lsp: PlayerLanguageService, exp: boolean): Promise<void>;
48
+ loadConfig(config: LSPAssetPluginConfigTypes, lsp: PlayerLanguageService): Promise<void>;
49
+ }
50
+ //# sourceMappingURL=LSPAssetsPlugin.d.ts.map