-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from teclone/feat/github-actions
feat: enable github action workflow
- Loading branch information
Showing
24 changed files
with
4,617 additions
and
2,465 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Release | ||
|
||
on: | ||
push: | ||
branches: [master] | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Use Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '16.x' | ||
|
||
- name: Install dependencies | ||
run: yarn --frozen-lockfile | ||
|
||
- name: Run tests | ||
run: yarn test | ||
|
||
- name: Run build | ||
run: yarn build | ||
|
||
- name: Run release | ||
run: yarn release | ||
env: | ||
GH_TOKEN: ${{secrets.GH_TOKEN}} | ||
NPM_TOKEN: ${{secrets.NPM_TOKEN}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Test | ||
|
||
on: | ||
pull_request: | ||
branches: [master] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [16.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
|
||
- name: Install dependencies | ||
run: yarn --frozen-lockfile | ||
|
||
- name: Run tests | ||
run: yarn test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,3 +64,11 @@ typings/ | |
/lib | ||
|
||
/dist | ||
|
||
/cjs | ||
|
||
/esm | ||
|
||
/iife | ||
|
||
/umd |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
module.exports = { | ||
testEnvironment: 'node', | ||
collectCoverage: true, | ||
transform: { | ||
'^.+\\.tsx?$': 'babel-jest', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,9 @@ | |
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"main": "build/index", | ||
"typings": "lib/index", | ||
"module": "build/esm/index", | ||
"main": "cjs/index", | ||
"typings": "esm/index", | ||
"module": "esm/index", | ||
"author": "Harrison Ifeanyichukwu <[email protected]> (https://github.com/teclone)", | ||
"license": "MIT", | ||
"repository": { | ||
|
@@ -18,37 +18,31 @@ | |
"commit": "git-cz", | ||
"generateLocales": "node ./scripts/generateLocales", | ||
"test": "yarn generateLocales && BABEL_ENV=test jest -i --detectOpenHandles --forceExit", | ||
"watch-test": "BABEL_ENV=test jest --watch -i --detectOpenHandles", | ||
"typings": "tsc --p ./tsconfig.build.json", | ||
"build": "yarn generateLocales && rimraf lib && yarn typings --declarationDir ./build && yarn typings --declarationDir ./build/esm && rollup-all", | ||
"build": "yarn generateLocales && rollup-all", | ||
"report-coverage": "jest --coverage --coverageReporters=text-lcov | coveralls", | ||
"semantic-release": "semantic-release" | ||
"release": "semantic-release" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "7.4.5", | ||
"@babel/node": "7.4.5", | ||
"@babel/plugin-proposal-class-properties": "7.4.4", | ||
"@babel/plugin-proposal-object-rest-spread": "7.4.4", | ||
"@babel/preset-env": "7.4.5", | ||
"@babel/preset-typescript": "7.3.3", | ||
"@teclone/rollup-all": "1.10.9", | ||
"@rollup/plugin-dynamic-import-vars": "^2.0.3", | ||
"@teclone/rollup-all": "^1.24.1", | ||
"@types/jest": "24.0.11", | ||
"@typescript-eslint/eslint-plugin": "1.6.0", | ||
"@typescript-eslint/parser": "1.6.0", | ||
"babel-jest": "24.3.1", | ||
"babel-plugin-dynamic-import-node": "^2.3.3", | ||
"commitizen": "3.1.1", | ||
"cz-conventional-changelog": "2.1.0", | ||
"jest": "24.8.0", | ||
"jest": "^29.5.0", | ||
"nodemon": "1.19.1", | ||
"rimraf": "2.6.2", | ||
"prettier": "^2.8.7", | ||
"semantic-release": "^17.0.4", | ||
"semantic-release-cli": "5.2.1", | ||
"typescript": "3.5.2" | ||
"typescript": "^5.0.2" | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "cz-conventional-changelog" | ||
} | ||
}, | ||
"dependencies": {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module.exports = { | ||
repositoryUrl: 'https://github.com/teclone/industries.git', | ||
plugins: [ | ||
'@semantic-release/commit-analyzer', | ||
'@semantic-release/release-notes-generator', | ||
['@semantic-release/github'], | ||
'@semantic-release/npm', | ||
], | ||
ci: true, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
const { config } = require('@teclone/rollup-all'); | ||
module.exports = config({ | ||
config: {}, | ||
const { createConfig } = require('@teclone/rollup-all'); | ||
module.exports = createConfig({ | ||
formats: ['cjs', 'esm', 'iife', 'umd'], | ||
envs: ['uni'], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,52 @@ | ||
const path = require("path"); | ||
const fs = require("fs"); | ||
const industriesDb = require("../db/industries.json"); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const prettier = require('prettier'); | ||
|
||
const locales = new Map(); | ||
const langs = new Set(); | ||
const industriesDb = require('../db/industries.json'); | ||
|
||
// Generate each locale group | ||
industriesDb.forEach(({ translations, ...record }) => { | ||
const en = locales.get("en") ?? []; | ||
en.push(record); | ||
locales.set("en", en); | ||
langs.add("en"); | ||
const supportedLocales = ['en', 'es', 'fr']; | ||
|
||
Object.keys(translations).forEach((lang) => { | ||
const loc = locales.get(lang) ?? []; | ||
loc.push({ | ||
...record, | ||
name: translations[lang], | ||
}); | ||
locales.set(lang.toLowerCase(), loc); | ||
langs.add(lang.toLowerCase()); | ||
}); | ||
}); | ||
const defaultLocale = 'en'; | ||
|
||
const en = locales.get("en") ?? []; | ||
|
||
for (const lang of locales.keys()) { | ||
const loc = locales.get(lang) ?? []; | ||
|
||
// Check that each ID has a translation, if it does not leave the name in English | ||
if (en.length !== loc.length) { | ||
const toAppend = []; | ||
en.forEach((enItem) => { | ||
const idx = loc.findIndex((item) => item.id === enItem.id); | ||
if (idx < 0) { | ||
toAppend.push(enItem); | ||
for (const locale of supportedLocales) { | ||
const industriesForLocale = industriesDb.map( | ||
({ id, linkedinId, name, translations }) => { | ||
if (locale === defaultLocale) { | ||
return { | ||
id, | ||
linkedinId, | ||
name, | ||
}; | ||
} | ||
}); | ||
|
||
loc.push(...toAppend); | ||
loc.sort((a, b) => { | ||
return a.id - b.id; | ||
}); | ||
} | ||
|
||
const filename = path.resolve("src", "locale", `${lang}.ts`); | ||
if (fs.existsSync(filename)) { | ||
fs.unlinkSync(filename); | ||
} | ||
fs.writeFileSync(filename, `export default ${JSON.stringify(loc)}`, "utf8", function (err) { | ||
if (err) { | ||
console.error(err); | ||
} else { | ||
console.log(`Generated: ${loc}`); | ||
return { | ||
id, | ||
linkedinId, | ||
name: translations[locale] || name, | ||
}; | ||
} | ||
}); | ||
} | ||
|
||
const filename = path.resolve("src", "locale", "en.ts"); | ||
if (fs.existsSync(filename)) { | ||
fs.unlinkSync(filename); | ||
); | ||
|
||
const content = JSON.stringify(industriesForLocale, null, 2); | ||
fs.writeFileSync( | ||
path.resolve(__dirname, `../src/locales/${locale}.json`), | ||
prettier.format(`${content}`, { | ||
parser: 'json', | ||
}) | ||
); | ||
} | ||
fs.writeFileSync(filename, `export default ${JSON.stringify(en)}`, "utf8", function (err) { | ||
if (err) { | ||
console.error(err); | ||
} else { | ||
console.log("Generated: en"); | ||
} | ||
}); | ||
|
||
const filenameLangs = path.resolve("src", "langs.ts"); | ||
if (fs.existsSync(filenameLangs)) { | ||
fs.unlinkSync(filenameLangs); | ||
} | ||
fs.writeFileSync( | ||
filenameLangs, | ||
`export default ${JSON.stringify(Array.from(langs))}`, | ||
"utf8", | ||
function (err) { | ||
if (err) { | ||
console.error(err); | ||
} else { | ||
console.log("Generated: langs"); | ||
path.resolve(__dirname, '../src/constants.ts'), | ||
|
||
prettier.format( | ||
` | ||
export const DEFAULT_LOCALE = '${defaultLocale}'; | ||
export const supportedLocales = ${JSON.stringify(supportedLocales)}; | ||
`, | ||
{ | ||
parser: 'typescript', | ||
} | ||
} | ||
) | ||
); | ||
|
||
console.log("Task finished successfully."); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const DEFAULT_LOCALE = "en"; | ||
|
||
export const supportedLocales = ["en", "es", "fr"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
import en from './locale/en'; | ||
import { Industry } from 'types'; | ||
import { supportedLocales } from './constants'; | ||
|
||
import { supportedLocales } from './supportedLocales'; | ||
import enIndustries from './locales/en.json'; | ||
|
||
export * from './supportedLocales'; | ||
export { enIndustries as industries }; | ||
|
||
export const industries = en; | ||
export function getIndustriesByLocale(locale: string): Promise<Industry[]> { | ||
locale = locale.toLowerCase(); | ||
|
||
export function getIndustriesByLocale (locale: string) { | ||
if (supportedLocales.indexOf(locale.toLowerCase())) { | ||
return require(`./locale/${locale.toLowerCase()}`).default; | ||
} else { | ||
return industries; | ||
if (!supportedLocales.includes(locale)) { | ||
throw new Error(`Unsupported locale: ${locale} is not supported`); | ||
} | ||
} | ||
|
||
return import(`./locales/${locale}.json`).then((result) => result.default); | ||
} | ||
|
||
export { DEFAULT_LOCALE, supportedLocales } from './constants'; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.