Compare commits
2 commits
e43815f2a6
...
5786338063
| Author | SHA1 | Date | |
|---|---|---|---|
| 5786338063 | |||
| b4a551489c |
3 changed files with 50 additions and 42 deletions
|
|
@ -2,6 +2,12 @@
|
||||||
All notable changes to this project will be documented in this file. See [conventional commits](https://www.conventionalcommits.org/) for commit guidelines.
|
All notable changes to this project will be documented in this file. See [conventional commits](https://www.conventionalcommits.org/) for commit guidelines.
|
||||||
|
|
||||||
- - -
|
- - -
|
||||||
|
## v0.1.2 - 2025-04-11
|
||||||
|
#### Bug Fixes
|
||||||
|
- add shebang to entrypoint - (b4a5514) - aleidk
|
||||||
|
|
||||||
|
- - -
|
||||||
|
|
||||||
## v0.1.1 - 2025-04-11
|
## v0.1.1 - 2025-04-11
|
||||||
#### Bug Fixes
|
#### Bug Fixes
|
||||||
- remove unecesary dependency - (cf7bf3f) - aleidk
|
- remove unecesary dependency - (cf7bf3f) - aleidk
|
||||||
|
|
|
||||||
84
index.ts
84
index.ts
|
|
@ -1,30 +1,32 @@
|
||||||
|
#!/usr/bin/env bun
|
||||||
|
|
||||||
import sassPlugin from "@alecodes/bun-plugin-sass";
|
import sassPlugin from "@alecodes/bun-plugin-sass";
|
||||||
import { parseArgs } from "node:util";
|
import { parseArgs } from "node:util";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
|
|
||||||
const { values } = parseArgs({
|
const { values } = parseArgs({
|
||||||
args: Bun.argv,
|
args: Bun.argv,
|
||||||
options: {
|
options: {
|
||||||
globs: {
|
globs: {
|
||||||
type: "string",
|
type: "string",
|
||||||
short: "g",
|
short: "g",
|
||||||
},
|
},
|
||||||
outdir: {
|
outdir: {
|
||||||
type: "string",
|
type: "string",
|
||||||
short: "o",
|
short: "o",
|
||||||
},
|
},
|
||||||
bundle_name: {
|
bundle_name: {
|
||||||
type: "string",
|
type: "string",
|
||||||
short: "n",
|
short: "n",
|
||||||
default: "main",
|
default: "main",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
strict: true,
|
strict: true,
|
||||||
allowPositionals: true,
|
allowPositionals: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (values.globs === undefined || values.outdir === undefined) {
|
if (values.globs === undefined || values.outdir === undefined) {
|
||||||
throw new Error("Error in the arguments provided.");
|
throw new Error("Error in the arguments provided.");
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Building glob "${values.globs}" to "${values.outdir}"`);
|
console.log(`Building glob "${values.globs}" to "${values.outdir}"`);
|
||||||
|
|
@ -33,39 +35,39 @@ console.log(`Building glob "${values.globs}" to "${values.outdir}"`);
|
||||||
const entrypoints = Array.from(new Bun.Glob(values.globs).scanSync("."));
|
const entrypoints = Array.from(new Bun.Glob(values.globs).scanSync("."));
|
||||||
|
|
||||||
const result = await Bun.build({
|
const result = await Bun.build({
|
||||||
entrypoints,
|
entrypoints,
|
||||||
publicPath: "/",
|
publicPath: "/",
|
||||||
// splitting: true,
|
// splitting: true,
|
||||||
plugins: [sassPlugin],
|
plugins: [sassPlugin],
|
||||||
minify: {
|
minify: {
|
||||||
whitespace: true,
|
whitespace: true,
|
||||||
identifiers: true,
|
identifiers: true,
|
||||||
syntax: true,
|
syntax: true,
|
||||||
},
|
},
|
||||||
naming: {
|
naming: {
|
||||||
entry: "[dir]/[name].[ext]",
|
entry: "[dir]/[name].[ext]",
|
||||||
chunk: "assets/[name]-[hash].[ext]",
|
chunk: "assets/[name]-[hash].[ext]",
|
||||||
asset: "assets/[name]-[hash].[ext]",
|
asset: "assets/[name]-[hash].[ext]",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
let out = "";
|
let out = "";
|
||||||
out += "|env: &mut minijinja::Environment| {\n";
|
out += "|env: &mut minijinja::Environment| {\n";
|
||||||
|
|
||||||
for (const res of result.outputs) {
|
for (const res of result.outputs) {
|
||||||
// Can be consumed as blobs
|
// Can be consumed as blobs
|
||||||
let asset_text = await res.text();
|
let asset_text = await res.text();
|
||||||
asset_text = asset_text.replaceAll(/\n/g, "\\n");
|
asset_text = asset_text.replaceAll(/\n/g, "\\n");
|
||||||
asset_text = asset_text.replaceAll(/"/g, `\\"`);
|
asset_text = asset_text.replaceAll(/"/g, `\\"`);
|
||||||
const asset_path = path.normalize(res.path);
|
const asset_path = path.normalize(res.path);
|
||||||
out += `env.add_template("${asset_path}", "${asset_text}").expect("Embedded an invalid template");\n`;
|
out += `env.add_template("${asset_path}", "${asset_text}").expect("Embedded an invalid template");\n`;
|
||||||
}
|
}
|
||||||
|
|
||||||
out += "}";
|
out += "}";
|
||||||
|
|
||||||
Bun.write(
|
Bun.write(
|
||||||
path.join(values.outdir, `minijinja_templates_${values.bundle_name}.rs`),
|
path.join(values.outdir, `minijinja_templates_${values.bundle_name}.rs`),
|
||||||
out,
|
out,
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log("Assets compiled!");
|
console.log("Assets compiled!");
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"version": "0.1.1",
|
"version": "0.1.2",
|
||||||
"name": "@alecodes/tmpl-build-and-load",
|
"name": "@alecodes/tmpl-build-and-load",
|
||||||
"module": "index.ts",
|
"module": "index.ts",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue