Skip to content

Commit ac7b2d1

Browse files
authored
fix: issues with init process and esbuild (#242)
* fix: issues with init process and esbuild * fix: issue with test
1 parent e615366 commit ac7b2d1

5 files changed

Lines changed: 13 additions & 44 deletions

File tree

docs/API.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Creates a new GodotJS project with TypeScript support
2525

2626
| long | short | description | required | defaultValue |
2727
| :-------------- | :---: | :----------------------------------------------------- | :------: | :----------- |
28-
| `--name` | | The name of your project | `` | `"MyGame"` |
28+
| `--name` | | The name of your project | `` | `"my-game"` |
2929
| `--out` | | Relative path where project is written | `` | `"."` |
3030
| `--forceDelete` | | Removes project dir if it's already there | `` | |
3131
| `--dry` | | Do a dry run with this command - prints/returns output | `` | |

src/commands/init/data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export type InitConfigType = {
1010
export const initOptions: ProgramOptionsType[] = [
1111
{
1212
name: "name",
13-
defaultValue: "MyGame",
13+
defaultValue: "my-game",
1414
description: "The name of your project",
1515
required: true,
1616
inquirer: {

src/utils/esbuild.ts

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,13 @@
1-
import { readFileSync, writeFileSync } from "node:fs";
21
import { glob } from "glob";
3-
import { BuildOptions, OnLoadArgs, Plugin } from "esbuild";
4-
import { pathClean, stripRelativePath } from "./path";
2+
import { BuildOptions } from "esbuild";
3+
import { pathClean } from "./path";
54

6-
const defaultOutdir = "scripts";
7-
const defaultOutbase = "src";
8-
9-
const godotTsPlugin: Plugin = {
10-
name: "godotTsPlugin",
11-
setup(build) {
12-
const absolutePaths: string[] = [];
13-
build.onLoad({ filter: /\.ts$/ }, (args: OnLoadArgs) => {
14-
absolutePaths.push(args.path);
15-
return undefined;
16-
});
17-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
18-
build.onEnd(async (_) => {
19-
const { outdir, outbase, outExtension } = build.initialOptions;
20-
const extension = outExtension?.[".js"] ?? ".js";
21-
for (const filePath of absolutePaths) {
22-
const genFilePath = filePath
23-
// Workaround for windows
24-
.replaceAll("\\", "/")
25-
.replace(stripRelativePath(outbase), stripRelativePath(outdir))
26-
.replace(".ts", extension);
27-
const content = readFileSync(genFilePath);
28-
const genContent = `//generatedPath=${filePath}\n${content.toString("utf8")}`;
29-
writeFileSync(genFilePath, genContent);
30-
}
31-
});
32-
},
33-
};
5+
const defaultOutdir = "./.godot/GodotJS";
6+
const defaultOutbase = ".";
347

358
const options: BuildOptions = {
369
format: "cjs",
3710
target: "esnext",
38-
plugins: [godotTsPlugin],
3911
};
4012

4113
export type ESBuildType = {
@@ -55,9 +27,11 @@ export const getESBuildOptions = async ({
5527
const outdir = pathClean(out ?? defaultOutdir);
5628

5729
const entryPointsClasses = await glob(`${outbase}/**/*.ts`, {
58-
ignore: [`${outbase}/**/*.bundle.ts`, `${outbase}/**/*.d.ts`],
30+
ignore: [`${outbase}/**/*.bundle.ts`, `**/*.d.ts`, `**/node_modules/**`],
31+
});
32+
const entryPointsBundle = await glob(`${outbase}/**/*.bundle.ts`, {
33+
ignore: [`**/*.d.ts`, `**/node_modules/**`],
5934
});
60-
const entryPointsBundle = await glob(`${outbase}/**/*.bundle.ts`);
6135
const classOptions: BuildOptions = {
6236
entryPoints: entryPointsClasses,
6337
outExtension: { ".js": ".js" },

src/utils/inquirer-process.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const startInquirerProcess = async <T>(
1515
inquirer?.input &&
1616
(!config[option.name] || config[option.name] === option.defaultValue)
1717
) {
18-
config[option.name] = await input({
18+
copyConfig[option.name] = await input({
1919
message: inquirer.input.message,
2020
default: option.defaultValue?.toString(),
2121
required: option.required,

test/esbuild/config.test.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ const buildResult = JSON.stringify({
1212
outExtension: { ".js": ".js" },
1313
format: "cjs",
1414
target: "esnext",
15-
minify: undefined,
1615
outbase: "./scripts",
17-
outdir: "scripts",
18-
sourcemap: undefined,
16+
outdir: "./.godot/GodotJS",
1917
},
2018
bundleOptions: {
2119
entryPoints: [],
@@ -25,8 +23,7 @@ const buildResult = JSON.stringify({
2523
format: "cjs",
2624
target: "esnext",
2725
outbase: "./scripts",
28-
outdir: "scripts",
29-
sourcemap: undefined,
26+
outdir: "./.godot/GodotJS",
3027
},
3128
});
3229

@@ -36,8 +33,6 @@ describe("config", () => {
3633
dry: true,
3734
config: "./test/esbuild/.config/godot-ts.json",
3835
});
39-
delete result.bundleOptions.plugins;
40-
delete result.classOptions.plugins;
4136
expect(JSON.stringify(result)).toEqual(buildResult);
4237
});
4338
});

0 commit comments

Comments
 (0)