diff --git a/.travis.yml b/.travis.yml
index 8f491ef..94487de 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -29,6 +29,7 @@ jobs:
script:
- echo "NPM Pack Testing Started ..."
- npm version
+ - ./scripts/generate-version.sh
- npm run test:pack
- echo "NPM Pack Testing Finished."
@@ -36,7 +37,8 @@ jobs:
script:
- echo "NPM Deploying Started ..."
- npm version
- - if ./scripts/development-release.ts; then ./scripts/package-publish-config-tag-next.ts; fi
+ - ./scripts/generate-version.sh
+ - ./scripts/package-publish-config-tag.sh
- npm run dist
- echo "NPM Building Finished."
diff --git a/package.json b/package.json
index dd46c2a..5a7163e 100644
--- a/package.json
+++ b/package.json
@@ -41,6 +41,8 @@
"url": "https://github.com/Chatie/wechaty-puppet-puppeteer/issues"
},
"devDependencies": {
+ "@chatie/semver": "^0.4.7",
+ "@chatie/tsconfig": "^0.6.1",
"@types/bl": "^2.1.0",
"@types/blue-tape": "^0.1.31",
"@types/lru-cache": "^5.1.0",
@@ -72,6 +74,8 @@
"markdownlint-cli": "^0.16.0",
"memory-card": "^0.6.2",
"normalize-package-data": "^2.4.0",
+ "pkg-jq": "^0.2.2",
+ "pkg-up": "^3.1.0",
"semver": "^6.0.0",
"shx": "^0.3.1",
"sinon": "^7.2.2",
@@ -79,12 +83,7 @@
"tslint": "^5.11.0",
"tslint-config-standard": "^8.0.0",
"typescript": "^3.0.1",
- "wechaty-puppet": "^0.14.1"
- },
- "git": {
- "scripts": {
- "pre-push": "./scripts/pre-push.sh"
- }
+ "wechaty-puppet": "^0.15.11"
},
"peerDependencies": {
"file-box": "^0.8.22",
@@ -92,6 +91,7 @@
},
"homepage": "https://github.com/Chatie/wechaty-puppet-puppeteer#readme",
"dependencies": {
+ "@chatie/git-scripts": "^0.2.4",
"bl": "^3.0.0",
"brolog": "^1.6.5",
"hot-import": "^0.2.1",
@@ -108,5 +108,14 @@
"state-switch": "^0.6.2",
"watchdog": "^0.8.15",
"xml2js": "^0.4.19"
+ },
+ "publishConfig": {
+ "access": "public",
+ "tag": "next"
+ },
+ "git": {
+ "scripts": {
+ "pre-push": "npx git-scripts-pre-push"
+ }
}
}
diff --git a/scripts/development-release.ts b/scripts/development-release.ts
deleted file mode 100755
index 2ae0e45..0000000
--- a/scripts/development-release.ts
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/usr/bin/env ts-node
-
-// tslint:disable:no-console
-// tslint:disable:no-var-requires
-
-import { minor } from 'semver'
-
-const { version } = require('../package.json')
-
-if (minor(version) % 2 === 0) { // production release
- console.log(`${version} is production release`)
- process.exit(1) // exit 1 for not development
-}
-
-// development release
-console.log(`${version} is development release`)
-process.exit(0)
diff --git a/scripts/generate-version.sh b/scripts/generate-version.sh
new file mode 100755
index 0000000..e8ef7f9
--- /dev/null
+++ b/scripts/generate-version.sh
@@ -0,0 +1,18 @@
+#!/usr/bin/env bash
+set -e
+
+SRC_VERSION_TS_FILE='src/version.ts'
+
+[ -f ${SRC_VERSION_TS_FILE} ] || {
+ echo ${SRC_VERSION_TS_FILE}" not found"
+ exit 1
+}
+
+VERSION=$(npx pkg-jq -r .version)
+
+cat <<_SRC_ > ${SRC_VERSION_TS_FILE}
+/**
+ * This file was auto generated from scripts/generate-version.sh
+ */
+export const VERSION: string = '${VERSION}'
+_SRC_
diff --git a/scripts/package-publish-config-tag-next.ts b/scripts/package-publish-config-tag-next.ts
deleted file mode 100755
index c57abf5..0000000
--- a/scripts/package-publish-config-tag-next.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/usr/bin/env ts-node
-
-// tslint:disable:no-console
-// tslint:disable:no-var-requires
-
-import * as fs from 'fs'
-import * as path from 'path'
-
-const PACKAGE_JSON = path.join(__dirname, '../package.json')
-
-const pkg = require(PACKAGE_JSON)
-
-pkg.publishConfig = {
- access: 'public',
- ...pkg.publishConfig,
- tag: 'next',
-}
-
-fs.writeFileSync(PACKAGE_JSON, JSON.stringify(pkg, null, 2))
-// console.log(JSON.stringify(pkg, null, 2))
-
-console.log('set package.json:publicConfig.tag to next.')
diff --git a/scripts/package-publish-config-tag.sh b/scripts/package-publish-config-tag.sh
new file mode 100755
index 0000000..0187283
--- /dev/null
+++ b/scripts/package-publish-config-tag.sh
@@ -0,0 +1,13 @@
+#!/usr/bin/env bash
+set -e
+
+VERSION=$(npx pkg-jq -r .version)
+
+if npx --package @chatie/semver semver-is-prod $VERSION; then
+ npx pkg-jq -i '.publishConfig.tag="latest"'
+ echo "production release: publicConfig.tag set to latest."
+else
+ npx pkg-jq -i '.publishConfig.tag="next"'
+ echo 'development release: publicConfig.tag set to next.'
+fi
+
diff --git a/scripts/pre-push.sh b/scripts/pre-push.sh
deleted file mode 100755
index 3ba4505..0000000
--- a/scripts/pre-push.sh
+++ /dev/null
@@ -1,56 +0,0 @@
-#!/bin/bash
-#
-# An example hook script to verify what is about to be committed.
-# Called by "git commit" with no arguments. The hook should
-# exit with non-zero status after issuing an appropriate message if
-# it wants to stop the commit.
-#
-# To enable this hook, rename this file to "pre-commit".
-set -e
-
-[ -n "$NO_HOOK" ] && exit 0
-
-[ -n "$HUAN_INNER_PRE_HOOK" ] && {
- # http://stackoverflow.com/a/21334985/1123955
- exit 0
-}
-
-npm run lint
-
-[ -z "$CYGWIN" ] && {
- # git rebase
- rm -f package-lock.json
- npm version patch --no-package-lock
- HUAN_INNER_PRE_HOOK=1 git push
-
- cat <<'_STR_'
- ____ _ _ ____ _
- / ___(_) |_ | _ \ _ _ ___| |__
-| | _| | __| | |_) | | | / __| '_ \
-| |_| | | |_ | __/| |_| \__ \ | | |
- \____|_|\__| |_| \__,_|___/_| |_|
-
- ____ _ _
-/ ___| _ _ ___ ___ ___ ___ __| | |
-\___ \| | | |/ __/ __/ _ \/ _ \/ _` | |
- ___) | |_| | (_| (_| __/ __/ (_| |_|
-|____/ \__,_|\___\___\___|\___|\__,_(_)
-
-_STR_
-
- echo
- echo
- echo
- echo " ### Npm verion bumped and pushed by inner push inside hook pre-push ###"
- echo " ------- vvvvvvv outer push will be canceled, never mind vvvvvvv -------"
- echo
- echo
- echo
- exit 127
-}
-
-# must run this after the above `test` ([ -z ...]),
-# or will whow a error: error: failed to push some refs to 'git@github.com:Chatie/wechaty.git'
-echo "PRE-PUSH HOOK PASSED"
-echo
-
diff --git a/src/config.ts b/src/config.ts
index 5e8bcaa..b9d5894 100644
--- a/src/config.ts
+++ b/src/config.ts
@@ -3,7 +3,7 @@
///
import promiseRetry = require('promise-retry')
-import { WrapOptions } from 'retry'
+import { OperationOptions } from 'retry'
import {
// Brolog,
@@ -12,6 +12,8 @@ import {
import { FileBox } from 'file-box'
import qrImage from 'qr-image'
+import { VERSION } from './version'
+
// export const log = new Brolog()
export async function retry (
@@ -33,7 +35,7 @@ export async function retry (
const retries = 9
// const unref = true
- const retryOptions: WrapOptions = {
+ const retryOptions: OperationOptions = {
factor,
maxTimeout,
minTimeout,
@@ -61,14 +63,7 @@ export function qrCodeForChatie (): FileBox {
export const MEMORY_SLOT = 'PUPPET_PUPPETEER'
-/**
- * VERSION
- */
-import readPkgUp from 'read-pkg-up'
-
-const pkg = readPkgUp.sync({ cwd: __dirname }).pkg
-export const VERSION = pkg.version
-
export {
+ VERSION,
log,
}
diff --git a/src/puppet-puppeteer.ts b/src/puppet-puppeteer.ts
index 76ebdf4..fb16e8b 100644
--- a/src/puppet-puppeteer.ts
+++ b/src/puppet-puppeteer.ts
@@ -209,7 +209,7 @@ export class PuppetPuppeteer extends Puppet {
data: info,
type: 'scan',
}))
- puppet.on('login', user => {
+ puppet.on('login', (/* user */) => {
// dog.feed({
// data: user,
// type: 'login',
@@ -338,7 +338,7 @@ export class PuppetPuppeteer extends Puppet {
}
public async messageUrl (messageId: string) : Promise {
- return throwUnsupportedError()
+ return throwUnsupportedError(messageId)
}
private async messageRawPayloadToFile (
@@ -401,7 +401,7 @@ export class PuppetPuppeteer extends Puppet {
to : Receiver,
urlLinkPayload : UrlLinkPayload,
) : Promise {
- throwUnsupportedError()
+ throwUnsupportedError(to, urlLinkPayload)
}
/**
@@ -548,11 +548,11 @@ export class PuppetPuppeteer extends Puppet {
}
public async contactSelfName (name: string): Promise {
- return throwUnsupportedError()
+ return throwUnsupportedError(name)
}
public async contactSelfSignature (signature: string): Promise {
- return throwUnsupportedError()
+ return throwUnsupportedError(signature)
}
/**
@@ -975,15 +975,15 @@ export class PuppetPuppeteer extends Puppet {
*
*/
public async roomInvitationAccept (roomInvitationId: string): Promise {
- return throwUnsupportedError()
+ return throwUnsupportedError(roomInvitationId)
}
public async roomInvitationRawPayload (roomInvitationId: string): Promise {
- return throwUnsupportedError()
+ return throwUnsupportedError(roomInvitationId)
}
public async roomInvitationRawPayloadParser (rawPayload: any): Promise {
- return throwUnsupportedError()
+ return throwUnsupportedError(rawPayload)
}
/**
diff --git a/src/version.spec.ts b/src/version.spec.ts
new file mode 100755
index 0000000..127e603
--- /dev/null
+++ b/src/version.spec.ts
@@ -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')
+})
diff --git a/src/version.ts b/src/version.ts
new file mode 100644
index 0000000..c36f2c5
--- /dev/null
+++ b/src/version.ts
@@ -0,0 +1,6 @@
+/**
+ * This file will be overwrite when we publish NPM module
+ * by scripts/generate_version.ts
+ */
+
+export const VERSION = '0.0.0'
diff --git a/tests/fixtures/smoke-testing.ts b/tests/fixtures/smoke-testing.ts
index 61f3166..0a9eff0 100644
--- a/tests/fixtures/smoke-testing.ts
+++ b/tests/fixtures/smoke-testing.ts
@@ -9,12 +9,17 @@
import {
PuppetPuppeteer,
+ VERSION,
log,
} from 'wechaty-puppet-puppeteer'
log.level('verbose')
async function main () {
+ if (VERSION === '0.0.0') {
+ throw new Error('VERSION should not be 0.0.0 when publishing')
+ }
+
const puppet = new PuppetPuppeteer()
const future = new Promise(r => puppet.once('scan', r))
diff --git a/tsconfig.json b/tsconfig.json
index e77f66e..60d402c 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,28 +1,24 @@
{
+ "extends": "@chatie/tsconfig",
"compilerOptions": {
- "target": "es6"
- , "module": "commonjs"
- , "outDir": "dist"
- , "declaration": true
- , "sourceMap": true
- , "strict": true
- , "traceResolution": false
- , "esModuleInterop" : true
- , "resolveJsonModule": true
- , "lib": [
- "dom"
- , "esnext"
- ]
- }
- , "exclude": [
- "node_modules/"
- , "dist/"
- ]
- , "include": [
- "bin/*.ts"
- , "scripts/**/*.ts"
- , "examples/**/*.ts"
- , "src/**/*.ts"
- , "tests/**/*.spec.ts"
- ]
+ "outDir": "dist",
+ "lib": [
+ "dom",
+ "esnext",
+ ],
+ },
+ "exclude": [
+ "node_modules/",
+ "dist/",
+ "tests/fixtures/",
+ ],
+ "include": [
+ "app/**/*.ts",
+ "bin/*.ts",
+ "bot/**/*.ts",
+ "examples/**/*.ts",
+ "scripts/**/*.ts",
+ "src/**/*.ts",
+ "tests/**/*.spec.ts",
+ ],
}