forked from openspending/os-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
145 lines (125 loc) · 3.91 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
'use strict';
var path = require('path');
var gulp = require('gulp');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var less = require('gulp-less');
var minifyCss = require('gulp-clean-css');
var prefixer = require('gulp-autoprefixer');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var resolve = require('resolve');
var stringify = require('stringify');
var frontSrcDir = path.join(__dirname, '/app/front');
var frontScriptsDir = path.join(frontSrcDir, '/scripts');
var frontStylesDir = path.join(frontSrcDir, '/styles');
var publicDir = path.join(__dirname, '/app/public');
var publicScriptsDir = path.join(publicDir, '/');
var publicStylesDir = path.join(publicDir, '/styles');
var publicFontsDir = path.join(publicDir, '/fonts');
var publicAssetsDir = path.join(publicDir, '/assets');
var nodeModulesDir = path.join(__dirname, '/node_modules');
gulp.task('default', [
'scripts',
'styles',
'assets'
]);
// Styles
gulp.task('styles', [
'styles.application',
'styles.embedded',
'styles.vendor'
]);
gulp.task('styles.application', function() {
var files = [
path.join(frontStylesDir, '/styles.less')
];
return gulp.src(files)
.pipe(sourcemaps.init())
.pipe(less())
.pipe(prefixer({browsers: ['last 4 versions']}))
.pipe(minifyCss({compatibility: 'ie8'}))
.pipe(concat('app.css'))
.pipe(sourcemaps.write())
.pipe(gulp.dest(publicStylesDir));
});
gulp.task('styles.embedded', function() {
var files = [
path.join(frontStylesDir, '/embedded.less')
];
return gulp.src(files)
.pipe(sourcemaps.init())
.pipe(less())
.pipe(prefixer({browsers: ['last 4 versions']}))
.pipe(minifyCss({compatibility: 'ie8'}))
.pipe(concat('embedded.css'))
.pipe(sourcemaps.write())
.pipe(gulp.dest(publicStylesDir));
});
gulp.task('styles.vendor', function() {
var files = [
path.join(nodeModulesDir, '/font-awesome/css/font-awesome.min.css'),
path.join(nodeModulesDir, '/os-bootstrap/dist/css/os-bootstrap.min.css'),
path.join(nodeModulesDir, '/angular/angular-csp.css'),
path.join(nodeModulesDir, '/babbage.ui/dist/babbage.css')
];
return gulp.src(files)
.pipe(concat('vendor.css'))
.pipe(minifyCss({compatibility: 'ie8'}))
.pipe(gulp.dest(publicStylesDir));
});
// Scripts
gulp.task('scripts', [
'scripts.application'
]);
gulp.task('scripts.application', function() {
var bundler = browserify({
standalone: 'application'
})
.transform(stringify, {
appliesTo: {
includeExtensions: ['.html']
},
minify: false
});
bundler.external('webpack-raphael');
bundler.require(resolve.sync(frontScriptsDir), {expose: 'application'});
return bundler.bundle()
.pipe(source('app.js'))
.pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest(publicScriptsDir));
});
// Assets
gulp.task('assets', [
'assets.fonts',
'assets.application',
'assets.favicon'
]);
gulp.task('assets.fonts', function() {
var files = [
path.join(nodeModulesDir, '/font-awesome/fonts/*'),
path.join(nodeModulesDir, '/os-bootstrap/dist/fonts/*')
];
return gulp.src(files)
.pipe(gulp.dest(publicFontsDir));
});
gulp.task('assets.application', function() {
return gulp.src([
path.join(nodeModulesDir, '/os-bootstrap/dist/assets/os-branding/vector/light/os.svg'),
path.join(nodeModulesDir, '/os-bootstrap/dist/assets/os-branding/vector/light/viewer.svg'),
path.join(nodeModulesDir, '/os-bootstrap/dist/assets/os-branding/vector/light/osviewer.svg'),
])
.pipe(gulp.dest(publicAssetsDir));
});
gulp.task('assets.favicon', function() {
var files = [
path.join(nodeModulesDir, '/os-bootstrap/dist/assets/os-branding/viewer-favicon.ico')
];
return gulp.src(files)
.pipe(rename('favicon.ico'))
.pipe(gulp.dest(publicDir));
});