Skip to content

Commit 00affbd

Browse files
committed
on watch files are observerd for changes and matched to there config. if match is found upload or save source
1 parent 4b823b0 commit 00affbd

File tree

1 file changed

+46
-7
lines changed

1 file changed

+46
-7
lines changed

webpack.config.js

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const fs = require('fs');
22
const path = require('path');
3-
3+
const file = require('@cocreate/file')
44
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
55
const TerserPlugin = require("terser-webpack-plugin");
66
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
@@ -126,16 +126,39 @@ module.exports = async (env, argv) => {
126126
if (!isProduction) {
127127
config.plugins.push({
128128
apply: (compiler) => {
129-
compiler.hooks.done.tap('BuildCompletePlugin', () => {
130-
console.log('Webpack build is complete in development mode!');
131-
symlink('./dist', '../dist', 'dir')
132-
symlink('./node_modules/@cocreate/pwa/src/service-worker.js', '../service-worker.js', 'file')
133-
symlink('./node_modules/@cocreate/pwa/src/manifest.webmanifest', '../manifest.webmanifest', 'file')
134-
});
129+
// console.log('Webpack build is complete in development mode!');
130+
symlink('./dist', '../dist', 'dir')
131+
symlink('./node_modules/@cocreate/pwa/src/service-worker.js', '../service-worker.js', 'file')
132+
symlink('./node_modules/@cocreate/pwa/src/manifest.webmanifest', '../manifest.webmanifest', 'file')
133+
symlink('./node_modules/@cocreate/pwa/src/offline.html', '../offline.html', 'file')
135134
},
136135
});
137136
}
138137

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+
});
161+
139162
return config;
140163

141164
}
@@ -157,3 +180,19 @@ function symlink(target, destination, option) {
157180
}
158181
}
159182
}
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

Comments
 (0)