-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
139 lines (119 loc) · 3.56 KB
/
Copy pathgulpfile.js
File metadata and controls
139 lines (119 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**
* Created by kumak7 on 25-11-2015.
*/
var paths = {
dist: './dist',
filesToCopy: [
'img/**/*',
'html/**/*',
'css/**/*',
'js/codemirror/lib/codemirror.js',
'js/codemirror/addon/hint/css-hint.js',
'js/codemirror/addon/hint/show-hint.js',
'js/codemirror/mode/css/css.js',
'js/codemirror/mode/javascript/javascript.js',
'js/codemirror/mode/xml/xml.js',
'js/codemirror/mode/htmlmixed/htmlmixed.js',
'js/codemirror/addon/hint/show-hint.css',
'js/codemirror/lib/codemirror.css',
'js/reveal.js/**/*',
'*.json',
'*.html'
]
};
var fs = require('fs');
var gulp = require('gulp');
var gutil = require('gulp-util');
var gftp = require( 'vinyl-ftp' );
var runSequence = require('run-sequence');
var argv = require('yargs').argv;
gulp.task('default', ['build']);
gulp.task('listcss', function() {
gulp
.src('css/**/*')
.pipe(require('gulp-filelist')('csslist.json'))
.pipe(gulp.dest('.'));
});
gulp.task('listhtml', function() {
gulp
.src('html/**/*')
.pipe(require('gulp-filelist')('htmllist.json'))
.pipe(gulp.dest('.'));
});
gulp.task('pack', function(done) {
if (!fs.existsSync(paths.dist)) {
fs.mkdirSync(paths.dist);
}
gulp.src(paths.filesToCopy, { base: '.' })
.pipe(gulp.dest(paths.dist))
.on('end', done);
});
gulp.task('build', function(done) {
if (!fs.existsSync(paths.dist)) {
fs.mkdirSync(paths.dist);
}
runSequence('pack','compress', 'minify-css', 'minify-html', 'listhtml', 'listcss', 'deploy', 'clean');
});
var uglify = require('gulp-uglify');
gulp.task('compress', function() {
return gulp.src('dist/**/*.js')
.pipe(uglify())
.pipe(gulp.dest('dist'));
});
var minifyCss = require('gulp-minify-css');
gulp.task('minify-css', function() {
return gulp.src('dist/js/**/*.css')
.pipe(minifyCss({compatibility: 'ie8'}))
.pipe(gulp.dest('dist'));
});
var minifyHTML = require('gulp-minify-html');
gulp.task('minify-html', function() {
var opts = {
conditionals: true,
spare:true,
cdata:true,
comments: true,
loose: true
};
return gulp.src('dist/*.html')
.pipe(minifyHTML(opts))
.pipe(gulp.dest('dist'));
});
gulp.task('clean', function() {
if (fs.existsSync(paths.dist)) {
deleteFolderRecursive(paths.dist);
}
});
/** Credit http://stackoverflow.com/a/12761924/2768444 */
function deleteFolderRecursive(path) {
var files = [];
if( fs.existsSync(path) ) {
files = fs.readdirSync(path);
files.forEach(function(file,index){
var curPath = path + "/" + file;
if(fs.lstatSync(curPath).isDirectory()) { // recurse
deleteFolderRecursive(curPath);
} else { // delete file
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(path);
}
}
gulp.task( 'deploy', function () {
var conn = gftp.create( {
host: 'ftp.ask4kapil.xyz',
user: argv.username,
pass: argv.password,
parallel: 3,
log: gutil.log
} );
var globs = [
'dist/**'
];
// using base = '.' will transfer everything to /public_html correctly
// turn off buffering in gulp.src for best performance
return gulp.src( globs, { base: 'dist', buffer: false } )
.pipe( conn.newer( '/public_html/cssintroduction' ) ) // only upload newer files
.pipe( conn.dest( '/public_html/cssintroduction' ) );
} );