Compare commits

..

3 commits
v0.1.2 ... main

Author SHA1 Message Date
76b8d3b342 chore(version): v0.1.3 2025-04-14 11:32:52 -04:00
a1b480fc47 fix: use raw string to prevent quote issues 2025-04-14 11:31:59 -04:00
f6077d4a1d docs: fix example 2025-04-11 19:42:35 -04:00
4 changed files with 49 additions and 44 deletions

View file

@ -2,6 +2,14 @@
All notable changes to this project will be documented in this file. See [conventional commits](https://www.conventionalcommits.org/) for commit guidelines.
- - -
## v0.1.3 - 2025-04-14
#### Bug Fixes
- use raw string to prevent quote issues - (a1b480f) - aleidk
#### Documentation
- fix example - (f6077d4) - aleidk
- - -
## v0.1.2 - 2025-04-11
#### Bug Fixes
- add shebang to entrypoint - (b4a5514) - aleidk

View file

@ -21,7 +21,7 @@ fn main() {
let output = Command::new("bun")
.args([
"run",
"scripts/build.ts",
"tmpl-build-and-load",
"--outdir",
out_dir.as_str(),
"--globs",

View file

@ -5,28 +5,28 @@ import { parseArgs } from "node:util";
import path from "node:path";
const { values } = parseArgs({
args: Bun.argv,
options: {
globs: {
type: "string",
short: "g",
},
outdir: {
type: "string",
short: "o",
},
bundle_name: {
type: "string",
short: "n",
default: "main",
},
},
strict: true,
allowPositionals: true,
args: Bun.argv,
options: {
globs: {
type: "string",
short: "g",
},
outdir: {
type: "string",
short: "o",
},
bundle_name: {
type: "string",
short: "n",
default: "main",
},
},
strict: true,
allowPositionals: true,
});
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}"`);
@ -35,40 +35,37 @@ console.log(`Building glob "${values.globs}" to "${values.outdir}"`);
const entrypoints = Array.from(new Bun.Glob(values.globs).scanSync("."));
const result = await Bun.build({
entrypoints,
publicPath: "/",
// splitting: true,
plugins: [sassPlugin],
minify: {
whitespace: true,
identifiers: true,
syntax: true,
},
naming: {
entry: "[dir]/[name].[ext]",
chunk: "assets/[name]-[hash].[ext]",
asset: "assets/[name]-[hash].[ext]",
},
entrypoints,
publicPath: "/",
// splitting: true,
plugins: [sassPlugin],
minify: {
whitespace: true,
identifiers: true,
syntax: true,
},
naming: {
entry: "[dir]/[name].[ext]",
chunk: "assets/[name]-[hash].[ext]",
asset: "assets/[name]-[hash].[ext]",
},
});
let out = "";
out += "|env: &mut minijinja::Environment| {\n";
for (const res of result.outputs) {
// Can be consumed as blobs
let asset_text = await res.text();
asset_text = asset_text.replaceAll(/\n/g, "\\n");
asset_text = asset_text.replaceAll(/"/g, `\\"`);
const asset_path = path.normalize(res.path);
out += `env.add_template("${asset_path}", "${asset_text}").expect("Embedded an invalid template");\n`;
// Can be consumed as blobs
const asset_text = await res.text();
const asset_path = path.normalize(res.path);
out += `env.add_template("${asset_path}", r##"${asset_text}"##).expect("Embedded an invalid template");\n`;
}
out += "}";
Bun.write(
path.join(values.outdir, `minijinja_templates_${values.bundle_name}.rs`),
out,
path.join(values.outdir, `minijinja_templates_${values.bundle_name}.rs`),
out,
);
console.log("Assets compiled!");

View file

@ -1,5 +1,5 @@
{
"version": "0.1.2",
"version": "0.1.3",
"name": "@alecodes/tmpl-build-and-load",
"module": "index.ts",
"type": "module",