forked from prose/prose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
166 lines (147 loc) · 4.01 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
var gulp = require('gulp');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var shell = require('gulp-shell');
var browserify = require('browserify');
var rename = require('gulp-rename');
var del = require('del');
var watch = require('gulp-watch');
var gulpif = require('gulp-if');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var merge2 = require('merge2');
var mkdirp = require('mkdirp');
var sass = require('gulp-sass');
var nodeJS = process.execPath;
// Scripts paths.
var paths = {
vendorScripts: [
'vendor/liquid.js'
],
app: [
'app/**/**/*.js'
],
test: [
'test/**/*.{js, json}',
'test/index.html',
'!test/lib/index.js' // built test file
],
templates: [
'templates/**/*.html'
],
css: [
'style/**/*.scss'
]
};
function isProd () {
return process.env.PROSE_ENV === 'production';
}
gulp.task('setProductionEnv', function () {
return process.env.PROSE_ENV = 'production';
});
var dist = './dist';
var dev = './';
// Removes `dist` folder.
gulp.task('clean', function (cb) {
return del([dist], cb);
});
// Translations.
// To run this task we have to have a `transifex.auth`
// file inside `translations` folder.
// Example file contents:
//
// {
// "user": "",
// "pass": ""
// }
//
// An account can be created at https://www.transifex.com/
//
gulp.task('translations', function () {
mkdirp(dist);
return gulp.src('')
.pipe(
shell([
nodeJS + ' translations/update_locales',
nodeJS + ' build'
])
);
});
// Parse stylesheet
gulp.task('css', function () {
return gulp.src('./style/style.scss')
.pipe(sass().on('error', sass.logError))
.pipe(rename('prose.css'))
.pipe(gulp.dest(dist));
});
// Build templates.
gulp.task('templates', function () {
mkdirp(dist);
return gulp.src('')
.pipe(
shell([
"\"" + nodeJS + "\"" + ' build'
])
);
});
// Creates `dist` directory if not created and
// creates `oauth.json`.
gulp.task('oauth', function () {
mkdirp(dist);
return gulp.src('')
.pipe(
shell([
'[ -f oauth.json ] && echo "Using existing oauth.json." || curl "https://raw.githubusercontent.com/prose/prose/gh-pages/oauth.json" > oauth.json'
])
);
});
// Build tests, then concatenate with vendor scripts
gulp.task('build-tests', ['templates', 'oauth'], function() {
var tests = browserify({
debug: true,
noParse: [require.resolve('handsontable/dist/handsontable.full')]
})
.add('./test/index.js')
.external(['chai', 'mocha'])
.bundle()
.pipe(source('index.js'))
.pipe(buffer());
return merge2(gulp.src(paths.vendorScripts), tests)
.pipe(concat('index.js'))
.pipe(gulp.dest('./test/lib'));
});
// Browserify app scripts, then concatenate with vendor scripts into `prose.js`.
gulp.task('build-app', ['templates', 'oauth'], function() {
var app = browserify({
noParse: [require.resolve('handsontable/dist/handsontable.full')]
})
.add('./app/boot.js')
.bundle()
.pipe(source('app.js'))
.pipe(buffer());
return merge2(gulp.src(paths.vendorScripts), app)
.pipe(concat('prose.js'))
.pipe(gulpif(isProd(), uglify()))
.pipe(gulp.dest(dist));
});
// Watch for changes in `app` scripts.
gulp.task('watch', ['build-app', 'build-tests', 'css'], function() {
// Watch any `.js` file under `app` folder.
gulp.watch(paths.app, ['build-app', 'build-tests']);
gulp.watch(paths.test, ['build-tests']);
gulp.watch(paths.templates, ['build-app']);
gulp.watch(paths.css, ['css']);
});
var testTask = shell.task([
'./node_modules/mocha-phantomjs/bin/mocha-phantomjs test/index.html'
], {ignoreErrors: true});
gulp.task('test', ['build-tests'], testTask);
// Run tests in command line on app, test, or template change
gulp.task('test-ci', ['test'], function() {
gulp.watch([paths.app, paths.test, paths.templates], ['test'])
});
// Build site, tests
gulp.task('build', ['build-tests', 'build-app', 'css']);
gulp.task('default', ['build']);
// Minify build
gulp.task('production', ['setProductionEnv', 'build']);