Skip to content

Instantly share code, notes, and snippets.

@vdelacou
Last active July 23, 2023 06:53
Show Gist options
  • Select an option

  • Save vdelacou/996f290aa5d108b55688229e15ff4b3b to your computer and use it in GitHub Desktop.

Select an option

Save vdelacou/996f290aa5d108b55688229e15ff4b3b to your computer and use it in GitHub Desktop.

Revisions

  1. vdelacou revised this gist Apr 25, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion example.test.ts
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    import { sum } from './password';
    import { sum } from './example';

    describe('Calc', () => {
    test('should return 10 for add(6, 4)', () => {
  2. vdelacou revised this gist Apr 25, 2021. 6 changed files with 61 additions and 7 deletions.
    6 changes: 6 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -20,4 +20,10 @@ mkdir src
    curl -o src/example.ts https://gist.githubusercontent.com/vdelacou/996f290aa5d108b55688229e15ff4b3b/raw/example.ts
    curl -o .eslintrc.json https://gist.githubusercontent.com/vdelacou/996f290aa5d108b55688229e15ff4b3b/raw/.eslintrc.json
    curl -o tsconfig.json https://gist.githubusercontent.com/vdelacou/996f290aa5d108b55688229e15ff4b3b/raw/tsconfig.json
    npm install --save-dev jest @types/jest ts-jest
    curl -o jest.config.js https://gist.githubusercontent.com/vdelacou/996f290aa5d108b55688229e15ff4b3b/raw/jest.config.js
    mkdir src/lib
    curl -o src/lib/log.ts https://gist.githubusercontent.com/vdelacou/996f290aa5d108b55688229e15ff4b3b/raw/log.ts
    npx json -I -f package.json -e 'this.scripts={...this.scripts , "test": "jest" }'
    curl -o src/example.test.ts https://gist.githubusercontent.com/vdelacou/996f290aa5d108b55688229e15ff4b3b/raw/example.test.ts
    ```
    10 changes: 10 additions & 0 deletions example.test.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    import { sum } from './password';

    describe('Calc', () => {
    test('should return 10 for add(6, 4)', () => {
    expect(sum(6, 4)).toBe(10);
    });
    test('should return 9 for add(10, -1)', () => {
    expect(sum(10, -1)).toBe(9);
    });
    });
    16 changes: 10 additions & 6 deletions example.ts
    Original file line number Diff line number Diff line change
    @@ -1,19 +1,23 @@
    import winston from 'winston';
    import { newLogger } from './lib/log';

    const logger = winston.createLogger({ transports: [new winston.transports.Console()] });
    const logger = newLogger('password');

    const delay = (milliseconds: number, count: number): Promise<number> => {
    export const sum = (a: number, b: number): number => {
    return a + b;
    };

    const delay = (milliseconds: number, a: number, b: number): Promise<number> => {
    return new Promise((resolve) => {
    setTimeout(() => {
    resolve(count);
    resolve(sum(a, b));
    }, milliseconds);
    });
    };

    (async () => {
    logger.info('Start');
    const count = await delay(1000, 2);
    logger.info(`End with count: ${count}`);
    const count = await delay(1000, 2, 6);
    logger.info(`End with count: ${count}`, { count });
    })().catch((e) => {
    logger.error(e);
    });
    2 changes: 1 addition & 1 deletion extensions.json
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    {
    "recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode", "editorconfig.editorconfig", "eamodio.gitlens"]
    "recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode", "editorconfig.editorconfig", "eamodio.gitlens", "orta.vscode-jest"]
    }
    13 changes: 13 additions & 0 deletions jest.config.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    module.exports = {
    roots: ['<rootDir>/src'],
    testMatch: ['**/__tests__/**/*.+(ts|js)', '**/?(*.)+(spec|test).+(ts|js)'],
    transform: {
    '^.+\\.(ts)$': 'ts-jest',
    },
    collectCoverageFrom: ['**/*.{js,ts}', '!**/*.d.ts', '!**/node_modules/**'],
    globals: {
    'ts-jest': {
    tsconfig: 'tsconfig.json',
    },
    },
    };
    21 changes: 21 additions & 0 deletions log.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    import winston from 'winston';

    const { createLogger, format, transports } = winston;

    export const newLogger = (service: string): winston.Logger => {
    const logger = createLogger({
    level: 'info',
    format: format.combine(
    format.timestamp({
    format: 'YYYY-MM-DD HH:mm:ss',
    }),
    format.ms(),
    format.errors({ stack: true }),
    format.splat(),
    format.json()
    ),
    defaultMeta: { service },
    transports: [new transports.Console()],
    });
    return logger;
    };
  3. vdelacou revised this gist Apr 25, 2021. 3 changed files with 37 additions and 4 deletions.
    6 changes: 2 additions & 4 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -6,8 +6,8 @@
    curl -o .gitignore https://gist.githubusercontent.com/vdelacou/1954a25d720f702b4af011ba2773001b/raw/.gitignore
    curl -o .prettierrc https://gist.githubusercontent.com/vdelacou/58484f1c11af70aaa457f4e5c289e893/raw/.prettierrc
    mkdir .vscode
    curl -o .vscode/extensions.json https://gist.githubusercontent.com/vdelacou/c5f3fd74c5e836706c0adaeb0d383bd0/raw/extensions.json
    curl -o .vscode/settings.json https://gist.githubusercontent.com/vdelacou/c5f3fd74c5e836706c0adaeb0d383bd0/raw/settings.json
    curl -o .vscode/extensions.json https://gist.githubusercontent.com/vdelacou/996f290aa5d108b55688229e15ff4b3b/raw/extensions.json
    curl -o .vscode/settings.json https://gist.githubusercontent.com/vdelacou/996f290aa5d108b55688229e15ff4b3b/raw/settings.json
    curl -o .editorconfig https://gist.githubusercontent.com/vdelacou/58484f1c11af70aaa457f4e5c289e893/raw/.editorconfig
    npm install --save-dev typescript ts-node eslint @typescript-eslint/eslint-plugin @typescript-eslint/parser prettier eslint-config-prettier eslint-plugin-prettier
    npm install husky --save-dev
    @@ -21,5 +21,3 @@ curl -o src/example.ts https://gist.githubusercontent.com/vdelacou/996f290aa5d10
    curl -o .eslintrc.json https://gist.githubusercontent.com/vdelacou/996f290aa5d108b55688229e15ff4b3b/raw/.eslintrc.json
    curl -o tsconfig.json https://gist.githubusercontent.com/vdelacou/996f290aa5d108b55688229e15ff4b3b/raw/tsconfig.json
    ```


    3 changes: 3 additions & 0 deletions extensions.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    {
    "recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode", "editorconfig.editorconfig", "eamodio.gitlens"]
    }
    32 changes: 32 additions & 0 deletions settings.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    {
    "editor.formatOnSave": true,
    "editor.codeActionsOnSave": {
    "source.organizeImports": true
    },
    "typescript.tsdk": "node_modules\\typescript\\lib",
    "files.autoSave": "afterDelay",
    "search.exclude": {
    "**/node_modules": true,
    "**/.vscode": true
    },
    "git.autofetch": true,
    "javascript.format.enable": false,
    "typescript.implementationsCodeLens.enabled": true,
    "editor.trimAutoWhitespace": true,
    "files.encoding": "utf8",
    "files.trimFinalNewlines": true,
    "files.trimTrailingWhitespace": true,
    "eslint.validate": ["javascript", "typescript"],
    "[javascript]": {
    "editor.formatOnSave": false,
    "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
    }
    },
    "[typescript]": {
    "editor.formatOnSave": false,
    "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
    }
    }
    }
  4. vdelacou revised this gist Apr 25, 2021. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -17,9 +17,9 @@ npx json -I -f package.json -e 'this.scripts={...this.scripts , "start": "ts-nod
    npm install winston
    npm install --save-dev @types/node
    mkdir src
    curl -o src/example.ts https://gist.githubusercontent.com/vdelacou/58484f1c11af70aaa457f4e5c289e893/raw/example.ts
    curl -o .eslintrc.json https://gist.githubusercontent.com/vdelacou/58484f1c11af70aaa457f4e5c289e893/raw/.eslintrc.json
    curl -o tsconfig.json https://gist.githubusercontent.com/vdelacou/58484f1c11af70aaa457f4e5c289e893/raw/tsconfig.json
    curl -o src/example.ts https://gist.githubusercontent.com/vdelacou/996f290aa5d108b55688229e15ff4b3b/raw/example.ts
    curl -o .eslintrc.json https://gist.githubusercontent.com/vdelacou/996f290aa5d108b55688229e15ff4b3b/raw/.eslintrc.json
    curl -o tsconfig.json https://gist.githubusercontent.com/vdelacou/996f290aa5d108b55688229e15ff4b3b/raw/tsconfig.json
    ```


  5. vdelacou created this gist Apr 25, 2021.
    24 changes: 24 additions & 0 deletions .eslintrc.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    {
    "env": {
    "node": true,
    "es2020": true
    },
    "extends": [
    "plugin:prettier/recommended",
    "plugin:@typescript-eslint/eslint-recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:@typescript-eslint/recommended-requiring-type-checking",
    "prettier"
    ],
    "globals": {
    "Atomics": "readonly",
    "SharedArrayBuffer": "readonly"
    },
    "parser": "@typescript-eslint/parser",
    "parserOptions": {
    "sourceType": "module",
    "project": "./tsconfig.json"
    },
    "plugins": ["@typescript-eslint", "prettier"],
    "rules": {}
    }
    25 changes: 25 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    # How to install a typescript project

    `npm init private`

    ```
    curl -o .gitignore https://gist.githubusercontent.com/vdelacou/1954a25d720f702b4af011ba2773001b/raw/.gitignore
    curl -o .prettierrc https://gist.githubusercontent.com/vdelacou/58484f1c11af70aaa457f4e5c289e893/raw/.prettierrc
    mkdir .vscode
    curl -o .vscode/extensions.json https://gist.githubusercontent.com/vdelacou/c5f3fd74c5e836706c0adaeb0d383bd0/raw/extensions.json
    curl -o .vscode/settings.json https://gist.githubusercontent.com/vdelacou/c5f3fd74c5e836706c0adaeb0d383bd0/raw/settings.json
    curl -o .editorconfig https://gist.githubusercontent.com/vdelacou/58484f1c11af70aaa457f4e5c289e893/raw/.editorconfig
    npm install --save-dev typescript ts-node eslint @typescript-eslint/eslint-plugin @typescript-eslint/parser prettier eslint-config-prettier eslint-plugin-prettier
    npm install husky --save-dev
    npx json -I -f package.json -e 'this.husky={"hooks":{"pre-commit": "npm run lint","pre-push": "npm run lint"}}'
    npx json -I -f package.json -e 'this.scripts={...this.scripts , "lint": "eslint . --ext .js,.ts" }'
    npx json -I -f package.json -e 'this.scripts={...this.scripts , "start": "ts-node ./src/example.ts" }'
    npm install winston
    npm install --save-dev @types/node
    mkdir src
    curl -o src/example.ts https://gist.githubusercontent.com/vdelacou/58484f1c11af70aaa457f4e5c289e893/raw/example.ts
    curl -o .eslintrc.json https://gist.githubusercontent.com/vdelacou/58484f1c11af70aaa457f4e5c289e893/raw/.eslintrc.json
    curl -o tsconfig.json https://gist.githubusercontent.com/vdelacou/58484f1c11af70aaa457f4e5c289e893/raw/tsconfig.json
    ```


    19 changes: 19 additions & 0 deletions example.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    import winston from 'winston';

    const logger = winston.createLogger({ transports: [new winston.transports.Console()] });

    const delay = (milliseconds: number, count: number): Promise<number> => {
    return new Promise((resolve) => {
    setTimeout(() => {
    resolve(count);
    }, milliseconds);
    });
    };

    (async () => {
    logger.info('Start');
    const count = await delay(1000, 2);
    logger.info(`End with count: ${count}`);
    })().catch((e) => {
    logger.error(e);
    });
    16 changes: 16 additions & 0 deletions tsconfig.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    {
    "compilerOptions": {
    "target": "ES2020",
    "module": "commonjs",
    "lib": ["ES2020"],
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictBindCallApply": true,
    "strictPropertyInitialization": true,
    "noImplicitThis": true,
    "alwaysStrict": true,
    "esModuleInterop": true
    }
    }