-
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathgulpfile.cjs
More file actions
188 lines (170 loc) · 5.85 KB
/
gulpfile.cjs
File metadata and controls
188 lines (170 loc) · 5.85 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
182
183
184
185
186
187
188
/*eslint-env node*/
const fs = require('fs');
const gulp = require('gulp');
const runSequence = require('run-sequence');
const useref = require('gulp-useref');
const cleanCSS = require('gulp-clean-css');
const concat = require('gulp-concat');
const babelMinify = require('babel-minify');
const childProcess = require('child_process');
const merge = require('merge-stream');
const zip = require('gulp-zip');
const hashFilename = require('gulp-hash-filename');
const fsUtil = require('./fs-util.cjs');
var packageJson = JSON.parse(fs.readFileSync('./package.json'));
function minifyJs(fileName) {
const content = fs.readFileSync(fileName, 'utf8');
const minifiedContent = babelMinify(
content,
{ mangle: content.length < 700000 },
{ sourceMaps: false },
).code;
fs.writeFileSync(fileName, minifiedContent);
console.log(
`[${fileName}]: ${content.length / 1024}K -> ${
minifiedContent.length / 1024
}K`,
);
}
gulp.task('copyFiles', function () {
return merge(
// Copy static assets
gulp.src('static/**/*').pipe(gulp.dest('app/static')),
gulp.src('help/**/*').pipe(gulp.dest('app/help')),
gulp.src('privacy-policy/*').pipe(gulp.dest('app/privacy-policy')),
gulp
.src('End-User-License-Agreement/*')
.pipe(gulp.dest('app/End-User-License-Agreement')),
// Copy library files that are still needed
gulp
.src('src/lib/codemirror/lib/*')
.pipe(gulp.dest('app/lib/codemirror/lib')),
gulp
.src('src/lib/codemirror/theme/*')
.pipe(gulp.dest('app/lib/codemirror/theme')),
gulp
.src('src/lib/codemirror/mode/**/*')
.pipe(gulp.dest('app/lib/codemirror/mode')),
gulp.src('src/lib/transpilers/*').pipe(gulp.dest('app/lib/transpilers')),
gulp.src('src/lib/prettier-worker.js').pipe(gulp.dest('app/lib/')),
gulp.src('src/lib/prettier/*').pipe(gulp.dest('app/lib/prettier')),
gulp.src('src/lib/screenlog.js').pipe(gulp.dest('app/lib')),
gulp.src('src/lib/paddle.js').pipe(gulp.dest('app/lib')),
gulp.src('src/lib/gtm.js').pipe(gulp.dest('app/lib')),
gulp.src('src/lib/sequence-ext.css').pipe(gulp.dest('app/lib')),
gulp.src('src/assets/*').pipe(gulp.dest('app/assets')),
gulp.src('src/animation/*').pipe(gulp.dest('app/animation')),
gulp.src('src/templates/*').pipe(gulp.dest('app/templates')),
gulp.src('icons/*').pipe(gulp.dest('app/icons')),
// Copy root files
gulp
.src([
'help.html',
'ZenUML_Sequence_Diagram_addon_help.html',
'src/detached-window.js',
'src/icon-16.png',
'src/icon-48.png',
'src/icon-128.png',
'static/manifest.json',
])
.pipe(gulp.dest('app')),
// Copy Vite build output from dist/ instead of build/
gulp.src('dist/**/*').pipe(gulp.dest('app')),
// Copy fonts
gulp
.src([
'src/FiraCode.ttf',
'src/FixedSys.ttf',
'src/Inconsolata.ttf',
'src/Monoid.ttf',
])
.pipe(gulp.dest('app')),
);
});
// This task is no longer needed since Vite handles HTML processing
gulp.task('useRef', function (callback) {
// Skip useRef since Vite already processes HTML files
callback();
});
// This task is no longer needed since Vite handles bundling
gulp.task('concat', function (callback) {
// Skip concat since Vite already handles bundling
callback();
});
gulp.task('minify', function () {
// Only minify specific files that need additional processing
if (fs.existsSync('app/lib/screenlog.js')) {
minifyJs('app/lib/screenlog.js');
}
// Minify CSS files if they exist
if (fs.existsSync('app') && fs.readdirSync('app').some(file => file.endsWith('.css'))) {
gulp
.src('app/*.css')
.pipe(
cleanCSS(
{
debug: true,
},
(details) => {
console.log(`${details.name}: ${details.stats.originalSize}`);
console.log(`${details.name}: ${details.stats.minifiedSize}`);
},
),
)
.pipe(gulp.dest('app'));
}
});
// This task is no longer needed since Vite handles file processing
gulp.task('fixIndex', function (callback) {
// Skip fixIndex since Vite already handles HTML processing with proper hashing
callback();
});
gulp.task('packageExtension', function () {
childProcess.execSync('cp -R app/ extension');
childProcess.execSync('cp static/manifest.json extension'); // manifest.json is in root, not src/
childProcess.execSync('cp src/extension/options.js extension');
childProcess.execSync('cp src/extension/options.html extension');
childProcess.execSync('cp src/extension/eventPage.js extension');
childProcess.execSync('cp src/extension/script.js extension');
// Copy icon files for Chrome Extension
if (fs.existsSync('static/favicon-128x128.png')) {
childProcess.execSync('cp static/favicon-128x128.png extension');
}
if (fs.existsSync('static/icon-16.png')) {
childProcess.execSync('cp static/icon-16.png extension');
}
if (fs.existsSync('static/icon-48.png')) {
childProcess.execSync('cp static/icon-48.png extension');
}
childProcess.execSync('rm -rf extension/partials');
return merge(
// Copy any additional JS files from dist if they exist
gulp.src('dist/assets/*.js', { allowEmpty: true }).pipe(gulp.dest('extension/assets')),
gulp.src('extension/**/*').pipe(zip(`extension.zip`)).pipe(gulp.dest('./')),
);
});
gulp.task('cleanup', function () {
return childProcess.execSync('rm -rf app extension');
});
gulp.task('cleanup-build', function () {
return childProcess.execSync('rm -rf build');
});
gulp.task('release', function (callback) {
runSequence(
'cleanup',
'copyFiles',
'fixIndex',
'useRef',
'concat',
'minify',
'packageExtension',
function (error) {
if (error) {
console.log(error.message);
} else {
console.log('RELEASE FINISHED SUCCESSFULLY');
}
callback(error);
},
);
});