Skip to content

Commit e7f9144

Browse files
committed
Try to fix build to work on Windows and Mac
1 parent 6e388c6 commit e7f9144

File tree

5 files changed

+235
-8
lines changed

5 files changed

+235
-8
lines changed

package-lock.json

Lines changed: 115 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
"scripts": {
99
"prebuild": "npm run generate-markdown && npm run i18n:sync && npm run crowdin:conditional",
10-
"build": "npm run build:${VERCEL_ENV:-preview}",
10+
"build": "node scripts/build.mjs",
1111
"build:preview": "docusaurus build --locale en",
1212
"build:production": "docusaurus build",
1313
"clear": "docusaurus clear",
@@ -16,7 +16,7 @@
1616
"deploy": "docusaurus deploy",
1717
"docusaurus": "docusaurus",
1818
"generate-markdown": "node scripts/native.mjs && concurrently \"node scripts/cli.mjs\" \"node scripts/release-notes.mjs\"",
19-
"i18n:sync": "node -e \"require('./scripts/utils.mjs').syncI18n()\"",
19+
"i18n:sync": "node scripts/i18n.mjs",
2020
"lint": "npm run prettier -- --write",
2121
"serve": "docusaurus serve",
2222
"playground:new": "hygen playground new",
@@ -63,6 +63,7 @@
6363
"remark-parse": "^11.0.0",
6464
"sass": "^1.44.0",
6565
"semver": "^7.3.5",
66+
"tar": "^6.1.11",
6667
"unified": "^11.0.0"
6768
},
6869
"devDependencies": {

scripts/build.mjs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { spawn } from 'child_process';
2+
3+
const vercelEnv = process.env.VERCEL_ENV || 'preview';
4+
const buildCommand = `build:${vercelEnv}`;
5+
6+
console.log(`Running build command: npm run ${buildCommand}`);
7+
8+
const child = spawn('npm', ['run', buildCommand], {
9+
stdio: 'inherit',
10+
shell: true
11+
});
12+
13+
child.on('close', (code) => {
14+
process.exit(code);
15+
});
16+
17+
child.on('error', (error) => {
18+
console.error('Build script error:', error);
19+
process.exit(1);
20+
});

scripts/i18n.bat

Lines changed: 0 additions & 6 deletions
This file was deleted.

scripts/i18n.mjs

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import { mkdir, rm } from 'fs/promises';
2+
import { createWriteStream } from 'fs';
3+
import { pipeline } from 'stream/promises';
4+
import { spawn } from 'child_process';
5+
import { promisify } from 'util';
6+
import { dirname, join } from 'path';
7+
import { fileURLToPath } from 'url';
8+
import { createGunzip } from 'zlib';
9+
import tar from 'tar';
10+
11+
const __filename = fileURLToPath(import.meta.url);
12+
const __dirname = dirname(__filename);
13+
14+
const TARGET_DIR = 'i18n/ja/docusaurus-plugin-content-docs/current';
15+
const TEMP_FILE = 'temp_jp.tar.gz';
16+
const DOWNLOAD_URL = 'https://github.com/ionic-team/ionic-docs/archive/refs/heads/translation/jp.tar.gz';
17+
18+
async function downloadFile(url, destination) {
19+
console.log('Downloading Japanese translation files...');
20+
21+
const response = await fetch(url);
22+
if (!response.ok) {
23+
throw new Error(`Failed to download: ${response.status} ${response.statusText}`);
24+
}
25+
26+
const fileStream = createWriteStream(destination);
27+
await pipeline(response.body, fileStream);
28+
}
29+
30+
async function extractTarGz(source, targetDir) {
31+
console.log('Extracting translation files...');
32+
33+
await tar.extract({
34+
file: source,
35+
cwd: targetDir,
36+
strip: 2,
37+
filter: (path) => path.startsWith('ionic-docs-translation-jp/docs/')
38+
});
39+
}
40+
41+
async function runCommand(command, args = []) {
42+
return new Promise((resolve, reject) => {
43+
const child = spawn(command, args, {
44+
stdio: 'inherit',
45+
shell: true
46+
});
47+
48+
child.on('close', (code) => {
49+
if (code === 0) {
50+
resolve();
51+
} else {
52+
reject(new Error(`Command failed with exit code ${code}`));
53+
}
54+
});
55+
56+
child.on('error', reject);
57+
});
58+
}
59+
60+
async function cleanup() {
61+
try {
62+
await rm(TEMP_FILE, { force: true });
63+
} catch (error) {
64+
// Ignore cleanup errors
65+
}
66+
}
67+
68+
async function main() {
69+
try {
70+
console.log('Running i18n synchronization...');
71+
72+
// Create target directory
73+
await mkdir(TARGET_DIR, { recursive: true });
74+
75+
// Download translation files
76+
await downloadFile(DOWNLOAD_URL, TEMP_FILE);
77+
78+
// Extract files
79+
await extractTarGz(TEMP_FILE, TARGET_DIR);
80+
81+
// Clean up temporary file
82+
await cleanup();
83+
84+
// Run API generation script
85+
console.log('Generating Japanese API documentation...');
86+
await runCommand('node', ['scripts/api-ja.js']);
87+
88+
console.log('✅ i18n sync completed successfully');
89+
90+
} catch (error) {
91+
console.error('❌ Error during i18n sync:', error.message);
92+
await cleanup();
93+
process.exit(1);
94+
}
95+
}
96+
97+
main();

0 commit comments

Comments
 (0)