@player-tools/cli 0.0.2-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/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # Player CLI
2
+
3
+ ## Config
4
+
5
+ Config files are able to customize the behavior of the CLI commands without requiring args. Behavior specific to execution can leverage `plugins`, which can be composed together using `presets`. Full configs can also be shared using `extensions`.
6
+
7
+ To resolve a full configuration, the `extension` is taken as the base, the `presets` are applied in order, then local `plugins`.
8
+ The format is similar to `eslint`, `babel` and other .rc/json/js based approaches.
9
+
10
+ Config files are searched using cosmiconfig, which will look for:
11
+
12
+ - a `player` property in package.json
13
+ - a `.playerrc` file in JSON or YAML format
14
+ - a `.player.json`, `.playerrc.yaml`, `.playerrc.yml`, `.playerrc.js`, or `.playerrc.cjs` file
15
+ - a `player.config.js` or `player.config.cjs` CommonJS module exporting an object
16
+
17
+ Example:
18
+
19
+ ```js
20
+ module.exports = {
21
+ extends: '@my-scope/base',
22
+ plugins: [
23
+ 'plugin-npm-package',
24
+ ['some-plugin-with-config', { config: true }],
25
+ {
26
+ // Plugins can also be defined inline
27
+ handler: () => {},
28
+ },
29
+ ],
30
+ };
31
+ ```
32
+
33
+ Options defined via the CLI arguments will take precedence over the config files (for things that overlap).
34
+
35
+ ## Plugins
36
+
37
+ Plugins are the way to change runtime behavior of the CLI actions. This includes augmenting the behavior of the DSL compiler, language-service, and more.
38
+
39
+ # Commands
40
+
41
+ <!-- commands -->
42
+
43
+ - [`player dsl compile`](#player-dsl-compile)
44
+
45
+ ## `player dsl compile`
46
+
47
+ Compile Player DSL files into JSON
48
+
49
+ ```
50
+ USAGE
51
+ $ player dsl compile -i <value> [-c <value>] [-o <value>] [--skip-validation]
52
+
53
+ FLAGS
54
+ -c, --config=<value> Path to a specific config file to load.
55
+ By default, will automatically search for an rc or config file to load
56
+ -i, --input=<value> (required) An input directory to compile.
57
+ Any jsx/ts/tsx files will be loaded via babel-require automatically.
58
+ -o, --output=<value> [default: _out] Output directory to write results to
59
+ --skip-validation Option to skip validating the generated JSON
60
+
61
+ DESCRIPTION
62
+ Compile Player DSL files into JSON
63
+ ```
64
+
65
+ <!-- commandsstop -->
package/bin/run ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+
3
+ const oclif = require('@oclif/core')
4
+ process.env.NODE_ENV = 'production'
5
+
6
+ oclif.run().then(require('@oclif/core/flush')).catch(require('@oclif/core/handle'))
@@ -0,0 +1,18 @@
1
+ import { BaseCommand } from '../../utils/base-command';
2
+ /** A command to compile player DSL content into JSON */
3
+ export default class DSLCompile extends BaseCommand {
4
+ static description: string;
5
+ static flags: {
6
+ input: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
7
+ output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
8
+ 'skip-validation': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
9
+ exp: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
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=compile.d.ts.map
@@ -0,0 +1,146 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ /* eslint-disable no-await-in-loop */
16
+ /* eslint-disable @typescript-eslint/no-var-requires */
17
+ /* eslint-disable global-require */
18
+ /* eslint-disable import/no-dynamic-require */
19
+ const core_1 = require("@oclif/core");
20
+ const globby_1 = __importDefault(require("globby"));
21
+ const path_1 = __importDefault(require("path"));
22
+ 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"));
27
+ const base_command_1 = require("../../utils/base-command");
28
+ const fs_2 = require("../../utils/fs");
29
+ const babel_register_1 = require("../../utils/babel-register");
30
+ const validate_1 = __importDefault(require("../json/validate"));
31
+ /** A command to compile player DSL content into JSON */
32
+ class DSLCompile extends base_command_1.BaseCommand {
33
+ getOptions() {
34
+ var _a, _b, _c, _d, _e, _f, _g, _h;
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ const { flags } = yield this.parse(DSLCompile);
37
+ const config = yield this.getPlayerConfig();
38
+ const input = (_a = flags.input) !== null && _a !== void 0 ? _a : (_b = config.dsl) === null || _b === void 0 ? void 0 : _b.src;
39
+ const { exp } = flags;
40
+ if (!input) {
41
+ throw new Error(`Input files are required for DSL compilation`);
42
+ }
43
+ return {
44
+ input,
45
+ output: (_e = (_c = flags.output) !== null && _c !== void 0 ? _c : (_d = config.dsl) === null || _d === void 0 ? void 0 : _d.outDir) !== null && _e !== void 0 ? _e : '_out',
46
+ skipValidation: (_h = (_f = flags['skip-validation']) !== null && _f !== void 0 ? _f : (_g = config.dsl) === null || _g === void 0 ? void 0 : _g.skipValidation) !== null && _h !== void 0 ? _h : false,
47
+ exp,
48
+ };
49
+ });
50
+ }
51
+ run() {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ const { input, output, skipValidation, exp } = yield this.getOptions();
54
+ const files = yield (0, globby_1.default)((0, fs_2.convertToFileGlob)([input], '**/*.(tsx|jsx|js|ts)'), {
55
+ expandDirectories: true,
56
+ });
57
+ (0, babel_register_1.registerForPaths)();
58
+ this.debug('Found %i files to process', files.length);
59
+ const results = {
60
+ exitCode: 0,
61
+ };
62
+ /** Compile a file from the DSL format into JSON */
63
+ const compileFile = (file) => __awaiter(this, void 0, void 0, function* () {
64
+ const compiler = yield this.createDSLCompiler();
65
+ const requiredModule = require(path_1.default.resolve(file));
66
+ const defaultExport = requiredModule.default;
67
+ if (!defaultExport) {
68
+ return;
69
+ }
70
+ let relativePath = path_1.default.relative(input, file);
71
+ if (!relativePath) {
72
+ relativePath = path_1.default.basename(file);
73
+ }
74
+ const outputFile = path_1.default.join(output, path_1.default.format(Object.assign(Object.assign({}, path_1.default.parse(relativePath)), { base: undefined, ext: '.json' })));
75
+ this.log(`${log_symbols_1.default.info} Compiling %s ${figures_1.default.arrowRight} %s`, (0, fs_2.normalizePath)(file), (0, fs_2.normalizePath)(outputFile));
76
+ const { value, contentType } = yield compiler.serialize(defaultExport);
77
+ const contentStr = JSON.stringify(value, null, 2);
78
+ yield (0, mkdirp_1.default)(path_1.default.dirname(outputFile));
79
+ yield fs_1.promises.writeFile(outputFile, contentStr);
80
+ return {
81
+ contentType,
82
+ outputFile,
83
+ inputFile: file,
84
+ };
85
+ });
86
+ const compilerResults = [];
87
+ // This has to be done serially b/c of the way React logs messages to console.error
88
+ // Otherwise the errors in console will be randomly interspersed between update messages
89
+ for (let fIndex = 0; fIndex < files.length; fIndex += 1) {
90
+ const file = files[fIndex];
91
+ try {
92
+ const result = yield compileFile(file);
93
+ compilerResults.push({
94
+ output: result,
95
+ state: 'completed',
96
+ });
97
+ }
98
+ catch (e) {
99
+ results.exitCode = 100;
100
+ console.log('');
101
+ console.log(chalk_1.default.red(`${log_symbols_1.default.error} Error compiling ${file}: ${e.message}`));
102
+ this.debug(e);
103
+ compilerResults.push({
104
+ state: 'completed',
105
+ error: e,
106
+ });
107
+ }
108
+ }
109
+ if (!skipValidation) {
110
+ console.log('');
111
+ const hasOutput = compilerResults.some((r) => { var _a; return ((_a = r.output) === null || _a === void 0 ? void 0 : _a.contentType) === 'flow'; });
112
+ if (hasOutput) {
113
+ yield validate_1.default.run([
114
+ '-f',
115
+ ...compilerResults
116
+ .filter((r) => { var _a; return ((_a = r.output) === null || _a === void 0 ? void 0 : _a.contentType) === 'flow'; })
117
+ .map((result) => {
118
+ var _a, _b;
119
+ return (_b = (_a = result.output) === null || _a === void 0 ? void 0 : _a.outputFile) !== null && _b !== void 0 ? _b : '';
120
+ }),
121
+ ...(exp ? ['--exp'] : []),
122
+ ]);
123
+ }
124
+ else {
125
+ console.log('No output to validate');
126
+ }
127
+ }
128
+ this.exit(results.exitCode);
129
+ return results;
130
+ });
131
+ }
132
+ }
133
+ exports.default = DSLCompile;
134
+ DSLCompile.description = 'Compile Player DSL files into JSON';
135
+ DSLCompile.flags = Object.assign(Object.assign({}, base_command_1.BaseCommand.flags), { input: core_1.Flags.string({
136
+ char: 'i',
137
+ description: 'An input directory to compile.\nAny jsx/ts/tsx files will be loaded via babel-require automatically.',
138
+ }), output: core_1.Flags.string({
139
+ char: 'o',
140
+ description: 'Output directory to write results to.',
141
+ }), 'skip-validation': core_1.Flags.boolean({
142
+ description: 'Option to skip validating the generated JSON',
143
+ }), exp: core_1.Flags.boolean({
144
+ description: 'Use experimental language features',
145
+ default: false,
146
+ }) });
@@ -0,0 +1,16 @@
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
+ config: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
9
+ };
10
+ private getOptions;
11
+ run(): Promise<{
12
+ /** the status code */
13
+ exitCode: number;
14
+ }>;
15
+ }
16
+ //# sourceMappingURL=validate.d.ts.map
@@ -0,0 +1,91 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const core_1 = require("@oclif/core");
16
+ const globby_1 = __importDefault(require("globby"));
17
+ const fs_1 = require("fs");
18
+ const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
19
+ const vscode_languageserver_types_1 = require("vscode-languageserver-types");
20
+ const base_command_1 = require("../../utils/base-command");
21
+ const diag_renderer_1 = require("../../utils/diag-renderer");
22
+ const fs_2 = require("../../utils/fs");
23
+ const task_runner_1 = require("../../utils/task-runner");
24
+ /** A command to validate JSON content */
25
+ class Validate extends base_command_1.BaseCommand {
26
+ getOptions() {
27
+ var _a;
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ const { flags } = yield this.parse(Validate);
30
+ const config = yield this.getPlayerConfig();
31
+ const files = flags.files && flags.files.length > 0 ? flags.files : (_a = config.json) === null || _a === void 0 ? void 0 : _a.src;
32
+ const { exp } = flags;
33
+ if (!files) {
34
+ throw new Error('JSON validation requires a file list');
35
+ }
36
+ return {
37
+ files: Array.isArray(files) ? files : [files],
38
+ exp,
39
+ };
40
+ });
41
+ }
42
+ run() {
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ const { files: inputFiles, exp } = yield this.getOptions();
45
+ const expandedFilesList = (0, fs_2.convertToFileGlob)(inputFiles, '**/*.json');
46
+ this.debug('Searching for files using: %o', expandedFilesList);
47
+ const files = yield (0, globby_1.default)(expandedFilesList, {
48
+ expandDirectories: true,
49
+ });
50
+ this.debug('Found %i files to process', files.length);
51
+ const results = {
52
+ exitCode: 0,
53
+ };
54
+ const taskRunner = (0, task_runner_1.createTaskRunner)({
55
+ renderer: diag_renderer_1.validationRenderer,
56
+ tasks: files.map((f) => ({
57
+ data: {
58
+ file: f,
59
+ },
60
+ run: () => __awaiter(this, void 0, void 0, function* () {
61
+ var _a;
62
+ const contents = yield fs_1.promises.readFile(f, 'utf-8');
63
+ const lsp = yield this.createLanguageService(exp);
64
+ const validations = (_a = (yield lsp.validateTextDocument(vscode_languageserver_textdocument_1.TextDocument.create(`file://${f}`, 'json', 1, contents)))) !== null && _a !== void 0 ? _a : [];
65
+ return validations;
66
+ }),
67
+ })),
68
+ });
69
+ const taskResults = yield taskRunner.run();
70
+ taskResults.forEach((t) => {
71
+ if (t.error ||
72
+ t.output.some((d) => d.severity === vscode_languageserver_types_1.DiagnosticSeverity.Error)) {
73
+ results.exitCode = 100;
74
+ }
75
+ });
76
+ this.debug('finished');
77
+ this.exit(results.exitCode);
78
+ return results;
79
+ });
80
+ }
81
+ }
82
+ exports.default = Validate;
83
+ Validate.description = 'Validate Player JSON content';
84
+ Validate.flags = Object.assign(Object.assign({}, base_command_1.BaseCommand.flags), { files: core_1.Flags.string({
85
+ char: 'f',
86
+ description: 'A list of files or globs to validate',
87
+ multiple: true,
88
+ }), exp: core_1.Flags.boolean({
89
+ description: 'Use experimental language features',
90
+ default: false,
91
+ }) });
@@ -0,0 +1,23 @@
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
+ };
13
+ private getOptions;
14
+ run(): Promise<{
15
+ /** the status code */
16
+ exitCode: number;
17
+ }>;
18
+ /** Serializes ES6 Maps */
19
+ private replacer;
20
+ /** Generate extension manifest/description files from an Enhanced Player Plugin */
21
+ private processPlugin;
22
+ }
23
+ //# sourceMappingURL=compile.d.ts.map
@@ -0,0 +1,233 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const core_1 = require("@oclif/core");
16
+ const typescript_1 = __importDefault(require("typescript"));
17
+ const fs_1 = __importDefault(require("fs"));
18
+ const path_1 = __importDefault(require("path"));
19
+ const globby_1 = __importDefault(require("globby"));
20
+ const log_symbols_1 = __importDefault(require("log-symbols"));
21
+ const xlr_converters_1 = require("@player-tools/xlr-converters");
22
+ const xlr_utils_1 = require("@player-tools/xlr-utils");
23
+ const chalk_1 = __importDefault(require("chalk"));
24
+ const base_command_1 = require("../../utils/base-command");
25
+ const PLAYER_PLUGIN_INTERFACE_NAME = 'ExtendedPlayerPlugin';
26
+ const customPrimitives = [
27
+ 'Expression',
28
+ 'Asset',
29
+ 'Binding',
30
+ 'AssetWrapper',
31
+ 'Schema.DataType',
32
+ ];
33
+ var Mode;
34
+ (function (Mode) {
35
+ Mode["PLUGIN"] = "plugin";
36
+ Mode["TYPES"] = "types";
37
+ })(Mode || (Mode = {}));
38
+ /**
39
+ * Exports TS Interfaces/Types to XLR format
40
+ */
41
+ class XLRCompile extends base_command_1.BaseCommand {
42
+ getOptions() {
43
+ var _a, _b, _c, _d, _e, _f;
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ const { flags } = yield this.parse(XLRCompile);
46
+ const config = yield this.getPlayerConfig();
47
+ const input = (_b = (_a = config.xlr) === null || _a === void 0 ? void 0 : _a.input) !== null && _b !== void 0 ? _b : flags.input;
48
+ const output = (_d = (_c = config.xlr) === null || _c === void 0 ? void 0 : _c.output) !== null && _d !== void 0 ? _d : flags.output;
49
+ const modeValue = (_f = (_e = config.xlr) === null || _e === void 0 ? void 0 : _e.mode) !== null && _f !== void 0 ? _f : flags.mode;
50
+ return {
51
+ inputPath: input,
52
+ outputDir: path_1.default.join(output, 'xlr'),
53
+ mode: modeValue === 'plugin' ? Mode.PLUGIN : Mode.TYPES,
54
+ };
55
+ });
56
+ }
57
+ run() {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ const { inputPath, outputDir, mode } = yield this.getOptions();
60
+ const inputFiles = globby_1.default.sync([
61
+ `${inputPath}/**/*.ts`,
62
+ `${inputPath}/**/*.tsx`,
63
+ ]);
64
+ try {
65
+ this.processPlugin(inputFiles, outputDir, {}, mode);
66
+ }
67
+ catch (e) {
68
+ console.log('');
69
+ console.log(chalk_1.default.red(`${log_symbols_1.default.error} Error compiling XLRs: ${e.message}`));
70
+ console.log(chalk_1.default.red(`${e.stack}`));
71
+ return {
72
+ exitCode: 1,
73
+ };
74
+ }
75
+ return { exitCode: 0 };
76
+ });
77
+ }
78
+ /** Serializes ES6 Maps */
79
+ replacer(key, value) {
80
+ if (value instanceof Map) {
81
+ return Object.fromEntries(value.entries());
82
+ }
83
+ return value;
84
+ }
85
+ /** Generate extension manifest/description files from an Enhanced Player Plugin */
86
+ processPlugin(fileNames, outputDir, options, mode = Mode.PLUGIN) {
87
+ var _a, _b, _c, _d;
88
+ // Build a program using the set of root file names in fileNames
89
+ const program = typescript_1.default.createProgram(fileNames, options);
90
+ fs_1.default.mkdirSync(outputDir, { recursive: true });
91
+ // Get the checker, we will use it to find more about classes
92
+ const checker = program.getTypeChecker();
93
+ const capabilities = {
94
+ pluginName: 'Unknown Plugin',
95
+ };
96
+ const converter = new xlr_converters_1.TsConverter(checker, customPrimitives);
97
+ /** visit nodes finding exported classes */
98
+ function pluginVisitor(node) {
99
+ var _a;
100
+ // Only consider exported nodes
101
+ if (!(0, xlr_utils_1.isNodeExported)(node)) {
102
+ return;
103
+ }
104
+ // Plugins are classes so filter those
105
+ if (typescript_1.default.isClassDeclaration(node) && node.name) {
106
+ const symbol = checker.getSymbolAtLocation(node.name);
107
+ if (symbol) {
108
+ // look at what they implement
109
+ (_a = node.heritageClauses) === null || _a === void 0 ? void 0 : _a.forEach((heritage) => {
110
+ var _a;
111
+ capabilities.pluginName =
112
+ ((_a = node.name) === null || _a === void 0 ? void 0 : _a.text) || capabilities.pluginName;
113
+ heritage.types.forEach((hInterface) => {
114
+ var _a, _b, _c;
115
+ // check if heritage is right one
116
+ if (hInterface.expression.getText() !== PLAYER_PLUGIN_INTERFACE_NAME) {
117
+ return;
118
+ }
119
+ const provides = new Map();
120
+ const typeArgs = hInterface.typeArguments;
121
+ const pluginDec = (_b = (_a = checker.getTypeAtLocation(hInterface).symbol) === null || _a === void 0 ? void 0 : _a.declarations) === null || _b === void 0 ? void 0 : _b[0];
122
+ // process type parameters to figure out what capabilities are provided
123
+ (_c = pluginDec === null || pluginDec === void 0 ? void 0 : pluginDec.typeParameters) === null || _c === void 0 ? void 0 : _c.forEach((param, index) => {
124
+ var _a;
125
+ const capabilityType = param.name.getText();
126
+ if (index < ((_a = typeArgs === null || typeArgs === void 0 ? void 0 : typeArgs.length) !== null && _a !== void 0 ? _a : 0)) {
127
+ const exportedCapabilities = typeArgs === null || typeArgs === void 0 ? void 0 : typeArgs[index];
128
+ // if its an array process each type
129
+ if (typescript_1.default.isTupleTypeNode(exportedCapabilities)) {
130
+ const capabilityNames = exportedCapabilities.elements.map((element) => {
131
+ var _a, _b;
132
+ if (typescript_1.default.isTypeReferenceNode(element)) {
133
+ const referenceSymbol = checker.getSymbolAtLocation(element.typeName);
134
+ const alias = referenceSymbol
135
+ ? checker.getAliasedSymbol(referenceSymbol)
136
+ : undefined;
137
+ const varDecl = (_a = alias === null || alias === void 0 ? void 0 : alias.declarations) === null || _a === void 0 ? void 0 : _a[0];
138
+ if (varDecl &&
139
+ (typescript_1.default.isInterfaceDeclaration(varDecl) ||
140
+ typescript_1.default.isTypeAliasDeclaration(varDecl))) {
141
+ const capabilityDescription = converter.convertDeclaration(varDecl);
142
+ const capabilityName = (_b = capabilityDescription === null || capabilityDescription === void 0 ? void 0 : capabilityDescription.name) !== null && _b !== void 0 ? _b : 'error';
143
+ fs_1.default.writeFileSync(path_1.default.join(outputDir, `${capabilityName}.json`), JSON.stringify(capabilityDescription, undefined, 4));
144
+ return capabilityName;
145
+ }
146
+ }
147
+ throw new Error(`Can't export non reference type ${element.getText()}`);
148
+ });
149
+ provides.set(capabilityType, capabilityNames);
150
+ }
151
+ else if (typescript_1.default.isTypeReferenceNode(exportedCapabilities)) {
152
+ const capabilityName = exportedCapabilities.typeName.getText();
153
+ const capabilityDescription = converter.convertTsTypeNode(exportedCapabilities);
154
+ fs_1.default.writeFileSync(path_1.default.join(outputDir, `${capabilityName}.json`), JSON.stringify(capabilityDescription, undefined, 4));
155
+ provides.set(capabilityType, [capabilityName]);
156
+ }
157
+ else {
158
+ throw new Error(`Can't figure out type ${capabilityType}`);
159
+ }
160
+ }
161
+ });
162
+ capabilities.capabilities = provides;
163
+ });
164
+ });
165
+ }
166
+ }
167
+ }
168
+ /** export all exported types in the file */
169
+ function fileVisitor(file) {
170
+ const convertedTypes = converter.convertSourceFile(file);
171
+ convertedTypes.data.types.forEach((type) => {
172
+ fs_1.default.writeFileSync(path_1.default.join(outputDir, `${type.name}.json`), JSON.stringify(type, undefined, 4));
173
+ });
174
+ capabilities.capabilities = new Map([
175
+ ['Types', convertedTypes.convertedTypes],
176
+ ]);
177
+ }
178
+ // Visit every sourceFile in the program
179
+ program.getSourceFiles().forEach((sourceFile) => {
180
+ if (!sourceFile.isDeclarationFile) {
181
+ // Walk the tree to search for classes
182
+ if (mode === Mode.PLUGIN) {
183
+ typescript_1.default.forEachChild(sourceFile, pluginVisitor);
184
+ }
185
+ else if (mode === Mode.TYPES) {
186
+ capabilities.pluginName = 'Types';
187
+ fileVisitor(sourceFile);
188
+ }
189
+ else {
190
+ throw new Error(`Error: Option ${mode} not recognized. Valid options are: plugin or type`);
191
+ }
192
+ }
193
+ });
194
+ // print out the manifest files
195
+ const jsonManifest = JSON.stringify(capabilities, this.replacer, 4);
196
+ fs_1.default.writeFileSync(path_1.default.join(outputDir, 'manifest.json'), jsonManifest);
197
+ const tsManifestFile = `${[...((_b = (_a = capabilities.capabilities) === null || _a === void 0 ? void 0 : _a.values()) !== null && _b !== void 0 ? _b : [])]
198
+ .flat(2)
199
+ .map((capability) => {
200
+ return `import ${capability} from './${capability}.json'`;
201
+ })
202
+ .join('\n')}
203
+
204
+ export default {
205
+ "pluginName": "${capabilities.pluginName}",
206
+ "capabilities": {
207
+ ${[...((_d = (_c = capabilities.capabilities) === null || _c === void 0 ? void 0 : _c.entries()) !== null && _d !== void 0 ? _d : [])]
208
+ .map(([capabilityName, provides]) => {
209
+ return `"${capabilityName}":[${provides.join(',')}],`;
210
+ })
211
+ .join('\n\t\t')}
212
+ }
213
+ }
214
+ `;
215
+ fs_1.default.writeFileSync(path_1.default.join(outputDir, 'manifest.js'), tsManifestFile);
216
+ }
217
+ }
218
+ exports.default = XLRCompile;
219
+ XLRCompile.description = 'Compiles typescript files to XLRs format';
220
+ XLRCompile.flags = Object.assign(Object.assign({}, base_command_1.BaseCommand.flags), { input: core_1.Flags.string({
221
+ char: 'i',
222
+ description: 'An input directory to search for types to export',
223
+ default: './src',
224
+ }), output: core_1.Flags.string({
225
+ char: 'o',
226
+ description: 'Output directory to write results to.',
227
+ default: './dist',
228
+ }), mode: core_1.Flags.enum({
229
+ char: 'm',
230
+ description: 'Search strategy for types to export: plugin (default, looks for exported EnchancedPlayerPlugin classes) or type (all exported types)',
231
+ options: ['plugin', 'types'],
232
+ default: 'plugin',
233
+ }) });
@@ -0,0 +1,19 @@
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
+ };
13
+ private getOptions;
14
+ run(): Promise<{
15
+ /** the status code */
16
+ exitCode: number;
17
+ }>;
18
+ }
19
+ //# sourceMappingURL=convert.d.ts.map