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

View File

@ -45,11 +45,6 @@
"version": "https://registry.npmjs.org/jsonfile/-/jsonfile-3.0.0.tgz", "version": "https://registry.npmjs.org/jsonfile/-/jsonfile-3.0.0.tgz",
"integrity": "sha1-kufHRE5f/V+jLmqa6LhQNN+DR9A=" "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": { "minimatch": {
"version": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "version": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
"integrity": "sha1-UWbihkV/AzBgZL5Ul+jbsMPTIIM=" "integrity": "sha1-UWbihkV/AzBgZL5Ul+jbsMPTIIM="

View File

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