From 9d124e72793ffc1c2e4a5715d2468d8b2a611bca Mon Sep 17 00:00:00 2001 From: Charlie Li Date: Mon, 15 Feb 2021 17:35:08 +0800 Subject: [PATCH] Initial commit --- .commitlintrc.json | 28 +++++++ .env | 0 .eslintignore | 2 + .eslintrc.js | 61 ++++++++++++++ .gitignore | 103 ++++++++++++++++++++++++ .npmignore | 8 ++ .prettierrc | 9 +++ .vscode/settings.json | 17 ++++ .vscode/tasks.json | 18 +++++ .yarnclean | 34 ++++++++ README.md | 0 jest.config.js | 183 ++++++++++++++++++++++++++++++++++++++++++ package.json | 90 +++++++++++++++++++++ postman/README.md | 0 resources/README.md | 0 src/index.ts | 0 tsconfig.json | 86 ++++++++++++++++++++ tsconfig.test.json | 6 ++ 18 files changed, 645 insertions(+) create mode 100644 .commitlintrc.json create mode 100644 .env create mode 100644 .eslintignore create mode 100644 .eslintrc.js create mode 100644 .gitignore create mode 100644 .npmignore create mode 100644 .prettierrc create mode 100644 .vscode/settings.json create mode 100644 .vscode/tasks.json create mode 100644 .yarnclean create mode 100644 README.md create mode 100644 jest.config.js create mode 100644 package.json create mode 100644 postman/README.md create mode 100644 resources/README.md create mode 100644 src/index.ts create mode 100644 tsconfig.json create mode 100644 tsconfig.test.json diff --git a/.commitlintrc.json b/.commitlintrc.json new file mode 100644 index 0000000..5c5e64d --- /dev/null +++ b/.commitlintrc.json @@ -0,0 +1,28 @@ +{ + "extends": ["@commitlint/config-angular"], + "rules": { + "subject-case": [ + 2, + "always", + ["sentence-case", "start-case", "pascal-case", "upper-case", "lower-case"] + ], + "type-enum": [ + 2, + "always", + [ + "build", + "chore", + "ci", + "docs", + "feat", + "fix", + "perf", + "refactor", + "revert", + "style", + "test", + "sample" + ] + ] + } +} diff --git a/.env b/.env new file mode 100644 index 0000000..e69de29 diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..2a8faf1 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,2 @@ +node_modules/** +dist/** diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..024145c --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,61 @@ +module.exports = { + parser: '@typescript-eslint/parser', + parserOptions: { + ecmaVersion: 2019, + sourceType: 'module', + }, + plugins: ['@typescript-eslint/eslint-plugin', 'simple-import-sort'], + extends: [ + 'plugin:@typescript-eslint/recommended', + 'prettier/@typescript-eslint', + 'plugin:prettier/recommended', + ], + ignorePatterns: ['node_modules/**', 'dist/**'], + root: true, + env: { + node: true, + jest: true, + }, + rules: { + '@typescript-eslint/interface-name-prefix': 'off', + '@typescript-eslint/explicit-function-return-type': 'off', + '@typescript-eslint/explicit-module-boundary-types': 'off', + '@typescript-eslint/no-explicit-any': 'off', + 'simple-import-sort/imports': 'error', + 'simple-import-sort/exports': 'error', + '@typescript-eslint/ban-ts-comment': 'off', + '@typescript-eslint/no-empty-interface': 'off', + 'quote-props': ['error', 'as-needed', { keywords: false }], + curly: ['error', 'multi-line'], + 'max-classes-per-file': 'off', + 'comma-dangle': ['error', 'never'], + '@typescript-eslint/explicit-member-accessibility': ['error', { accessibility: 'no-public' }], + 'arrow-parens': ['error', 'as-needed'], + semi: ['error', 'never'], + '@typescript-eslint/semi': ['error', 'never'], + 'object-shorthand': ['error', 'always'], + '@typescript-eslint/member-delimiter-style': [ + 'error', + { + multiline: { + delimiter: 'none', + requireLast: false + }, + singleline: { + delimiter: 'semi', + requireLast: false + } + } + ], + 'no-use-before-define': 'off', + '@typescript-eslint/no-use-before-define': 'off', + '@typescript-eslint/no-explicit-any': 'off', + "no-unused-vars": "off", + "@typescript-eslint/no-unused-vars": ["error", { + "vars": "all", + "args": "after-used", + "ignoreRestSiblings": false, + "argsIgnorePattern": "^_" + }] + }, +}; diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e86c257 --- /dev/null +++ b/.gitignore @@ -0,0 +1,103 @@ +/backup + +# compiled output +dist +node_modules + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# OS +.DS_Store + +# Tests +coverage +/.coverage +/.nyc_output + +# IDEs and editors +/.idea +.project +.classpath +.c9/ +*.launch +.settings/ +*.sublime-workspace + +# IDE - VSCode +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + +# Do not checking npm package lock files -- use package.json +package-lock.json +yarn.lock + +# Runtime data +pids +*.pid +*.seed +*.pid. + +# Do not checking npm package lock files -- use package.json +package-lock.json + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +tsconfig.tsbuildinfo + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Unit test code coverage +coverage +lcov.info +*.code-workspace +*.iml + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +jspm_packages/ + +# Typescript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Yarn Integrity file +.yarn-integrity \ No newline at end of file diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..1201687 --- /dev/null +++ b/.npmignore @@ -0,0 +1,8 @@ +lib/ +.idea/ +src +tsconfig.json +.eslintrc.js +.eslintignore +.prettierrc.json +create_git_properties.sh diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..8eeff18 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,9 @@ +{ + "trailingComma": "none", + "semi": false, + "bracketSpacing": true, + "arrowParens": "avoid", + "printWidth": 120, + "singleQuote": true, + "useTabs": false +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..461a179 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,17 @@ +// See VS Code settings in https: //code.visualstudio.com/docs/getstarted/settings#_default-settings +{ + "editor.codeActionsOnSave": { + "source.fixAll.eslint": true + }, + "search.exclude": { + "**/node_modules": true, + "**/dist": true + }, + "[typescript]": { + "editor.defaultFormatter": "esbenp.prettier-vscode", + "editor.formatOnSave": true, + "editor.formatOnPaste": true + }, + "typescript.tsdk": "node_modules/typescript/lib", + "typescript.format.semicolons": "remove", +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..42a8180 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,18 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "type": "typescript", + "tsconfig": "tsconfig.json", + "problemMatcher": [ + "$tsc" + ], + "group": { + "kind": "build", + "isDefault": true + } + } + ] +} diff --git a/.yarnclean b/.yarnclean new file mode 100644 index 0000000..f8e0e95 --- /dev/null +++ b/.yarnclean @@ -0,0 +1,34 @@ +# test directories +__tests__ +test +tests +powered-test + +# code coverage directories +coverage +.nyc_output + +# build scripts +Makefile +Gulpfile.js +Gruntfile.js + +# configs +appveyor.yml +circle.yml +codeship-services.yml +codeship-steps.yml +wercker.yml +.tern-project +.gitattributes +.editorconfig +.*ignore +.eslintrc +.jshintrc +.flowconfig +.documentup.json +.yarn-metadata.json +.travis.yml + +# misc +*.md \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000..2837148 --- /dev/null +++ b/jest.config.js @@ -0,0 +1,183 @@ +/* + * For a detailed explanation regarding each configuration property and type check, visit: + * https://jestjs.io/docs/en/configuration.html + */ + +module.exports = { + // All imported modules in your tests should be mocked automatically + // automock: false, + + // Stop running tests after `n` failures + // bail: 0, + + // The directory where Jest should store its cached dependency information + // cacheDirectory: "/private/var/folders/_q/02b48r7941l2zg3k7cfv0c040000gn/T/jest_dx", + + // Automatically clear mock calls and instances between every test + clearMocks: true, + + // Indicates whether the coverage information should be collected while executing the test + collectCoverage: true, + + // An array of glob patterns indicating a set of files for which coverage information should be collected + collectCoverageFrom: ['**/*.ts', '!src/**/*.spec.ts'], + + // The directory where Jest should output its coverage files + coverageDirectory: './coverage', + + // An array of regexp pattern strings used to skip coverage collection + // coveragePathIgnorePatterns: [ + // "/node_modules/" + // ], + + // Indicates which provider should be used to instrument code for coverage + // coverageProvider: "babel", + + // A list of reporter names that Jest uses when writing coverage reports + coverageReporters: ['lcov'], + + // An object that configures minimum threshold enforcement for coverage results + // coverageThreshold: undefined, + + // A path to a custom dependency extractor + // dependencyExtractor: undefined, + + // Make calling deprecated APIs throw helpful error messages + // errorOnDeprecated: false, + + // Force coverage collection from ignored files using an array of glob patterns + // forceCoverageMatch: [], + + // A path to a module which exports an async function that is triggered once before all test suites + // globalSetup: undefined, + + // A path to a module which exports an async function that is triggered once after all test suites + // globalTeardown: undefined, + + // A set of global variables that need to be available in all test environments + globals: { + 'ts-jest': { + tsConfig: 'tsconfig.test.json' + // 'enableTsDiagnostics': true + } + }, + + // The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers. + // maxWorkers: "50%", + + // An array of directory names to be searched recursively up from the requiring module's location + // moduleDirectories: [ + // "node_modules" + // ], + + // An array of file extensions your modules use + moduleFileExtensions: ['js', 'json', 'jsx', 'ts', 'tsx', 'node'], + + // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module + // moduleNameMapper: {}, + + // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader + modulePathIgnorePatterns: ['/dist'], + + // Activates notifications for test results + // notify: false, + + // An enum that specifies notification mode. Requires { notify: true } + // notifyMode: "failure-change", + + // A preset that is used as a base for Jest's configuration + // preset: undefined, + + // Run tests from one or more projects + // projects: undefined, + + // Use this configuration option to add custom reporters to Jest + // reporters: undefined, + + // Automatically reset mock state between every test + // resetMocks: false, + + // Reset the module registry before running each individual test + // resetModules: false, + + // A path to a custom resolver + // resolver: undefined, + + // Automatically restore mock state between every test + // restoreMocks: false, + + // The root directory that Jest should scan for tests and modules within + // rootDir: 'src', + + // A list of paths to directories that Jest should use to search for files in + roots: ['./'], + + // Allows you to use a custom runner instead of Jest's default test runner + // runner: "jest-runner", + + // The paths to modules that run some code to configure or set up the testing environment before each test + // setupFiles: [], + + // A list of paths to modules that run some code to configure or set up the testing framework before each test + // setupFilesAfterEnv: [], + + // The number of seconds after which a test is considered as slow and reported as such in the results. + // slowTestThreshold: 5, + + // A list of paths to snapshot serializer modules Jest should use for snapshot testing + // snapshotSerializers: [], + + // The test environment that will be used for testing + testEnvironment: 'node', + + // Options that will be passed to the testEnvironment + // testEnvironmentOptions: {}, + + // Adds a location field to test results + // testLocationInResults: false, + + // The glob patterns Jest uses to detect test files + // testMatch: [ + // "**/__tests__/**/*.[jt]s?(x)", + // "**/?(*.)+(spec|test).[tj]s?(x)" + // ], + + // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped + testPathIgnorePatterns: ['/node_modules/', '/dist/'], + + // The regexp pattern or array of patterns that Jest uses to detect test files + testRegex: '.spec.ts$', + + // This option allows the use of a custom results processor + // testResultsProcessor: undefined, + + // This option allows use of a custom test runner + // testRunner: "jasmine2", + + // This option sets the URL for the jsdom environment. It is reflected in properties such as location.href + testURL: 'http://localhost', + + // Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout" + // timers: "real", + + // A map from regular expressions to paths to transformers + 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: [ + // "/node_modules/", + // "\\.pnp\\.[^\\/]+$" + // ], + + // An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them + // unmockedModulePathPatterns: undefined, + + // Indicates whether each individual test should be reported during the run + // verbose: undefined, + + // An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode + // watchPathIgnorePatterns: [], + + // Whether to use watchman for file crawling + // watchman: true, +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..7a13144 --- /dev/null +++ b/package.json @@ -0,0 +1,90 @@ +{ + "name": "service-template", + "version": "0.0.1", + "private": true, + "description": "", + "keywords": [], + "author": "Charlie Li ", + "license": "ISC", + "publishConfig": { + "registry": "https://xxx/api/npm/npm-local" + }, + "repository": { + "type": "git", + "url": "https://github.com/CCharlieLi/service-template.git" + }, + "main": "dist/index.js", + "types": "dist/index.d.ts", + "scripts": { + "compile": "tsc -b", + "compile:watch": "tsc -w -p .", + "clean": "rimraf dist coverage tsconfig.tsbuildinfo yarn.lock package-lock.json .nyc_output", + "lint": "eslint . --ext .ts", + "lint:fix": "eslint . --ext .ts --fix", + "prettier": "prettier --write '{src,test,resources}/**/*.{ts,json,md}'", + "test": "yarn lint:fix && jest --passWithNoTests --collect-coverage", + "prepublishOnly": "yarn test && yarn lint", + "preversion": "yarn lint" + }, + "husky": { + "hooks": { + "post-commit": "git update-index --again", + "pre-commit": "lint-staged", + "pre-push": "yarn compile && yarn test", + "commit-msg": "commitlint -c .commitlintrc.json -E HUSKY_GIT_PARAMS" + } + }, + "lint-staged": { + "./src/**/*.ts": [ + "yarn prettier", + "yarn lint" + ] + }, + "jest": { + "modulePathIgnorePatterns": [ + "./dist" + ] + }, + "dependencies": {}, + "devDependencies": { + "@types/accept-language-parser": "1.5.1", + "@types/bluebird": "3.5.33", + "@types/body-parser": "1.19.0", + "@types/compression": "1.0.1", + "@types/cors": "2.8.6", + "@types/express": "4.17.3", + "@types/fs-extra": "8.0.1", + "@types/helmet": "0.0.45", + "@types/intl": "1.2.0", + "@types/ioredis": "4.16.4", + "@types/jest": "~25.1.4", + "@types/jsonwebtoken": "8.3.8", + "@types/morgan": "1.9.0", + "@types/node": "~10.14.22", + "@types/node-fetch": "~2.5.5", + "@types/request": "2.48.5", + "@types/supertest": "~2.0.8", + "@types/utf8": "2.1.6", + "@types/uuid": "3.4.6", + "@types/vitalsigns": "0.4.3", + "@types/xml2js": "0.4.5", + "@typescript-eslint/eslint-plugin": "~2.23.0", + "@typescript-eslint/parser": "~2.23.0", + "dotenv": "~8.2.0", + "eslint": "~6.8.0", + "eslint-config-prettier": "~6.10.0", + "eslint-plugin-prettier": "~3.1.2", + "eslint-plugin-simple-import-sort": "^7.0.0", + "husky": "~4.2.3", + "jest": "~25.1.0", + "lint-staged": "10.0.8", + "nock": "~11.7.0", + "nockback-harder": "~4.0.1", + "prettier": "~1.19.1", + "supertest": "~4.0.2", + "ts-jest": "~25.2.1", + "ts-mockery": "^1.2.0", + "ts-node": "8.5.0", + "typescript": "3.8.3" + } +} diff --git a/postman/README.md b/postman/README.md new file mode 100644 index 0000000..e69de29 diff --git a/resources/README.md b/resources/README.md new file mode 100644 index 0000000..e69de29 diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..e69de29 diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..f1ee398 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,86 @@ +{ + "exclude": [ + "node_modules", + "dist", + "**/__mocks__/*", + "**/__test__/*", + "**/*.spec.ts", + "**/*.ispec.ts" + ], + "include": [ + "src/**/*" + ], + "compileOnSave": false, + "buildOnSave": false, + "compilerOptions": { + /* Visit https://aka.ms/tsconfig.json to read more about this file */ + /* Basic Options */ + "incremental": true, /* Enable incremental compilation */ + "target": "ES2019", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ + "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ + "lib": [ + "ES2019" + ], /* Specify library files to be included in the compilation. */ + // "allowJs": true, /* Allow javascript files to be compiled. */ + // "checkJs": true, /* Report errors in .js files. */ + // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ + "declaration": true, /* Generates corresponding '.d.ts' file. */ + // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ + "sourceMap": true, /* Generates corresponding '.map' file. */ + // "outFile": "./", /* Concatenate and emit output to single file. */ + "outDir": "./dist", /* Redirect output structure to the directory. */ + // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ + // "composite": true, /* Enable project compilation */ + // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ + "removeComments": true, /* Do not emit comments to output. */ + // "noEmit": true, /* Do not emit outputs. */ + // "importHelpers": true, /* Import emit helpers from 'tslib'. */ + // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ + // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ + /* Strict Type-Checking Options */ + "strict": true, /* Enable all strict type-checking options. */ + "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ + "strictNullChecks": true, /* Enable strict null checks. */ + // "strictFunctionTypes": true, /* Enable strict checking of function types. */ + // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ + "strictPropertyInitialization": false, /* Enable strict checking of property initialization in classes. */ + "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ + "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + /* Additional Checks */ + "noUnusedLocals": true, /* Report errors on unused locals. */ + "noUnusedParameters": true, /* Report errors on unused parameters. */ + "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + /* Module Resolution Options */ + "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ + // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ + // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ + // "typeRoots": [], /* List of folders to include type definitions from. */ + // "types": [ + // "reflect-metadata", + // "swagger-express-ts" + // ], /* Type declaration files to be included in compilation. */ + "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "allowUnreachableCode": false, + "allowUnusedLabels": false, + "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ + // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + /* Source Map Options */ + // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ + // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ + /* Experimental Options */ + "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ + "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + /* Advanced Options */ + "skipLibCheck": true, /* Skip type checking of declaration files. */ + "forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */ + "noEmitOnError": true, + "pretty": true, + "resolveJsonModule": true + } +} \ No newline at end of file diff --git a/tsconfig.test.json b/tsconfig.test.json new file mode 100644 index 0000000..b8173c0 --- /dev/null +++ b/tsconfig.test.json @@ -0,0 +1,6 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "types": ["reflect-metadata", "jest"] + } + } \ No newline at end of file