Skip to content

Commit 3e0073c

Browse files
author
Brian Vaughn
committed
Tidied up reqiure statements for Crowdin scripts
1 parent 2cf08de commit 3e0073c

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

crowdin/download.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
const Crowdin = require('crowdin-node');
22
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');
55
const {symlink, lstatSync, readdirSync} = require('fs');
66

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__');
99

1010
// Path to the "docs" folder within the downloaded Crowdin translations bundle.
11-
const downloadedDocsPath = path.resolve(
11+
const downloadedDocsPath = resolve(
1212
EXPORTED_PATH,
1313
downloadedRootDirectory,
1414
);
@@ -56,16 +56,16 @@ const downloadAndSymlink = () => {
5656

5757
usableLocales.forEach(locale => {
5858
const languageCode = localeToFolderMap.get(locale);
59-
const rootLanguageFolder = path.resolve(TRANSLATED_PATH, languageCode);
59+
const rootLanguageFolder = resolve(TRANSLATED_PATH, languageCode);
6060

6161
if (Array.isArray(whitelist)) {
62-
if (!fs.existsSync(rootLanguageFolder)) {
63-
fs.mkdirSync(rootLanguageFolder);
62+
if (!existsSync(rootLanguageFolder)) {
63+
mkdirSync(rootLanguageFolder);
6464
}
6565

6666
// Symlink only the whitelisted subdirectories
6767
whitelist.forEach(subdirectory => {
68-
createSymLink(path.join(languageCode, subdirectory));
68+
createSymLink(join(languageCode, subdirectory));
6969
});
7070
} else {
7171
// Otherwise symlink the entire language export
@@ -80,8 +80,8 @@ const downloadAndSymlink = () => {
8080
// Note that the current working directory of this node process should be where the symlink is created
8181
// or else the relative paths would be incorrect
8282
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);
8585
symlink(from, to, err => {
8686
if (!err) {
8787
return;
@@ -133,7 +133,7 @@ const createLocaleToFolderMap = (directories) => {
133133
const getLanguageDirectories = source =>
134134
readdirSync(source).filter(
135135
name =>
136-
lstatSync(path.join(source, name)).isDirectory() && name !== '_data',
136+
lstatSync(join(source, name)).isDirectory() && name !== '_data',
137137
);
138138

139139
validateCrowdinConfig();

crowdin/update-languages.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
const fs = require('fs');
2-
const path = require('path');
1+
const {readdirSync, statSync, writeFileSync} = require('fs');
2+
const {join, resolve} = require('path');
33

4-
const TRANSLATED_LANGUAGES_JSON_PATH = path.resolve(__dirname, 'languages.json');
5-
const TRANSLATED_PATH = path.resolve(__dirname, '__translated__');
4+
const TRANSLATED_LANGUAGES_JSON_PATH = resolve(__dirname, 'languages.json');
5+
const TRANSLATED_PATH = resolve(__dirname, '__translated__');
66

77
// Determine which languages we have translations downloaded for...
88
const languages = [];
9-
fs.readdirSync(TRANSLATED_PATH).forEach(entry => {
10-
if (fs.statSync(path.join(TRANSLATED_PATH, entry)).isDirectory()) {
9+
readdirSync(TRANSLATED_PATH).forEach(entry => {
10+
if (statSync(join(TRANSLATED_PATH, entry)).isDirectory()) {
1111
languages.push(entry);
1212
}
1313
});
1414

1515
// Update the languages JSON config file.
1616
// This file is used to display the localization toggle UI.
17-
fs.writeFileSync(
17+
writeFileSync(
1818
TRANSLATED_LANGUAGES_JSON_PATH,
1919
JSON.stringify(languages),
2020
);

0 commit comments

Comments
 (0)