@player-tools/cli 0.7.0-next.6 → 0.7.0-next.7

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.
@@ -74,9 +74,10 @@ class DSLCompile extends base_command_1.BaseCommand {
74
74
  return;
75
75
  }
76
76
  const preProcessedValue = await context.dslCompiler.hooks.preProcessFlow.call(defaultExport);
77
- const contentType = (await context.hooks.identifyContentType.call(file, preProcessedValue)) ||
78
- (0, dsl_1.fingerprintContent)(preProcessedValue, file) ||
79
- "unknown";
77
+ const { type: contentType, extension: ext } = (await context.hooks.identifyContentType.call(file, preProcessedValue)) || {
78
+ type: (0, dsl_1.fingerprintContent)(preProcessedValue, file) || "unknown",
79
+ extension: ".json",
80
+ };
80
81
  let relativePath = path_1.default.relative(input, file);
81
82
  if (!relativePath) {
82
83
  relativePath = path_1.default.basename(file);
@@ -84,30 +85,26 @@ class DSLCompile extends base_command_1.BaseCommand {
84
85
  const outputFile = path_1.default.join(output, path_1.default.format({
85
86
  ...path_1.default.parse(relativePath),
86
87
  base: undefined,
87
- ext: ".json",
88
+ ext,
88
89
  }));
89
90
  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);
90
91
  const compileResult = await context.hooks.compileContent.call({ type: contentType }, preProcessedValue, file);
91
92
  if (compileResult) {
92
- const contentStr = JSON.stringify(compileResult.value, null, 2);
93
93
  await (0, mkdirp_1.default)(path_1.default.dirname(outputFile));
94
- await fs_1.promises.writeFile(outputFile, contentStr);
94
+ await fs_1.promises.writeFile(outputFile, compileResult.value);
95
95
  if (compileResult.sourceMap) {
96
96
  await fs_1.promises.writeFile(`${outputFile}.map`, compileResult.sourceMap);
97
97
  }
98
- if (contentType) {
99
- return {
100
- contentType,
101
- outputFile,
102
- inputFile: file,
103
- };
104
- }
105
98
  return {
106
99
  contentType,
107
100
  outputFile,
108
101
  inputFile: file,
109
102
  };
110
103
  }
104
+ else {
105
+ this.log(`${log_symbols_1.default.error} Error compiling %s, no result was returned by compiler`, (0, fs_2.normalizePath)(file));
106
+ throw new Error(`Error compiling file ${(0, fs_2.normalizePath)(file)}`);
107
+ }
111
108
  };
112
109
  const compilerResults = [];
113
110
  // This has to be done serially b/c of the way React logs messages to console.error
@@ -1,5 +1,20 @@
1
- import type { DSLCompiler, CompilerReturn, SerializeContext } from "@player-tools/dsl";
1
+ import type { DSLCompiler, SerializeContext } from "@player-tools/dsl";
2
2
  import { AsyncSeriesBailHook } from "tapable-ts";
3
+ export interface identifyContentReturn {
4
+ /** The identified type the content should be compiled as */
5
+ type: string;
6
+ /** The file extension the content should be written as */
7
+ extension: string;
8
+ }
9
+ export interface compileContentArgs extends Omit<SerializeContext, "type"> {
10
+ type: string;
11
+ }
12
+ export interface compilationResult {
13
+ /** the JSON value of the source */
14
+ value: string;
15
+ /** The sourcemap of the content */
16
+ sourceMap?: string;
17
+ }
3
18
  /**
4
19
  *
5
20
  */
@@ -11,9 +26,9 @@ export declare class CompilationContext {
11
26
  *
12
27
  * @param fileName - The relative name of the file
13
28
  * @param content - The contents in the file
14
- * @returns string with the content type.
29
+ * @returns content type and extension
15
30
  */
16
- identifyContentType: AsyncSeriesBailHook<[string, any], string, Record<string, any>>;
31
+ identifyContentType: AsyncSeriesBailHook<[string, any], identifyContentReturn, Record<string, any>>;
17
32
  /**
18
33
  * Function for returning the compile content given an specific type or condition
19
34
  *
@@ -22,7 +37,7 @@ export declare class CompilationContext {
22
37
  * @param fileName - The relative name of the file
23
38
  * @returns CompilerReturn object instance or undefined
24
39
  */
25
- compileContent: AsyncSeriesBailHook<[SerializeContext, any, string], CompilerReturn, Record<string, any>>;
40
+ compileContent: AsyncSeriesBailHook<[compileContentArgs, any, string], compilationResult, Record<string, any>>;
26
41
  };
27
42
  /** A DSL compiler instance */
28
43
  dslCompiler: DSLCompiler;
@@ -14,7 +14,7 @@ class CompilationContext {
14
14
  *
15
15
  * @param fileName - The relative name of the file
16
16
  * @param content - The contents in the file
17
- * @returns string with the content type.
17
+ * @returns content type and extension
18
18
  */
19
19
  identifyContentType: new tapable_ts_1.AsyncSeriesBailHook(),
20
20
  /**
@@ -33,7 +33,15 @@ class CompilationContext {
33
33
  this.dslCompiler = dslCompiler;
34
34
  this.hooks.compileContent.tap("default", async ({ type }, content) => {
35
35
  if ((0, dsl_1.isDefaultCompilerContentType)(type)) {
36
- return this.dslCompiler.serialize(content, { type });
36
+ const compilationResults = await this.dslCompiler.serialize(content, {
37
+ type,
38
+ });
39
+ if (compilationResults) {
40
+ return {
41
+ value: JSON.stringify(compilationResults.value),
42
+ sourceMap: compilationResults.sourceMap,
43
+ };
44
+ }
37
45
  }
38
46
  });
39
47
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@player-tools/cli",
3
- "version": "0.7.0-next.6",
3
+ "version": "0.7.0-next.7",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "files": [
@@ -21,12 +21,12 @@
21
21
  "player": "bin/run"
22
22
  },
23
23
  "dependencies": {
24
- "@player-tools/dsl": "0.7.0-next.6",
25
- "@player-tools/json-language-service": "0.7.0-next.6",
26
- "@player-tools/xlr": "0.7.0-next.6",
27
- "@player-tools/xlr-converters": "0.7.0-next.6",
28
- "@player-tools/xlr-sdk": "0.7.0-next.6",
29
- "@player-tools/xlr-utils": "0.7.0-next.6",
24
+ "@player-tools/dsl": "0.7.0-next.7",
25
+ "@player-tools/json-language-service": "0.7.0-next.7",
26
+ "@player-tools/xlr": "0.7.0-next.7",
27
+ "@player-tools/xlr-converters": "0.7.0-next.7",
28
+ "@player-tools/xlr-sdk": "0.7.0-next.7",
29
+ "@player-tools/xlr-utils": "0.7.0-next.7",
30
30
  "@babel/plugin-transform-react-jsx-source": "^7.23.3",
31
31
  "@babel/preset-env": "^7.23.3",
32
32
  "@babel/preset-react": "^7.23.3",