a bold block image export script

This commit is contained in:
Loren Norman 2025-07-29 16:11:19 -04:00
parent 552fffaaf6
commit 5b5f9d9c4f
3 changed files with 91 additions and 3 deletions

View file

@ -1,9 +1,14 @@
import { spawn, spawnSync } from 'node:child_process'
import { copyFileSync, cpSync } from 'node:fs'
import { cleanDir, write, totalBytesWritten } from "./export_util.js"
import DefinitionSet from '#src/definitions/definition_set.js'
import { exportTo } from '#src/exporters/index.js'
const toExport = process.argv[2]
const
toExport = process.argv[2],
taskArgs = process.argv.slice(3)
if(!toExport) {
console.error(`Export Error: Missing export name!\nUsage: node export.js [export name]`)
@ -30,8 +35,15 @@ const
},
"docs": async () => {
await exporters.app("docs/blockly")
// allow option to skip image generation
const skipImages = taskArgs.includes("skipImages")
if(!skipImages) {
await exporters.blockImages()
cleanDir("docs/block_images")
cpSync("tmp/block_images/images", "docs/block_images", { recursive: true })
}
await exporters.app("docs/blockly")
cleanDir("docs/blocks")
await exportTo("docs", definitions, exportItem => {
@ -41,6 +53,33 @@ const
// exportItem.blockExamples(block => "blocks/${block.definitionPath}/examples.json")
})
},
"blockImages": async () => {
const destination = "tmp/block_images"
cleanDir(destination)
cleanDir(`${destination}/images`)
// export a special app with no toolbox, all blocks on workspace
await exportTo(destination, definitions, exportItem => {
exportItem.workspaceAllBlocks("workspace.json")
write(`${destination}/toolbox.json`, "null")
exportItem.blocks("blocks.json")
exportItem.script("blockly_app.js")
// TODO: make a DocumentExporter for generating html wrappers
copyFileSync("src/exporters/document_templates/blockly_workspace.template.html", `${destination}/index.html`)
})
// serve it
console.log('Serving workspace for screenshots...')
const viteProcess = spawn("npx", ["vite", "serve", destination])
// extract the screenshots
console.log('Generating screenshots...')
spawnSync("npx", ["cypress", "run", "--config", `downloadsFolder=${destination}/images`])
// kill the server
viteProcess.kill()
}
},
exporterNames = Object.keys(exporters)

View file

@ -8,7 +8,7 @@ export const
if(fs.existsSync(dirName)) {
fs.rmSync(dirName, { recursive: true, force: true })
}
fs.mkdirSync(dirName)
fs.mkdirSync(dirName, { recursive: true, force: true })
console.log(`/${dirName}: clean`)
},

View file

@ -0,0 +1,49 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Blockly: All Blocks</title>
<script type="module">
import { inject } from './blockly_app.js'
import { imageExportRegistryItems } from '#src/image_exporter.js'
inject("blocklyDiv", {
contextMenu: {
register: [ ...imageExportRegistryItems ]
},
extensionData: {
feedOptions: [
["Feeder 1", "abc123"],
["A Feed Z", "qrstuv"],
["Feedinsky &", "oneforyou-oneforme"],
],
weatherLocationOptions: [
[ "Industry City", "1" ],
[ "Varick", "2" ],
[ "Shenzhen", "3" ],
],
currentWeatherByLocation: {
1: {
current: {
cloudCover: "5.4321",
}
}
}
}
})
</script>
<style>
#blocklyDiv {
width: 100%;
height: 100%;
position: absolute;
}
</style>
</head>
<body>
<div id="blocklyDiv"></div>
</body>
</html>