2015-10-17 14:12:04 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var gulp = require('gulp');
|
|
|
|
var sourcemaps = require('gulp-sourcemaps');
|
2015-09-26 14:02:03 +02:00
|
|
|
var browserSync = require('browser-sync').create();
|
2015-10-18 20:05:30 +02:00
|
|
|
var del = require('del');
|
2015-10-18 23:34:07 +02:00
|
|
|
var flatten = require('gulp-flatten');
|
2015-10-21 22:05:49 +02:00
|
|
|
var ts = require('gulp-typescript');
|
|
|
|
var merge = require('merge2');
|
|
|
|
var concat = require('gulp-concat');
|
2015-10-24 14:57:34 +02:00
|
|
|
var fileinclude = require('gulp-file-include');
|
2015-09-26 14:02:03 +02:00
|
|
|
|
2015-10-24 00:39:49 +02:00
|
|
|
var tsProject = ts.createProject('tsconfig.json', {
|
|
|
|
sortOutput : true
|
|
|
|
});
|
2015-10-17 14:12:04 +02:00
|
|
|
|
2015-10-21 22:05:49 +02:00
|
|
|
gulp.task('scripts', function() {
|
|
|
|
var tsResult = gulp.src('src/*.ts')
|
|
|
|
.pipe(sourcemaps.init())
|
|
|
|
.pipe(ts(tsProject));
|
2015-10-17 14:12:04 +02:00
|
|
|
|
2015-10-21 22:05:49 +02:00
|
|
|
return tsResult.js
|
|
|
|
.pipe(concat('bundle.js'))
|
|
|
|
.pipe(sourcemaps.write()) // Now the sourcemaps are added to the .js file
|
2015-10-24 14:57:34 +02:00
|
|
|
.pipe(gulp.dest('tmp'));
|
2015-10-21 22:05:49 +02:00
|
|
|
});
|
2015-10-17 14:12:04 +02:00
|
|
|
|
2015-10-24 14:57:34 +02:00
|
|
|
// build project for serving up locally
|
|
|
|
gulp.task('tmp', ['scripts', 'dist-node-modules'], function () {
|
2015-10-18 20:05:30 +02:00
|
|
|
return gulp.src([
|
|
|
|
'src/**/*.html',
|
|
|
|
'src/**/*.css',
|
2015-10-24 14:57:34 +02:00
|
|
|
'src/content_script_web.js'
|
2015-10-18 20:05:30 +02:00
|
|
|
], {base: 'src'})
|
2015-10-21 22:05:49 +02:00
|
|
|
.pipe(flatten())
|
2015-10-24 14:57:34 +02:00
|
|
|
.pipe(fileinclude({
|
|
|
|
prefix: '@@',
|
|
|
|
basePath: '@file'
|
|
|
|
}))
|
|
|
|
.pipe(gulp.dest('tmp'));
|
|
|
|
});
|
|
|
|
|
|
|
|
// build project for loading up in Chrome
|
|
|
|
gulp.task('dist', ['tmp'], function () {
|
|
|
|
var tmp = gulp.src([
|
|
|
|
'tmp/**/*',
|
|
|
|
'!tmp/index.html',
|
|
|
|
'!tmp/content_script_web.js'
|
|
|
|
], {base: 'tmp'});
|
|
|
|
var chromePluginResources = gulp.src([
|
|
|
|
'src/content_script.js',
|
|
|
|
'manifest.json'
|
|
|
|
])
|
|
|
|
.pipe(flatten())
|
|
|
|
.pipe(fileinclude({
|
|
|
|
prefix: '@@',
|
|
|
|
basePath: '@file'
|
|
|
|
}));
|
|
|
|
|
|
|
|
return merge([tmp, chromePluginResources])
|
2015-10-21 22:05:49 +02:00
|
|
|
.pipe(gulp.dest('dist'));
|
2015-10-18 20:05:30 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('dist-node-modules', function () {
|
|
|
|
return gulp.src([
|
2015-10-21 22:05:49 +02:00
|
|
|
'node_modules/bootstrap/**/*',
|
|
|
|
'node_modules/angular/**/*',
|
|
|
|
'node_modules/jquery/**/*'
|
2015-10-18 20:05:30 +02:00
|
|
|
], {base: 'node_modules'})
|
2015-10-24 14:57:34 +02:00
|
|
|
.pipe(gulp.dest('tmp/vendor'));
|
2015-10-18 20:05:30 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('clean', function () {
|
2015-10-24 14:57:34 +02:00
|
|
|
return del(['tmp', 'dist']);
|
2015-10-18 20:05:30 +02:00
|
|
|
});
|
|
|
|
|
2015-10-24 14:57:34 +02:00
|
|
|
gulp.task('serve', ['tmp'], function () {
|
|
|
|
// Serve files from the root of this project
|
|
|
|
browserSync.init({
|
|
|
|
server: {
|
|
|
|
baseDir: "./tmp",
|
|
|
|
}
|
|
|
|
});
|
2015-09-26 14:02:03 +02:00
|
|
|
|
2015-10-24 14:57:34 +02:00
|
|
|
// add browserSync.reload to the tasks array to make
|
|
|
|
// all browsers reload after tasks are complete.
|
|
|
|
gulp.watch("src/**/*.ts", ['scripts']);
|
|
|
|
gulp.watch([
|
|
|
|
"src/**/*.html",
|
|
|
|
"src/**/*.css",
|
|
|
|
"src/**/*.js"
|
|
|
|
], ['tmp']);
|
|
|
|
gulp.watch("tmp/**/*").on("change", browserSync.reload);
|
2015-09-26 14:02:03 +02:00
|
|
|
});
|