diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..516cf662 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,18 @@ +# EditorConfig is awesome: https://EditorConfig.org + +# top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +end_of_line = lf +insert_final_newline = true +max_line_length = 80 + +[*.{json,md,yml}] +indent_style = space +indent_size = 2 + +[*.{ts,js}] +indent_style = space +indent_size = 4 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 85ec50d7..b5fe1009 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -7,16 +7,16 @@ jobs: matrix: node-version: [12.x] steps: - - uses: actions/checkout@v2 - - name: Install Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - uses: actions/cache@v2 - with: - path: ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- - - run: npm ci - - run: npm run lint-check-only + - uses: actions/checkout@v2 + - name: Install Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - uses: actions/cache@v2 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + - run: npm ci + - run: npm run lint-check-only diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 43f22370..7db97d02 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -7,56 +7,56 @@ jobs: matrix: node-version: [12.x] steps: - - uses: actions/checkout@v2 - - name: Install Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - uses: actions/cache@v2 - id: npm-cache - with: - path: ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- - - run: npm ci - - run: npm run test + - uses: actions/checkout@v2 + - name: Install Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - uses: actions/cache@v2 + id: npm-cache + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + - run: npm ci + - run: npm run test build: runs-on: ubuntu-latest strategy: matrix: node-version: [12.x] steps: - - uses: actions/checkout@v2 - - name: Install Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - uses: actions/cache@v2 - with: - path: ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- - - run: npm ci - - run: npm run lint + - uses: actions/checkout@v2 + - name: Install Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - uses: actions/cache@v2 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + - run: npm ci + - run: npm run lint docs: runs-on: ubuntu-latest strategy: matrix: node-version: [12.x] steps: - - uses: actions/checkout@v2 - - name: Install Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - uses: actions/cache@v2 - with: - path: ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- - - run: npm ci - - run: npm run build:doc - - run: git diff-files --ignore-all-space --name-only --exit-code + - uses: actions/checkout@v2 + - name: Install Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - uses: actions/cache@v2 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + - run: npm ci + - run: npm run build:doc + - run: git diff-files --ignore-all-space --name-only --exit-code diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..3a13445f --- /dev/null +++ b/.prettierignore @@ -0,0 +1,4 @@ +package-lock.json +doc/ +dist/ +coverage/ diff --git a/.prettierrc.js b/.prettierrc.js index 4a129dab..032a5f9a 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -1,20 +1,4 @@ module.exports = { - printWidth: 80, semi: false, trailingComma: "all", - tabWidth: 4, - overrides: [ - { - files: ["*.json"], - options: { - tabWidth: 2, - }, - }, - { - files: "*.md", - options: { - tabWidth: 2, - }, - }, - ], } diff --git a/README.md b/README.md index 7296b296..f142dfee 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,12 @@ Within the project root directory: npm install ``` +### Format Code Files + +```shell +npm run formatcode +``` + ### Run Linter ```shell diff --git a/package-lock.json b/package-lock.json index dd4d8af4..4ae8063f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4493,9 +4493,9 @@ } }, "node_modules/prettier": { - "version": "2.6.2", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.6.2.tgz", - "integrity": "sha512-PkUpF+qoXTqhOeWL9fu7As8LXsIUZ1WYaJiY/a7McAQzxjk82OF0tibkFXVCDImZtWxbvojFjerkiLb0/q8mew==", + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz", + "integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==", "dev": true, "bin": { "prettier": "bin-prettier.js" @@ -9085,9 +9085,9 @@ "dev": true }, "prettier": { - "version": "2.6.2", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.6.2.tgz", - "integrity": "sha512-PkUpF+qoXTqhOeWL9fu7As8LXsIUZ1WYaJiY/a7McAQzxjk82OF0tibkFXVCDImZtWxbvojFjerkiLb0/q8mew==", + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz", + "integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==", "dev": true }, "prettier-linter-helpers": { diff --git a/package.json b/package.json index fbdb9870..e8a64d65 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "build": "tsc --build", "build:doc": "rimraf doc && typedoc src/index.ts", "build:release": "rimraf dist && rollup -c", + "formatcode": "prettier --write .", "lint": "tsc && eslint --fix 'src/**'", "lint-check-only": "tsc && eslint 'src/**'", "test": "jest --coverage", diff --git a/rollup.config.js b/rollup.config.js index 2e563973..7a170201 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,62 +1,61 @@ -import path from "path"; -import resolve from "@rollup/plugin-node-resolve"; -import typescript from "@rollup/plugin-typescript"; -import { terser } from "rollup-plugin-terser"; -import license from "rollup-plugin-license"; -import sizes from "rollup-plugin-sizes"; +import path from "path" +import resolve from "@rollup/plugin-node-resolve" +import typescript from "@rollup/plugin-typescript" +import { terser } from "rollup-plugin-terser" +import license from "rollup-plugin-license" +import sizes from "rollup-plugin-sizes" -const __dirname = path.resolve(); -const extensions = [".ts", ".js"]; +const __dirname = path.resolve() +const extensions = [".ts", ".js"] const commonPlugins = [ terser({ - output: { - comments: false - } + output: { + comments: false, + }, }), license({ - banner: { - content: { - file: "LICENSE_TEMPLATE" - } - } + banner: { + content: { + file: "LICENSE_TEMPLATE", + }, + }, }), - sizes() -]; + sizes(), +] export default [ - { - input: "./src/index.ts", - plugins: [ - resolve({ extensions }), - typescript({ - target: "es5", - composite: false - }), - ...commonPlugins - ], - output: { - dir: path.resolve(__dirname, "dist"), - format: "umd", - name: "openinsights" - } - }, - { - input: "./src/index.ts", - plugins: [ - resolve({ extensions }), - typescript({ - declaration: true, - composite: false, - declarationDir: path.resolve(__dirname, "dist", "esm", "types"), - outDir: path.resolve(__dirname, "dist", "esm"), - rootDir: path.resolve(__dirname, "src") - }), - ...commonPlugins - ], - output: { - dir: path.resolve(__dirname, "dist", "esm"), - format: "es" - } - } -]; - + { + input: "./src/index.ts", + plugins: [ + resolve({ extensions }), + typescript({ + target: "es5", + composite: false, + }), + ...commonPlugins, + ], + output: { + dir: path.resolve(__dirname, "dist"), + format: "umd", + name: "openinsights", + }, + }, + { + input: "./src/index.ts", + plugins: [ + resolve({ extensions }), + typescript({ + declaration: true, + composite: false, + declarationDir: path.resolve(__dirname, "dist", "esm", "types"), + outDir: path.resolve(__dirname, "dist", "esm"), + rootDir: path.resolve(__dirname, "src"), + }), + ...commonPlugins, + ], + output: { + dir: path.resolve(__dirname, "dist", "esm"), + format: "es", + }, + }, +] diff --git a/setupJest.js b/setupJest.js index 2bf59e07..e696725a 100644 --- a/setupJest.js +++ b/setupJest.js @@ -1 +1 @@ -require('jest-fetch-mock').enableMocks() +require("jest-fetch-mock").enableMocks() diff --git a/tsconfig.json b/tsconfig.json index 3c14b632..ecb4cd71 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,23 +1,19 @@ { - "compilerOptions": { - "target": "es5", - "composite": true, - "rootDir": "src", - "outDir": "dist", - "lib": ["DOM", "ES2015", "ES2020"], - "module": "es6", - "moduleResolution": "node", - "strict": true, - "esModuleInterop": true, - "forceConsistentCasingInFileNames": true, - "declaration": true, - "declarationDir": "dist/types", - "declarationMap": true - }, - "include": ["src/**/*"], - "exclude": [ - "dist", - "**/*.test.ts", - "src/testUtil" - ] + "compilerOptions": { + "target": "es5", + "composite": true, + "rootDir": "src", + "outDir": "dist", + "lib": ["DOM", "ES2015", "ES2020"], + "module": "es6", + "moduleResolution": "node", + "strict": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "declaration": true, + "declarationDir": "dist/types", + "declarationMap": true + }, + "include": ["src/**/*"], + "exclude": ["dist", "**/*.test.ts", "src/testUtil"] }