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