tag-youre-it/Gulpfile.js

100 lines
No EOL
2.4 KiB
JavaScript

'use strict';
var gulp = require('gulp');
var $ = require('gulp-load-plugins')({
pattern: ['gulp-*', 'del', 'merge2'],
rename: {
'merge2': 'merge'
}
});
var browserSync = require('browser-sync').create();
var tsProject = $.typescript.createProject('tsconfig.json', {
sortOutput : true
});
gulp.task('scripts', function() {
var tsResult = gulp.src('src/*.ts')
.pipe($.sourcemaps.init())
.pipe($.typescript(tsProject));
return tsResult.js
.pipe($.concat('bundle.js'))
.pipe($.ngAnnotate())
.pipe($.sourcemaps.write()) // Now the sourcemaps are added to the .js file
.pipe(gulp.dest('tmp'));
});
// build project for serving up locally
gulp.task('tmp', ['scripts', 'dist-node-modules'], function () {
return gulp.src([
'src/**/*.html',
'src/**/*.css',
'src/content_script_web.js'
], {base: 'src'})
.pipe($.flatten())
.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 imageAssets = gulp.src('src/*.png').pipe($.flatten());
var chromePluginResources = gulp.src([
'src/content_script.js',
'src/background.js',
'src/manifest.json',
])
.pipe($.flatten())
.pipe($.fileInclude({
prefix: '@@',
basePath: '@file'
}));
return $.merge([tmp, chromePluginResources, imageAssets])
.pipe(gulp.dest('dist'));
});
gulp.task('dist-node-modules', function () {
return gulp.src([
'node_modules/bootstrap/**/*',
'node_modules/material-design-lite/**/*',
'node_modules/angular/**/*',
'node_modules/jquery/**/*'
], {base: 'node_modules'})
.pipe(gulp.dest('tmp/vendor'));
});
gulp.task('clean', function () {
return $.del(['tmp', 'dist']);
});
gulp.task('watch-plugin', ['dist'], function () {
gulp.watch("src/**/*", ['dist']);
});
gulp.task('serve', ['tmp'], function () {
// Serve files from the root of this project
browserSync.init({
server: {
baseDir: "./tmp",
}
});
// 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);
});