├── .devcontainer └── devcontainer.json ├── .eslintrc.jest.yml ├── .eslintrc.production.yml ├── .eslintrc.react.yml ├── .eslintrc.typescript.yml ├── .eslintrc.yml ├── .github ├── ISSUE_TEMPLATE │ ├── bug.yml │ └── config.yml ├── pull_request_template.md └── workflows │ ├── bump-dependencies.yml │ ├── bump-scaffold.yml │ ├── continuous-deployment.yml │ ├── list-outdated-dependencies.yml │ ├── prepare-release.yml │ ├── publish-release.yml │ └── pull-request-validation.yml ├── .gitignore ├── .prettierrc.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── package-lock.json ├── package.json └── packages ├── integration-test ├── .eslintrc.custom.yml ├── .eslintrc.yml ├── .gitignore ├── jest.config.json ├── tsconfig.custom.json └── tsconfig.json ├── pages ├── .eslintrc.custom.yml ├── .eslintrc.yml ├── .gitignore └── src │ ├── tsconfig.custom.json │ └── tsconfig.json └── version-from-git ├── .eslintrc.custom.yml ├── .eslintrc.yml ├── .gitignore ├── __tests__ ├── __setup__ │ └── typingTestTransformer.js └── types │ └── .gitignore ├── jest.config.json ├── package.json ├── src ├── index.ts ├── tsconfig.custom.json ├── tsconfig.json ├── tsconfig.precommit.production.json └── tsconfig.precommit.test.json └── tsup.config.ts /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "forwardPorts": [8000], 3 | "image": "mcr.microsoft.com/devcontainers/typescript-node", 4 | "remoteUser": "node", 5 | "updateContentCommand": "npm clean-install && npm run build" 6 | } 7 | -------------------------------------------------------------------------------- /.eslintrc.jest.yml: -------------------------------------------------------------------------------- 1 | env: 2 | commonjs: true 3 | es2021: true 4 | es2022: true 5 | jest: true 6 | rules: 7 | # Disable for convenience 8 | react/display-name: off 9 | # Disable for convenience 10 | react/prop-types: off 11 | '@typescript-eslint/no-require-imports': off 12 | -------------------------------------------------------------------------------- /.eslintrc.production.yml: -------------------------------------------------------------------------------- 1 | extends: 2 | - plugin:import/recommended 3 | plugins: 4 | - import 5 | rules: 6 | import/no-deprecated: error 7 | import/no-empty-named-blocks: error 8 | import/no-extraneous-dependencies: error 9 | import/no-mutable-exports: error 10 | import/no-named-as-default: error 11 | import/no-named-as-default-member: error 12 | import/no-unused-modules: error 13 | import/no-amd: error 14 | import/no-commonjs: error 15 | import/no-absolute-path: error 16 | import/no-cycle: error 17 | import/no-dynamic-require: error 18 | import/no-self-import: error 19 | import/no-useless-path-segments: error 20 | import/no-webpack-loader-syntax: error 21 | import/consistent-type-specifier-style: 22 | - error 23 | - prefer-inline 24 | import/exports-last: error 25 | import/extensions: 26 | - error 27 | - ignorePackages # eslint-plugin-import does not understand named import 28 | import/first: error 29 | import/newline-after-import: error 30 | import/no-anonymous-default-export: error 31 | import/no-duplicates: error 32 | import/no-namespace: error 33 | import/no-unassigned-import: 34 | - error 35 | - allow: 36 | - '**/*.css' 37 | - dotenv/config 38 | settings: 39 | import/extensions: 40 | - .cjs 41 | - .mjs 42 | - .js 43 | - .jsx 44 | - .cts 45 | - .mts 46 | - .ts 47 | - .tsx 48 | import/resolver: 49 | node: true 50 | typescript: true 51 | -------------------------------------------------------------------------------- /.eslintrc.react.yml: -------------------------------------------------------------------------------- 1 | extends: 2 | - plugin:react/recommended 3 | plugins: 4 | - react 5 | -------------------------------------------------------------------------------- /.eslintrc.typescript.yml: -------------------------------------------------------------------------------- 1 | extends: 2 | - plugin:@typescript-eslint/recommended 3 | parser: '@typescript-eslint/parser' 4 | plugins: 5 | - '@typescript-eslint' 6 | rules: 7 | # Shortening if-statement into &&, ||, or ternary operators. 8 | '@typescript-eslint/no-unused-expressions': off 9 | 10 | '@typescript-eslint/no-unused-vars': 11 | - error 12 | - argsIgnorePattern: ^_ 13 | caughtErrorsIgnorePattern: ^_ 14 | destructuredArrayIgnorePattern: ^_ 15 | varsIgnorePattern: ^_ 16 | -------------------------------------------------------------------------------- /.eslintrc.yml: -------------------------------------------------------------------------------- 1 | extends: 2 | - eslint:recommended 3 | overrides: 4 | - extends: .eslintrc.react.yml 5 | files: 6 | - '**/*.jsx' 7 | - '**/*.tsx' 8 | - extends: .eslintrc.typescript.yml 9 | files: 10 | - '**/*.cts' 11 | - '**/*.mts' 12 | - '**/*.ts' 13 | - '**/*.tsx' 14 | - extends: .eslintrc.jest.yml 15 | files: 16 | - '**/__tests__/**' 17 | - '**/*.spec.cjs' 18 | - '**/*.spec.mjs' 19 | - '**/*.spec.js' 20 | - '**/*.spec.jsx' 21 | - '**/*.spec.cts' 22 | - '**/*.spec.mts' 23 | - '**/*.spec.ts' 24 | - '**/*.spec.tsx' 25 | - '**/*.test.cjs' 26 | - '**/*.test.mjs' 27 | - '**/*.test.js' 28 | - '**/*.test.jsx' 29 | - '**/*.test.cts' 30 | - '**/*.test.mts' 31 | - '**/*.test.ts' 32 | - '**/*.test.tsx' 33 | - '**/test/**' 34 | - extends: .eslintrc.production.yml 35 | excludedFiles: 36 | - '**/__tests__/**' 37 | - '**/*.spec.cjs' 38 | - '**/*.spec.mjs' 39 | - '**/*.spec.js' 40 | - '**/*.spec.jsx' 41 | - '**/*.spec.cts' 42 | - '**/*.spec.mts' 43 | - '**/*.spec.ts' 44 | - '**/*.spec.tsx' 45 | - '**/*.test.cjs' 46 | - '**/*.test.mjs' 47 | - '**/*.test.js' 48 | - '**/*.test.jsx' 49 | - '**/*.test.cts' 50 | - '**/*.test.mts' 51 | - '**/*.test.ts' 52 | - '**/*.test.tsx' 53 | - '**/test/**' 54 | files: 55 | - '**/*.cjs' 56 | - '**/*.mjs' 57 | - '**/*.js' 58 | - '**/*.jsx' 59 | - '**/*.cts' 60 | - '**/*.mts' 61 | - '**/*.ts' 62 | - '**/*.tsx' 63 | parserOptions: 64 | ecmaVersion: latest 65 | sourceType: module 66 | plugins: 67 | - prettier 68 | root: true 69 | rules: 70 | prettier/prettier: error 71 | no-empty: 72 | - error 73 | - allowEmptyCatch: true 74 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug.yml: -------------------------------------------------------------------------------- 1 | name: Bug report 2 | description: Use this template to report a bug. 3 | labels: 4 | - bug 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | We run this project out of our spare time and may not monitor this repository every day. Our support capacity is very limited. 10 | 11 | Developers in professional capacity will receive prioritized support. 12 | - type: dropdown 13 | attributes: 14 | label: Version 15 | description: | 16 | Please verify the issue on latest versions. Support on non-latest version is minimal and on a per case basis. 17 | 18 | If you are using latest production, please verify against our latest development version as the issue could have been resolved recently. To install latest development version, run `npm install iter-fest@main`. 19 | 20 | multiple: true 21 | options: 22 | - Latest production (@latest) 23 | - Latest development (@main) 24 | - Not latest 25 | validations: 26 | required: true 27 | - type: textarea 28 | attributes: 29 | label: Test case 30 | description: | 31 | Please write a minimal test case which fail the scenario with comments in [BDD format (given/when/then)](https://www.thoughtworks.com/insights/blog/applying-bdd-acceptance-criteria-user-stories). 32 | 33 | To protect from regressions, once the issue is resolved, your test case will be added to [our test suite](../tree/main/packages/integration-test/). 34 | 35 | For your convenience, a basic test case is provided below. For advanced scenarios, please look at [our test suite](../tree/main/packages/integration-test/). 36 | 37 | *Support will be slow or denied if a test case is not provided.* 38 | render: sh 39 | value: 40 | - type: input 41 | attributes: 42 | label: Coding sandbox URL 43 | description: | 44 | If you have a minimal repro in a coding sandbox, please provide a URL here. Please prepare it from scratch. We cannot work directly on your app source code. 45 | placeholder: 'https://' 46 | - type: textarea 47 | attributes: 48 | label: Console errors 49 | description: Please copy any related errors printed to the console here. 50 | render: js 51 | - type: textarea 52 | attributes: 53 | label: Screenshots 54 | description: Please remove or obscure any personally identifiable information from your screenshots or recordings. 55 | - type: textarea 56 | attributes: 57 | label: Additional context 58 | description: If any of the answers is "others or unrelated", please explain it here. 59 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | ## Changelog 2 | 3 | > Please copy and paste new entries from `CHANGELOG.md` here. 4 | 5 | ## Specific changes 6 | 7 | > Please list each individual specific change in this pull request. 8 | 9 | - -------------------------------------------------------------------------------- /.github/workflows/bump-dependencies.yml: -------------------------------------------------------------------------------- 1 | name: Bump dependencies 2 | 3 | on: 4 | workflow_dispatch: {} 5 | 6 | jobs: 7 | call-workflow: 8 | permissions: 9 | contents: write 10 | id-token: write 11 | secrets: inherit 12 | uses: compulim/workflows/.github/workflows/bump-dependencies.yml@main 13 | with: 14 | package-name: version-from-git 15 | -------------------------------------------------------------------------------- /.github/workflows/bump-scaffold.yml: -------------------------------------------------------------------------------- 1 | name: Bump scaffold 2 | 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | package-name: 7 | default: version-from-git 8 | description: Name of the package 9 | required: true 10 | type: string 11 | use-react: 12 | default: false 13 | description: Use React 14 | required: true 15 | type: boolean 16 | skip-integration-test: 17 | default: false 18 | description: Skip integration test 19 | required: true 20 | type: boolean 21 | 22 | jobs: 23 | call-workflow: 24 | secrets: inherit 25 | uses: compulim/workflows/.github/workflows/bump-scaffold.yml@main 26 | with: 27 | package-name: ${{ inputs.package-name }} 28 | skip-integration-test: ${{ inputs.skip-integration-test }} 29 | use-react: ${{ inputs.use-react }} 30 | -------------------------------------------------------------------------------- /.github/workflows/continuous-deployment.yml: -------------------------------------------------------------------------------- 1 | name: Continuous deployment 2 | 3 | on: 4 | push: 5 | branches: [main] 6 | paths-ignore: 7 | - '.devcontainer/**' 8 | - '.github/**' 9 | workflow_dispatch: {} 10 | 11 | jobs: 12 | call-workflow: 13 | permissions: 14 | attestations: write 15 | contents: write 16 | id-token: write 17 | pages: write 18 | secrets: inherit 19 | uses: compulim/workflows/.github/workflows/continuous-deployment.yml@main 20 | with: 21 | github-pages: false 22 | node-version: 18.x 23 | package-name: version-from-git 24 | -------------------------------------------------------------------------------- /.github/workflows/list-outdated-dependencies.yml: -------------------------------------------------------------------------------- 1 | name: List outdated dependencies 2 | 3 | on: 4 | schedule: 5 | - cron: '0 4 * * 1' 6 | workflow_dispatch: {} 7 | 8 | jobs: 9 | call-workflow: 10 | uses: compulim/workflows/.github/workflows/list-outdated-dependencies.yml@main 11 | -------------------------------------------------------------------------------- /.github/workflows/prepare-release.yml: -------------------------------------------------------------------------------- 1 | name: Prepare release 2 | 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | version-to-bump: 7 | default: patch 8 | description: Version to bump 9 | options: 10 | - major 11 | - minor 12 | - patch 13 | required: true 14 | type: choice 15 | 16 | jobs: 17 | call-workflow: 18 | permissions: 19 | contents: write 20 | id-token: write 21 | secrets: inherit 22 | uses: compulim/workflows/.github/workflows/prepare-release.yml@main 23 | with: 24 | version-to-bump: ${{ inputs.version-to-bump }} 25 | -------------------------------------------------------------------------------- /.github/workflows/publish-release.yml: -------------------------------------------------------------------------------- 1 | name: Publish release 2 | 3 | on: 4 | release: 5 | types: [created] 6 | 7 | jobs: 8 | call-workflow: 9 | permissions: 10 | contents: write 11 | pages: write 12 | id-token: write 13 | secrets: inherit 14 | uses: compulim/workflows/.github/workflows/publish-release.yml@main 15 | with: 16 | package-name: version-from-git 17 | tag: ${{ github.ref_name }} 18 | -------------------------------------------------------------------------------- /.github/workflows/pull-request-validation.yml: -------------------------------------------------------------------------------- 1 | name: Pull request validation 2 | 3 | on: 4 | pull_request: 5 | branches: [main] 6 | workflow_dispatch: {} 7 | 8 | jobs: 9 | call-workflow: 10 | strategy: 11 | matrix: 12 | switch: [current] 13 | uses: compulim/workflows/.github/workflows/pull-request-validation.yml@main 14 | with: 15 | github-pages: false 16 | package-name: version-from-git 17 | project-type: legacy 18 | skip-integration-test: true 19 | switch: ${{ matrix.switch }} 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | -------------------------------------------------------------------------------- /.prettierrc.yml: -------------------------------------------------------------------------------- 1 | arrowParens: avoid 2 | bracketSameLine: false 3 | bracketSpacing: true 4 | endOfLine: auto 5 | printWidth: 120 6 | proseWrap: preserve 7 | quoteProps: as-needed 8 | semi: true 9 | singleQuote: true 10 | tabWidth: 2 11 | trailingComma: none 12 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) 6 | and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). 7 | 8 | ## [Unreleased] 9 | 10 | ### Changed 11 | 12 | - 💢 Moved to ESM only, in PR [#27](https://github.com/compulim/version-from-git/pull/27) 13 | - Ported to TypeScript, in PR [#24](https://github.com/compulim/version-from-git/pull/24) 14 | - Bumped dependencies, in PR [#23](https://github.com/compulim/version-from-git/pull/23) 15 | - Production dependencies 16 | - [`chalk@5.3.0`](https://npmjs.com/package/chalk/v/5.3.0) 17 | - [`commander@12.1.0`](https://npmjs.com/package/commander/v/12.1.0) 18 | - [`cross-spawn@7.0.3`](https://npmjs.com/package/cross-spawn/v/7.0.3) 19 | - [`on-error-resume-next@2.0.1`](https://npmjs.com/package/on-error-resume-next/v/2.0.1) 20 | - [`semver@7.6.2`](https://npmjs.com/package/semver/v/7.6.2) 21 | - Added [ESLint import/export syntax](https://npmjs.com/package/eslint-plugin-import), in PR [#26](https://github.com/compulim/version-from-git/pull/26) 22 | - Added [`publint`](https://npmjs.com/package/publint), in PR [#26](https://github.com/compulim/version-from-git/pull/26) 23 | - Bumped dependencies, in PR [#28](https://github.com/compulim/version-from-git/pull/28) 24 | - Production dependencies 25 | - [`semver@7.6.3`](https://npmjs.com/package/semver/v/7.6.3) 26 | - Development dependencies 27 | - [`@typescript-eslint/eslint-plugin@8.8.1`](https://npmjs.com/package/@typescript-eslint/eslint-plugin/v/8.8.1) 28 | - [`@typescript-eslint/parser@8.8.1`](https://npmjs.com/package/@typescript-eslint/parser/v/8.8.1) 29 | - [`eslint@9.12.0`](https://npmjs.com/package/eslint/v/9.12.0) 30 | - [`eslint-plugin-prettier@5.2.1`](https://npmjs.com/package/eslint-plugin-prettier/v/5.2.1) 31 | - [`eslint-plugin-react@7.37.1`](https://npmjs.com/package/eslint-plugin-react/v/7.37.1) 32 | - [`prettier@3.3.3`](https://npmjs.com/package/prettier/v/3.3.3) 33 | - [`tsup@8.3.0`](https://npmjs.com/package/tsup/v/8.3.0) 34 | 35 | ## [1.1.2] - 2024-05-24 36 | 37 | ### Fixed 38 | 39 | - Resolves [#16](https://github.com/compulim/version-from-git/issues/16). Fixes for Node.js 20, in PR [#17](https://github.com/compulim/version-from-git/pulls/17) and [#18](https://github.com/compulim/version-from-git/pulls/18), by [@evilru](https://github.com/evilru] 40 | 41 | ## [1.1.1] - 2019-08-12 42 | 43 | ### Added 44 | 45 | - Fix [#2](https://github.com/compulim/version-from-git/issues/2). Supports customizing pre-release thru `--template`, in [PR #3](https://github.com/compulim/version-from-git/pulls/3) 46 | 47 | ## [1.0.0] - 2018-05-18 48 | 49 | ### Added 50 | 51 | - Initial commit 52 | 53 | [Unreleased]: https://github.com/compulim/version-from-git/compare/v1.1.2...HEAD 54 | [1.1.2]: https://github.com/compulim/version-from-git/compare/v1.1.1...v1.1.2 55 | [1.1.1]: https://github.com/compulim/version-from-git/compare/v1.0.0...v1.1.1 56 | [1.0.0]: https://github.com/compulim/version-from-git/releases/tag/v1.0.0 57 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 William Wong 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # version-from-git 2 | 3 | [![npm version](https://badge.fury.io/js/version-from-git.svg)](https://badge.fury.io/js/version-from-git) 4 | 5 | # Background 6 | 7 | We want to use `npm version` to bump to a customized version that contains both Git branch and commit hash. 8 | 9 | And use Travis CI to automatically publish the pre-release version to NPM, tagged using [`npm dist-tag`](https://docs.npmjs.com/cli/dist-tag). 10 | 11 | > Instead of using plus (+) to denote build information, we prefer period (.) for simpler escapes. If you prefer the plus sign, you can [customize the pre-release version pattern](#customizing-pre-release-version-pattern). 12 | 13 | # How to use 14 | 15 | Run `npx version-from-git`, it will run `npm version 1.0.0-main.1a2b3c4`. 16 | 17 | ``` 18 | Usage: version-from-git [options] 19 | 20 | Bump package.json version to pre-release tagged with Git branch and short commit hash, 1.0.0-main.1a2b3c4 21 | 22 | Options: 23 | 24 | -V, --version output the version number 25 | -p, --path path to package.json, default to current directory (default: C:\Users\Compulim\Source\Repos\version-from-git) 26 | --template