Skip to content

Commit

Permalink
🚢 Towards BuildMode.Release
Browse files Browse the repository at this point in the history
  • Loading branch information
KimlikDAO-bot committed Sep 13, 2024
1 parent dbd8910 commit 4bbae23
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 31 deletions.
3 changes: 0 additions & 3 deletions kastro/compiler/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ const compilePage = async (componentName, pageGlobals) => {
// TODO(KimlikDAO-bot): Remove when we have 3 languages
pageGlobals.TR = pageGlobals.Lang == LangCode.TR;
initGlobals(pageGlobals);

console.log(pageGlobals);

return compileComponent(componentName, {}, pageGlobals)
.then((html) => {
html = "<!DOCTYPE html>" + html;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { compile } from "../../kdjs/compile";
import { ensureDotJs, selectDefines } from "../defines";
import { ensureDotJs, selectDefines } from "./defines";

/**
* @param {string} dirName
Expand Down
1 change: 1 addition & 0 deletions kastro/crate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { readFile, readdir } from "node:fs/promises";
import { I18nString, LangCode } from "../util/i18n";

/**
* @dict
* @typedef {{
* index: string,
* codebaseLang: LangCode,
Expand Down
62 changes: 36 additions & 26 deletions kastro/kastro.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,54 @@
import yaml from "js-yaml";
import { readFile } from "node:fs/promises";
import { uploadWorker } from "./cloudflare/targets";
import { BuildMode } from "./compiler/compiler";
import { compilePage } from "./compiler/page";
import { compileWorker } from "./compiler/worker";
import { readCrateRecipe } from "./crate";
import { sayfaOku } from "./sayfa/eskiOkuyucu";
import { compileWorker } from "./sunucu/targets";
import { plugin } from "bun";

/** @define {string} */
const ROOT_PATH = "../../..";


/**
* @param {string} createDir
* @param {!Object} env
*/
const buildCrate = (createDir, env) => import(`${ROOT_PATH}/${createDir}/build.js`)
.then((buildFile) => buildFile.default && buildFile.default.build
? buildFile.default.build(env)
: Promise.reject())
.catch(() => readCrateRecipe(createDir)
.then((recipe) => {
const tasks = [];
if (recipe.dizin) {
const pages = [].concat({
en: "en",
tr: "tr",
konum: `${recipe.dizin}/sayfa.html`
}, recipe.sayfalar);
const buildCrate = (createDir, env) => readCrateRecipe(createDir)
.then((crate) => {
const tasks = [];
/** @const {!Array<string>} */
const langs = crate.pages ? Object.keys(crate.pages[0]) : crate.languages;

for (const lang of ["tr", "en"])
for (const page of pages) {
page.konum ||= `${page.tr}/sayfa.html`;
tasks.push(sayfaOku({ ...page, dil: lang }));
}
if (crate.index) {
/**
* Given a page, schedules the compilation of it in all languages of the
* crate.
*
* @param {I18nString} page a page defined by its routes
* @param {string=} rootComponent
*/
const buildPage = (page, rootComponent) => {
for (const lang of langs) {
const pageData = {
BuildMode: BuildMode.Dev, // TODO(KimlikDAO-bot): fix
Lang: lang,
CodebaseLang: crate.codebaseLang,
Route: { ...page }
};
delete pageData.Route[lang];
tasks.push(compilePage(rootComponent || page[crate.codebaseLang], pageData));
}
}

if (recipe.worker)
compileWorker(createDir, recipe.worker, env);
})
);
buildPage(Object.fromEntries(langs.map(lang => [lang, lang])), crate.index);
// if (crate.pages)
// for (const page of crate.pages)
// buildPage(page);
}

if (crate.worker)
compileWorker(crate.worker.name, crate.worker, env);
});

/**
* @param {string} createDir
Expand Down
1 change: 0 additions & 1 deletion kastro/workers/devServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const readCrate = (crateName, buildMode) => readCrateRecipe(crateName)
const langs = crate.pages ? Object.keys(crate.pages[0]) : crate.languages;
const map = {};
const add = (page, rootComponent) => {
const route = {};
for (const lang of langs) {
const pageData = {
RootComponent: (crateName === "." ? "" : `${crateName}/`) + (rootComponent || page[crate.codebaseLang]),
Expand Down

0 comments on commit 4bbae23

Please sign in to comment.