Snapshot: add parallelism
This commit is contained in:
parent
933725bbaf
commit
db2ea4242b
4 changed files with 190 additions and 131 deletions
|
@ -1,9 +1,11 @@
|
|||
"use strict";
|
||||
|
||||
const { app, BrowserWindow } = require("electron");
|
||||
let argDir = process.argv[2];
|
||||
let fs = require("fs");
|
||||
let cp = require("child_process");
|
||||
const fs = require("fs");
|
||||
const cp = require("child_process");
|
||||
|
||||
const argDir = process.argv[2];
|
||||
const taskFile = process.argv[3];
|
||||
|
||||
let mainWindow = null;
|
||||
let allWindowClosed = false;
|
||||
|
@ -43,6 +45,13 @@ const phases = {
|
|||
prepare: function (event, arg) {
|
||||
console.log(arg);
|
||||
GOTO(phases["receive-rect"]);
|
||||
|
||||
const tasks = JSON.parse(fs.readFileSync(taskFile));
|
||||
event.sender.send("start", tasks);
|
||||
},
|
||||
"wait-screenshot": function (event, arg) {
|
||||
console.log(arg);
|
||||
GOTO(phases["receive-rect"]);
|
||||
},
|
||||
"receive-rect": function (event, rect) {
|
||||
pendingTasks += 1;
|
||||
|
|
|
@ -3,9 +3,36 @@
|
|||
"use strict";
|
||||
|
||||
const ipc = require("electron").ipcRenderer;
|
||||
const packagingTasks = require("./packaging-tasks.json");
|
||||
const auxData = require("./index.data.json");
|
||||
|
||||
ipc.on("start", function (event, snapshotTasksRaw) {
|
||||
let snapshotTasks = [];
|
||||
for (const task of snapshotTasksRaw) {
|
||||
for (const theme of ["dark", "light"]) {
|
||||
for (const bg of ["black", "white"]) {
|
||||
snapshotTasks.push({
|
||||
...task,
|
||||
theme,
|
||||
background: bg,
|
||||
name: task.name + "." + theme + "." + bg
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
let current = 0;
|
||||
const step = function () {
|
||||
const doit = function () {
|
||||
captureElement(snapshotTasks[current], function () {
|
||||
current += 1;
|
||||
if (current >= snapshotTasks.length) window.close();
|
||||
else setTimeout(step, 100);
|
||||
});
|
||||
};
|
||||
setTimeout(doit, 100);
|
||||
};
|
||||
setTimeout(step, 2000);
|
||||
});
|
||||
|
||||
let onScroll = function () {};
|
||||
ipc.on("scroll", function () {
|
||||
onScroll.apply(this, arguments);
|
||||
|
@ -13,6 +40,7 @@ ipc.on("scroll", function () {
|
|||
ipc.send("snapshot", "scroll-done");
|
||||
}, 100);
|
||||
});
|
||||
|
||||
let onComplete = function () {};
|
||||
ipc.on("complete", function () {
|
||||
onComplete.apply(this, arguments);
|
||||
|
@ -153,32 +181,5 @@ function captureElement(options, callback) {
|
|||
}
|
||||
|
||||
window.onload = function () {
|
||||
const snapshotTasksRaw = [...auxData.readmeSnapshotTasks, ...packagingTasks];
|
||||
let snapshotTasks = [];
|
||||
for (const task of snapshotTasksRaw) {
|
||||
for (const theme of ["dark", "light"]) {
|
||||
for (const bg of ["black", "white"]) {
|
||||
snapshotTasks.push({
|
||||
...task,
|
||||
theme,
|
||||
background: bg,
|
||||
name: task.name + "." + theme + "." + bg
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
let current = 0;
|
||||
const step = function () {
|
||||
const doit = function () {
|
||||
captureElement(snapshotTasks[current], function () {
|
||||
current += 1;
|
||||
if (current >= snapshotTasks.length) window.close();
|
||||
else setTimeout(step, 100);
|
||||
});
|
||||
};
|
||||
setTimeout(doit, 100);
|
||||
};
|
||||
ipc.send("snapshot", "i am ready");
|
||||
console.log("I AM READY");
|
||||
setTimeout(step, 2000);
|
||||
ipc.send("snapshot", "Browser process ready");
|
||||
};
|
||||
|
|
|
@ -27,12 +27,32 @@ module.exports = async function main(argv) {
|
|||
});
|
||||
await fs.writeFile(argv.outputPath, html);
|
||||
|
||||
let readmeSnapshotTasks = [
|
||||
{ el: "#languages", name: "languages" },
|
||||
{ el: "#matrix", name: "matrix" },
|
||||
{ el: "#previews", name: "preview-all" },
|
||||
{ el: "#weights", name: "weights" }
|
||||
];
|
||||
for (let i = 0; i < argv.parallel; i++) {
|
||||
await generateTaskFile(
|
||||
argv.outputTaskFilePrefix,
|
||||
i,
|
||||
argv.parallel,
|
||||
variationData,
|
||||
ligationData
|
||||
);
|
||||
}
|
||||
|
||||
await fs.writeJson(
|
||||
argv.outputDataPath,
|
||||
{ ligationSamples: ligationData.samples, ligationCherry: ligationData.cherry },
|
||||
{ spaces: " " }
|
||||
);
|
||||
};
|
||||
|
||||
async function generateTaskFile(prefix, ith, total, variationData, ligationData) {
|
||||
let readmeSnapshotTasks = [];
|
||||
{
|
||||
readmeSnapshotTasks.push({ el: "#languages", name: "languages" });
|
||||
readmeSnapshotTasks.push({ el: "#matrix", name: "matrix" });
|
||||
readmeSnapshotTasks.push({ el: "#previews", name: "preview-all" });
|
||||
readmeSnapshotTasks.push({ el: "#weights", name: "weights" });
|
||||
}
|
||||
{
|
||||
for (const ls of ligationData.nonMergeSets) {
|
||||
readmeSnapshotTasks.push({
|
||||
el: "#ligation-sampler",
|
||||
|
@ -43,6 +63,8 @@ module.exports = async function main(argv) {
|
|||
applyCallbackArgs: ls
|
||||
});
|
||||
}
|
||||
}
|
||||
{
|
||||
for (const ss of variationData.composites) {
|
||||
readmeSnapshotTasks.push({
|
||||
el: "#packaging-sampler",
|
||||
|
@ -61,6 +83,8 @@ module.exports = async function main(argv) {
|
|||
applyCallbackArgs: { hotChars: ss.hotChars.sans.italic }
|
||||
});
|
||||
}
|
||||
}
|
||||
{
|
||||
readmeSnapshotTasks.push({
|
||||
el: "#cv-sampler",
|
||||
applyClass: "cv-sampler",
|
||||
|
@ -89,7 +113,10 @@ module.exports = async function main(argv) {
|
|||
applyFeature: "'APLF' on",
|
||||
name: "character-variant-APLF-on",
|
||||
applyCallback: `cbAmendCharacterVariantContents`,
|
||||
applyCallbackArgs: { hotChars: ["∆", "∇", "○", "←", "→", "↑", "↓"], slopeDependent: false }
|
||||
applyCallbackArgs: {
|
||||
hotChars: ["∆", "∇", "○", "←", "→", "↑", "↓"],
|
||||
slopeDependent: false
|
||||
}
|
||||
});
|
||||
readmeSnapshotTasks.push({
|
||||
el: "#cv-sampler",
|
||||
|
@ -97,7 +124,10 @@ module.exports = async function main(argv) {
|
|||
applyFeature: "'APLF' off",
|
||||
name: "character-variant-APLF-off",
|
||||
applyCallback: `cbAmendCharacterVariantContents`,
|
||||
applyCallbackArgs: { hotChars: ["∆", "∇", "○", "←", "→", "↑", "↓"], slopeDependent: false }
|
||||
applyCallbackArgs: {
|
||||
hotChars: ["∆", "∇", "○", "←", "→", "↑", "↓"],
|
||||
slopeDependent: false
|
||||
}
|
||||
});
|
||||
for (const cv of variationData.primes) {
|
||||
if (!cv.tag) continue;
|
||||
|
@ -115,14 +145,11 @@ module.exports = async function main(argv) {
|
|||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await fs.writeJson(
|
||||
argv.outputDataPath,
|
||||
{
|
||||
readmeSnapshotTasks,
|
||||
ligationSamples: ligationData.samples,
|
||||
ligationCherry: ligationData.cherry
|
||||
},
|
||||
{ spaces: " " }
|
||||
);
|
||||
};
|
||||
let filteredTasks = [];
|
||||
for (let i = 0; i < readmeSnapshotTasks.length; i++) {
|
||||
if (i % total === ith) filteredTasks.push(readmeSnapshotTasks[i]);
|
||||
}
|
||||
await fs.writeJson(prefix + "-" + ith + ".json", filteredTasks);
|
||||
}
|
||||
|
|
36
verdafile.js
36
verdafile.js
|
@ -639,14 +639,17 @@ const PagesFastFontExport = task.group(`pages:fast-font-export`, async (target,
|
|||
///////////////////////////////////////////////////////////
|
||||
// Sample Images
|
||||
|
||||
const SnapshotParallel = 8;
|
||||
const SampleImages = task(`sample-images`, async target => {
|
||||
const [cfgP, sh] = await target.need(PackageSnapshotConfig, SnapShotHtml, TakeSampleImages);
|
||||
const de = JSON.parse(fs.readFileSync(`${sh.dir}/${sh.name}.data.json`));
|
||||
let snapshotFiles = [...cfgP];
|
||||
for (let i = 0; i < SnapshotParallel; i++) {
|
||||
const de = JSON.parse(fs.readFileSync(`${sh.dir}/readme-tasks-${i}.json`));
|
||||
for (const x of de) snapshotFiles.push(x);
|
||||
}
|
||||
await target.need(
|
||||
cfgP.map(opt => ScreenShot(opt.name + ".dark")),
|
||||
cfgP.map(opt => ScreenShot(opt.name + ".light")),
|
||||
de.readmeSnapshotTasks.map(opt => ScreenShot(opt.name + ".dark")),
|
||||
de.readmeSnapshotTasks.map(opt => ScreenShot(opt.name + ".light"))
|
||||
snapshotFiles.map(opt => ScreenShot(opt.name + ".dark")),
|
||||
snapshotFiles.map(opt => ScreenShot(opt.name + ".light"))
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -696,7 +699,9 @@ const SnapShotHtml = file(`${SNAPSHOT_TMP}/index.html`, async (target, out) => {
|
|||
await node(`utility/generate-snapshot-page/index`, {
|
||||
inputPath: "snapshot-src/templates",
|
||||
outputPath: out.full,
|
||||
outputDataPath: `${out.dir}/${out.name}.data.json`
|
||||
outputDataPath: `${out.dir}/${out.name}.data.json`,
|
||||
outputTaskFilePrefix: `${out.dir}/readme-tasks`,
|
||||
parallel: SnapshotParallel
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -736,7 +741,18 @@ const SnapShotCSS = file(`${SNAPSHOT_TMP}/index.css`, async (target, out) => {
|
|||
});
|
||||
const TakeSampleImages = task(`sample-images:take`, async target => {
|
||||
await target.need(SampleImagesPre);
|
||||
await cd(SNAPSHOT_TMP).run("npx", "electron", "get-snap.js", "../../images");
|
||||
|
||||
await run("npm", "install", "--no-save", "electron");
|
||||
|
||||
let taskLists = [`packaging-tasks.json`];
|
||||
for (let i = 0; i < SnapshotParallel; i++) taskLists.push(`readme-tasks-${i}.json`);
|
||||
await Promise.all(
|
||||
taskLists.map((file, i) =>
|
||||
Delay(i * 1000).then(() =>
|
||||
cd(SNAPSHOT_TMP).run("npx", "electron", "get-snap.js", "../../images", file)
|
||||
)
|
||||
)
|
||||
);
|
||||
});
|
||||
const ScreenShot = file.make(
|
||||
img => `images/${img}.png`,
|
||||
|
@ -1065,3 +1081,9 @@ const VlCssFontStretch = {
|
|||
x == "extra-expanded" ||
|
||||
x == "ultra-expanded"
|
||||
};
|
||||
|
||||
// Utilities
|
||||
|
||||
function Delay(t) {
|
||||
return new Promise(resolve => setTimeout(resolve, t));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue