Skip to content

Commit

Permalink
follow @Chatie devops toolset
Browse files Browse the repository at this point in the history
  • Loading branch information
huan committed Jun 15, 2019
1 parent 7c6c1ef commit 4e7009f
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 145 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Expand Up @@ -29,14 +29,16 @@ jobs:
script:
- echo "NPM Pack Testing Started ..."
- npm version
- ./scripts/generate-version.sh
- npm run test:pack
- echo "NPM Pack Testing Finished."

- stage: deploy
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."

Expand Down
21 changes: 15 additions & 6 deletions package.json
Expand Up @@ -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",
Expand Down Expand Up @@ -72,26 +74,24 @@
"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",
"ts-node": "^8.0.2",
"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",
"wechaty-puppet": "^0.14.1"
},
"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",
Expand All @@ -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"
}
}
}
17 changes: 0 additions & 17 deletions scripts/development-release.ts

This file was deleted.

18 changes: 18 additions & 0 deletions 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_
22 changes: 0 additions & 22 deletions scripts/package-publish-config-tag-next.ts

This file was deleted.

13 changes: 13 additions & 0 deletions 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

56 changes: 0 additions & 56 deletions scripts/pre-push.sh

This file was deleted.

15 changes: 5 additions & 10 deletions src/config.ts
Expand Up @@ -3,7 +3,7 @@
/// <reference path="./typings.d.ts" />

import promiseRetry = require('promise-retry')
import { WrapOptions } from 'retry'
import { OperationOptions } from 'retry'

import {
// Brolog,
Expand All @@ -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<T> (
Expand All @@ -33,7 +35,7 @@ export async function retry<T> (
const retries = 9
// const unref = true

const retryOptions: WrapOptions = {
const retryOptions: OperationOptions = {
factor,
maxTimeout,
minTimeout,
Expand Down Expand Up @@ -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,
}
16 changes: 8 additions & 8 deletions src/puppet-puppeteer.ts
Expand Up @@ -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',
Expand Down Expand Up @@ -338,7 +338,7 @@ export class PuppetPuppeteer extends Puppet {
}

public async messageUrl (messageId: string) : Promise<UrlLinkPayload> {
return throwUnsupportedError()
return throwUnsupportedError(messageId)
}

private async messageRawPayloadToFile (
Expand Down Expand Up @@ -401,7 +401,7 @@ export class PuppetPuppeteer extends Puppet {
to : Receiver,
urlLinkPayload : UrlLinkPayload,
) : Promise<void> {
throwUnsupportedError()
throwUnsupportedError(to, urlLinkPayload)
}

/**
Expand Down Expand Up @@ -548,11 +548,11 @@ export class PuppetPuppeteer extends Puppet {
}

public async contactSelfName (name: string): Promise<void> {
return throwUnsupportedError()
return throwUnsupportedError(name)
}

public async contactSelfSignature (signature: string): Promise<void> {
return throwUnsupportedError()
return throwUnsupportedError(signature)
}

/**
Expand Down Expand Up @@ -975,15 +975,15 @@ export class PuppetPuppeteer extends Puppet {
*
*/
public async roomInvitationAccept (roomInvitationId: string): Promise<void> {
return throwUnsupportedError()
return throwUnsupportedError(roomInvitationId)
}

public async roomInvitationRawPayload (roomInvitationId: string): Promise<any> {
return throwUnsupportedError()
return throwUnsupportedError(roomInvitationId)
}

public async roomInvitationRawPayloadParser (rawPayload: any): Promise<RoomInvitationPayload> {
return throwUnsupportedError()
return throwUnsupportedError(rawPayload)
}

/**
Expand Down
10 changes: 10 additions & 0 deletions 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')
})
6 changes: 6 additions & 0 deletions 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'
5 changes: 5 additions & 0 deletions tests/fixtures/smoke-testing.ts
Expand Up @@ -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))

Expand Down
46 changes: 21 additions & 25 deletions 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",
],
}

0 comments on commit 4e7009f

Please sign in to comment.