@player-tools/cli 0.4.0-next.4 → 0.4.0-next.5
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/dsl/compile.js +31 -14
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/plugins/index.d.ts +5 -0
- package/dist/utils/base-command.d.ts +2 -0
- package/dist/utils/base-command.js +13 -0
- package/dist/utils/compilation-context.d.ts +31 -0
- package/dist/utils/compilation-context.js +48 -0
- package/dist/utils/fs.js +8 -2
- package/oclif.manifest.json +1 -1
- package/package.json +8 -6
|
@@ -24,6 +24,7 @@ const mkdirp_1 = __importDefault(require("mkdirp"));
|
|
|
24
24
|
const log_symbols_1 = __importDefault(require("log-symbols"));
|
|
25
25
|
const figures_1 = __importDefault(require("figures"));
|
|
26
26
|
const chalk_1 = __importDefault(require("chalk"));
|
|
27
|
+
const dsl_1 = require("@player-tools/dsl");
|
|
27
28
|
const base_command_1 = require("../../utils/base-command");
|
|
28
29
|
const fs_2 = require("../../utils/fs");
|
|
29
30
|
const babel_register_1 = require("../../utils/babel-register");
|
|
@@ -59,7 +60,7 @@ class DSLCompile extends base_command_1.BaseCommand {
|
|
|
59
60
|
const results = {
|
|
60
61
|
exitCode: 0,
|
|
61
62
|
};
|
|
62
|
-
const
|
|
63
|
+
const context = yield this.createCompilerContext();
|
|
63
64
|
/** Compile a file from the DSL format into JSON */
|
|
64
65
|
const compileFile = (file) => __awaiter(this, void 0, void 0, function* () {
|
|
65
66
|
const requiredModule = require(path_1.default.resolve(file));
|
|
@@ -67,21 +68,37 @@ class DSLCompile extends base_command_1.BaseCommand {
|
|
|
67
68
|
if (!defaultExport) {
|
|
68
69
|
return;
|
|
69
70
|
}
|
|
71
|
+
const preProcessedValue = yield context.dslCompiler.hooks.preProcessFlow.call(defaultExport);
|
|
72
|
+
const contentType = (yield context.hooks.identifyContentType.call(file, preProcessedValue)) ||
|
|
73
|
+
(0, dsl_1.fingerprintContent)(preProcessedValue, file) ||
|
|
74
|
+
'unknown';
|
|
70
75
|
let relativePath = path_1.default.relative(input, file);
|
|
71
76
|
if (!relativePath) {
|
|
72
77
|
relativePath = path_1.default.basename(file);
|
|
73
78
|
}
|
|
74
79
|
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 {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
contentType,
|
|
98
|
+
outputFile,
|
|
99
|
+
inputFile: file,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
85
102
|
});
|
|
86
103
|
const compilerResults = [];
|
|
87
104
|
// This has to be done serially b/c of the way React logs messages to console.error
|
|
@@ -97,8 +114,8 @@ class DSLCompile extends base_command_1.BaseCommand {
|
|
|
97
114
|
}
|
|
98
115
|
catch (e) {
|
|
99
116
|
results.exitCode = 100;
|
|
100
|
-
|
|
101
|
-
|
|
117
|
+
this.log('');
|
|
118
|
+
this.log(chalk_1.default.red(`${log_symbols_1.default.error} Error compiling ${file}: ${e.message}`));
|
|
102
119
|
this.debug(e);
|
|
103
120
|
compilerResults.push({
|
|
104
121
|
state: 'completed',
|
|
@@ -106,7 +123,7 @@ class DSLCompile extends base_command_1.BaseCommand {
|
|
|
106
123
|
});
|
|
107
124
|
}
|
|
108
125
|
}
|
|
109
|
-
yield
|
|
126
|
+
yield context.dslCompiler.hooks.onEnd.call({ output });
|
|
110
127
|
if (!skipValidation) {
|
|
111
128
|
console.log('');
|
|
112
129
|
const hasOutput = compilerResults.some((r) => { var _a; return ((_a = r.output) === null || _a === void 0 ? void 0 : _a.contentType) === 'flow'; });
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -20,3 +20,4 @@ Object.defineProperty(exports, "run", { enumerable: true, get: function () { ret
|
|
|
20
20
|
__exportStar(require("./config"), exports);
|
|
21
21
|
__exportStar(require("./plugins"), exports);
|
|
22
22
|
__exportStar(require("./utils/base-command"), exports);
|
|
23
|
+
__exportStar(require("./utils/compilation-context"), exports);
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { PlayerLanguageService } from '@player-tools/json-language-service'
|
|
|
2
2
|
import type { DSLCompiler } from '@player-tools/dsl';
|
|
3
3
|
import type { ExportTypes } from '@player-tools/xlr-sdk';
|
|
4
4
|
import type { TransformFunction } from '@player-tools/xlr';
|
|
5
|
+
import type { CompilationContext } from '../utils/compilation-context';
|
|
5
6
|
export * from './LSPAssetsPlugin';
|
|
6
7
|
export interface PlayerCLIPlugin {
|
|
7
8
|
/**
|
|
@@ -19,6 +20,10 @@ export interface PlayerCLIPlugin {
|
|
|
19
20
|
* Append the transforms to apply to the passed in array based on the provided format
|
|
20
21
|
*/
|
|
21
22
|
onConvertXLR?: (format: ExportTypes, transforms: Array<TransformFunction>) => void | Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Handler to expose hooks that influence how content is compiled
|
|
25
|
+
*/
|
|
26
|
+
createCompilerContext?: (context: CompilationContext) => void | Promise<void>;
|
|
22
27
|
}
|
|
23
28
|
export declare type PlayerCLIClass = {
|
|
24
29
|
new (): PlayerCLIPlugin;
|
|
@@ -4,6 +4,7 @@ import { DSLCompiler } from '@player-tools/dsl';
|
|
|
4
4
|
import type { ExportTypes } from '@player-tools/xlr-sdk';
|
|
5
5
|
import type { TransformFunction } from '@player-tools/xlr';
|
|
6
6
|
import type { PlayerConfigResolvedShape } from '../config';
|
|
7
|
+
import { CompilationContext } from './compilation-context';
|
|
7
8
|
/** The common configs for all */
|
|
8
9
|
export declare abstract class BaseCommand extends Command {
|
|
9
10
|
static flags: {
|
|
@@ -18,6 +19,7 @@ export declare abstract class BaseCommand extends Command {
|
|
|
18
19
|
createLanguageService(exp: boolean): Promise<PlayerLanguageService>;
|
|
19
20
|
createDSLCompiler(): Promise<DSLCompiler>;
|
|
20
21
|
getXLRTransforms(format: ExportTypes): Promise<Array<TransformFunction>>;
|
|
22
|
+
createCompilerContext(): Promise<CompilationContext>;
|
|
21
23
|
exit(code?: number): void;
|
|
22
24
|
}
|
|
23
25
|
//# sourceMappingURL=base-command.d.ts.map
|
|
@@ -21,6 +21,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
21
21
|
const cosmiconfig_1 = require("cosmiconfig");
|
|
22
22
|
const json_language_service_1 = require("@player-tools/json-language-service");
|
|
23
23
|
const dsl_1 = require("@player-tools/dsl");
|
|
24
|
+
const compilation_context_1 = require("./compilation-context");
|
|
24
25
|
const configLoader = (0, cosmiconfig_1.cosmiconfig)('player');
|
|
25
26
|
/** The common configs for all */
|
|
26
27
|
class BaseCommand extends core_1.Command {
|
|
@@ -151,6 +152,18 @@ class BaseCommand extends core_1.Command {
|
|
|
151
152
|
return transforms;
|
|
152
153
|
});
|
|
153
154
|
}
|
|
155
|
+
createCompilerContext() {
|
|
156
|
+
var _a, _b;
|
|
157
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
158
|
+
const compilerContext = new compilation_context_1.CompilationContext(yield this.createDSLCompiler());
|
|
159
|
+
const { plugins } = yield this.getPlayerConfig();
|
|
160
|
+
for (let i = 0; i < plugins.length; i++) {
|
|
161
|
+
// eslint-disable-next-line no-await-in-loop
|
|
162
|
+
yield ((_b = (_a = plugins[i]).createCompilerContext) === null || _b === void 0 ? void 0 : _b.call(_a, compilerContext));
|
|
163
|
+
}
|
|
164
|
+
return compilerContext;
|
|
165
|
+
});
|
|
166
|
+
}
|
|
154
167
|
exit(code) {
|
|
155
168
|
if (process.env.NODE_ENV !== 'test') {
|
|
156
169
|
super.exit(code);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { DSLCompiler, CompilerReturn, SerializeContext } from '@player-tools/dsl';
|
|
2
|
+
import { AsyncSeriesBailHook } from 'tapable-ts';
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
export declare class CompilationContext {
|
|
7
|
+
/** Hooks to wrap the context of the compilation */
|
|
8
|
+
hooks: {
|
|
9
|
+
/**
|
|
10
|
+
* Function for determining a specific or desired content type given on the file contents or other conditions
|
|
11
|
+
*
|
|
12
|
+
* @param fileName - The relative name of the file
|
|
13
|
+
* @param content - The contents in the file
|
|
14
|
+
* @returns string with the content type.
|
|
15
|
+
*/
|
|
16
|
+
identifyContentType: AsyncSeriesBailHook<[string, any], string, Record<string, any>>;
|
|
17
|
+
/**
|
|
18
|
+
* Function for returning the compile content given an specific type or condition
|
|
19
|
+
*
|
|
20
|
+
* @param context - Settings for the content to be compiled, such as type
|
|
21
|
+
* @param content - The contents in the file
|
|
22
|
+
* @param fileName - The relative name of the file
|
|
23
|
+
* @returns CompilerReturn object instance or undefined
|
|
24
|
+
*/
|
|
25
|
+
compileContent: AsyncSeriesBailHook<[SerializeContext, any, string], CompilerReturn, Record<string, any>>;
|
|
26
|
+
};
|
|
27
|
+
/** A DSL compiler instance */
|
|
28
|
+
dslCompiler: DSLCompiler;
|
|
29
|
+
constructor(dslCompiler: DSLCompiler);
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=compilation-context.d.ts.map
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CompilationContext = void 0;
|
|
13
|
+
const dsl_1 = require("@player-tools/dsl");
|
|
14
|
+
const tapable_ts_1 = require("tapable-ts");
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
class CompilationContext {
|
|
19
|
+
constructor(dslCompiler) {
|
|
20
|
+
/** Hooks to wrap the context of the compilation */
|
|
21
|
+
this.hooks = {
|
|
22
|
+
/**
|
|
23
|
+
* Function for determining a specific or desired content type given on the file contents or other conditions
|
|
24
|
+
*
|
|
25
|
+
* @param fileName - The relative name of the file
|
|
26
|
+
* @param content - The contents in the file
|
|
27
|
+
* @returns string with the content type.
|
|
28
|
+
*/
|
|
29
|
+
identifyContentType: new tapable_ts_1.AsyncSeriesBailHook(),
|
|
30
|
+
/**
|
|
31
|
+
* Function for returning the compile content given an specific type or condition
|
|
32
|
+
*
|
|
33
|
+
* @param context - Settings for the content to be compiled, such as type
|
|
34
|
+
* @param content - The contents in the file
|
|
35
|
+
* @param fileName - The relative name of the file
|
|
36
|
+
* @returns CompilerReturn object instance or undefined
|
|
37
|
+
*/
|
|
38
|
+
compileContent: new tapable_ts_1.AsyncSeriesBailHook(),
|
|
39
|
+
};
|
|
40
|
+
this.dslCompiler = dslCompiler;
|
|
41
|
+
this.hooks.compileContent.tap('default', ({ type }, content) => __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
if ((0, dsl_1.isDefaultCompilerContentType)(type)) {
|
|
43
|
+
return this.dslCompiler.serialize(content, { type });
|
|
44
|
+
}
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.CompilationContext = CompilationContext;
|
package/dist/utils/fs.js
CHANGED
|
@@ -6,16 +6,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.normalizePath = exports.convertToFileGlob = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
/** To handle globby issue on windows https://github.com/sindresorhus/globby/issues/152 */
|
|
10
|
+
function forcePathSeparatorToPosix(input) {
|
|
11
|
+
return path_1.default.sep === path_1.default.win32.sep
|
|
12
|
+
? input.split(path_1.default.sep).join(path_1.default.posix.sep)
|
|
13
|
+
: input;
|
|
14
|
+
}
|
|
9
15
|
/** Check if an input is a directory, if it is, then swap it to a globbed path */
|
|
10
16
|
const convertToFileGlob = (input, glob) => {
|
|
11
17
|
return input.map((i) => {
|
|
12
18
|
try {
|
|
13
19
|
if (fs_1.default.statSync(i).isDirectory()) {
|
|
14
|
-
return path_1.default.join(i, glob);
|
|
20
|
+
return forcePathSeparatorToPosix(path_1.default.join(i, glob));
|
|
15
21
|
}
|
|
16
22
|
}
|
|
17
23
|
catch (e) { }
|
|
18
|
-
return i;
|
|
24
|
+
return forcePathSeparatorToPosix(i);
|
|
19
25
|
});
|
|
20
26
|
};
|
|
21
27
|
exports.convertToFileGlob = convertToFileGlob;
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.4.0-next.
|
|
1
|
+
{"version":"0.4.0-next.5","commands":{"dsl:compile":{"id":"dsl:compile","description":"Compile Player DSL files into JSON","strict":false,"pluginName":"@player-tools/cli","pluginAlias":"@player-tools/cli","pluginType":"core","aliases":[],"flags":{"config":{"name":"config","type":"option","char":"c","description":"Path to a specific config file to load.\nBy default, will automatically search for an rc or config file to load","multiple":false},"input":{"name":"input","type":"option","char":"i","description":"An input directory to compile.\nAny jsx/ts/tsx files will be loaded via babel-require automatically.","multiple":false},"output":{"name":"output","type":"option","char":"o","description":"Output directory to write results to.","multiple":false},"skip-validation":{"name":"skip-validation","type":"boolean","description":"Option to skip validating the generated JSON","allowNo":false},"exp":{"name":"exp","type":"boolean","description":"Use experimental language features","allowNo":false}},"args":[],"_globalFlags":{}},"json:validate":{"id":"json:validate","description":"Validate Player JSON content","strict":false,"pluginName":"@player-tools/cli","pluginAlias":"@player-tools/cli","pluginType":"core","aliases":[],"flags":{"config":{"name":"config","type":"option","char":"c","description":"Path to a specific config file to load.\nBy default, will automatically search for an rc or config file to load","multiple":false},"files":{"name":"files","type":"option","char":"f","description":"A list of files or globs to validate","multiple":true},"exp":{"name":"exp","type":"boolean","description":"Use experimental language features","allowNo":false}},"args":[],"_globalFlags":{}},"xlr:compile":{"id":"xlr:compile","description":"Compiles typescript files to XLRs format","strict":false,"pluginName":"@player-tools/cli","pluginAlias":"@player-tools/cli","pluginType":"core","aliases":[],"flags":{"config":{"name":"config","type":"option","char":"c","description":"Path to a specific config file to load.\nBy default, will automatically search for an rc or config file to load","multiple":false},"input":{"name":"input","type":"option","char":"i","description":"An input directory to search for types to export","multiple":false,"default":"./src"},"output":{"name":"output","type":"option","char":"o","description":"Output directory to write results to.","multiple":false,"default":"./dist"},"mode":{"name":"mode","type":"option","char":"m","description":"Search strategy for types to export: plugin (default, looks for exported EnchancedPlayerPlugin classes) or type (all exported types)","helpValue":"(plugin|types)","multiple":false,"options":["plugin","types"],"default":"plugin"}},"args":[],"_globalFlags":{}},"xlr:convert":{"id":"xlr:convert","description":"Exports XLRs files to a specific language","strict":false,"pluginName":"@player-tools/cli","pluginAlias":"@player-tools/cli","pluginType":"core","aliases":[],"flags":{"config":{"name":"config","type":"option","char":"c","description":"Path to a specific config file to load.\nBy default, will automatically search for an rc or config file to load","multiple":false},"input":{"name":"input","type":"option","char":"i","description":"An input directory to search for types to export","multiple":false,"default":"./dist"},"output":{"name":"output","type":"option","char":"o","description":"Output directory to write results to.","multiple":false},"lang":{"name":"lang","type":"option","char":"l","description":"Search strategy for types to export: plugin (default, looks for exported EnchancedPlayerPlugin classes) or type (all exported types)","helpValue":"(TypeScript)","multiple":false,"options":["TypeScript"]}},"args":[],"_globalFlags":{}}}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@player-tools/cli",
|
|
3
|
-
"version": "0.4.0-next.
|
|
3
|
+
"version": "0.4.0-next.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
"peerDependencies": {},
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@babel/core": "^7.15.5",
|
|
11
|
+
"react": "^17.0.2",
|
|
12
|
+
"tapable-ts": "^0.2.4",
|
|
11
13
|
"@babel/preset-env": "^7.15.6",
|
|
12
14
|
"@babel/preset-react": "^7.14.5",
|
|
13
15
|
"@babel/preset-typescript": "^7.15.0",
|
|
@@ -28,11 +30,11 @@
|
|
|
28
30
|
"vscode-languageserver-textdocument": "^1.0.1",
|
|
29
31
|
"vscode-languageserver-types": "^3.15.1",
|
|
30
32
|
"typescript": "4.8.4",
|
|
31
|
-
"@player-tools/dsl": "0.4.0-next.
|
|
32
|
-
"@player-tools/json-language-service": "0.4.0-next.
|
|
33
|
-
"@player-tools/xlr-sdk": "0.4.0-next.
|
|
34
|
-
"@player-tools/xlr-utils": "0.4.0-next.
|
|
35
|
-
"@player-tools/xlr-converters": "0.4.0-next.
|
|
33
|
+
"@player-tools/dsl": "0.4.0-next.5",
|
|
34
|
+
"@player-tools/json-language-service": "0.4.0-next.5",
|
|
35
|
+
"@player-tools/xlr-sdk": "0.4.0-next.5",
|
|
36
|
+
"@player-tools/xlr-utils": "0.4.0-next.5",
|
|
37
|
+
"@player-tools/xlr-converters": "0.4.0-next.5"
|
|
36
38
|
},
|
|
37
39
|
"main": "./dist/index.js",
|
|
38
40
|
"module": "dist/index.esm.js",
|