Created
July 20, 2016 16:02
-
-
Save 321zeno/d055ceb0fda64a284d07a5225d2db576 to your computer and use it in GitHub Desktop.
Tabs to spaces using globally installed node modules
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
// USAGE: | |
// Assuming you have gulp installed globally | |
// npm install -g gulp-soften yargs gulp-eol gulp-trimlines path-exists | |
// gulp --folder public_html OR gulp --folder public_html/styles | |
var base = process.env.USERPROFILE + '/AppData/Roaming/', | |
node_modules = base + 'npm/node_modules/'; | |
var gulp = require(node_modules + 'gulp'); | |
var soften = require(node_modules + 'gulp-soften'), | |
argv = require(node_modules + 'yargs').argv, | |
eol = require(node_modules + 'gulp-eol'), | |
trimlines = require(node_modules + 'gulp-trimlines'), | |
pathExists = require(node_modules + 'path-exists') //part of Node | |
; | |
var pageFileTypeArray = ['html', 'php', 'htaccess', 'scss'], | |
pageFileTypes = pageFileTypeArray.join(','); | |
gulp.task('clean', function(){ | |
var isFolder = (argv.folder) ? true : false; | |
if(isFolder){ | |
var path = argv.folder; | |
if(pathExists(path)){ | |
console.log('Processed path: ' + path); | |
return gulp.src([path + '/**/*.{' + pageFileTypes + '}'], {dot: true}) | |
.pipe(soften(4)) //4 spaces | |
.pipe(eol('\r\n', false)) | |
.pipe(trimlines({ leading: false })) | |
.pipe(gulp.dest(path + '/')) | |
; | |
} else { | |
console.error('Error: Path not found at ' + path); | |
} | |
} else { | |
console.error('Error: --folder flag not set'); | |
} | |
}); | |
gulp.task('default', function(){ | |
return gulp.start('clean'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment