Comparing version 0.3.0 to 1.0.0
'use strict'; | ||
const _ = require('lodash'), | ||
fs = require('fs'), | ||
path = require('path'), | ||
@@ -10,36 +9,7 @@ IGNORED_CLAY_MODULES = [ | ||
]; | ||
var pkg = require(path.resolve(process.cwd(), 'package.json')); | ||
/** | ||
* @param {string} file | ||
* @returns {boolean} | ||
*/ | ||
function isDirectory(file) { | ||
try { | ||
return fs.statSync(file).isDirectory(); | ||
} catch (ex) { | ||
return false; | ||
} | ||
} | ||
var getFolders = require('../getFolders'), | ||
pkg = require(path.resolve(process.cwd(), 'package.json')); | ||
/** | ||
* Get folder names. | ||
* | ||
* Should only occur once per directory. | ||
* | ||
* @param {string} dir enclosing folder | ||
* @return {[]} array of folder names | ||
*/ | ||
function getFolders(dir) { | ||
try { | ||
return fs.readdirSync(dir) | ||
.filter(function (file) { | ||
return isDirectory(path.join(dir, file)); | ||
}); | ||
} catch (ex) { | ||
return []; | ||
} | ||
} | ||
/** | ||
* Get array of component names, from node_modules and components folder. | ||
@@ -71,1 +41,4 @@ * | ||
module.exports.setPackageConfiguration = (val) => { pkg = val; }; | ||
module.exports.setDeps = (gF) => { | ||
getFolders = gF; | ||
}; |
@@ -7,4 +7,2 @@ 'use strict'; | ||
sinon = require('sinon'), | ||
fs = require('fs'), | ||
path = require('path'), | ||
lib = require('./' + filename), | ||
@@ -14,14 +12,9 @@ pkg = require('../../test/fixtures/package.json'); | ||
describe(_.startCase(filename), function () { | ||
var sandbox; | ||
var sandbox, getFolders; | ||
function createMockStat(options) { | ||
return { | ||
isDirectory: _.constant(!!options.isDirectory) | ||
}; | ||
} | ||
beforeEach(function () { | ||
sandbox = sinon.sandbox.create(); | ||
sandbox.stub(fs); | ||
getFolders = sandbox.stub(); | ||
lib.setDeps(getFolders); | ||
lib.cache = new _.memoize.Cache(); | ||
@@ -38,6 +31,10 @@ | ||
describe('getComponents', function () { | ||
it('returns empty array if no components', function () { | ||
getFolders.returns([]); | ||
lib.setPackageConfiguration({ dependencies: [] }); | ||
expect(lib()).to.eql([]); | ||
}); | ||
it('gets a list of internal components', function () { | ||
fs.readdirSync.withArgs(path.join(process.cwd(), 'components')).returns(['c1', 'c2']); | ||
fs.statSync.withArgs(path.join(process.cwd(), 'components/c1')).returns(createMockStat({isDirectory: true})); | ||
fs.statSync.withArgs(path.join(process.cwd(), 'components/c2')).returns(createMockStat({isDirectory: false})); | ||
getFolders.returns(['c1', 'c2', 'c3']); | ||
@@ -48,16 +45,7 @@ expect(lib()).to.contain('c1', 'c2'); | ||
it('gets a list of npm components', function () { | ||
fs.readdirSync.withArgs('components').returns([]); | ||
sandbox.stub(path, 'resolve').returnsArg(0); | ||
getFolders.returns([]); | ||
expect(lib()).to.contain('clay-c3', 'clay-c4'); | ||
}); | ||
it('returns false if statSync fails', function () { | ||
fs.readdirSync.withArgs(path.join(process.cwd(), 'components')).returns(['c1', 'c2']); | ||
fs.statSync.withArgs(path.join(process.cwd(), 'components/c1')).returns(createMockStat({isDirectory: true})); | ||
fs.statSync.withArgs(path.join(process.cwd(), 'components/c2')).returns(new Error('not a directory')); | ||
expect(lib()).to.not.contain('c2'); | ||
}); | ||
}); | ||
}); |
'use strict'; | ||
const _ = require('lodash'), | ||
fs = require('fs'), | ||
path = require('path'); | ||
/** | ||
* @param {string} file | ||
* @returns {boolean} | ||
*/ | ||
function isDirectory(file) { | ||
try { | ||
return fs.statSync(file).isDirectory(); | ||
} catch (ex) { | ||
return false; | ||
} | ||
} | ||
let getFolders = require('../getFolders'); | ||
/** | ||
* Get folder names. | ||
* | ||
* Should only occur once per directory. | ||
* | ||
* @param {string} dir enclosing folder | ||
* @return {[]} array of folder names | ||
*/ | ||
function getFolders(dir) { | ||
try { | ||
return fs.readdirSync(dir).filter(file => isDirectory(path.join(dir, file))); | ||
} catch (ex) { | ||
return []; | ||
} | ||
} | ||
/** | ||
* Get array of layout names from layouts folder. | ||
@@ -46,1 +19,5 @@ * | ||
module.exports = _.memoize(getLayouts); | ||
// for testing | ||
module.exports.setDeps = (gF) => { | ||
getFolders = gF; | ||
}; |
@@ -7,19 +7,12 @@ 'use strict'; | ||
sinon = require('sinon'), | ||
fs = require('fs'), | ||
path = require('path'), | ||
lib = require('./' + filename); | ||
describe(_.startCase(filename), function () { | ||
var sandbox; | ||
var sandbox, getFolders; | ||
function createMockStat(options) { | ||
return { | ||
isDirectory: _.constant(!!options.isDirectory) | ||
}; | ||
} | ||
beforeEach(function () { | ||
sandbox = sinon.sandbox.create(); | ||
sandbox.stub(fs); | ||
getFolders = sandbox.stub(); | ||
lib.setDeps(getFolders); | ||
lib.cache = new _.memoize.Cache(); | ||
@@ -33,26 +26,13 @@ }); | ||
describe('getLayouts', function () { | ||
it('gets a list of internal layouts', function () { | ||
fs.readdirSync.withArgs(path.join(process.cwd(), 'layouts')).returns(['c1', 'c2']); | ||
fs.statSync.withArgs(path.join(process.cwd(), 'layouts/c1')).returns(createMockStat({isDirectory: true})); | ||
fs.statSync.withArgs(path.join(process.cwd(), 'layouts/c2')).returns(createMockStat({isDirectory: false})); | ||
expect(lib()).to.eql(['c1']); | ||
it('returns empty array if no layouts', function () { | ||
getFolders.returns([]); | ||
expect(lib()).to.eql([]); | ||
}); | ||
it('returns false if statSync errors', function () { | ||
fs.readdirSync.withArgs(path.join(process.cwd(), 'layouts')).returns(['c1', 'c2']); | ||
fs.statSync.withArgs(path.join(process.cwd(), 'layouts/c1')).returns(createMockStat({isDirectory: true})); | ||
fs.statSync.withArgs(path.join(process.cwd(), 'layouts/c2')).returns(new Error('not a layout')); | ||
it('gets a list of internal layouts', function () { | ||
getFolders.returns(['c1']); | ||
expect(lib()).to.eql(['c1']); | ||
}); | ||
it('returns an empty array if readdirSync errors', function () { | ||
fs.readdirSync.returns(new Error('read dir failed')); | ||
fs.statSync.withArgs(path.join(process.cwd(), 'layouts/c1')).returns(createMockStat({isDirectory: true})); | ||
fs.statSync.withArgs(path.join(process.cwd(), 'layouts/c2')).returns(new Error('not a layout')); | ||
expect(lib()).to.eql([]); | ||
}); | ||
}); | ||
}); |
{ | ||
"name": "amphora-fs", | ||
"version": "0.3.0", | ||
"version": "1.0.0", | ||
"description": "File system utils for Amphora and the Clay ecosystem", | ||
@@ -16,4 +16,5 @@ "main": "index.js", | ||
"clayutils": "^2.1.0", | ||
"js-yaml": "^3.10.0", | ||
"lodash": "^4.17.4" | ||
"js-yaml": "^3.12.0", | ||
"lodash": "^4.17.4", | ||
"template2env": "^1.0.4" | ||
}, | ||
@@ -20,0 +21,0 @@ "devDependencies": { |
@@ -20,10 +20,18 @@ # Amphora FS | ||
* **fileExists** [(code|tests|docs)](https://github.com/clay/amphora-fs/tree/master/lib/fileExists) | ||
* **getComponents** [(code|tests|docs)](https://github.com/clay/amphora-fs/tree/master/lib/getComponents) | ||
* **getComponentModule** [(code|tests|docs)](https://github.com/clay/amphora-fs/tree/master/lib/getComponentModule) | ||
* **getComponentName** [(code|tests|docs)](https://github.com/clay/amphora-fs/tree/master/lib/getComponentName) | ||
* **getComponentPackage** [(code|tests|docs)](https://github.com/clay/amphora-fs/tree/master/lib/getComponentPackage) | ||
* **getComponentPath** [(code|tests|docs)](https://github.com/clay/amphora-fs/tree/master/lib/getComponentPath) | ||
* **getLayouts** [(code|tests|docs)](https://github.com/clay/amphora-fs/tree/master/lib/getLayouts) | ||
* **getComponents** [(code|tests|docs)](https://github.com/clay/amphora-fs/tree/master/lib/getComponents) | ||
* **getFiles** [(code|tests|docs)](https://github.com/clay/amphora-fs/tree/master/lib/getFiles) | ||
* **getFolders** [(code|tests|docs)](https://github.com/clay/amphora-fs/tree/master/lib/getFolders) | ||
* **getIndices** [(code|tests|docs)](https://github.com/clay/amphora-fs/tree/master/lib/getIndices) | ||
* **getLayoutModule** [(code|tests|docs)](https://github.com/clay/amphora-fs/tree/master/lib/getLayoutModule) | ||
* **getLayoutName** [(code|tests|docs)](https://github.com/clay/amphora-fs/tree/master/lib/getLayoutName) | ||
* **getLayoutPath** [(code|tests|docs)](https://github.com/clay/amphora-fs/tree/master/lib/getLayoutPath) | ||
* **getIndices** [(code|tests|docs)](https://github.com/clay/amphora-fs/tree/master/lib/getIndices) | ||
* **getLayouts** [(code|tests|docs)](https://github.com/clay/amphora-fs/tree/master/lib/getLayouts) | ||
* **getSchemaPath** [(code|tests|docs)](https://github.com/clay/amphora-fs/tree/master/lib/getSchemaPath) | ||
* **getYaml** [(code|tests|docs)](https://github.com/clay/amphora-fs/tree/master/lib/getYaml) | ||
* **isDirectory** [(code|tests|docs)](https://github.com/clay/amphora-fs/tree/master/lib/isDirectory) | ||
* **readFilePromise** [(code|tests|docs)](https://github.com/clay/amphora-fs/tree/master/lib/readFilePromise) | ||
* **tryRequire** [(code|tests|docs)](https://github.com/clay/amphora-fs/tree/master/lib/tryRequire) |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
45024
47
1245
1
37
4
40
1
+ Addedtemplate2env@^1.0.4
+ Addedtemplate2env@1.0.4(transitive)
Updatedjs-yaml@^3.12.0