Skip to content

Commit

Permalink
chore: handle TS for building dictionaries
Browse files Browse the repository at this point in the history
  • Loading branch information
ijemmao committed Jun 21, 2023
1 parent f12bf2f commit ec62220
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = {
'function-call-argument-newline': ['off'],
'function-paren-newline': ['off'],
'import/prefer-default-export': ['off'],
'import/extensions': ['warn'],
'import/extensions': ['off'],
'newline-per-chained-call': ['off'],
'no-console': ['off'],
'no-nested-ternary': ['off'],
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"build": "rm -rf dist/ && yarn build:site && yarn build:src && cross-env NODE_ENV=build yarn build:dictionaries && yarn build:functions",
"build:functions": "rm -rf functions/src && shx cp -r ./dist ./functions/src && cp -r ./dist/dictionaries/ig-en ./functions/src/dictionaries",
"build:src": "babel -d dist/ ./src -s --extensions '.js,.jsx,.ts,.tsx'",
"build:dictionaries": "babel-node src/dictionaries/buildDictionaries.js",
"prebuild:dictionaries": "shx cp -r ./src/dictionaries/ig-en ./dist/dictionaries/ig-en && shx cp -r ./src/dictionaries/en-ig ./dist/dictionaries/en-ig",
"build:dictionaries": "node dist/dictionaries/buildDictionaries.js",
"build:site": "cross-env NEXT_PUBLIC_GA_ID=$GA_TRACKING_ID next build && yarn build:fonts && yarn build:assets",
"build:fonts": "shx cp -r ./src/public/fonts/ ./dist/fonts",
"build:assets": "shx cp -r ./src/pages/assets/ ./dist/assets",
Expand Down
21 changes: 10 additions & 11 deletions src/dictionaries/buildDictionaries.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import fs from 'fs';
import shell from 'shelljs';
import flatten from 'lodash/flatten';
import {
DICTIONARIES_DIR,
BUILD_DICTIONARIES_DIR,
} from '../shared/constants/parseFileLocations';
import { DICTIONARIES_DIR, BUILD_DICTIONARIES_DIR } from '../shared/constants/parseFileLocations';
import commonDictionary from './ig-en/ig-en_1000_common.json';
import normalizedDictionary from './ig-en/ig-en_normalized_expanded.json';
import dictionary from './ig-en/ig-en_expanded.json';
Expand All @@ -25,13 +22,15 @@ const updateJSONDictionary = () => {
[`${DICTIONARIES_DIR}/ig-en.json`, JSON.stringify(dictionary)],
];

const buildDictionaryFilePaths = process.env.NODE_ENV === 'build'
? [
[`${BUILD_DICTIONARIES_DIR}/ig-en_1000_common.json`, JSON.stringify(commonDictionary, null, 4)],
[`${BUILD_DICTIONARIES_DIR}/ig-en_expanded.json`, JSON.stringify(dictionary, null, 4)],
[`${BUILD_DICTIONARIES_DIR}/ig-en_normalized_expanded.json`, JSON.stringify(normalizedDictionary, null, 4)],
[`${BUILD_DICTIONARIES_DIR}/ig-en.json`, JSON.stringify(dictionary)],
] : [];
const buildDictionaryFilePaths =
process.env.NODE_ENV === 'build'
? [
[`${BUILD_DICTIONARIES_DIR}/ig-en_1000_common.json`, JSON.stringify(commonDictionary, null, 4)],
[`${BUILD_DICTIONARIES_DIR}/ig-en_expanded.json`, JSON.stringify(dictionary, null, 4)],
[`${BUILD_DICTIONARIES_DIR}/ig-en_normalized_expanded.json`, JSON.stringify(normalizedDictionary, null, 4)],
[`${BUILD_DICTIONARIES_DIR}/ig-en.json`, JSON.stringify(dictionary)],
]
: [];

flatten([dictionaryFilePaths, buildDictionaryFilePaths]).forEach((config) => {
fs.writeFileSync(...config, () => {
Expand Down

0 comments on commit ec62220

Please sign in to comment.