forked from max-mapper/standard-format
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor to transform using standard-format then add semicolons
- Loading branch information
Showing
11 changed files
with
87 additions
and
592 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,9 @@ | ||
var deglob = require('deglob') | ||
var fs = require('fs') | ||
var formatter = require('esformatter') | ||
|
||
var ESFORMATTER_CONFIG = require('./rc/esformatter.json') | ||
var DEFAULT_IGNORE = [ | ||
'node_modules/**', | ||
'.git/**', | ||
'**/*.min.js', | ||
'**/bundle.js' | ||
] | ||
|
||
var MULTI_NEWLINE_N = /((?:\n){3,})/g | ||
var MULTI_NEWLINE_RN = /((?:\r\n){3,})/g | ||
|
||
var SOF_NEWLINES = /^(\r?\n)+/g | ||
|
||
module.exports.transform = function (file) { | ||
file = file | ||
.replace(MULTI_NEWLINE_N, '\n\n') | ||
.replace(MULTI_NEWLINE_RN, '\r\n\r\n') | ||
.replace(SOF_NEWLINES, '') | ||
|
||
var formatted = formatter.format(file, ESFORMATTER_CONFIG) | ||
|
||
return formatted | ||
} | ||
|
||
module.exports.load = function (opts, cb) { | ||
if (typeof opts === 'function') { | ||
cb = opts | ||
opts = {} | ||
} | ||
if (!opts) opts = {} | ||
|
||
var ignore = [].concat(DEFAULT_IGNORE) // globs to ignore | ||
if (opts.ignore) ignore = ignore.concat(opts.ignore) | ||
|
||
var deglobOpts = { | ||
ignore: ignore, | ||
cwd: opts.cwd || process.cwd(), | ||
useGitIgnore: true, | ||
usePackageJson: true, | ||
configKey: 'standard' | ||
} | ||
|
||
deglob(['**/*.js', '**/*.jsx'], deglobOpts, function (err, files) { | ||
if (err) return cb(err) | ||
|
||
files = files.map(function (f) { | ||
return { name: f, data: fs.readFileSync(f).toString() } // assume utf8 | ||
}) | ||
cb(null, files) | ||
}) | ||
var semi = require('semi') | ||
var transform = require('standard-format').transform | ||
module.exports.transform = function (text) { | ||
text = transform(text) | ||
// handle errors | ||
semi.on('error', function (err) { throw err }) | ||
|
||
return semi.add(text) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.