export workspace containing all blocks
This commit is contained in:
parent
e3dcab44e5
commit
6949620141
2 changed files with 52 additions and 0 deletions
|
|
@ -2,6 +2,7 @@ import BlockExporter from "./block_exporter.js"
|
||||||
import ToolboxExporter from "./toolbox_exporter.js"
|
import ToolboxExporter from "./toolbox_exporter.js"
|
||||||
import WorkspaceExporter from "./workspace_exporter.js"
|
import WorkspaceExporter from "./workspace_exporter.js"
|
||||||
import ScriptExporter from "./script_exporter.js"
|
import ScriptExporter from "./script_exporter.js"
|
||||||
|
import WorkspaceAllBlocksExporter from "./workspace_all_blocks_exporter.js"
|
||||||
import SidebarExporter from "./sidebar_exporter.js"
|
import SidebarExporter from "./sidebar_exporter.js"
|
||||||
import BlockIndexExporter from "./block_index_exporter.js"
|
import BlockIndexExporter from "./block_index_exporter.js"
|
||||||
import BlockPageExporter from "./block_page_exporter.js"
|
import BlockPageExporter from "./block_page_exporter.js"
|
||||||
|
|
@ -24,6 +25,7 @@ export const exportTo = async (destination, definitions, exportFunc) => {
|
||||||
blocks: new BlockExporter(definitions, destination).exportToFile,
|
blocks: new BlockExporter(definitions, destination).exportToFile,
|
||||||
script: new ScriptExporter(definitions, destination).exportToFile,
|
script: new ScriptExporter(definitions, destination).exportToFile,
|
||||||
// docs exporters
|
// docs exporters
|
||||||
|
workspaceAllBlocks: new WorkspaceAllBlocksExporter(definitions, destination).exportToFile,
|
||||||
sidebar: new SidebarExporter(definitions, destination).exportToFile,
|
sidebar: new SidebarExporter(definitions, destination).exportToFile,
|
||||||
blockIndex: new BlockIndexExporter(definitions, destination).exportToFile,
|
blockIndex: new BlockIndexExporter(definitions, destination).exportToFile,
|
||||||
blockPages: new BlockPageExporter(definitions, destination).exportToFile,
|
blockPages: new BlockPageExporter(definitions, destination).exportToFile,
|
||||||
|
|
|
||||||
50
src/exporters/workspace_all_blocks_exporter.js
Normal file
50
src/exporters/workspace_all_blocks_exporter.js
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
import { writeFileSync } from 'fs'
|
||||||
|
import { isString, invokeMap } from 'lodash-es'
|
||||||
|
|
||||||
|
|
||||||
|
export default class WorkspaceExporter {
|
||||||
|
definitionSet = null
|
||||||
|
destination = null
|
||||||
|
|
||||||
|
constructor(definitionSet, destination) {
|
||||||
|
this.definitionSet = definitionSet
|
||||||
|
this.destination = destination
|
||||||
|
}
|
||||||
|
|
||||||
|
export(givenOptions = {}) {
|
||||||
|
const
|
||||||
|
options = {
|
||||||
|
toFile: false,
|
||||||
|
...givenOptions
|
||||||
|
},
|
||||||
|
allBlocks = invokeMap(this.definitionSet.blocks, "toBlocklyInstanceJSON"),
|
||||||
|
workspaceObject = {
|
||||||
|
blocks: {
|
||||||
|
languageVersion: 0,
|
||||||
|
blocks: allBlocks.map((block, index) => ({
|
||||||
|
...block,
|
||||||
|
x: 50,
|
||||||
|
y: 50*index
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!options.toFile) {
|
||||||
|
return workspaceObject
|
||||||
|
}
|
||||||
|
|
||||||
|
const filename = isString(options.toFile)
|
||||||
|
? options.toFile
|
||||||
|
: `workspace_all_blocks.json`
|
||||||
|
|
||||||
|
writeFileSync(`${this.destination}/${filename}`, JSON.stringify(workspaceObject, null, 2))
|
||||||
|
}
|
||||||
|
|
||||||
|
exportToFile = (toFile=true) => {
|
||||||
|
this.export({ toFile })
|
||||||
|
}
|
||||||
|
|
||||||
|
static export() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue