forked from be5invis/Iosevka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
verdafile.js
475 lines (434 loc) · 16.5 KB
/
verdafile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
"use strict";
const build = require("verda").create();
const { task, tasks, file, files, oracle, oracles, computed, computes, phony } = build.ruleTypes;
const { de, fu } = build.rules;
const { run, node, cd, cp, rm } = build.actions;
const { FileList } = build.predefinedFuncs;
module.exports = build;
///////////////////////////////////////////////////////////
const fs = require("fs");
const path = require("path");
const toml = require("toml");
const BUILD = "build";
const DIST = "dist";
const ARCHIVE_DIR = "release-archives";
const PATEL_C = ["node", "./node_modules/patel/bin/patel-c"];
const GENERATE = ["node", "gen/generator"];
const webfontFormats = [["woff2", "woff2"], ["woff", "woff"], ["ttf", "truetype"]];
const BUILD_PLANS = path.relative(__dirname, path.resolve(__dirname, "./build-plans.toml"));
const PRIVATE_BUILD_PLANS = path.relative(
__dirname,
path.resolve(__dirname, "./private-build-plans.toml")
);
// Save journal to build/
build.setJournal(`${BUILD}/.verda-build-journal`);
// Enable self-tracking
build.setSelfTracking();
///////////////////////////////////////////////////////////
////// Oracles //////
///////////////////////////////////////////////////////////
const Version = oracle(`version`, async () => {
const package_json = JSON.parse(fs.readFileSync(path.join(__dirname, "package.json")));
return package_json.version;
});
const RawPlans = oracle(`raw-plans`, async target => {
await target.need(fu(BUILD_PLANS));
if (fs.existsSync(PRIVATE_BUILD_PLANS)) {
await target.need(fu(PRIVATE_BUILD_PLANS));
}
const t = toml.parse(fs.readFileSync(BUILD_PLANS, "utf-8"));
if (fs.existsSync(PRIVATE_BUILD_PLANS)) {
Object.assign(
t.buildPlans,
toml.parse(fs.readFileSync(PRIVATE_BUILD_PLANS, "utf-8")).buildPlans
);
}
for (const prefix in t.buildPlans) {
const plan = t.buildPlans[prefix];
plan.prefix = prefix;
// Style groups
if (!plan.pre) plan.pre = {};
if (!plan.post) plan.post = {};
if (!plan.pre.design) plan.pre.design = plan.design || [];
if (!plan.pre.upright) plan.pre.upright = plan.upright || [];
if (!plan.pre.italic) plan.pre.italic = plan.italic || [];
if (!plan.pre.oblique) plan.pre.oblique = plan.oblique || [];
if (!plan.post.design) plan.post.design = [];
if (!plan.post.upright) plan.post.upright = [];
if (!plan.post.italic) plan.post.italic = [];
if (!plan.post.oblique) plan.post.oblique = [];
}
for (const prefix in t.collectPlans) {
t.collectPlans[prefix].prefix = prefix;
}
return t;
});
const BuildPlans = computed("build-plans", async target => {
const [rp] = await target.need(RawPlans);
return rp.buildPlans;
});
const ExportPlans = computed("export-plans", async target => {
const [rp] = await target.need(RawPlans);
return rp.exportPlans;
});
const RawCollectPlans = computed("raw-collect-plans", async target => {
const [rp] = await target.need(RawPlans);
return rp.collectPlans;
});
const Weights = computed("weights", async target => {
const [rp] = await target.need(RawPlans);
return rp.weights;
});
const Slants = computed("slants", async target => {
const [rp] = await target.need(RawPlans);
return rp.slants;
});
function getSuffixSet(weights, slants) {
const mapping = {};
for (const w in weights) {
for (const s in slants) {
const suffix =
(w === "regular" ? (s === "upright" ? "regular" : "") : w) +
(s === "upright" ? "" : s);
mapping[suffix] = {
hives: [`w-${weights[w].shape}`, `s-${s}`],
weight: w,
cssWeight: weights[w].css || w,
menuWeight: weights[w].menu || weights[w].css || w,
slant: s,
cssStyle: slants[s] || s,
menuStyle: slants[s] || s
};
}
}
return mapping;
}
const Suffixes = computed(`suffixes`, async target => {
const [weights, slants] = await target.need(Weights, Slants);
return getSuffixSet(weights, slants);
});
const FontBuildingParameters = computed(`font-building-parameters`, async target => {
const [buildPlans, defaultWeights, defaultSlants] = await target.need(
BuildPlans,
Weights,
Slants
);
const fontInfos = {};
const bp = {};
for (const p in buildPlans) {
const { pre, post, prefix, family, weights, slants } = buildPlans[p];
const targets = [];
const suffixMapping = getSuffixSet(weights || defaultWeights, slants || defaultSlants);
for (const suffix in suffixMapping) {
if (weights && !weights[suffixMapping[suffix].weight]) continue;
if (slants && !slants[suffixMapping[suffix].slant]) continue;
const fileName = [prefix, suffix].join("-");
const preHives = [...pre.design, ...pre[suffixMapping[suffix].slant]];
const postHives = [...post.design, ...post[suffixMapping[suffix].slant]];
fontInfos[fileName] = {
name: fileName,
family,
hives: ["iosevka", ...preHives, ...suffixMapping[suffix].hives, ...postHives],
menuWeight: suffixMapping[suffix].menuWeight,
menuStyle: suffixMapping[suffix].menuStyle,
cssWeight: suffixMapping[suffix].cssWeight,
cssStyle: suffixMapping[suffix].cssStyle
};
targets.push(fileName);
}
bp[prefix] = {
family,
prefix,
targets
};
}
return { fontInfos, buildPlans: bp };
});
const CollectPlans = computed(`collect-plans`, async target => {
const [rawCollectPlans, suffixMapping] = await target.need(RawCollectPlans, Suffixes);
const composition = {},
groups = {};
for (const gid in rawCollectPlans) {
groups[gid] = [];
const collect = rawCollectPlans[gid];
for (const suffix in suffixMapping) {
const fileName = `${collect.prefix}-${suffix}`;
composition[fileName] = [];
for (const prefix of collect.from) {
composition[fileName].push({
dir: prefix,
file: `${prefix}-${suffix}`
});
}
groups[gid].push(fileName);
}
}
return { composition, groups };
});
const HivesOf = computes.group("hives-of", async (target, gid) => {
const [{ fontInfos }] = await target.need(FontBuildingParameters);
return fontInfos[gid];
});
const GroupInfo = computes.group("group-info", async (target, gid) => {
const [{ buildPlans }] = await target.need(FontBuildingParameters);
return buildPlans[gid];
});
const GroupFontsOf = computes.group("group-fonts-of", async (target, gid) => {
const [plan] = await target.need(GroupInfo(gid));
return plan.targets;
});
const CollectionPartsOf = computes.group("collection-parts-of", async (target, id) => {
const [{ composition }] = await target.need(CollectPlans);
return composition[id];
});
///////////////////////////////////////////////////////////
////// Font Building //////
///////////////////////////////////////////////////////////
const BuildTTF = files(`${BUILD}/*/*.ttf`, async (target, path) => {
const [, suffix] = path.$;
const [{ hives, family, menuWeight, menuStyle }, version] = await target.need(
HivesOf(suffix),
Version
);
const otd = path.dir + "/" + path.name + ".otd";
const charmap = path.dir + "/" + path.name + ".charmap";
await target.need(Scripts, fu`parameters.toml`, de`${path.dir}`);
await run(
GENERATE,
["-o", otd],
["--charmap", charmap],
["--family", family],
["--ver", version],
["--menu-weight", menuWeight],
["--menu-slant", menuStyle],
hives
);
await run("otfccbuild", otd, "-o", path.full, "-O3", "--keep-average-char-width");
await rm(otd);
});
const BuildCM = files(`${BUILD}/*/*.charmap`, async (target, path) => {
await target.need(BuildTTF(path.dir + "/" + path.name + ".ttf"));
});
///////////////////////////////////////////////////////////
////// Font Distribution //////
///////////////////////////////////////////////////////////
// Per group file
const DistUnhintedTTF = files(`${DIST}/*/ttf-unhinted/*.ttf`, async (target, path) => {
const [gr, f] = path.$;
const [from] = await target.need(BuildTTF`${BUILD}/${gr}/${f}.ttf`, de`${path.dir}`);
await cp(from.full, path.full);
});
const DistHintedTTF = files(`${DIST}/*/ttf/*.ttf`, async (target, path) => {
const [gr, f] = path.$;
const [from] = await target.need(BuildTTF`${BUILD}/${gr}/${f}.ttf`, de`${path.dir}`);
await run("ttfautohint", from.full, path.full);
});
const DistWoff = files(`${DIST}/*/woff/*.woff`, async (target, path) => {
const [group, f] = path.$;
const [from] = await target.need(DistHintedTTF`${DIST}/${group}/ttf/${f}.ttf`, de`${path.dir}`);
await node(`utility/ttf-to-woff.js`, from.full, path.full);
});
const DistWoff2 = files(`${DIST}/*/woff2/*.woff2`, async (target, path) => {
const [group, f] = path.$;
const [from] = await target.need(DistHintedTTF`${DIST}/${group}/ttf/${f}.ttf`, de`${path.dir}`);
await node(`utility/ttf-to-woff2.js`, from.full, path.full);
});
// TTC
const DistTTC = files(`${DIST}/collections/*/*.ttc`, async (target, { full, dir, $: [, f] }) => {
const [parts] = await target.need(CollectionPartsOf(f));
await target.need(de`${dir}`);
const [ttfs] = await target.need(
parts.map(part => DistHintedTTF`${DIST}/${part.dir}/ttf/${part.file}.ttf`)
);
await run(`otfcc-ttcize`, ttfs.map(p => p.full), "-o", full);
});
// Group-level
const GroupTTFs = tasks.group("ttf", async (target, gid) => {
const [ts] = await target.need(GroupFontsOf(gid));
await target.need(ts.map(tn => DistHintedTTF`${DIST}/${gid}/ttf/${tn}.ttf`));
});
const GroupUnhintedTTFs = tasks.group("ttf-unhinted", async (target, gid) => {
const [ts] = await target.need(GroupFontsOf(gid));
await target.need(ts.map(tn => DistUnhintedTTF`${DIST}/${gid}/ttf-unhinted/${tn}.ttf`));
});
const GroupWoffs = tasks.group("woff", async (target, gid) => {
const [ts] = await target.need(GroupFontsOf(gid));
await target.need(ts.map(tn => DistWoff`${DIST}/${gid}/woff/${tn}.woff`));
});
const GroupWoff2s = tasks.group("woff2", async (target, gid) => {
const [ts] = await target.need(GroupFontsOf(gid));
await target.need(ts.map(tn => DistWoff2`${DIST}/${gid}/woff2/${tn}.woff2`));
});
const GroupFonts = tasks.group("fonts", async (target, gid) => {
await target.need(GroupTTFs(gid), GroupUnhintedTTFs(gid), GroupWoffs(gid), GroupWoff2s(gid));
});
// Charmap (for specimen)
const DistCharMaps = files(
`${DIST}/*/*.charmap`,
async (target, { full, dir, $: [gid, suffix] }) => {
const [src] = await target.need(BuildCM`${BUILD}/${gid}/${suffix}.charmap`, de`${dir}`);
await cp(src.full, full);
}
);
// Webfont CSS
const DistWebFontCSS = files(`${DIST}/*/webfont.css`, async (target, { dir, $: [gid] }) => {
// Note: this target does NOT depend on the font files.
const [gr, ts] = await target.need(GroupInfo(gid), GroupFontsOf(gid), de(dir));
const hs = await target.need(...ts.map(HivesOf));
await node(
"utility/make-webfont-css.js",
`${DIST}/${gid}/webfont.css`,
gr.family,
hs,
webfontFormats
);
});
const GroupContents = tasks.group("contents", async (target, gid) => {
const [gr] = await target.need(GroupInfo(gid));
await target.need(
GroupFonts(gid),
DistWebFontCSS`${DIST}/${gid}/webfont.css`,
DistCharMaps`${DIST}/${gid}/${gr.prefix}-regular.charmap`
);
return gid;
});
// Archive
const ArchiveFile = files(`${ARCHIVE_DIR}/*-*.zip`, async (target, { dir, full, $: [gid] }) => {
// Note: this target does NOT depend on the font files.
const [exportPlans] = await target.need(ExportPlans, de`${dir}`);
await target.need(GroupContents(exportPlans[gid]));
await cd(`${DIST}/${exportPlans[gid]}`).run(
["7z", "a"],
["-tzip", "-r", "-mx=9"],
`../../${full}`,
`./`
);
});
const GroupArchives = tasks.group(`archive`, async (target, gid) => {
const [version] = await target.need(Version);
await target.need(ArchiveFile`${ARCHIVE_DIR}/${gid}-${version}.zip`);
});
// Collection-level
const CollectionFontsOf = tasks.group("collection-fonts", async (target, cid) => {
const [{ groups }] = await target.need(CollectPlans);
await target.need(groups[cid].map(file => DistTTC`${DIST}/collections/${cid}/${file}.ttc`));
});
const TTCArchiveFile = files(
`${ARCHIVE_DIR}/ttc-*-*.zip`,
async (target, { dir, full, $: [cid] }) => {
// Note: this target does NOT depend on the font files.
await target.need(de`${dir}`);
await target.need(CollectionFontsOf(cid));
await cd(`${DIST}/collections/${cid}`).run(
["7z", "a"],
["-tzip", "-r", "-mx=9"],
`../../../${full}`,
`./`
);
}
);
const CollectionArchive = tasks.group(`collection-archive`, async (target, cid) => {
const [version] = await target.need(Version);
await target.need(TTCArchiveFile`${ARCHIVE_DIR}/ttc-${cid}-${version}.zip`);
});
///////////////////////////////////////////////////////////
////// Root Tasks //////
///////////////////////////////////////////////////////////
const Pages = task(`pages`, async target => {
const [sans, slab] = await target.need(GroupContents`iosevka`, GroupContents`iosevka-slab`);
await cp(`${DIST}/${sans}`, `pages/${sans}`);
await cp(`${DIST}/${slab}`, `pages/${slab}`);
});
const SampleImagesPre = task(`sample-images:pre`, async target => {
const [sans, slab] = await target.need(
GroupContents`iosevka`,
GroupContents`iosevka-slab`,
de`images`
);
await cp(`${DIST}/${sans}`, `snapshot/${sans}`);
await cp(`${DIST}/${slab}`, `snapshot/${slab}`);
});
const SnapShotCSS = file(`snapshot/index.css`, async target => {
await target.need(fu`snapshot/index.styl`);
await cd(`snapshot`).run(`stylus`, `index.styl`, `-c`);
});
const TakeSampleImages = task(`sample-images:take`, async target => {
await target.need(SampleImagesPre, SnapShotCSS);
await cd(`snapshot`).run("npx", "electron", "get-snap.js", ["--dir", "../images"]);
});
const ScreenShot = files(`images/*.png`, async (target, { full }) => {
await target.need(TakeSampleImages);
await run("optipng", full);
});
const SampleImages = task(`sample-images`, async target => {
await target.need(TakeSampleImages);
await target.need(
ScreenShot`images/charvars.png`,
ScreenShot`images/download-options.png`,
ScreenShot`images/family.png`,
ScreenShot`images/languages.png`,
ScreenShot`images/ligations.png`,
ScreenShot`images/matrix.png`,
ScreenShot`images/preview-all.png`,
ScreenShot`images/stylesets.png`,
ScreenShot`images/variants.png`,
ScreenShot`images/weights.png`
);
});
const AllArchives = task(`all:archives`, async target => {
const [exportPlans, collectPlans] = await target.need(ExportPlans, CollectPlans);
await target.need(
Object.keys(exportPlans).map(GroupArchives),
Object.keys(collectPlans.groups).map(CollectionArchive)
);
});
phony(`clean`, async () => {
await rm(`build`);
await rm(`dist`);
await rm(`release-archives`);
build.deleteJournal(); // Disable journal
});
phony(`release`, async target => {
await target.need(AllArchives);
await target.need(SampleImages, Pages);
});
///////////////////////////////////////////////////////////
////// Script Building //////
///////////////////////////////////////////////////////////
const MARCOS = [fu`meta/macros.ptl`];
const ScriptsUnder = oracles("{ptl|js}-scripts-under::***", (target, $ext, $1) =>
FileList({ under: $1, pattern: `**/*.${$ext}` })(target)
);
const ScriptFiles = computes.group("script-files", async (target, ext) => {
const [gen, meta, glyphs, support] = await target.need(
ScriptsUnder`${ext}-scripts-under::gen`,
ScriptsUnder`${ext}-scripts-under::meta`,
ScriptsUnder`${ext}-scripts-under::glyphs`,
ScriptsUnder`${ext}-scripts-under::support`
);
return [...gen, ...meta, ...glyphs, ...support];
});
const JavaScriptFromPtl = computed("scripts-js-from-ptl", async target => {
const [ptl] = await target.need(ScriptFiles`ptl`);
return ptl.map(x => x.replace(/\.ptl$/g, ".js"));
});
const ScriptJS = files(`{gen|glyphs|support|meta}/**/*.js`, async (target, path) => {
const [jsFromPtl] = await target.need(JavaScriptFromPtl);
if (jsFromPtl.indexOf(path.full) >= 0) {
const ptl = path.full.replace(/\.js$/g, ".ptl");
if (/^glyphs\//.test(path.full)) {
await target.need(MARCOS);
}
await target.need(fu`${ptl}`);
await run(PATEL_C, "--strict", ptl, "-o", path.full);
} else {
await target.need(fu`${path.full}`);
}
});
const Scripts = task("scripts", async target => {
const [jsFromPtl] = await target.need(JavaScriptFromPtl);
await target.need(jsFromPtl);
const [js] = await target.need(ScriptFiles`js`);
await target.need(js.map(ScriptJS));
await target.need(fu`parameters.toml`, fu`variants.toml`, fu`emptyfont.toml`);
});