@@ -23,6 +23,9 @@ const BUILD = ".build";
23
23
const DIST = "dist" ;
24
24
const IMAGES = "images" ;
25
25
26
+ const PACKAGES = "packages" ;
27
+ const TOOLS = "tools" ;
28
+
26
29
const IMAGE_TASKS = ".build/image-tasks" ;
27
30
const GLYF_TTC = ".build/glyf-ttc" ;
28
31
@@ -321,8 +324,8 @@ const FontInfoOf = computed.group("metadata:font-info-of", async (target, fileNa
321
324
customLigationTags : bp . customLigationTags || null ,
322
325
// Shape
323
326
shape : {
324
- serifs : bp . serifs || null ,
325
- spacing : bp . spacing || null ,
327
+ serifs : bp . serifs || "sans" ,
328
+ spacing : bp . spacing || "normal" ,
326
329
weight : sfi . shapeWeight ,
327
330
width : sfi . shapeWidth ,
328
331
slope : sfi . shapeSlope ,
@@ -482,7 +485,7 @@ const DistUnhintedTTF = file.make(
482
485
// Ab-initio build
483
486
const cacheFileName =
484
487
`${ 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 } ` ;
486
489
const cachePath = `${ SHARED_CACHE } /${ cacheFileName } .mpz` ;
487
490
const cacheDiffPath = `${ charMapPath . dir } /${ fn } .cache.mpz` ;
488
491
@@ -1288,7 +1291,7 @@ const ReleaseAncillary = task(`release:ancillary`, async target => {
1288
1291
await target . need ( SampleImages , Pages , AmendReadme , ReleaseNotes , ChangeLog ) ;
1289
1292
} ) ;
1290
1293
const ReleaseArchives = task ( `release:archives` , async target => {
1291
- const [ collectPlans ] = await target . need ( CollectPlans , UtilScriptFiles ) ;
1294
+ const [ collectPlans ] = await target . need ( CollectPlans , UtilScripts ) ;
1292
1295
1293
1296
let goals = [ ] ;
1294
1297
for ( const [ cgr , plan ] of Object . entries ( collectPlans ) ) {
@@ -1300,7 +1303,7 @@ const ReleaseArchives = task(`release:archives`, async target => {
1300
1303
} ) ;
1301
1304
1302
1305
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 ) ;
1304
1307
const plan = collectPlans [ cgr ] ;
1305
1308
if ( ! plan || ! plan . inRelease ) throw new Error ( `CollectGroup ${ cgr } is not in release.` ) ;
1306
1309
@@ -1329,54 +1332,65 @@ const ReleaseArchivesFor = task.group(`release:archives-for`, async (target, cgr
1329
1332
////// Script Building //////
1330
1333
///////////////////////////////////////////////////////////
1331
1334
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 (
1337
1352
( ext , dir ) => `${ ext } -scripts-under::${ dir } ` ,
1338
1353
( target , ext , dir ) => FileList ( { under : dir , pattern : `**/*.${ ext } ` } ) ( target ) ,
1339
1354
) ;
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 ) ) ;
1347
1359
} ) ;
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 ) ;
1351
1367
} ) ;
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 ( / p a c k a g e s \/ ( [ \w - ] + ) \/ s r c (? = $ | \/ ) / , "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
+ ] ;
1354
1377
}
1355
1378
1356
- const CompiledJs = file . make (
1379
+ const CompiledJsFromPtl = file . make (
1357
1380
p => p ,
1358
1381
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
+
1362
1388
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
1363
1391
await silently . run ( PATEL_C , "--strict" , "--esm" , ptl , "-o" , out . full ) ;
1364
1392
} ,
1365
1393
) ;
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
- } ) ;
1380
1394
1381
1395
const Parameters = task ( `meta:parameters` , async target => {
1382
1396
await target . need (
0 commit comments