From cc850048710efe983991e4562406f9e0b54bea33 Mon Sep 17 00:00:00 2001 From: Benjamin Jesuiter Date: Thu, 3 Apr 2025 13:16:27 +0200 Subject: [PATCH 01/26] add deno.json for jsr publishing --- deno.json | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 deno.json diff --git a/deno.json b/deno.json new file mode 100644 index 0000000..2b16454 --- /dev/null +++ b/deno.json @@ -0,0 +1,9 @@ +{ + "name": "@codemonument/asset-builder", + "version": "0.0.1", + "description": "Compiles assets into a assets.ts file for deno.compile - forked from https://deno.land/x/asset_builder", + "main": "index.ts", + "scripts": { + "build": "deno run --allow-read --allow-write index.ts" + } +} \ No newline at end of file From bf2e5af99a5fb349f75c615ce96c8125fa786fab Mon Sep 17 00:00:00 2001 From: Benjamin Jesuiter Date: Thu, 3 Apr 2025 13:21:47 +0200 Subject: [PATCH 02/26] add "run" task to deno json --- deno.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deno.json b/deno.json index 2b16454..00e647f 100644 --- a/deno.json +++ b/deno.json @@ -4,6 +4,6 @@ "description": "Compiles assets into a assets.ts file for deno.compile - forked from https://deno.land/x/asset_builder", "main": "index.ts", "scripts": { - "build": "deno run --allow-read --allow-write index.ts" + "run": "deno run --allow-read ./asset_builder.ts" } } \ No newline at end of file From 5eb58f233bd623834ff7da62dae99e3f739833d9 Mon Sep 17 00:00:00 2001 From: Benjamin Jesuiter Date: Thu, 3 Apr 2025 13:24:43 +0200 Subject: [PATCH 03/26] add "exports" field in deno json --- deno.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/deno.json b/deno.json index 00e647f..ce8b28f 100644 --- a/deno.json +++ b/deno.json @@ -1,8 +1,10 @@ { "name": "@codemonument/asset-builder", - "version": "0.0.1", "description": "Compiles assets into a assets.ts file for deno.compile - forked from https://deno.land/x/asset_builder", - "main": "index.ts", + "version": "0.0.1", + "exports": { + ".": "./asset_builder.ts" + }, "scripts": { "run": "deno run --allow-read ./asset_builder.ts" } From 17763749057b364bf1f06614f951f250bfe7136a Mon Sep 17 00:00:00 2001 From: Benjamin Jesuiter Date: Thu, 3 Apr 2025 13:25:11 +0200 Subject: [PATCH 04/26] fix tasks section in deno.json --- deno.json | 2 +- deno.lock | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 deno.lock diff --git a/deno.json b/deno.json index ce8b28f..513434d 100644 --- a/deno.json +++ b/deno.json @@ -5,7 +5,7 @@ "exports": { ".": "./asset_builder.ts" }, - "scripts": { + "tasks": { "run": "deno run --allow-read ./asset_builder.ts" } } \ No newline at end of file diff --git a/deno.lock b/deno.lock new file mode 100644 index 0000000..249a874 --- /dev/null +++ b/deno.lock @@ -0,0 +1,8 @@ +{ + "version": "4", + "remote": { + "https://deno.land/std@0.66.0/_util/assert.ts": "e1f76e77c5ccb5a8e0dbbbe6cce3a56d2556c8cb5a9a8802fc9565af72462149", + "https://deno.land/std@0.66.0/flags/mod.ts": "11f51e7fec72bfe01d531acb4e0b0ae54115439367377b088b3c6e7e7142918f", + "https://deno.land/std@0.97.0/encoding/base64.ts": "eecae390f1f1d1cae6f6c6d732ede5276bf4b9cd29b1d281678c054dc5cc009e" + } +} From 67d523973c850837aedff54c2389f9d43e95671f Mon Sep 17 00:00:00 2001 From: Benjamin Jesuiter Date: Thu, 3 Apr 2025 13:26:55 +0200 Subject: [PATCH 05/26] add config import to deno.json --- deno.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deno.json b/deno.json index 513434d..4f3fbd7 100644 --- a/deno.json +++ b/deno.json @@ -6,6 +6,6 @@ ".": "./asset_builder.ts" }, "tasks": { - "run": "deno run --allow-read ./asset_builder.ts" + "run": "deno run --allow-read ./asset_builder.ts --import-file ./example/asset_config.json" } } \ No newline at end of file From 7e1eec75a59adae08bc00406c501456e06d8fb59 Mon Sep 17 00:00:00 2001 From: Benjamin Jesuiter Date: Thu, 3 Apr 2025 13:28:59 +0200 Subject: [PATCH 06/26] add working example script --- deno.json | 2 +- example/asset.ts | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/deno.json b/deno.json index 4f3fbd7..abb2cfd 100644 --- a/deno.json +++ b/deno.json @@ -6,6 +6,6 @@ ".": "./asset_builder.ts" }, "tasks": { - "run": "deno run --allow-read ./asset_builder.ts --import-file ./example/asset_config.json" + "example": "deno run --allow-read ./asset_builder.ts --import-file ./example/asset_config.json >> ./example/asset.ts" } } \ No newline at end of file diff --git a/example/asset.ts b/example/asset.ts index 84a2fa5..cc9a7b7 100644 --- a/example/asset.ts +++ b/example/asset.ts @@ -1,16 +1,16 @@ -import { decode } from "https://deno.land/std@0.97.0/encoding/base64.ts"; +import {decode} from 'https://deno.land/std@0.97.0/encoding/base64.ts'; const bundledObject = { - files:{ - "test-text":{ - content:decode("SGVsbG8gV29ybGQhIQ=="), - extension: "txt" - }, - "test-text2":{ - content:decode("SGVsbG8gV29ybGQhIQ=="), - extension: "txt" - } - } -} + files: { + 'test-text': { + content: decode('SGVsbG8gV29ybGQhIQ=='), + extension: 'txt', + }, + 'test-text2': { + content: decode('SGVsbG8gV29ybGQhIQ=='), + extension: 'txt', + }, + }, +}; -export default bundledObject +export default bundledObject; From ef8ee097807f46b2f9b896c5ba3aeed5b1d4ede1 Mon Sep 17 00:00:00 2001 From: Benjamin Jesuiter Date: Thu, 3 Apr 2025 13:30:34 +0200 Subject: [PATCH 07/26] add verification script for example --- deno.json | 3 ++- example/{example.ts => verify.ts} | 0 2 files changed, 2 insertions(+), 1 deletion(-) rename example/{example.ts => verify.ts} (100%) diff --git a/deno.json b/deno.json index abb2cfd..cfad980 100644 --- a/deno.json +++ b/deno.json @@ -6,6 +6,7 @@ ".": "./asset_builder.ts" }, "tasks": { - "example": "deno run --allow-read ./asset_builder.ts --import-file ./example/asset_config.json >> ./example/asset.ts" + "example": "deno run --allow-read ./asset_builder.ts --import-file ./example/asset_config.json >> ./example/asset.ts", + "verify-example": "deno run --allow-read ./example/verify.ts" } } \ No newline at end of file diff --git a/example/example.ts b/example/verify.ts similarity index 100% rename from example/example.ts rename to example/verify.ts From cef4794b0515e3612454df99b65f79c566adabfd Mon Sep 17 00:00:00 2001 From: Benjamin Jesuiter Date: Thu, 3 Apr 2025 13:34:52 +0200 Subject: [PATCH 08/26] use jsr std/encoding instead of older deno.land/x import --- deno.json | 3 +++ deno.lock | 13 +++++++++++++ src/export_text.ts | 34 +++++++++++++++------------------- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/deno.json b/deno.json index cfad980..8a5ca10 100644 --- a/deno.json +++ b/deno.json @@ -8,5 +8,8 @@ "tasks": { "example": "deno run --allow-read ./asset_builder.ts --import-file ./example/asset_config.json >> ./example/asset.ts", "verify-example": "deno run --allow-read ./example/verify.ts" + }, + "imports": { + "@std/encoding": "jsr:@std/encoding@^1.0.8" } } \ No newline at end of file diff --git a/deno.lock b/deno.lock index 249a874..62e5642 100644 --- a/deno.lock +++ b/deno.lock @@ -1,8 +1,21 @@ { "version": "4", + "specifiers": { + "jsr:@std/encoding@^1.0.8": "1.0.8" + }, + "jsr": { + "@std/encoding@1.0.8": { + "integrity": "a6c8f3f933ab1bed66244f435d1dc0fd23a888e07195532122ddc3d5f8f0e6b4" + } + }, "remote": { "https://deno.land/std@0.66.0/_util/assert.ts": "e1f76e77c5ccb5a8e0dbbbe6cce3a56d2556c8cb5a9a8802fc9565af72462149", "https://deno.land/std@0.66.0/flags/mod.ts": "11f51e7fec72bfe01d531acb4e0b0ae54115439367377b088b3c6e7e7142918f", "https://deno.land/std@0.97.0/encoding/base64.ts": "eecae390f1f1d1cae6f6c6d732ede5276bf4b9cd29b1d281678c054dc5cc009e" + }, + "workspace": { + "dependencies": [ + "jsr:@std/encoding@^1.0.8" + ] } } diff --git a/src/export_text.ts b/src/export_text.ts index c587db9..6eafc9a 100644 --- a/src/export_text.ts +++ b/src/export_text.ts @@ -1,7 +1,7 @@ -import { ImportedFile } from "./type.d.ts"; +import type {ImportedFile} from './type.d.ts'; -const exportText = (exportText: string) => - `import { decode } from "https://deno.land/std@0.97.0/encoding/base64.ts"; +const exportTextFn = (exportText: string) => + `import { decodeBase64 } from "jsr:@std/encoding@~1.0.8"; const bundledObject = { files:{ @@ -11,22 +11,18 @@ const bundledObject = { export default bundledObject`; -const exportObjectText = ( - bundledObject: { [key: string]: ImportedFile }, -) => { - return Object.keys(bundledObject) - .map( - (key, index) => - `${index>0 ? ' ':''} "${key}":{\r\n content:decode("${ - bundledObject[key].content - }"),\r\n extension: "${bundledObject[key].extension}"\r\n }`, - ) - .join(",\r\n"); +const exportObjectText = (bundledObject: {[key: string]: ImportedFile}) => { + return Object.keys(bundledObject) + .map( + (key, index) => + `${index > 0 ? ' ' : ''} "${key}":{\r\n content:decode("${ + bundledObject[key].content + }"),\r\n extension: "${bundledObject[key].extension}"\r\n }` + ) + .join(',\r\n'); }; -export const exportBundledObject = ( - bundledObject: { [key: string]: ImportedFile }, -) => { - const tmp = exportObjectText(bundledObject); - return exportText(tmp); +export const exportBundledObject = (bundledObject: {[key: string]: ImportedFile}) => { + const tmp = exportObjectText(bundledObject); + return exportTextFn(tmp); }; From 8ce57c62e0d5ac3ab5eec5ec41a570a67f6f0e47 Mon Sep 17 00:00:00 2001 From: Benjamin Jesuiter Date: Thu, 3 Apr 2025 13:36:47 +0200 Subject: [PATCH 09/26] reformat exportTextFn for better readability --- src/export_text.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/export_text.ts b/src/export_text.ts index 6eafc9a..925f243 100644 --- a/src/export_text.ts +++ b/src/export_text.ts @@ -1,15 +1,15 @@ import type {ImportedFile} from './type.d.ts'; const exportTextFn = (exportText: string) => - `import { decodeBase64 } from "jsr:@std/encoding@~1.0.8"; - -const bundledObject = { - files:{ - ${exportText} - } -} - -export default bundledObject`; + ` + import { decodeBase64 } from "jsr:@std/encoding@~1.0.8"; + const bundledObject = { + files:{ + ${exportText} + } + } + export default bundledObject; +`; const exportObjectText = (bundledObject: {[key: string]: ImportedFile}) => { return Object.keys(bundledObject) From 6d53e754339424a6c2ecdaacc35e5c1d4ec95b9a Mon Sep 17 00:00:00 2001 From: Benjamin Jesuiter Date: Thu, 3 Apr 2025 13:38:38 +0200 Subject: [PATCH 10/26] overwrite example asset file --- deno.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deno.json b/deno.json index 8a5ca10..45c45ff 100644 --- a/deno.json +++ b/deno.json @@ -6,7 +6,7 @@ ".": "./asset_builder.ts" }, "tasks": { - "example": "deno run --allow-read ./asset_builder.ts --import-file ./example/asset_config.json >> ./example/asset.ts", + "example": "deno run --allow-read ./asset_builder.ts --import-file ./example/asset_config.json > ./example/asset.ts", "verify-example": "deno run --allow-read ./example/verify.ts" }, "imports": { From 8f20d17915f4a4c5f0edd2eba366f9009d0416a5 Mon Sep 17 00:00:00 2001 From: Benjamin Jesuiter Date: Thu, 3 Apr 2025 13:39:32 +0200 Subject: [PATCH 11/26] use new jsr based decodeBase64 in export_text file --- deno.lock | 3 ++- example/asset.ts | 29 +++++++++++++++-------------- src/export_text.ts | 3 ++- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/deno.lock b/deno.lock index 62e5642..b069522 100644 --- a/deno.lock +++ b/deno.lock @@ -1,7 +1,8 @@ { "version": "4", "specifiers": { - "jsr:@std/encoding@^1.0.8": "1.0.8" + "jsr:@std/encoding@^1.0.8": "1.0.8", + "jsr:@std/encoding@~1.0.8": "1.0.8" }, "jsr": { "@std/encoding@1.0.8": { diff --git a/example/asset.ts b/example/asset.ts index cc9a7b7..eb33885 100644 --- a/example/asset.ts +++ b/example/asset.ts @@ -1,16 +1,17 @@ -import {decode} from 'https://deno.land/std@0.97.0/encoding/base64.ts'; -const bundledObject = { - files: { - 'test-text': { - content: decode('SGVsbG8gV29ybGQhIQ=='), - extension: 'txt', - }, - 'test-text2': { - content: decode('SGVsbG8gV29ybGQhIQ=='), - extension: 'txt', - }, - }, -}; + import { decodeBase64 } from "jsr:@std/encoding@~1.0.8"; + + const bundledObject = { + files:{ + "test-text":{ + content:decodeBase64("SGVsbG8gV29ybGQhIQ=="), + extension: "txt" + }, + "test-text2":{ + content:decodeBase64("SGVsbG8gV29ybGQhIQ=="), + extension: "txt" + } + } + } + export default bundledObject; -export default bundledObject; diff --git a/src/export_text.ts b/src/export_text.ts index 925f243..7cf91b9 100644 --- a/src/export_text.ts +++ b/src/export_text.ts @@ -3,6 +3,7 @@ import type {ImportedFile} from './type.d.ts'; const exportTextFn = (exportText: string) => ` import { decodeBase64 } from "jsr:@std/encoding@~1.0.8"; + const bundledObject = { files:{ ${exportText} @@ -15,7 +16,7 @@ const exportObjectText = (bundledObject: {[key: string]: ImportedFile}) => { return Object.keys(bundledObject) .map( (key, index) => - `${index > 0 ? ' ' : ''} "${key}":{\r\n content:decode("${ + `${index > 0 ? ' ' : ''} "${key}":{\r\n content:decodeBase64("${ bundledObject[key].content }"),\r\n extension: "${bundledObject[key].extension}"\r\n }` ) From 9aab879eeac66bd0b146959620c344cd41eb3fa6 Mon Sep 17 00:00:00 2001 From: Benjamin Jesuiter Date: Thu, 3 Apr 2025 13:41:09 +0200 Subject: [PATCH 12/26] convert internal functions from lambda to real "function" --- src/export_text.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/export_text.ts b/src/export_text.ts index 7cf91b9..d4448da 100644 --- a/src/export_text.ts +++ b/src/export_text.ts @@ -1,7 +1,7 @@ import type {ImportedFile} from './type.d.ts'; -const exportTextFn = (exportText: string) => - ` +function exportTextFn(exportText: string): string { + return ` import { decodeBase64 } from "jsr:@std/encoding@~1.0.8"; const bundledObject = { @@ -11,8 +11,9 @@ const exportTextFn = (exportText: string) => } export default bundledObject; `; +} -const exportObjectText = (bundledObject: {[key: string]: ImportedFile}) => { +function exportObjectText(bundledObject: {[key: string]: ImportedFile}): string { return Object.keys(bundledObject) .map( (key, index) => @@ -21,7 +22,7 @@ const exportObjectText = (bundledObject: {[key: string]: ImportedFile}) => { }"),\r\n extension: "${bundledObject[key].extension}"\r\n }` ) .join(',\r\n'); -}; +} export const exportBundledObject = (bundledObject: {[key: string]: ImportedFile}) => { const tmp = exportObjectText(bundledObject); From b06a538af133982318aaa83e34c0b8ec21a6adfa Mon Sep 17 00:00:00 2001 From: Benjamin Jesuiter Date: Thu, 3 Apr 2025 13:44:37 +0200 Subject: [PATCH 13/26] use jsr:@std/encoding@~1.0.8 and direct imports in asset_builder instead of deps.ts --- asset_builder.ts | 60 +++++++++++++++++++++++------------------------- deps.ts | 5 +--- 2 files changed, 30 insertions(+), 35 deletions(-) diff --git a/asset_builder.ts b/asset_builder.ts index b6de835..018f688 100644 --- a/asset_builder.ts +++ b/asset_builder.ts @@ -1,47 +1,45 @@ -import { parse, encode, ImportTargetFile, ImportedFile, exportBundledObject } from "./deps.ts" +import {parse} from './deps.ts'; + +import {encodeBase64} from 'jsr:@std/encoding@~1.0.8'; +import {exportBundledObject} from './src/export_text.ts'; +import type {ImportedFile, ImportTargetFile} from './src/type.d.ts'; const parsedArgs = parse(Deno.args); const importFileName = - typeof parsedArgs["import-file"] === "string" - ? parsedArgs["import-file"] - : "assets_config.json"; + typeof parsedArgs['import-file'] === 'string' ? parsedArgs['import-file'] : 'assets_config.json'; -let bundleList = ""; +let bundleList = ''; try { - const readFile = Deno.readTextFileSync(importFileName); - bundleList = readFile; + const readFile = Deno.readTextFileSync(importFileName); + bundleList = readFile; } catch (error) { - if (error.name === "NotFound") { - console.error( - `Import Config file [${importFileName}] is not Found!!\nplease confirm.` - ); - Deno.exit(); - } - throw error; + if (error.name === 'NotFound') { + console.error(`Import Config file [${importFileName}] is not Found!!\nplease confirm.`); + Deno.exit(); + } + throw error; } const bundleListArr: [ImportTargetFile] = JSON.parse(bundleList).files; -let bundledObject: { [key: string]: ImportedFile } = {}; - -bundleListArr.forEach((file) => { - try { - const content = encode(Deno.readFileSync(file.importPath)); - const extension = file.importPath.split(".").slice(-1)[0]; - bundledObject[`${file.calledName}`] = { content, extension }; - } catch (error) { - if (error.name === "NotFound") { - console.error( - `Import file [${file.importPath}] is not Found!!\nplease confirm.` - ); - Deno.exit(); - } - throw error; - } +let bundledObject: {[key: string]: ImportedFile} = {}; + +bundleListArr.forEach(file => { + try { + const content = encodeBase64(Deno.readFileSync(file.importPath)); + const extension = file.importPath.split('.').slice(-1)[0]; + bundledObject[`${file.calledName}`] = {content, extension}; + } catch (error) { + if (error.name === 'NotFound') { + console.error(`Import file [${file.importPath}] is not Found!!\nplease confirm.`); + Deno.exit(); + } + throw error; + } }); -const exportText = exportBundledObject(bundledObject) +const exportText = exportBundledObject(bundledObject); console.log(exportText); diff --git a/deps.ts b/deps.ts index dfd1128..40af164 100644 --- a/deps.ts +++ b/deps.ts @@ -1,4 +1 @@ -export { parse } from "https://deno.land/std@0.66.0/flags/mod.ts"; -export { encode } from "https://deno.land/std@0.97.0/encoding/base64.ts"; -export type { ImportTargetFile, ImportedFile } from "./src/type.d.ts" -export { exportBundledObject } from "./src/export_text.ts" +export {parse} from 'https://deno.land/std@0.66.0/flags/mod.ts'; From 49ba5ddb4e5c3c5ef4dbc432ce5f0ae62887d00c Mon Sep 17 00:00:00 2001 From: Benjamin Jesuiter Date: Thu, 3 Apr 2025 13:46:27 +0200 Subject: [PATCH 14/26] use parseArgs fn from jsr --- asset_builder.ts | 5 ++--- deno.json | 1 + deno.lock | 5 +++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/asset_builder.ts b/asset_builder.ts index 018f688..4bd44d5 100644 --- a/asset_builder.ts +++ b/asset_builder.ts @@ -1,10 +1,9 @@ -import {parse} from './deps.ts'; - +import {parseArgs} from '@std/cli/parse-args'; import {encodeBase64} from 'jsr:@std/encoding@~1.0.8'; import {exportBundledObject} from './src/export_text.ts'; import type {ImportedFile, ImportTargetFile} from './src/type.d.ts'; -const parsedArgs = parse(Deno.args); +const parsedArgs = parseArgs(Deno.args); const importFileName = typeof parsedArgs['import-file'] === 'string' ? parsedArgs['import-file'] : 'assets_config.json'; diff --git a/deno.json b/deno.json index 45c45ff..de6bcb5 100644 --- a/deno.json +++ b/deno.json @@ -10,6 +10,7 @@ "verify-example": "deno run --allow-read ./example/verify.ts" }, "imports": { + "@std/cli": "jsr:@std/cli@^1.0.15", "@std/encoding": "jsr:@std/encoding@^1.0.8" } } \ No newline at end of file diff --git a/deno.lock b/deno.lock index b069522..b8c33f2 100644 --- a/deno.lock +++ b/deno.lock @@ -1,10 +1,14 @@ { "version": "4", "specifiers": { + "jsr:@std/cli@^1.0.15": "1.0.15", "jsr:@std/encoding@^1.0.8": "1.0.8", "jsr:@std/encoding@~1.0.8": "1.0.8" }, "jsr": { + "@std/cli@1.0.15": { + "integrity": "e79ba3272ec710ca44d8342a7688e6288b0b88802703f3264184b52893d5e93f" + }, "@std/encoding@1.0.8": { "integrity": "a6c8f3f933ab1bed66244f435d1dc0fd23a888e07195532122ddc3d5f8f0e6b4" } @@ -16,6 +20,7 @@ }, "workspace": { "dependencies": [ + "jsr:@std/cli@^1.0.15", "jsr:@std/encoding@^1.0.8" ] } From 0588c9c7ab299ce837b73a9450205e8b85cdb088 Mon Sep 17 00:00:00 2001 From: Benjamin Jesuiter Date: Thu, 3 Apr 2025 13:53:07 +0200 Subject: [PATCH 15/26] modernize asset_builder.ts --- asset_builder.ts | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/asset_builder.ts b/asset_builder.ts index 4bd44d5..db01644 100644 --- a/asset_builder.ts +++ b/asset_builder.ts @@ -5,34 +5,39 @@ import type {ImportedFile, ImportTargetFile} from './src/type.d.ts'; const parsedArgs = parseArgs(Deno.args); -const importFileName = +const assetsConfigFileName = typeof parsedArgs['import-file'] === 'string' ? parsedArgs['import-file'] : 'assets_config.json'; -let bundleList = ''; +let assetsConfigString = ''; try { - const readFile = Deno.readTextFileSync(importFileName); - bundleList = readFile; + assetsConfigString = Deno.readTextFileSync(assetsConfigFileName); } catch (error) { - if (error.name === 'NotFound') { - console.error(`Import Config file [${importFileName}] is not Found!!\nplease confirm.`); + if (error instanceof Deno.errors.NotFound) { + console.error( + `Assets Config file [${assetsConfigFileName}] is not Found!!\nPlease confirm path.` + ); Deno.exit(); } throw error; } -const bundleListArr: [ImportTargetFile] = JSON.parse(bundleList).files; +// The list of asset files to be bundled +const assetFilesList: [ImportTargetFile] = JSON.parse(assetsConfigString).files; -let bundledObject: {[key: string]: ImportedFile} = {}; +// The output object of bundled files +const bundledObject: {[key: string]: ImportedFile} = {}; -bundleListArr.forEach(file => { +assetFilesList.forEach(file => { try { const content = encodeBase64(Deno.readFileSync(file.importPath)); const extension = file.importPath.split('.').slice(-1)[0]; bundledObject[`${file.calledName}`] = {content, extension}; } catch (error) { - if (error.name === 'NotFound') { - console.error(`Import file [${file.importPath}] is not Found!!\nplease confirm.`); + if (error instanceof Deno.errors.NotFound) { + console.error( + `Asset file [${file.importPath}] is not Found - Cannot bundle!!\nPlease confirm.` + ); Deno.exit(); } throw error; From dc4e857bc4a06f3013fa20265dbbf31b0df88687 Mon Sep 17 00:00:00 2001 From: Benjamin Jesuiter Date: Thu, 3 Apr 2025 13:55:11 +0200 Subject: [PATCH 16/26] add publishing commands --- deno.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/deno.json b/deno.json index de6bcb5..b85545b 100644 --- a/deno.json +++ b/deno.json @@ -7,7 +7,9 @@ }, "tasks": { "example": "deno run --allow-read ./asset_builder.ts --import-file ./example/asset_config.json > ./example/asset.ts", - "verify-example": "deno run --allow-read ./example/verify.ts" + "verify-example": "deno run --allow-read ./example/verify.ts", + "dry": "deno publish --dry-run", + "deploy": "deno publish" }, "imports": { "@std/cli": "jsr:@std/cli@^1.0.15", From 834703620bf5068d1aa8d23e9fe61993881c62a7 Mon Sep 17 00:00:00 2001 From: Benjamin Jesuiter Date: Thu, 3 Apr 2025 13:58:20 +0200 Subject: [PATCH 17/26] update license --- LICENSE | 1 + 1 file changed, 1 insertion(+) diff --git a/LICENSE b/LICENSE index 1beb820..890ddfb 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,6 @@ MIT License +Copyright (c) 2024 Benjamin Jesuiter (for changes made to the original code, see github commit history) Copyright (c) 2021 Octo Permission is hereby granted, free of charge, to any person obtaining a copy From 96428948e10e4c8b2451fc40d6b54a4660ecf0dc Mon Sep 17 00:00:00 2001 From: Benjamin Jesuiter Date: Thu, 3 Apr 2025 13:59:13 +0200 Subject: [PATCH 18/26] set version to 1.0.4 --- deno.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deno.json b/deno.json index b85545b..be16330 100644 --- a/deno.json +++ b/deno.json @@ -1,7 +1,7 @@ { "name": "@codemonument/asset-builder", "description": "Compiles assets into a assets.ts file for deno.compile - forked from https://deno.land/x/asset_builder", - "version": "0.0.1", + "version": "1.0.4", "exports": { ".": "./asset_builder.ts" }, From 3b1128316f68a65b14a959e7489b561656cd0f11 Mon Sep 17 00:00:00 2001 From: Benjamin Jesuiter Date: Thu, 3 Apr 2025 14:00:54 +0200 Subject: [PATCH 19/26] exclude the example folder from jsr publish --- deno.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/deno.json b/deno.json index be16330..853ae0a 100644 --- a/deno.json +++ b/deno.json @@ -5,6 +5,9 @@ "exports": { ".": "./asset_builder.ts" }, + "exclude": [ + "./example" + ], "tasks": { "example": "deno run --allow-read ./asset_builder.ts --import-file ./example/asset_config.json > ./example/asset.ts", "verify-example": "deno run --allow-read ./example/verify.ts", From 646fcd75e84f84867270d35725d47b21b75d8087 Mon Sep 17 00:00:00 2001 From: Benjamin Jesuiter Date: Thu, 3 Apr 2025 14:01:56 +0200 Subject: [PATCH 20/26] delete legacy deps.ts --- deps.ts | 1 - 1 file changed, 1 deletion(-) delete mode 100644 deps.ts diff --git a/deps.ts b/deps.ts deleted file mode 100644 index 40af164..0000000 --- a/deps.ts +++ /dev/null @@ -1 +0,0 @@ -export {parse} from 'https://deno.land/std@0.66.0/flags/mod.ts'; From a86f0ab9b41d850dfc9a59007e04209bd63e0fa9 Mon Sep 17 00:00:00 2001 From: Benjamin Jesuiter Date: Thu, 3 Apr 2025 14:02:48 +0200 Subject: [PATCH 21/26] ignore ./asset_config.json.sample for publishing --- deno.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/deno.json b/deno.json index 853ae0a..7ea1bdf 100644 --- a/deno.json +++ b/deno.json @@ -6,7 +6,8 @@ ".": "./asset_builder.ts" }, "exclude": [ - "./example" + "./example", + "./asset_config.json.sample" ], "tasks": { "example": "deno run --allow-read ./asset_builder.ts --import-file ./example/asset_config.json > ./example/asset.ts", From f72e43f75a623a8f25c136d0ddfeb4c71932836b Mon Sep 17 00:00:00 2001 From: Benjamin Jesuiter Date: Thu, 3 Apr 2025 14:02:59 +0200 Subject: [PATCH 22/26] rename file form confusing type.d.ts file to types.ts file --- asset_builder.ts | 2 +- src/export_text.ts | 2 +- src/{type.d.ts => types.ts} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename src/{type.d.ts => types.ts} (100%) diff --git a/asset_builder.ts b/asset_builder.ts index db01644..d6594b4 100644 --- a/asset_builder.ts +++ b/asset_builder.ts @@ -1,7 +1,7 @@ import {parseArgs} from '@std/cli/parse-args'; import {encodeBase64} from 'jsr:@std/encoding@~1.0.8'; import {exportBundledObject} from './src/export_text.ts'; -import type {ImportedFile, ImportTargetFile} from './src/type.d.ts'; +import type {ImportedFile, ImportTargetFile} from './src/types.ts'; const parsedArgs = parseArgs(Deno.args); diff --git a/src/export_text.ts b/src/export_text.ts index d4448da..5bb0204 100644 --- a/src/export_text.ts +++ b/src/export_text.ts @@ -1,4 +1,4 @@ -import type {ImportedFile} from './type.d.ts'; +import type {ImportedFile} from './types.ts'; function exportTextFn(exportText: string): string { return ` diff --git a/src/type.d.ts b/src/types.ts similarity index 100% rename from src/type.d.ts rename to src/types.ts From b99f6141df2a22c980443b071545489dbe396f54 Mon Sep 17 00:00:00 2001 From: Benjamin Jesuiter Date: Thu, 3 Apr 2025 14:05:10 +0200 Subject: [PATCH 23/26] add github actions publishing flow --- .github/workflows/publish.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..ce541c8 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,18 @@ +# .github/workflows/publish.yml + +name: Publish + +on: + push: + branches: + - main + +jobs: + publish: + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write # The OIDC ID token is used for authentication with JSR. + steps: + - uses: actions/checkout@v4 + - run: npx jsr publish From 21068372770ed469d26df6dc1f1a093787685bc2 Mon Sep 17 00:00:00 2001 From: Benjamin Jesuiter Date: Thu, 3 Apr 2025 14:08:53 +0200 Subject: [PATCH 24/26] trigger on new tags --- .github/workflows/publish.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ce541c8..1da3ac8 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -4,8 +4,8 @@ name: Publish on: push: - branches: - - main + tags: + - '*' jobs: publish: From da467dbd752c37fdfbf0495f1e017b41bb47d920 Mon Sep 17 00:00:00 2001 From: Benjamin Jesuiter Date: Thu, 3 Apr 2025 14:21:52 +0200 Subject: [PATCH 25/26] add example script to test running this from jsr --- README.md | 50 ++++++++++++++++++++++++++++---------------------- deno.json | 3 ++- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 224e6c0..afa1add 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,29 @@ -# asset_builder -Asset files (eg, text, image) bundle tool for Deno. +# Deno asset-builder for deno compile -# Install +Bundles asset files (eg, text, image) for deno compile into base64 encoded strings in a typescript file. +This TS file can be used with `deno compile` to load these assets at runtime. -```sh -deno install --allow-read https://deno.land/x/asset_builder/asset_builder.ts +# Usage - directly run from jsr +```sh # Import config file from default ./assets_config.json. -asset_builder >> asset.ts +deno run --allow-read jsr:@codemonument/asset-builder >> asset.ts # Set Import config file. -asset_builder --import-file my_assets_config.json >> asset.ts +deno run --allow-read jsr:@codemonument/asset-builder --import-file my_assets_config.json >> asset.ts ``` -# Usage +# Usage - install as a global binary ```sh -# Import config file from default ./assets_config.json. -deno run --allow-read https://deno.land/x/asset_builder/asset_builder.ts >> asset.ts +# change the name for this binary by passing a different -n argument +deno install --global --allow-read -n asset-builder jsr:@codemonument/asset-builder -# Set Import config file. -deno run --allow-read https://deno.land/x/asset_builder/asset_builder.ts --import-file my_assets_config.json >> asset.ts +# Use default config (./assets_config.json) +asset-builder >> asset.ts + +# Use a custom config file +asset-builder --import-file my_assets_config.json >> asset.ts ``` # Configuration @@ -30,12 +33,12 @@ Write as follows. ```json { - "files":[ - { - "importPath": "./sample.txt", - "calledName": "sample-text" - } - ] + "files": [ + { + "importPath": "./sample.txt", + "calledName": "sample-text" + } + ] } ``` @@ -43,13 +46,16 @@ Write as follows. The file created by asset_builder is used as follows. -```ts -import asset from './asset.ts' +```ts +import asset from './asset.ts'; for (const [key, value] of Object.entries(asset.files)) { - console.log(`key: ${key}, extension: ${value.extension}, content: ${new TextDecoder().decode(value.content) }`); + console.log( + `key: ${key}, extension: ${value.extension}, content: ${new TextDecoder().decode( + value.content + )}` + ); } // key: test-text, extension: txt, content: Hello World!! // key: test-text2, extension: txt, content: Hello World!! ``` - diff --git a/deno.json b/deno.json index 7ea1bdf..1f557c1 100644 --- a/deno.json +++ b/deno.json @@ -13,7 +13,8 @@ "example": "deno run --allow-read ./asset_builder.ts --import-file ./example/asset_config.json > ./example/asset.ts", "verify-example": "deno run --allow-read ./example/verify.ts", "dry": "deno publish --dry-run", - "deploy": "deno publish" + "deploy": "deno publish", + "example-jsr": "deno run --allow-read jsr:@codemonument/asset-builder --import-file example/asset_config.json > example/asset.ts" }, "imports": { "@std/cli": "jsr:@std/cli@^1.0.15", From 8e8c62406e8961b6cc33b82a1b19e6da5be08736 Mon Sep 17 00:00:00 2001 From: Benjamin Jesuiter Date: Thu, 3 Apr 2025 14:22:05 +0200 Subject: [PATCH 26/26] improve readme and release version 1.0.5 --- deno.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deno.json b/deno.json index 1f557c1..2ac1df1 100644 --- a/deno.json +++ b/deno.json @@ -1,7 +1,7 @@ { "name": "@codemonument/asset-builder", "description": "Compiles assets into a assets.ts file for deno.compile - forked from https://deno.land/x/asset_builder", - "version": "1.0.4", + "version": "1.0.5", "exports": { ".": "./asset_builder.ts" },