diff --git a/packages/xod-fs/src/convertTypes.js b/packages/xod-fs/src/convertTypes.js index f60b3814..4ebcbb14 100644 --- a/packages/xod-fs/src/convertTypes.js +++ b/packages/xod-fs/src/convertTypes.js @@ -45,3 +45,22 @@ export const convertPatchFileContentsToPatch = def( XP.createPatch )() ); + +const optionalPatchFields = { + nodes: [], + links: [], + description: '', +}; + +const optionalNodeFields = { + boundValues: {}, + label: '', + description: '', +}; + +export const addMissingOptionsToPatchFileContents = R.compose( + R.evolve({ + nodes: R.map(R.merge(optionalNodeFields)), + }), + R.merge(optionalPatchFields) +); diff --git a/packages/xod-fs/src/load.js b/packages/xod-fs/src/load.js index ab7a6caa..eef668ac 100644 --- a/packages/xod-fs/src/load.js +++ b/packages/xod-fs/src/load.js @@ -20,7 +20,10 @@ import { } from './utils'; import { loadAttachments } from './attachments'; import { loadPatchImpls } from './impls'; -import { convertPatchFileContentsToPatch } from './convertTypes'; +import { + convertPatchFileContentsToPatch, + addMissingOptionsToPatchFileContents, +} from './convertTypes'; // ============================================================================= // // Reading of files @@ -83,6 +86,7 @@ const readXodFile = projectPath => xodfile => loadPatchImpls(dir), R.assoc('path', XP.getLocalPath(getPatchName(xodfile))), convertPatchFileContentsToPatch, + addMissingOptionsToPatchFileContents, Promise.resolve.bind(Promise) )(patch) ), diff --git a/packages/xod-fs/src/loadLibs.js b/packages/xod-fs/src/loadLibs.js index 00e92abf..506628c9 100644 --- a/packages/xod-fs/src/loadLibs.js +++ b/packages/xod-fs/src/loadLibs.js @@ -10,7 +10,10 @@ import { } from './utils'; import { loadAttachments } from './attachments'; import { loadPatchImpls } from './impls'; -import { convertPatchFileContentsToPatch } from './convertTypes'; +import { + convertPatchFileContentsToPatch, + addMissingOptionsToPatchFileContents, +} from './convertTypes'; const scanLibsFolder = (libs, libsDir) => Promise.all( libs.map( @@ -39,6 +42,7 @@ const readLibFiles = (libfiles) => { loadPatchImpls(path.dirname(patchPath)), R.assoc('path', `${name}/${getPatchName(patchPath)}`), convertPatchFileContentsToPatch, + addMissingOptionsToPatchFileContents, readJSON )(patchPath) ) diff --git a/packages/xod-fs/test/backup.spec.js b/packages/xod-fs/test/backup.spec.js index b3b1a997..73a137f9 100644 --- a/packages/xod-fs/test/backup.spec.js +++ b/packages/xod-fs/test/backup.spec.js @@ -21,7 +21,7 @@ describe('Backup', () => { backup.make() .then(() => readDir(tempPath)) .then((files) => { - expect(files).to.have.lengthOf(6); + expect(files).to.have.lengthOf(7); done(); }) .catch(err => done(err)); diff --git a/packages/xod-fs/test/fixtures/libs.json b/packages/xod-fs/test/fixtures/libs.json index efbe6117..f4addc01 100644 --- a/packages/xod-fs/test/fixtures/libs.json +++ b/packages/xod-fs/test/fixtures/libs.json @@ -165,6 +165,34 @@ "path": "user/utils/test", "attachments": [] }, + "user/with-omitted-optionals/empty-lib-patch": { + "attachments": [], + "description": "", + "impls": {}, + "links": {}, + "nodes": {}, + "path": "user/with-omitted-optionals/empty-lib-patch" + }, + "user/with-omitted-optionals/optional-node-fields-omitted": { + "attachments": [], + "description": "", + "impls": {}, + "links": {}, + "nodes": { + "5c03e488-fefd-4f12-gq6a-78d209d9148c": { + "boundValues": {}, + "description": "", + "id": "5c03e488-fefd-4f12-gq6a-78d209d9148c", + "label": "", + "position": { + "x": 292, + "y": 182 + }, + "type": "xod/core/pot" + } + }, + "path": "user/with-omitted-optionals/optional-node-fields-omitted" + }, "xod/math/test": { "description": "", "impls": {}, diff --git a/packages/xod-fs/test/fixtures/unpacked.json b/packages/xod-fs/test/fixtures/unpacked.json index 6bba610a..0901a214 100644 --- a/packages/xod-fs/test/fixtures/unpacked.json +++ b/packages/xod-fs/test/fixtures/unpacked.json @@ -1,4 +1,15 @@ [ + { + "path": "./awesome-project/empty-local-patch/patch.xodp", + "content": { + "description": "", + "impls": {}, + "links": {}, + "nodes": {}, + "path": "@/empty-local-patch", + "attachments": [] + } + }, { "path": "./awesome-project/project.xod", "content": { diff --git a/packages/xod-fs/test/fixtures/workspace/awesome-project/empty-local-patch/patch.xodp b/packages/xod-fs/test/fixtures/workspace/awesome-project/empty-local-patch/patch.xodp new file mode 100644 index 00000000..9e26dfee --- /dev/null +++ b/packages/xod-fs/test/fixtures/workspace/awesome-project/empty-local-patch/patch.xodp @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/packages/xod-fs/test/fixtures/workspace/lib/user/with-omitted-optionals/empty-lib-patch/patch.xodp b/packages/xod-fs/test/fixtures/workspace/lib/user/with-omitted-optionals/empty-lib-patch/patch.xodp new file mode 100644 index 00000000..9e26dfee --- /dev/null +++ b/packages/xod-fs/test/fixtures/workspace/lib/user/with-omitted-optionals/empty-lib-patch/patch.xodp @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/packages/xod-fs/test/fixtures/workspace/lib/user/with-omitted-optionals/optional-node-fields-omitted/patch.xodp b/packages/xod-fs/test/fixtures/workspace/lib/user/with-omitted-optionals/optional-node-fields-omitted/patch.xodp new file mode 100644 index 00000000..606b65a0 --- /dev/null +++ b/packages/xod-fs/test/fixtures/workspace/lib/user/with-omitted-optionals/optional-node-fields-omitted/patch.xodp @@ -0,0 +1,12 @@ +{ + "nodes": [ + { + "id": "5c03e488-fefd-4f12-gq6a-78d209d9148c", + "type": "xod/core/pot", + "position": { + "x": 292, + "y": 182 + } + } + ] +} diff --git a/packages/xod-fs/test/fixtures/workspace/lib/user/with-omitted-optionals/project.xod b/packages/xod-fs/test/fixtures/workspace/lib/user/with-omitted-optionals/project.xod new file mode 100644 index 00000000..4d0805b3 --- /dev/null +++ b/packages/xod-fs/test/fixtures/workspace/lib/user/with-omitted-optionals/project.xod @@ -0,0 +1,5 @@ +{ + "name": "utils", + "authors": ["user"], + "version": "0.0.1" +} diff --git a/packages/xod-fs/test/fixtures/xodball.json b/packages/xod-fs/test/fixtures/xodball.json index ce09fbc5..1f2bb55d 100644 --- a/packages/xod-fs/test/fixtures/xodball.json +++ b/packages/xod-fs/test/fixtures/xodball.json @@ -173,6 +173,34 @@ "path": "user/utils/test", "attachments": [] }, + "user/with-omitted-optionals/empty-lib-patch": { + "attachments": [], + "description": "", + "impls": {}, + "links": {}, + "nodes": {}, + "path": "user/with-omitted-optionals/empty-lib-patch" + }, + "user/with-omitted-optionals/optional-node-fields-omitted": { + "attachments": [], + "description": "", + "impls": {}, + "links": {}, + "nodes": { + "5c03e488-fefd-4f12-gq6a-78d209d9148c": { + "boundValues": {}, + "description": "", + "id": "5c03e488-fefd-4f12-gq6a-78d209d9148c", + "label": "", + "position": { + "x": 292, + "y": 182 + }, + "type": "xod/core/pot" + } + }, + "path": "user/with-omitted-optionals/optional-node-fields-omitted" + }, "xod/math/test": { "description": "", "impls": {}, @@ -181,6 +209,14 @@ "path": "xod/math/test", "attachments": [] }, + "@/empty-local-patch": { + "attachments": [], + "description": "", + "impls": {}, + "links": {}, + "nodes": {}, + "path": "@/empty-local-patch" + }, "@/main": { "nodes": { "2c03e470-fefd-4f58-be6a-58d209d9158c": { diff --git a/packages/xod-fs/test/load.spec.js b/packages/xod-fs/test/load.spec.js index be84144d..33dc4373 100644 --- a/packages/xod-fs/test/load.spec.js +++ b/packages/xod-fs/test/load.spec.js @@ -50,7 +50,7 @@ describe('Loader', () => { it('getProjects: return an array of projects in workspace, including libs', () => Loader.getProjects(workspace) .then((projects) => { - expect(projects).to.have.lengthOf(4); + expect(projects).to.have.lengthOf(5); }) ); it('getProjects: reject CANT_ENUMERATE_PROJECTS for non-existent workspace', diff --git a/packages/xod-fs/test/loadLibs.spec.js b/packages/xod-fs/test/loadLibs.spec.js index 130e5321..7d33a5ab 100644 --- a/packages/xod-fs/test/loadLibs.spec.js +++ b/packages/xod-fs/test/loadLibs.spec.js @@ -11,7 +11,15 @@ describe('Library loader', () => { const workspace = path.resolve(__dirname, workspaceDir); it('should load xod/core libs from ./fixtures/workspace/lib', (done) => { - const coreLibsOnly = R.omit(['user/utils/test', 'xod/math/test'], libsFixture); + const coreLibsOnly = R.omit( + [ + 'user/utils/test', + 'user/with-omitted-optionals/empty-lib-patch', + 'user/with-omitted-optionals/optional-node-fields-omitted', + 'xod/math/test', + ], + libsFixture + ); const nodeTypes = Object.assign({}, coreLibsOnly); delete nodeTypes['@/qux']; // lib loader don't know anything about patch nodes! @@ -28,6 +36,8 @@ describe('Library loader', () => { .then((data) => { expect(data).to.have.keys([ 'user/utils/test', + 'user/with-omitted-optionals/empty-lib-patch', + 'user/with-omitted-optionals/optional-node-fields-omitted', 'xod/core/and', 'xod/core/led', 'xod/core/pot', diff --git a/packages/xod-fs/test/save.spec.js b/packages/xod-fs/test/save.spec.js index cc02f961..1a6d87f7 100644 --- a/packages/xod-fs/test/save.spec.js +++ b/packages/xod-fs/test/save.spec.js @@ -53,14 +53,15 @@ describe('saveArrangedFiles', () => { it('should save an extracted project into temp directory', (done) => { const dataToSave = arrangeByFiles(xodball); + const expectedFilesNumber = 7; const onFinish = () => { try { recReadDir(workspacePath, ['.DS_Store', 'Thumbs.db'], (err, files) => { - if (files.length === 6) { + if (files.length === expectedFilesNumber) { done(); } else { - throw new Error('Wrong amount of files (not equal 5). Check .xodball or change amount in the test!'); + throw new Error(`Wrong amount of files (not equal ${expectedFilesNumber}). Check .xodball or change amount in the test!`); } }); } catch (err) {