Skip to content

Commit

Permalink
Generate static version string before publish to NPM (wechaty/wechaty…
Browse files Browse the repository at this point in the history
  • Loading branch information
huan committed May 14, 2019
1 parent cc08f6f commit 0e101bf
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
- echo "NPM Deploying Started ..."
- npm version
- if ./scripts/development-release.ts; then ./scripts/package-publish-config-tag-next.ts; fi
- ./scripts/generate-version.ts
- npm run dist
- echo "NPM Building Finished."

Expand Down
18 changes: 18 additions & 0 deletions scripts/generate-version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env ts-node

// tslint:disable:no-console
// tslint:disable:no-var-requires

import fs from 'fs'

const { version } = require('../package.json')

const VERSION_CODE = `
/**
* This file will be overwrite when we publish NPM module
* by scripts/generate_version.ts
*/
export const VERSION = '${version}'
`
fs.writeFileSync('src/version.ts', VERSION_CODE)
8 changes: 1 addition & 7 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@ export function qrCodeForChatie (): FileBox {
return FileBox.fromStream(qrStream, name)
}

/**
* VERSION
*/
import readPkgUp from 'read-pkg-up'

const pkg = readPkgUp.sync({ cwd: __dirname }).pkg
export const VERSION = pkg.version
export { VERSION } from './version'

export {
log,
Expand Down
10 changes: 10 additions & 0 deletions src/version.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env ts-node

// tslint:disable:no-shadowed-variable
import test from 'blue-tape'

import { VERSION } from './version'

test('Make sure the VERSION is fresh in source code', async (t) => {
t.equal(VERSION, '0.0.0', 'version should be 0.0.0 in source code, only updated before publish to NPM')
})
7 changes: 7 additions & 0 deletions src/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

/**
* This file will be overwrite when we publish NPM module
* by scripts/generate_version.ts
*/

export const VERSION = '0.0.0'

0 comments on commit 0e101bf

Please sign in to comment.