@@ -11,7 +11,7 @@ const childProcess = require('child_process');
1111const merge = require ( 'merge-stream' ) ;
1212const zip = require ( 'gulp-zip' ) ;
1313const hashFilename = require ( 'gulp-hash-filename' ) ;
14- const fsUtil = require ( './fs-util' ) ;
14+ const fsUtil = require ( './fs-util.cjs ' ) ;
1515var packageJson = JSON . parse ( fs . readFileSync ( './package.json' ) ) ;
1616
1717function minifyJs ( fileName ) {
@@ -31,12 +31,15 @@ function minifyJs(fileName) {
3131
3232gulp . 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
117104gulp . 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- / s t y l e \. c s s / 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- / s t y l e \. c s s / 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
155135gulp . 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
173164gulp . task ( 'cleanup' , function ( ) {
174165 return childProcess . execSync ( 'rm -rf app extension' ) ;
175166} ) ;
167+
176168gulp . task ( 'cleanup-build' , function ( ) {
177169 return childProcess . execSync ( 'rm -rf build' ) ;
178170} ) ;
0 commit comments