forked from fgpv-vpgf/geoApi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
135 lines (115 loc) · 4.13 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
/* globals -$ */
'use strict';
const gulp = require('gulp');
const del = require('del');
const yargs = require('yargs');
const args = yargs.argv;
const runSequence = require('run-sequence');
const browserify = require('browserify');
const buffer = require('vinyl-buffer');
const source = require('vinyl-source-stream');
const babelify = require('babelify');
const pkg = require('./package.json');
const $ = require('gulp-load-plugins')({ lazy: true });
const Dgeni = require('dgeni');
require('gulp-help')(gulp);
let PROD_MODE = args.prod;
/**
* --prod: generate source maps and uglify code; this is turned on when running 'gulp dist'
* --guts: skip style checks
*/
gulp.task('clean', 'Remove dist folder', function () {
del.sync('dist');
});
gulp.task('check', 'Checks code against style guidelines', function (done) {
if (args.guts) {
return done();
}
return gulp
.src(['src/**/*.js', '*.js'])
.pipe($.jshint())
.pipe($.jscs())
.pipe($.jscsStylish.combineWithHintResults()) // combine with jshint results
.pipe($.jshint.reporter('jshint-stylish', { verbose:true }))
.pipe($.jshint.reporter('fail'));
});
gulp.task('tgz', 'Generate tarball for distribution', ['build'], function () {
return gulp
.src(['dist/*.js', 'dist/*.map'])
.pipe($.tar('geoapi-' + pkg.version + '.tgz'))
.pipe($.gzip({ append: false }))
.pipe(gulp.dest('dist'));
});
gulp.task('zip', 'Generate zip for distribution', ['build'], function () {
return gulp
.src(['dist/*.js', 'dist/*.map'])
.pipe($.zip('geoapi-' + pkg.version + '.zip'))
.pipe(gulp.dest('dist'));
});
// gulp.task('dist', 'Generate tgz and zip files for distribution', ['zip', 'tgz']);
gulp.task('dist', 'Generate tgz and zip files for distribution', done => {
// turn on --prod flag to enable minification
runSequence('prod', 'check', ['zip', 'tgz'], done);
});
gulp.task('build', 'Transpile and concatenate the code', ['clean'], function () {
var b = browserify({ entries: 'src/index.js', standalone: 'geoapi' }).transform(babelify);
return b.bundle()
.pipe(source('gapi.js'))
.pipe(buffer())
.pipe($.derequire())
.pipe($.if(PROD_MODE, $.sourcemaps.init()))
/* .pipe($.babel()) */
.pipe($.concat('geoapi.js'))
/* .pipe(gulp.dest('dist/v' + pkg.version)) */
.pipe(gulp.dest('dist'))
.pipe($.if(PROD_MODE, $.rename('geoapi.min.js'))) // do not create a minified file unless --prod is provided
.pipe($.if(PROD_MODE, $.uglify()))
.pipe($.if(PROD_MODE, $.sourcemaps.write('.')))
.pipe($.if(PROD_MODE, gulp.dest('dist')));
});
gulp.task('prod', 'Sets production mode', () => PROD_MODE = true);
gulp.task('test', 'Run unit tests in jasmine', ['check', 'build'], function () {
return gulp
.src('spec/*Spec.js')
.pipe($.jasmine({ verbose: true }));
});
gulp.task('default', 'Check style and unit tests', ['check', 'test']);
gulp.task('serve', ['check', 'build'], function () {
$.connect.server({ root:'.', port:6002 });
});
/**
* Remove dgeni generated docs
*/
gulp.task('docs-clean', function (done) {
return del([
'dist/docs/**'
], done);
});
/**
* Build docs
*/
gulp.task('docs-build', ['docs-clean'], function () {
var dgeni = new Dgeni([require('./docs/config/dgeni-conf')]);
return dgeni.generate();
});
// important task: copy site resources to the app folder; images, styles, app.js
// !myDgeni/docs/app/js/**/*.txt is for exclusion.
gulp.task('docs-resources', ['docs-build'], function () {
return gulp.src(['docs/app/**/*', '!docs/app/js/**/*.txt'])
.pipe(gulp.dest('dist/docs/app'));
});
/**
* Serves the app.
* -- test : run Karma auto tests in parallel
* -- protractor: prepare index-protractor page and do not inject app-seed
*/
gulp.task('serve:docs', 'Build the docs and start a local development server', ['dgeni'],
function () {
$.connect.server({
root: './dist/docs/app/',
livereload: true,
port: '6002'
});
});
// run doc generation
gulp.task('dgeni', ['docs-resources']);