-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
68 lines (58 loc) · 1.68 KB
/
index.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
'use strict';
const PLUGIN_NAME = 'viur-ignite-js';
const path = require('path');
const isThere = require('is-there');
const gulp = require('gulp');
const gutil = require('gulp-util');
const rename = require('gulp-rename');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
module.exports = {
build: function (options) {
// Set Default Options
var defaultOptions = {
src: './sources/js/app.js',
dest: './appengine/static/js'
};
if (typeof options === 'undefined') {
options = {};
}
for (var key in defaultOptions) {
if (typeof options[key] === 'undefined') {
options[key] = defaultOptions[key];
}
}
// minify js and put in single file
return gulp.src([path.join(__dirname, '/js/viur.js'), options.src])
.pipe(concat('app.js'))
.pipe(gulp.dest(options.dest))
.pipe(uglify())
.pipe(rename('app.min.js'))
.pipe(gulp.dest(options.dest));
},
init: function (options) {
// Set Default Options
var defaultOptions = {
dest: './sources/js/app.js',
overwrite: false
};
if (typeof options === 'undefined') {
options = {};
}
for (var key in defaultOptions) {
if (typeof options[key] === 'undefined') {
options[key] = defaultOptions[key];
}
}
if (isThere(options.dest) && (options.overwrite === false || options.overwrite === 'false')) {
throw new gutil.PluginError(PLUGIN_NAME, '\'' + options.dest + '\' already exists\n\tcall function with option overwrite: true');
} else {
return copyPrototype(options.dest);
}
}
};
function copyPrototype(dest) {
return gulp.src(path.join(__dirname, '/prototype/app.js'))
.pipe(rename(path.basename(dest)))
.pipe(gulp.dest(path.dirname(dest)));
}