forked from intersystems-community/DeepSeeWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
169 lines (148 loc) · 5.28 KB
/
gulpfile.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
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
var gulp = require('gulp'),
uglify = require('gulp-uglify'),
useref = require('gulp-useref'),
jshint = require('gulp-jshint'),
concat = require('gulp-concat'),
cssmin = require('gulp-cssmin'),
templateCache = require('gulp-angular-templatecache'),
del = require('del'),
zip = require('gulp-zip'),
bump = require('gulp-bump'),
replace = require('gulp-replace'),
release = require('gulp-github-release'),
through = require('through2')
// TODO: add html-min
//jsdoc = require("gulp-jsdoc");
// Runing jshint an all source
gulp.task('lint', function() {
gulp.src(['src/**/*.js', '!src/lib/*'])
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
// Minify all project js files
gulp.task('minify', function () {
var assets = useref.assets();
var p = require('./package.json');
return gulp.src('index.html')
.pipe(assets)
.pipe(replace('"{{package.json.version}}"', '"' + p.version + '"'))
.pipe(uglify())
.pipe(assets.restore())
.pipe(useref())
.pipe(gulp.dest('build'));
});
// Append templates.js to app.js
gulp.task('concat-templates', ['templates', 'minify'], function() {
return gulp.src(['build/src/app.js', 'build/src/templates.js'])
.pipe(concat('app.js'))
.pipe(gulp.dest('build/src'));
});
// Minify css files
gulp.task('cssminify', function () {
gulp.src(['css/**/*.css', '!css/**/*.min.css'])
.pipe(cssmin())
.pipe(concat('main.css'))
.pipe(gulp.dest('build/css'));
});
// Copy other files to dist (like fonts, libs, images)
gulp.task('copyfiles', function () {
gulp.src(['src/lib/*.js'])
.pipe(gulp.dest('build/src/lib'));
gulp.src(['css/*.min.css'])
.pipe(gulp.dest('build/css'));
gulp.src(['fonts/*'])
.pipe(gulp.dest('build/fonts'));
gulp.src(['img/*'])
.pipe(gulp.dest('build/img'));
gulp.src(['updater.csp'])
.pipe(gulp.dest('build'));
});
// Create single tamplates file from *.html views
gulp.task('templates', function() {
var p = require('./package.json');
return gulp.src(['src/views/*.html'])
.pipe(replace('{{package.json.version}}', p.version))
.pipe(templateCache({root:"src/views/"}))
.pipe(gulp.dest('build/src'));
});
// Remove temporary files
gulp.task('cleanup', ['concat-templates'], function() {
del(["build/src/templates.js"]);
del(["build/*.zip"]);
});
// Creates zip with builded project
gulp.task('zip', function() {
var p = require('./package.json');
return gulp.src('build/**/*')
.pipe(zip('DSW-' + p.version + '.zip'))
.pipe(gulp.dest('build'));
});
// Deploys release on github
/*gulp.task('upload', ['zip'], function() {
var p = require('./package.json');
return gulp.src('./build/' + 'DSW-' + p.version + '.zip')
.pipe(release({
token: '', // or you can set an env var called GITHUB_TOKEN instead
owner: 'gnibeda',
name: 'DeepSeeWeb v' + p.version,
repo: 'publish-release',
tag: 'v'+p.version,
manifest: p
}));
});*/
gulp.task('makerelease', ['zip'], function() {
return gulp.src('./package.json')
//.pipe(bump())
.pipe(gulp.dest('./'));
});
var FILE_LIST;
gulp.task('enum-files', function() {
FILE_LIST = [];
return gulp.src(['./build/**/*', '!./build/DSW.Installer.xml'])
.pipe(through.obj(function (chunk, enc, cb) {
if (!chunk.isDirectory()) FILE_LIST.push(chunk.relative);
cb(null, chunk);
}));
});
/*gulp.task('test', function() {
var fs = require('fs');
var content = fs.readFileSync('./build/fonts/FontAwesome.otf', 'binary');
console.log(content.charCodeAt(7));
content = new Buffer(content, 'binary').toString('base64');
var dec = new Buffer(content, 'base64').toString("ascii");
console.log(content.substring(0, 40));
console.log(dec.charCodeAt(7));
});*/
gulp.task('create-install-package', ['enum-files'], function() {
var fs = require('fs');
var append = '';
for (var i = 0; i < FILE_LIST.length; i++) {
console.log('Adding file:', FILE_LIST[i]);
var content = fs.readFileSync('./build/' + FILE_LIST[i], 'binary');
content = new Buffer(content, 'binary').toString('base64');
var step = 32767;
var k = step;
while (k < content.length) {
content = content.substring(0, k) + '\r\n' + content.substring(k, content.length);
k += step;
}
append += `
<XData name="File${i}">
<Description>${FILE_LIST[i]}</Description>
<MimeType>text/plain</MimeType>
<Data><![CDATA[${content}]]></Data>
</XData>`;
}
// Change exists Installer class
var installer = fs.readFileSync('./DSW.Installer.xml', 'utf8');
installer = installer.substring(0, installer.length - 11);
installer += '<Class name="DSW.InstallerData">' + append + '</Class></Export>';
fs.writeFileSync('./build/DSW.Installer.xml', installer);
console.log('DSW.Installer.xml was created!')
});
/* Generate jsdoc
gulp.task('jsdoc', function() {
return gulp.src(['src/ * * /*.js', '!src/lib/*'])
.pipe(jsdoc('./documentation'));
});*/
gulp.task('default', ['lint', 'minify', 'cssminify', 'concat-templates', 'copyfiles', 'cleanup'], function () {});