forked from bline/bootstrap-webpack-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
148 lines (131 loc) · 4.73 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
/*
* Copyright (C) 2014 Scott Beck, all rights reserved
*
* Licensed under the MIT license
*
*/
(function () {
'use strict';
// ## Setup
var _ = require('lodash');
var del = require("del");
var gulp = require("gulp");
var $ = require('gulp-load-plugins')();
var opn = require('opn');
var marked = require('marked');
var part = require('code-part');
// [Karma](http://karma-runner.github.io/) for running browser tests
// in [PhantomJS](http://phantomjs.org/).
var karma = require('karma').server;
// Load config for webpack target below.
// karma.conf.js uses the same configuration file.
var webpackConfig = require("./webpack.config.js");
// [Karma](http://karma-runner.github.io/) needs a full path to the config file.
var KarmaConfig = require('path').join(__dirname, './karma.conf.js');
// Sources for generating `index.html`.
var IndexSources = [
'index.js',
'index.html',
'webpack.config.js',
'gulpfile.js',
'karma.conf.js',
'style.less',
'bootstrap.config.less',
'bootstrap.config.js'
];
// ## Helper Functions
// ### highlight
// Returns code with [google-code-prettify](https://code.google.com/p/google-code-prettify/)
// markup setup to use line numbers started at specified line. Used in both docco and
// doccoHtml to add prettify markup to the code sections of the docs.
var highlight = function (code, startLine) {
var html = '<?prettify';
if (_.isNumber(startLine))
html += ' linenums=' + startLine;
html += '><pre class="prettyprint">' + _.escape(code) + '</pre>'
return html;
};
// Setup marked to use our highlighter.
marked.setOptions({ highlight: highlight });
// ### docco
// [code-part](http://github.com/bline/code-part) To parse out code/docs
// and [marked](https://github.com/chjj/marked) to format the docs.
// marked is manually applied because we are using
// [google-code-prettify](https://code.google.com/p/google-code-prettify/)
// to highlight code.
var docco = function (path, code, config) {
var sections = part(path, code, config);
_.forEach(sections, function (section) {
section.codeHtml = highlight(section.codeText, section.codeLine);
section.docsHtml = marked(section.docsText);
});
return sections;
}
// ## Tasks
// ### task clean
// Cleans up dist directory using [del](https://github.com/sindresorhus/del).
gulp.task("clean", function (done) {
del(["dist/*"], done);
});
// ### task index
// Build's the index file with documentation from [docco](http://jashkenas.github.io/docco/)
// with the `index.html` [lodash template](https://lodash.com/docs#template).
gulp.task("index", ["clean"], function (done) {
var docs = [];
gulp.src(IndexSources)
.pipe($.tap(function (file) {
docs.push({
file: file,
docco: docco(file.path, file.contents.toString()),
id: _.uniqueId('file-')
})}))
// After we've created the `docs` array, build the template.
.on('end', function () {
gulp.src('index.html')
.pipe($.template({ docs: docs }))
.pipe(gulp.dest('dist'))
.on('end', function () { done() })
});
});
// ### task webpack
// Builds the main.js and any resources (bootstrap uses a few)
// into the dist directory. Uses [gulp-webpack](https://github.com/shama/gulp-webpack).
gulp.task("webpack", ["clean"], function () {
return gulp.src("index.js")
.pipe($.webpack(webpackConfig))
.pipe(gulp.dest('dist'));
});
// ### task build
// Build `index.html` and `main.js`.
gulp.task("build", ["webpack", "index"]);
// ### task watch
// Build and serve `index.html` on localhost port 3000
// launching a browser with [opn](https://github.com/sindresorhus/opn) to view.
// If you have the [livereload](https://github.com/vohof/gulp-livereload)
// plugin for chrome installed it will also reload
// your browser when files in the dist directory change.
gulp.task("watch", ["build"], function () {
$.livereload.listen();
gulp.watch('dist/**/*').on('change', $.livereload.changed);
gulp.watch(IndexSources, ['build']);
opn("http://127.0.0.1:3000/");
return $.serve('dist')();
});
// ### task deploy
// Deploy to Github pages. *UNTESTED*
gulp.task("deploy", ['build'], function () {
return gulp.src("dist/**/*")
.pipe($.ghPages('git@github.com:bline/bootstrap-webpack-example.git'));
});
// ### task test
// Run tests in [Karma](http://karma-runner.github.io/) using [FantomJS](http://phantomjs.org/).
gulp.task("test", function (done) {
karma.start({
configFile: KarmaConfig,
singleRun: true
}, done);
});
// ### task default
// Run test by default.
gulp.task("default", ["test"]);
})();