文件
mynode/packages/tools/validateFilenames.ts
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

36 行
1.3 KiB
TypeScript

// This is used to validate the Markdown filenames. The updateNews script uses the filename as the
// Discourse external_id, however that ID does not support certain characters, such as ".".
import { getRootDir } from '@joplin/utils';
import { fileExtension } from '@joplin/utils/path';
import { readdir } from 'fs/promises';
import { filename } from '@joplin/lib/path-utils';
const supportedExtensions = ['md', 'mdx'];
const allowedRegex = '^[a-zA-Z0-9_-]+$';
const main = async () => {
const readmeDir = `${await getRootDir()}/readme`;
const filePaths = await readdir(readmeDir, { recursive: true });
for (const filePath of filePaths) {
try {
const ext = fileExtension(filePath);
if (!supportedExtensions.includes(ext.toLowerCase())) continue;
if (!supportedExtensions.includes(ext)) throw new Error(`Invalid extension case (Supported extensions: ${JSON.stringify(supportedExtensions)})`);
const name = filename(filePath);
if (!name.match(new RegExp(allowedRegex))) throw new Error(`File format not allowed (Allowed characters: ${allowedRegex})`);
} catch (error) {
console.info(`Invalid filename: "${filePath}":`, error.message);
process.exit(1);
}
}
};
main().catch((error) => {
console.error('Fatal error');
console.error(error);
process.exit(1);
});