1
1
const fs = require ( 'fs' ) ;
2
+ const path = require ( 'path' ) ;
3
+
2
4
const upload = require ( '@cocreate/cli/src/commands/upload.js' )
3
5
4
6
class ModuleGenerator {
@@ -54,6 +56,7 @@ class ModuleGenerator {
54
56
} ) ;
55
57
}
56
58
}
59
+
57
60
class fileUploader {
58
61
constructor ( env ) {
59
62
this . env = env ;
@@ -78,5 +81,39 @@ class fileUploader {
78
81
}
79
82
}
80
83
84
+ class SymlinkCreator {
85
+ constructor ( options ) {
86
+ // Store options if necessary, or just hard-code paths
87
+ }
88
+
89
+ apply ( compiler ) {
90
+ // Use compiler.hooks to tap into the Webpack build process
91
+ compiler . hooks . afterEmit . tap ( 'SymlinkPlugin' , ( compilation ) => {
92
+ // Perform symlink operations here
93
+ symlink ( './dist' , '../dist' , 'dir' ) ;
94
+ symlink ( './node_modules/@cocreate/pwa/src/service-worker.js' , '../service-worker.js' , 'file' ) ;
95
+ symlink ( './node_modules/@cocreate/pwa/src/manifest.webmanifest' , '../manifest.webmanifest' , 'file' ) ;
96
+ symlink ( './node_modules/@cocreate/pwa/src/offline.html' , '../offline.html' , 'file' ) ;
97
+ } ) ;
98
+
99
+ function symlink ( target , destination , option ) {
100
+ if ( fs . existsSync ( target ) ) {
101
+ target = path . resolve ( target )
102
+
103
+ if ( ! fs . existsSync ( destination ) ) {
104
+ destination = path . resolve ( destination )
105
+
106
+ fs . symlink ( target , destination , option , ( err ) => {
107
+ if ( err )
108
+ console . log ( err ) ;
109
+ else
110
+ console . log ( "symlink added: " , target ) ;
111
+ } )
112
+
113
+ }
114
+ }
115
+ }
116
+ }
117
+ }
81
118
82
- module . exports = { ModuleGenerator, fileUploader } ;
119
+ module . exports = { ModuleGenerator, fileUploader, SymlinkCreator } ;
0 commit comments