Skip to content

Commit

Permalink
Eng: Move MJS compiled from PTL to package/<name>/lib directory (#2462
Browse files Browse the repository at this point in the history
)
  • Loading branch information
be5invis authored Aug 8, 2024
1 parent 854b4f7 commit 27ab378
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 44 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dist
release-archives

# Generated files
packages/*/lib
packages/font-glyphs/src/**/*.mjs
packages/font-otl/src/**/*.mjs

Expand Down
6 changes: 3 additions & 3 deletions packages/font-glyphs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"version": "31.1.0",
"private": true,
"exports": {
".": "./src/index.mjs",
"./aesthetics": "./src/meta/aesthetics.mjs",
"./unicode-knowledge": "./src/meta/unicode-knowledge.mjs"
".": "./lib/index.mjs",
"./aesthetics": "./lib/meta/aesthetics.mjs",
"./unicode-knowledge": "./lib/meta/unicode-knowledge.mjs"
},
"dependencies": {
"@iosevka/font-kits": "31.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/font-otl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "31.1.0",
"private": true,
"exports": {
".": "./src/index.mjs"
".": "./lib/index.mjs"
},
"dependencies": {
"@iosevka/font-glyphs": "31.1.0",
Expand Down
94 changes: 54 additions & 40 deletions verdafile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const BUILD = ".build";
const DIST = "dist";
const IMAGES = "images";

const PACKAGES = "packages";
const TOOLS = "tools";

const IMAGE_TASKS = ".build/image-tasks";
const GLYF_TTC = ".build/glyf-ttc";

Expand Down Expand Up @@ -321,8 +324,8 @@ const FontInfoOf = computed.group("metadata:font-info-of", async (target, fileNa
customLigationTags: bp.customLigationTags || null,
// Shape
shape: {
serifs: bp.serifs || null,
spacing: bp.spacing || null,
serifs: bp.serifs || "sans",
spacing: bp.spacing || "normal",
weight: sfi.shapeWeight,
width: sfi.shapeWidth,
slope: sfi.shapeSlope,
Expand Down Expand Up @@ -482,7 +485,7 @@ const DistUnhintedTTF = file.make(
// Ab-initio build
const cacheFileName =
`${Math.round(1000 * fi.shape.weight)}-${Math.round(1000 * fi.shape.width)}-` +
`${Math.round(3600 * fi.shape.slopeAngle)}`;
`${Math.round(3600 * fi.shape.slopeAngle)}-${fi.shape.serifs}`;
const cachePath = `${SHARED_CACHE}/${cacheFileName}.mpz`;
const cacheDiffPath = `${charMapPath.dir}/${fn}.cache.mpz`;

Expand Down Expand Up @@ -1288,7 +1291,7 @@ const ReleaseAncillary = task(`release:ancillary`, async target => {
await target.need(SampleImages, Pages, AmendReadme, ReleaseNotes, ChangeLog);
});
const ReleaseArchives = task(`release:archives`, async target => {
const [collectPlans] = await target.need(CollectPlans, UtilScriptFiles);
const [collectPlans] = await target.need(CollectPlans, UtilScripts);

let goals = [];
for (const [cgr, plan] of Object.entries(collectPlans)) {
Expand All @@ -1300,7 +1303,7 @@ const ReleaseArchives = task(`release:archives`, async target => {
});

const ReleaseArchivesFor = task.group(`release:archives-for`, async (target, cgr) => {
const [version, collectPlans] = await target.need(Version, CollectPlans, UtilScriptFiles);
const [version, collectPlans] = await target.need(Version, CollectPlans, UtilScripts);
const plan = collectPlans[cgr];
if (!plan || !plan.inRelease) throw new Error(`CollectGroup ${cgr} is not in release.`);

Expand Down Expand Up @@ -1329,54 +1332,65 @@ const ReleaseArchivesFor = task.group(`release:archives-for`, async (target, cgr
////// Script Building //////
///////////////////////////////////////////////////////////

const MARCOS = [
fu`packages/font-glyphs/src/meta/macros.ptl`,
fu`packages/font-otl/src/meta/macros.ptl`,
];
const ScriptsUnder = oracle.make(
const Scripts = task("scripts", async target => {
const [jsFromPtlMap] = await target.need(JsFilesFromPtl);
const [jsList] = await target.need(FindScriptsUnder(`mjs`, PACKAGES));
const jsFromPtlSet = new Set(Object.keys(jsFromPtlMap));

let subGoals = [];
for (const js of jsFromPtlSet) subGoals.push(CompiledJsFromPtl(js));
for (const js of jsList) if (!jsFromPtlSet.has(js)) subGoals.push(sfu(js));
await target.need(subGoals);
});
const UtilScripts = task("util-scripts", async target => {
const [mjs] = await target.need(FindScriptsUnder("mjs", TOOLS));
const [md] = await target.need(FindScriptsUnder("md", TOOLS));
await target.need(mjs.map(fu), md.map(fu));
});

const FindScriptsUnder = oracle.make(
(ext, dir) => `${ext}-scripts-under::${dir}`,
(target, ext, dir) => FileList({ under: dir, pattern: `**/*.${ext}` })(target),
);
const UtilScriptFiles = computed("util-script-files", async target => {
const [mjs, md] = await target.need(ScriptsUnder("mjs", "tools"), ScriptsUnder("md", "tools"));
return [...mjs, ...md];
});
const ScriptFiles = computed.group("script-files", async (target, ext) => {
const [ss] = await target.need(ScriptsUnder(ext, `packages`));
return ss;

const JsFilesFromPtl = computed("scripts-js-from-ptl", async target => {
const [ptl] = await target.need(FindScriptsUnder(`ptl`, PACKAGES));
return Object.fromEntries(ptl.map(compiledMjsPathFromPtlPath));
});
const JavaScriptFromPtl = computed("scripts-js-from-ptl", async target => {
const [ptl] = await target.need(ScriptFiles("ptl"));
return ptl.map(x => replaceExt(".mjs", x));
const MacroPtlFiles = computed("macro-ptl-files", async target => {
const [jsFromPtlMap] = await target.need(JsFilesFromPtl);
let macroGoals = [];
for (const [mjs, { isMacro, fromPath }] of Object.entries(jsFromPtlMap)) {
if (isMacro) macroGoals.push(sfu(fromPath));
}
await target.need(macroGoals);
});
function replaceExt(extNew, file) {
return Path.posix.join(Path.dirname(file), Path.basename(file, Path.extname(file)) + extNew);
function compiledMjsPathFromPtlPath(path) {
const dirName = Path.dirname(path);
const newDirName = dirName.replace(/packages\/([\w-]+)\/src(?=$|\/)/, "packages/$1/lib");
const newFileName = Path.basename(path, Path.extname(path)) + ".mjs";
const isMacro = Path.basename(path) === "macros.ptl";
return [
`${newDirName}/${newFileName}`,
{ isMacro, fromPath: path, oldOutPath: `${dirName}/${newFileName}` },
];
}

const CompiledJs = file.make(
const CompiledJsFromPtl = file.make(
p => p,
async (target, out) => {
const ptl = replaceExt(".ptl", out.full);
await target.need(MARCOS);
await target.need(sfu(ptl));
const [jsFromPtlMap] = await target.need(JsFilesFromPtl);
const ptl = jsFromPtlMap[out.full].fromPath;
const oldOutPath = jsFromPtlMap[out.full].oldOutPath;

await target.need(MacroPtlFiles, sfu(ptl));

echo.action(echo.hl.command("Compile Script"), ptl);
await Promise.all([rm(oldOutPath), rm(out.full)]); // Remove old output file
await target.need(de(Path.dirname(out.full))); // Create output directory
await silently.run(PATEL_C, "--strict", "--esm", ptl, "-o", out.full);
},
);
const Scripts = task("scripts", async target => {
const [jsFromPtlList] = await target.need(JavaScriptFromPtl);
const [jsList] = await target.need(ScriptFiles("mjs"));
const jsFromPtlSet = new Set(jsFromPtlList);

let subGoals = [];
for (const js of jsFromPtlSet) subGoals.push(CompiledJs(js));
for (const js of jsList) if (!jsFromPtlSet.has(js)) subGoals.push(sfu(js));
await target.need(subGoals);
});
const UtilScripts = task("util-scripts", async target => {
const [files] = await target.need(UtilScriptFiles);
await target.need(files.map(fu));
});

const Parameters = task(`meta:parameters`, async target => {
await target.need(
Expand Down

0 comments on commit 27ab378

Please sign in to comment.