├── .editorconfig ├── .gitattributes ├── .gitignore ├── .npmrc ├── .travis.yml ├── index.js ├── license ├── package.json ├── readme.md └── test ├── .esformatter └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [*.yml] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.js text eol=lf 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | yarn.lock 3 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '8' 4 | - '6' 5 | - '4' 6 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const through = require('through2'); 3 | const esformatter = require('esformatter'); 4 | const PluginError = require('plugin-error'); 5 | 6 | module.exports = options => { 7 | return through.obj(function (file, enc, cb) { 8 | if (file.isNull()) { 9 | cb(null, file); 10 | return; 11 | } 12 | 13 | if (file.isStream()) { 14 | cb(new PluginError('gulp-esformatter', 'Streaming not supported')); 15 | return; 16 | } 17 | 18 | try { 19 | file.contents = Buffer.from(esformatter.format(file.contents.toString(), esformatter.rc(file.path, options))); 20 | this.push(file); 21 | } catch (err) { 22 | this.emit('error', new PluginError('gulp-esformatter', err, {fileName: file.path})); 23 | } 24 | 25 | cb(); 26 | }); 27 | }; 28 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Sindre Sorhus (sindresorhus.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gulp-esformatter", 3 | "version": "8.0.0", 4 | "description": "Beautify JavaScript code with esformatter", 5 | "license": "MIT", 6 | "repository": "sindresorhus/gulp-esformatter", 7 | "author": { 8 | "name": "Sindre Sorhus", 9 | "email": "sindresorhus@gmail.com", 10 | "url": "sindresorhus.com" 11 | }, 12 | "engines": { 13 | "node": ">=4" 14 | }, 15 | "scripts": { 16 | "test": "xo && mocha" 17 | }, 18 | "files": [ 19 | "index.js" 20 | ], 21 | "keywords": [ 22 | "gulpplugin", 23 | "javascript", 24 | "ecmascript", 25 | "js", 26 | "code", 27 | "style", 28 | "conventions", 29 | "ast", 30 | "format", 31 | "formatter", 32 | "beautify", 33 | "beautifier" 34 | ], 35 | "dependencies": { 36 | "esformatter": "^0.10.0", 37 | "plugin-error": "^0.1.2", 38 | "through2": "^2.0.0" 39 | }, 40 | "devDependencies": { 41 | "mocha": "^4.1.0", 42 | "vinyl": "^2.1.0", 43 | "xo": "*" 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Deprecated 2 | 3 | The `esformatter` project is no longer maintained. 4 | 5 | --- 6 | 7 | # gulp-esformatter [![Build Status](https://travis-ci.org/sindresorhus/gulp-esformatter.svg?branch=master)](https://travis-ci.org/sindresorhus/gulp-esformatter) 8 | 9 | > Beautify JavaScript code with [esformatter](https://github.com/millermedeiros/esformatter) 10 | 11 | *Issues with the output should be reported on the esformatter [issue tracker](https://github.com/millermedeiros/esformatter/issues).* 12 | 13 | 14 | ## Install 15 | 16 | ``` 17 | $ npm install --save-dev gulp-esformatter 18 | ``` 19 | 20 | 21 | ## Usage 22 | 23 | ```js 24 | const gulp = require('gulp'); 25 | const esformatter = require('gulp-esformatter'); 26 | 27 | gulp.task('default', () => 28 | gulp.src('src/app.js') 29 | .pipe(esformatter({indent: {value: ' '}})) 30 | .pipe(gulp.dest('dist')) 31 | ); 32 | ``` 33 | 34 | 35 | ## API 36 | 37 | ### esformatter(options) 38 | 39 | See the esformatter [options](https://github.com/millermedeiros/esformatter#esformatterformatstr-optsstring). 40 | 41 | Options are passed to [`esformatter.rc()`](https://github.com/millermedeiros/esformatter#esformatterrcfilepath-customoptionsobject). 42 | 43 | 44 | ## License 45 | 46 | MIT © [Sindre Sorhus](https://sindresorhus.com) 47 | -------------------------------------------------------------------------------- /test/.esformatter: -------------------------------------------------------------------------------- 1 | { 2 | "whiteSpace": { 3 | "after": { 4 | "ArrayExpressionComma": 0 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | /* eslint-env mocha */ 2 | 'use strict'; 3 | const path = require('path'); 4 | const assert = require('assert'); 5 | const Vinyl = require('vinyl'); 6 | const esformatter = require('..'); 7 | 8 | it('should format JS', cb => { 9 | const stream = esformatter({ 10 | preset: 'jquery' 11 | }); 12 | 13 | stream.once('data', file => { 14 | assert.equal(file.contents.toString(), 'const foo = [ 1, 2, 3 ]'); 15 | }); 16 | 17 | stream.on('end', cb); 18 | 19 | stream.end(new Vinyl({ 20 | contents: Buffer.from('const foo=[1,2,3]') 21 | })); 22 | }); 23 | 24 | it('should fetch .esformatter options from path', cb => { 25 | const stream = esformatter(); 26 | 27 | stream.on('data', file => { 28 | assert.equal(file.contents.toString(), 'const foo = [1,2,3]'); 29 | }); 30 | 31 | stream.on('end', cb); 32 | 33 | stream.end(new Vinyl({ 34 | path: path.join(__dirname, 'foo.js'), 35 | contents: Buffer.from('const foo=[1,2,3]') 36 | })); 37 | }); 38 | --------------------------------------------------------------------------------