-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgulpfile.js
158 lines (144 loc) · 3.8 KB
/
gulpfile.js
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/**
* Gulpfile for DaisyJS
* By Waren Gonzaga
**/
// gulp packages
const gulp = require('gulp');
const fs = require('fs');
const clean = require('gulp-clean');
const rename = require('gulp-rename');
const header = require('gulp-header');
const jshint = require('gulp-jshint');
const stylish = require('jshint-stylish');
const uglify = require('gulp-uglify');
const options = require('gulp-options');
const pipeline = require('readable-stream').pipeline;
// gulp paths
const path = {
build: './prod',
source: './src'
};
// copyright label
const pkg = JSON.parse(fs.readFileSync('package.json'));
const copydata = {
copybanner: [
'/*!',
' * <%= name %> - <%= homepage %>',
' * Version: <%= version %>',
' * Demo: <%= demo %>',
' * Licensed under the MIT license - http://opensource.org/licenses/MIT',
' * Copyright (c) <%= new Date().getFullYear() %> <%= author %>',
' * ',
' * Facebook: @WarenGonzagaOfficialPage',
' * Twitter: @Waren_Gonzaga',
' * Github: @WarenGonzaga',
' * Website: warengonzaga.com',
' * ',
' * Maintained and LTS Version of Particleground by jnicol',
' * https://github.com/jnicol/particleground',
' * ',
' * Donote or Support!',
' * https://buymeacoff.ee/warengonzaga',
' */\n\n',
].join('\n')
};
/**
* Gulp Tasks
* Writen by Waren Gonzaga
*/
// check scripts for production
function devcheck() {
return gulp
.src([path.source+'/daisy.js'], {allowEmpty: true})
.pipe(jshint())
.pipe(jshint.reporter(stylish))
.pipe(jshint.reporter('fail'))
.pipe(rename('daisy-v'+pkg.version+'.js'))
.pipe(gulp.dest([path.build]));
}
// minify scripts for production
function minifyjs() {
return pipeline(
gulp.src([path.build+'/daisy-v'+pkg.version+'.js']),
uglify(),
rename({
suffix: '.min',
extname: '.js'
}),
gulp.dest([path.build])
);
}
// add copyright label
function copyright() {
return gulp
.src([path.build+'/*.js'], {allowEmpty: true})
.pipe(header(copydata.copybanner, pkg))
.pipe(gulp.dest([path.build]));
}
// copy dev build to root
function copyDevJS() {
return gulp
.src([path.build+'/daisy-v'+pkg.version+'.js'], {allowEmpty: true})
.pipe(rename({
basename: 'daisy',
extname: '.js'
}))
.pipe(gulp.dest('./'));
}
//copy minified build to root
function copyMinJS() {
return gulp
.src([path.build+'/daisy-v'+pkg.version+'.min.js'], {allowEmpty: true})
.pipe(rename({
basename: 'daisy.min',
extname: '.js'
}))
.pipe(gulp.dest('./'));
}
// cleaning options
function cleanOptions() {
if(options.has('scripts')) {
return gulp
.src([path.build+'/*'], {allowEmpty: true})
.pipe(clean());
} else if (options.has('build')) {
return gulp
.src([path.build], {allowEmpty: true})
.pipe(clean());
} else if(options.has('daisy')) {
return gulp
.src('./daisy*.js', {allowEmpty: true})
.pipe(clean());
} else {
return gulp
.src([path.build], {allowEmpty: true})
.pipe(clean());
}
}
// clean production folder
function cleanprod() {
return gulp
.src('./prod', {allowEmpty: true})
.pipe(clean());
}
// clean existing builds
function cleanroot() {
return gulp
.src('./daisy*.js')
.pipe(clean());
}
// gulp series
const build = gulp.series([devcheck, minifyjs, copyright, copyDevJS, copyMinJS]);
const cleanAll = gulp.series([cleanprod, cleanroot]);
// gulp commands
exports.devcheck = devcheck;
exports.copyright = copyright;
exports.minifyjs = minifyjs;
exports.copydevjs = copyDevJS;
exports.copyminjs = copyMinJS;
exports.cleanprod = cleanprod;
exports.cleanroot = cleanroot;
exports.reset = cleanAll;
exports.clean = cleanOptions;
exports.build = build;
exports.default = build;