Commit e95d6af7 authored by Matija Obreza's avatar Matija Obreza
Browse files

Setup: Proper lerna modules and build artifacts

parent f4b23e4f
......@@ -7,3 +7,5 @@ node_modules/
*.iml
react-loadable.json
*.snap
packages/client/lib
packages/i18n/lib
......@@ -8,6 +8,13 @@ technicians, curators and managers to interact with the
## Development environment setup
`node >=10.4.1` and `yarn >=1.21.1` are required. See below for installation
instructions.
Run `yarn install` in the project root directory.
### node and yarn
Install `node 10.4.1` or higher:
```bash
......@@ -23,5 +30,4 @@ sudo apt update
sudo apt install yarn
```
Run `yarn run installAndLink` in the project root directory.
......@@ -9,15 +9,16 @@
"url": "https://gitlab.croptrust.org/grin-global/grin-global-ui"
},
"scripts": {
"installAndLink": "yarn install && lerna bootstrap",
"clean": "lerna run clean"
"clean": "lerna run clean",
"postinstall": "lerna bootstrap && lerna run setup && lerna link",
"build": "lerna run build"
},
"workspaces": [
"packages/i18n",
"packages/client"
],
"devDependencies": {
"lerna": "^3.20.2"
"lerna": "^3.0.0"
},
"engines": {
"node": ">=10.4.1",
......
......@@ -3,11 +3,13 @@
"version": "0.0.1",
"license": "Apache-2.0",
"scripts": {
"clean": "rimraf target",
"i18nGenerate": "cross-env moduleName=client lerna run i18n:generateI18n --stream",
"clean": "rimraf lib",
"build": "gg-i18n && tsc",
"i18nGenerate": "gg-i18n",
"test": "jest"
},
"dependencies": {
"@gringlobal/i18n": "*",
"axios": "^0.19.2",
"connected-react-router": "^6.6.1",
"cross-env": "^7.0.0",
......@@ -21,6 +23,7 @@
"i18next-xhr-backend": "^3.2.2",
"immutability-helper": "^3.0.1",
"js-md5": "^0.7.3",
"jsonwebtoken": "^8.5.1",
"path": "^0.12.7",
"prop-types": "^15.7.2",
"react": "^16.12.0",
......@@ -37,14 +40,15 @@
"url-template": "^2.0.8"
},
"devDependencies": {
"@gringlobal/i18n": "*",
"@babel/cli": "^7.8.4",
"@babel/core": "^7.8.4",
"@types/enzyme": "^3.10.5",
"@types/jest": "^25.1.2",
"@types/node": "13.5.3",
"@types/react": "16.9.19",
"@types/react-router": "5.1.4",
"@types/react-router-dom": "5.1.3",
"@types/react": "^16.9.0",
"@types/react-router": "^5.1.0",
"@types/react-router-dom": "^5.1.0",
"@types/redux-form": "8.2.0",
"@types/webpack-env": "^1.15.1",
"@typescript-eslint/eslint-plugin": "^2.17.0",
......
......@@ -14,15 +14,16 @@
"node_modules"
]
},
"outDir": "target/web",
"outDir": "./lib",
"module": "esnext",
"target": "esnext",
"jsx": "react",
"moduleResolution": "node"
},
"exclude": [
"test",
"node_modules",
"build",
"lib",
"typings/main",
"typings/main.d.ts"
],
......
......@@ -3,10 +3,13 @@
"version": "0.0.1",
"license": "Apache-2.0",
"scripts": {
"precompile": "yarn run i18n:generateI18n",
"i18n:generateI18n": "node tools/generateI18n.ts",
"i18n:scanI18nDuplicates": "ts-node tools/duplicateDetector.ts",
"i18n:i18nscan": "i18next-scanner --config i18next-scanner.config.js '../**/src/**/*.tsx'"
"setup": "yarn run build",
"clean": "rimraf lib",
"build": "tsc && lerna link"
},
"bin": {
"gg-i18n": "lib/tools/generateI18n.js",
"gg-i18n-dd": "lib/tools/duplicateDetector.js"
},
"dependencies": {
"axios": "^0.19.2",
......@@ -21,9 +24,9 @@
"@babel/core": "^7.8.4",
"@types/enzyme": "^3.10.5",
"@types/jest": "^25.1.2",
"@types/react": "16.9.19",
"@types/react-router": "5.1.4",
"@types/react-router-dom": "5.1.3",
"@types/react": "^16.9.0",
"@types/react-router": "^5.1.0",
"@types/react-router-dom": "^5.1.0",
"@types/redux-form": "8.2.0",
"@types/webpack-env": "^1.15.1",
"@typescript-eslint/eslint-plugin": "^2.17.0",
......
import languages from '@gringlobal/i18n/data/Languages';
import languages from 'data/Languages';
export default function detectLocaleFromPath(virtualPath: string, path: string, index: number) {
if (virtualPath && path.startsWith(virtualPath)) {
......
......@@ -2,9 +2,9 @@
import i18n from 'i18next';
import axios from 'axios';
// eslint-disable-next-line no-restricted-imports
import optionsBase from '@gringlobal/i18n/options-base';
import optionsBase from 'options-base';
// eslint-disable-next-line no-restricted-imports
import langDetector from '@gringlobal/i18n/langDetector';
import langDetector from 'langDetector';
import XHR from 'i18next-xhr-backend';
import LanguageDetector from 'i18next-browser-languagedetector';
......
// @ts-ignore
import i18n from 'i18next';
import * as path from 'path';
import optionsBase from '@gringlobal/i18n/options-base';
import optionsBase from 'options-base';
import Backend from 'i18next-sync-fs-backend';
import { initReactI18next } from 'react-i18next';
......
import detectLocaleFromPath from '@gringlobal/i18n/detectLocaleFromPath';
import detectLocaleFromPath from 'detectLocaleFromPath';
export default {
name: 'pathStartLangDetector',
......
#!/usr/bin/env node
const fastGlob = require('fast-glob');
const fileStream = require('fs');
const path = require('path');
......
#!/usr/bin/env node
const fg = require('fast-glob');
const _ = require('lodash');
const fs = require('fs');
......@@ -5,13 +7,21 @@ const md5 = require('js-md5');
const mkdirp = require('mkdirp');
const rimraf = require('rimraf');
// console.log('Env', process.env);
// console.log('Args' , process.argv);
// console.log('CWD', process.cwd());
// console.log('env.INIT_CWD', rootDir);
const rootDir = process.cwd();
console.log(`Scanning ${rootDir}`);
const getPrefix = (path) => {
console.log(`Converting ${path}`);
return path.substring(path.indexOf('/src/') + '/src/'.length, path.indexOf('/translations.json'));
};
// TODO fix generated paths
fg([`${process.env.INIT_CWD}/src/**/translations.json`, `${process.env.INIT_CWD}/rc/translations.json`])
fg([`${rootDir}/src/**/translations.json`, `${rootDir}/rc/translations.json`])
.then((entries) => {
console.log(`Inspecting ${entries}`);
return entries.filter((e) => ! /\/node_modules\//.test(e));
......@@ -25,13 +35,13 @@ fg([`${process.env.INIT_CWD}/src/**/translations.json`, `${process.env.INIT_CWD}
return result;
})
.then((content) => {
if (!fs.existsSync(`${process.env.INIT_CWD}/locales/en`)) {
mkdirp.sync(`${process.env.INIT_CWD}/locales/en`); // create dir if no exist
if (!fs.existsSync(`${rootDir}/locales/en`)) {
mkdirp.sync(`${rootDir}/locales/en`); // create dir if no exist
}
fs.writeFileSync(`${process.env.INIT_CWD}/locales/en/${process.env.moduleName || 'translations'}.json`, JSON.stringify(content, null, 2))
fs.writeFileSync(`${rootDir}/locales/en/${process.env.moduleName || 'translations'}.json`, JSON.stringify(content, null, 2))
})
.then(() => {
const content = fs.readFileSync(`${process.env.INIT_CWD}/locales/en/${process.env.moduleName || 'translations'}.json`);
const content = fs.readFileSync(`${rootDir}/locales/en/${process.env.moduleName || 'translations'}.json`);
JSON.parse(content);
}).catch((error) => {
console.log(`Error reading resulting locales/en/${process.env.moduleName || 'translations'}.json`, error);
......@@ -44,22 +54,22 @@ const generateHashedLocales = () => {
? process.env.includedLocales.replace(/[\[\]]/gi, '').split(',')
: [];
rimraf(`${process.env.INIT_CWD}/generated/locales`, (err) => { // delete old generated locales
fg([`${process.env.INIT_CWD}/locales/**/${process.env.moduleName || 'translations'}.json`, ...includedLocales]) // scan for all translations files
rimraf(`${rootDir}/generated/locales`, (err) => { // delete old generated locales
fg([`${rootDir}/locales/**/${process.env.moduleName || 'translations'}.json`, ...includedLocales]) // scan for all translations files
.then((entries) => {
const localeHashMapping = {}; // map commonPath -> pathWithHash
mkdirp(`${process.env.INIT_CWD}/generated/locales`, () => {
mkdirp(`${rootDir}/generated/locales`, () => {
entries.forEach((path) => {
const fileContent = fs.readFileSync(path); // reading content for generating hash
const contentHash = md5(fileContent);
const newFilePath = path.substring(path.indexOf('/locales')).replace('locales', 'generated/locales').replace('.json', `-${ contentHash }.json`); // adding hash before .json
const generatedLocaleDirPath = newFilePath.substring(0, newFilePath.lastIndexOf('/')); // getting all but the filename as folder of locale lang
mkdirp.sync(`${process.env.INIT_CWD}/${generatedLocaleDirPath}`); // create dir if no exist
fs.writeFileSync(`${process.env.INIT_CWD}/${newFilePath}`, fileContent, { flag: 'wx' });
mkdirp.sync(`${rootDir}/${generatedLocaleDirPath}`); // create dir if no exist
fs.writeFileSync(`${rootDir}/${newFilePath}`, fileContent, { flag: 'wx' });
localeHashMapping[path.substring(1)] = newFilePath.replace('./generated', ''); // deleting '/generated' from new path for further loading
// console.log(`Generated ${ newFilePath } for ${ path }`);
});
fs.writeFileSync(`${process.env.INIT_CWD}/generated/locales/localesMapping.json`, JSON.stringify(localeHashMapping), { encoding: 'utf8' }); // after all locales moved creating file with mappings
fs.writeFileSync(`${rootDir}/generated/locales/localesMapping.json`, JSON.stringify(localeHashMapping), { encoding: 'utf8' }); // after all locales moved creating file with mappings
});
});
});
......
......@@ -4,7 +4,6 @@
"baseUrl": ".",
"paths": {
"*": [
"*",
"src/*",
"server/*",
"node_modules/*"
......@@ -12,11 +11,8 @@
"@gringlobal/client/*": [
"../client/src/*"
],
"@gringlobal/i18n/*": [
"../i18n/src/*"
]
},
"outDir": "../../target",
"outDir": "./lib",
"module": "esnext",
"target": "esnext",
"sourceMap": false,
......@@ -34,7 +30,8 @@
},
"exclude": [
"node_modules",
"build",
"tools",
"lib",
"typings/main",
"typings/main.d.ts"
]
......
......@@ -1425,7 +1425,7 @@
resolved "https://registry.yarnpkg.com/@types/q/-/q-1.5.2.tgz#690a1475b84f2a884fd07cd797c00f5f31356ea8"
integrity sha512-ce5d3q03Ex0sy4R14722Rmt6MT07Ua+k4FwDfdcToYJcMKNtRVQvJ6JCAPdAmAnbRb6CsX6aYb9m96NGod9uTw==
 
"@types/react-router-dom@5.1.3":
"@types/react-router-dom@^5.1.0":
version "5.1.3"
resolved "https://registry.yarnpkg.com/@types/react-router-dom/-/react-router-dom-5.1.3.tgz#b5d28e7850bd274d944c0fbbe5d57e6b30d71196"
integrity sha512-pCq7AkOvjE65jkGS5fQwQhvUp4+4PVD9g39gXLZViP2UqFiFzsEpB3PKf0O6mdbKsewSK8N14/eegisa/0CwnA==
......@@ -1434,7 +1434,7 @@
"@types/react" "*"
"@types/react-router" "*"
 
"@types/react-router@*", "@types/react-router@5.1.4":
"@types/react-router@*", "@types/react-router@^5.1.0":
version "5.1.4"
resolved "https://registry.yarnpkg.com/@types/react-router/-/react-router-5.1.4.tgz#7d70bd905543cb6bcbdcc6bd98902332054f31a6"
integrity sha512-PZtnBuyfL07sqCJvGg3z+0+kt6fobc/xmle08jBiezLS8FrmGeiGkJnuxL/8Zgy9L83ypUhniV5atZn/L8n9MQ==
......@@ -1442,7 +1442,7 @@
"@types/history" "*"
"@types/react" "*"
 
"@types/react@*":
"@types/react@*", "@types/react@^16.9.0":
version "16.9.21"
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.9.21.tgz#99e274e2ecfab6bb93920e918341daa3198b348d"
integrity sha512-xpmenCMeBwJRct8vmIfczlgdOXWIWASoOM857kxKfHlVQvDltRh7IFRVfGws79iO2jkNPXOeWREyKoClzhBaQA==
......@@ -1450,14 +1450,6 @@
"@types/prop-types" "*"
csstype "^2.2.0"
 
"@types/react@16.9.19":
version "16.9.19"
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.9.19.tgz#c842aa83ea490007d29938146ff2e4d9e4360c40"
integrity sha512-LJV97//H+zqKWMms0kvxaKYJDG05U2TtQB3chRLF8MPNs+MQh/H1aGlyDUxjaHvu08EAGerdX2z4LTBc7ns77A==
dependencies:
"@types/prop-types" "*"
csstype "^2.2.0"
"@types/redux-form@8.2.0":
version "8.2.0"
resolved "https://registry.yarnpkg.com/@types/redux-form/-/redux-form-8.2.0.tgz#e177fb1b837c11ec4c9eb66b4f5e833cdb4bef3f"
......@@ -3180,6 +3172,11 @@ btoa-lite@^1.0.0:
resolved "https://registry.yarnpkg.com/btoa-lite/-/btoa-lite-1.0.0.tgz#337766da15801210fdd956c22e9c6891ab9d0337"
integrity sha1-M3dm2hWAEhD92VbCLpxokaudAzc=
 
buffer-equal-constant-time@1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz#f8e71132f7ffe6e01a5c9697a4c6f3e48d5cc819"
integrity sha1-+OcRMvf/5uAaXJaXpMbz5I1cyBk=
buffer-equal@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/buffer-equal/-/buffer-equal-1.0.0.tgz#59616b498304d556abd466966b22eeda3eca5fbe"
......@@ -4693,6 +4690,13 @@ ecc-jsbn@~0.1.1:
jsbn "~0.1.0"
safer-buffer "^2.1.0"
 
ecdsa-sig-formatter@1.0.11:
version "1.0.11"
resolved "https://registry.yarnpkg.com/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz#ae0f0fa2d85045ef14a817daa3ce9acd0489e5bf"
integrity sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==
dependencies:
safe-buffer "^5.0.1"
editions@^2.2.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/editions/-/editions-2.3.0.tgz#47f2d5309340bce93ab5eb6ad755b9e90ff825e4"
......@@ -7802,6 +7806,22 @@ jsonparse@^1.2.0:
resolved "https://registry.yarnpkg.com/jsonparse/-/jsonparse-1.3.1.tgz#3f4dae4a91fac315f71062f8521cc239f1366280"
integrity sha1-P02uSpH6wxX3EGL4UhzCOfE2YoA=
 
jsonwebtoken@^8.5.1:
version "8.5.1"
resolved "https://registry.yarnpkg.com/jsonwebtoken/-/jsonwebtoken-8.5.1.tgz#00e71e0b8df54c2121a1f26137df2280673bcc0d"
integrity sha512-XjwVfRS6jTMsqYs0EsuJ4LGxXV14zQybNd4L2r0UvbVnSF9Af8x7p5MzbJ90Ioz/9TI41/hTCvznF/loiSzn8w==
dependencies:
jws "^3.2.2"
lodash.includes "^4.3.0"
lodash.isboolean "^3.0.3"
lodash.isinteger "^4.0.4"
lodash.isnumber "^3.0.3"
lodash.isplainobject "^4.0.6"
lodash.isstring "^4.0.1"
lodash.once "^4.0.0"
ms "^2.1.1"
semver "^5.6.0"
jsprim@^1.2.2:
version "1.4.1"
resolved "https://registry.yarnpkg.com/jsprim/-/jsprim-1.4.1.tgz#313e66bc1e5cc06e438bc1b7499c2e5c56acb6a2"
......@@ -7820,6 +7840,23 @@ jsx-ast-utils@^2.2.1, jsx-ast-utils@^2.2.3:
array-includes "^3.0.3"
object.assign "^4.1.0"
 
jwa@^1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/jwa/-/jwa-1.4.1.tgz#743c32985cb9e98655530d53641b66c8645b039a"
integrity sha512-qiLX/xhEEFKUAJ6FiBMbes3w9ATzyk5W7Hvzpa/SLYdxNtng+gcurvrI7TbACjIXlsJyr05/S1oUhZrc63evQA==
dependencies:
buffer-equal-constant-time "1.0.1"
ecdsa-sig-formatter "1.0.11"
safe-buffer "^5.0.1"
jws@^3.2.2:
version "3.2.2"
resolved "https://registry.yarnpkg.com/jws/-/jws-3.2.2.tgz#001099f3639468c9414000e99995fa52fb478304"
integrity sha512-YHlZCB6lMTllWDtSPHz/ZXTsi8S00usEV6v1tjq8tOUZzw7DpSDWVXjXDre6ed1w/pd495ODpHZYSdkRTsa0HA==
dependencies:
jwa "^1.4.1"
safe-buffer "^5.0.1"
keygrip@~1.0.2:
version "1.0.3"
resolved "https://registry.yarnpkg.com/keygrip/-/keygrip-1.0.3.tgz#399d709f0aed2bab0a059e0cdd3a5023a053e1dc"
......@@ -7888,7 +7925,7 @@ lead@^1.0.0:
dependencies:
flush-write-stream "^1.0.2"
 
lerna@^3.20.2:
lerna@^3.0.0, lerna@^3.20.2:
version "3.20.2"
resolved "https://registry.yarnpkg.com/lerna/-/lerna-3.20.2.tgz#abf84e73055fe84ee21b46e64baf37b496c24864"
integrity sha512-bjdL7hPLpU3Y8CBnw/1ys3ynQMUjiK6l9iDWnEGwFtDy48Xh5JboR9ZJwmKGCz9A/sarVVIGwf1tlRNKUG9etA==
......@@ -8061,26 +8098,56 @@ lodash.get@^4.4.2:
resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99"
integrity sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=
 
lodash.includes@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/lodash.includes/-/lodash.includes-4.3.0.tgz#60bb98a87cb923c68ca1e51325483314849f553f"
integrity sha1-YLuYqHy5I8aMoeUTJUgzFISfVT8=
lodash.isboolean@^3.0.3:
version "3.0.3"
resolved "https://registry.yarnpkg.com/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz#6c2e171db2a257cd96802fd43b01b20d5f5870f6"
integrity sha1-bC4XHbKiV82WgC/UOwGyDV9YcPY=
lodash.isequal@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0"
integrity sha1-QVxEePK8wwEgwizhDtMib30+GOA=
 
lodash.isinteger@^4.0.4:
version "4.0.4"
resolved "https://registry.yarnpkg.com/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz#619c0af3d03f8b04c31f5882840b77b11cd68343"
integrity sha1-YZwK89A/iwTDH1iChAt3sRzWg0M=
lodash.ismatch@^4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/lodash.ismatch/-/lodash.ismatch-4.4.0.tgz#756cb5150ca3ba6f11085a78849645f188f85f37"
integrity sha1-dWy1FQyjum8RCFp4hJZF8Yj4Xzc=
 
lodash.isnumber@^3.0.3:
version "3.0.3"
resolved "https://registry.yarnpkg.com/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz#3ce76810c5928d03352301ac287317f11c0b1ffc"
integrity sha1-POdoEMWSjQM1IwGsKHMX8RwLH/w=
lodash.isplainobject@^4.0.6:
version "4.0.6"
resolved "https://registry.yarnpkg.com/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz#7c526a52d89b45c45cc690b88163be0497f550cb"
integrity sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs=
 
lodash.isstring@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/lodash.isstring/-/lodash.isstring-4.0.1.tgz#d527dfb5456eca7cc9bb95d5daeaf88ba54a5451"
integrity sha1-1SfftUVuynzJu5XV2ur4i6VKVFE=
lodash.memoize@4.x, lodash.memoize@^4.1.2:
version "4.1.2"
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"
integrity sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4=
 
lodash.once@^4.0.0:
version "4.1.1"
resolved "https://registry.yarnpkg.com/lodash.once/-/lodash.once-4.1.1.tgz#0dd3971213c7c56df880977d504c88fb471a97ac"
integrity sha1-DdOXEhPHxW34gJd9UEyI+0cal6w=
lodash.set@^4.3.2:
version "4.3.2"
resolved "https://registry.yarnpkg.com/lodash.set/-/lodash.set-4.3.2.tgz#d8757b1da807dde24816b0d6a84bea1a76230b23"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment