11const fs = require ( 'fs' ) ;
22const path = require ( 'path' ) ;
3- const file = require ( '@cocreate/file' )
3+ const upload = require ( '@cocreate/cli/src/commands/upload.js' )
4+
45const { CleanWebpackPlugin } = require ( 'clean-webpack-plugin' ) ;
56const TerserPlugin = require ( "terser-webpack-plugin" ) ;
67const MiniCssExtractPlugin = require ( 'mini-css-extract-plugin' ) ;
78const CssMinimizerPlugin = require ( 'css-minimizer-webpack-plugin' ) ;
89
910module . exports = async ( env , argv ) => {
10- let isProduction = false
11- if ( argv . mode === 'production' )
12- isProduction = true
11+ const isProduction = argv . mode === 'production'
12+ const isWatch = argv . watch === true ;
1313
1414 const config = {
1515 // Path to your entry point. From this file Webpack will begin his work
@@ -135,29 +135,9 @@ module.exports = async (env, argv) => {
135135 } ) ;
136136 }
137137
138- const parentDirectory = path . join ( __dirname , '..' ) ;
139- console . log ( 'Watching: ' , parentDirectory )
140-
141- fs . watch ( parentDirectory , { recursive : true } , async ( eventType , filename ) => {
142- if ( ! filename . includes ( 'CoCreate.config.js' ) ) {
143- const filePath = path . resolve ( parentDirectory , filename ) ;
144- if ( ! filePath . includes ( 'node_modules' ) ) {
145-
146- const configPath = findClosestConfig ( filePath ) ;
147- if ( configPath ) {
148- const config = require ( configPath ) ;
149-
150- if ( config ) {
151- await file ( config , configPath , filePath )
152- } else {
153- console . log ( 'Failed to read or parse CoCreate.config.js.' ) ;
154- }
155- } else {
156- console . log ( 'No CoCreate.config file found in parent directories.' ) ;
157- }
158- }
159- }
160- } ) ;
138+ if ( isWatch ) {
139+ upload ( __dirname , [ '../' , '-w' ] )
140+ }
161141
162142 return config ;
163143
@@ -180,19 +160,3 @@ function symlink(target, destination, option) {
180160 }
181161 }
182162}
183-
184- function findClosestConfig ( filePath ) {
185- let currentDir = path . dirname ( filePath ) ;
186-
187- while ( currentDir !== '/' && currentDir !== '.' ) {
188- let configFile = path . join ( currentDir , 'CoCreate.config.js' ) ;
189- if ( fs . existsSync ( configFile ) ) {
190- return configFile ;
191- }
192-
193- currentDir = path . dirname ( currentDir ) ;
194- }
195-
196- return null ;
197- }
198-
0 commit comments