Skip to content

Commit

Permalink
[Release] v1.0.20210930
Browse files Browse the repository at this point in the history
  • Loading branch information
ptkdev committed Sep 29, 2021
1 parent 30cb44c commit 4d0d87e
Show file tree
Hide file tree
Showing 25 changed files with 14,201 additions and 23,114 deletions.
101 changes: 49 additions & 52 deletions .eslintrc.cjs
@@ -1,86 +1,83 @@
module.exports = {
"env": {
"es6": true,
"node": true,
"browser": false,
"jest/globals": true
env: {
es6: true,
node: true,
browser: false,
"jest/globals": true,
},
"parser": "@typescript-eslint/parser",
"extends": ["eslint:recommended", "plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/recommended"],
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2019
parser: "@typescript-eslint/parser",
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
],
parserOptions: {
sourceType: "module",
ecmaVersion: 2019,
},
"plugins": ["jsdoc", "jest", "@typescript-eslint"],
"globals": {
"fetch": false
plugins: ["jsdoc", "jest", "@typescript-eslint"],
globals: {
fetch: false,
},
"settings": {
"jsdoc": {
"tagNamePreference": {
"returns": "return"
}
}
settings: {
jsdoc: {
tagNamePreference: {
returns: "return",
},
},
},
"rules": {
rules: {
"no-multi-spaces": [
"error",
{
"ignoreEOLComments": true,
"exceptions": {
"VariableDeclarator": true
}
}
ignoreEOLComments: true,
exceptions: {
VariableDeclarator: true,
},
},
],
"block-spacing": ["error", "always"],
"array-bracket-spacing": ["error", "never"],
"space-in-parens": ["error", "never"],
"comma-spacing": [
"error",
{
"before": false,
"after": true
}
before: false,
after: true,
},
],
"key-spacing": [
"error",
{
"afterColon": true,
"beforeColon": false
}
afterColon: true,
beforeColon: false,
},
],
"indent": [
"error",
"tab",
{
"SwitchCase": 1
}
],
"quotes": [
quotes: [
"error",
"double",
{
"avoidEscape": true,
"allowTemplateLiterals": true
}
avoidEscape: true,
allowTemplateLiterals: true,
},
],
"semi": ["error", "always"],
semi: ["error", "always"],
"no-console": ["warn"],
"no-constant-condition": ["warn"],
"curly": ["error", "all"],
curly: ["error", "all"],
"brace-style": [
"error",
"1tbs",
{
"allowSingleLine": false
}
allowSingleLine: false,
},
],
"keyword-spacing": [
"error",
{
"before": true,
"after": true
}
before: true,
after: true,
},
],
"object-curly-spacing": ["error", "always"],
"no-mixed-spaces-and-tabs": ["error", "smart-tabs"],
Expand All @@ -106,6 +103,6 @@ module.exports = {
"jsdoc/require-returns-description": 1,
"jsdoc/require-returns-type": 1,
"jsdoc/require-returns-check": 1,
"jsdoc/require-hyphen-before-param-description": 1
}
}
"jsdoc/require-hyphen-before-param-description": 1,
},
};
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -123,5 +123,6 @@ npm-debug.log
#######
/app/configs/config.js
/app/configs/config.ts
/app/configs/config.json
/dist
/build
4 changes: 4 additions & 0 deletions .prettierignore
@@ -0,0 +1,4 @@
/dist
/build
/node_modules
package-lock.json
2 changes: 1 addition & 1 deletion .prettierrc
@@ -1,6 +1,6 @@
{
"bracketSpacing": true,
"printWidth": 160,
"printWidth": 120,
"semi": true,
"singleQuote": false,
"tabWidth": 4,
Expand Down
4 changes: 2 additions & 2 deletions .vscode/settings.json
Expand Up @@ -6,10 +6,10 @@
},
"eslint.format.enable": true,
"[javascript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "vscode.typescript-language-features"
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[scss]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
Expand Down
7 changes: 4 additions & 3 deletions CHANGELOG.md
@@ -1,7 +1,8 @@
# v1.0.20210412 (April 12, 2021)
# v1.0.20210930 (September 30, 2021)

- Fix: minor fix
- Fix: readme of issues
- Security: update
- Feature: translations
- Fix: logs

<!-- all-shields/sponsors-badges:START -->

Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -2,7 +2,7 @@

<!-- all-shields/header-badges:START -->

[![v1.0.20210412](https://img.shields.io/badge/version-v1.0.20210412-lightgray.svg?style=flat&logo=)](https://github.com/ptkdev-boilerplate/node-cli-boilerplate/blob/main/CHANGELOG.md) [![](https://img.shields.io/npm/v/@ptkdev/node-cli-boilerplate?color=CC3534&logo=npm)](https://www.npmjs.com/package/@ptkdev/node-cli-boilerplate) [![License: MIT](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat&logo=license)](https://github.com/ptkdev-boilerplate/node-cli-boilerplate/blob/main/LICENSE.md) [![Language: TypeScript](https://img.shields.io/badge/language-typescript-blue.svg?style=flat&logo=typescript)](https://www.typescriptlang.org/) [![ECMAScript: 2019](https://img.shields.io/badge/ES-9-F7DF1E.svg?style=flat&logo=javascript)](https://github.com/tc39/ecma262) [![Discord Server](https://discordapp.com/api/guilds/383373985666301975/embed.png)](https://discord.ptkdev.io)
[![v1.0.20210930](https://img.shields.io/badge/version-v1.0.20210930-lightgray.svg?style=flat&logo=)](https://github.com/ptkdev-boilerplate/node-cli-boilerplate/blob/main/CHANGELOG.md) [![](https://img.shields.io/npm/v/@ptkdev/node-cli-boilerplate?color=CC3534&logo=npm)](https://www.npmjs.com/package/@ptkdev/node-cli-boilerplate) [![License: MIT](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat&logo=license)](https://github.com/ptkdev-boilerplate/node-cli-boilerplate/blob/main/LICENSE.md) [![Language: TypeScript](https://img.shields.io/badge/language-typescript-blue.svg?style=flat&logo=typescript)](https://www.typescriptlang.org/) [![ECMAScript: 2019](https://img.shields.io/badge/ES-9-F7DF1E.svg?style=flat&logo=javascript)](https://github.com/tc39/ecma262) [![Discord Server](https://discordapp.com/api/guilds/383373985666301975/embed.png)](https://discord.ptkdev.io)

<!-- all-shields/header-badges:END -->

Expand Down
10 changes: 6 additions & 4 deletions app/cli/cli.ts
Expand Up @@ -10,11 +10,13 @@
*
*/
import m from "@app/functions/module";
import configs from "@configs/config";
import configs from "@configs/config.json";
import translate from "@translations/translate";
import logger from "@app/utils/logger";

(async () => {
const { app } = await m({ text: "hello-world" });
const { app } = await m({ text: translate("hello", { name: "Boilerplate" }) });

console.log(app());
console.log(`debug: ${configs.debug}`);
logger.info(app());
logger.debug(configs.debug ? "true" : "false");
})();
26 changes: 0 additions & 26 deletions app/configs/config.js.tpl

This file was deleted.

17 changes: 17 additions & 0 deletions app/configs/config.json.tpl
@@ -0,0 +1,17 @@
{
"server": { "port": 5000 },
"debug": true,
"language": "en",
"logger": {
"path": { "debug_log": "./logs/debug.log", "error_log": "./logs/errors.log" },
"language": "en",
"colors": "enabled",
"debug": "enabled",
"info": "enabled",
"warning": "enabled",
"error": "enabled",
"sponsor": "enabled",
"write": "disabled",
"type": "log"
}
}
22 changes: 22 additions & 0 deletions app/core/run.ts
@@ -0,0 +1,22 @@
/**
* Run
* =====================
*
* Start module
*
* @contributors: Patryk Rzucidło [@ptkdev] <support@ptkdev.io> (https://ptk.dev)
*
* @license: MIT License
*
*/
import m from "@app/functions/module";
import configs from "@configs/config.json";
import translate from "@translations/translate";
import logger from "@app/utils/logger";

(async () => {
const { app } = await m({ text: translate("hello", { name: "Boilerplate" }) });

logger.info(app());
logger.debug(configs.debug ? "true" : "false");
})();
2 changes: 1 addition & 1 deletion app/functions/module.ts
Expand Up @@ -28,7 +28,7 @@ const m = async ({ text }: ModuleInterface): Promise<ModuleResponseInterface> =>
const app = () => text;

return {
app
app,
};
};

Expand Down
9 changes: 8 additions & 1 deletion app/routes/translations.ts
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/**
* Translations
* =====================
Expand All @@ -11,4 +12,10 @@
import en from "@translations/en.json";
import it from "@translations/it.json";

export default { en, it };
const translations: any = {
en,
it,
};

export { it, en };
export default translations;
2 changes: 1 addition & 1 deletion app/translations/en.json
Expand Up @@ -5,5 +5,5 @@
"contributors": ["Patryk Rzucidło [@ptkdev] <support@ptkdev.io> (https://ptk.dev)"]
},
"app_name": "node-cli-boilerplate",
"hello": "Hello World!"
"hello": "Hello {{name}}!"
}
2 changes: 1 addition & 1 deletion app/translations/it.json
Expand Up @@ -5,5 +5,5 @@
"contributors": ["Patryk Rzucidło [@ptkdev] <support@ptkdev.io> (https://ptk.dev)"]
},
"app_name": "node-cli-boilerplate",
"hello": "Ciao Mondo!"
"hello": "Ciao {{name}}!"
}
72 changes: 72 additions & 0 deletions app/translations/translate.ts
@@ -0,0 +1,72 @@
/**
* Translate
* =====================
*
* @contributors: Patryk Rzucidło [@ptkdev] <support@ptkdev.io> (https://ptk.dev)
*
* @license: MIT License
*
*/
import configs from "@configs/config.json";
import translations from "@app/routes/translations";
import type { TranslateParamsInterface } from "@app/types/translate.type";

/**
* Replace Params
* =====================
* If translation text is: hi {{name}} how are you?
* This function replace {{name}} token with correct value
*
* @param {string} text - text of current phrase to translate (mandatory)
* @param {Object} language_params - object with token to replace, example: {name:"alex"} (mandatory)
*
* @return {string} text - text with replaced token
*
*/
const replaceParams = (text: string, language_params: TranslateParamsInterface): string => {
for (const [key, value] of Object.entries(language_params)) {
text = text.replace(`{{${key}}}`, value);
}

return text;
};

/**
* Check
* =====================
* Check if exist translation in selected language, if not exist get string of phrase from "en" translation
*
* @param {string} language_id - key of translation phrase from /translations/*.json (mandatory)
*
* @return {string} text - text of available translation
*
*/
const check = (language_id: string): string => {
return translations[configs.language] && translations[configs.language][language_id]
? translations[configs.language][language_id]
: translations["en"][language_id];
};

/**
* Translate
* =====================
* Get correct translation
*
* @param {string} language_id - key of translation phrase from /translations/*.json (mandatory)
* @param {Object} language_params - object with token to replace, example: {name:"alex"} (optional)
*
* @return {string} text - text of available translation
*
*/
const translate = (language_id: string, language_params?: TranslateParamsInterface): string => {
let text = "";
text = check(language_id);
if (language_params) {
text = replaceParams(text, language_params);
}

return text;
};

export { translate };
export default translate;

0 comments on commit 4d0d87e

Please sign in to comment.