File tree Expand file tree Collapse file tree 10 files changed +324
-20
lines changed Expand file tree Collapse file tree 10 files changed +324
-20
lines changed Original file line number Diff line number Diff line change 1
- # PR
1
+ # Pull Request
2
2
3
- Insert notes here
3
+ Add PR details here
4
+
5
+ ## Testing Instructions (or AC)
6
+
7
+ Add testing instructions or AC here
Original file line number Diff line number Diff line change
1
+ name : Publish Package to npmjs
2
+
3
+ # Trigger the workflow on a new release in Github
4
+ on :
5
+ release :
6
+ types : [published]
7
+
8
+ jobs :
9
+ build :
10
+ runs-on : ubuntu-latest
11
+ permissions :
12
+ contents : read
13
+ id-token : write
14
+ steps :
15
+ - uses : actions/checkout@v4
16
+ # Setup .npmrc file to publish to npm
17
+ - name : Install Node.js
18
+ uses : actions/setup-node@v4
19
+ with :
20
+ registry-url : " https://registry.npmjs.org"
21
+ cache : " npm"
22
+ - run : npm ci
23
+ - run : npm publish --provenance --access public
24
+ env :
25
+ NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
Original file line number Diff line number Diff line change
1
+ name : Tests Workflow
2
+
3
+ on :
4
+ pull_request :
5
+ branches : ["main"]
6
+
7
+ jobs :
8
+ test :
9
+ runs-on : ubuntu-latest
10
+ steps :
11
+ - uses : actions/checkout@v4
12
+ - name : Install Node.js
13
+ uses : actions/setup-node@v4
14
+ with :
15
+ cache : " npm"
16
+ - run : npm ci
17
+ - run : npm run test
Original file line number Diff line number Diff line change 1
- v23.1 .0
1
+ v23.4 .0
Original file line number Diff line number Diff line change 1
- # nodejs
1
+ # npm-gitver
2
2
3
- Nodejs template. Use node version in nvmrc file
3
+ ` npm-gitver ` is an NPM library for managing versioning in your Node.js projects using Git tags.
4
4
5
+ ## Installation
6
+
7
+ Install the library using npm:
8
+
9
+ ``` bash
10
+ npm install npm-gitver --save-dev
5
11
```
6
- nvm use
12
+
13
+ ## Usage
14
+
15
+ ### Running via npm script
16
+
17
+ 1 . Ensure you are using the correct Node.js version specified in the ` .nvmrc ` file:
18
+
19
+ ``` bash
20
+ nvm use
21
+ ```
22
+
23
+ 2 . Add a script in your ` package.json ` to run ` npm-gitver ` :
24
+
25
+ ``` json
26
+ "scripts" : {
27
+ "version" : " npm-gitver"
28
+ }
29
+ ```
30
+
31
+ 3 . Run the versioning script:
32
+
33
+ ``` bash
34
+ npm run version
35
+ ```
36
+
37
+ This will automatically update your project version based on Git tags.
38
+
39
+ ### Running directly via CLI
40
+
41
+ You can also run ` npm-gitver ` directly using ` npx ` without adding it to your ` package.json ` :
42
+
43
+ ``` bash
44
+ npx npm-gitver
7
45
```
8
46
47
+ This will execute the package directly from the command line, creating or updating the version based on Git tags.
48
+
9
49
## Linting
10
50
11
- https://eslint.org/docs/latest/
51
+ Follow best practices for linting your code. Refer to the ESLint documentation for setup and configuration:
52
+
53
+ [ ESLint Documentation] ( https://eslint.org/docs/latest/ )
54
+
55
+ ## Additional Information
56
+
57
+ For more details on how ` npm-gitver ` works, refer to the [ GitHub repository] ( https://github.com/your-repo/npm-gitver ) .
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env node
2
+
3
+ const { generateGitVersion } = require ( '../index' ) ;
4
+
5
+ const version = generateGitVersion ( ) ;
6
+ console . log ( version ) ;
Original file line number Diff line number Diff line change
1
+ const fs = require ( 'fs' ) ;
2
+ const childProcess = require ( 'child_process' ) ;
3
+ const path = require ( 'path' ) ;
4
+
5
+ function getShortGitSHA ( ) {
6
+ return childProcess . execSync ( 'git rev-parse --short HEAD' ) . toString ( ) . trim ( ) ;
7
+ }
8
+
9
+ function readPackageJson ( ) {
10
+ const pkgPath = path . resolve ( process . cwd ( ) , 'package.json' ) ;
11
+ if ( ! fs . existsSync ( pkgPath ) ) {
12
+ throw new Error ( 'package.json not found in the current working directory.' ) ;
13
+ }
14
+ const raw = fs . readFileSync ( pkgPath ) ;
15
+ return JSON . parse ( raw ) ;
16
+ }
17
+
18
+ function generateGitVersion ( ) {
19
+ const sha = getShortGitSHA ( ) ;
20
+ const pkg = readPackageJson ( ) ;
21
+
22
+ if ( ! pkg . version ) {
23
+ throw new Error ( 'The "version" key is missing in package.json.' ) ;
24
+ }
25
+ const baseVersion = pkg . version . split ( '-' ) [ 0 ] ; // remove any pre-release suffix
26
+ const newVersion = `${ baseVersion } -${ sha } ` ;
27
+
28
+ return newVersion ;
29
+ }
30
+
31
+ module . exports = {
32
+ generateGitVersion,
33
+ } ;
Original file line number Diff line number Diff line change 1
1
{
2
- "name" : " nodejs " ,
2
+ "name" : " npm-gitver " ,
3
3
"version" : " 1.0.0" ,
4
- "description" : " Node template" ,
4
+ "description" : " npm gitver is a simple command line tool that allows you to easily manage your git versioning." ,
5
+ "bin" : {
6
+ "npm-gitver" : " ./bin/npm-gitver.js"
7
+ },
5
8
"keywords" : [
6
9
" nodejs" ,
7
- " javascript"
10
+ " javascript" ,
11
+ " git"
8
12
],
9
- "homepage" : " https://github.com/TheBookKnight/nodejs #readme" ,
13
+ "homepage" : " https://github.com/TheBookKnight/npm-gitver #readme" ,
10
14
"bugs" : {
11
- "url" : " https://github.com/TheBookKnight/nodejs /issues"
15
+ "url" : " https://github.com/TheBookKnight/npm-gitver /issues"
12
16
},
13
17
"repository" : {
14
18
"type" : " git" ,
15
- "url" : " git+https://github.com/TheBookKnight/nodejs .git"
19
+ "url" : " git+https://github.com/TheBookKnight/npm-gitver .git"
16
20
},
17
21
"license" : " ISC" ,
18
22
"author" : " Joshua Cadavez" ,
19
- "type" : " commonjs" ,
20
23
"main" : " index.js" ,
21
24
"scripts" : {
22
25
"lint" : " eslint ." ,
23
- "test" : " echo \" Error: no test specified \" && exit 1 "
26
+ "test" : " node -- test"
24
27
},
25
28
"devDependencies" : {
26
29
"@eslint/js" : " ^9.21.0" ,
27
30
"eslint" : " ^9.21.0" ,
28
- "globals" : " ^16.0.0"
31
+ "globals" : " ^16.0.0" ,
32
+ "sinon" : " ^20.0.0"
29
33
}
30
- }
34
+ }
You can’t perform that action at this time.
0 commit comments