port /dev symlinks
This commit is contained in:
parent
23075d6739
commit
a890b25bc4
2 changed files with 76 additions and 3 deletions
|
|
@ -4,7 +4,7 @@
|
||||||
<title>OxJS - A JavaScript Library for Web Applications</title>
|
<title>OxJS - A JavaScript Library for Web Applications</title>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||||
<link rel="stylesheet" type="text/css" href="index.css"/>
|
<link rel="stylesheet" type="text/css" href="index.css"/>
|
||||||
<script type="text/javascript" src="source/Ox.js"></script>
|
<script type="text/javascript" src="dev/Ox.js"></script>
|
||||||
<script type="text/javascript" src="index.js"></script>
|
<script type="text/javascript" src="index.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body></body>
|
<body></body>
|
||||||
|
|
|
||||||
|
|
@ -98,11 +98,83 @@ function install(options = {}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: 'theme-plugin',
|
name: 'install-plugin',
|
||||||
writeBundle
|
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: get version
|
||||||
// TBD: add ' OxJS %s (c) %s 0x2620, dual-licensed GPL/MIT, see https://oxjs.org for details ' % (version, year)
|
// 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'
|
hook: 'writeBundle'
|
||||||
}),
|
}),
|
||||||
install()
|
install(),
|
||||||
|
symlinkDevPlugin()
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue