-
Notifications
You must be signed in to change notification settings - Fork 14
/
gulpfile.js
105 lines (95 loc) · 3.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
var browserify = require('browserify');
var gulp = require('gulp');
var gutil = require('gulp-util');
var sass = require('gulp-sass');
var cssnano = require('gulp-cssnano');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
var fileinclude = require('gulp-file-include');
var del = require('del');
var buffer = require('vinyl-buffer');
var source = require('vinyl-source-stream');
gulp.task('clean', function() {
return del(['examples/dist/**/*']);
});
gulp.task('sass', ['clean'], function() {
[
'./src/stylesheets/project_specific/documentation/documentation.scss',
'./src/stylesheets/project_specific/website/website.scss',
'./src/stylesheets/project_specific/developer/developer.scss',
'./src/stylesheets/project_specific/styleguidepage/styleguidepage.scss',
'./src/stylesheets/styleguide.scss'
].forEach(function(file_path) {
gulp.src(file_path)
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./dist/styles')) // Write unminified CSS first
// .pipe(gulpif((gutil.env.target !== "prod"), sourcemaps.write()))
.pipe(cssnano({
safe: true, // Primarily to prevent z-index rebasing, which is a terrible idea
discardComments: { removeAll: true } // Force removal of noisy /*! "special" comments */
}))
.pipe(rename({
dirname: '',
extname: '.min.css'
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./dist/styles'));
});
});
gulp.task('js', function () {
var b = browserify({
entries: 'src/scripts/main.js',
debug: true
});
return b.bundle()
.pipe(source('src/main.js'))
.pipe(buffer())
.pipe(gutil.env.target !== 'prod' ? sourcemaps.init({ loadMaps: true }): gutil.noop())
// Add transformation tasks to the pipeline here.
.pipe(uglify())
.pipe(rename({
dirname: '',
basename: 'mapzen-styleguide',
extname: '.min.js'
}))
.on('error', gutil.log)
.pipe(gutil.env.target !== 'prod' ? sourcemaps.write('./'): gutil.noop())
.pipe(gulp.dest('dist/scripts/'));
});
gulp.task('fileinclude', function() {
gulp.src(['./src/site/*'])
.pipe(fileinclude({
prefix: '@@',
basepath: '@file'
}))
.pipe(gulp.dest('./dist/'));
});
gulp.task('watch', function() {
gulp.watch('./src/stylesheets/**/*.scss', ['sass']);
gulp.watch('./src/scripts/**/*.js', ['js']);
gulp.watch('./src/site/**/*', ['fileinclude']);
});
gulp.task('publish', ['build'], function() {
var s3 = require('gulp-s3-upload')();
var s3bucket;
if (gutil.env.target === "prod") {
s3bucket = process.env.MAPZEN_PROD_BUCKET;
} else {
s3bucket = process.env.MAPZEN_DEV_BUCKET;
}
return gulp.src(
['dist/**/*'],
{base: 'dist'}
).pipe(s3({
Bucket: s3bucket,
ACL: 'public-read',
CacheControl: 'max-age=300,public',
keyTransform: function (relative_filename) {
return 'common/styleguide/' + relative_filename;
}
}));
});
gulp.task('build', ['sass', 'js', 'fileinclude']);
gulp.task('default', ['build', 'watch']);