Comparing version 2.0.1 to 3.0.0
#!/usr/bin/env node | ||
// Based on https://gist.github.com/oculus42/99092766633ca2451e9d6e2217a94a80 | ||
const methods = require('../src/methods'); | ||
const configs = require('../src/configs'); | ||
@@ -10,28 +10,26 @@ const defaultArgs = ['airbnb']; | ||
if (!module.parent) { | ||
// Directly invoked. | ||
// Directly invoked. | ||
// Slice out the script from the args | ||
const origArgs = process.argv.slice(process.argv[0].endsWith('node') ? 2 : 1); | ||
// Slice out the script from the args | ||
const origArgs = process.argv.slice(process.argv[0].endsWith('node') ? 2 : 1); | ||
// Optional default logic if no arguments were provided | ||
const myArgs = origArgs.length < 3 ? defaultArgs : origArgs; | ||
const method = myArgs[0]; | ||
const myArgs = !origArgs.length ? defaultArgs : origArgs; | ||
const configName = myArgs[0]; | ||
// Check if the argument is one of our named methods | ||
if (methods[method]) { | ||
// Args arrive as strings, so this might need more work. | ||
// Arrays and Objects are probably not convenient. | ||
// Check if the argument is one of our named configs | ||
if (configs[configName]) { | ||
// Args arrive as strings, so this might need more work. | ||
// Arrays and Objects are probably not convenient. | ||
console.log(`Installing ${configName}`); | ||
console.log(`Installing ${method}`); | ||
// Execute our method with the rest of the command-line arguments | ||
methods[method].apply(null, myArgs.slice(1)) | ||
.then(({data}) => console.log(data), err => console.error(err)); | ||
} else { | ||
// You could put a default here if you don't want it to use the methods above | ||
console.log('The method you requested was not found.'); | ||
} | ||
// Execute our configName with the rest of the command-line arguments | ||
configs[configName].apply(null, myArgs.slice(1)) | ||
.then(({ data }) => console.log(data), err => console.error(err)); | ||
} else { | ||
// You could put a default here if you don't want it to use the configs above | ||
console.log('The config you requested was not found.'); | ||
} | ||
} else { | ||
// Required by another file | ||
module.exports = methods; | ||
// Required by another file | ||
module.exports = configs; | ||
} |
@@ -1,3 +0,1 @@ | ||
// Based on https://gist.github.com/oculus42/99092766633ca2451e9d6e2217a94a80 | ||
module.exports = require('./src/methods'); | ||
module.exports = require('./src/configs'); |
@@ -15,2 +15,9 @@ { | ||
}, | ||
"devDependencies": { | ||
"eslint": "^4.19.1", | ||
"eslint-config-airbnb": "^16.1.0", | ||
"eslint-plugin-import": "^2.11.0", | ||
"eslint-plugin-jsx-a11y": "^6.0.3", | ||
"eslint-plugin-react": "^7.7.0" | ||
}, | ||
"description": "Linter", | ||
@@ -31,3 +38,3 @@ "homepage": "https://github.com/oculus42/eastwood#readme", | ||
}, | ||
"version": "2.0.1" | ||
"version": "3.0.0" | ||
} |
@@ -1,9 +0,8 @@ | ||
# eastwood | ||
# Eastwood | ||
[![npm](https://img.shields.io/npm/v/eastwood.svg)](https://www.npmjs.com/package/eastwood) | ||
## Do you feel linty? | ||
Eastwood aims to provide simple setup of ESLint and editor configurations. | ||
3.0.0 correctly installs packages as devDependencies. | ||
`eastwood` aims to provide automated install and setup of various linting rulesets. | ||
## Installation | ||
@@ -21,1 +20,19 @@ | ||
### Supported Rulesets | ||
* `airbnb` - The [Airbnb Style Guide](http://airbnb.io/javascript/) as provided by [eslint-config-airbnb](https://www.npmjs.com/package/eslint-config-airbnb). | ||
* `airbnb-base` - Airbnb without React support as provided by [eslint-config-airbnb-base](https://www.npmjs.com/package/eslint-config-airbnb-base). | ||
* `google` - The [Google Style Guide](https://google.github.io/styleguide/jsguide.html) as provided by [eslint-config-google](https://www.npmjs.com/package/eslint-config-google). | ||
If no ruleset is provided, `airbnb` is used as default. | ||
## Plans | ||
* Updating `.eslintrc` rather than just an initial write. | ||
* Updating ``.editorconfig` rather than just an initial write. | ||
And maybe: | ||
* Prettier? | ||
* Plugin support for configs? | ||
* Who knows? |
@@ -5,34 +5,40 @@ const fs = require('fs'); | ||
const hasPackageFile = filename => pkgDir() | ||
.then((dir) => { | ||
if (dir === null) { | ||
return Promise.reject(new ReferenceError('Directory not found')); | ||
} | ||
const path = `${dir}/${filename}`; | ||
const hasEslintRc = () => { | ||
return pkgDir() | ||
.then(dir => { | ||
if (dir === null) { | ||
Promise.reject(new ReferenceError('Directory not found')); | ||
} | ||
return { | ||
path: dir + '/.eslintrc', | ||
exists: fs.existsSync(dir + '/.eslintrc') | ||
}; | ||
}); | ||
}; | ||
return { | ||
path, | ||
exists: fs.existsSync(path), | ||
}; | ||
}); | ||
const editLintRc = (data, overwrite) => { | ||
return hasEslintRc() | ||
.then(({path, exists}) => { | ||
if (!exists || overwrite) { | ||
return new Promise((resolve, reject) => { | ||
fs.writeFile(path, data, (err) => { | ||
if (err) { | ||
reject(err); | ||
} | ||
resolve(true); | ||
}) | ||
}); | ||
} | ||
const editPackageFile = (filename, data, overwrite) => hasPackageFile(filename) | ||
.then(({ path, exists }) => { | ||
if (!exists || overwrite) { | ||
return new Promise((resolve, reject) => { | ||
fs.writeFile(path, data, (err) => { | ||
if (err) { | ||
reject(err); | ||
} | ||
resolve(true); | ||
}); | ||
}; | ||
}); | ||
} | ||
return Promise.resolve(false); | ||
}); | ||
const chainEdit = (filename, data, overwrite) => | ||
(log = { data: '' }) => editPackageFile(filename, data, overwrite) | ||
.then(written => ({ | ||
data: `${log.data}\n${filename} ${written ? '' : 'not '}written`, | ||
})); | ||
module.exports = { | ||
editLintRc | ||
chainEdit, | ||
editPackageFile, | ||
hasPackageFile, | ||
}; |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
7635
12
153
38
5
1