From 2c7cf6780987b492618699e534b7bd6b66b65a9a Mon Sep 17 00:00:00 2001 From: Marcos Passos Date: Wed, 23 Oct 2024 12:28:48 -0600 Subject: [PATCH] Initial commit --- .codeclimate.yml | 31 +++++ .eslintrc.js | 10 ++ .github/CODEOWNERS | 5 + .github/ISSUE_TEMPLATE/bug-report.md | 24 ++++ .github/ISSUE_TEMPLATE/config.yml | 1 + .github/ISSUE_TEMPLATE/feature-request.md | 20 ++++ .github/pull_request_template.md | 18 +++ .github/release-drafter.yml | 34 ++++++ .github/workflows/branch-validations.yaml | 108 ++++++++++++++++++ .github/workflows/check-required-labels.yaml | 19 +++ .../workflows/deploy-published-releases.yaml | 56 +++++++++ .github/workflows/release-drafter.yaml | 17 +++ .github/workflows/send-guidelines.yaml | 30 +++++ .github/workflows/update-release-notes.yaml | 17 +++ .gitignore | 3 + README.md | 103 +++++++++++++++++ jest.config.js | 8 ++ package.json | 47 ++++++++ renovate.json | 5 + src/.gitkeep | 0 test/.gitkeep | 0 test/jestExtended.d.ts | 1 + tsconfig.build.json | 13 +++ tsconfig.json | 28 +++++ 24 files changed, 598 insertions(+) create mode 100644 .codeclimate.yml create mode 100644 .eslintrc.js create mode 100644 .github/CODEOWNERS create mode 100644 .github/ISSUE_TEMPLATE/bug-report.md create mode 100644 .github/ISSUE_TEMPLATE/config.yml create mode 100644 .github/ISSUE_TEMPLATE/feature-request.md create mode 100644 .github/pull_request_template.md create mode 100644 .github/release-drafter.yml create mode 100644 .github/workflows/branch-validations.yaml create mode 100644 .github/workflows/check-required-labels.yaml create mode 100644 .github/workflows/deploy-published-releases.yaml create mode 100644 .github/workflows/release-drafter.yaml create mode 100644 .github/workflows/send-guidelines.yaml create mode 100644 .github/workflows/update-release-notes.yaml create mode 100644 .gitignore create mode 100644 README.md create mode 100644 jest.config.js create mode 100644 package.json create mode 100644 renovate.json create mode 100644 src/.gitkeep create mode 100644 test/.gitkeep create mode 100644 test/jestExtended.d.ts create mode 100644 tsconfig.build.json create mode 100644 tsconfig.json diff --git a/.codeclimate.yml b/.codeclimate.yml new file mode 100644 index 0000000..2db239d --- /dev/null +++ b/.codeclimate.yml @@ -0,0 +1,31 @@ +version: "2" +checks: + argument-count: + config: + threshold: 4 + complex-logic: + config: + threshold: 4 + file-lines: + config: + threshold: 500 + method-complexity: + config: + threshold: 5 + method-count: + config: + threshold: 30 + method-lines: + config: + threshold: 100 + nested-control-flow: + config: + threshold: 4 + return-statements: + config: + threshold: 4 + identical-code: + config: + threshold: 80 + similar-code: + enabled: false diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..5a28eb0 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,10 @@ +// Workaround for https://github.com/eslint/eslint/issues/3458 +require('@rushstack/eslint-patch/modern-module-resolution'); + +module.exports = { + extends: ['plugin:@croct/typescript'], + plugins: ['@croct'], + parserOptions: { + project: ['**/tsconfig.json'], + }, +}; diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..38bee7c --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,5 @@ +# Default owners +* @croct-tech/js + +# GitHub configurations +/.github/ @croct-tech/infra diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md new file mode 100644 index 0000000..64265fb --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-report.md @@ -0,0 +1,24 @@ +--- +name: "๐Ÿž Bug report" +about: "Create a report to help us improve" +labels: bug +--- + +## ๐Ÿž Bug report +Please describe the problem you are experiencing. + +### Steps to reproduce +Please provide a minimal code snippet and the detailed steps for reproducing the issue. + +1. Step 1 +2. Step 2 +3. Step 3 + +### Expected behavior +Please describe the behavior you are expecting. + +### Screenshots +If applicable, add screenshots to help explain your problem. + +### Additional context +Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions. diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..3ba13e0 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1 @@ +blank_issues_enabled: false diff --git a/.github/ISSUE_TEMPLATE/feature-request.md b/.github/ISSUE_TEMPLATE/feature-request.md new file mode 100644 index 0000000..af795c2 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature-request.md @@ -0,0 +1,20 @@ +--- +name: "โœจ Feature request" +about: "Suggest an idea for this project" +labels: enhancement +--- + +## โœจ Feature request +Please provide a brief explanation of the feature. + +### Motivation +Please share the motivation for the new feature, and what problem it is solving. + +### Example +If the proposal involves a new or changed API, please include a basic code example. + +### Alternatives +Please describe the alternative solutions or features you've considered. + +### Additional context +Please provide any other context or screenshots about the feature request here. diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..c803c20 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,18 @@ +## Summary +Please include a summary of the change and which issue is addressed. + +- Fixes #(issue 1) +- Fixes #(issue 2) +- Fixes #(issue 3) + +### Checklist + +- [ ] My code follows the style guidelines of this project +- [ ] I have performed a self-review of my own code +- [ ] I have commented my code, particularly in hard-to-understand areas +- [ ] I have made corresponding changes to the documentation +- [ ] My changes generate no new warnings +- [ ] I have added tests that prove my fix is effective or that my feature works +- [ ] New and existing unit tests pass locally with my changes +- [ ] Any dependent changes have been merged and published in downstream modules +- [ ] I have checked my code and corrected any misspellings \ No newline at end of file diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml new file mode 100644 index 0000000..513a3e9 --- /dev/null +++ b/.github/release-drafter.yml @@ -0,0 +1,34 @@ +name-template: '$NEXT_PATCH_VERSION' +tag-template: '$NEXT_PATCH_VERSION' +prerelease: true +categories: + - title: '๐Ÿš€ Features' + labels: + - feature + - title: '๐Ÿ”ง Enhancements' + labels: + - enhancement + - title: '๐Ÿž Bug Fixes' + labels: + - bug + - title: '๐Ÿšง Maintenance' + labels: + - maintenance +change-template: '- $TITLE (#$NUMBER), thanks [$AUTHOR](https://github.com/$AUTHOR)!' +sort-by: merged_at +sort-direction: descending +branches: + - master +exclude-labels: + - wontfix + - duplicate + - invalid + - question +no-changes-template: 'This release contains minor changes and bugfixes.' +template: |- + ## What's Changed + + $CHANGES + + ๐ŸŽ‰ **Thanks to all contributors helping with this release:** + $CONTRIBUTORS diff --git a/.github/workflows/branch-validations.yaml b/.github/workflows/branch-validations.yaml new file mode 100644 index 0000000..d9bd019 --- /dev/null +++ b/.github/workflows/branch-validations.yaml @@ -0,0 +1,108 @@ +name: Validations + +on: + push: + tags-ignore: + - '**' + branches: + - master + pull_request: + types: + - synchronize + - opened + +jobs: + security-checks: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 18 + + - name: Cache dependencies + id: cache-dependencies + uses: actions/cache@v4 + with: + path: node_modules + key: node_modules-${{ hashFiles('**/package-lock.json') }} + + - name: Install dependencies + if: steps.cache-dependencies.outputs.cache-hit != 'true' + run: npm ci + + - name: Check dependency vulnerabilities + run: |- + npm i -g npm-audit-resolver@3.0.0-7 + npx check-audit --omit dev + + validate: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 18 + + - name: Cache dependencies + id: cache-dependencies + uses: actions/cache@v4 + with: + path: node_modules + key: node_modules-${{ hashFiles('**/package-lock.json') }} + + - name: Install dependencies + if: steps.cache-dependencies.outputs.cache-hit != 'true' + run: npm ci + + - name: Check compilation errors + run: npm run validate + + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 18 + + - name: Cache dependencies + id: cache-dependencies + uses: actions/cache@v4 + with: + path: node_modules + key: node_modules-${{ hashFiles('**/package-lock.json') }} + + - name: Install dependencies + if: steps.cache-dependencies.outputs.cache-hit != 'true' + run: npm ci + + - name: Check coding standard violations + run: npm run lint + + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 18 + + - name: Cache dependencies + id: cache-dependencies + uses: actions/cache@v4 + with: + path: node_modules + key: node_modules-${{ hashFiles('**/package-lock.json') }} + + - name: Install dependencies + if: steps.cache-dependencies.outputs.cache-hit != 'true' + run: npm ci + + - uses: paambaati/codeclimate-action@v5 + env: + CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} + with: + coverageCommand: npm test + coverageLocations: + ./coverage/lcov.info:lcov diff --git a/.github/workflows/check-required-labels.yaml b/.github/workflows/check-required-labels.yaml new file mode 100644 index 0000000..03984e9 --- /dev/null +++ b/.github/workflows/check-required-labels.yaml @@ -0,0 +1,19 @@ +name: Label requirements +on: + pull_request: + types: + - opened + - synchronize + - reopened + - labeled + - unlabeled + +jobs: + check-labels: + name: Check labels + runs-on: ubuntu-latest + steps: + - uses: docker://agilepathway/pull-request-label-checker:latest + with: + any_of: maintenance,feature,bug,enhancement + repo_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/deploy-published-releases.yaml b/.github/workflows/deploy-published-releases.yaml new file mode 100644 index 0000000..8d479a8 --- /dev/null +++ b/.github/workflows/deploy-published-releases.yaml @@ -0,0 +1,56 @@ +name: Release + +on: + release: + types: + - published + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 18 + registry-url: 'https://npm.pkg.github.com' + + - name: Cache dependencies + id: cache-dependencies + uses: actions/cache@v4 + with: + path: node_modules + key: node_modules-${{ hashFiles('**/package-lock.json') }} + + - name: Install dependencies + if: steps.cache-dependencies.outputs.cache-hit != 'true' + run: |- + echo "//npm.pkg.github.com/:_authToken=${{ secrets.GH_PACKAGES_TOKEN }}" >> ~/.npmrc + npm ci + rm -rf ~/.npmrc + + - name: Build package + run: |- + npm run build + + - name: Prepare release + run: |- + cp package.json LICENSE README.md build/ + cd build + sed -i -e "s~\"version\": \"0.0.0-dev\"~\"version\": \"${GITHUB_REF##*/}\"~" package.json + + - name: Publish pre-release to NPM + if: ${{ github.event.release.prerelease }} + run: |- + cd build + npm publish --tag next + env: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Publish release to NPM + if: ${{ !github.event.release.prerelease }} + run: |- + cd build + npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release-drafter.yaml b/.github/workflows/release-drafter.yaml new file mode 100644 index 0000000..e9103f5 --- /dev/null +++ b/.github/workflows/release-drafter.yaml @@ -0,0 +1,17 @@ +name: Release Drafter + +on: + push: + branches: + - master + tags-ignore: + - '**' + +jobs: + release-draft: + runs-on: ubuntu-latest + steps: + - name: Update release draft + uses: release-drafter/release-drafter@v6 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/send-guidelines.yaml b/.github/workflows/send-guidelines.yaml new file mode 100644 index 0000000..919c5f6 --- /dev/null +++ b/.github/workflows/send-guidelines.yaml @@ -0,0 +1,30 @@ +name: Guidelines + +on: + pull_request: + types: + - opened +jobs: + send-guidelines: + runs-on: ubuntu-latest + steps: + - uses: wow-actions/auto-comment@v1 + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + pullRequestOpened: | + ๐Ÿ‘‹ @{{ author }} + **Thanks for your contribution!** + The approval and merge process is almost fully automated ๐Ÿง™ + Here's how it works: + 1. You open a new pull request + 2. Automated tests check the code + 3. Maintainers review the code + 4. Once approved, the PR is ready to merge. + + > ๐Ÿ‘‰ **Omit the extended description** + > Please remove the commit body before merging the pull request. + > Instead, include the pull request number in the title to provide the full context + > about the change. + + โ˜๏ธ Lastly, the title for the commit will come from the pull request title. So please provide a descriptive title that summarizes the changes in **50 characters or less using the imperative mood.** + Happy coding! ๐ŸŽ‰ \ No newline at end of file diff --git a/.github/workflows/update-release-notes.yaml b/.github/workflows/update-release-notes.yaml new file mode 100644 index 0000000..0bc9171 --- /dev/null +++ b/.github/workflows/update-release-notes.yaml @@ -0,0 +1,17 @@ +name: Release notes + +on: + push: + branches: + - master + tags-ignore: + - '**' + +jobs: + update-notes: + runs-on: ubuntu-latest + steps: + - name: Update release draft + uses: release-drafter/release-drafter@v6 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e19e233 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules/ +build/ +coverage/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..b7b25ac --- /dev/null +++ b/README.md @@ -0,0 +1,103 @@ +

+ + Croct + +
+ TypeScript Project Title +
+ A brief description about the project. +

+

+ Build + Coverage + Maintainability +
+
+ ๐Ÿ“ฆ Releases + ยท + ๐Ÿž Report Bug + ยท + โœจ Request Feature +

+ +# Instructions +Follow the steps below to create a new repository: + +1. Customize the repository + 1. Click on the _Use this template_ button at the top of this page + 2. Clone the repository locally + 3. Update the `README.md` and `package.json` with the new package information +2. Setup Code Climate + 1. Add the project to [Croct's code climate organization](https://codeclimate.com/accounts/5e714648faaa9c00fb000081/dashboard) + 2. Go to **Repo Settings > Test coverage** and copy the "_TEST REPORTER ID_" + 3. Go to **Repo Settings > Badges** and copy the maintainability and coverage badges to the `README.md` + 4. On the Github repository page, go to **Settings > Secrets** and add a secret with name `CC_TEST_REPORTER_ID` and the ID from the previous step as value. + +## Installation +We recommend using [NPM](https://www.npmjs.com) to install the package: + +```sh +npm install @croct/project-ts +``` + +## Basic usage + +```typescript +import {Example} from '@croct/project-ts'; + +const example = new Example(); +example.displayBasicUsage(); +``` + +## Contributing +Contributions to the package are always welcome! + +- Report any bugs or issues on the [issue tracker](https://github.com/croct-tech/project-ts/issues). +- For major changes, please [open an issue](https://github.com/croct-tech/project-ts/issues) first to discuss what you would like to change. +- Please make sure to update tests as appropriate. + +## Testing + +Before running the test suites, the development dependencies must be installed: + +```sh +npm install +``` + +Then, to run all tests: + +```sh +npm run test +``` + +Run the following command to check the code against the style guide: + +```sh +npm run lint +``` + +## Building + +Before building the project, the dependencies must be installed: + +```sh +npm install +``` + +Then, to build the CommonJS module: + +```sh +npm run rollup +``` + +The following command bundles a minified IIFE module for browsers: + +``` +npm run rollup-min +``` + +## License + +Copyright ยฉ 2015-2022 Croct Limited, All Rights Reserved. + +All information contained herein is, and remains the property of Croct Limited. The intellectual, design and technical concepts contained herein are proprietary to Croct Limited s and may be covered by U.S. and Foreign Patents, patents in process, and are protected by trade secret or copyright law. Dissemination of this information or reproduction of this material is strictly forbidden unless prior written permission is obtained from Croct Limited. diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000..be17b5c --- /dev/null +++ b/jest.config.js @@ -0,0 +1,8 @@ +module.exports = { + transform: { + '^.+\\.ts$': '@swc/jest', + }, + setupFilesAfterEnv: ['jest-extended/all'], + restoreMocks: true, + resetMocks: true, +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..0b549b9 --- /dev/null +++ b/package.json @@ -0,0 +1,47 @@ +{ + "name": "@croct/ts-project", + "version": "0.0.0-dev", + "description": "A brief description about the project.", + "author": { + "name": "Croct", + "email": "lib+project-ts@croct.com", + "url": "https://github.com/croct-tech/project-ts" + }, + "license": "UNLICENSED", + "keywords": [ + "croct", + "personalization", + "typescript" + ], + "types": "index.d.ts", + "main": "index.js", + "repository": { + "type": "git", + "url": "git+https://github.com/croct-tech/project-ts.git" + }, + "bugs": { + "url": "https://github.com/croct-tech/project-ts/issues" + }, + "homepage": "https://github.com/croct-tech/project-ts", + "scripts": { + "lint": "eslint 'src/**/*.ts' 'test/**/*.ts'", + "test": "jest -c jest.config.js --coverage", + "validate": "tsc --noEmit", + "build": "tsc -p tsconfig.build.json" + }, + "devDependencies": { + "@croct/eslint-plugin": "^0.7.0", + "@swc/jest": "^0.2.24", + "@types/jest": "^29.0.0", + "@typescript-eslint/parser": "^8.0.0", + "eslint": "^9.0.0", + "jest": "^29.0.0", + "jest-extended": "^4.0.0", + "ts-node": "^10.8.2", + "typescript": "^5.0.0" + }, + "files": [ + "**/*.js", + "**/*.ts" + ] +} diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..8ac14db --- /dev/null +++ b/renovate.json @@ -0,0 +1,5 @@ +{ + "extends": [ + "github>croct-tech/renovate-presets:js" + ] +} diff --git a/src/.gitkeep b/src/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/test/.gitkeep b/test/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/test/jestExtended.d.ts b/test/jestExtended.d.ts new file mode 100644 index 0000000..9e6c1db --- /dev/null +++ b/test/jestExtended.d.ts @@ -0,0 +1 @@ +import 'jest-extended'; diff --git a/tsconfig.build.json b/tsconfig.build.json new file mode 100644 index 0000000..8978d8b --- /dev/null +++ b/tsconfig.build.json @@ -0,0 +1,13 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "noEmit": false, + "rootDir": "src", + "outDir": "build" + }, + "exclude": [ + "node_modules", + "build", + "**/*.test.ts" + ] +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..dbfa77a --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,28 @@ +{ + "compilerOptions": { + "module": "CommonJS", + "target": "ES2020", + "esModuleInterop": true, + "moduleResolution": "Node", + "stripInternal": true, + "allowSyntheticDefaultImports": true, + "resolveJsonModule": true, + "noImplicitAny": true, + "noFallthroughCasesInSwitch": true, + "noImplicitReturns": true, + "noImplicitThis": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "strictNullChecks": true, + "removeComments": false, + "noEmit": true, + "downlevelIteration": true, + "declaration": true, + "lib": ["es6"] + }, + "include": [ + "src/**/*.ts", + "test/**/*.ts" + ], + "exclude": ["node_modules", "build"] +}