Skip to content

Commit 8d31801

Browse files
style: reformat code
1 parent bec9b54 commit 8d31801

File tree

3 files changed

+67
-61
lines changed

3 files changed

+67
-61
lines changed

.github/workflows/update-migrate-progress.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ name: Update Migration Progress
22

33
on:
44
schedule:
5-
- cron: '0 * * * *'
5+
- cron: "0 * * * *"
66
workflow_dispatch:
77
inputs:
88
force:
9-
description: 'Force update even if no changes'
9+
description: "Force update even if no changes"
1010
required: false
1111
type: boolean
1212

@@ -47,4 +47,4 @@ jobs:
4747
git config user.email "github-actions[bot]@users.noreply.github.com"
4848
git add CPPREF_MIGRATE_PROGRESS.md
4949
git commit -m "chore: update migration progress [skip ci]"
50-
git push
50+
git push

migrate/cppref_index.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6639,4 +6639,4 @@
66396639
"cpp/experimental/ranges/utility/tagged/tagged",
66406640
"cpp/experimental/ranges/utility/tagged/tuple_element",
66416641
"cpp/experimental/ranges/utility/tagged/tuple_size"
6642-
]
6642+
]

migrate/update-migrate-progress.ts

Lines changed: 63 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,97 @@
1-
import fs from 'fs/promises';
2-
import path from 'path';
3-
import { fileURLToPath } from 'url';
1+
import fs from "fs/promises";
2+
import path from "path";
3+
import { fileURLToPath } from "url";
44

55
const __dirname = path.dirname(fileURLToPath(import.meta.url));
6-
const REPO_ROOT = path.join(__dirname, '..');
6+
const REPO_ROOT = path.join(__dirname, "..");
77

88
interface EntryStatus {
9-
entry: string;
10-
migrated: boolean;
11-
cpprefUrl: string;
12-
cppdocUrl: string;
13-
issueUrl: string;
9+
entry: string;
10+
migrated: boolean;
11+
cpprefUrl: string;
12+
cppdocUrl: string;
13+
issueUrl: string;
1414
}
1515

1616
async function fileExists(filePath: string): Promise<boolean> {
17-
try {
18-
await fs.access(filePath);
19-
return true;
20-
} catch {
21-
return false;
22-
}
17+
try {
18+
await fs.access(filePath);
19+
return true;
20+
} catch {
21+
return false;
22+
}
2323
}
2424

2525
async function isMigrated(entry: string): Promise<boolean> {
26-
// Possible paths
27-
const mdxPath = path.join(REPO_ROOT, 'src/content/docs', `${entry}.mdx`);
28-
const indexPath = path.join(REPO_ROOT, 'src/content/docs', entry, 'index.mdx');
26+
// Possible paths
27+
const mdxPath = path.join(REPO_ROOT, "src/content/docs", `${entry}.mdx`);
28+
const indexPath = path.join(
29+
REPO_ROOT,
30+
"src/content/docs",
31+
entry,
32+
"index.mdx"
33+
);
2934

30-
return (await fileExists(mdxPath)) || (await fileExists(indexPath));
35+
return (await fileExists(mdxPath)) || (await fileExists(indexPath));
3136
}
3237

33-
function generateUrls(entry: string): Omit<EntryStatus, 'entry' | 'migrated'> {
34-
const cpprefUrl = `http://en.cppreference.com/w/${entry}.html`;
35-
const cppdocUrl = `http://cppdoc.cc/${entry}`;
36-
const issueUrl = `https://github.com/cppdoc-cc/cppdoc/issues/new?title=${encodeURIComponent(cpprefUrl)}&labels=migrate-cppref-page`;
37-
return { cpprefUrl, cppdocUrl, issueUrl };
38+
function generateUrls(entry: string): Omit<EntryStatus, "entry" | "migrated"> {
39+
const cpprefUrl = `http://en.cppreference.com/w/${entry}.html`;
40+
const cppdocUrl = `http://cppdoc.cc/${entry}`;
41+
const issueUrl = `https://github.com/cppdoc-cc/cppdoc/issues/new?title=${encodeURIComponent(cpprefUrl)}&labels=migrate-cppref-page`;
42+
return { cpprefUrl, cppdocUrl, issueUrl };
3843
}
3944

4045
function generateMarkdown(status: EntryStatus): string {
41-
const { entry, migrated, cpprefUrl, cppdocUrl, issueUrl } = status;
42-
if (migrated) {
43-
return `| ✅ | [cppref](${cpprefUrl}) | [cppdoc](${cppdocUrl}) | \`${entry}\` | `;
44-
} else {
45-
return `| ❌ | [cppref](${cpprefUrl}) | [create](${issueUrl}) | \`${entry}\` |`;
46-
}
46+
const { entry, migrated, cpprefUrl, cppdocUrl, issueUrl } = status;
47+
if (migrated) {
48+
return `| ✅ | [cppref](${cpprefUrl}) | [cppdoc](${cppdocUrl}) | \`${entry}\` | `;
49+
} else {
50+
return `| ❌ | [cppref](${cpprefUrl}) | [create](${issueUrl}) | \`${entry}\` |`;
51+
}
4752
}
4853

4954
async function loadEntries(): Promise<string[]> {
50-
const indexPath = path.join(__dirname, 'cppref_index.json');
51-
const content = await fs.readFile(indexPath, 'utf-8');
52-
const entries = JSON.parse(content) as string[];
53-
// Ensure entries are strings and filter out any empty
54-
return entries.filter((e): e is string => typeof e === 'string' && e.length > 0);
55+
const indexPath = path.join(__dirname, "cppref_index.json");
56+
const content = await fs.readFile(indexPath, "utf-8");
57+
const entries = JSON.parse(content) as string[];
58+
// Ensure entries are strings and filter out any empty
59+
return entries.filter(
60+
(e): e is string => typeof e === "string" && e.length > 0
61+
);
5562
}
5663

5764
async function main() {
58-
console.log('Loading entries from cppref_index.json...');
59-
const entries = await loadEntries();
60-
console.log(`Total entries: ${entries.length}`);
65+
console.log("Loading entries from cppref_index.json...");
66+
const entries = await loadEntries();
67+
console.log(`Total entries: ${entries.length}`);
6168

62-
const statuses: EntryStatus[] = [];
63-
for (const entry of entries) {
64-
const migrated = await isMigrated(entry);
65-
const urls = generateUrls(entry);
66-
statuses.push({ entry, migrated, ...urls });
67-
if (statuses.length % 100 === 0) {
68-
console.log(`Processed ${statuses.length} entries...`);
69-
}
69+
const statuses: EntryStatus[] = [];
70+
for (const entry of entries) {
71+
const migrated = await isMigrated(entry);
72+
const urls = generateUrls(entry);
73+
statuses.push({ entry, migrated, ...urls });
74+
if (statuses.length % 100 === 0) {
75+
console.log(`Processed ${statuses.length} entries...`);
7076
}
77+
}
7178

72-
const migratedCount = statuses.filter(s => s.migrated).length;
73-
const markdownLines = statuses.map(generateMarkdown);
74-
const output =
75-
`### cppreference.com Migration Progress
79+
const migratedCount = statuses.filter((s) => s.migrated).length;
80+
const markdownLines = statuses.map(generateMarkdown);
81+
const output = `### cppreference.com Migration Progress
7682
#### Overall Progress: ${migratedCount} / ${statuses.length} migrated (${((migratedCount / statuses.length) * 100).toFixed(2)}%)
7783
Updated at ${new Date().toISOString()}
7884
7985
| Status | Cppref Link | Cppdoc Link | Entry |
8086
|--------|-------------|-------------|-------|
81-
${markdownLines.join('\n')}`;
87+
${markdownLines.join("\n")}`;
8288

83-
const outputPath = path.join(REPO_ROOT, 'CPPREF_MIGRATE_PROGRESS.md');
84-
await fs.writeFile(outputPath, output, 'utf-8');
85-
console.log(`Written to ${outputPath}`);
89+
const outputPath = path.join(REPO_ROOT, "CPPREF_MIGRATE_PROGRESS.md");
90+
await fs.writeFile(outputPath, output, "utf-8");
91+
console.log(`Written to ${outputPath}`);
8692
}
8793

8894
main().catch((err) => {
89-
console.error(err);
90-
process.exit(1);
91-
});
95+
console.error(err);
96+
process.exit(1);
97+
});

0 commit comments

Comments
 (0)