Skip to content

Commit a8cd2ea

Browse files
Fix CI failures: convert JS scripts to TS, fix Prettier formatting, add spellcheck words
Co-authored-by: Stephanie Elliott <stephanieelliott@users.noreply.github.com>
1 parent a3842c8 commit a8cd2ea

6 files changed

Lines changed: 110 additions & 112 deletions

File tree

.github/scripts/createDocsRoutes.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,18 +188,15 @@ function run() {
188188
const travelArticleHubs = fs.readdirSync(`${docsDir}/articles/${platformNames.travel}`);
189189
const consolidatedArticleHubs = fs.readdirSync(`${docsDir}/articles/${platformNames.consolidated}`);
190190

191-
192191
const expensifyClassicRoute = routes.platforms.find((platform) => platform.href === platformNames.expensifyClassic);
193192
const newExpensifyRoute = routes.platforms.find((platform) => platform.href === platformNames.newExpensify);
194193
const travelRoute = routes.platforms.find((platform) => platform.href === platformNames.travel);
195-
const consolidatedRoute = routes.platforms.find(
196-
(platform) => platform.href === platformNames.consolidated
197-
);
194+
const consolidatedRoute = routes.platforms.find((platform) => platform.href === platformNames.consolidated);
198195

199196
if (!consolidatedRoute) {
200-
console.error('Consolidated platform missing from _routes.yml');
201-
process.exit(1);
202-
}
197+
console.error('Consolidated platform missing from _routes.yml');
198+
process.exit(1);
199+
}
203200
if (expensifyClassicArticleHubs.length !== expensifyClassicRoute?.hubs.length) {
204201
console.error(warnMessage(platformNames.expensifyClassic));
205202
process.exit(1);
@@ -218,7 +215,7 @@ function run() {
218215
if (consolidatedArticleHubs.length !== consolidatedRoute?.hubs.length) {
219216
console.error(warnMessage(platformNames.consolidated));
220217
process.exit(1);
221-
}
218+
}
222219

223220
createHubsWithArticles(expensifyClassicArticleHubs, platformNames.expensifyClassic, expensifyClassicRoute.hubs);
224221
createHubsWithArticles(newExpensifyArticleHubs, platformNames.newExpensify, newExpensifyRoute.hubs);

cspell.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
"Bushwick",
110110
"BYOC",
111111
"cacerts",
112+
"cancelation",
112113
"canvaskit",
113114
"capitalone",
114115
"cardreader",
@@ -280,6 +281,7 @@
280281
"Français",
281282
"Frederico",
282283
"freetext",
284+
"frontmatter",
283285
"frontpart",
284286
"fullstory",
285287
"FWTV",
@@ -604,6 +606,7 @@
604606
"rebooking",
605607
"recategorize",
606608
"recents",
609+
"recordkeeping",
607610
"REDIRECTURI",
608611
"regexpu",
609612
"reimagination",

scripts/add-platform-frontmatter.js

Lines changed: 0 additions & 62 deletions
This file was deleted.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env ts-node
2+
/**
3+
* Adds `platform` frontmatter to test articles only.
4+
* Test articles live under docs/articles/consolidated/billing (source for docs/consolidated/hubs/billing).
5+
* Only Specific (single-platform) articles get platform; Universal and Semi-Universal stay without platform.
6+
*/
7+
import fs from 'fs';
8+
import path from 'path';
9+
10+
const ARTICLES_DIR = path.join(__dirname, '..', 'docs', 'articles');
11+
12+
// Specific articles that apply to one platform only (add platform)
13+
const CONSOLIDATED_CLASSIC = [
14+
'billing/other-billing-scenarios/Personal-and-Corporate-Karma.md',
15+
'billing/other-billing-scenarios/Tax-Exempt.md',
16+
'billing/subscription-management/How-to-Manage-Billing-and-Subscriptions-in-Expensify-Classic.md',
17+
'billing/subscription-setup-and-billing-ownership/How-to-configure-your-subscription-in-Expensify-Classic.md',
18+
'billing/plans-and-pricing/Expensify-Classic-Plans-Track-Submit-and-Legacy-Pricing.md',
19+
];
20+
const CONSOLIDATED_NEW = [
21+
'billing/subscription-management/How-to-Manage-Subscriptions-and-Billing-in-New-Expensify.md',
22+
'billing/subscription-setup-and-billing-ownership/How-to-configure-your-subscription-in-New-Expensify.md',
23+
];
24+
25+
function addPlatformToFrontmatter(content: string, platformValue: string): string | null {
26+
if (content.includes('platform:') && /^\s*platform:\s*\S+/m.test(content)) {
27+
return null; // already has platform
28+
}
29+
const firstFence = content.indexOf('---');
30+
if (firstFence === -1) return null;
31+
const afterFirstFence = content.slice(firstFence);
32+
if (!afterFirstFence.startsWith('---\n')) return null;
33+
const secondFence = afterFirstFence.indexOf('\n---\n', 4);
34+
if (secondFence === -1) return null;
35+
const closeFenceStart = firstFence + secondFence;
36+
const before = content.slice(0, closeFenceStart);
37+
const after = content.slice(closeFenceStart);
38+
const platformBlock = `\nplatform: ${platformValue}\n---\n`;
39+
return before + platformBlock + after.slice(5);
40+
}
41+
42+
function processFile(filePath: string, platformValue: string) {
43+
const fullPath = path.join(ARTICLES_DIR, filePath);
44+
if (!fs.existsSync(fullPath)) return;
45+
const content = fs.readFileSync(fullPath, 'utf8');
46+
const newContent = addPlatformToFrontmatter(content, platformValue);
47+
if (newContent) {
48+
fs.writeFileSync(fullPath, newContent);
49+
console.log('Updated:', filePath);
50+
}
51+
}
52+
53+
// Only consolidated/billing test articles
54+
for (const rel of CONSOLIDATED_CLASSIC) {
55+
processFile(path.join('consolidated', rel), 'Expensify_Classic');
56+
}
57+
for (const rel of CONSOLIDATED_NEW) {
58+
processFile(path.join('consolidated', rel), 'New_Expensify');
59+
}
60+
61+
console.log('Done.');

scripts/remove-platform-frontmatter.js

Lines changed: 0 additions & 42 deletions
This file was deleted.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env ts-node
2+
/**
3+
* Removes platform frontmatter from all .md files under the given directories.
4+
* Use to revert platform from expensify-classic and new-expensify.
5+
*/
6+
import {execSync} from 'child_process';
7+
import fs from 'fs';
8+
import path from 'path';
9+
10+
const ARTICLES_DIR = path.join(__dirname, '..', 'docs', 'articles');
11+
const DIRS_TO_REVERT = ['expensify-classic', 'new-expensify'];
12+
13+
function removePlatform(filePath: string): boolean {
14+
const full = path.join(ARTICLES_DIR, filePath);
15+
if (!fs.existsSync(full)) return false;
16+
let content = fs.readFileSync(full, 'utf8');
17+
const orig = content;
18+
// Remove a line that is exactly "platform: Expensify_Classic" or "platform: New_Expensify" (with optional trailing whitespace)
19+
content = content.replace(/\nplatform: (?:Expensify_Classic|New_Expensify)\s*\n/g, '\n');
20+
if (content !== orig) {
21+
fs.writeFileSync(full, content);
22+
return true;
23+
}
24+
return false;
25+
}
26+
27+
let count = 0;
28+
for (const dir of DIRS_TO_REVERT) {
29+
const fullDir = path.join(ARTICLES_DIR, dir);
30+
if (!fs.existsSync(fullDir)) continue;
31+
const out = execSync(`find . -name "*.md"`, {encoding: 'utf8', cwd: fullDir});
32+
const files = out.trim().split('\n').filter(Boolean);
33+
for (const f of files) {
34+
const rel = path.join(dir, f);
35+
if (removePlatform(rel)) {
36+
console.log('Reverted:', rel);
37+
count++;
38+
}
39+
}
40+
}
41+
console.log('Reverted platform from', count, 'files.');

0 commit comments

Comments
 (0)