build: add precompiled CLI distribution
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import 'dotenv/config';
|
||||
import path from 'node:path';
|
||||
import { discoverDecks, validateDeck } from "./lib/content.js";
|
||||
import { loadProjectConfig } from "./lib/config.js";
|
||||
import { formatStaticOverflowResult } from "./lib/overflow-report.js";
|
||||
import { auditStaticDecks } from "./lib/static-overflow.js";
|
||||
import { hasPresenterToken } from "./lib/token.js";
|
||||
export async function checkProject(cwd = process.cwd(), providedConfig) {
|
||||
const config = providedConfig ?? await loadProjectConfig(cwd);
|
||||
const decks = await discoverDecks(cwd, config.slidesDir);
|
||||
const issues = [];
|
||||
if (decks.length === 0)
|
||||
issues.push({ level: 'error', file: path.join(cwd, config.slidesDir), message: `没有发现 ${config.slidesDir}/<slug>/slides.md` });
|
||||
for (const deck of decks)
|
||||
issues.push(...await validateDeck(deck));
|
||||
const staticOverflow = await auditStaticDecks(decks);
|
||||
if (!hasPresenterToken()) {
|
||||
issues.push({
|
||||
level: 'warning',
|
||||
file: path.join(cwd, '.env'),
|
||||
message: '未设置 PRESENTER_TOKEN;生产构建将隐藏演示者入口',
|
||||
});
|
||||
}
|
||||
return { config, decks, issues, staticOverflow };
|
||||
}
|
||||
export function printIssues(issues, cwd = process.cwd()) {
|
||||
for (const issue of issues) {
|
||||
const marker = issue.level === 'error' ? 'ERROR' : 'WARN ';
|
||||
console.log(`${marker} ${path.relative(cwd, issue.file)}: ${issue.message}`);
|
||||
}
|
||||
}
|
||||
export async function runCheck() {
|
||||
const result = await checkProject();
|
||||
printIssues(result.issues);
|
||||
formatStaticOverflowResult(result.staticOverflow).forEach(line => console.log(line));
|
||||
const errors = result.issues.filter(issue => issue.level === 'error');
|
||||
if (errors.length > 0) {
|
||||
console.error(`\n检查失败:${errors.length} 个错误`);
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
const warnings = result.issues.filter(issue => issue.level === 'warning').length
|
||||
+ result.staticOverflow.issues.length
|
||||
+ result.staticOverflow.errors.length;
|
||||
console.log(`\n检查通过:${result.decks.length} 套演示,${warnings} 个警告`);
|
||||
}
|
||||
if (import.meta.url === new URL(process.argv[1], 'file:').href)
|
||||
await runCheck();
|
||||
//# sourceMappingURL=check.js.map
|
||||
Reference in New Issue
Block a user