From a0a63b567a0de2924479b14d8ff6b2b7b5deca46 Mon Sep 17 00:00:00 2001 From: KimlikDAO-bot Date: Mon, 30 Dec 2024 23:00:39 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Kastro=20auto=20deploy=202/3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kastro/compiler/compiler.js | 13 ++++++++++++- kastro/compiler/script.js | 10 +++++----- kastro/image.js | 8 +++----- kastro/kastro.js | 25 +++++++++++++++++++------ kastro/props.js | 15 ++++++++++++++- util/cli.js | 3 +++ 6 files changed, 56 insertions(+), 18 deletions(-) diff --git a/kastro/compiler/compiler.js b/kastro/compiler/compiler.js index 8b5e175..97f0811 100644 --- a/kastro/compiler/compiler.js +++ b/kastro/compiler/compiler.js @@ -38,6 +38,9 @@ const Encoder = new TextEncoder(); /** @const {!Object} */ const CACHE = {}; +/** @const {!Set} */ +const NAMED_ASSETS = new Set(); + const populateChildTargets = (props) => { const childProps = { BuildMode: props.BuildMode, @@ -192,6 +195,8 @@ const bundleTarget = (targetName, props) => props.BuildMode == BuildMode.Dev /** @const {string} */ const bundleName = "build/crate/" + (props.bundleName || `${hash.toStr(contentHash)}.${getExt(targetName)}`); + if (props.bundleName) + NAMED_ASSETS.add(props.bundleName); /** @const {!Promise} */ const bundle = mkdir("build/crate", { recursive: true }).then(() => CompressedMimes[getExt(targetName)] @@ -205,9 +210,15 @@ const bundleTarget = (targetName, props) => props.BuildMode == BuildMode.Dev return bundle.then(() => bundleName.slice(12)); }); +/** + * @return {!Array} + */ +const getNamedAssets = () => Array.from(NAMED_ASSETS); + export default { BuildMode, bundleTarget, buildTarget, - forceBuildTarget + forceBuildTarget, + getNamedAssets, }; diff --git a/kastro/compiler/script.js b/kastro/compiler/script.js index b1aebb7..59e827e 100644 --- a/kastro/compiler/script.js +++ b/kastro/compiler/script.js @@ -1,17 +1,17 @@ import { compile } from "../../kdjs/compile"; -import { filterGlobalProps } from "../props"; +import { filterGlobalProps, filterOutGlobalProps } from "../props"; /** @const {TargetFunction} */ -const scriptTarget = (_, props) => { +const scriptTarget = (_, { src: entry, ...props }) => { const params = { - entry: props.src, + entry, isolateDir: `kdjs-${props.Lang}`, globals: { ...filterGlobalProps(props), GEN: false - } + }, + ...filterOutGlobalProps(props) }; - if (props.strict) params.globals.strict = true; return compile(params, props.checkFreshFn); } diff --git a/kastro/image.js b/kastro/image.js index 39d47a2..f7c16c9 100644 --- a/kastro/image.js +++ b/kastro/image.js @@ -5,12 +5,10 @@ import compiler from "./compiler/compiler"; import { Props } from "./compiler/targetRegistry"; import { removeGlobalProps } from "./props"; -const REMOVE_PROPS = ["piggyback", "bundleName", "childTargets"]; - -const makeImageElement = (bundleName, { inSvg, ...props }) => { +const makeImageElement = (bundleName, { inSvg, piggyback, childTargets, ...props }) => { removeGlobalProps(props); - for (const prop of REMOVE_PROPS) - if (prop in props) delete props[prop]; + if (piggyback) + bundleName = piggyback + bundleName; if (inSvg) props.href = bundleName; else props.src = bundleName; return tagYaz(inSvg ? "image" : "img", props, true); diff --git a/kastro/kastro.js b/kastro/kastro.js index 75609f7..138fd4a 100644 --- a/kastro/kastro.js +++ b/kastro/kastro.js @@ -1,7 +1,7 @@ import { plugin } from "bun"; import { readFile } from "node:fs/promises"; import { createServer } from "vite"; -import { parseArgs } from "../util/cli"; +import { Blue, Clear, Green, parseArgs } from "../util/cli"; import { combine, getDir } from "../util/paths"; import compiler from "./compiler/compiler"; import { ttfTarget, woff2Target } from "./compiler/font"; @@ -144,15 +144,28 @@ const buildCrate = (crateName, buildMode) => import(crateName) const map = cratePageProps(crate, buildMode); for (const [route, props] of Object.entries(map)) if (route != "/") { - console.info("\n\n\nBuilding", props.targetName); + console.info(`${Blue}[Building]${Clear} ${props.targetName}`); await compiler.bundleTarget(props.targetName, props); } + if (crate.Page) { + const targetName = "/" + combine(`build/${getDir(crateName)}`, "kvPageWorker.js"); + console.info(`${Blue}[Building]${Clear} ${targetName}`); + await compiler.bundleTarget(targetName, { + src: "lib/kastro/cloudflare/kvPageWorker.js", + globals: { + HOST_URL: crate.HOST_URL, + }, + strict: true, + }); + } + return crate; }) -const deployCrate = (crateName) => import(crateName) - .then(async (crate) => { - // TODO(KimlikDAO-bot) - }) +const deployCrate = (crateName) => buildCrate(crateName, compiler.BuildMode.Compiled) + .then((crate) => { + console.info(`${Green}[Deploying]${Clear} ${crate.HOST_URL}`); + console.log(compiler.getNamedAssets()); + }); setupKastro(); diff --git a/kastro/props.js b/kastro/props.js index 044d93f..cbb5ace 100644 --- a/kastro/props.js +++ b/kastro/props.js @@ -15,4 +15,17 @@ const filterGlobalProps = (props) => { return result; } -export { Props, removeGlobalProps, filterGlobalProps }; +const filterOutGlobalProps = (props) => { + const result = {}; + for (const prop in props) + if (prop.charCodeAt(0) >= 91) + result[prop] = props[prop]; + return result; +} + +export { + Props, + filterGlobalProps, + filterOutGlobalProps, + removeGlobalProps +}; diff --git a/util/cli.js b/util/cli.js index d7f6402..ee0ea59 100644 --- a/util/cli.js +++ b/util/cli.js @@ -3,6 +3,8 @@ const Red = "\x1b[41m"; /** @const {string} */ const Green = "\x1b[42m"; /** @const {string} */ +const Blue = "\x1b[44m"; +/** @const {string} */ const Clear = "\x1b[0m"; /** @typedef {!Object)>} */ @@ -35,6 +37,7 @@ const parseArgs = (args, defaultArgKey, shortArgMap) => { } export { + Blue, Clear, CliArgs, Green,