Repository navigation
Expand file tree
/
Copy pathgulpfile.js
More file actions
181 lines (164 loc) · 5.18 KB
/
Copy pathgulpfile.js
File metadata and controls
181 lines (164 loc) · 5.18 KB
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*global require, __dirname*/
var src = './appdev';
var srcNode = './node_modules';
var dist = src + '/dist';
var build = 'build';
var release = 'release';
var manifest = require(src + '/manifest.json');
// Include gulp
var gulp = require('gulp');
// Include plugins
var del = require('del');
var plugins = require('gulp-load-plugins')();
var runSequence = require('run-sequence');
var htmlmin = {
removeComments: true,
collapseWhitespace: true,
conservativeCollapse: true,
collapseInlineTagWhitespace: true,
removeTagWhitespace: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
};
//Copy libraries to correct place from node_modules during npm install
gulp.task('installJSTree', function() {
return gulp.src([srcNode + '/jstree/dist/**/*(*.js)', srcNode + '/jstree/dist/themes/default/**/*(*.min.css|*.png|*.gif)'], {
base: srcNode + '/jstree/dist',
})
.pipe(gulp.dest(dist + '/jstree'));
});
gulp.task('installjs', function() {
return gulp.src([srcNode + '/jquery/dist/*.js', srcNode + '/angular/angular*.js', srcNode + "/angular-drag-and-drop-lists/angular-drag-and-drop-lists*.js"])
.pipe(gulp.dest(dist));
});
gulp.task('installngjstree', function(cb) {
gulp.src(srcNode + '/ng-js-tree/ngJsTree.js')
.pipe(plugins.rename({
suffix: '.min',
}))
.pipe(plugins.uglify())
.pipe(gulp.dest(dist));
gulp.src(srcNode + '/ng-js-tree/ngJsTree.js')
.pipe(gulp.dest(dist));
return cb();
});
gulp.task('install', ['installjs', 'installJSTree', 'installngjstree'], function(cb) {
cb();
});
gulp.task('update', ['installjs', 'installJSTree', 'installngjstree', 'buildUI'], function(cb) {
cb();
});
//Build Support libraries
//semantic-ui
var
watchUI = require('./dist/semantic-ui/tasks/watch'),
buildUI = require('./dist/semantic-ui/tasks/build'),
installUI = require('./node_modules/semantic-ui/tasks/install');
// import task with a custom task name
gulp.task('watchUI', watchUI);
gulp.task('buildUI', buildUI);
gulp.task('installUI', installUI);
var buildUIA = require('./dist/ui-angular/tasks/build')(__dirname);
gulp.task('buildUIA', buildUIA);
//build
//Clean build and release folder
gulp.task('clean', function() {
return del(['build', 'release']);
});
//combine .js Files
gulp.task('buildScripts', function() {
return gulp.src(src + '/app/**/*.js')
.pipe(plugins.eslint())
.pipe(plugins.eslint.format())
.pipe(plugins.ngAnnotate())
.pipe(plugins.angularFilesort())
.pipe(plugins.concat('startpage.js'))
.pipe(plugins.rename({
suffix: '.min',
}))
.pipe(plugins.uglify())
.pipe(gulp.dest(build + '/app'));
});
//CSS
gulp.task('buildCss', function() {
return gulp.src(src + '/app/**/*.css')
// .pipe(plugins.csslint())
// .pipe(plugins.csslint.reporter())
.pipe(plugins.concat('startpage.css'))
.pipe(plugins.rename({
suffix: '.min',
}))
.pipe(plugins.cssnano())
.pipe(gulp.dest(build + '/app'));
});
//Get distributions
gulp.task('getDist', function() {
return gulp.src([src + '/dist/**/*(*.min.js|*.min.css)', src + '/dist/**/!(*.js|*.css)'])
.pipe(gulp.dest(build + '/dist'));
});
//Get code pieces
gulp.task('getHtml', function() {
return gulp.src([src + '/app/**/*.html'])
.pipe(plugins.htmlmin(htmlmin))
.pipe(gulp.dest(build + '/app'));
});
gulp.task('getLocales', function() {
return gulp.src([src + '/_locales/**/*.json'])
.pipe(gulp.dest(build + '/_locales'));
});
gulp.task('buildConfig', function(cb) {
gulp.src(src + '/' + manifest.chrome_url_overrides.newtab)
.pipe(plugins.htmlReplace({
'css': 'app/startpage.min.css',
'js': 'app/startpage.min.js',
'html': '<title>' + manifest.short_name + '</title>',
}))
.pipe(plugins
.replace(/(dist.*\.)(js)/gm, function(r1, r2, r3) {
return r2 + 'min.' + r3;
})
)
.pipe(plugins.htmlmin(htmlmin))
.pipe(gulp.dest(build));
gulp.src(src + '/' + manifest.options_ui.page)
.pipe(plugins.htmlReplace({
'css': 'app/startpage.min.css',
'js': 'app/startpage.min.js',
}))
.pipe(plugins
.replace(/(dist.*\.)(js)/gm, function(r1, r2, r3) {
return r2 + 'min.' + r3;
})
)
.pipe(plugins.htmlmin(htmlmin))
.pipe(gulp.dest(build));
gulp.src(src + '/manifest.json')
.pipe(plugins.jsonEditor({
'name': 'Practical Startpage',
'options_ui': {
"page": "chrome.optionsUI.html",
"open_in_tab": false,
},
}))
.pipe(gulp.dest(build));
gulp.src([src + '/img/*'])
.pipe(gulp.dest(build + '/img'));
cb();
});
//Zip all files in deployment package for chrome
gulp.task('release', ['build'], function() {
return gulp.src(build + '/**/*')
.pipe(plugins.zip('practical startpage ' + manifest.version + '.zip'))
.pipe(gulp.dest(release));
});
//Watch
gulp.task('watch', function() {
gulp.watch(src + '/app/**/*.js', ['buildScripts']);
gulp.watch(src + '/app/**/*.css', ['buildCss']);
gulp.watch([src + '/app/**/*.html', src + '/app/**/*.json'], ['getHtml']);
});
// Default Task
gulp.task('default', ['build', 'watch']);
gulp.task('build', function(cb) {
runSequence('clean', ['buildScripts', 'getDist', 'buildCss', 'buildConfig', 'getHtml', 'getLocales'], cb);
});