Skip to content

Commit c1d4ac0

Browse files
0.1.0
1 parent 8a98234 commit c1d4ac0

File tree

16 files changed

+124
-24
lines changed

16 files changed

+124
-24
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.1.0
2+
3+
- Custom esbuild file
4+
15
## 0.0.11
26

37
- Cleanup

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Build scripts and configuration
2+
3+
## Installation
4+
5+
Add configuration and setup scripts:
6+
7+
```sh
8+
npm install -D -E baxast
9+
```
10+
11+
## Usage
12+
13+
`package.json`
14+
15+
```json
16+
{
17+
"name": "my-awesome-package",
18+
"scripts": {
19+
"prepublishOnly": "baxast 'Source/**/*.ts'"
20+
},
21+
"dependencies": {
22+
"baxast": "latest"
23+
}
24+
}
25+
```
26+
27+
or with a custom esbuild config file:
28+
29+
```json
30+
{
31+
"scripts": {
32+
"prepublishOnly": "baxast 'Source/**/*.ts' -es ESBuild.ts"
33+
}
34+
}
35+
```
36+
37+
#### See an example of a config file in [ESBuild.ts](Source/Configuration/esbuild.ts)
38+
39+
`tsconfig.json`
40+
41+
```json
42+
{
43+
"compilerOptions": {
44+
"outDir": "Target"
45+
},
46+
"extends": "./Source/Configuration/TypeScript",
47+
"include": ["Source"]
48+
}
49+
```
50+
51+
The script will now automatically compile your build files with [esbuild] and
52+
add TypeScript types.
53+
54+
[baxast]: https://npmjs.org/baxast
55+
[esbuild]: https://npmjs.org/esbuild

Source/Command/Build.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ import type { BuildOptions } from "esbuild";
44
import { build as Build } from "esbuild";
55
import type { Pattern } from "fast-glob";
66
import Glob from "fast-glob";
7-
import esbuild from "../Configuration/esbuild.js";
7+
import _esbuild from "../Configuration/esbuild.js";
8+
import File from "../Library/File.js";
89

910
export type Pipe = string[];
1011

11-
export default async (Files: Pattern[], Options?: { TypeScript?: string }) => {
12+
export default async (
13+
Files: Pattern[],
14+
Options?: { esbuild?: string; TypeScript?: string }
15+
) => {
1216
const Pipe: Pipe = [];
1317

1418
for (const File of Files) {
@@ -21,18 +25,19 @@ export default async (Files: Pattern[], Options?: { TypeScript?: string }) => {
2125

2226
Pipe.reverse();
2327

28+
const esbuild = Merge(_esbuild, {
29+
entryPoints: Object.fromEntries(
30+
Pipe.map((File) => [
31+
File.replace("Source/", "").split(".").slice(0, -1.0).join("."),
32+
File,
33+
])
34+
),
35+
} satisfies BuildOptions);
36+
2437
await Build(
25-
Merge(esbuild, {
26-
entryPoints: Object.fromEntries(
27-
Pipe.map((File) => [
28-
File.replace("Source/", "")
29-
.split(".")
30-
.slice(0, -1.0)
31-
.join("."),
32-
File,
33-
])
34-
),
35-
} satisfies BuildOptions)
38+
Options?.esbuild
39+
? Merge(esbuild, await File(Options?.esbuild))
40+
: esbuild
3641
);
3742

3843
if (Options?.TypeScript) {

Source/Configuration/TypeScript.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"lib": [
2424
"ESNext"
2525
],
26-
"module": "NodeNext",
26+
"module": "ESNext",
2727
"moduleResolution": "NodeNext",
2828
"noFallthroughCasesInSwitch": true,
2929
"noImplicitOverride": true,
@@ -40,7 +40,8 @@
4040
"strictNullChecks": true,
4141
"target": "ESNext",
4242
"types": [
43-
"node"
43+
"node",
44+
"@types/node"
4445
],
4546
"verbatimModuleSyntax": true
4647
},

Source/Configuration/esbuild.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export default {
1111
platform: "node",
1212
target: "esnext",
1313
write: true,
14-
sourcemap: false,
1514
plugins: [
1615
{
1716
name: "Target",

Source/Index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ try {
88
.version((await _JSON("../package.json", import.meta.url))?.version)
99
.description("Builds files")
1010
.argument("<Files...>", "Files to build")
11+
.option("-es, --esbuild <File>", "esbuild configuration file")
1112
.option("-ts, --TypeScript <File>", "TypeScript configuration file")
1213
.action(Build)
1314
.parse();

Source/Library/File.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { readFile as _File, writeFile as File } from "fs/promises";
2+
import TypeScript from "typescript";
3+
import { pathToFileURL as URL } from "url";
4+
import _JSON from "./JSON.js";
5+
6+
export default async (Path: string) => {
7+
if (Path.split(".").pop() === "ts") {
8+
const { options } = TypeScript.convertCompilerOptionsFromJson(
9+
(await _JSON("../Configuration/TypeScript.json", import.meta.url))
10+
?.compilerOptions,
11+
"."
12+
);
13+
14+
TypeScript.createProgram(
15+
[Path],
16+
options,
17+
TypeScript.createCompilerHost(options)
18+
).emit();
19+
20+
await File(
21+
Path.replace(".ts", ".js"),
22+
TypeScript.transpile(
23+
(await _File(Path, "utf-8")).toString(),
24+
options
25+
)
26+
);
27+
}
28+
29+
return (await import(URL(Path).toString().replace(".ts", ".js"))).default;
30+
};

Target/Command/Build.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Pattern } from "fast-glob";
22
export type Pipe = string[];
33
declare const _default: (Files: Pattern[], Options?: {
4+
esbuild?: string;
45
TypeScript?: string;
56
}) => Promise<void>;
67
export default _default;

Target/Command/Build.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Target/Configuration/TypeScript.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"lib": [
2424
"ESNext"
2525
],
26-
"module": "NodeNext",
26+
"module": "ESNext",
2727
"moduleResolution": "NodeNext",
2828
"noFallthroughCasesInSwitch": true,
2929
"noImplicitOverride": true,
@@ -40,7 +40,8 @@
4040
"strictNullChecks": true,
4141
"target": "ESNext",
4242
"types": [
43-
"node"
43+
"node",
44+
"@types/node"
4445
],
4546
"verbatimModuleSyntax": true
4647
},

Target/Configuration/esbuild.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ declare const _default: {
55
platform: "node";
66
target: string;
77
write: true;
8-
sourcemap: false;
98
plugins: any[];
109
};
1110
export default _default;

Target/Configuration/esbuild.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Target/Index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Target/Library/File.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare const _default: (Path: string) => Promise<any>;
2+
export default _default;

Target/Library/File.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "baxast",
3-
"version": "0.0.11",
3+
"version": "0.1.0",
44
"homepage": "https://github.com/baxast/baxast#readme",
55
"bugs": {
66
"url": "https://github.com/baxast/baxast/issues"
@@ -24,7 +24,8 @@
2424
"esbuild": "0.19.0",
2525
"esbuild-plugin-copy": "2.1.1",
2626
"fast-glob": "3.3.1",
27-
"typescript": "5.1.6"
27+
"typescript": "5.1.6",
28+
"@types/node": "20.4.9"
2829
},
2930
"devDependencies": {
3031
"@types/node": "20.4.9",

0 commit comments

Comments
 (0)