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
4 changes: 2 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ common --remote_cache_compression --remote_cache_async

# CI Config
common:ci --build_metadata=ROLE=CI
common:ci --local_resources=cpu=4
common:ci --local_resources=memory=8000
common:ci --local_resources=cpu=2
common:ci --local_resources=memory=4000

# Release Config
common:release --config=ci --stamp --workspace_status_command=./scripts/workspace-status.sh
Expand Down
12 changes: 6 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ executors:
base:
docker:
- image: docker.io/playerui/bazel-docker-slim:18
working_directory: ~/tools
resource_class: xlarge
working_directory: ~/cli
resource_class: medium
Comment on lines +18 to +19

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we decide which resource_class is appropriate?

environment:
TZ: "/usr/share/zoneinfo/America/Los_Angeles"

Expand All @@ -25,7 +25,7 @@ commands:
description: Perform Auto shipit
steps:
- attach_workspace:
at: ~/tools
at: ~/cli

- restore_cache:
keys:
Expand Down Expand Up @@ -70,7 +70,7 @@ jobs:
executor: base
steps:
- attach_workspace:
at: ~/player
at: ~/cli
- run: |
echo "build --remote_header=x-buildbuddy-api-key=${BUILDBUDDY_API_KEY}" >> .bazelrc.local
echo "test --remote_header=x-buildbuddy-api-key=${BUILDBUDDY_API_KEY}" >> .bazelrc.local
Expand All @@ -84,7 +84,7 @@ jobs:
executor: base
steps:
- attach_workspace:
at: ~/tools
at: ~/cli
- run: bazel build -- $(bazel query "kind(npm_package, //...)" --output label 2>/dev/null | tr '\n' ' ')

- persist_to_workspace:
Expand All @@ -97,7 +97,7 @@ jobs:
executor: base
steps:
- attach_workspace:
at: ~/tools
at: ~/cli

- restore_cache:
keys:
Expand Down
65 changes: 65 additions & 0 deletions cli/src/__tests__/commands/dsl-compile.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { describe, test, expect } from "vitest";
import DSLCompile from "../../commands/dsl/compile";
import DSLValidate from "../../commands/dsl/validate";
import JSONValidate from "../../commands/json/validate";
import XLRCompile from "../../commands/xlr/compile";
import XLRConvert from "../../commands/xlr/convert";

describe("command structure and basic functionality", () => {
test("DSL compile command should be defined with correct structure", () => {
expect(DSLCompile).toBeDefined();
expect(DSLCompile.description).toBe("Compile Player DSL files into JSON");
expect(DSLCompile.flags).toBeDefined();
expect(DSLCompile.flags.input).toBeDefined();
expect(DSLCompile.flags.output).toBeDefined();
expect(DSLCompile.strict).toBe(false);
});

test("DSL validate command should be defined with correct structure", () => {
expect(DSLValidate).toBeDefined();
expect(DSLValidate.description).toBe(
"Validate TSX files before they get compiled",
);
expect(DSLValidate.flags).toBeDefined();
expect(DSLValidate.flags.files).toBeDefined();
expect(DSLValidate.flags.severity).toBeDefined();
});

test("JSON validate command should be defined with correct structure", () => {
expect(JSONValidate).toBeDefined();
expect(JSONValidate.description).toBe("Validate Player JSON content");
expect(JSONValidate.flags).toBeDefined();
expect(JSONValidate.flags.files).toBeDefined();
expect(JSONValidate.flags.severity).toBeDefined();
});

test("XLR compile command should be defined with correct structure", () => {
expect(XLRCompile).toBeDefined();
expect(XLRCompile.description).toBe(
"Compiles typescript files to XLRs format",
);
expect(XLRCompile.flags).toBeDefined();
expect(XLRCompile.flags.input).toBeDefined();
expect(XLRCompile.flags.output).toBeDefined();
expect(XLRCompile.flags.mode).toBeDefined();
});

test("XLR convert command should be defined with correct structure", () => {
expect(XLRConvert).toBeDefined();
expect(XLRConvert.description).toBe(
"Exports XLRs files to a specific language",
);
expect(XLRConvert.flags).toBeDefined();
expect(XLRConvert.flags.input).toBeDefined();
expect(XLRConvert.flags.output).toBeDefined();
expect(XLRConvert.flags.lang).toBeDefined();
});

test("all commands extend BaseCommand and have required config support", () => {
expect(DSLCompile.flags.config).toBeDefined();
expect(DSLValidate.flags.config).toBeDefined();
expect(JSONValidate.flags.config).toBeDefined();
expect(XLRCompile.flags.config).toBeDefined();
expect(XLRConvert.flags.config).toBeDefined();
});
});
2 changes: 2 additions & 0 deletions cli/src/commands/dsl/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type TaskResult = Array<Omit<CompletedTask<CompilationResult, any>, "run">>;
export default class DSLCompile extends BaseCommand {
static description = "Compile Player DSL files into JSON";

static strict = false;

static flags = {
...BaseCommand.flags,
input: Flags.string({
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/xlr/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class XLRCompile extends BaseCommand {
description: "Output directory to write results to.",
default: "./dist",
}),
mode: Flags.enum({
mode: Flags.string({

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this change for?

char: "m",
description:
"Search strategy for types to export: plugin (default, looks for exported EnchancedPlayerPlugin classes) or type (all exported types)",
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/xlr/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default class XLRConvert extends BaseCommand {
char: "o",
description: "Output directory to write results to.",
}),
lang: Flags.enum({
lang: Flags.string({
char: "l",
description:
"Search strategy for types to export: plugin (default, looks for exported EnchancedPlayerPlugin classes) or type (all exported types)",
Expand Down
17 changes: 13 additions & 4 deletions cli/src/utils/base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export abstract class BaseCommand extends Command {
}

private async readConfig(): Promise<PlayerConfigResolvedShape> {
const { flags } = await this.parse(BaseCommand);
const { flags } = await this.parse();
const configFile = await this.loadConfig(flags.config);
return this.resolveConfig(configFile?.config);
}
Expand Down Expand Up @@ -201,9 +201,18 @@ export abstract class BaseCommand extends Command {
return compilerContext;
}

exit(code?: number): void {
if (process.env.NODE_ENV !== "test") {
super.exit(code);
// Override exit to prevent process termination during tests
override exit(exitCode = 0): never {
if (process.env.NODE_ENV === "test") {
// In test mode, skip the actual exit process
// We satisfy the 'never' return type by using type assertion
// since tests need the function to return normally
return undefined as never;
} else if (exitCode != 0) {
// In production, delegate to parent which terminates the process
return super.exit(exitCode);
} else {
return undefined as never;
}
}
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"@babel/preset-react": "^7.23.3",
"@babel/preset-typescript": "^7.23.3",
"@babel/register": "^7.23.3",
"@oclif/core": "1.9.0",
"@oclif/plugin-plugins": "^1.9.0",
"@oclif/core": "^4.8.0",
"@oclif/plugin-plugins": "^5.4.56",
"@player-tools/dsl": "^0.12.0",
"@player-tools/json-language-service": "^0.12.0",
"@player-tools/xlr": "^0.12.0",
Expand Down Expand Up @@ -79,6 +79,7 @@
"eslint-config-prettier": "^10.1.1",
"eslint-plugin-prettier": "^5.2.3",
"eslint-plugin-react": "^7.37.4",
"ts-node": "^10.9.2",
"tslib": "^2.6.2",
"tsup": "^8.0.1",
"typescript": "5.5.4",
Expand Down
Loading