Skip to content

Commit

Permalink
🤖 Kastro auto deploy 2/3
Browse files Browse the repository at this point in the history
  • Loading branch information
KimlikDAO-bot committed Dec 31, 2024
1 parent 73ae026 commit a0a63b5
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 18 deletions.
13 changes: 12 additions & 1 deletion kastro/compiler/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ const Encoder = new TextEncoder();
/** @const {!Object<string, (CacheEntry|undefined)>} */
const CACHE = {};

/** @const {!Set<string>} */
const NAMED_ASSETS = new Set();

const populateChildTargets = (props) => {
const childProps = {
BuildMode: props.BuildMode,
Expand Down Expand Up @@ -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<void>} */
const bundle = mkdir("build/crate", { recursive: true }).then(() =>
CompressedMimes[getExt(targetName)]
Expand All @@ -205,9 +210,15 @@ const bundleTarget = (targetName, props) => props.BuildMode == BuildMode.Dev
return bundle.then(() => bundleName.slice(12));
});

/**
* @return {!Array<string>}
*/
const getNamedAssets = () => Array.from(NAMED_ASSETS);

export default {
BuildMode,
bundleTarget,
buildTarget,
forceBuildTarget
forceBuildTarget,
getNamedAssets,
};
10 changes: 5 additions & 5 deletions kastro/compiler/script.js
Original file line number Diff line number Diff line change
@@ -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);
}

Expand Down
8 changes: 3 additions & 5 deletions kastro/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
25 changes: 19 additions & 6 deletions kastro/kastro.js
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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();

Expand Down
15 changes: 14 additions & 1 deletion kastro/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
3 changes: 3 additions & 0 deletions util/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, (string|boolean|!Array<string>)>} */
Expand Down Expand Up @@ -35,6 +37,7 @@ const parseArgs = (args, defaultArgKey, shortArgMap) => {
}

export {
Blue,
Clear,
CliArgs,
Green,
Expand Down

0 comments on commit a0a63b5

Please sign in to comment.