-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
125 lines (111 loc) · 2.75 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
/**
* @fileoverview Gulpfile
*/
'use strict';
var path = require('path');
var gulp = require('gulp');
var del = require('del');
var connect = require('gulp-connect');
var scss = require('gulp-sass');
var jsdoc = require('gulp-jsdoc3');
var sourcemaps = require('gulp-sourcemaps');
/* Demo paths */
var DEMO_PATH = path.join(__dirname, 'demo');
var DEMO_TEMPLATE_PATH = __dirname;
var DEMO_DESTINATION_PATH = 'doc';
var demoFilePaths = ['src/**/*.js'].map(function(filePath) {
return path.join(DEMO_PATH, filePath);
});
demoFilePaths.push('README.md');
gulp.task('demo:default', ['del'], function(done) {
var config = {
opts: {
destination: path.join(DEMO_DESTINATION_PATH, '-docstrap')
}
};
gulp
.src(demoFilePaths, {
read: false
})
.pipe(jsdoc(config, done));
});
gulp.task('scss', function() {
gulp
.src('./scss/**/*.scss')
.pipe(sourcemaps.init())
.pipe(
scss({
outputStyle: 'compressed'
}).on('error', scss.logError)
)
.pipe(sourcemaps.write())
.pipe(gulp.dest('./static/styles'));
});
/**
* Generate demo document
*/
gulp.task('demo', ['del'], function(done) {
/* Demo config */
var domeConfigPath = path.join(DEMO_PATH, 'jsdoc-conf.json');
var config = require(domeConfigPath);
delete require.cache[require.resolve(domeConfigPath)]; // remove cache
config.opts.template = DEMO_TEMPLATE_PATH;
config.opts.destination = DEMO_DESTINATION_PATH;
gulp
.src(demoFilePaths, {
read: false
})
.pipe(jsdoc(config, done));
});
/**
* Watch file paths
* @type {string[]}
*/
var watchPaths = [
'demo/src/**/*.js',
'demo/jsdoc-conf.json',
'demo/samples/**/*',
'static/scripts/**/*.js',
'static/styles/**/*.css',
'tmpl/**/*.tmpl',
'publish.js'
];
/**
* Reload server
*/
gulp.task('reload', ['demo'], function() {
return gulp.src(watchPaths).pipe(connect.reload());
});
/**
* Regenerate demo document when a file changes
*/
gulp.task('watch', ['demo'], function() {
gulp.watch('scss/**/*.scss', ['scss']);
var watcher = gulp.watch(watchPaths, ['demo', 'reload']);
watcher.on('change', function(event) {
console.log(
'File: ' + event.path + ' was ' + event.type + ', running tasks...'
);
});
});
/**
* Run web server
*/
gulp.task('connect', ['demo'], function() {
connect.server({
root: DEMO_DESTINATION_PATH,
livereload: true
});
});
/**
* @command gulp serve
* Connect-server with watch
*/
gulp.task('serve', ['connect', 'watch']);
/**
* @command gulp del
* Delete all demo-doc files
*/
gulp.task('del', function() {
return del([DEMO_DESTINATION_PATH]);
});