diff --git a/index.html b/index.html
index 3c0f2dc4..d9c9d3dc 100644
--- a/index.html
+++ b/index.html
@@ -4,7 +4,7 @@
OxJS - A JavaScript Library for Web Applications
-
+
diff --git a/rollup.config.js b/rollup.config.js
index b131da12..9204cc9f 100644
--- a/rollup.config.js
+++ b/rollup.config.js
@@ -98,11 +98,83 @@ function install(options = {}) {
}
return {
- name: 'theme-plugin',
+ name: 'install-plugin',
writeBundle
};
}
+function symlinkDevPlugin(options = {}) {
+ const sourcePath = options.source || 'source';
+ const devPath = options.dev || 'dev';
+
+ function shouldInclude(filePath, filename) {
+ if (filePath.includes('_')) return false;
+ if (filename.startsWith('.') || filename.startsWith('_')) return false;
+ if (filename.endsWith('~')) return false;
+ if (filePath.includes(`${path.sep}UI${path.sep}svg`)) return false;
+ return true;
+ }
+
+ function ensureDir(dir) {
+ fs.mkdirSync(dir, { recursive: true });
+ }
+
+ function removeIfExists(target) {
+ if (fs.existsSync(target) || fs.lstatSync(target, { throwIfNoEntry: false })) {
+ try {
+ const stat = fs.lstatSync(target);
+ if (stat.isSymbolicLink()) {
+ fs.unlinkSync(target);
+ } else if (stat.isDirectory()) {
+ fs.rmdirSync(target);
+ } else {
+ console.log("not symlink, what to do?", target)
+ }
+ } catch (err) {
+ // ignore if it doesn't exist anymore
+ }
+ }
+ }
+
+ function walk(dir) {
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
+
+ for (const entry of entries) {
+ const fullPath = path.join(dir, entry.name);
+
+ if (entry.isDirectory()) {
+ walk(fullPath);
+ } else if (entry.isFile()) {
+ if (!shouldInclude(dir, entry.name)) continue;
+
+ const relativePath = path.relative(sourcePath, dir);
+ const targetDir = path.join(devPath, relativePath);
+ const targetPath = path.join(targetDir, entry.name);
+ const relativeSource = path.relative(targetDir, fullPath);
+ ensureDir(targetDir);
+ removeIfExists(targetPath);
+ if (!fs.existsSync(targetPath)) {
+ fs.symlinkSync(relativeSource, targetPath);
+ }
+ }
+ }
+ }
+
+ return {
+ name: 'symlink-dev-plugin',
+
+ writeBundle() {
+ if (!fs.existsSync(sourcePath)) {
+ this.warn(`Source path "${sourcePath}" does not exist.`);
+ return;
+ }
+
+ walk(sourcePath);
+ }
+ };
+}
+
+
// TBD: get version
// TBD: add ' OxJS %s (c) %s 0x2620, dual-licensed GPL/MIT, see https://oxjs.org for details ' % (version, year)
//
@@ -183,6 +255,7 @@ export default {
],
hook: 'writeBundle'
}),
- install()
+ install(),
+ symlinkDevPlugin()
]
};