Skip to content

Commit

Permalink
Merge pull request #33 from teclone/feat/github-actions
Browse files Browse the repository at this point in the history
feat: enable github action workflow
  • Loading branch information
Harrison Ifeanyichukwu authored Apr 16, 2023
2 parents 2510716 + 6d73869 commit ba8c37b
Show file tree
Hide file tree
Showing 24 changed files with 4,617 additions and 2,465 deletions.
8 changes: 2 additions & 6 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
"modules": "cjs"
}
],
"@babel/preset-typescript"
],
"plugins": [
"@babel/plugin-transform-runtime",
"@babel/proposal-class-properties",
"@babel/proposal-object-rest-spread"
"dynamic-import-node"
]
}
}
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/release.yml
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}}
27 changes: 27 additions & 0 deletions .github/workflows/test.yml
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
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,11 @@ typings/
/lib

/dist

/cjs

/esm

/iife

/umd
19 changes: 0 additions & 19 deletions .travis.yml

This file was deleted.

1 change: 0 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module.exports = {
testEnvironment: 'node',
collectCoverage: true,
transform: {
'^.+\\.tsx?$': 'babel-jest',
Expand Down
30 changes: 12 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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": {}
}
}
10 changes: 10 additions & 0 deletions release.config.js
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,
};
7 changes: 4 additions & 3 deletions rollup.config.js
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'],
});
117 changes: 40 additions & 77 deletions scripts/generateLocales.js
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.");
3 changes: 3 additions & 0 deletions src/constants.ts
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"];
23 changes: 13 additions & 10 deletions src/index.ts
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';
1 change: 0 additions & 1 deletion src/langs.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/locale/en.ts

This file was deleted.

Loading

0 comments on commit ba8c37b

Please sign in to comment.