1
1
#! /usr/bin/env node
2
- const fs = require ( 'fs' )
3
- const git = require ( 'git-rev-sync' )
4
- const readPkgUp = require ( 'read-pkg-up' )
5
- const writePkg = require ( 'write-pkg' )
6
- const chalk = require ( 'chalk' )
7
- const options = require ( 'minimist' ) ( process . argv . slice ( 2 ) )
8
- const path = require ( 'path' )
2
+ //rm -rf node_modules/ && npm i . && node index.js --verbose
3
+ import git from 'git-rev-sync' ;
4
+ import {
5
+ readPackageUp as readPkgUp
6
+ } from 'read-pkg-up' ;
7
+ import {
8
+ writePackage as writePkg
9
+ } from 'write-pkg' ;
10
+ import minimist from 'minimist' ;
11
+ const options = minimist ( process . argv . slice ( 2 ) )
12
+ import path from 'path' ;
9
13
10
14
// don't normalize package.json
11
- readPkgUp ( { normalize : false } ) . then ( result => {
12
- let { pkg} = result
13
- const pkgPath = result . path
14
- const gitPath = path . dirname ( pkgPath )
15
+ readPkgUp ( {
16
+ normalize : false
17
+ } ) . then ( result => {
18
+ let {
19
+ packageJson
20
+ } = result
21
+ const pkgPath = result . path
22
+ const gitPath = path . dirname ( pkgPath )
15
23
16
- const gitInfo = {
17
- short : git . short ( gitPath ) ,
18
- long : git . long ( gitPath ) ,
19
- branch : git . branch ( gitPath ) ,
20
- tag : git . tag ( )
21
- }
24
+ const gitInfo = {
25
+ short : git . short ( gitPath ) ,
26
+ long : git . long ( gitPath ) ,
27
+ branch : git . branch ( gitPath ) ,
28
+ tag : git . tag ( )
29
+ }
30
+ packageJson . git = gitInfo ;
22
31
23
- const updatedPkg = Object . assign ( { } , pkg , {
24
- git : gitInfo
25
- } )
26
-
27
- writePkg ( pkgPath , updatedPkg ) . then ( ( ) => {
28
- if ( options . verbose || options . v ) {
29
- const logMsg = `
32
+ writePkg ( pkgPath , packageJson ) . then ( ( ) => {
33
+ if ( options . verbose || options . v ) {
34
+ const logMsg = `
30
35
Git path: ${ gitPath }
31
36
Git info in ${ pkgPath } was updated:
32
- Short: ${ chalk . green ( gitInfo . short ) }
33
- Long: ${ chalk . yellow ( gitInfo . long ) }
34
- Branch: ${ chalk . red ( gitInfo . branch ) }
35
- Tag: ${ chalk . red ( gitInfo . tag ) } `
36
- console . log ( logMsg )
37
- }
38
- } )
39
- } )
37
+ Short: ${ gitInfo . short }
38
+ Long: ${ gitInfo . long }
39
+ Branch: ${ gitInfo . branch }
40
+ Tag: ${ gitInfo . tag } `
41
+ console . log ( logMsg )
42
+ }
43
+ } )
44
+ } )
0 commit comments