auto-prettier
Advanced tools
Comparing version 1.0.0 to 1.1.0
57
index.js
@@ -5,3 +5,3 @@ 'use strict' | ||
const path = require('path') | ||
const glob = require('glob') | ||
const globby = require('globby') | ||
const ignores = require('ignore')() | ||
@@ -42,25 +42,38 @@ const prettier = require('prettier') | ||
function matchFiles() { | ||
return new Promise((resolve, reject) => { | ||
glob(options.files.join(), options.glob, (err, matches) => { | ||
if (err) { | ||
reject(err) | ||
} | ||
resolve(rules.filter(matches)) | ||
}) | ||
}) | ||
let changeFileCount = 0 | ||
function filterIgnores(paths) { | ||
return Promise.resolve(rules.filter(paths)) | ||
} | ||
matchFiles().then(filenames => { | ||
filenames.forEach(filename => { | ||
const filePath = path.resolve(filename) | ||
const content = fs.readFileSync(filePath, 'utf-8') | ||
const formatted = prettier.format(content, prettierConfig) | ||
if (content !== formatted) { | ||
fs.writeFileSync(filePath, formatted, 'utf-8') | ||
log('write', filePath) | ||
} | ||
}) | ||
log('Finished') | ||
}) | ||
function findGlobMatches(files) { | ||
return globby(files, options.glob) | ||
} | ||
function writeFileIfNecessary(filename) { | ||
const filePath = path.resolve(filename) | ||
const content = fs.readFileSync(filePath, 'utf-8') | ||
const formatted = prettier.format(content, prettierConfig) | ||
if (content !== formatted) { | ||
changeFileCount++ | ||
fs.writeFileSync(filePath, formatted, 'utf-8') | ||
log('write', filePath) | ||
} | ||
} | ||
function batchWriteFiles(files) { | ||
files.forEach(writeFileIfNecessary) | ||
if (changeFileCount === 0) { | ||
log('No File Changed!') | ||
} else { | ||
log('Overwrite Finished') | ||
} | ||
} | ||
function main() { | ||
findGlobMatches(options.files).then(filterIgnores).then(batchWriteFiles) | ||
} | ||
// execute | ||
main() |
{ | ||
"name": "auto-prettier", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "", | ||
@@ -14,3 +14,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"glob": "^7.1.2", | ||
"globby": "^6.1.0", | ||
"ignore": "^3.3.3", | ||
@@ -17,0 +17,0 @@ "prettier": "^1.5.2" |
# auto-prettier | ||
> prettier with restricted rules | ||
### Features | ||
- Help you filter out ignorance in `.gitignore` | ||
- Auto resolve your project directory | ||
### Rules | ||
@@ -27,5 +32,8 @@ | ||
"auto-prettier": { | ||
"files": ["./src/**/*.js"] | ||
"files": [ | ||
"src/**/*.js", | ||
"test/**/*.js" | ||
] | ||
} | ||
} | ||
``` |
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
2569
69
39
+ Addedglobby@^6.1.0
+ Addedarray-union@1.0.2(transitive)
+ Addedarray-uniq@1.0.3(transitive)
+ Addedglobby@6.1.0(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedpify@2.3.0(transitive)
+ Addedpinkie@2.0.4(transitive)
+ Addedpinkie-promise@2.0.1(transitive)
- Removedglob@^7.1.2