Remove lodash dependency

This commit is contained in:
Jeroen Engels 2017-06-16 18:19:37 +02:00
parent f15c3d0374
commit 166699e294
3 changed files with 9 additions and 15 deletions

View File

@ -1,18 +1,21 @@
const path = require('path');
const _ = require('lodash');
const fs = require('fs-extra');
const glob = require('glob');
const defaultGlob = '**/*.elm';
const ignore = ['**/elm-stuff/**', '**/node_modules/**', 'lintingDir/**'];
function flatMap(array, fn) {
return array.reduce((res, item) => res.concat(fn(item)), []);
}
function getFiles(filename) {
if (!fs.existsSync(filename)) {
return [];
}
if (fs.lstatSync(filename).isDirectory()) {
console.log(candidate);
return _.flatMap(
return flatMap(
glob.sync('/' + defaultGlob, {
root: filename,
nocase: true,
@ -28,9 +31,7 @@ function getFiles(filename) {
// Recursively search directories for *.elm files, excluding elm-stuff/
function resolveFilePath(filename) {
// Exclude everything having anything to do with elm-stuff
return getFiles(filename).filter(
candidate => !candidate.split(path.sep).includes('elm-stuff')
);
return getFiles(filename).filter(candidate => !candidate.split(path.sep).includes('elm-stuff'));
}
function globify(filename) {
@ -52,17 +53,16 @@ function globifyWithRoot(root, filename) {
function getElmFilePaths(filePathArgs) {
if (filePathArgs.length > 0) {
return _.flatMap(filePathArgs, globify);
return flatMap(filePathArgs, globify);
}
const root = path.join(path.resolve(process.cwd()), '..');
return globifyWithRoot(root, '**/*.elm');
}
function getElmFiles(filePathArgs) {
const relativeElmFiles = getElmFilePaths(filePathArgs);
return _.flatMap(relativeElmFiles, resolveFilePath).map(file => {
return flatMap(relativeElmFiles, resolveFilePath).map(file => {
return {
filename: file,
source: fs.readFileSync(file, 'utf8')

View File

@ -45,11 +45,6 @@
"version": "https://registry.npmjs.org/jsonfile/-/jsonfile-3.0.0.tgz",
"integrity": "sha1-kufHRE5f/V+jLmqa6LhQNN+DR9A="
},
"lodash": {
"version": "4.17.4",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz",
"integrity": "sha1-eCA6TRwyiuHYbcpkYONptX9AVa4="
},
"minimatch": {
"version": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
"integrity": "sha1-UWbihkV/AzBgZL5Ul+jbsMPTIIM="

View File

@ -11,7 +11,6 @@
"license": "ISC",
"dependencies": {
"fs-extra": "^3.0.1",
"glob": "^7.1.2",
"lodash": "^4.17.4"
"glob": "^7.1.2"
}
}