diff --git a/.github/workflows/practica-quality-check.yml b/.github/workflows/practica-quality-check.yml index d387f1b5..6e65568f 100644 --- a/.github/workflows/practica-quality-check.yml +++ b/.github/workflows/practica-quality-check.yml @@ -3,7 +3,7 @@ name: practica-quality-check on: push: branches: - - "*" + - '*' pull_request: branches: [main] diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 00000000..9c77a473 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,4 @@ +#!/usr/bin/env sh +. "$(dirname -- "$0")/_/husky.sh" + +npx pretty-quick --staged \ No newline at end of file diff --git a/.prettierrc.json b/.prettierrc.json index 0967ef42..dc08f702 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1 +1,15 @@ -{} +{ + "arrowParens": "avoid", + "bracketSpacing": true, + "endOfLine": "lf", + "bracketSameLine": false, + "jsxSingleQuote": false, + "printWidth": 80, + "proseWrap": "preserve", + "quoteProps": "as-needed", + "semi": true, + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "all", + "useTabs": false +} diff --git a/package-lock.json b/package-lock.json index 4eafe6c0..0d69179b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -41,6 +41,7 @@ "@types/prettier": "^2.4.4", "@types/sinon": "^10.0.11", "execa": "^5.1.1", + "husky": "^8.0.1", "jest": "^27.5.1", "jest-watch-suspend": "^1.1.2", "jest-watch-typeahead": "^1.1.0", @@ -3695,6 +3696,21 @@ "node": ">=10.17.0" } }, + "node_modules/husky": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/husky/-/husky-8.0.1.tgz", + "integrity": "sha512-xs7/chUH/CKdOCs7Zy0Aev9e/dKOMZf3K1Az1nar3tzlv0jfqnYtu235bstsWTmXOR0EfINrPa97yy4Lz6RiKw==", + "dev": true, + "bin": { + "husky": "lib/bin.js" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/typicode" + } + }, "node_modules/iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", @@ -10881,6 +10897,12 @@ "integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==", "dev": true }, + "husky": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/husky/-/husky-8.0.1.tgz", + "integrity": "sha512-xs7/chUH/CKdOCs7Zy0Aev9e/dKOMZf3K1Az1nar3tzlv0jfqnYtu235bstsWTmXOR0EfINrPa97yy4Lz6RiKw==", + "dev": true + }, "iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", diff --git a/package.json b/package.json index 639b1dec..e47f59a8 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,8 @@ "copy-templates": "rsync -av --exclude '*node_modules*' ./src/code-templates/ ./.dist/src/code-templates", "build:watch": "tsc --watch", "start:cli": "node ./.dist/bin/cli.js interactive", - "publish:build": "npm run build && npm publish ./.dist --access public" + "publish:build": "npm run build && npm publish ./.dist --access public", + "prepare": "husky install" }, "repository": { "type": "git", @@ -66,6 +67,7 @@ "@types/prettier": "^2.4.4", "@types/sinon": "^10.0.11", "execa": "^5.1.1", + "husky": "^8.0.0", "jest": "^27.5.1", "jest-watch-suspend": "^1.1.2", "jest-watch-typeahead": "^1.1.0", diff --git a/src/code-templates/libraries/logger/definition.ts b/src/code-templates/libraries/logger/definition.ts index c761b5a6..40a50ba2 100644 --- a/src/code-templates/libraries/logger/definition.ts +++ b/src/code-templates/libraries/logger/definition.ts @@ -1,16 +1,16 @@ -export type LOG_LEVELS = 'debug' | 'info' | 'warn' | 'error' | 'critical'; +export type LOG_LEVELS = 'debug' | 'info' | 'warn' | 'error' | 'critical' export interface Logger { - info(message: string, ...args: any[]): void; + info(message: string, ...args: any[]): void - error(message: string, ...args: any[]): void; + error(message: string, ...args: any[]): void - debug(message: string, ...args: any[]): void; + debug(message: string, ...args: any[]): void - warning(message: string, ...args: any[]): void; + warning(message: string, ...args: any[]): void } -export interface LoggerConfiguration{ - level: LOG_LEVELS; - prettyPrint: boolean; +export interface LoggerConfiguration { + level: LOG_LEVELS + prettyPrint: boolean } diff --git a/src/code-templates/libraries/logger/jest.config.js b/src/code-templates/libraries/logger/jest.config.js index 104e1ef3..d3c1bcca 100644 --- a/src/code-templates/libraries/logger/jest.config.js +++ b/src/code-templates/libraries/logger/jest.config.js @@ -23,7 +23,7 @@ module.exports = { // collectCoverageFrom: undefined, // The directory where Jest should output its coverage files - coverageDirectory: "coverage", + coverageDirectory: 'coverage', // An array of regexp pattern strings used to skip coverage collection // coveragePathIgnorePatterns: [ @@ -31,7 +31,7 @@ module.exports = { // ], // Indicates which provider should be used to instrument code for coverage - coverageProvider: "v8", + coverageProvider: 'v8', // A list of reporter names that Jest uses when writing coverage reports // coverageReporters: [ @@ -90,7 +90,7 @@ module.exports = { notify: true, // An enum that specifies notification mode. Requires { notify: true } - notifyMode: "change", + notifyMode: 'change', // A preset that is used as a base for Jest's configuration //preset: "ts-jest", @@ -137,7 +137,7 @@ module.exports = { // snapshotSerializers: [], // The test environment that will be used for testing - testEnvironment: "node", + testEnvironment: 'node', // Options that will be passed to the testEnvironment // testEnvironmentOptions: {}, @@ -146,10 +146,10 @@ module.exports = { // testLocationInResults: false, // The glob patterns Jest uses to detect test files - testMatch: ["**/*.test.ts"], + testMatch: ['**/*.test.ts'], // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped - testPathIgnorePatterns: ["/node_modules/"], + testPathIgnorePatterns: ['/node_modules/'], // The regexp pattern or array of patterns that Jest uses to detect test files // testRegex: [], @@ -167,7 +167,7 @@ module.exports = { // timers: "real", // A map from regular expressions to paths to transformers - transform: { "^.+\\.(t|j)s$": "ts-jest" }, + transform: { '^.+\\.(t|j)s$': 'ts-jest' }, // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation // transformIgnorePatterns: [ @@ -186,4 +186,4 @@ module.exports = { // Whether to use watchman for file crawling // watchman: true, -}; +} diff --git a/src/code-templates/services/order-service/config.ts b/src/code-templates/services/order-service/config.ts index 9fc1eed7..a29a4cc6 100644 --- a/src/code-templates/services/order-service/config.ts +++ b/src/code-templates/services/order-service/config.ts @@ -2,56 +2,56 @@ export default { port: { - doc: "The API listening port. By default is 0 (ephemeral) which serves as a dynamic port for testing purposes. For production use, a specific port must be assigned", - format: "Number", + doc: 'The API listening port. By default is 0 (ephemeral) which serves as a dynamic port for testing purposes. For production use, a specific port must be assigned', + format: 'Number', default: 0, nullable: true, - env: "PORT", + env: 'PORT', }, logger: { level: { - doc: "Which type of logger entries should actually be written to the target medium (e.g., stdout)", - format: ["debug", "info", "warn", "error", "critical"], - default: "info", + doc: 'Which type of logger entries should actually be written to the target medium (e.g., stdout)', + format: ['debug', 'info', 'warn', 'error', 'critical'], + default: 'info', nullable: false, - env: "LOGGER_LEVEL", + env: 'LOGGER_LEVEL', }, prettyPrint: { - doc: "Weather the logger should be configured to pretty print the output", + doc: 'Weather the logger should be configured to pretty print the output', format: 'Boolean', default: true, nullable: false, - env: "PRETTY_PRINT_LOG", + env: 'PRETTY_PRINT_LOG', }, destination: { - doc: "destination in which the logger should be written, empty value will be considered as stdout", + doc: 'destination in which the logger should be written, empty value will be considered as stdout', format: '*', default: null, nullable: true, - env: "LOGGER_DEST", - } + env: 'LOGGER_DEST', + }, }, DB: { userName: { - doc: "The DB connection user name", - format: "String", - default: "myuser", + doc: 'The DB connection user name', + format: 'String', + default: 'myuser', nullable: false, - env: "DB_USERNAME", + env: 'DB_USERNAME', }, password: { doc: "The DB connection password. Don't put production code here", - format: "String", - default: "myuserpassword", + format: 'String', + default: 'myuserpassword', nullable: false, - env: "DB_PASSWORD", + env: 'DB_PASSWORD', }, dbName: { - doc: "The default database name", - format: "String", - default: "shop", + doc: 'The default database name', + format: 'String', + default: 'shop', nullable: false, - env: "DB_NAME", + env: 'DB_NAME', }, }, -}; +} diff --git a/src/code-templates/services/order-service/data-access/migrations/20191229152126-entire-schema.ts b/src/code-templates/services/order-service/data-access/migrations/20191229152126-entire-schema.ts index 4e1fe88e..ffa2e7c1 100644 --- a/src/code-templates/services/order-service/data-access/migrations/20191229152126-entire-schema.ts +++ b/src/code-templates/services/order-service/data-access/migrations/20191229152126-entire-schema.ts @@ -1,6 +1,6 @@ module.exports = { up: async (queryInterface, Sequelize) => { - await queryInterface.createTable("Orders", { + await queryInterface.createTable('Orders', { id: { allowNull: false, autoIncrement: true, @@ -32,9 +32,9 @@ module.exports = { allowNull: false, type: Sequelize.DATE, }, - }); + }) - await queryInterface.createTable("Countries", { + await queryInterface.createTable('Countries', { id: { allowNull: false, autoIncrement: true, @@ -44,8 +44,8 @@ module.exports = { name: { type: Sequelize.STRING, }, - }); + }) }, - down: (queryInterface, Sequelize) => queryInterface.dropTable("Orders"), -}; + down: (queryInterface, Sequelize) => queryInterface.dropTable('Orders'), +} diff --git a/src/code-templates/services/order-service/data-access/seeders/20191229151823-countries.ts b/src/code-templates/services/order-service/data-access/seeders/20191229151823-countries.ts index 6a0985dd..6b82b45d 100644 --- a/src/code-templates/services/order-service/data-access/seeders/20191229151823-countries.ts +++ b/src/code-templates/services/order-service/data-access/seeders/20191229151823-countries.ts @@ -2,20 +2,20 @@ module.exports = { up: async (queryInterface, Sequelize) => { // ✅ Best Practice: Seed only metadata and not test record, read "Dealing with data" section for further information await queryInterface.bulkInsert( - "Countries", + 'Countries', [ { - name: "Italy", + name: 'Italy', }, { - name: "USA", + name: 'USA', }, { - name: "India", + name: 'India', }, ], {} - ); + ) }, down: (queryInterface, Sequelize) => {}, -}; +}