feat(xod-fs): allow some fields in ‘patch.xodp’ files to be optional

This commit is contained in:
Evgeny Kochetkov
2017-07-14 18:00:52 +03:00
parent 6e5dbda8b7
commit 3292324b9b
14 changed files with 139 additions and 7 deletions

View File

@@ -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)
);

View File

@@ -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)
),

View File

@@ -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)
)

View File

@@ -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));

View File

@@ -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": {},

View File

@@ -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": {

View File

@@ -0,0 +1,12 @@
{
"nodes": [
{
"id": "5c03e488-fefd-4f12-gq6a-78d209d9148c",
"type": "xod/core/pot",
"position": {
"x": 292,
"y": 182
}
}
]
}

View File

@@ -0,0 +1,5 @@
{
"name": "utils",
"authors": ["user"],
"version": "0.0.1"
}

View File

@@ -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": {

View File

@@ -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',

View File

@@ -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',

View File

@@ -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) {