forked from sympmarc/SPServices
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
168 lines (149 loc) · 5.1 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
159
160
161
162
163
164
165
166
167
168
"use strict";
var gulp = require('gulp');
var del = require('del');
var jshint = require('gulp-jshint');
var less = require('gulp-less');
var path = require('path');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var gulpIf = require('gulp-if');
var gutil = require('gulp-util');
var webpack = require('webpack-stream');
var sourcemaps = require('gulp-sourcemaps');
var header = require('gulp-header');
var rename = require('gulp-rename');
var ghPages = require('gulp-gh-pages');
var markdown = require('gulp-markdown');
var tap = require('gulp-tap');
var
packageFile = 'package.json',
pkg = require('./' + packageFile),
paths = {
scripts: ['src/**/*.js', '!src/jquery.SPServices Intellisense.js'],
less: ['src/less/**/*.less'],
docs: ['docs/**/*.md'],
dist: ['dist/**/*']
},
// buildDate = gulp.template.today('yyyy-mm-dd'),
// buildYear = gulp.template.today('yyyy'),
// buildId = (new Date()).getTime(),
banner = "/*\n" +
"* <%= pkg.name %> - <%= pkg.description_short %>\n" +
"* Version <%= pkg.version %>\n" +
"* @requires <%= pkg.requires %>\n" +
"*\n" +
"* Copyright (c) <%= pkg.copyright %>\n" +
"* Examples and docs at:\n" +
"* <%= pkg.homepage %>\n" +
"* Licensed under the MIT license:\n" +
"* http://www.opensource.org/licenses/mit-license.php\n" +
"*/\n" +
"/*\n" +
"* @description <%= pkg.description_long %>\n" +
"* @type jQuery\n" +
"* @name <%= pkg.name %>\n" +
"* @category Plugins/<%= pkg.name %>\n" +
"* @author <%= pkg.authors %>\n" +
// "* @build <%= pkg.name %> <%= pkg.version %> <%= grunt.template.today('yyyy-mm-dd hh:MM:ss') %>\n" +
"*/\n";
gulp.task('config', function() {
fs = require("fs");
pkg = fs.readFileSync(packageFile, "utf8");
gutil.log(pkg.toString());
});
gulp.task('clean:build', function() {
// You can use multiple globbing patterns as you would with `gulp.src`
return del(['build']);
});
// Convert .less files to .css
gulp.task('less', function () {
return gulp.src(paths.less)
.pipe(less({
paths: [ path.join(__dirname, 'less', 'includes') ]
}))
.pipe(gulp.dest('src/css'));
});
// Lint the files to catch any issues
gulp.task('lint', function() {
return gulp.src(paths.scripts)
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
// Gulp watch syntax
gulp.task('watch', ['less'], function(){
gulp.watch(paths.less, ['less']);
// Other watchers
});
gulp.task('scripts', function() {
// Minify and copy all JavaScript (except vendor scripts)
// with sourcemaps all the way down
return gulp.src(paths.scripts)
.pipe(sourcemaps.init())
// .pipe(uglify())
.pipe(header(banner, { pkg : pkg } ))
.pipe(concat('jQuery.SPServices-' + pkg.version + '.js'))
.pipe(sourcemaps.write())
.pipe(gulp.dest('build/'));
});
/*
gulp.task('fixdocs', function () {
return gulp.src(paths.docs) //paths.docs
.pipe(tap(function(file) {
gutil.log(file.path);
var tmp = file.path.split('\\');
var cat = tmp.length > 4 ? tmp[4] : '';
var name = tmp[tmp.length - 1].split('.')[0];
file.contents = Buffer.concat([
new Buffer(['---',
'label: ' + name,
'id: ' + name,
'categorySlug: \'' + cat + '\'',
'categoryLabel: \'' + cat + '\'',
'categorySort: \'alphabetical\'', // 'alphabetical' || 'rank'
'documentSort: \'alphabetical\'', // 'alphabetical' || 'rank'
'', ''].join('\n')),
file.contents
])
}))
.pipe(gulp.dest('dist/tmp'));
});
*/
gulp.task('docs', function () {
return gulp.src(paths.docs) //paths.docs
.pipe(markdown('index.html', {
yamlMeta: true,
templatePath: 'docs/index.html',
highlightTheme: 'solarized_light'
}))
.pipe(gulp.dest('dist/docs/'));
});
// Build module
gulp.task('build', function() {
return gulp.src(paths.scripts)
.pipe(webpack(require('./webpack.config.js'), null, function(err, stats) {
// Output stats so we can tell what happened
gutil.log(stats.toString());
}))
.pipe(rename('jQuery.SPServices-' + pkg.version + '.js'))
.pipe(gulp.dest('build/')) // SPServices.js
.pipe(gulpIf('*.js', uglify())) // Minify all modules
.pipe(rename('jQuery.SPServices-' + pkg.version + '.min.js'))
.pipe(gulp.dest('build/')); // SPServices.min.js
});
// Deploy to gh-pages
gulp.task('deploydocs', function() {
return gulp.src(paths.dist)
.pipe(ghPages());
});
// Default task(s).
gulp.task('default', [
'clean:build',
'lint',
'less',
'scripts',
'build'
// 'concat',
// 'copy:processBuildVariables',
// 'uglify',
// 'zip'
]);