forked from pattern-lab/patternlab-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
185 lines (160 loc) · 5.14 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
// Special thanks to oscar-g (https://github.com/oscar-g) for starting this at
// https://github.com/oscar-g/patternlab-node/tree/dev-gulp
var pkg = require('./package.json'),
gulp = require('gulp'),
path = require('path'),
eol = require('os').EOL,
del = require('del'),
strip_banner = require('gulp-strip-banner'),
header = require('gulp-header'),
nodeunit = require('gulp-nodeunit'),
eslint = require('gulp-eslint'),
browserSync = require('browser-sync').create();
require('gulp-load')(gulp);
var banner = [ '/** ',
' * <%= pkg.name %> - v<%= pkg.version %> - <%= today %>',
' * ',
' * <%= pkg.author %>, and the web community.',
' * Licensed under the <%= pkg.license %> license.',
' * ',
' * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.',
' * ', ' **/'].join(eol);
function paths() {
return require('./patternlab-config.json').paths;
}
//load patternlab-node tasks
gulp.loadTasks(__dirname + '/core/lib/patternlab_gulp.js');
//clean patterns dir
gulp.task('clean', function (cb) {
del.sync([path.resolve(paths().public.patterns, '*')], {force: true});
cb();
});
//build the banner
gulp.task('banner', function () {
return gulp.src([
'./core/lib/patternlab.js',
'./core/lib/object_factory.js',
'./core/lib/lineage_hunter.js',
'./core/lib/media_hunter.js',
'./core/lib/patternlab_grunt.js',
'./core/lib/patternlab_gulp.js',
'./core/lib/parameter_hunter.js',
'./core/lib/pattern_exporter.js',
'./core/lib/pattern_assembler.js',
'./core/lib/pseudopattern_hunter.js',
'./core/lib/list_item_hunter.js',
'./core/lib/style_modifier_hunter.js'
])
.pipe(strip_banner())
.pipe(header(banner, {
pkg : pkg,
today : new Date().getFullYear() }
))
.pipe(gulp.dest('./core/lib'));
});
// COPY TASKS
// JS copy
gulp.task('cp:js', function () {
return gulp.src('**/*.js', {cwd: path.resolve(paths().source.js)})
.pipe(gulp.dest(path.resolve(paths().public.js)));
});
// Images copy
gulp.task('cp:img', function () {
return gulp.src(
['**/*.gif', '**/*.png', '**/*.jpg', '**/*.jpeg'],
{cwd: path.resolve(paths().source.images)})
.pipe(gulp.dest(path.resolve(paths().public.images)));
});
// Fonts copy
gulp.task('cp:font', function () {
return gulp.src('*', {cwd: path.resolve(paths().source.fonts)})
.pipe(gulp.dest(path.resolve(paths().public.fonts)));
});
// Data copy
gulp.task('cp:data', function () {
return gulp.src('annotations.js', {cwd: path.resolve(paths().source.data)})
.pipe(gulp.dest(path.resolve(paths().public.data)));
});
// CSS Copy
gulp.task('cp:css', function () {
return gulp.src(path.resolve(paths().source.css, 'style.css'))
.pipe(gulp.dest(path.resolve(paths().public.css)))
.pipe(browserSync.stream());
});
// Styleguide Copy
gulp.task('cp:styleguide', function () {
return gulp.src(
['**/*'],
{cwd: path.resolve(paths().source.styleguide)})
.pipe(gulp.dest(path.resolve(paths().public.styleguide)))
.pipe(browserSync.stream());
});
// server and watch tasks
gulp.task('connect', ['lab'], function () {
browserSync.init({
server: {
baseDir: path.resolve(paths().public.root)
},
snippetOptions: {
// Ignore all HTML files within the templates folder
blacklist: ['/index.html', '/', '/?*']
},
notify: {
styles: [
'display: none',
'padding: 15px',
'font-family: sans-serif',
'position: fixed',
'font-size: 1em',
'z-index: 9999',
'bottom: 0px',
'right: 0px',
'border-top-left-radius: 5px',
'background-color: #1B2032',
'opacity: 0.4',
'margin: 0',
'color: white',
'text-align: center'
]
}
});
gulp.watch(path.resolve(paths().source.css, '**/*.css'), ['cp:css']);
gulp.watch(path.resolve(paths().source.styleguide, '**/*.*'), ['cp:styleguide']);
gulp.watch(
[
path.resolve(paths().source.patterns, '**/*.mustache'),
path.resolve(paths().source.patterns, '**/*.json'),
path.resolve(paths().source.data, '*.json'),
path.resolve(paths().source.fonts + '/*'),
path.resolve(paths().source.images + '/*'),
path.resolve(paths().source.data + '*.json')
],
['lab-pipe'],
function () { browserSync.reload(); }
);
});
//lint
gulp.task('eslint', function () {
return gulp.src(['./core/lib/*.js', '!node_modules/**'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
//unit test
gulp.task('nodeunit', function () {
return gulp.src('./test/**/*_tests.js')
.pipe(nodeunit());
});
gulp.task('lab-pipe', ['lab'], function (cb) {
cb();
browserSync.reload();
});
gulp.task('default', ['lab']);
gulp.task('assets', ['cp:js', 'cp:img', 'cp:font', 'cp:data', 'cp:css', 'cp:styleguide' ]);
gulp.task('prelab', ['clean', 'assets']);
gulp.task('lab', ['prelab', 'patternlab'], function (cb) { cb(); });
gulp.task('patterns', ['patternlab:only_patterns']);
gulp.task('serve', ['lab', 'connect']);
gulp.task('build', ['eslint', 'nodeunit', 'banner']);
gulp.task('version', ['patternlab:version']);
gulp.task('help', ['patternlab:help']);