Last active
December 24, 2017 02:54
-
-
Save u01jmg3/15d98940b7a9cf3f1cfa to your computer and use it in GitHub Desktop.
Convert all PHP/HTML files within a specified folder (and its subfolders) to use 4 spaces over tabs and `\n` for all line endings - *LOCAL*
This file contains hidden or 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
'use strict'; | |
var gulp = require('gulp'); | |
var soften = require('gulp-soften'), | |
argv = require('yargs').argv, | |
eol = require('gulp-eol'), | |
trimlines = require('gulp-trimlines'), | |
pathExists = require('path-exists'), | |
gulpIgnore = require('gulp-ignore') | |
; | |
var pageFileTypeArray = ['php'], | |
pageFileTypes = pageFileTypeArray.join(','); | |
gulp.task('clean', function(){ | |
var isFolder = (argv.folder) ? true : false; | |
if (isFolder) { | |
var path = argv.folder; | |
if (pathExists(path)) { | |
var d = new Date(); | |
var t = ('0' + d.getHours()).slice(-2) + ':' + ('0' + d.getMinutes()).slice(-2) + ':' + ('0' + d.getSeconds()).slice(-2); | |
console.log('[' + t + '] Processing path: ' + path); | |
if (pageFileTypeArray.length > 1) { | |
pageFileTypes = '{' + pageFileTypes + '}'; | |
} | |
return gulp.src([path + '/**/*.' + pageFileTypes], { dot: true }) | |
.pipe(gulpIgnore.exclude('**/node_modules/**')) | |
.pipe(gulpIgnore.exclude('**/vendor/**')) | |
.pipe(soften(4)) //4 spaces | |
.pipe(eol('\n', true)) | |
.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'); | |
}); | |
// USAGE: | |
// npm install gulp gulp-soften yargs gulp-eol gulp-trimlines path-exists gulp-ignore | |
// gulp --folder public_html OR gulp --folder public_html/styles |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ℹ️