2015-06-05 11:06:36 +02:00
|
|
|
'use strict';
|
|
|
|
|
2015-06-08 09:53:14 +02:00
|
|
|
require("harmonize")();
|
|
|
|
|
2015-05-26 19:16:30 +02:00
|
|
|
var gulp = require('gulp');
|
2015-06-09 17:53:44 +02:00
|
|
|
var template = require('gulp-template');
|
2015-05-26 19:16:30 +02:00
|
|
|
var gulpif = require('gulp-if');
|
|
|
|
var sourcemaps = require('gulp-sourcemaps');
|
|
|
|
var util = require('gulp-util');
|
|
|
|
var source = require('vinyl-source-stream');
|
|
|
|
var buffer = require('vinyl-buffer');
|
|
|
|
var watchify = require('watchify');
|
|
|
|
var browserify = require('browserify');
|
|
|
|
var browserSync = require('browser-sync');
|
|
|
|
var babelify = require('babelify');
|
|
|
|
var notify = require('gulp-notify');
|
2015-05-29 11:45:10 +02:00
|
|
|
var sass = require('gulp-sass');
|
|
|
|
var concat = require('gulp-concat');
|
2015-05-26 19:16:30 +02:00
|
|
|
var _ = require('lodash');
|
2015-06-05 09:17:41 +02:00
|
|
|
var eslint = require('gulp-eslint');
|
2015-06-08 09:53:14 +02:00
|
|
|
var jest = require('jest-cli');
|
2015-06-08 15:24:58 +02:00
|
|
|
var argv = require('yargs').argv;
|
|
|
|
var server = require('./server.js').app;
|
2015-06-08 15:42:28 +02:00
|
|
|
var minifyCss = require('gulp-minify-css');
|
|
|
|
var uglify = require('gulp-uglify');
|
2015-08-31 17:55:27 +02:00
|
|
|
var opn = require('opn');
|
2015-05-29 13:38:59 +02:00
|
|
|
|
2015-06-09 17:53:44 +02:00
|
|
|
|
2015-05-29 13:38:59 +02:00
|
|
|
var config = {
|
2015-06-08 09:53:14 +02:00
|
|
|
bootstrapDir: './node_modules/bootstrap-sass',
|
|
|
|
jestOptions: {
|
|
|
|
rootDir: 'js',
|
|
|
|
scriptPreprocessor: '../node_modules/babel-jest',
|
|
|
|
testFileExtensions: [
|
|
|
|
'es6',
|
|
|
|
'js'
|
|
|
|
],
|
|
|
|
unmockedModulePathPatterns: [
|
|
|
|
'<rootDir>/node_modules/react',
|
|
|
|
'<rootDir>/node_modules/react-tools'
|
|
|
|
],
|
|
|
|
moduleFileExtensions: [
|
|
|
|
'js',
|
|
|
|
'json',
|
|
|
|
'react',
|
|
|
|
'es6'
|
|
|
|
]
|
2015-06-17 17:15:21 +02:00
|
|
|
},
|
|
|
|
filesToWatch: [
|
|
|
|
'build/css/*.css',
|
2015-08-31 18:05:14 +02:00
|
|
|
'build/js/*.js'
|
2015-06-17 17:15:21 +02:00
|
|
|
]
|
2015-05-29 13:38:59 +02:00
|
|
|
};
|
|
|
|
|
2015-08-13 16:50:28 +02:00
|
|
|
var SERVER_URL = process.env.ONION_SERVER_URL || 'https://staging.ascribe.io/';
|
2015-08-13 17:06:27 +02:00
|
|
|
|
2015-06-10 17:28:36 +02:00
|
|
|
var constants = {
|
|
|
|
BASE_URL: (function () { var baseUrl = process.env.ONION_BASE_URL || '/'; return baseUrl + (baseUrl.match(/\/$/) ? '' : '/'); })(),
|
2015-06-24 18:02:32 +02:00
|
|
|
SERVER_URL: SERVER_URL,
|
2015-08-13 16:50:28 +02:00
|
|
|
API_ENDPOINT: SERVER_URL + 'api/' || 'https://staging.ascribe.io/api/',
|
2015-06-10 17:28:36 +02:00
|
|
|
DEBUG: !argv.production,
|
|
|
|
CREDENTIALS: 'ZGltaUBtYWlsaW5hdG9yLmNvbTowMDAwMDAwMDAw' // dimi@mailinator:0000000000
|
|
|
|
};
|
|
|
|
|
2015-06-09 17:53:44 +02:00
|
|
|
|
2015-06-08 15:42:28 +02:00
|
|
|
gulp.task('build', ['js:build', 'sass:build', 'copy'], function() {
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('js:build', function() {
|
2015-05-26 19:16:30 +02:00
|
|
|
bundle(false);
|
|
|
|
});
|
2015-06-08 15:24:58 +02:00
|
|
|
|
2015-06-24 15:52:43 +02:00
|
|
|
gulp.task('serve', ['browser-sync', 'run-server', 'sass:build', 'sass:watch', 'copy'], function() {
|
2015-05-26 19:16:30 +02:00
|
|
|
bundle(true);
|
2015-08-31 18:05:14 +02:00
|
|
|
|
|
|
|
// opens the browser window with the correct url, which is localhost.com
|
2015-08-31 17:55:27 +02:00
|
|
|
opn('http://www.localhost.com:3000');
|
2015-05-26 19:16:30 +02:00
|
|
|
});
|
|
|
|
|
2015-06-08 09:53:14 +02:00
|
|
|
gulp.task('jest', function(done) {
|
|
|
|
jest.runCLI({ config : config.jestOptions }, ".", function() {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('jest:watch', function(done) {
|
|
|
|
gulp.watch([ config.jestOptions.rootDir + "/**/*.js" ], [ 'jest' ]);
|
|
|
|
});
|
|
|
|
|
2015-06-08 15:24:58 +02:00
|
|
|
gulp.task('run-server', function() {
|
|
|
|
server.listen(4000);
|
|
|
|
});
|
|
|
|
|
2015-05-26 19:16:30 +02:00
|
|
|
gulp.task('browser-sync', function() {
|
|
|
|
browserSync({
|
2015-06-17 17:15:21 +02:00
|
|
|
files: config.filesToWatch,
|
2015-06-08 15:24:58 +02:00
|
|
|
proxy: 'http://localhost:4000',
|
2015-08-31 17:55:27 +02:00
|
|
|
port: 3000,
|
2015-08-31 18:05:14 +02:00
|
|
|
open: false, // does not open the browser-window anymore (handled manually)
|
|
|
|
ghostMode: false
|
2015-05-26 19:16:30 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-06-08 15:42:28 +02:00
|
|
|
gulp.task('sass:build', function () {
|
2015-05-29 11:45:10 +02:00
|
|
|
gulp.src('./sass/**/main.scss')
|
2015-06-10 17:28:36 +02:00
|
|
|
.pipe(template(constants))
|
2015-06-08 15:42:28 +02:00
|
|
|
.pipe(gulpif(!argv.production, sourcemaps.init()))
|
2015-05-29 13:38:59 +02:00
|
|
|
.pipe(sass({
|
|
|
|
includePaths: [
|
|
|
|
config.bootstrapDir + '/assets/stylesheets'
|
|
|
|
]
|
|
|
|
}).on('error', sass.logError))
|
2015-06-08 15:42:28 +02:00
|
|
|
.pipe(gulpif(!argv.production, sourcemaps.write('./maps')))
|
2015-10-21 22:35:03 +02:00
|
|
|
// We need to set `advanced` to false, as it merges
|
|
|
|
// some of the styles wrongly
|
|
|
|
.pipe(gulpif(argv.production, minifyCss({
|
|
|
|
advanced: false
|
|
|
|
})))
|
2015-05-29 14:00:09 +02:00
|
|
|
.pipe(gulp.dest('./build/css'))
|
2015-06-08 15:24:58 +02:00
|
|
|
.pipe(browserSync.stream());
|
2015-05-29 12:08:26 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('sass:watch', function () {
|
2015-06-12 13:36:55 +02:00
|
|
|
gulp.watch('./sass/**/*.scss', ['sass:build']);
|
2015-05-29 11:45:10 +02:00
|
|
|
});
|
|
|
|
|
2015-05-29 11:57:24 +02:00
|
|
|
gulp.task('copy', function () {
|
2015-06-08 15:24:58 +02:00
|
|
|
var staticAssets = [
|
2015-05-29 11:57:24 +02:00
|
|
|
'./fonts/**/*',
|
2015-05-29 13:38:59 +02:00
|
|
|
'./img/**/*'
|
2015-05-29 11:57:24 +02:00
|
|
|
];
|
|
|
|
|
2015-06-08 15:24:58 +02:00
|
|
|
gulp.src(staticAssets, {base: './'})
|
|
|
|
.pipe(gulp.dest('./build'));
|
2015-05-29 13:38:59 +02:00
|
|
|
|
|
|
|
gulp.src(config.bootstrapDir + '/assets/fonts/**/*')
|
2015-05-29 14:00:09 +02:00
|
|
|
.pipe(gulp.dest('./build/fonts'));
|
2015-06-09 17:53:44 +02:00
|
|
|
|
|
|
|
gulp.src('./index.html')
|
2015-06-10 17:28:36 +02:00
|
|
|
.pipe(template(constants))
|
2015-06-09 17:53:44 +02:00
|
|
|
.pipe(gulp.dest('./build'));
|
2015-05-29 11:57:24 +02:00
|
|
|
});
|
|
|
|
|
2015-06-05 09:17:41 +02:00
|
|
|
gulp.task('lint', function () {
|
|
|
|
return gulp.src(['js/**/*.js'])
|
|
|
|
// eslint() attaches the lint output to the eslint property
|
|
|
|
// of the file object so it can be used by other modules.
|
|
|
|
.pipe(eslint())
|
|
|
|
// eslint.format() outputs the lint results to the console.
|
|
|
|
// Alternatively use eslint.formatEach() (see Docs).
|
2015-06-08 09:53:14 +02:00
|
|
|
.pipe(eslint.format());
|
2015-06-05 09:17:41 +02:00
|
|
|
// To have the process exit with an error code (1) on
|
|
|
|
// lint error, return the stream and pipe to failOnError last.
|
|
|
|
});
|
|
|
|
|
2015-06-05 11:06:36 +02:00
|
|
|
gulp.task('lint:watch', function () {
|
|
|
|
gulp.watch('js/**/*.js', ['lint']);
|
|
|
|
});
|
|
|
|
|
2015-05-26 19:16:30 +02:00
|
|
|
function bundle(watch) {
|
|
|
|
var bro;
|
2015-06-08 15:24:58 +02:00
|
|
|
|
2015-05-26 19:16:30 +02:00
|
|
|
if (watch) {
|
|
|
|
bro = watchify(browserify('./js/app.js',
|
|
|
|
// Assigning debug to have sourcemaps
|
|
|
|
_.assign(watchify.args, {
|
|
|
|
debug: true
|
|
|
|
})));
|
|
|
|
bro.on('update', function() {
|
|
|
|
rebundle(bro, true);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
bro = browserify('./js/app.js', {
|
|
|
|
debug: true
|
|
|
|
});
|
|
|
|
}
|
2015-06-05 16:57:56 +02:00
|
|
|
|
2015-05-26 19:16:30 +02:00
|
|
|
bro.transform(babelify.configure({
|
|
|
|
compact: false
|
|
|
|
}));
|
2015-06-05 16:57:56 +02:00
|
|
|
|
2015-05-26 19:16:30 +02:00
|
|
|
function rebundle(bundler, watch) {
|
|
|
|
return bundler.bundle()
|
|
|
|
.on('error', notify.onError('Error: <%= error.message %>'))
|
|
|
|
.pipe(source('app.js'))
|
2015-06-19 13:13:37 +02:00
|
|
|
.on('error', notify.onError('Error: <%= error.message %>'))
|
2015-05-26 19:16:30 +02:00
|
|
|
.pipe(buffer())
|
2015-06-19 13:13:37 +02:00
|
|
|
.on('error', notify.onError('Error: <%= error.message %>'))
|
2015-06-08 15:42:28 +02:00
|
|
|
.pipe(gulpif(!argv.production, sourcemaps.init({
|
2015-05-26 19:16:30 +02:00
|
|
|
loadMaps: true
|
2015-06-08 15:42:28 +02:00
|
|
|
}))) // loads map from browserify file
|
2015-06-19 13:13:37 +02:00
|
|
|
.on('error', notify.onError('Error: <%= error.message %>'))
|
2015-06-08 15:42:28 +02:00
|
|
|
.pipe(gulpif(!argv.production, sourcemaps.write())) // writes .map file
|
2015-06-19 13:13:37 +02:00
|
|
|
.on('error', notify.onError('Error: <%= error.message %>'))
|
2015-07-20 11:26:06 +02:00
|
|
|
.pipe(gulpif(argv.production, uglify({
|
2015-09-04 18:04:03 +02:00
|
|
|
mangle: true
|
2015-07-20 11:26:06 +02:00
|
|
|
})))
|
2015-07-14 10:52:44 +02:00
|
|
|
.on('error', notify.onError('Error: <%= error.message %>'))
|
2015-06-08 15:24:58 +02:00
|
|
|
.pipe(gulp.dest('./build/js'))
|
2015-06-19 13:13:37 +02:00
|
|
|
.on('error', notify.onError('Error: <%= error.message %>'))
|
|
|
|
.pipe(browserSync.stream())
|
|
|
|
.on('error', notify.onError('Error: <%= error.message %>'));
|
2015-05-26 19:16:30 +02:00
|
|
|
}
|
2015-06-05 16:57:56 +02:00
|
|
|
|
2015-05-26 19:16:30 +02:00
|
|
|
return rebundle(bro);
|
2015-06-08 15:24:58 +02:00
|
|
|
}
|