mirror of
https://github.com/xodio/xod.git
synced 2026-03-18 14:46:52 +01:00
feat(xod-fs): allow some fields in ‘patch.xodp’ files to be optional
This commit is contained in:
@@ -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)
|
||||
);
|
||||
|
||||
@@ -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)
|
||||
),
|
||||
|
||||
@@ -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)
|
||||
)
|
||||
|
||||
@@ -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));
|
||||
|
||||
28
packages/xod-fs/test/fixtures/libs.json
vendored
28
packages/xod-fs/test/fixtures/libs.json
vendored
@@ -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": {},
|
||||
|
||||
11
packages/xod-fs/test/fixtures/unpacked.json
vendored
11
packages/xod-fs/test/fixtures/unpacked.json
vendored
@@ -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": {
|
||||
|
||||
1
packages/xod-fs/test/fixtures/workspace/awesome-project/empty-local-patch/patch.xodp
vendored
Normal file
1
packages/xod-fs/test/fixtures/workspace/awesome-project/empty-local-patch/patch.xodp
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{}
|
||||
@@ -0,0 +1 @@
|
||||
{}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"nodes": [
|
||||
{
|
||||
"id": "5c03e488-fefd-4f12-gq6a-78d209d9148c",
|
||||
"type": "xod/core/pot",
|
||||
"position": {
|
||||
"x": 292,
|
||||
"y": 182
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
5
packages/xod-fs/test/fixtures/workspace/lib/user/with-omitted-optionals/project.xod
vendored
Normal file
5
packages/xod-fs/test/fixtures/workspace/lib/user/with-omitted-optionals/project.xod
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "utils",
|
||||
"authors": ["user"],
|
||||
"version": "0.0.1"
|
||||
}
|
||||
36
packages/xod-fs/test/fixtures/xodball.json
vendored
36
packages/xod-fs/test/fixtures/xodball.json
vendored
@@ -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": {
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user