fbp-manifest
Advanced tools
Comparing version 0.2.1 to 0.2.2
module.exports = { | ||
"extends": "standard", | ||
"extends": "airbnb-base", | ||
"rules": { | ||
"semi": [2, "always"] | ||
} | ||
"no-console": 0, | ||
}, | ||
}; |
@@ -1,7 +0,1 @@ | ||
/* | ||
* decaffeinate suggestions: | ||
* DS102: Remove unnecessary code created because of implicit returns | ||
* DS207: Consider shorter variations of null checks | ||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md | ||
*/ | ||
module.exports = function () { | ||
@@ -12,3 +6,3 @@ this.initConfig({ | ||
eslint: { | ||
target: ['*.js', 'src/*.js', 'src/**/*.js'] | ||
target: ['*.js', 'src/*.js', 'src/**/*.js'], | ||
}, | ||
@@ -22,6 +16,6 @@ | ||
src: '*.yml', | ||
dest: 'schema/' | ||
} | ||
] | ||
} | ||
dest: 'schema/', | ||
}, | ||
], | ||
}, | ||
}, | ||
@@ -31,3 +25,3 @@ | ||
yamllint: { | ||
schemas: ['schemata/*.yml'] | ||
schemas: ['schemata/*.yml'], | ||
}, | ||
@@ -39,6 +33,6 @@ | ||
options: { | ||
reporter: 'spec' | ||
} | ||
} | ||
} | ||
reporter: 'spec', | ||
}, | ||
}, | ||
}, | ||
}); | ||
@@ -55,15 +49,13 @@ | ||
// Our local tasks | ||
this.registerTask('build', 'Build', target => { | ||
if (target == null) { target = 'all'; } | ||
return this.task.run('yaml'); | ||
this.registerTask('build', 'Build', () => { | ||
this.task.run('yaml'); | ||
}); | ||
this.registerTask('test', 'Build and run tests', target => { | ||
if (target == null) { target = 'all'; } | ||
this.registerTask('test', 'Build and run tests', () => { | ||
this.task.run('eslint'); | ||
this.task.run('yamllint'); | ||
return this.task.run('mochaTest'); | ||
this.task.run('mochaTest'); | ||
}); | ||
return this.registerTask('default', ['test']); | ||
this.registerTask('default', ['test']); | ||
}; |
{ | ||
"name": "fbp-manifest", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "Flow-Based Programming Manifest tools", | ||
@@ -28,14 +28,12 @@ "main": "index.js", | ||
"coveralls": "^3.0.0", | ||
"eslint-config-standard": "^10.2.1", | ||
"eslint-plugin-import": "^2.8.0", | ||
"eslint-plugin-node": "^5.2.1", | ||
"eslint-plugin-promise": "^3.6.0", | ||
"eslint-plugin-standard": "^3.0.1", | ||
"eslint": "^6.8.0", | ||
"eslint-config-airbnb-base": "^14.1.0", | ||
"eslint-plugin-import": "^2.14.0", | ||
"grunt": "^1.0.1", | ||
"grunt-eslint": "^20.1.0", | ||
"grunt-eslint": "^21.0.0", | ||
"grunt-mocha-test": "^0.13.2", | ||
"grunt-yaml": "^0.4.2", | ||
"grunt-yamllint": "^0.3.0", | ||
"mocha": "^4.0.0", | ||
"nyc": "^11.2.1" | ||
"mocha": "^5.0.0", | ||
"nyc": "^14.0.0" | ||
}, | ||
@@ -45,3 +43,3 @@ "dependencies": { | ||
"clone": "^2.0.0", | ||
"commander": "^2.9.0", | ||
"commander": "^5.1.0", | ||
"fbp": "^1.5.0", | ||
@@ -48,0 +46,0 @@ "tv4": "^1.2.7" |
@@ -1,2 +0,2 @@ | ||
Flow-Based Programming Manifest Tools [![Build Status](https://travis-ci.org/flowbased/fbp-manifest.svg?branch=master)](https://travis-ci.org/flowbased/fbp-manifest) [![Greenkeeper badge](https://badges.greenkeeper.io/flowbased/fbp-manifest.svg)](https://greenkeeper.io/) [![Coverage Status](https://coveralls.io/repos/github/flowbased/fbp-manifest/badge.svg?branch=master)](https://coveralls.io/github/flowbased/fbp-manifest?branch=master) | ||
Flow-Based Programming Manifest Tools [![Build Status](https://travis-ci.org/flowbased/fbp-manifest.svg?branch=master)](https://travis-ci.org/flowbased/fbp-manifest) [![Coverage Status](https://coveralls.io/repos/github/flowbased/fbp-manifest/badge.svg?branch=master)](https://coveralls.io/github/flowbased/fbp-manifest?branch=master) | ||
===================================== | ||
@@ -82,1 +82,6 @@ | ||
* [FBP Glossary](http://www.jpaulmorrison.com/fbp/gloss.htm) | ||
## Changes | ||
* 0.2.2 (2020-09-17) | ||
- Added support for finding NoFlo TypeScript components |
@@ -5,16 +5,16 @@ /* eslint-disable | ||
const chai = require('chai'); | ||
const path = require('path'); | ||
const manifest = require('../index.js'); | ||
const path = require('path'); | ||
describe('Finding component dependencies', function () { | ||
describe('with NoFlo module without dependecies', function () { | ||
describe('Finding component dependencies', () => { | ||
describe('with NoFlo module without dependecies', () => { | ||
let modules = null; | ||
let baseDir = null; | ||
before(function (done) { | ||
before((done) => { | ||
baseDir = path.resolve(__dirname, 'fixtures/noflo-basic'); | ||
return manifest.list.list(baseDir, { | ||
runtimes: ['noflo'], | ||
recursive: true | ||
} | ||
, function (err, mods) { | ||
recursive: true, | ||
}, | ||
(err, mods) => { | ||
if (err) { return done(err); } | ||
@@ -25,55 +25,50 @@ modules = mods; | ||
}); | ||
describe('with elementary component', function () { | ||
it('should fail on missing component', done => | ||
manifest.dependencies.find(modules, 'basic/Baz', | ||
{baseDir} | ||
, function (err, dependedModules) { | ||
chai.expect(err).to.be.an('error'); | ||
return done(); | ||
}) | ||
); | ||
return it('should only find the component itself', done => | ||
manifest.dependencies.find(modules, 'basic/Foo', | ||
{baseDir} | ||
, function (err, dependedModules) { | ||
if (err) { return done(err); } | ||
chai.expect(dependedModules.length).to.equal(1); | ||
const dep = dependedModules[0]; | ||
chai.expect(dep.name).to.equal('basic'); | ||
chai.expect(dep.components.length).to.equal(1); | ||
chai.expect(dep.components[0].name).to.equal('Foo'); | ||
return done(); | ||
}) | ||
); | ||
describe('with elementary component', () => { | ||
it('should fail on missing component', done => manifest.dependencies.find(modules, 'basic/FooBaz', | ||
{ baseDir }, | ||
(err) => { | ||
chai.expect(err).to.be.an('error'); | ||
done(); | ||
})); | ||
return it('should only find the component itself', done => manifest.dependencies.find(modules, 'basic/Foo', | ||
{ baseDir }, | ||
(err, dependedModules) => { | ||
if (err) { | ||
done(err); | ||
return; | ||
} | ||
chai.expect(dependedModules.length).to.equal(1); | ||
const dep = dependedModules[0]; | ||
chai.expect(dep.name).to.equal('basic'); | ||
chai.expect(dep.components.length).to.equal(1); | ||
chai.expect(dep.components[0].name).to.equal('Foo'); | ||
done(); | ||
})); | ||
}); | ||
return describe('with component that is a graph', () => | ||
it('should find all dependencies', done => | ||
manifest.dependencies.find(modules, 'basic/Hello', | ||
{baseDir} | ||
, function (err, dependedModules) { | ||
if (err) { return done(err); } | ||
chai.expect(dependedModules.length).to.equal(2); | ||
const dep1 = dependedModules[0]; | ||
chai.expect(dep1.name).to.equal('basic'); | ||
const names = dep1.components.map(d => d.name); | ||
chai.expect(names).to.contain('Bar', 'Hello'); | ||
const dep2 = dependedModules[1]; | ||
chai.expect(dep2.name).to.equal('basic'); | ||
chai.expect(dep2.components.length).to.equal(1); | ||
chai.expect(dep2.components[0].name).to.equal('Foo'); | ||
return done(); | ||
}) | ||
) | ||
); | ||
return describe('with component that is a graph', () => it('should find all dependencies', done => manifest.dependencies.find(modules, 'basic/Hello', | ||
{ baseDir }, | ||
(err, dependedModules) => { | ||
if (err) { return done(err); } | ||
chai.expect(dependedModules.length).to.equal(2); | ||
const dep1 = dependedModules[0]; | ||
chai.expect(dep1.name).to.equal('basic'); | ||
const names = dep1.components.map(d => d.name); | ||
chai.expect(names).to.contain('Bar', 'Hello'); | ||
const dep2 = dependedModules[1]; | ||
chai.expect(dep2.name).to.equal('basic'); | ||
chai.expect(dep2.components.length).to.equal(1); | ||
chai.expect(dep2.components[0].name).to.equal('Foo'); | ||
return done(); | ||
}))); | ||
}); | ||
describe('with NoFlo module with components in a subdirectory', function () { | ||
describe('with NoFlo module with components in a subdirectory', () => { | ||
let modules = null; | ||
let baseDir = null; | ||
before(function (done) { | ||
before((done) => { | ||
baseDir = path.resolve(__dirname, 'fixtures/noflo-subdirs'); | ||
return manifest.list.list(baseDir, { | ||
runtimes: ['noflo'], | ||
recursive: true | ||
} | ||
, function (err, mods) { | ||
recursive: true, | ||
}, | ||
(err, mods) => { | ||
if (err) { return done(err); } | ||
@@ -84,68 +79,58 @@ modules = mods; | ||
}); | ||
describe('with elementary component', function () { | ||
it('should fail on missing component', done => | ||
manifest.dependencies.find(modules, 'subdirs/Baz', | ||
{baseDir} | ||
, function (err, dependedModules) { | ||
chai.expect(err).to.be.an('error'); | ||
return done(); | ||
}) | ||
); | ||
it('should only find the component itself', done => | ||
manifest.dependencies.find(modules, 'subdirs/Foo', | ||
{baseDir} | ||
, function (err, dependedModules) { | ||
if (err) { return done(err); } | ||
chai.expect(dependedModules.length).to.equal(1); | ||
const dep = dependedModules[0]; | ||
chai.expect(dep.name).to.equal('subdirs'); | ||
chai.expect(dep.components.length).to.equal(1); | ||
chai.expect(dep.components[0].name).to.equal('Foo'); | ||
return done(); | ||
}) | ||
); | ||
return it('should also find from a subdir', done => | ||
manifest.dependencies.find(modules, 'subdirs/Bar', | ||
{baseDir} | ||
, function (err, dependedModules) { | ||
if (err) { return done(err); } | ||
chai.expect(dependedModules.length).to.equal(1); | ||
const dep = dependedModules[0]; | ||
chai.expect(dep.name).to.equal('subdirs'); | ||
chai.expect(dep.components.length).to.equal(1); | ||
chai.expect(dep.components[0].name).to.equal('Bar'); | ||
return done(); | ||
}) | ||
); | ||
describe('with elementary component', () => { | ||
it('should fail on missing component', done => manifest.dependencies.find(modules, 'subdirs/Baz', | ||
{ baseDir }, | ||
(err) => { | ||
chai.expect(err).to.be.an('error'); | ||
return done(); | ||
})); | ||
it('should only find the component itself', done => manifest.dependencies.find(modules, 'subdirs/Foo', | ||
{ baseDir }, | ||
(err, dependedModules) => { | ||
if (err) { return done(err); } | ||
chai.expect(dependedModules.length).to.equal(1); | ||
const dep = dependedModules[0]; | ||
chai.expect(dep.name).to.equal('subdirs'); | ||
chai.expect(dep.components.length).to.equal(1); | ||
chai.expect(dep.components[0].name).to.equal('Foo'); | ||
return done(); | ||
})); | ||
return it('should also find from a subdir', done => manifest.dependencies.find(modules, 'subdirs/Bar', | ||
{ baseDir }, | ||
(err, dependedModules) => { | ||
if (err) { return done(err); } | ||
chai.expect(dependedModules.length).to.equal(1); | ||
const dep = dependedModules[0]; | ||
chai.expect(dep.name).to.equal('subdirs'); | ||
chai.expect(dep.components.length).to.equal(1); | ||
chai.expect(dep.components[0].name).to.equal('Bar'); | ||
return done(); | ||
})); | ||
}); | ||
return describe('with component that is a graph', () => | ||
it('should find all dependencies', done => | ||
manifest.dependencies.find(modules, 'subdirs/Hello', | ||
{baseDir} | ||
, function (err, dependedModules) { | ||
if (err) { return done(err); } | ||
chai.expect(dependedModules.length).to.equal(2); | ||
const dep1 = dependedModules[1]; | ||
chai.expect(dep1.name).to.equal('subdirs'); | ||
const names = dep1.components.map(d => d.name); | ||
chai.expect(names).to.contain('Bar', 'Hello'); | ||
const dep2 = dependedModules[0]; | ||
chai.expect(dep2.name).to.equal('subdirs'); | ||
chai.expect(dep2.components.length).to.equal(1); | ||
chai.expect(dep2.components[0].name).to.equal('Foo'); | ||
return done(); | ||
}) | ||
) | ||
); | ||
return describe('with component that is a graph', () => it('should find all dependencies', done => manifest.dependencies.find(modules, 'subdirs/Hello', | ||
{ baseDir }, | ||
(err, dependedModules) => { | ||
if (err) { return done(err); } | ||
chai.expect(dependedModules.length).to.equal(2); | ||
const dep1 = dependedModules[1]; | ||
chai.expect(dep1.name).to.equal('subdirs'); | ||
const names = dep1.components.map(d => d.name); | ||
chai.expect(names).to.contain('Bar', 'Hello'); | ||
const dep2 = dependedModules[0]; | ||
chai.expect(dep2.name).to.equal('subdirs'); | ||
chai.expect(dep2.components.length).to.equal(1); | ||
chai.expect(dep2.components[0].name).to.equal('Foo'); | ||
return done(); | ||
}))); | ||
}); | ||
return describe('with NoFlo module with dependecies', function () { | ||
return describe('with NoFlo module with dependecies', () => { | ||
let modules = null; | ||
let baseDir = null; | ||
before(function (done) { | ||
before((done) => { | ||
baseDir = path.resolve(__dirname, 'fixtures/noflo-deps'); | ||
return manifest.list.list(baseDir, { | ||
runtimes: ['noflo'], | ||
recursive: true | ||
} | ||
, function (err, mods) { | ||
recursive: true, | ||
}, | ||
(err, mods) => { | ||
if (err) { return done(err); } | ||
@@ -156,98 +141,82 @@ modules = mods; | ||
}); | ||
describe('with elementary component', function () { | ||
it('should fail on missing component', done => | ||
manifest.dependencies.find(modules, 'deps/Baz', | ||
{baseDir} | ||
, function (err, dependedModules) { | ||
chai.expect(err).to.be.an('error'); | ||
chai.expect(err.message).to.contain('deps/Baz'); | ||
return done(); | ||
}) | ||
); | ||
it('should only find the component itself', done => | ||
manifest.dependencies.find(modules, 'deps/Foo', | ||
{baseDir} | ||
, function (err, dependedModules) { | ||
if (err) { return done(err); } | ||
chai.expect(dependedModules.length).to.equal(1); | ||
const dep = dependedModules[0]; | ||
chai.expect(dep.name).to.equal('deps'); | ||
chai.expect(dep.base).to.equal(''); | ||
chai.expect(dep.components.length).to.equal(1); | ||
chai.expect(dep.components[0].name).to.equal('Foo'); | ||
return done(); | ||
}) | ||
); | ||
it('should also find a component from the depended module', done => | ||
manifest.dependencies.find(modules, 'dep/Foo', | ||
{baseDir} | ||
, function (err, dependedModules) { | ||
if (err) { return done(err); } | ||
chai.expect(dependedModules.length).to.equal(1); | ||
const dep = dependedModules[0]; | ||
chai.expect(dep.name).to.equal('dep'); | ||
chai.expect(dep.base).to.equal(path.normalize('node_modules/noflo-dep')); | ||
chai.expect(dep.components.length).to.equal(1); | ||
chai.expect(dep.components[0].name).to.equal('Foo'); | ||
return done(); | ||
}) | ||
); | ||
return it('should also find a component from a subdependency', done => | ||
manifest.dependencies.find(modules, 'subdep/SubSubComponent', | ||
{baseDir} | ||
, function (err, dependedModules) { | ||
if (err) { return done(err); } | ||
chai.expect(dependedModules.length).to.equal(1); | ||
const dep = dependedModules[0]; | ||
chai.expect(dep.name).to.equal('subdep'); | ||
chai.expect(dep.base).to.equal(path.normalize('node_modules/noflo-dep/node_modules/noflo-subdep')); | ||
chai.expect(dep.components.length).to.equal(1); | ||
chai.expect(dep.components[0].name).to.equal('SubSubComponent'); | ||
return done(); | ||
}) | ||
); | ||
describe('with elementary component', () => { | ||
it('should fail on missing component', done => manifest.dependencies.find(modules, 'deps/Baz', | ||
{ baseDir }, | ||
(err) => { | ||
chai.expect(err).to.be.an('error'); | ||
chai.expect(err.message).to.contain('deps/Baz'); | ||
return done(); | ||
})); | ||
it('should only find the component itself', done => manifest.dependencies.find(modules, 'deps/Foo', | ||
{ baseDir }, | ||
(err, dependedModules) => { | ||
if (err) { return done(err); } | ||
chai.expect(dependedModules.length).to.equal(1); | ||
const dep = dependedModules[0]; | ||
chai.expect(dep.name).to.equal('deps'); | ||
chai.expect(dep.base).to.equal(''); | ||
chai.expect(dep.components.length).to.equal(1); | ||
chai.expect(dep.components[0].name).to.equal('Foo'); | ||
return done(); | ||
})); | ||
it('should also find a component from the depended module', done => manifest.dependencies.find(modules, 'dep/Foo', | ||
{ baseDir }, | ||
(err, dependedModules) => { | ||
if (err) { return done(err); } | ||
chai.expect(dependedModules.length).to.equal(1); | ||
const dep = dependedModules[0]; | ||
chai.expect(dep.name).to.equal('dep'); | ||
chai.expect(dep.base).to.equal(path.normalize('node_modules/noflo-dep')); | ||
chai.expect(dep.components.length).to.equal(1); | ||
chai.expect(dep.components[0].name).to.equal('Foo'); | ||
return done(); | ||
})); | ||
return it('should also find a component from a subdependency', done => manifest.dependencies.find(modules, 'subdep/SubSubComponent', | ||
{ baseDir }, | ||
(err, dependedModules) => { | ||
if (err) { return done(err); } | ||
chai.expect(dependedModules.length).to.equal(1); | ||
const dep = dependedModules[0]; | ||
chai.expect(dep.name).to.equal('subdep'); | ||
chai.expect(dep.base).to.equal(path.normalize('node_modules/noflo-dep/node_modules/noflo-subdep')); | ||
chai.expect(dep.components.length).to.equal(1); | ||
chai.expect(dep.components[0].name).to.equal('SubSubComponent'); | ||
return done(); | ||
})); | ||
}); | ||
describe('with component that is a graph', function () { | ||
it('should fail on missing dependencies', done => | ||
manifest.dependencies.find(modules, 'deps/Missing', | ||
{baseDir} | ||
, function (err, dependedModules) { | ||
chai.expect(err).to.be.an('error'); | ||
chai.expect(err.message).to.contain('deps/Baz'); | ||
return done(); | ||
}) | ||
); | ||
return it('should find all dependencies, also from subgraph', done => | ||
manifest.dependencies.find(modules, 'deps/Hello', | ||
{baseDir} | ||
, function (err, dependedModules) { | ||
if (err) { return done(err); } | ||
chai.expect(dependedModules.length).to.equal(2); | ||
let dep = dependedModules[0]; | ||
chai.expect(dep.name).to.equal('deps'); | ||
let names = dep.components.map(d => d.name); | ||
chai.expect(names).to.eql(['Bar', 'Hello']); | ||
dep = dependedModules[1]; | ||
chai.expect(dep.name).to.equal('dep'); | ||
names = dep.components.map(d => d.name); | ||
chai.expect(names).to.eql(['Bar', 'Foo', 'Baz']); | ||
return done(); | ||
}) | ||
); | ||
describe('with component that is a graph', () => { | ||
it('should fail on missing dependencies', done => manifest.dependencies.find(modules, 'deps/Missing', | ||
{ baseDir }, | ||
(err) => { | ||
chai.expect(err).to.be.an('error'); | ||
chai.expect(err.message).to.contain('deps/Baz'); | ||
return done(); | ||
})); | ||
return it('should find all dependencies, also from subgraph', done => manifest.dependencies.find(modules, 'deps/Hello', | ||
{ baseDir }, | ||
(err, dependedModules) => { | ||
if (err) { return done(err); } | ||
chai.expect(dependedModules.length).to.equal(2); | ||
let dep = dependedModules[0]; | ||
chai.expect(dep.name).to.equal('deps'); | ||
let names = dep.components.map(d => d.name); | ||
chai.expect(names).to.eql(['Bar', 'Hello']); | ||
[, dep] = dependedModules; | ||
chai.expect(dep.name).to.equal('dep'); | ||
names = dep.components.map(d => d.name); | ||
chai.expect(names).to.eql(['Bar', 'Foo', 'Baz']); | ||
return done(); | ||
})); | ||
}); | ||
return describe('with a graph that depends on components from a dynamic component loader', () => | ||
it('should find the dependencies and register the loader', done => | ||
manifest.dependencies.find(modules, 'deps/WithLoader', | ||
{baseDir} | ||
, function (err, dependedModules) { | ||
if (err) { return done(err); } | ||
chai.expect(dependedModules.length).to.equal(3); | ||
const [withLoader] = Array.from(dependedModules.filter(m => m.name === 'loader')); | ||
chai.expect(withLoader.noflo.loader).to.equal('lib/ComponentLoader'); | ||
chai.expect(withLoader.components).to.eql([]); | ||
return done(); | ||
}) | ||
) | ||
); | ||
return describe('with a graph that depends on components from a dynamic component loader', () => it('should find the dependencies and register the loader', done => manifest.dependencies.find(modules, 'deps/WithLoader', | ||
{ baseDir }, | ||
(err, dependedModules) => { | ||
if (err) { return done(err); } | ||
chai.expect(dependedModules.length).to.equal(3); | ||
const [withLoader] = Array.from(dependedModules.filter(m => m.name === 'loader')); | ||
chai.expect(withLoader.noflo.loader).to.equal('lib/ComponentLoader'); | ||
chai.expect(withLoader.components).to.eql([]); | ||
return done(); | ||
}))); | ||
}); | ||
}); |
@@ -5,9 +5,9 @@ /* eslint-disable | ||
const chai = require('chai'); | ||
const path = require('path'); | ||
const manifest = require('../index.js'); | ||
const path = require('path'); | ||
describe('Listing components', function () { | ||
it('should fail without provided runtimes', function (done) { | ||
describe('Listing components', () => { | ||
it('should fail without provided runtimes', (done) => { | ||
const baseDir = path.resolve(__dirname, 'fixtures/noflo-basic'); | ||
return manifest.list.list(baseDir, {}, function (err, components) { | ||
manifest.list.list(baseDir, {}, (err) => { | ||
chai.expect(err).to.be.an('error'); | ||
@@ -18,9 +18,9 @@ return done(); | ||
return it('should find NoFlo components', function (done) { | ||
return it('should find NoFlo components', (done) => { | ||
const baseDir = path.resolve(__dirname, 'fixtures/noflo-basic'); | ||
return manifest.list.list(baseDir, { | ||
runtimes: ['noflo'], | ||
recursive: true | ||
} | ||
, function (err, modules) { | ||
recursive: true, | ||
}, | ||
(err, modules) => { | ||
if (err) { return done(err); } | ||
@@ -33,7 +33,9 @@ chai.expect(modules.length).to.equal(2); | ||
chai.expect(nodejs).to.be.an('object'); | ||
chai.expect(nodejs.components.length).to.equal(2); | ||
chai.expect(nodejs.components.length).to.equal(3); | ||
chai.expect(nodejs.components[0].name).to.equal('Bar'); | ||
chai.expect(nodejs.components[0].elementary).to.equal(true); | ||
chai.expect(nodejs.components[1].name).to.equal('Hello'); | ||
chai.expect(nodejs.components[1].elementary).to.equal(false); | ||
chai.expect(nodejs.components[1].name).to.equal('Baz'); | ||
chai.expect(nodejs.components[1].elementary).to.equal(true); | ||
chai.expect(nodejs.components[2].name).to.equal('Hello'); | ||
chai.expect(nodejs.components[2].elementary).to.equal(false); | ||
return done(); | ||
@@ -40,0 +42,0 @@ }); |
@@ -1,14 +0,1 @@ | ||
/* eslint-disable | ||
no-unused-vars, | ||
*/ | ||
// TODO: This file was updated by bulk-decaffeinate. | ||
// Fix any style issues and re-enable lint. | ||
/* | ||
* decaffeinate suggestions: | ||
* DS101: Remove unnecessary use of Array.from | ||
* DS102: Remove unnecessary code created because of implicit returns | ||
* DS207: Consider shorter variations of null checks | ||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md | ||
*/ | ||
let main; | ||
const clone = require('clone'); | ||
@@ -19,8 +6,12 @@ const path = require('path'); | ||
const Promise = require('bluebird'); | ||
const program = require('commander'); | ||
const loader = require('./load'); | ||
const loadGraph = (graphPath, callback) => | ||
fs.readFile(graphPath, 'utf-8', function (err, content) { | ||
let e, graph; | ||
if (err) { return callback(err); } | ||
function loadGraph(graphPath, callback) { | ||
return fs.readFile(graphPath, 'utf-8', (err, content) => { | ||
if (err) { | ||
callback(err); | ||
return; | ||
} | ||
let graph; | ||
if (path.extname(graphPath) === '.fbp') { | ||
@@ -30,20 +21,22 @@ try { | ||
} catch (error) { | ||
e = error; | ||
return callback(e); | ||
callback(error); | ||
return; | ||
} | ||
return callback(null, graph); | ||
callback(null, graph); | ||
return; | ||
} | ||
try { | ||
graph = JSON.parse(content); | ||
} catch (error1) { | ||
e = error1; | ||
return callback(e); | ||
} catch (error) { | ||
callback(error); | ||
} | ||
return callback(null, graph); | ||
}) | ||
; | ||
callback(null, graph); | ||
}); | ||
} | ||
exports.findComponent = function (modules, component) { | ||
for (let m of Array.from(modules)) { | ||
for (let c of Array.from(m.components)) { | ||
exports.findComponent = (modules, component) => { | ||
for (let i = 0; i < modules.length; i += 1) { | ||
const m = modules[i]; | ||
for (let ii = 0; ii < m.components.length; ii += 1) { | ||
const c = m.components[ii]; | ||
if ((c.name === component) || (`${m.name}/${c.name}` === component)) { | ||
@@ -57,6 +50,6 @@ return c; | ||
exports.checkCustomLoaderInModules = function (modules, component) { | ||
for (let m of Array.from(modules)) { | ||
if (exports.checkCustomLoader(m, component)) { return true; } | ||
continue; | ||
exports.checkCustomLoaderInModules = (modules, component) => { | ||
const foundLoader = modules.find((m) => exports.checkCustomLoader(m, component)); | ||
if (foundLoader) { | ||
return true; | ||
} | ||
@@ -66,3 +59,3 @@ return false; | ||
exports.checkCustomLoader = function (module, component) { | ||
exports.checkCustomLoader = (module, component) => { | ||
if (!component) { return false; } | ||
@@ -75,9 +68,9 @@ if (!(module.noflo != null ? module.noflo.loader : undefined)) { return false; } | ||
exports.filterModules = function (modules, components, callback) { | ||
exports.filterModules = (modules, components, callback) => { | ||
let componentsFound = []; | ||
const filteredModules = []; | ||
modules.forEach(function (m) { | ||
modules.forEach((m) => { | ||
// Filter components list to only the ones used in graph(s) | ||
const foundComponents = m.components.filter(function (c) { | ||
const foundComponents = m.components.filter((c) => { | ||
if (!c) { return false; } | ||
@@ -96,3 +89,3 @@ let foundAsDependency = false; | ||
// Check if graph(s) depend on dynamically loaded components | ||
const customLoaderComponents = components.filter(function (c) { | ||
const customLoaderComponents = components.filter((c) => { | ||
if (!c) { return false; } | ||
@@ -108,14 +101,14 @@ if (exports.checkCustomLoader(m, c)) { | ||
newModule.components = foundComponents; | ||
return filteredModules.push(newModule); | ||
filteredModules.push(newModule); | ||
}); | ||
components = components.filter(c => componentsFound.indexOf(c) === -1); | ||
if (components.length) { | ||
return callback(new Error(`Missing components: ${components.join(', ')}`)); | ||
const missingComponents = components.filter((c) => componentsFound.indexOf(c) === -1); | ||
if (missingComponents.length) { | ||
callback(new Error(`Missing components: ${missingComponents.join(', ')}`)); | ||
return; | ||
} | ||
return callback(null, filteredModules); | ||
callback(null, filteredModules); | ||
}; | ||
exports.resolve = function (modules, component, options, callback) { | ||
exports.resolve = (modules, component, options, callback) => { | ||
const componentFound = exports.findComponent(modules, component); | ||
@@ -125,5 +118,9 @@ if (!componentFound) { | ||
const customLoader = exports.checkCustomLoaderInModules(modules, component); | ||
if (customLoader) { return callback(null, [component]); } | ||
if (customLoader) { | ||
callback(null, [component]); | ||
return; | ||
} | ||
// Otherwise we fail with missing dependency | ||
return callback(new Error(`Component ${component} not available`)); | ||
callback(new Error(`Component ${component} not available`)); | ||
return; | ||
} | ||
@@ -137,27 +134,33 @@ | ||
if (!componentFound.source) { | ||
return callback(new Error(`Graph source not available for ${component}`)); | ||
callback(new Error(`Graph source not available for ${component}`)); | ||
return; | ||
} | ||
const graphPath = path.resolve(options.baseDir, componentFound.source); | ||
return loadGraph(graphPath, function (err, graph) { | ||
loadGraph(graphPath, (err, graph) => { | ||
if (err) { return callback(err); } | ||
const components = []; | ||
for (let k in graph.processes) { | ||
Object.keys(graph.processes).forEach((k) => { | ||
const v = graph.processes[k]; | ||
if (!v.component) { continue; } | ||
if (!v.component) { return; } | ||
components.push(v.component); | ||
} | ||
}); | ||
const resolver = Promise.promisify(exports.resolve); | ||
return Promise.map(components, c => resolver(modules, c, options)).nodeify(function (err, deps) { | ||
if (err != null ? err.cause : undefined) { return callback(err.cause); } | ||
if (err) { return callback(err); } | ||
return Promise.map(components, (c) => resolver(modules, c, options)).nodeify((e, deps) => { | ||
if (e) { | ||
if (e.cause) { | ||
callback(e.cause); | ||
return; | ||
} | ||
callback(e); | ||
} | ||
const subs = [component]; | ||
for (let s of Array.from(deps)) { | ||
for (let sc of Array.from(s)) { | ||
if (subs.indexOf(sc) !== -1) { continue; } | ||
deps.forEach((s) => { | ||
s.forEach((sc) => { | ||
if (subs.indexOf(sc) !== -1) { return; } | ||
subs.push(sc); | ||
} | ||
} | ||
return callback(null, subs); | ||
}); | ||
}); | ||
callback(null, subs); | ||
}); | ||
@@ -167,19 +170,27 @@ }); | ||
exports.find = (modules, component, options, callback) => | ||
exports.resolve(modules, component, options, function (err, components) { | ||
exports.find = (modules, component, options, callback) => exports.resolve( | ||
modules, | ||
component, | ||
options, | ||
(err, components) => { | ||
if (err) { return callback(err); } | ||
return exports.filterModules(modules, components, callback); | ||
}) | ||
; | ||
}, | ||
); | ||
exports.loadAndFind = (baseDir, component, options, callback) => | ||
loader.load(baseDir, options, function (err, manifest) { | ||
if (err) { return callback(err); } | ||
return exports.find(manifest.modules, component, options, callback); | ||
}) | ||
; | ||
exports.loadAndFind = (baseDir, component, options, callback) => loader.load( | ||
baseDir, | ||
options, | ||
(err, manifest) => { | ||
if (err) { | ||
callback(err); | ||
return; | ||
} | ||
exports.find(manifest.modules, component, options, callback); | ||
}, | ||
); | ||
exports.main = (main = function () { | ||
const list = val => val.split(','); | ||
const program = require('commander') | ||
exports.main = () => { | ||
const list = (val) => val.split(','); | ||
program | ||
.option('--runtimes <runtimes>', 'List components from runtimes', list) | ||
@@ -195,4 +206,4 @@ .option('--manifest <manifest>', 'Manifest file to use. Default is fbp.json', 'fbp.json') | ||
program.recursive = true; | ||
program.baseDir = program.args[0]; | ||
return exports.loadAndFind(program.args[0], program.args[1], program, function (err, dependedModules) { | ||
[program.baseDir] = program.args; | ||
return exports.loadAndFind(program.args[0], program.args[1], program, (err, dependedModules) => { | ||
if (err) { | ||
@@ -205,7 +216,7 @@ console.error(err); | ||
version: 1, | ||
modules: dependedModules | ||
modules: dependedModules, | ||
}; | ||
console.log(JSON.stringify(manifest, null, 2)); | ||
return process.exit(0); | ||
process.exit(0); | ||
}); | ||
}); | ||
}; |
@@ -1,24 +0,13 @@ | ||
/* eslint-disable | ||
no-unused-vars, | ||
*/ | ||
// TODO: This file was updated by bulk-decaffeinate. | ||
// Fix any style issues and re-enable lint. | ||
/* | ||
* decaffeinate suggestions: | ||
* DS101: Remove unnecessary use of Array.from | ||
* DS102: Remove unnecessary code created because of implicit returns | ||
* DS207: Consider shorter variations of null checks | ||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md | ||
*/ | ||
let main; | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const Promise = require('bluebird'); | ||
const program = require('commander'); | ||
const noflo = require('./runtimes/noflo'); | ||
const msgflo = require('./runtimes/msgflo'); | ||
const runtimes = { | ||
noflo: require('./runtimes/noflo'), | ||
msgflo: require('./runtimes/msgflo') | ||
noflo, | ||
msgflo, | ||
}; | ||
exports.list = function (baseDir, options, callback) { | ||
exports.list = (baseDir, opts, callback) => { | ||
const options = opts; | ||
if (!options.root) { options.root = baseDir; } | ||
@@ -28,32 +17,40 @@ if (typeof options.subdirs === 'undefined') { options.subdirs = true; } | ||
if (!(options.runtimes != null ? options.runtimes.length : undefined)) { | ||
return callback(new Error('No runtimes specified')); | ||
callback(new Error('No runtimes specified')); | ||
return; | ||
} | ||
const missingRuntimes = options.runtimes.filter(r => typeof runtimes[r] === 'undefined'); | ||
const missingRuntimes = options.runtimes.filter((r) => typeof runtimes[r] === 'undefined'); | ||
if (missingRuntimes.length) { | ||
return callback(new Error(`Unsupported runtime types: ${missingRuntimes.join(', ')}`)); | ||
callback(new Error(`Unsupported runtime types: ${missingRuntimes.join(', ')}`)); | ||
return; | ||
} | ||
Promise.map(options.runtimes, function (runtime) { | ||
Promise.map(options.runtimes, (runtime) => { | ||
const lister = Promise.promisify(runtimes[runtime].list); | ||
return lister(baseDir, options); | ||
}).then(function (results) { | ||
}).then((results) => { | ||
// Flatten | ||
let modules = []; | ||
for (let r of Array.from(results)) { modules = modules.concat(r); } | ||
results.forEach((r) => { | ||
modules = modules.concat(r); | ||
}); | ||
if (!options.recursive) { return Promise.resolve(modules); } | ||
return Promise.map(options.runtimes, function (runtime) { | ||
return Promise.map(options.runtimes, (runtime) => { | ||
const depLister = Promise.promisify(runtimes[runtime].listDependencies); | ||
return depLister(baseDir, options) | ||
.map(function (dep) { | ||
.map((dep) => { | ||
const subLister = Promise.promisify(exports.list); | ||
return subLister(dep, options); | ||
}).then(function (subDeps) { | ||
}).then((subDeps) => { | ||
let subs = []; | ||
for (let s of Array.from(subDeps)) { subs = subs.concat(s); } | ||
subDeps.forEach((s) => { | ||
subs = subs.concat(s); | ||
}); | ||
return Promise.resolve(subs); | ||
}); | ||
}).then(function (subDeps) { | ||
}).then((subDeps) => { | ||
let subs = []; | ||
for (let s of Array.from(subDeps)) { subs = subs.concat(s); } | ||
subDeps.forEach((s) => { | ||
subs = subs.concat(s); | ||
}); | ||
modules = modules.concat(subs); | ||
@@ -65,6 +62,6 @@ return Promise.resolve(modules); | ||
exports.main = (main = function () { | ||
exports.main = () => { | ||
const availableRuntimes = Object.keys(runtimes); | ||
const list = val => val.split(','); | ||
const program = require('commander') | ||
const list = (val) => val.split(','); | ||
program | ||
.option('--recursive', 'List also from dependencies', true) | ||
@@ -80,3 +77,3 @@ .option('--subdirs', 'List also from subdirectories of the primary component locations', true) | ||
return exports.list(program.args[0], program, function (err, modules) { | ||
return exports.list(program.args[0], program, (err, modules) => { | ||
if (err) { | ||
@@ -88,3 +85,3 @@ console.log(err); | ||
version: 1, | ||
modules | ||
modules, | ||
}; | ||
@@ -94,2 +91,2 @@ console.log(JSON.stringify(manifest, null, 2)); | ||
}); | ||
}); | ||
}; |
@@ -1,6 +0,1 @@ | ||
/* | ||
* decaffeinate suggestions: | ||
* DS102: Remove unnecessary code created because of implicit returns | ||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md | ||
*/ | ||
const path = require('path'); | ||
@@ -10,3 +5,4 @@ const fs = require('fs'); | ||
exports.load = function (baseDir, options, callback) { | ||
exports.load = (baseDir, opts, callback) => { | ||
const options = opts; | ||
if (typeof options.discover === 'undefined') { options.discover = true; } | ||
@@ -16,24 +12,30 @@ if (!options.manifest) { options.manifest = 'fbp.json'; } | ||
const manifestPath = path.resolve(baseDir, options.manifest); | ||
return fs.readFile(manifestPath, 'utf-8', function (err, contents) { | ||
return fs.readFile(manifestPath, 'utf-8', (err, contents) => { | ||
let manifest; | ||
if (err && (err.code === 'ENOENT') && options.discover) { | ||
if (!options.silent) { console.warn(`${manifestPath} not found, running auto-discovery`); } | ||
lister.list(baseDir, options, function (err, modules) { | ||
if (err) { return callback(err); } | ||
const manifest = { | ||
lister.list(baseDir, options, (error, modules) => { | ||
if (error) { | ||
callback(error); | ||
return; | ||
} | ||
callback(null, { | ||
version: 1, | ||
modules | ||
}; | ||
return callback(null, manifest); | ||
modules, | ||
}); | ||
}); | ||
return; | ||
} | ||
if (err) { return callback(err); } | ||
if (err) { | ||
callback(err); | ||
return; | ||
} | ||
try { | ||
manifest = JSON.parse(contents); | ||
} catch (e) { | ||
return callback(e); | ||
callback(e); | ||
return; | ||
} | ||
return callback(null, manifest); | ||
callback(null, manifest); | ||
}); | ||
}; |
@@ -1,7 +0,1 @@ | ||
/* | ||
* decaffeinate suggestions: | ||
* DS102: Remove unnecessary code created because of implicit returns | ||
* DS207: Consider shorter variations of null checks | ||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md | ||
*/ | ||
const path = require('path'); | ||
@@ -13,16 +7,17 @@ const fs = require('fs'); | ||
const replaceMarker = function (str, marker, value) { | ||
marker = `#${marker.toUpperCase()}`; | ||
return str.replace(marker, value); | ||
}; | ||
function replaceMarker(str, marker, value) { | ||
return str.replace(`#${marker.toUpperCase()}`, value); | ||
} | ||
const replaceVariables = function (str, variables) { | ||
for (let marker in variables) { | ||
function replaceVariables(string, variables) { | ||
let str = string; | ||
Object.keys(variables).forEach((marker) => { | ||
const value = variables[marker]; | ||
str = replaceMarker(str, marker, value); | ||
} | ||
}); | ||
return str; | ||
}; | ||
} | ||
const componentsFromConfig = function (config) { | ||
function componentsFromConfig(c) { | ||
const config = c; | ||
const variables = config.variables || {}; | ||
@@ -32,18 +27,18 @@ if (!config.components) { config.components = {}; } | ||
const components = {}; | ||
for (let component in config.components) { | ||
Object.keys(config.components).forEach((component) => { | ||
const cmd = config.components[component]; | ||
let componentName = component.split('/')[1]; | ||
if (!componentName) { componentName = component; } | ||
variables['COMPONENTNAME'] = componentName; | ||
variables['COMPONENT'] = component; | ||
variables.COMPONENTNAME = componentName; | ||
variables.COMPONENT = component; | ||
components[component] = replaceVariables(cmd, variables); | ||
} | ||
}); | ||
return components; | ||
}; | ||
} | ||
exports.list = function (baseDir, options, callback) { | ||
exports.list = (baseDir, options, callback) => { | ||
const packageFile = path.resolve(baseDir, 'package.json'); | ||
return readfile(packageFile, 'utf-8') | ||
.then(function (json) { | ||
.then((json) => { | ||
const packageData = JSON.parse(json); | ||
@@ -57,3 +52,3 @@ if (!packageData.msgflo) { return Promise.resolve([]); } | ||
base: path.relative(options.root, baseDir), | ||
components: [] | ||
components: [], | ||
}; | ||
@@ -66,3 +61,3 @@ | ||
const object = componentsFromConfig(packageData.msgflo); | ||
for (let name in object) { | ||
Object.keys(object).forEach((name) => { | ||
const definition = object[name]; | ||
@@ -74,5 +69,5 @@ let componentName = name.split('/')[1]; | ||
exec: definition, | ||
elementary: false | ||
elementary: false, | ||
}); | ||
} | ||
}); | ||
@@ -79,0 +74,0 @@ return Promise.resolve([module]); |
@@ -1,18 +0,1 @@ | ||
/* eslint-disable | ||
no-return-assign, | ||
no-useless-escape, | ||
*/ | ||
// TODO: This file was updated by bulk-decaffeinate. | ||
// Fix any style issues and re-enable lint. | ||
/* | ||
* decaffeinate suggestions: | ||
* DS101: Remove unnecessary use of Array.from | ||
* DS102: Remove unnecessary code created because of implicit returns | ||
* DS103: Rewrite code to no longer use __guard__ | ||
* DS104: Avoid inline assignments | ||
* DS201: Simplify complex destructure assignments | ||
* DS204: Change includes calls to have a more natural evaluation order | ||
* DS207: Consider shorter variations of null checks | ||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md | ||
*/ | ||
const path = require('path'); | ||
@@ -30,61 +13,59 @@ const fs = require('fs'); | ||
'noflo-nodejs', | ||
'noflo-browser' | ||
'noflo-browser', | ||
]; | ||
var listComponents = function (componentDir, options, callback) { | ||
function listComponents(componentDir, options, callback) { | ||
readdir(componentDir) | ||
.then(function (entries) { | ||
const potential = entries.filter(function (c) { | ||
let needle; | ||
return (needle = path.extname(c), [ | ||
'.coffee', | ||
'.js', | ||
'.litcoffee' | ||
].includes(needle)); | ||
}); | ||
return Promise.filter(potential, function (p) { | ||
.then((entries) => { | ||
const potentialComponents = entries.filter((c) => [ | ||
'.coffee', | ||
'.ts', | ||
'.js', | ||
'.litcoffee', | ||
].includes(path.extname(c))); | ||
return Promise.filter(potentialComponents, (p) => { | ||
const componentPath = path.resolve(componentDir, p); | ||
return stat(componentPath) | ||
.then(stats => stats.isFile()); | ||
}).then(potential => | ||
Promise.map(potential, function (p) { | ||
const componentPath = path.resolve(componentDir, p); | ||
const component = { | ||
name: null, | ||
path: path.relative(options.root, componentPath), | ||
source: path.relative(options.root, componentPath), | ||
elementary: true | ||
}; | ||
return readfile(componentPath, 'utf-8') | ||
.then(function (source) { | ||
component.name = utils.parseId(source, componentPath); | ||
component.runtime = utils.parsePlatform(source); | ||
// Default to NoFlo on any platform | ||
if (['all', null].includes(component.runtime)) { component.runtime = 'noflo'; } | ||
return Promise.resolve(component); | ||
}); | ||
})).then(function (components) { | ||
const potentialDirs = entries.filter(entry => !Array.from(potential).includes(entry)); | ||
.then((stats) => stats.isFile()); | ||
}).then((potential) => Promise.map(potential, (p) => { | ||
const componentPath = path.resolve(componentDir, p); | ||
const component = { | ||
name: null, | ||
path: path.relative(options.root, componentPath), | ||
source: path.relative(options.root, componentPath), | ||
elementary: true, | ||
}; | ||
return readfile(componentPath, 'utf-8') | ||
.then((source) => { | ||
component.name = utils.parseId(source, componentPath); | ||
component.runtime = utils.parsePlatform(source); | ||
// Default to NoFlo on any platform | ||
if (['all', null].includes(component.runtime)) { component.runtime = 'noflo'; } | ||
return Promise.resolve(component); | ||
}); | ||
})).then((comps) => { | ||
let components = comps; | ||
const potentialDirs = entries.filter((entry) => !potentialComponents.includes(entry)); | ||
if (!potentialDirs.length) { return Promise.resolve(components); } | ||
if (!options.subdirs) { return Promise.resolve(components); } | ||
// Seek from subdirectories | ||
return Promise.filter(potentialDirs, function (d) { | ||
return Promise.filter(potentialDirs, (d) => { | ||
const dirPath = path.resolve(componentDir, d); | ||
return stat(dirPath) | ||
.then(stats => stats.isDirectory()); | ||
}).then(directories => | ||
Promise.map(directories, function (d) { | ||
const dirPath = path.resolve(componentDir, d); | ||
listComponents = Promise.promisify(listComponents); | ||
return listComponents(dirPath, options); | ||
})).then(function (subDirs) { | ||
for (let subComponents of Array.from(subDirs)) { | ||
.then((stats) => stats.isDirectory()); | ||
}).then((directories) => Promise.map(directories, (d) => { | ||
const dirPath = path.resolve(componentDir, d); | ||
return Promise.promisify(listComponents)(dirPath, options); | ||
})).then((subDirs) => { | ||
subDirs.forEach((subComponents) => { | ||
components = components.concat(subComponents); | ||
} | ||
}); | ||
return Promise.resolve(components); | ||
}); | ||
}); | ||
}).then(components => | ||
Promise.resolve(components.filter(c => Array.from(supportedRuntimes).includes(c.runtime)) | ||
)).nodeify(function (err, components) { | ||
}) | ||
.then((components) => Promise.resolve(components.filter( | ||
(c) => supportedRuntimes.includes(c.runtime), | ||
))) | ||
.nodeify((err, components) => { | ||
if (err && (err.code === 'ENOENT')) { return callback(null, []); } | ||
@@ -95,57 +76,58 @@ if (err) { return callback(err); } | ||
return null; | ||
}; | ||
} | ||
const listGraphs = function (componentDir, options, callback) { | ||
function listGraphs(componentDir, options, callback) { | ||
readdir(componentDir) | ||
.then(function (components) { | ||
const potential = components.filter(function (c) { | ||
let needle; | ||
return (needle = path.extname(c), [ | ||
'.json', | ||
'.fbp' | ||
].includes(needle)); | ||
}); | ||
return Promise.filter(potential, function (p) { | ||
.then((components) => { | ||
const potentialGraphs = components.filter((c) => [ | ||
'.json', | ||
'.fbp', | ||
].includes(path.extname(c))); | ||
return Promise.filter(potentialGraphs, (p) => { | ||
const componentPath = path.resolve(componentDir, p); | ||
return stat(componentPath) | ||
.then(stats => stats.isFile()); | ||
}).then(potential => | ||
Promise.map(potential, function (p) { | ||
const componentPath = path.resolve(componentDir, p); | ||
const component = { | ||
name: null, | ||
path: path.relative(options.root, componentPath), | ||
source: path.relative(options.root, componentPath), | ||
elementary: false | ||
}; | ||
return readfile(componentPath, 'utf-8') | ||
.then(function (source) { | ||
if (path.extname(component.path) === '.fbp') { | ||
component.name = utils.parseId(source, componentPath); | ||
component.runtime = utils.parsePlatform(source); | ||
return Promise.resolve(component); | ||
} | ||
const graph = JSON.parse(source); | ||
component.name = (graph.properties != null ? graph.properties.id : undefined) || utils.parseId(source, componentPath); | ||
component.runtime = __guard__(graph.properties != null ? graph.properties.environment : undefined, x => x.type) || null; | ||
if (graph.properties != null ? graph.properties.main : undefined) { | ||
if (!component.noflo) { component.noflo = {}; } | ||
component.noflo.main = graph.properties.main; | ||
} | ||
.then((stats) => stats.isFile()); | ||
}).then((potential) => Promise.map(potential, (p) => { | ||
const componentPath = path.resolve(componentDir, p); | ||
const component = { | ||
name: null, | ||
path: path.relative(options.root, componentPath), | ||
source: path.relative(options.root, componentPath), | ||
elementary: false, | ||
}; | ||
return readfile(componentPath, 'utf-8') | ||
.then((source) => { | ||
if (path.extname(component.path) === '.fbp') { | ||
component.name = utils.parseId(source, componentPath); | ||
component.runtime = utils.parsePlatform(source); | ||
return Promise.resolve(component); | ||
}).then(function (component) { | ||
// Default to NoFlo on any platform | ||
if (['all', null].includes(component.runtime)) { component.runtime = 'noflo'; } | ||
return Promise.resolve(component); | ||
}); | ||
}) | ||
); | ||
}).then(components => | ||
Promise.resolve(components.filter(function (c) { | ||
} | ||
const graph = JSON.parse(source); | ||
if (graph.properties && graph.properties.id) { | ||
component.name = graph.properties.id; | ||
} else { | ||
component.name = utils.parseid(source, componentPath); | ||
} | ||
component.runtime = null; | ||
if (graph.properties && graph.properties.environment) { | ||
component.runtime = graph.properties.environment; | ||
} | ||
if (graph.properties != null ? graph.properties.main : undefined) { | ||
if (!component.noflo) { component.noflo = {}; } | ||
component.noflo.main = graph.properties.main; | ||
} | ||
return Promise.resolve(component); | ||
}).then((c) => { | ||
const comp = c; | ||
// Default to NoFlo on any platform | ||
if (['all', null].includes(comp.runtime)) { comp.runtime = 'noflo'; } | ||
return Promise.resolve(comp); | ||
}); | ||
})); | ||
}).then((components) => Promise.resolve(components.filter((c) => { | ||
// Don't register "main" graphs as modules | ||
if (c.noflo != null ? c.noflo.main : undefined) { return false; } | ||
// Skip non-supported runtimes | ||
return Array.from(supportedRuntimes).includes(c.runtime); | ||
}) | ||
)).nodeify(function (err, components) { | ||
if (c.noflo != null ? c.noflo.main : undefined) { return false; } | ||
// Skip non-supported runtimes | ||
return Array.from(supportedRuntimes).includes(c.runtime); | ||
}))).nodeify((err, components) => { | ||
if (err && (err.code === 'ENOENT')) { return callback(null, []); } | ||
@@ -156,8 +138,8 @@ if (err) { return callback(err); } | ||
return null; | ||
}; | ||
} | ||
const getModuleInfo = function (baseDir, options, callback) { | ||
function getModuleInfo(baseDir, options, callback) { | ||
const packageFile = path.resolve(baseDir, 'package.json'); | ||
return readfile(packageFile, 'utf-8') | ||
.catch(function (e) { | ||
.catch((e) => { | ||
if ((e != null ? e.code : undefined) !== 'ENOENT') { return Promise.reject(e); } | ||
@@ -167,11 +149,11 @@ // Fake package with just dirname | ||
name: path.basename(baseDir), | ||
description: null | ||
description: null, | ||
}); | ||
}).then(function (json) { | ||
}).then((json) => { | ||
if (typeof json === 'object') { return Promise.resolve(json); } | ||
return Promise.resolve(JSON.parse(json)); | ||
}).then(function (packageData) { | ||
}).then((packageData) => { | ||
const module = { | ||
name: packageData.name, | ||
description: packageData.description | ||
description: packageData.description, | ||
}; | ||
@@ -189,7 +171,8 @@ | ||
if (module.name === 'noflo') { module.name = ''; } | ||
if (module.name[0] === '@') { module.name = module.name.replace(/\@[a-z\-]+\//, ''); } | ||
if (module.name[0] === '@') { module.name = module.name.replace(/@[a-z-]+\//, ''); } | ||
module.name = module.name.replace('noflo-', ''); | ||
return Promise.resolve(module); | ||
}).nodeify(function (err, module) { | ||
}) | ||
.nodeify((err, module) => { | ||
if (err && (err.code === 'ENOENT')) { return callback(null, null); } | ||
@@ -199,5 +182,5 @@ if (err) { return callback(err); } | ||
}); | ||
}; | ||
} | ||
exports.list = function (baseDir, options, callback) { | ||
exports.list = (baseDir, options, callback) => { | ||
const listC = Promise.promisify(listComponents); | ||
@@ -209,21 +192,23 @@ const listG = Promise.promisify(listGraphs); | ||
listC(path.resolve(baseDir, 'components/'), options), | ||
listG(path.resolve(baseDir, 'graphs/'), options) | ||
listG(path.resolve(baseDir, 'graphs/'), options), | ||
]) | ||
.then(function (...args) { | ||
.then((...args) => { | ||
const [module, components, graphs] = Array.from(args[0]); | ||
if (!module) { return Promise.resolve([]); } | ||
const runtimes = {}; | ||
for (var c of Array.from(components)) { | ||
if (!runtimes[c.runtime]) { runtimes[c.runtime] = []; } | ||
runtimes[c.runtime].push(c); | ||
delete c.runtime; | ||
} | ||
for (c of Array.from(graphs)) { | ||
if (!runtimes[c.runtime]) { runtimes[c.runtime] = []; } | ||
runtimes[c.runtime].push(c); | ||
delete c.runtime; | ||
} | ||
components.forEach((c) => { | ||
const component = c; | ||
if (!runtimes[component.runtime]) { runtimes[component.runtime] = []; } | ||
runtimes[component.runtime].push(component); | ||
delete component.runtime; | ||
}); | ||
graphs.forEach((c) => { | ||
const component = c; | ||
if (!runtimes[component.runtime]) { runtimes[component.runtime] = []; } | ||
runtimes[component.runtime].push(component); | ||
delete component.runtime; | ||
}); | ||
const modules = []; | ||
for (let k in runtimes) { | ||
Object.keys(runtimes).forEach((k) => { | ||
const v = runtimes[k]; | ||
@@ -237,8 +222,10 @@ modules.push({ | ||
icon: module.icon, | ||
components: v | ||
components: v, | ||
}); | ||
} | ||
}); | ||
if ((graphs.length === 0) && (components.length === 0) && (module.noflo != null ? module.noflo.loader : undefined)) { | ||
// Component that only provides a custom loader, register for "noflo" | ||
if ((graphs.length === 0) | ||
&& (components.length === 0) | ||
&& (module.noflo != null ? module.noflo.loader : undefined)) { | ||
// Component that only provides a custom loader, register for "noflo" | ||
modules.push({ | ||
@@ -251,3 +238,4 @@ name: module.name, | ||
icon: module.icon, | ||
components: []}); | ||
components: [], | ||
}); | ||
} | ||
@@ -259,8 +247,8 @@ | ||
exports.listDependencies = function (baseDir, options, callback) { | ||
exports.listDependencies = (baseDir, options, callback) => { | ||
const depsDir = path.resolve(baseDir, 'node_modules/'); | ||
return readdir(depsDir) | ||
.then(function (deps) { | ||
deps = deps.filter(d => d[0] !== '.'); | ||
return Promise.map(deps, function (d) { | ||
.then((deps) => { | ||
const suitableDeps = deps.filter((d) => d[0] !== '.'); | ||
return Promise.map(suitableDeps, (d) => { | ||
const depsPath = path.resolve(depsDir, d); | ||
@@ -271,9 +259,11 @@ if (d[0] !== '@') { | ||
return readdir(depsPath) | ||
.then(subDeps => Promise.resolve(subDeps.map(s => path.resolve(depsPath, s)))); | ||
}).then(function (depsPaths) { | ||
deps = []; | ||
for (let d of Array.from(depsPaths)) { deps = deps.concat(d); } | ||
return Promise.resolve(deps); | ||
.then((subDeps) => Promise.resolve(subDeps.map((s) => path.resolve(depsPath, s)))); | ||
}).then((depsPaths) => { | ||
let selectedDeps = []; | ||
depsPaths.forEach((d) => { | ||
selectedDeps = selectedDeps.concat(d); | ||
}); | ||
return Promise.resolve(selectedDeps); | ||
}); | ||
}).nodeify(function (err, deps) { | ||
}).nodeify((err, deps) => { | ||
if (err && (err.code === 'ENOENT')) { return callback(null, []); } | ||
@@ -284,5 +274,1 @@ if (err) { return callback(err); } | ||
}; | ||
function __guard__ (value, transform) { | ||
return (typeof value !== 'undefined' && value !== null) ? transform(value) : undefined; | ||
} |
@@ -13,3 +13,3 @@ /* eslint-disable | ||
exports.parseId = function (source, filepath) { | ||
exports.parseId = (source, filepath) => { | ||
const id = source.match(/@name ([A-Za-z0-9]+)/); | ||
@@ -20,3 +20,3 @@ if (id) { return id[1]; } | ||
exports.parsePlatform = function (source) { | ||
exports.parsePlatform = (source) => { | ||
const runtimeType = source.match(/@runtime ([a-z\-]+)/); | ||
@@ -23,0 +23,0 @@ if (runtimeType) { return runtimeType[1]; } |
@@ -1,39 +0,30 @@ | ||
/* eslint-disable | ||
no-unused-vars, | ||
*/ | ||
// TODO: This file was updated by bulk-decaffeinate. | ||
// Fix any style issues and re-enable lint. | ||
/* | ||
* decaffeinate suggestions: | ||
* DS101: Remove unnecessary use of Array.from | ||
* DS102: Remove unnecessary code created because of implicit returns | ||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md | ||
*/ | ||
let main; | ||
const program = require('commander'); | ||
const loader = require('./load'); | ||
const countStats = function (baseDir, options, callback) { | ||
options.recursive = true; | ||
return loader.load(baseDir, options, function (err, manifest) { | ||
function countStats(baseDir, options, callback) { | ||
const opts = { | ||
...options, | ||
recursive: true, | ||
}; | ||
return loader.load(baseDir, opts, (err, manifest) => { | ||
if (err) { return callback(err); } | ||
let local = 0; | ||
let deps = 0; | ||
for (let module of Array.from(manifest.modules)) { | ||
manifest.modules.forEachj((module) => { | ||
if (module.base === '') { | ||
local += module.components.length; | ||
continue; | ||
return; | ||
} | ||
deps += module.components.length; | ||
} | ||
}); | ||
return callback(null, { | ||
local, | ||
deps | ||
} | ||
); | ||
deps, | ||
}); | ||
}); | ||
}; | ||
} | ||
exports.main = (main = function () { | ||
const list = val => val.split(','); | ||
const program = require('commander') | ||
exports.main = () => { | ||
const list = (val) => val.split(','); | ||
program | ||
.option('--runtimes <runtimes>', 'List components from runtimes', list) | ||
@@ -48,3 +39,3 @@ .option('--manifest <manifest>', 'Manifest file to use. Default is fbp.json', 'fbp.json') | ||
return countStats(program.args[0], program, function (err, stats) { | ||
return countStats(program.args[0], program, (err, stats) => { | ||
let reuse; | ||
@@ -66,2 +57,2 @@ if (err) { | ||
}); | ||
}); | ||
}; |
@@ -1,13 +0,1 @@ | ||
/* eslint-disable | ||
no-unused-vars, | ||
*/ | ||
// TODO: This file was updated by bulk-decaffeinate. | ||
// Fix any style issues and re-enable lint. | ||
/* | ||
* decaffeinate suggestions: | ||
* DS101: Remove unnecessary use of Array.from | ||
* DS102: Remove unnecessary code created because of implicit returns | ||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md | ||
*/ | ||
let main; | ||
const tv4 = require('tv4'); | ||
@@ -17,2 +5,3 @@ const path = require('path'); | ||
const Promise = require('bluebird'); | ||
const program = require('commander'); | ||
@@ -22,18 +11,17 @@ const readdir = Promise.promisify(fs.readdir); | ||
const loadSchemas = function (callback) { | ||
function loadSchemas(callback) { | ||
const schemaPath = path.resolve(__dirname, '../schema'); | ||
return readdir(schemaPath) | ||
.then(files => | ||
Promise.map(files, function (file) { | ||
const filePath = path.resolve(schemaPath, file); | ||
return readfile(filePath, 'utf-8') | ||
.then(content => Promise.resolve(JSON.parse(content))); | ||
})).nodeify(callback); | ||
}; | ||
.then((files) => Promise.map(files, (file) => { | ||
const filePath = path.resolve(schemaPath, file); | ||
return readfile(filePath, 'utf-8') | ||
.then((content) => Promise.resolve(JSON.parse(content))); | ||
})).nodeify(callback); | ||
} | ||
exports.validateJSON = function (json, callback) { | ||
exports.validateJSON = (json, callback) => { | ||
const load = Promise.promisify(loadSchemas); | ||
return load() | ||
.then(function (schemas) { | ||
for (let schema of Array.from(schemas)) { tv4.addSchema(schema.id, schema); } | ||
.then((schemas) => { | ||
schemas.forEach((schema) => tv4.addSchema(schema.id, schema)); | ||
const result = tv4.validateResult(json, 'manifest.json'); | ||
@@ -45,12 +33,10 @@ if (!result.valid) { return Promise.reject(result.error); } | ||
exports.validateFile = (file, callback) => | ||
readfile(file, 'utf-8') | ||
.then(contents => Promise.resolve(JSON.parse(contents))).nodeify(function (err, manifest) { | ||
if (err) { return callback(err); } | ||
return exports.validateJSON(manifest, callback); | ||
}) | ||
; | ||
exports.validateFile = (file, callback) => readfile(file, 'utf-8') | ||
.then((contents) => Promise.resolve(JSON.parse(contents))).nodeify((err, manifest) => { | ||
if (err) { return callback(err); } | ||
return exports.validateJSON(manifest, callback); | ||
}); | ||
exports.main = (main = function () { | ||
const program = require('commander') | ||
exports.main = () => { | ||
program | ||
.arguments('<fbp.json>') | ||
@@ -65,3 +51,3 @@ .parse(process.argv); | ||
const fileName = path.resolve(process.cwd(), program.args[0]); | ||
return exports.validateFile(fileName, function (err, valid) { | ||
return exports.validateFile(fileName, (err) => { | ||
if (err) { | ||
@@ -74,2 +60,2 @@ console.log(err); | ||
}); | ||
}); | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12
49
87
5
50639
1059
+ Addedcommander@5.1.0(transitive)
- Removedcommander@2.20.3(transitive)
Updatedcommander@^5.1.0