1
1
const Crowdin = require ( 'crowdin-node' ) ;
2
2
const { downloadedRootDirectory, key, threshold, url, whitelist} = require ( './config' ) ;
3
- const fs = require ( 'fs' ) ;
4
- const path = require ( 'path' ) ;
3
+ const { existsSync , mkdirSync } = require ( 'fs' ) ;
4
+ const { join , resolve } = require ( 'path' ) ;
5
5
const { symlink, lstatSync, readdirSync} = require ( 'fs' ) ;
6
6
7
- const TRANSLATED_PATH = path . resolve ( __dirname , '__translated__' ) ;
8
- const EXPORTED_PATH = path . resolve ( __dirname , '__exported__' ) ;
7
+ const TRANSLATED_PATH = resolve ( __dirname , '__translated__' ) ;
8
+ const EXPORTED_PATH = resolve ( __dirname , '__exported__' ) ;
9
9
10
10
// Path to the "docs" folder within the downloaded Crowdin translations bundle.
11
- const downloadedDocsPath = path . resolve (
11
+ const downloadedDocsPath = resolve (
12
12
EXPORTED_PATH ,
13
13
downloadedRootDirectory ,
14
14
) ;
@@ -56,16 +56,16 @@ const downloadAndSymlink = () => {
56
56
57
57
usableLocales . forEach ( locale => {
58
58
const languageCode = localeToFolderMap . get ( locale ) ;
59
- const rootLanguageFolder = path . resolve ( TRANSLATED_PATH , languageCode ) ;
59
+ const rootLanguageFolder = resolve ( TRANSLATED_PATH , languageCode ) ;
60
60
61
61
if ( Array . isArray ( whitelist ) ) {
62
- if ( ! fs . existsSync ( rootLanguageFolder ) ) {
63
- fs . mkdirSync ( rootLanguageFolder ) ;
62
+ if ( ! existsSync ( rootLanguageFolder ) ) {
63
+ mkdirSync ( rootLanguageFolder ) ;
64
64
}
65
65
66
66
// Symlink only the whitelisted subdirectories
67
67
whitelist . forEach ( subdirectory => {
68
- createSymLink ( path . join ( languageCode , subdirectory ) ) ;
68
+ createSymLink ( join ( languageCode , subdirectory ) ) ;
69
69
} ) ;
70
70
} else {
71
71
// Otherwise symlink the entire language export
@@ -80,8 +80,8 @@ const downloadAndSymlink = () => {
80
80
// Note that the current working directory of this node process should be where the symlink is created
81
81
// or else the relative paths would be incorrect
82
82
const createSymLink = ( relativePath ) => {
83
- const from = path . resolve ( downloadedDocsPath , relativePath ) ;
84
- const to = path . resolve ( TRANSLATED_PATH , relativePath ) ;
83
+ const from = resolve ( downloadedDocsPath , relativePath ) ;
84
+ const to = resolve ( TRANSLATED_PATH , relativePath ) ;
85
85
symlink ( from , to , err => {
86
86
if ( ! err ) {
87
87
return ;
@@ -133,7 +133,7 @@ const createLocaleToFolderMap = (directories) => {
133
133
const getLanguageDirectories = source =>
134
134
readdirSync ( source ) . filter (
135
135
name =>
136
- lstatSync ( path . join ( source , name ) ) . isDirectory ( ) && name !== '_data' ,
136
+ lstatSync ( join ( source , name ) ) . isDirectory ( ) && name !== '_data' ,
137
137
) ;
138
138
139
139
validateCrowdinConfig ( ) ;
0 commit comments