提交 2d5c1085 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

use read-pkg-up module to get version from package.json

上级 9e98c089
......@@ -2,6 +2,7 @@ export {
config,
log,
Sayable,
VERSION,
} from './src/config'
export { Contact } from './src/contact'
......@@ -24,8 +25,6 @@ export { PuppetWeb } from './src/puppet-web/'
export { Room } from './src/room'
export { Misc } from './src/misc'
export const VERSION = require('./package.json').version
import Wechaty from './src/wechaty'
export { Wechaty }
export default Wechaty
......@@ -15,7 +15,7 @@
},
"scripts": {
"ts-node": "ts-node",
"dist": "npm run clean && tsc && jq \"del (.files)\" < package.json > dist/package.json && shx cp src/puppet-web/*.js dist/src/puppet-web/",
"dist": "npm run clean && tsc && shx cp src/puppet-web/*.js dist/src/puppet-web/",
"doc": "npm run dist && echo '# Wechaty v'$(jq -r .version package.json)' Documentation\n' > docs/index.md && jsdoc2md dist/src/{wechaty,room,contact,friend-request,message}.js dist/src/puppet-web/friend-request.js>> docs/index.md",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"changelog": "github_changelog_generator -u chatie -p wechaty && sed -i'.bak' /greenkeeper/d CHANGELOG.md && ts-node script/sort-contributiveness.ts < CHANGELOG.md > CHANGELOG.new.md 2>/dev/null && cat CHANGELOG.md >> CHANGELOG.new.md && mv CHANGELOG.new.md CHANGELOG.md",
......@@ -96,6 +96,7 @@
"mime": "^2.0.3",
"puppeteer": "^0.12.0",
"raven": "^2.2.1",
"read-pkg-up": "^2.0.0",
"request": "^2.83.0",
"retry-promise": "^1.0.0",
"rxjs": "^5.4.3",
......@@ -113,6 +114,7 @@
"@types/mime": "^2.0.0",
"@types/puppeteer": "^0.12.0",
"@types/raven": "^2.1.2",
"@types/read-pkg-up": "^2.0.0",
"@types/request": "^2.0.4",
"@types/sinon": "^2.3.5",
"@types/xml2js": "^0.4.0",
......
......@@ -20,6 +20,11 @@ import * as fs from 'fs'
import * as os from 'os'
import * as path from 'path'
import * as readPkgUp from 'read-pkg-up'
const pkg = readPkgUp.sync().pkg
export const VERSION = pkg.version
/**
* Raven.io
*/
......@@ -31,7 +36,7 @@ Raven
process.env.NODE_ENV === 'production'
&& 'https://f6770399ee65459a82af82650231b22c:d8d11b283deb441e807079b8bb2c45cd@sentry.io/179672',
{
release: require('../package.json').version,
release: VERSION,
tags: {
git_commit: 'c0deb10c4',
platform: !!process.env['WECHATY_DOCKER']
......@@ -113,14 +118,13 @@ export interface ConfigSetting {
puppetInstance(instance: Puppet): void
puppetInstance(instance?: Puppet | null): Puppet | void,
gitVersion(): string | null,
npmVersion(): string,
gitRevision(): string | null,
docker: boolean,
}
/* tslint:disable:variable-name */
/* tslint:disable:no-var-requires */
export const config: ConfigSetting = require('../package.json').wechaty
export const config: ConfigSetting = pkg.wechaty
/**
* 1. ENVIRONMENT VARIABLES + PACKAGES.JSON (default)
......@@ -236,19 +240,8 @@ function gitVersion(): string | null {
}
}
function npmVersion(): string {
try {
return require('../package.json').version
} catch (e) {
log.error('Wechaty', 'npmVersion() exception %s', e.message)
Raven.captureException(e)
return '0.0.0'
}
}
Object.assign(config, {
gitVersion,
npmVersion,
puppetInstance,
})
......
......@@ -32,6 +32,7 @@ import {
Raven,
Sayable,
log,
VERSION,
} from './config'
import Contact from './contact'
......@@ -153,12 +154,12 @@ export class Wechaty extends EventEmitter implements Sayable {
*/
public static version(forceNpm = false): string {
if (!forceNpm) {
const revision = config.gitVersion()
const revision = config.gitRevision()
if (revision) {
return `#git[${revision}]`
}
}
return config.npmVersion()
return VERSION
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册