use new export routine, fix tests

This commit is contained in:
Loren Norman 2025-07-13 17:18:23 -04:00
parent e8792e195c
commit 763a94b4db
3 changed files with 36 additions and 13 deletions

View file

@ -62,6 +62,12 @@ export class DefinitionSet {
writeFileSync(`${this.exportDirectory}/${filename}`, JSON.stringify(blocklyObject))
}
exportBlockTrunk(blockType) {
const blockDefinition = this.findBlock({ type: blockType })
return blockDefinition.toBlocklyInstanceJSON()
}
exportBlocks(givenOptions = {}) {
const
options = {
@ -83,11 +89,13 @@ export class DefinitionSet {
}
async export(options = {}) {
const destination = options.to || this.exportDirectory
writeFileSync(`${destination}/workspace.json`, this.workspaces[0].toBlocklyJSONString())
writeFileSync(`${destination}/toolbox.json`, this.toolboxes[0].toBlocklyJSONString())
writeFileSync(`${destination}/blocks.json`, BlockDefinition.allToBlocklyJSONString(this.blocks))
writeFileSync(`${destination}/blockly_app.js`, await BlocklyJSExporter.exportFor({
if(options.to) {
this.exportDirectory = options.to
}
writeFileSync(`${this.exportDirectory}/workspace.json`, this.workspaces[0].toBlocklyJSONString())
writeFileSync(`${this.exportDirectory}/toolbox.json`, this.toolboxes[0].toBlocklyJSONString())
this.exportBlocks({ toFile: true })
writeFileSync(`${this.exportDirectory}/blockly_app.js`, await BlocklyJSExporter.exportFor({
blocks: this.blocks,
toolbox: this.toolboxes[0],
workspace: this.workspaces[0],

View file

@ -1,4 +1,14 @@
export default {
type: "sentence",
name: "Sentence"
name: "Sentence",
inputs: {
SUBJECT: {
shadow: 'subject'
},
PREDICATE: {
shadow: 'predicate'
}
}
}

View file

@ -71,11 +71,16 @@ describe("Exporting Blockly Files", () => {
// - fields defaulted
// - unremovable shadows attached to inputs
// - optional sub-blocks, as warranted
it("export the special 'trunk' form of a block", () => {
defSet.exportBlockTrunk("sentence") // returns the trunk form of the sentence block
it("export the special 'trunk' form of a block", { only:true }, () => {
const trunkObject = defSet.exportBlockTrunk("sentence") // returns the trunk form of the sentence block
assert.exists(trunkObject)
assert.hasAllKeys(trunkObject, ["type", "inputs"])
assert.hasAllKeys(trunkObject.inputs, ["SUBJECT", "PREDICATE"])
assert.hasAllKeys(trunkObject.inputs.SUBJECT, ["shadow"])
assert.hasAllKeys(trunkObject.inputs.PREDICATE, ["shadow"])
})
it("export other block trees by name", () => {
it("export other block trees by name", { skip: true }, () => {
const defSet = {}
defSet.exportBlockTree("sentence", "simple") // exports the sentence block tree identified as "simple"
defSet.exportBlockTree("sentence", "complex") // exports the sentence block tree identified as "complex"
@ -91,7 +96,7 @@ describe("Exporting Blockly Files", () => {
describe("exporting regenerators")
describe("exporting all scripts: blockly_app.js")
describe("exporting Toolboxes", () => {
describe("exporting Toolboxes", { skip: true }, () => {
it("export a Toolbox category Blockly object", () => {
const defSet = {}
// the "Sentence Parts" category of the "main" toolbox
@ -107,7 +112,7 @@ describe("Exporting Blockly Files", () => {
})
})
describe("exporting a Workspaces", () => {
describe("exporting a Workspaces", { skip: true }, () => {
it("export a Workspace Blockly object", () => {
const defSet = {}
// the entire "main" workspace
@ -117,7 +122,7 @@ describe("Exporting Blockly Files", () => {
})
})
describe("exporting a standalone Blockly app", () => {
describe("exporting a standalone Blockly app", { skip: true }, () => {
it("exports all 4 files correctly", () => {
const defSet = {}
const config = {}
@ -131,7 +136,7 @@ describe("Exporting Blockly Files", () => {
})
})
describe("exporting a documentation site for a Blockly app", () => {
describe("exporting a documentation site for a Blockly app", { skip: true }, () => {
it("exports tiny Blockly apps for each block definition", () => {
const defSet = {}
const config = {}