next-format
Advanced tools
Comparing version 0.0.11 to 0.0.12
{ | ||
"name": "next-format", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"description": "Opinionated es-next formatter inspired by golang fmt.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/pre63/next-format", |
@@ -12,5 +12,5 @@ # next-format | ||
## usage | ||
In any directory contining `.js` files run `nextformat` in the command line and all the javascript files will be formatted. | ||
In any directory contining `.js` files run `nextformat [path]` in the command line and all the javascript files will be formatted. `path` is optional. | ||
``` bash | ||
> nextformat | ||
> nextformat ./src/ | ||
``` | ||
@@ -17,0 +17,0 @@ |
@@ -5,5 +5,6 @@ const compose = require('oncha/compose').default | ||
const path = require('path') | ||
const crypto = require('crypto') | ||
// IMPURE | ||
const walker = dir => { | ||
const walker = lastRunTime => dir => { | ||
const many = [] | ||
@@ -17,5 +18,8 @@ const walkSync = d => { | ||
const p = `${d}/${file}` | ||
if (fs.statSync(p).isDirectory()) { | ||
const stat = fs.statSync(p) | ||
const now = new Date().getTime() | ||
if (stat.isDirectory()) { | ||
walkSync(p) | ||
} else { | ||
} else if (stat.mtime.getTime() > lastRunTime || stat.ctime.getTime() > lastRunTime) { | ||
many.push(path.relative(process.cwd(), p)) | ||
@@ -34,6 +38,15 @@ } | ||
const format = file => write(file)(next(read(file))) | ||
const format = file => { | ||
const init = read(file) | ||
const res = next(init) | ||
const plurial = count => (count > 1 ? 's' : '') | ||
init != res && write(file)(res) | ||
} | ||
const plural = count => (count === 1 ? '' : 's') | ||
const setLastRunTime = path => write(path)(Date.now()) | ||
const getLastRunTime = path => fs.existsSync(path) ? read(path) : 0 | ||
// PROGRAM | ||
@@ -47,8 +60,12 @@ const selectPathArg = () => (process.argv[2] || '').concat('/') | ||
const count = walker(selectPath()) | ||
const lastRunPath = path.resolve(__dirname, '../.last_' + crypto.createHash('md5').update(selectPath()).digest('hex')) | ||
const count = walker(getLastRunTime(lastRunPath))(selectPath()) | ||
.filter(f => f.toLowerCase().endsWith('.js')) | ||
.map(format).length | ||
setLastRunTime(lastRunPath) | ||
const seconds = (Date.now() - startDate) / 1000 | ||
console.log(`Formatted ${count} file${plurial(count)} in ${seconds}s.`) | ||
console.log(`Formatted ${count} file${plural(count)} in ${seconds}s.`) |
@@ -17,5 +17,3 @@ const assert = require('assert') | ||
const createTestData = compose( | ||
createTestObject, | ||
split('-----------------------------------')) | ||
const createTestData = compose(createTestObject, split('-----------------------------------')) | ||
@@ -22,0 +20,0 @@ const tryCatch = func => { |
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
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
18894
119
1