This repository has been archived by the owner on Jul 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathverdafile.js
258 lines (240 loc) · 7.9 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
"use strict";
const os = require("os");
const fs = require("fs-extra");
const build = require("verda").create();
const { task, file, oracle } = build.ruleTypes;
const { de, fu } = build.rules;
const { run, rm, cd, cp, node } = build.actions;
const BUILD = `.build`;
const SRC = `src`;
const OUT = `out`;
const HINT_CONFIG = `hint-config`;
const NODEJS = `node`;
const OTF2OTC = `otf2otc`;
const OTC2OTF = `otc2otf`;
const OTF2TTF = `otf2ttf`;
const TTFAUTOHINT = `ttfautohint`;
const SEVEN_ZIP = `7z`;
build.setJournal(`build/.verda-build-journal`);
build.setSelfTracking();
module.exports = build;
///////////////////////////////////////////////////////////////////////////////////////////////////
// Pass 1
const PASS1 = `${BUILD}/pass1`;
const BreakTtc = task.make(
(weight) => `break-ttc::${weight}`,
async ($, weight) => {
const [config] = await $.need(Config, Dependencies, de(PASS1), fu`renaming/index.js`);
await run(OTC2OTF, `${SRC}/${config.sourcePrefix}-${weight}.ttc`);
for (const suffix of config.allRegions) {
const sourcePartName = `${SourceFontFileName(config, suffix, weight)}.otf`;
const partName = `${FontFileName(config, suffix, weight)}.otf`;
if (await fs.pathExists(`${SRC}/${sourcePartName}`)) {
await rm(`${PASS1}/${partName}`);
await node(`renaming/index.js`, {
from: `${SRC}/${sourcePartName}`,
to: `${PASS1}/${partName}`,
region: suffix,
weight,
config,
});
await rm(`${SRC}/${sourcePartName}`);
}
}
}
);
const Pass1Otf = file.make(
(init, weight) => `${PASS1}/${init}-${weight}.otf`,
async ($, output, init, weight) => {
await $.need(BreakTtc(weight));
}
);
const Pass1Ttf = file.make(
(init, weight) => `${PASS1}/${init}-${weight}.ttf`,
async ($, output, init, weight) => {
const [input] = await $.need(Pass1Otf(init, weight));
await run(OTF2TTF, "-o", output.full, input.full);
}
);
function SourceFontFileName(config, suffix, weight) {
return `${config.sourcePrefix}${suffix}-${weight}`;
}
function FontFileName(config, suffix, weight) {
return `${config.prefix}${suffix}-${weight}`;
}
function GroupFileNamesT(config, weight, fn) {
const results = [];
for (const suffix of config.regions) {
results.push(fn(`${config.prefix}${suffix}`, `${weight}`));
}
return results;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// Pass 2
const PASS2 = `${BUILD}/pass2`;
const Pass2Ttc = file.make(
(init, weight) => `${PASS2}/${init}-${weight}.ttc`,
async ($, output, init, weight) => {
const [config] = await $.need(Config, de(PASS2));
const ttfTasks = GroupFileNamesT(config, weight, Pass1Ttf);
const [input] = await $.need(ttfTasks);
const tempTtc = `${output.dir}/${output.name}.temp.ttc`;
await run(
OTF2OTC,
[`-o`, tempTtc],
input.map((x) => x.full)
);
await run(TTFAUTOHINT, tempTtc, output.full);
await rm(tempTtc);
await run(OTC2OTF, output.full);
}
);
const Pass2Ttf = file.make(
(init, weight) => `${PASS2}/${init}-${weight}.ttf`,
async ($, output, init, weight) => {
const [config] = await $.need(Config, de(PASS2));
await $.need(Pass2Ttc(config.prefix, weight));
}
);
///////////////////////////////////////////////////////////////////////////////////////////////////
// Pass 3
const PASS3 = `${BUILD}/pass3`;
const Chlorophytum = [
NODEJS,
`--experimental-worker`,
`--max-old-space-size=8192`,
`./node_modules/@chlorophytum/cli/lib/index.js`,
];
const Pass3Ttf = file.make(
(init, weight) => `${PASS3}/${init}-${weight}.ttf`,
async ($, output, init, weight) => {
await $.need(de(PASS3));
const [input] = await $.need(Pass2Ttf(init, weight));
await cp(input.full, output.full);
}
);
const GroupHint = task.make(
(weight) => `group-hint::${weight}`,
async ($, weight) => {
const [config, jHint, hintConfig] = await $.need(
Config,
JHint,
fu(`${HINT_CONFIG}/${weight}.json`),
de(PASS3)
);
const otdTasks = GroupFileNamesT(config, weight, Pass3Ttf);
const [inputs] = await $.need(otdTasks);
await run(
Chlorophytum,
`hint`,
[`-c`, hintConfig.full],
[`-h`, `${PASS3}/hint-cache-${weight}.gz`],
[`--jobs`, jHint],
[...HintParams(inputs)]
);
}
);
const HintAll = task(`hint-all`, async ($) => {
const [config] = await $.need(Config);
for (const weight of config.weights) {
await $.need(GroupHint(weight));
}
});
const GroupInstr = task.make(
(weight) => `group-instr::${weight}`,
async ($, weight) => {
const [config, hintParam] = await $.need(Config, fu(`${HINT_CONFIG}/${weight}.json`));
const otdTasks = GroupFileNamesT(config, weight, Pass3Ttf);
const [inputs] = await $.need(otdTasks);
await $.need(HintAll);
//await $.need(GroupHint`group-hint::${weight}`);
await run(Chlorophytum, `instruct`, [`-c`, hintParam.full], [...InstrParams(inputs)]);
}
);
const OutTtf = `${OUT}/ttf`;
const Pass3TtfOut = file.make(
(init, weight) => `${OutTtf}/${init}-${weight}.ttf`,
async (t, output, init, weight) => {
await t.need(fu(`${HINT_CONFIG}/${weight}.json`), GroupInstr(weight));
}
);
function* HintParams(fonts) {
for (const ttf of fonts) {
yield ttf.full;
yield `${ttf.dir}/${ttf.name}.hint.gz`;
}
}
function* InstrParams(fonts) {
for (const ttf of fonts) {
yield ttf.full;
yield `${ttf.dir}/${ttf.name}.hint.gz`;
yield `${OutTtf}/${ttf.name}.ttf`;
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// Pass 4
const OutTtc = `${OUT}/ttc`;
const TTCIZE = ["node", "node_modules/otb-ttc-bundle/bin/otb-ttc-bundle"];
const Pass4Group = file.make(
(init, weight) => `${OutTtc}/${init}-${weight}.ttc`,
async ($, output, init, weight) => {
const [config] = await $.need(Config, de`${OUT}/ttc`);
const [parts] = await $.need(GroupFileNamesT(config, weight, Pass3TtfOut));
await run(TTCIZE, "-x", ["-o", output.full], [...parts.map((t) => t.full)]);
}
);
const All = task(`all`, async ($) => {
const [config] = await $.need(Config);
await $.need(config.weights.map((w) => Pass4Group(config.prefix, w)));
});
const TTCArchive = file.make(
(version) => `${OUT}/release-ttc-${version}.7z`,
async (t, target) => {
await t.need(All, de`${OUT}/ttc`);
await rm(target.full);
await cd(`${OUT}/ttc`).run(
[SEVEN_ZIP, `a`],
[`-t7z`, `-mmt=on`, `-m0=LZMA:a=0:d=1536m:fb=256`],
[`../${target.name}.7z`, `*.ttc`]
);
}
);
const TTFArchive = file.make(
(version) => `${OUT}/release-ttf-${version}.7z`,
async (t, target) => {
const [config] = await t.need(Config, de`${OUT}/ttf`);
await t.need(All);
await rm(target.full);
for (const weight of config.weights) {
await cd(`${OUT}/ttf`).run(
[SEVEN_ZIP, `a`],
[`-t7z`, `-mmt=on`, `-m0=LZMA:a=0:d=1536m:fb=256`],
[`../${target.name}.7z`, `*-${weight}.ttf`]
);
}
}
);
const _Release = task(`release`, async ($) => {
const version = await $.need(Version);
await $.need(TTFArchive(version), TTCArchive(version));
});
///////////////////////////////////////////////////////////////////////////////////////////////////
// Configuration, directories
const Config = oracle("config", async () => {
return await fs.readJSON(__dirname + "/config.json");
});
const Version = oracle("oracles::version", async () => {
const pkg = await fs.readJSON(__dirname + "/package.json");
return pkg.version;
});
const Dependencies = oracle("oracles::dependencies", async () => {
const pkg = await fs.readJSON(__dirname + "/package.json");
const depJson = {};
for (const pkgName in pkg.dependencies) {
const depPkg = await fs.readJSON(__dirname + "/node_modules/" + pkgName + "/package.json");
const depVer = depPkg.version;
depJson[pkgName] = depVer;
}
return { requirements: pkg.dependencies, actual: depJson };
});
const JHint = oracle("hinting-jobs", async () => os.cpus().length);