Skip to content

Commit 27ab378

Browse files
authored
Eng: Move MJS compiled from PTL to package/<name>/lib directory (be5invis#2462)
1 parent 854b4f7 commit 27ab378

File tree

4 files changed

+59
-44
lines changed

4 files changed

+59
-44
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ dist
1111
release-archives
1212

1313
# Generated files
14+
packages/*/lib
1415
packages/font-glyphs/src/**/*.mjs
1516
packages/font-otl/src/**/*.mjs
1617

packages/font-glyphs/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"version": "31.1.0",
44
"private": true,
55
"exports": {
6-
".": "./src/index.mjs",
7-
"./aesthetics": "./src/meta/aesthetics.mjs",
8-
"./unicode-knowledge": "./src/meta/unicode-knowledge.mjs"
6+
".": "./lib/index.mjs",
7+
"./aesthetics": "./lib/meta/aesthetics.mjs",
8+
"./unicode-knowledge": "./lib/meta/unicode-knowledge.mjs"
99
},
1010
"dependencies": {
1111
"@iosevka/font-kits": "31.1.0",

packages/font-otl/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "31.1.0",
44
"private": true,
55
"exports": {
6-
".": "./src/index.mjs"
6+
".": "./lib/index.mjs"
77
},
88
"dependencies": {
99
"@iosevka/font-glyphs": "31.1.0",

verdafile.mjs

+54-40
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ const BUILD = ".build";
2323
const DIST = "dist";
2424
const IMAGES = "images";
2525

26+
const PACKAGES = "packages";
27+
const TOOLS = "tools";
28+
2629
const IMAGE_TASKS = ".build/image-tasks";
2730
const GLYF_TTC = ".build/glyf-ttc";
2831

@@ -321,8 +324,8 @@ const FontInfoOf = computed.group("metadata:font-info-of", async (target, fileNa
321324
customLigationTags: bp.customLigationTags || null,
322325
// Shape
323326
shape: {
324-
serifs: bp.serifs || null,
325-
spacing: bp.spacing || null,
327+
serifs: bp.serifs || "sans",
328+
spacing: bp.spacing || "normal",
326329
weight: sfi.shapeWeight,
327330
width: sfi.shapeWidth,
328331
slope: sfi.shapeSlope,
@@ -482,7 +485,7 @@ const DistUnhintedTTF = file.make(
482485
// Ab-initio build
483486
const cacheFileName =
484487
`${Math.round(1000 * fi.shape.weight)}-${Math.round(1000 * fi.shape.width)}-` +
485-
`${Math.round(3600 * fi.shape.slopeAngle)}`;
488+
`${Math.round(3600 * fi.shape.slopeAngle)}-${fi.shape.serifs}`;
486489
const cachePath = `${SHARED_CACHE}/${cacheFileName}.mpz`;
487490
const cacheDiffPath = `${charMapPath.dir}/${fn}.cache.mpz`;
488491

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

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

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

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

1332-
const MARCOS = [
1333-
fu`packages/font-glyphs/src/meta/macros.ptl`,
1334-
fu`packages/font-otl/src/meta/macros.ptl`,
1335-
];
1336-
const ScriptsUnder = oracle.make(
1335+
const Scripts = task("scripts", async target => {
1336+
const [jsFromPtlMap] = await target.need(JsFilesFromPtl);
1337+
const [jsList] = await target.need(FindScriptsUnder(`mjs`, PACKAGES));
1338+
const jsFromPtlSet = new Set(Object.keys(jsFromPtlMap));
1339+
1340+
let subGoals = [];
1341+
for (const js of jsFromPtlSet) subGoals.push(CompiledJsFromPtl(js));
1342+
for (const js of jsList) if (!jsFromPtlSet.has(js)) subGoals.push(sfu(js));
1343+
await target.need(subGoals);
1344+
});
1345+
const UtilScripts = task("util-scripts", async target => {
1346+
const [mjs] = await target.need(FindScriptsUnder("mjs", TOOLS));
1347+
const [md] = await target.need(FindScriptsUnder("md", TOOLS));
1348+
await target.need(mjs.map(fu), md.map(fu));
1349+
});
1350+
1351+
const FindScriptsUnder = oracle.make(
13371352
(ext, dir) => `${ext}-scripts-under::${dir}`,
13381353
(target, ext, dir) => FileList({ under: dir, pattern: `**/*.${ext}` })(target),
13391354
);
1340-
const UtilScriptFiles = computed("util-script-files", async target => {
1341-
const [mjs, md] = await target.need(ScriptsUnder("mjs", "tools"), ScriptsUnder("md", "tools"));
1342-
return [...mjs, ...md];
1343-
});
1344-
const ScriptFiles = computed.group("script-files", async (target, ext) => {
1345-
const [ss] = await target.need(ScriptsUnder(ext, `packages`));
1346-
return ss;
1355+
1356+
const JsFilesFromPtl = computed("scripts-js-from-ptl", async target => {
1357+
const [ptl] = await target.need(FindScriptsUnder(`ptl`, PACKAGES));
1358+
return Object.fromEntries(ptl.map(compiledMjsPathFromPtlPath));
13471359
});
1348-
const JavaScriptFromPtl = computed("scripts-js-from-ptl", async target => {
1349-
const [ptl] = await target.need(ScriptFiles("ptl"));
1350-
return ptl.map(x => replaceExt(".mjs", x));
1360+
const MacroPtlFiles = computed("macro-ptl-files", async target => {
1361+
const [jsFromPtlMap] = await target.need(JsFilesFromPtl);
1362+
let macroGoals = [];
1363+
for (const [mjs, { isMacro, fromPath }] of Object.entries(jsFromPtlMap)) {
1364+
if (isMacro) macroGoals.push(sfu(fromPath));
1365+
}
1366+
await target.need(macroGoals);
13511367
});
1352-
function replaceExt(extNew, file) {
1353-
return Path.posix.join(Path.dirname(file), Path.basename(file, Path.extname(file)) + extNew);
1368+
function compiledMjsPathFromPtlPath(path) {
1369+
const dirName = Path.dirname(path);
1370+
const newDirName = dirName.replace(/packages\/([\w-]+)\/src(?=$|\/)/, "packages/$1/lib");
1371+
const newFileName = Path.basename(path, Path.extname(path)) + ".mjs";
1372+
const isMacro = Path.basename(path) === "macros.ptl";
1373+
return [
1374+
`${newDirName}/${newFileName}`,
1375+
{ isMacro, fromPath: path, oldOutPath: `${dirName}/${newFileName}` },
1376+
];
13541377
}
13551378

1356-
const CompiledJs = file.make(
1379+
const CompiledJsFromPtl = file.make(
13571380
p => p,
13581381
async (target, out) => {
1359-
const ptl = replaceExt(".ptl", out.full);
1360-
await target.need(MARCOS);
1361-
await target.need(sfu(ptl));
1382+
const [jsFromPtlMap] = await target.need(JsFilesFromPtl);
1383+
const ptl = jsFromPtlMap[out.full].fromPath;
1384+
const oldOutPath = jsFromPtlMap[out.full].oldOutPath;
1385+
1386+
await target.need(MacroPtlFiles, sfu(ptl));
1387+
13621388
echo.action(echo.hl.command("Compile Script"), ptl);
1389+
await Promise.all([rm(oldOutPath), rm(out.full)]); // Remove old output file
1390+
await target.need(de(Path.dirname(out.full))); // Create output directory
13631391
await silently.run(PATEL_C, "--strict", "--esm", ptl, "-o", out.full);
13641392
},
13651393
);
1366-
const Scripts = task("scripts", async target => {
1367-
const [jsFromPtlList] = await target.need(JavaScriptFromPtl);
1368-
const [jsList] = await target.need(ScriptFiles("mjs"));
1369-
const jsFromPtlSet = new Set(jsFromPtlList);
1370-
1371-
let subGoals = [];
1372-
for (const js of jsFromPtlSet) subGoals.push(CompiledJs(js));
1373-
for (const js of jsList) if (!jsFromPtlSet.has(js)) subGoals.push(sfu(js));
1374-
await target.need(subGoals);
1375-
});
1376-
const UtilScripts = task("util-scripts", async target => {
1377-
const [files] = await target.need(UtilScriptFiles);
1378-
await target.need(files.map(fu));
1379-
});
13801394

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

0 commit comments

Comments
 (0)