Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions cli/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ build_deps = [
]

deps = [
"//:node_modules/@player-lang/react-dsl",
"//:node_modules/@player-lang/json-language-service",
"//:node_modules/@xlr-lib/xlr",
"//:node_modules/@xlr-lib/xlr-converters",
"//:node_modules/@xlr-lib/xlr-sdk",
"//:node_modules/@xlr-lib/xlr-utils",
"//:node_modules/@babel/plugin-transform-react-jsx-source",
"//:node_modules/@babel/preset-env",
"//:node_modules/@babel/preset-react",
Expand Down Expand Up @@ -54,9 +48,19 @@ deps = [
"//:node_modules/vscode-languageserver-types",
]

peer_deps = [
"//:node_modules/@player-lang/react-dsl",
"//:node_modules/@player-lang/json-language-service",
"//:node_modules/@xlr-lib/xlr",
"//:node_modules/@xlr-lib/xlr-converters",
"//:node_modules/@xlr-lib/xlr-sdk",
"//:node_modules/@xlr-lib/xlr-utils",
]

oclif_pipeline(
package_name = "@player-cli/cli",
build_deps = build_deps,
deps = deps,
peer_deps = peer_deps,
manifest = False
)
24 changes: 16 additions & 8 deletions cli/src/commands/xlr/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@ import { Flags } from "@oclif/core";
import path from "path";
import fs from "fs";
import chalk from "chalk";
import type { ExportTypes } from "@xlr-lib/xlr-sdk";
import { XLRSDK } from "@xlr-lib/xlr-sdk";
import { exportTypesToTypeScript } from "@xlr-lib/xlr-converters";
import logSymbols from "log-symbols";
import { BaseCommand } from "../../utils/base-command";

const PlayerImportMap = new Map([
[
"@player-ui/types",
["Expression", "Asset", "Binding", "AssetWrapper", "Schema.DataType"],
[
"Expression",
"Asset",
"Binding",
"AssetWrapper",
"Schema.DataType",
"ExpressionHandler",
"FormatType",
"ValidatorFunction",
],
],
]);

Expand Down Expand Up @@ -48,7 +57,7 @@ export default class XLRConvert extends BaseCommand {
throw new Error(`Need to specify location to export to`);
}

const language = flags.lang as ExportTypes;
const language = flags.lang as "TypeScript";

if (!language) {
throw new Error(`Need to specifiy lanauge to export to`);
Expand All @@ -65,18 +74,17 @@ export default class XLRConvert extends BaseCommand {
/** the status code */
exitCode: number;
}> {
const { inputPath, outputDir, language } = await this.getOptions();
const { inputPath, outputDir } = await this.getOptions();
try {
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}

const sdk = new XLRSDK();
sdk.loadDefinitionsFromDisk(inputPath);
const files = sdk.exportRegistry(language, PlayerImportMap);
files.forEach(([filename, fileContents]) => {
fs.writeFileSync(path.join(outputDir, filename), fileContents, {});
});
const types = sdk.listTypes();
const fileContents = exportTypesToTypeScript(types, PlayerImportMap);
fs.writeFileSync(path.join(outputDir, "out.d.ts"), fileContents, {});
} catch (e: any) {
console.log("");
console.log(
Expand Down
3 changes: 1 addition & 2 deletions cli/src/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { PlayerLanguageService } from "@player-lang/json-language-service";
import type { DSLCompiler } from "@player-lang/react-dsl";
import type { ExportTypes } from "@xlr-lib/xlr-sdk";
import type { TransformFunction } from "@xlr-lib/xlr";
import type { CompilationContext } from "../utils/compilation-context";

Expand Down Expand Up @@ -29,7 +28,7 @@ export interface PlayerCLIPlugin {
* Append the transforms to apply to the passed in array based on the provided format
*/
onConvertXLR?: (
format: ExportTypes,
format: "TypeScript",
transforms: Array<TransformFunction>,
) => void | Promise<void>;

Expand Down
3 changes: 1 addition & 2 deletions cli/src/utils/base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import path from "path";
import { cosmiconfig } from "cosmiconfig";
import { PlayerLanguageService } from "@player-lang/json-language-service";
import { DSLCompiler } from "@player-lang/react-dsl";
import type { ExportTypes } from "@xlr-lib/xlr-sdk";
import type { TransformFunction } from "@xlr-lib/xlr";
import type {
PlayerConfigFileShape,
Expand Down Expand Up @@ -177,7 +176,7 @@ export abstract class BaseCommand extends Command {
}

async getXLRTransforms(
format: ExportTypes,
format: "TypeScript",
): Promise<Array<TransformFunction>> {
const transforms: Array<TransformFunction> = [];
const { plugins } = await this.getPlayerConfig();
Expand Down
24 changes: 22 additions & 2 deletions cli/src/utils/xlr/visitors/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { TopLevelNode } from "@xlr-lib/xlr-utils";
import { isNodeExported, isTopLevelNode } from "@xlr-lib/xlr-utils";
import path from "path";
import ts from "typescript";
import fs from "fs";
Expand All @@ -8,6 +6,28 @@ import type { TsConverter } from "@xlr-lib/xlr-converters";
import type { VisitorProps } from "./types";
import { PLAYER_PLUGIN_INTERFACE_NAME } from "../consts";

type TopLevelNode =
| ts.InterfaceDeclaration
| ts.TypeAliasDeclaration
| ts.VariableStatement;

function isTopLevelNode(node: ts.Node): node is TopLevelNode {
return (
ts.isInterfaceDeclaration(node) ||
ts.isTypeAliasDeclaration(node) ||
ts.isVariableStatement(node)
);
}

function isNodeExported(node: ts.Node): boolean {
return (
(ts.getCombinedModifierFlags(node as ts.Declaration) &
ts.ModifierFlags.Export) !==
0 ||
(!!node.parent && node.parent.kind === ts.SyntaxKind.SourceFile)
);
}

/**
* Follows references to get the actual underlying declaration
*/
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
"@babel/register": "^7.23.3",
"@oclif/core": "1.9.0",
"@oclif/plugin-plugins": "^1.9.0",
"@player-lang/react-dsl": "0.0.2-next.1",
"@player-lang/json-language-service": "0.0.2-next.1",
"@xlr-lib/xlr": "0.1.1-next.4",
"@xlr-lib/xlr-converters": "0.1.1-next.4",
"@xlr-lib/xlr-sdk": "0.1.1-next.4",
"@xlr-lib/xlr-utils": "0.1.1-next.4",
"@player-lang/react-dsl": "^1.0.1",
"@player-lang/json-language-service": "^1.0.1",
"@xlr-lib/xlr": "^1.0.0",
"@xlr-lib/xlr-converters": "^1.0.0",
"@xlr-lib/xlr-sdk": "^1.0.0",
"@xlr-lib/xlr-utils": "^1.0.0",
"@types/babel__register": "^7.17.0",
"@types/fs-extra": "^9.0.13",
"@types/mkdirp": "^1.0.2",
Expand Down
84 changes: 38 additions & 46 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.