forked from yhat/rodeo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
173 lines (154 loc) · 4.96 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
'use strict';
const _ = require('lodash'),
gulp = require('gulp'),
concat = require('gulp-concat'),
less = require('gulp-less'),
path = require('path'),
sourcemaps = require('gulp-sourcemaps'),
map = require('vinyl-map'),
tmpAppDirectory = 'app',
uglify = require('gulp-uglify'),
distTasks = require('./tasks/dist'),
karmaTasks = require('./tasks/karma'),
lintTasks = require('./tasks/lint'),
webpackTasks = require('./tasks/webpack'),
outputMap = {
app: tmpAppDirectory,
browser: path.join(tmpAppDirectory, 'browser'),
fonts: path.join(tmpAppDirectory, 'browser', 'fonts'),
images: path.join(tmpAppDirectory, 'browser', 'images'),
config: path.join(tmpAppDirectory, 'config'),
node: path.join(tmpAppDirectory, 'node'),
themes: path.join(tmpAppDirectory, 'browser', 'themes')
};
distTasks.importTasks(gulp);
karmaTasks.importTasks(gulp);
lintTasks.importTasks(gulp);
webpackTasks.importTasks(gulp, outputMap);
gulp.task('ace:core', function () {
return gulp.src([
'src/browser/ace/ace.js',
'src/browser/ace/**/*.js',
'!src/browser/ace/mode-*.js',
'!src/browser/ace/theme-*.js'
]).pipe(concat('ace.min.js'))
.pipe(uglify())
.pipe(gulp.dest(outputMap.browser));
});
gulp.task('ace:modes-js', function () {
return gulp.src([
'src/browser/ace/mode-*.js'
]).pipe(gulp.dest(outputMap.browser));
});
gulp.task('ace:themes-js', function () {
return gulp.src([
'src/browser/ace/theme-*.js'
]).pipe(uglify())
.pipe(gulp.dest(outputMap.browser));
});
/**
* Ace is so large that its easier to keep it separate.
* Also, it minifies well, unlike other ext
*/
gulp.task('ace', ['ace:core', 'ace:themes-js', 'ace:modes-js']);
/**
* This files should be included in every screen, and have already been processed, so keep it separate.
*/
gulp.task('external', function () {
return gulp.src([
'node_modules/jquery/dist/jquery.min.js',
'node_modules/bootstrap/dist/js/bootstrap.min.js',
'node_modules/react/dist/react-with-addons.js',
'node_modules/react-dom/dist/react-dom.js',
'src/browser/jsx/lib/*.js'
]).pipe(concat('external.min.js'))
.pipe(gulp.dest(outputMap.browser));
});
gulp.task('html', function () {
return gulp.src([
'src/browser/jsx/entry/*.html'
]).pipe(gulp.dest(outputMap.browser));
});
/**
* I don't know why less doesn't do this automatically.
*/
gulp.task('fonts', function () {
return gulp.src([
'node_modules/font-awesome/fonts/**/*',
'src/browser/fonts/lato/Lato-Regular.ttf',
'src/browser/fonts/NotoMono-hinted/NotoMono-Regular.ttf',
'src/browser/fonts/NotoSans-unhinted/NotoSans-Regular.ttf',
'src/browser/fonts/NotoSerif-unhinted/NotoSerif-Regular.ttf',
'src/browser/fonts/roboto/Roboto-Regular.ttf',
'src/browser/fonts/fonts.css'
]).pipe(gulp.dest(outputMap.fonts));
});
gulp.task('themes', ['fonts'], function () {
return gulp.src([
'src/browser/themes/*.less'
]).pipe(sourcemaps.init())
.pipe(less())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(outputMap.themes));
});
/**
* We should eventually eliminate all of these and move them to the jsx folder so they're optimized
*/
gulp.task('images', function () {
return gulp.src([
'src/browser/images/**/*.{svg,gif,png}'
]).pipe(gulp.dest(outputMap.images));
});
/**
* Copy the config-specific code over to the temp directory that will be distributed with a deployed app
*/
gulp.task('config', function () {
// copy node program
return gulp.src([
'config/**/*'
]).pipe(gulp.dest(outputMap.config));
});
/**
* Copy the node-specific code over to the temp directory that will be distributed with a deployed app
*/
gulp.task('node', function () {
// copy node program
return gulp.src([
'src/node/**/*',
'!**/*.test*', // leave the tests behind
'!**/*.md' // leave the documentation behind
]).pipe(gulp.dest(outputMap.node));
});
/**
* Make an "app" version of the package.json according to electron-builder's arbitrary rules and put it in the
* temp directory to be consumed by them.
*/
gulp.task('package.json', function () {
return gulp.src('package.json')
.pipe(map(function (chunk) {
const pkg = JSON.parse(chunk.toString());
pkg.main = 'node/index.js';
return JSON.stringify(_.omit(pkg, ['devDependencies', 'build', 'bin']), null, 2);
}))
.pipe(gulp.dest(outputMap.app));
});
/**
* Installs only the dependencies need to the run the app (not build the app) to the tmpAppDirectory
* @returns {Promise}
*/
gulp.task('npm-install', function () {
const path = tmpAppDirectory,
args = ['--production'];
return new Promise(function (resolve, reject) {
require('npm-i')({path, args}, function (err) {
if (err) {
return reject(err);
}
resolve();
});
});
});
gulp.task('test', ['lint', 'karma']);
gulp.task('build', ['themes', 'external', 'images', 'ace', 'jsx', 'html', 'config', 'node', 'package.json']);
gulp.task('dist', ['dist:all']);
gulp.task('default', ['test', 'build']);