1+ import gulp from 'gulp' ;
2+ import { deleteAsync } from 'del' ;
3+ //const del = require('del');
4+ import { promises as fs } from 'fs' ;
5+ import path from 'path' ;
6+
7+ import replace from 'gulp-replace' ;
8+
9+ const dist_path = 'docs/.vitepress/dist' ;
10+ const www_path = 'www' ;
11+
12+ // Copy Job files
13+ async function copyDist ( ) {
14+ // Clean destination folder
15+ await deleteAsync ( [ path . join ( www_path , 'dist/**/*' ) ] ) ;
16+
17+ // Ensure destination directory exists
18+ await fs . mkdir ( path . join ( www_path , 'dist' ) , { recursive : true } ) ;
19+
20+ return new Promise ( ( resolve , reject ) => {
21+ // Copy files from source to destination
22+ gulp . src ( path . join ( dist_path , '**' , '*' ) ) // Include all files and subfolders
23+ . pipe ( gulp . dest ( path . join ( www_path , 'dist' ) ) ) // Destination folder
24+ . on ( 'end' , resolve ) // Resolve the Promise when the task is complete
25+ . on ( 'error' , reject ) // Reject the Promise if an error occurs
26+ . on ( 'error' , ( err ) => console . error ( 'Error during copy:' , err ) ) ; // Log errors
27+ } ) ;
28+
29+ }
30+
31+ function copyReplace ( ) {
32+ return gulp . src ( path . join ( dist_path , '**' , '*.*' ) ) // Adjust the path to your directory and file types
33+ . pipe ( replace ( / \/ c o m f o r t h r m d o c s \/ / g, ( match ) => {
34+ console . log ( `Replaced: ${ match } ` ) ; // Log every replacement
35+ return '' ; // Replace with '/'
36+ } ) )
37+ . pipe ( gulp . dest ( path . join ( www_path , 'dist' ) ) ) ; // Save the modified files to a 'dist' directory
38+ }
39+
40+
41+ // Define complex tasks
42+ const www = gulp . series ( copyDist , copyReplace ) ;
43+
44+ export { www } ; // Export task so it can be run via npm
0 commit comments