diff --git a/cli/BUILD b/cli/BUILD index 5f5e1db..7f688e9 100644 --- a/cli/BUILD +++ b/cli/BUILD @@ -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", @@ -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 ) \ No newline at end of file diff --git a/cli/src/commands/xlr/convert.ts b/cli/src/commands/xlr/convert.ts index a9753a1..fd59bcb 100644 --- a/cli/src/commands/xlr/convert.ts +++ b/cli/src/commands/xlr/convert.ts @@ -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", + ], ], ]); @@ -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`); @@ -65,7 +74,7 @@ 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 }); @@ -73,10 +82,9 @@ export default class XLRConvert extends BaseCommand { 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( diff --git a/cli/src/plugins/index.ts b/cli/src/plugins/index.ts index 83786c9..0ba8aa7 100644 --- a/cli/src/plugins/index.ts +++ b/cli/src/plugins/index.ts @@ -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"; @@ -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, ) => void | Promise; diff --git a/cli/src/utils/base-command.ts b/cli/src/utils/base-command.ts index b1ac4ee..84eb010 100644 --- a/cli/src/utils/base-command.ts +++ b/cli/src/utils/base-command.ts @@ -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, @@ -177,7 +176,7 @@ export abstract class BaseCommand extends Command { } async getXLRTransforms( - format: ExportTypes, + format: "TypeScript", ): Promise> { const transforms: Array = []; const { plugins } = await this.getPlayerConfig(); diff --git a/cli/src/utils/xlr/visitors/plugin.ts b/cli/src/utils/xlr/visitors/plugin.ts index 30a9fa9..3d72247 100644 --- a/cli/src/utils/xlr/visitors/plugin.ts +++ b/cli/src/utils/xlr/visitors/plugin.ts @@ -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"; @@ -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 */ diff --git a/package.json b/package.json index 6e94b34..e42dc5a 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1886b00..5dfe289 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -36,11 +36,11 @@ importers: specifier: ^1.9.0 version: 1.10.11(@oclif/config@1.18.17) '@player-lang/json-language-service': - specifier: 0.0.2-next.1 - version: 0.0.2-next.1 + specifier: ^1.0.1 + version: 1.0.1 '@player-lang/react-dsl': - specifier: 0.0.2-next.1 - version: 0.0.2-next.1(@types/react@18.3.27)(react@18.3.1) + specifier: ^1.0.1 + version: 1.0.1(@types/react@18.3.27)(react@18.3.1) '@types/babel__register': specifier: ^7.17.0 version: 7.17.3 @@ -57,17 +57,17 @@ importers: specifier: ^1.0.1 version: 1.0.4 '@xlr-lib/xlr': - specifier: 0.1.1-next.4 - version: 0.1.1-next.4 + specifier: ^1.0.0 + version: 1.0.0 '@xlr-lib/xlr-converters': - specifier: 0.1.1-next.4 - version: 0.1.1-next.4(jsonc-parser@2.3.1)(typescript@5.5.4) + specifier: ^1.0.0 + version: 1.0.0(jsonc-parser@2.3.1) '@xlr-lib/xlr-sdk': - specifier: 0.1.1-next.4 - version: 0.1.1-next.4(typescript@5.5.4) + specifier: ^1.0.0 + version: 1.0.0 '@xlr-lib/xlr-utils': - specifier: 0.1.1-next.4 - version: 0.1.1-next.4(jsonc-parser@2.3.1)(typescript@5.5.4) + specifier: ^1.0.0 + version: 1.0.0(jsonc-parser@2.3.1) chalk: specifier: ^4.0.1 version: 4.1.2 @@ -1667,11 +1667,11 @@ packages: resolution: {integrity: sha512-QNqXyfVS2wm9hweSYD2O7F0G06uurj9kZ96TRQE5Y9hU7+tgdZwIkbAKc5Ocy1HxEY2kuDQa6cQ1WRs/O5LFKA==, tarball: https://registry.npmjs.org/@pkgr/core/-/core-0.2.9.tgz} engines: {node: ^12.20.0 || ^14.18.0 || >=16.0.0} - '@player-lang/json-language-service@0.0.2-next.1': - resolution: {integrity: sha512-+seD2rFBa+tCIKe8R8cATkd3+e0n9r5/NnNDvplnnJ+bUHNkuK3+Sjv6EoRahriVsGQIk08d6n0ycdQ+bYFCfA==, tarball: https://registry.npmjs.org/@player-lang/json-language-service/-/json-language-service-0.0.2-next.1.tgz} + '@player-lang/json-language-service@1.0.1': + resolution: {integrity: sha512-yJ7gqzk/F+l/DnDItziglvv2eBbynJHL5601S1upkA3IasDBshfNBU+wvA+dGBeDfXs/11DiN74fSnpiiW8cvQ==, tarball: https://registry.npmjs.org/@player-lang/json-language-service/-/json-language-service-1.0.1.tgz} - '@player-lang/react-dsl@0.0.2-next.1': - resolution: {integrity: sha512-6LyI77q8cpVVlrmVt2pS1afDOS2ATo2U3vTQYAVP7Zwk+StgibmUMsVf37jXeE9wS3qA1yCM4ePdu13vOJ1XIA==, tarball: https://registry.npmjs.org/@player-lang/react-dsl/-/react-dsl-0.0.2-next.1.tgz} + '@player-lang/react-dsl@1.0.1': + resolution: {integrity: sha512-6fOpvZ9F3a/YlaDiQ54Z9qWtJVtTUuprLJv5Rtphu6omh11uKwsVpH1Hqn7umUQZEX2KM9bKq1OFrxOvkmNVow==, tarball: https://registry.npmjs.org/@player-lang/react-dsl/-/react-dsl-1.0.1.tgz} peerDependencies: '@types/react': ^18.3.3 react: ^18.2.0 @@ -2224,25 +2224,20 @@ packages: '@vitest/utils@2.1.9': resolution: {integrity: sha512-v0psaMSkNJ3A2NMrUEHFRzJtDPFn+/VWZ5WxImB21T9fjucJRmS7xCS3ppEnARb9y11OAzaD+P2Ps+b+BGX5iQ==, tarball: https://registry.npmjs.org/@vitest/utils/-/utils-2.1.9.tgz} - '@xlr-lib/xlr-converters@0.1.1-next.4': - resolution: {integrity: sha512-D5Sag7X2dQbya/l4DBqr/lyUDmu7ADDtKQotRdA8KixZE7JMJoI9CW5itera0PAo3WvIA7lTPTN1CrEvlTCe1A==, tarball: https://registry.npmjs.org/@xlr-lib/xlr-converters/-/xlr-converters-0.1.1-next.4.tgz} + '@xlr-lib/xlr-converters@1.0.0': + resolution: {integrity: sha512-TovXuu4VMwJBWZnAhhO93jncx5NXfn1khy1mYVIgMXrC7b1c++g6EyxLs4svkUAiQiynEkmSa96QvydSgAeYzw==, tarball: https://registry.npmjs.org/@xlr-lib/xlr-converters/-/xlr-converters-1.0.0.tgz} hasBin: true - peerDependencies: - typescript: 5.5.4 - '@xlr-lib/xlr-sdk@0.1.1-next.4': - resolution: {integrity: sha512-q46qn+7yzMJHT09+hHj0hej2t/p+IpIBT48BptlsKpEugENpFihrK4ITGJA6TO7QgtG58AKZsgTx95z8ebisyg==, tarball: https://registry.npmjs.org/@xlr-lib/xlr-sdk/-/xlr-sdk-0.1.1-next.4.tgz} - peerDependencies: - typescript: 5.5.4 + '@xlr-lib/xlr-sdk@1.0.0': + resolution: {integrity: sha512-3ge1NTzCukn9F76HQPZXeNZI/C/HOJF365II6m5GbzhR1Aag9Ghf4/5w5/PIrfb734eZ5kFkMiF6UeMOXUegtQ==, tarball: https://registry.npmjs.org/@xlr-lib/xlr-sdk/-/xlr-sdk-1.0.0.tgz} - '@xlr-lib/xlr-utils@0.1.1-next.4': - resolution: {integrity: sha512-BDCQnfHy1SVY0bB6BByshpsSihgJ7imqNV9uhuk2OD003uhawOFa5WH4HRjmWnvXXuWp/5asjB9ObIwkNh3m4g==, tarball: https://registry.npmjs.org/@xlr-lib/xlr-utils/-/xlr-utils-0.1.1-next.4.tgz} + '@xlr-lib/xlr-utils@1.0.0': + resolution: {integrity: sha512-swoRx3QppioaClwvf+89yJrPJ8oEsIJNWUdney7Vom9XmUKbVY4XgPF0fZSYSC+HWsvB8NbkQ5CNCE8AXW6oxQ==, tarball: https://registry.npmjs.org/@xlr-lib/xlr-utils/-/xlr-utils-1.0.0.tgz} peerDependencies: jsonc-parser: 2.3.1 - typescript: 5.5.4 - '@xlr-lib/xlr@0.1.1-next.4': - resolution: {integrity: sha512-FCi+Fc0KQHUbKO+OTUp291aFcC/t7pmjtMYM6lQdXB55Lu+EV47jE3PjHqxZuS3LSitGxonXMEOrprQDrqL9MQ==, tarball: https://registry.npmjs.org/@xlr-lib/xlr/-/xlr-0.1.1-next.4.tgz} + '@xlr-lib/xlr@1.0.0': + resolution: {integrity: sha512-Zfu6/lLauRQafuUo+JvbKZ2lmQkxtDgJxnGtWieGNct6mSHhWKWRc7siXQlboBxwu84yMcjLSrOxvD9WrBtLWQ==, tarball: https://registry.npmjs.org/@xlr-lib/xlr/-/xlr-1.0.0.tgz} '@yarnpkg/lockfile@1.1.0': resolution: {integrity: sha512-GpSwvyXOcOOlV70vbnzjj4fW5xW/FdUF6nQEt1ENy7m4ZCczi1+/buVUPAqmGfqznsORNFzUMjctTIp8a9tuCQ==, tarball: https://registry.npmjs.org/@yarnpkg/lockfile/-/lockfile-1.1.0.tgz} @@ -7171,12 +7166,12 @@ snapshots: '@pkgr/core@0.2.9': {} - '@player-lang/json-language-service@0.0.2-next.1': + '@player-lang/json-language-service@1.0.1': dependencies: '@player-ui/player': 0.15.0 - '@xlr-lib/xlr': 0.1.1-next.4 - '@xlr-lib/xlr-sdk': 0.1.1-next.4(typescript@5.5.4) - '@xlr-lib/xlr-utils': 0.1.1-next.4(jsonc-parser@2.3.1)(typescript@5.5.4) + '@xlr-lib/xlr': 1.0.0 + '@xlr-lib/xlr-sdk': 1.0.0 + '@xlr-lib/xlr-utils': 1.0.0(jsonc-parser@2.3.1) detect-indent: 6.1.0 jsonc-parser: 2.3.1 tapable-ts: 0.2.4 @@ -7186,7 +7181,7 @@ snapshots: vscode-languageserver-textdocument: 1.0.12 vscode-languageserver-types: 3.17.5 - '@player-lang/react-dsl@0.0.2-next.1(@types/react@18.3.27)(react@18.3.1)': + '@player-lang/react-dsl@1.0.1(@types/react@18.3.27)(react@18.3.1)': dependencies: '@player-ui/player': 0.15.0 '@player-ui/types': 0.15.0 @@ -7896,35 +7891,32 @@ snapshots: loupe: 3.2.1 tinyrainbow: 1.2.0 - '@xlr-lib/xlr-converters@0.1.1-next.4(jsonc-parser@2.3.1)(typescript@5.5.4)': + '@xlr-lib/xlr-converters@1.0.0(jsonc-parser@2.3.1)': dependencies: - '@xlr-lib/xlr': 0.1.1-next.4 - '@xlr-lib/xlr-utils': 0.1.1-next.4(jsonc-parser@2.3.1)(typescript@5.5.4) + '@xlr-lib/xlr': 1.0.0 + '@xlr-lib/xlr-utils': 1.0.0(jsonc-parser@2.3.1) tslib: 2.8.1 typescript: 5.5.4 transitivePeerDependencies: - jsonc-parser - '@xlr-lib/xlr-sdk@0.1.1-next.4(typescript@5.5.4)': + '@xlr-lib/xlr-sdk@1.0.0': dependencies: '@types/fs-extra': 9.0.13 '@types/node': 18.19.130 - '@xlr-lib/xlr': 0.1.1-next.4 - '@xlr-lib/xlr-converters': 0.1.1-next.4(jsonc-parser@2.3.1)(typescript@5.5.4) - '@xlr-lib/xlr-utils': 0.1.1-next.4(jsonc-parser@2.3.1)(typescript@5.5.4) + '@xlr-lib/xlr': 1.0.0 + '@xlr-lib/xlr-utils': 1.0.0(jsonc-parser@2.3.1) fs-extra: 10.1.0 jsonc-parser: 2.3.1 tslib: 2.8.1 - typescript: 5.5.4 - '@xlr-lib/xlr-utils@0.1.1-next.4(jsonc-parser@2.3.1)(typescript@5.5.4)': + '@xlr-lib/xlr-utils@1.0.0(jsonc-parser@2.3.1)': dependencies: - '@xlr-lib/xlr': 0.1.1-next.4 + '@xlr-lib/xlr': 1.0.0 jsonc-parser: 2.3.1 tslib: 2.8.1 - typescript: 5.5.4 - '@xlr-lib/xlr@0.1.1-next.4': + '@xlr-lib/xlr@1.0.0': dependencies: tslib: 2.8.1