Skip to content

Commit 48b04bd

Browse files
committed
convert translation scripts to straight node
1 parent d38a5e3 commit 48b04bd

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
},
1515
"scripts": {
1616
"lint": "prettier --write \"src/**/*.js\"",
17-
"make:combined-translation-keys": "babel-node scripts/findTranslationKeys.js && babel-node scripts/combineTranslationKeys.js",
18-
"make:translation-keys": "babel-node scripts/findTranslationKeys.js",
19-
"make:arrows": "babel-node scripts/makeArrows.js",
17+
"make:combined-translation-keys": "npm run make:translation-keys && node scripts/combineTranslationKeys.js",
18+
"make:translation-keys": "node scripts/findTranslationKeys.js",
19+
"make:arrows": "node scripts/makeArrows.js",
2020
"make:lib": "mkdirp lib && npm run make:lib:js && npm run make:lib:css && npm run make:combined-translation-keys",
2121
"make:lib:js": "mkdirp lib && babel src --out-dir lib --ignore=__tests__/* --source-maps",
2222
"make:lib:css": "mkdirp lib && babel-node scripts/styles.js && SASS_ENV=ie babel-node scripts/styles.js && babel-node scripts/postcss.js && SASS_ENV=ie babel-node scripts/postcss.js",

scripts/combineTranslationKeys.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import path from 'path';
2-
import fs from 'fs';
1+
const path = require('path');
2+
const fs = require('fs');
33

44
// generalize so we can use this script in other es6 repos
55
// so you can call:
@@ -36,7 +36,7 @@ function combineTranslationKeys() {
3636
const dict = {};
3737
let maxLen = 0;
3838

39-
inputPaths.forEach(inputPath => {
39+
inputPaths.map(relPath => path.resolve(relPath)).forEach(inputPath => {
4040
const lines = fs.readFileSync(inputPath, 'utf-8').split(/\r?\n/);
4141

4242
const repository = getRepository(inputPath);
@@ -60,12 +60,12 @@ function combineTranslationKeys() {
6060
.map(k => k + spaces(maxLen - k.length) + dict[k])
6161
.join('\n');
6262

63-
fs.writeFile(outputPath, strings);
63+
fs.writeFileSync(outputPath, strings);
6464
console.log(`combined translation keys were written to: ${outputPath}`);
6565
}
6666

6767
function getRepository(inputPath) {
68-
var dir = path.dirname(inputPath);
68+
const dir = path.dirname(inputPath);
6969
if (fs.existsSync(path.join(dir, 'package.json'))) {
7070
return path.basename(dir);
7171
}

scripts/findTranslationKeys.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import {transform} from 'babel-core';
2-
import traverse from 'babel-traverse';
3-
import fs from 'fs';
4-
import glob from 'glob';
5-
import path from 'path';
1+
const transform = require('babel-core').transform;
2+
const traverse = require('babel-traverse').default;
3+
const fs = require('fs');
4+
const glob = require('glob');
5+
const path = require('path');
66

77
// generalize so we can use this script in other es6 repos
88
// so you can call:
@@ -90,7 +90,7 @@ function findLocaleStrings() {
9090
.map(k => k + spaces(maxLen - k.length) + ' // ' + dict[k])
9191
.join('\n');
9292

93-
fs.writeFile(pathToTranslationKeys, strings);
93+
fs.writeFileSync(pathToTranslationKeys, strings);
9494
console.log(`translation keys were written to: ${pathToTranslationKeys}`);
9595
});
9696
}

scripts/makeArrows.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import path from 'path';
2-
import fs from 'fs';
1+
const path = require('path');
2+
const fs = require('fs');
33

44
// generalize so we can use this script in other repos
55
// so you can call:
@@ -16,6 +16,7 @@ const pathToArrowsOut = process.argv[3] || path.join(
1616
);
1717

1818
const wordRE = /^[A-Za-z]+$/;
19+
const maxLineLen = 80;
1920

2021
function makeArrows() {
2122
const lines = fs
@@ -38,7 +39,9 @@ function makeArrows() {
3839
const quotedVal = quoteChar + arrowStr + key + arrowStr + quoteChar + ',';
3940
const singleLine = ' ' + maybeQuoteKey + ': ' + quotedVal;
4041

41-
if (singleLine.length <= 80) return singleLine;
42+
if (singleLine.length <= maxLineLen) {
43+
return singleLine;
44+
}
4245

4346
return ' ' + maybeQuoteKey + ':\n ' + quotedVal;
4447
})
@@ -47,13 +50,14 @@ function makeArrows() {
4750
const head = 'export default {';
4851
const tail = '};\n';
4952

50-
fs.writeFile(pathToArrowsOut, [head, entries, tail].join('\n'));
53+
fs.writeFileSync(pathToArrowsOut, [head, entries, tail].join('\n'));
5154
console.log('arrows mock translation written to: ' + pathToArrowsOut);
5255
}
5356

5457
// inferred from the arrow file Greg provided
58+
const arrowFactor = 5.7;
5559
function getArrowLen(key) {
56-
return Math.max(1, Math.round(key.length / 5.7));
60+
return Math.max(1, Math.round(key.length / arrowFactor));
5761
}
5862

5963
function arrowPad(n) {

0 commit comments

Comments
 (0)