Skip to content

Commit cf84dee

Browse files
authored
Merge pull request #761 from ZenUml/migrate-vite
Migrate vite
2 parents f3851b1 + 94c0b97 commit cf84dee

File tree

199 files changed

+1706
-6403
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

199 files changed

+1706
-6403
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
### OSX ###
22
.DS_Store
3+
.cursor
34

45
.vscode
56
logs
@@ -17,8 +18,9 @@ node_modules/
1718
*.map
1819

1920
.sass-cache
20-
### folders built by preact or gulp
21+
### folders built by vite, preact or gulp
2122
/build/
23+
/dist/
2224
/extension/
2325
/app/
2426

File renamed without changes.

gulpfile.js renamed to gulpfile.cjs

Lines changed: 63 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const childProcess = require('child_process');
1111
const merge = require('merge-stream');
1212
const zip = require('gulp-zip');
1313
const hashFilename = require('gulp-hash-filename');
14-
const fsUtil = require('./fs-util');
14+
const fsUtil = require('./fs-util.cjs');
1515
var packageJson = JSON.parse(fs.readFileSync('./package.json'));
1616

1717
function minifyJs(fileName) {
@@ -31,12 +31,15 @@ function minifyJs(fileName) {
3131

3232
gulp.task('copyFiles', function () {
3333
return merge(
34+
// Copy static assets
3435
gulp.src('static/**/*').pipe(gulp.dest('app/static')),
3536
gulp.src('help/**/*').pipe(gulp.dest('app/help')),
3637
gulp.src('privacy-policy/*').pipe(gulp.dest('app/privacy-policy')),
3738
gulp
3839
.src('End-User-License-Agreement/*')
3940
.pipe(gulp.dest('app/End-User-License-Agreement')),
41+
42+
// Copy library files that are still needed
4043
gulp
4144
.src('src/lib/codemirror/lib/*')
4245
.pipe(gulp.dest('app/lib/codemirror/lib')),
@@ -57,6 +60,8 @@ gulp.task('copyFiles', function () {
5760
gulp.src('src/animation/*').pipe(gulp.dest('app/animation')),
5861
gulp.src('src/templates/*').pipe(gulp.dest('app/templates')),
5962
gulp.src('icons/*').pipe(gulp.dest('app/icons')),
63+
64+
// Copy root files
6065
gulp
6166
.src([
6267
'help.html',
@@ -65,29 +70,14 @@ gulp.task('copyFiles', function () {
6570
'src/icon-16.png',
6671
'src/icon-48.png',
6772
'src/icon-128.png',
68-
'manifest.json',
73+
'static/manifest.json',
6974
])
7075
.pipe(gulp.dest('app')),
71-
gulp.src('build/*.js').pipe(gulp.dest('app')),
72-
gulp.src('build/*.css').pipe(gulp.dest('app')),
73-
// Following CSS are copied to build/ folder where they'll be referenced by
74-
// useRef plugin to concat into one.
75-
gulp
76-
.src('src/lib/codemirror/lib/codemirror.css')
77-
.pipe(gulp.dest('build/lib/codemirror/lib')),
78-
gulp
79-
.src('src/lib/codemirror/addon/hint/show-hint.css')
80-
.pipe(gulp.dest('build/lib/codemirror/addon/hint')),
81-
gulp
82-
.src('src/lib/codemirror/addon/fold/foldgutter.css')
83-
.pipe(gulp.dest('build/lib/codemirror/addon/fold')),
84-
gulp
85-
.src('src/lib/codemirror/addon/dialog/dialog.css')
86-
.pipe(gulp.dest('build/lib/codemirror/addon/dialog')),
87-
gulp.src('src/lib/hint.min.css').pipe(gulp.dest('build/lib')),
88-
gulp.src('src/lib/inlet.css').pipe(gulp.dest('build/lib')),
89-
gulp.src('src/style.css').pipe(hashFilename()).pipe(gulp.dest('build')),
90-
gulp.src('src/preview.html').pipe(gulp.dest('build')),
76+
77+
// Copy Vite build output from dist/ instead of build/
78+
gulp.src('dist/**/*').pipe(gulp.dest('app')),
79+
80+
// Copy fonts
9181
gulp
9282
.src([
9383
'src/FiraCode.ttf',
@@ -99,80 +89,82 @@ gulp.task('copyFiles', function () {
9989
);
10090
});
10191

102-
// Generate script.js, vendor.js, style.css and vendor.css and index.html under ./app/
103-
gulp.task('useRef', function () {
104-
return gulp.src('build/*.html').pipe(useref()).pipe(gulp.dest('app'));
92+
// This task is no longer needed since Vite handles HTML processing
93+
gulp.task('useRef', function (callback) {
94+
// Skip useRef since Vite already processes HTML files
95+
callback();
10596
});
10697

107-
const bundleJs = () => fsUtil.getBundleJs('build');
108-
109-
gulp.task('concat', function () {
110-
// TODO: Don't understand what does it do
111-
gulp
112-
.src([`app/${bundleJs()}`])
113-
.pipe(concat(bundleJs()))
114-
.pipe(gulp.dest('app'));
98+
// This task is no longer needed since Vite handles bundling
99+
gulp.task('concat', function (callback) {
100+
// Skip concat since Vite already handles bundling
101+
callback();
115102
});
116103

117104
gulp.task('minify', function () {
118-
// TODO: don't know why it causes unknown error: `Uncaught IllegalState`
119-
// minifyJs(`app/${bundleJs()}`);
120-
minifyJs('app/lib/screenlog.js');
121-
122-
gulp
123-
.src('app/*.css')
124-
.pipe(
125-
cleanCSS(
126-
{
127-
debug: true,
128-
},
129-
(details) => {
130-
console.log(`${details.name}: ${details.stats.originalSize}`);
131-
console.log(`${details.name}: ${details.stats.minifiedSize}`);
132-
},
133-
),
134-
)
135-
.pipe(gulp.dest('app'));
105+
// Only minify specific files that need additional processing
106+
if (fs.existsSync('app/lib/screenlog.js')) {
107+
minifyJs('app/lib/screenlog.js');
108+
}
109+
110+
// Minify CSS files if they exist
111+
if (fs.existsSync('app') && fs.readdirSync('app').some(file => file.endsWith('.css'))) {
112+
gulp
113+
.src('app/*.css')
114+
.pipe(
115+
cleanCSS(
116+
{
117+
debug: true,
118+
},
119+
(details) => {
120+
console.log(`${details.name}: ${details.stats.originalSize}`);
121+
console.log(`${details.name}: ${details.stats.minifiedSize}`);
122+
},
123+
),
124+
)
125+
.pipe(gulp.dest('app'));
126+
}
136127
});
137128

138-
gulp.task('fixIndex', function () {
139-
var contents = fs.readFileSync('build/index.html', 'utf8');
140-
// style.css is replaced with style-[hash].css
141-
contents = contents.replace(
142-
/style\.css/g,
143-
fsUtil.getHashedFile('build', 'style-', 'css'),
144-
);
145-
fs.writeFileSync('build/index.html', contents, 'utf8');
146-
contents = fs.readFileSync('build/preview.html', 'utf8');
147-
// style.css is replaced with style-[hash].css
148-
contents = contents.replace(
149-
/style\.css/g,
150-
fsUtil.getHashedFile('build', 'style-', 'css'),
151-
);
152-
fs.writeFileSync('build/preview.html', contents, 'utf8');
129+
// This task is no longer needed since Vite handles file processing
130+
gulp.task('fixIndex', function (callback) {
131+
// Skip fixIndex since Vite already handles HTML processing with proper hashing
132+
callback();
153133
});
154134

155135
gulp.task('packageExtension', function () {
156136
childProcess.execSync('cp -R app/ extension');
157-
childProcess.execSync('cp src/manifest.json extension');
137+
childProcess.execSync('cp static/manifest.json extension'); // manifest.json is in root, not src/
158138
childProcess.execSync('cp src/extension/options.js extension');
159139
childProcess.execSync('cp src/extension/options.html extension');
160140
childProcess.execSync('cp src/extension/eventPage.js extension');
161141
childProcess.execSync('cp src/extension/script.js extension');
162-
childProcess.execSync('cp src/icon-16.png extension');
163-
childProcess.execSync('cp src/icon-48.png extension');
164-
childProcess.execSync('cp src/icon-128.png extension');
142+
143+
// Copy icon files from their actual locations
144+
if (fs.existsSync('static/icon-16.png')) {
145+
childProcess.execSync('cp static/icon-16.png extension');
146+
}
147+
if (fs.existsSync('static/icon-48.png')) {
148+
childProcess.execSync('cp static/icon-48.png extension');
149+
}
150+
if (fs.existsSync('icon-128.png')) {
151+
childProcess.execSync('cp icon-128.png extension');
152+
} else if (fs.existsSync('static/icon-128.png')) {
153+
childProcess.execSync('cp static/icon-128.png extension');
154+
}
165155

166156
childProcess.execSync('rm -rf extension/partials');
167157
return merge(
168-
gulp.src('build/bundle.*.js').pipe(gulp.dest('extension')),
158+
// Copy any additional JS files from dist if they exist
159+
gulp.src('dist/assets/*.js', { allowEmpty: true }).pipe(gulp.dest('extension/assets')),
169160
gulp.src('extension/**/*').pipe(zip(`extension.zip`)).pipe(gulp.dest('./')),
170161
);
171162
});
172163

173164
gulp.task('cleanup', function () {
174165
return childProcess.execSync('rm -rf app extension');
175166
});
167+
176168
gulp.task('cleanup-build', function () {
177169
return childProcess.execSync('rm -rf build');
178170
});

package.json

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
"version": "1.0.24",
44
"description": "A real-time tool for generating sequence diagrams",
55
"main": "index.html",
6+
"type": "module",
67
"scripts": {
78
"engine": "use yarn instead of npm please",
89
"start": "if-env NODE_ENV=production && yarn serve || yarn dev",
9-
"build": "preact build --template src/index.html --no-inline-css --no-prerender --no-sw",
10-
"release": "gulp release",
10+
"build": "vite build",
11+
"release": "gulp --gulpfile gulpfile.cjs release",
1112
"prep:release:git-tag-push": "git tag release-`date +%Y%m%d%H%M` && git push origin release-`date +%Y%m%d%H%M`",
12-
"dev": "preact watch --template src/index.html --no-prerender",
13+
"dev": "vite",
14+
"preview": "vite preview",
1315
"lint": "eslint src",
1416
"test": "jest ./",
1517
"deploy:staging": "firebase deploy --project staging",
@@ -25,6 +27,7 @@
2527
},
2628
"eslintIgnore": [
2729
"build/*",
30+
"dist/*",
2831
"src/lib/",
2932
"src/tests/",
3033
"src/CodeMirror.js",
@@ -39,6 +42,9 @@
3942
"devDependencies": {
4043
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
4144
"@babel/plugin-proposal-optional-chaining": "^7.21.0",
45+
"@preact/preset-vite": "^2.10.1",
46+
"@vitejs/plugin-legacy": "^6.1.1",
47+
"autoprefixer": "^10.4.21",
4248
"babel-minify": "^0.5.2",
4349
"enzyme": "^3.11.0",
4450
"enzyme-adapter-preact-pure": "^2.3.0",
@@ -55,12 +61,14 @@
5561
"gulp-zip": "^5.0.2",
5662
"jest": "^24.9.0",
5763
"jest-preset-preact": "^1.0.0",
64+
"postcss": "^8.5.4",
5865
"postcss-custom-media": "^10.0.4",
59-
"preact-cli": "^3.5.1",
6066
"prettier": "^3.2.5",
6167
"run-sequence": "^2.2.1",
6268
"sirv-cli": "1.0.3",
63-
"tailwindcss": "^3.4.3"
69+
"tailwindcss": "^3.4.3",
70+
"terser": "^5.41.0",
71+
"vite": "^6.3.5"
6472
},
6573
"dependencies": {
6674
"@emmetio/codemirror-plugin": "^1.1.3",
@@ -82,6 +90,7 @@
8290
"http-server": "^0.12.3",
8391
"jszip": "3.8.0",
8492
"preact": "10.18.1",
93+
"preact-compat": "^3.19.0",
8594
"preact-render-to-string": "^6.2.2",
8695
"preact-router": "^4.1.2",
8796
"split.js": "1.6.0",

postcss.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default {
2+
plugins: {
3+
'postcss-custom-media': {},
4+
tailwindcss: {},
5+
autoprefixer: {},
6+
},
7+
};

preact.config.js

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)