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