Skip to content

Commit

Permalink
0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaRHristov committed Aug 10, 2023
1 parent 8a98234 commit c1d4ac0
Show file tree
Hide file tree
Showing 16 changed files with 124 additions and 24 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.0

- Custom esbuild file

## 0.0.11

- Cleanup
Expand Down
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Build scripts and configuration

## Installation

Add configuration and setup scripts:

```sh
npm install -D -E baxast
```

## Usage

`package.json`

```json
{
"name": "my-awesome-package",
"scripts": {
"prepublishOnly": "baxast 'Source/**/*.ts'"
},
"dependencies": {
"baxast": "latest"
}
}
```

or with a custom esbuild config file:

```json
{
"scripts": {
"prepublishOnly": "baxast 'Source/**/*.ts' -es ESBuild.ts"
}
}
```

#### See an example of a config file in [ESBuild.ts](Source/Configuration/esbuild.ts)

`tsconfig.json`

```json
{
"compilerOptions": {
"outDir": "Target"
},
"extends": "./Source/Configuration/TypeScript",
"include": ["Source"]
}
```

The script will now automatically compile your build files with [esbuild] and
add TypeScript types.

[baxast]: https://npmjs.org/baxast
[esbuild]: https://npmjs.org/esbuild
31 changes: 18 additions & 13 deletions Source/Command/Build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ import type { BuildOptions } from "esbuild";
import { build as Build } from "esbuild";
import type { Pattern } from "fast-glob";
import Glob from "fast-glob";
import esbuild from "../Configuration/esbuild.js";
import _esbuild from "../Configuration/esbuild.js";
import File from "../Library/File.js";

export type Pipe = string[];

export default async (Files: Pattern[], Options?: { TypeScript?: string }) => {
export default async (
Files: Pattern[],
Options?: { esbuild?: string; TypeScript?: string }
) => {
const Pipe: Pipe = [];

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

Pipe.reverse();

const esbuild = Merge(_esbuild, {
entryPoints: Object.fromEntries(
Pipe.map((File) => [
File.replace("Source/", "").split(".").slice(0, -1.0).join("."),
File,
])
),
} satisfies BuildOptions);

await Build(
Merge(esbuild, {
entryPoints: Object.fromEntries(
Pipe.map((File) => [
File.replace("Source/", "")
.split(".")
.slice(0, -1.0)
.join("."),
File,
])
),
} satisfies BuildOptions)
Options?.esbuild
? Merge(esbuild, await File(Options?.esbuild))
: esbuild
);

if (Options?.TypeScript) {
Expand Down
5 changes: 3 additions & 2 deletions Source/Configuration/TypeScript.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"lib": [
"ESNext"
],
"module": "NodeNext",
"module": "ESNext",
"moduleResolution": "NodeNext",
"noFallthroughCasesInSwitch": true,
"noImplicitOverride": true,
Expand All @@ -40,7 +40,8 @@
"strictNullChecks": true,
"target": "ESNext",
"types": [
"node"
"node",
"@types/node"
],
"verbatimModuleSyntax": true
},
Expand Down
1 change: 0 additions & 1 deletion Source/Configuration/esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export default {
platform: "node",
target: "esnext",
write: true,
sourcemap: false,
plugins: [
{
name: "Target",
Expand Down
1 change: 1 addition & 0 deletions Source/Index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ try {
.version((await _JSON("../package.json", import.meta.url))?.version)
.description("Builds files")
.argument("<Files...>", "Files to build")
.option("-es, --esbuild <File>", "esbuild configuration file")
.option("-ts, --TypeScript <File>", "TypeScript configuration file")
.action(Build)
.parse();
Expand Down
30 changes: 30 additions & 0 deletions Source/Library/File.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { readFile as _File, writeFile as File } from "fs/promises";
import TypeScript from "typescript";
import { pathToFileURL as URL } from "url";
import _JSON from "./JSON.js";

export default async (Path: string) => {
if (Path.split(".").pop() === "ts") {
const { options } = TypeScript.convertCompilerOptionsFromJson(
(await _JSON("../Configuration/TypeScript.json", import.meta.url))
?.compilerOptions,
"."
);

TypeScript.createProgram(
[Path],
options,
TypeScript.createCompilerHost(options)
).emit();

await File(
Path.replace(".ts", ".js"),
TypeScript.transpile(
(await _File(Path, "utf-8")).toString(),
options
)
);
}

return (await import(URL(Path).toString().replace(".ts", ".js"))).default;
};
1 change: 1 addition & 0 deletions Target/Command/Build.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Pattern } from "fast-glob";
export type Pipe = string[];
declare const _default: (Files: Pattern[], Options?: {
esbuild?: string;
TypeScript?: string;
}) => Promise<void>;
export default _default;
2 changes: 1 addition & 1 deletion Target/Command/Build.js

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

5 changes: 3 additions & 2 deletions Target/Configuration/TypeScript.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"lib": [
"ESNext"
],
"module": "NodeNext",
"module": "ESNext",
"moduleResolution": "NodeNext",
"noFallthroughCasesInSwitch": true,
"noImplicitOverride": true,
Expand All @@ -40,7 +40,8 @@
"strictNullChecks": true,
"target": "ESNext",
"types": [
"node"
"node",
"@types/node"
],
"verbatimModuleSyntax": true
},
Expand Down
1 change: 0 additions & 1 deletion Target/Configuration/esbuild.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ declare const _default: {
platform: "node";
target: string;
write: true;
sourcemap: false;
plugins: any[];
};
export default _default;
2 changes: 1 addition & 1 deletion Target/Configuration/esbuild.js

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

2 changes: 1 addition & 1 deletion Target/Index.js

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

2 changes: 2 additions & 0 deletions Target/Library/File.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare const _default: (Path: string) => Promise<any>;
export default _default;
1 change: 1 addition & 0 deletions Target/Library/File.js

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

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "baxast",
"version": "0.0.11",
"version": "0.1.0",
"homepage": "https://github.com/baxast/baxast#readme",
"bugs": {
"url": "https://github.com/baxast/baxast/issues"
Expand All @@ -24,7 +24,8 @@
"esbuild": "0.19.0",
"esbuild-plugin-copy": "2.1.1",
"fast-glob": "3.3.1",
"typescript": "5.1.6"
"typescript": "5.1.6",
"@types/node": "20.4.9"
},
"devDependencies": {
"@types/node": "20.4.9",
Expand Down

0 comments on commit c1d4ac0

Please sign in to comment.