文件
mynode/packages/tools/absolute-to-relative-paths.js
chen 301194963b
一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
feat: Initial clean release of CHM
2026-11-04 11:29:39 +08:00

49 行
1.2 KiB
JavaScript

const glob = require('glob');
const fs = require('fs-extra');
const dirname = require('path').dirname;
const relative = require('relative');
const libDir = `${dirname(__dirname)}/lib`;
// function getBasename(p) {
// const pieces = p.split('/');
// pieces.pop();
// return pieces.join('/');
// }
function toLinuxPath(p) {
return p.replace(/\\/g, '/');
}
function getRelativePath(from, to) {
let p = relative(from, to);
if (p.indexOf('.') !== 0) p = `./${p}`;
return toLinuxPath(p);
}
async function main() {
const files = glob.sync(`${libDir}{/**/*.ts,/**/*.tsx,/**/*.js}`, {
ignore: [
'**/node_modules/**',
'**/*.d.ts',
],
}).map(f => f.substr(libDir.length + 1));
for (const file of files) {
const content = await fs.readFile(`${libDir}/${file}`, 'utf8');
const newContent = content.replace(/('|")(inner\/lib\/.*)('|")/g, (_matched, p1, p2, p3) => {
const absoluteRequirePath = p2.substr(10);
const relativePath = getRelativePath(file, absoluteRequirePath);
return p1 + relativePath + p3;
});
await fs.writeFile(`${libDir}/${file}`, newContent, 'utf8');
}
}
main().catch((error) => {
console.error(error);
process.exit(1);
});