diff --git a/Dockerfile b/Dockerfile index 2b3afe1..f3c51a9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,12 @@ FROM node COPY . /code-machine RUN mkdir /code +# NODE_ENV for configurations +ENV NODE_ENV HOM + EXPOSE 8000 -CMD ["/bin/sh", "-c", "cd /code-machine && node ."] +# set the working dir to the code machine directory +WORKDIR /code-machine + +CMD ["node", "index.js"] diff --git a/README.md b/README.md index c0412d2..e7b4ef5 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ To run the service from a new container Once the image is on the registry server (and it is accessible), execute: -```docker run -dP /``` +```docker run -dP -v /path/to/front-end-project:/code /``` Running and testing diff --git a/app/controllers/api.js b/app/controllers/api.js index e672dd6..94060cd 100644 --- a/app/controllers/api.js +++ b/app/controllers/api.js @@ -1,3 +1,23 @@ +/** + * The MIT License (MIT) + * Copyright (c) 2015 Fabrica de Aplicativos S/A + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ 'use strict'; var _ = require('lodash'); diff --git a/app/controllers/manipulator.js b/app/controllers/manipulator.js index 797eb25..3fddc5b 100644 --- a/app/controllers/manipulator.js +++ b/app/controllers/manipulator.js @@ -1,7 +1,28 @@ +/** + * The MIT License (MIT) + * Copyright (c) 2015 Fabrica de Aplicativos S/A + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ 'use strict'; var CM = require('../lib/code-manipulator'); var Reply = require('../lib/socket-reply'); var Message = require('carbono-json-messages'); +var PRM = require('../lib/project-resource-manager'); module.exports = function (app) { @@ -110,5 +131,10 @@ module.exports = function (app) { socket.on('disconnect', cm.removeUpdateListener.bind(cm, emitUpdate)); }; + this.registerSocket = function (socket) { + PRM.setSocket(socket); + socket.on('disconnect', PRM.removeSocket.bind(PRM,socket)); + }; + return this; }; diff --git a/app/controllers/resources.js b/app/controllers/resources.js index fd50eba..2c8dca9 100644 --- a/app/controllers/resources.js +++ b/app/controllers/resources.js @@ -1,3 +1,23 @@ +/** + * The MIT License (MIT) + * Copyright (c) 2015 Fabrica de Aplicativos S/A + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ 'use strict'; var createResourcesServer = require('../lib/code-interpreter'); diff --git a/app/lib/code-interpreter/clean.js b/app/lib/code-interpreter/clean.js index d3bd306..75db4a8 100644 --- a/app/lib/code-interpreter/clean.js +++ b/app/lib/code-interpreter/clean.js @@ -1,3 +1,23 @@ +/** + * The MIT License (MIT) + * Copyright (c) 2015 Fabrica de Aplicativos S/A + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ 'use strict'; var express = require('express'); diff --git a/app/lib/code-interpreter/index.js b/app/lib/code-interpreter/index.js index 6186c3f..4484a2c 100644 --- a/app/lib/code-interpreter/index.js +++ b/app/lib/code-interpreter/index.js @@ -1,3 +1,23 @@ +/** + * The MIT License (MIT) + * Copyright (c) 2015 Fabrica de Aplicativos S/A + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ 'use strict'; // External dependencies diff --git a/app/lib/code-interpreter/marked.js b/app/lib/code-interpreter/marked.js index 979d350..7491df8 100644 --- a/app/lib/code-interpreter/marked.js +++ b/app/lib/code-interpreter/marked.js @@ -1,3 +1,23 @@ +/** + * The MIT License (MIT) + * Copyright (c) 2015 Fabrica de Aplicativos S/A + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ 'use strict'; // External dependencies diff --git a/app/lib/code-manipulator/index.js b/app/lib/code-manipulator/index.js index 19d20cf..963c90d 100644 --- a/app/lib/code-manipulator/index.js +++ b/app/lib/code-manipulator/index.js @@ -1,3 +1,23 @@ +/** + * The MIT License (MIT) + * Copyright (c) 2015 Fabrica de Aplicativos S/A + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ 'use strict'; var domFs = require('../dom-wrapper'); var bower = require('bower'); @@ -5,6 +25,7 @@ var Q = require('q'); var _ = require('lodash'); var fs = require('fs'); var path = require('path'); +var projResManager = require('../project-resource-manager'); module.exports = function (options) { @@ -63,27 +84,29 @@ module.exports = function (options) { this.insertElement = function (path, html, components, reply) { // Install components in sequence, so that the installation // does not run into filesystem conflicts. - // + // // TODO: improve this, bower supports multiple component // paralell installation, we must take advantage of that. - // + // // Some documentation on how to run sequence of promise returning // functions. // https://github.com/kriskowal/q#sequences - // http://stackoverflow.com/questions/17757654/how-to-chain-a-variable-number-of-promises-in-q-in-order + // http://stackoverflow.com/questions/17757654/how-to-chain-a-variable\ + // -number-of-promises-in-q-in-order var installationChain; if (components.length > 0) { - // only build up an installation chain if there + // Only build up an installation chain if there // are dependencies to be installed - installationChain = components.reduce(function (previousPromise, component) { + installationChain = components.reduce( + function (previousPromise, component) { return previousPromise.then(function () { - return installAndImport(component) + return installAndImport(component); }); }, installAndImport(components.shift())); } else { - // otherwise, simply make up a promise - installationChain = Q(); + // Otherwise, simply make up a promise + installationChain = new Q(); } installationChain @@ -101,7 +124,8 @@ module.exports = function (options) { this.createEntityFromSchema = function (entityName, schema, reply) { if (schema) { try { - entityManager.createEntity(entityName, schema); + var route = projResManager.getCrudRoute(); + entityManager.createEntity(entityName, route, schema); reply.success(); } catch (e) { reply.error({ diff --git a/app/lib/dom-wrapper/index.js b/app/lib/dom-wrapper/index.js index 679c917..fab3b18 100644 --- a/app/lib/dom-wrapper/index.js +++ b/app/lib/dom-wrapper/index.js @@ -1,3 +1,23 @@ +/** + * The MIT License (MIT) + * Copyright (c) 2015 Fabrica de Aplicativos S/A + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ 'use strict'; var DomFs = require('dom-fs'); diff --git a/app/lib/entity-manager/index.js b/app/lib/entity-manager/index.js index 200f0a6..3e19757 100644 --- a/app/lib/entity-manager/index.js +++ b/app/lib/entity-manager/index.js @@ -1,3 +1,23 @@ +/** + * The MIT License (MIT) + * Copyright (c) 2015 Fabrica de Aplicativos S/A + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ 'use strict'; var path = require('path'); var fs = require('fs'); @@ -13,18 +33,25 @@ module.exports = function (options) { * project's entities.json. * * @param {string} entityName - name of entity to create. + * @param {string} route - route to the CRUDr responsible for this entity. * @param {?Object} schema - entity's schema. */ - var createEntity = function (entityName, schema) { + var createEntity = function (entityName, route, schema) { if (entityName in entities) { throw new Error('Unavailable entity name: ' + entityName); } + if (!route) { + throw new Error('CRUDr route not provided for entity creation'); + } schema = schema || {}; // Maybe we should validate the schema's sanity here? - entities[entityName] = schema; + entities[entityName] = { + route: route, + schema: schema, + }; saveEntities(); }; diff --git a/app/lib/project-resource-manager/index.js b/app/lib/project-resource-manager/index.js new file mode 100644 index 0000000..fb36951 --- /dev/null +++ b/app/lib/project-resource-manager/index.js @@ -0,0 +1,79 @@ +/** + * The MIT License (MIT) + * Copyright (c) 2015 Fabrica de Aplicativos S/A + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ +'use strict'; + +var config = require('config'); +var path = require('path'); +var fs = require('fs'); +var Message = require('carbono-json-messages'); + +var projectDir = path.resolve(config.get('projectDir')); +var resFile = 'project_resources.json'; + +var ProjectResourceManager = function () { + + this.resFilePath = path.join(projectDir, resFile); + this.resIndex = JSON.parse(fs.readFileSync(this.resFilePath)); + + this.socket = null; + + return this; +}; + +ProjectResourceManager.prototype.setSocket = function (socket) { + this.socket = socket; +}; + +ProjectResourceManager.prototype.removeSocket = function (socket) { + if (this.socket === socket) { + this.socket = null; + } +}; + +ProjectResourceManager.prototype.getCrudRoute = function () { + var crudAlias = 'crud-basic'; + if (!(crudAlias in this.resIndex)) { + var crudRoute = '/crud/crud001'; + this.requestMachine(crudAlias, crudRoute); + this.resIndex[crudAlias] = crudRoute; + } + return this.resIndex[crudAlias]; +}; + +ProjectResourceManager.prototype.requestMachine = function (machine, route) { + var msg = new Message({apiVersion: '1.0'}); + var data = { + items: [ + { + component: machine, + route: route, + }, + ], + }; + msg.setData(data); + this.socket.emit('project:createMachine', msg.toJSON()); +}; + +ProjectResourceManager.prototype.saveResourceIndex = function () { + fs.writeFileSync(this.resFilePath, JSON.stringify(this.resIndex, null, 4)); +}; + +module.exports = new ProjectResourceManager(); diff --git a/app/lib/socket-reply/index.js b/app/lib/socket-reply/index.js index 20b8673..90233af 100644 --- a/app/lib/socket-reply/index.js +++ b/app/lib/socket-reply/index.js @@ -1,3 +1,23 @@ +/** + * The MIT License (MIT) + * Copyright (c) 2015 Fabrica de Aplicativos S/A + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ 'use strict'; var Message = require('carbono-json-messages'); @@ -9,11 +29,15 @@ var SocketReply = function (socket, command, id) { }; SocketReply.prototype.sendData = function (eventType, data) { - var message = new Message({apiVersion: '1.0', id: this.id}); + var message = new Message({ + apiVersion: '1.0', + id: this.id, + method: this.command, + }); message.setData(data); - this.socket.emit(this.command + '/' + eventType, message.toJSON()); + this.socket.emit('status:' + eventType, message.toJSON()); }; SocketReply.prototype.notify = function (data) { @@ -31,7 +55,11 @@ SocketReply.prototype.success = function (data) { SocketReply.prototype.error = function (data) { console.log('Operation error: ', data); - var message = new Message({apiVersion: '1.0', id: this.id}); + var message = new Message({ + apiVersion: '1.0', + id: this.id, + method: this.command, + }); var error = { code: data.code, @@ -41,7 +69,7 @@ SocketReply.prototype.error = function (data) { message.setError(error); - this.socket.emit(this.command + '/error', message.toJSON()); + this.socket.emit('status:failure', message.toJSON()); }; module.exports = SocketReply; diff --git a/app/routes/api.js b/app/routes/api.js index e7a501d..e65c19d 100644 --- a/app/routes/api.js +++ b/app/routes/api.js @@ -1,3 +1,23 @@ +/** + * The MIT License (MIT) + * Copyright (c) 2015 Fabrica de Aplicativos S/A + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ 'use strict'; module.exports = function (app) { diff --git a/app/routes/manipulator.js b/app/routes/manipulator.js index 7815924..13b924e 100644 --- a/app/routes/manipulator.js +++ b/app/routes/manipulator.js @@ -1,3 +1,23 @@ +/** + * The MIT License (MIT) + * Copyright (c) 2015 Fabrica de Aplicativos S/A + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ 'use strict'; module.exports = function (app) { @@ -10,6 +30,7 @@ module.exports = function (app) { manipulator.createEntityFromSchema(socket); manipulator.bindComponentToEntity(socket); manipulator.broadcastUpdates(socket); + manipulator.registerSocket(socket); }); return this; diff --git a/app/routes/resources.js b/app/routes/resources.js index 82134f9..e75c8ce 100644 --- a/app/routes/resources.js +++ b/app/routes/resources.js @@ -1,3 +1,23 @@ +/** + * The MIT License (MIT) + * Copyright (c) 2015 Fabrica de Aplicativos S/A + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ 'use strict'; module.exports = function (app) { diff --git a/config/HOM.json b/config/HOM.json new file mode 100644 index 0000000..19fc0b7 --- /dev/null +++ b/config/HOM.json @@ -0,0 +1,5 @@ +{ + "port": 8000, + "projectDir": "/code", + "sourceDir": "src/" +} diff --git a/gulpfile.js b/gulpfile.js index e80d026..df9b47f 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,3 +1,23 @@ +/** + * The MIT License (MIT) + * Copyright (c) 2015 Fabrica de Aplicativos S/A + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ 'use strict'; var gulp = require('gulp'); diff --git a/index.js b/index.js index aff4f64..2b5034c 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,23 @@ +/** + * The MIT License (MIT) + * Copyright (c) 2015 Fabrica de Aplicativos S/A + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ 'use strict'; var config = require('config'); var consign = require('consign'); diff --git a/package.json b/package.json index 0aab103..b55335b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "code-machine", - "version": "0.0.0", + "version": "0.0.1", "description": "", "main": "index.js", "scripts": { @@ -32,7 +32,7 @@ "async": "^1.4.2", "bower": "^1.5.2", "carbo-inspector": "git+ssh://git@github.com/carbono-io/carbo-inspector.git", - "carbono-json-messages": "git+ssh://git@bitbucket.org/carbonoio/carbono-json-messages.git", + "carbono-json-messages": "0.0.3", "commander": "^2.8.1", "config": "^1.15.0", "consign": "^0.1.1", diff --git a/test/code_manipulator.js b/test/code_manipulator.js index 9fa7701..ad5a398 100644 --- a/test/code_manipulator.js +++ b/test/code_manipulator.js @@ -1,3 +1,23 @@ +/** + * The MIT License (MIT) + * Copyright (c) 2015 Fabrica de Aplicativos S/A + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ 'use strict'; require('chai').should(); var io = require('socket.io-client'); @@ -23,6 +43,7 @@ var backupPath = path.join(codeDir, indexFile + '.bak'); var bowerDir = path.join(codeDir, 'bower_components'); var entitiesFilePath = path.join(codeDir, 'entities.json'); +var resourcesFilePath = path.join(projectDir, 'project_resources.json'); var conn; @@ -35,6 +56,7 @@ describe('Code Manipulator', function () { after(function (done) { fs.writeFileSync(entitiesFilePath, '{}'); + fs.writeFileSync(resourcesFilePath, '{}'); rimraf(bowerDir, done); }); @@ -53,12 +75,9 @@ describe('Code Manipulator', function () { conn.disconnect(); } - var backup = fs.createReadStream(backupPath); - backup.pipe(fs.createWriteStream(indexPath)); - backup.on('end', function () { - fs.unlink(backupPath); - done(); - }); + fs.writeFileSync(indexPath, fs.readFileSync(backupPath)); + fs.unlink(backupPath); + done(); }); it('Should be able to insert a new bower component', function (done) { @@ -88,10 +107,14 @@ describe('Code Manipulator', function () { conn.emit('command:insertElement', message.toJSON()); - conn.once('command:insertElement/success', function (message) { - var data = JSON.parse(message).data; + conn.once('status:success', function (reply) { + var msg = JSON.parse(reply); + var data = msg.data; var domFs = new DomFs(codeDir); var domFile = domFs.getFile(insert.path.file); + + msg.id.should.eql(message.id); + var formXpath = '/html/body/iron-form'; var ironForm = domFile.getElementByXPath(formXpath); ironForm.should.not.be.null; @@ -113,8 +136,11 @@ describe('Code Manipulator', function () { done(); }); - conn.once('command:insertElement/error', function (err) { - done(err); + conn.once('status:failure', function (reply) { + var msg = JSON.parse(reply); + if (msg.id === message.id) { + done(reply.error); + } }); }); }); @@ -134,12 +160,18 @@ describe('Code Manipulator', function () { conn.emit(command, message.toJSON()); - conn.once(command + '/success', function () { - done(); + conn.once('status:success', function (reply) { + var msg = JSON.parse(reply); + if (msg.id === message.id) { + done(); + } }); - conn.once(command + '/error', function (err) { - done(err); + conn.once('status:failure', function (reply) { + var msg = JSON.parse(reply); + if (msg.id === message.id) { + done(reply.error); + } }); }); @@ -155,12 +187,18 @@ describe('Code Manipulator', function () { conn.emit(command, message.toJSON()); - conn.once(command + '/success', function () { - done(new Error('Operation succeeded in error scenario')); + conn.once('status:success', function (reply) { + var msg = JSON.parse(reply); + if (msg.id === message.id) { + done(new Error('Operation succeeded in error scenario')); + } }); - conn.once(command + '/error', function () { - done(); + conn.once('status:failure', function (reply) { + var msg = JSON.parse(reply); + if (msg.id === message.id) { + done(); + } }); }); @@ -186,12 +224,18 @@ describe('Code Manipulator', function () { conn.emit(command, message.toJSON()); - conn.once(command + '/success', function () { - done(); + conn.once('status:success', function (reply) { + var msg = JSON.parse(reply); + if (msg.id === message.id) { + done(); + } }); - conn.once(command + '/error', function (err) { - done(err); + conn.once('status:failure', function (reply) { + var msg = JSON.parse(reply); + if (msg.id === message.id) { + done(reply.error); + } }); }); }); @@ -222,17 +266,20 @@ describe('Code Manipulator', function () { conn.emit('command:insertElement', message.toJSON()); - conn.once('control:contentUpdate', function (message) { - message = JSON.parse(message); - var data = message.data.items[0]; + conn.once('control:contentUpdate', function (reply) { + var msg = JSON.parse(reply); + var data = msg.data.items[0]; data.file.should.eql(insert.path.file); data.elementUuid.should.match(re); data.content.should.not.be.null; done(); }); - conn.once('command:insertElement/error', function (err) { - done(err); + conn.once('status:failure', function (reply) { + var msg = JSON.parse(reply); + if (msg.id === message.id) { + done(reply.error); + } }); }); }); diff --git a/test/entity-manager.js b/test/entity-manager.js index 301b0bb..23047fc 100644 --- a/test/entity-manager.js +++ b/test/entity-manager.js @@ -1,3 +1,23 @@ +/** + * The MIT License (MIT) + * Copyright (c) 2015 Fabrica de Aplicativos S/A + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ 'use strict'; require('chai').should(); var rimraf = require('rimraf'); @@ -23,35 +43,48 @@ describe('Entity Manager Lib', function () { it('Should be able to create entity with given schema', function (done) { var entityName = 'newEntity'; + var entityRoute = '/my/route'; var entitySchema = {name: 'base:String'}; - em.createEntity(entityName, entitySchema); + em.createEntity(entityName, entityRoute, entitySchema); var entities = JSON.parse(fs.readFileSync(testDir + 'entities.json')); entities.should.have.ownProperty(entityName); - entities[entityName].should.eql(entitySchema); + entities[entityName].route.should.eql(entityRoute); + entities[entityName].schema.should.eql(entitySchema); done(); }); it('Should be able to create entity with no schema given', function (done) { var entityName = 'entityWithoutSchema'; + var entityRoute = '/my/route'; - em.createEntity(entityName); + em.createEntity(entityName, entityRoute); var entities = JSON.parse(fs.readFileSync(testDir + 'entities.json')); entities.should.have.ownProperty(entityName); - entities[entityName].should.eql({}); + entities[entityName].route.should.eql(entityRoute); + entities[entityName].schema.should.eql({}); done(); }); it('Should throw error when creating existing entity', function (done) { - var existingEntityName = 'newEntity'; + var existingName = 'newEntity'; + var route = '/my/route'; - em.createEntity.bind(null, existingEntityName).should.throw(Error); + em.createEntity.bind(null, existingName, route).should.throw(Error); + + done(); + }); + + it('Should throw error if no route is given', function (done) { + var entityName = 'entityWithoutRoute'; + + em.createEntity.bind(null, entityName).should.throw(Error); done(); }); diff --git a/test/resources-server.js b/test/resources-server.js index 2a9a0c7..d7a1744 100644 --- a/test/resources-server.js +++ b/test/resources-server.js @@ -1,3 +1,23 @@ +/** + * The MIT License (MIT) + * Copyright (c) 2015 Fabrica de Aplicativos S/A + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ 'use strict'; var fs = require('fs'); var path = require('path'); diff --git a/test/testServer/project_resources.json b/test/testServer/project_resources.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/test/testServer/project_resources.json @@ -0,0 +1 @@ +{} \ No newline at end of file