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

Follow Chatie DevOps toolset (#1793)

上级 9101e387
// {
// "rules": {
// "indent": [
// "error",
// 4,
// {
// "CallExpression": {
// "arguments": "first"
// }
// }
// ]
// }
// }
const rules = {
indent: ['error', 2, {
CallExpression: {
arguments: 'off',
},
SwitchCase: 1,
}],
}
module.exports = {
extends: '@chatie',
rules,
}
...@@ -36,7 +36,6 @@ script: ...@@ -36,7 +36,6 @@ script:
- npm test - npm test
# - if [ "$TRAVIS_OS_NAME" == 'linux' ]; then npm run coverage; fi # - if [ "$TRAVIS_OS_NAME" == 'linux' ]; then npm run coverage; fi
- echo "Testing Finished" - echo "Testing Finished"
- echo "TRAVIS_TEST_RESULT=$TRAVIS_TEST_RESULT"
jobs: jobs:
include: include:
...@@ -45,18 +44,18 @@ jobs: ...@@ -45,18 +44,18 @@ jobs:
script: script:
- echo "NPM Pack Testing Started ..." - echo "NPM Pack Testing Started ..."
- npm version - npm version
- ./scripts/generate-version.sh
- npm run test:pack - npm run test:pack
- echo "NPM Pack Testing Finished." - echo "NPM Pack Testing Finished."
- echo "TRAVIS_TEST_RESULT=$TRAVIS_TEST_RESULT"
- stage: deploy - stage: deploy
script: script:
- echo "NPM Deploying Started ..." - echo "NPM Deploying Started ..."
- npm version - 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 - npm run dist
- echo "NPM Building Finished." - echo "NPM Building Finished."
- echo "TRAVIS_TEST_RESULT=$TRAVIS_TEST_RESULT"
deploy: deploy:
provider: npm provider: npm
......
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
"alignment": { "alignment": {
"operatorPadding": "right", "operatorPadding": "right",
"indentBase": "firstline", "indentBase": "firstline",
"surroundSpace": {, "surroundSpace": {
"colon": [1, 1], // The first number specify how much space to add to the left, can be negative. The second number is how much space to the right, can be negative. "colon": [1, 1], // The first number specify how much space to add to the left, can be negative. The second number is how much space to the right, can be negative.
"assignment": [1, 1], // The same as above. "assignment": [1, 1], // The same as above.
"arrow": [1, 1], // The same as above. "arrow": [1, 1], // The same as above.
...@@ -66,4 +66,8 @@ ...@@ -66,4 +66,8 @@
}, },
"editor.formatOnSave": false, "editor.formatOnSave": false,
"python.pythonPath": "python3", "python.pythonPath": "python3",
"eslint.validate": [
"javascript",
"typescript",
],
} }
...@@ -52,7 +52,7 @@ if (!token) { ...@@ -52,7 +52,7 @@ if (!token) {
log.warn('Client', `set token to "${token}" for demo purpose`) log.warn('Client', `set token to "${token}" for demo purpose`)
} }
console.log(welcome) console.info(welcome)
log.info('Client', 'Starting for WECHATY_TOKEN: %s', token) log.info('Client', 'Starting for WECHATY_TOKEN: %s', token)
const client = new IoClient({ const client = new IoClient({
...@@ -61,7 +61,7 @@ const client = new IoClient({ ...@@ -61,7 +61,7 @@ const client = new IoClient({
}) })
client.start() client.start()
.catch(onError.bind(client)) .catch(onError.bind(client))
// client.initWeb() // client.initWeb()
// .catch(onError.bind(client)) // .catch(onError.bind(client))
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
import { PuppetManager } from '../src/puppet-manager' import { PuppetManager } from '../src/puppet-manager'
PuppetManager.installAll() PuppetManager.installAll()
.catch(e => { .catch(e => {
console.error(e) console.error(e)
process.exit(1) process.exit(1)
}) })
...@@ -20,4 +20,4 @@ ...@@ -20,4 +20,4 @@
import { Wechaty } from '../src/wechaty' import { Wechaty } from '../src/wechaty'
console.log(Wechaty.version()) console.info(Wechaty.version())
...@@ -40,11 +40,11 @@ const bot = new Wechaty({ ...@@ -40,11 +40,11 @@ const bot = new Wechaty({
* *
*/ */
bot bot
.on('logout', onLogout) .on('logout', onLogout)
.on('login', onLogin) .on('login', onLogin)
.on('scan', onScan) .on('scan', onScan)
.on('error', onError) .on('error', onError)
.on('message', onMessage) .on('message', onMessage)
/** /**
* *
...@@ -52,11 +52,11 @@ bot ...@@ -52,11 +52,11 @@ bot
* *
*/ */
bot.start() bot.start()
.catch(async e => { .catch(async e => {
console.error('Bot start() fail:', e) console.error('Bot start() fail:', e)
await bot.stop() await bot.stop()
process.exit(-1) process.exit(-1)
}) })
/** /**
* *
...@@ -80,16 +80,16 @@ function onScan (qrcode: string, status: number) { ...@@ -80,16 +80,16 @@ function onScan (qrcode: string, status: number) {
encodeURIComponent(qrcode), encodeURIComponent(qrcode),
].join('') ].join('')
console.log(`[${status}] ${qrcodeImageUrl}\nScan QR Code above to log in: `) console.info(`[${status}] ${qrcodeImageUrl}\nScan QR Code above to log in: `)
} }
function onLogin (user: Contact) { function onLogin (user: Contact) {
console.log(`${user.name()} login`) console.info(`${user.name()} login`)
bot.say('Wechaty login').catch(console.error) bot.say('Wechaty login').catch(console.error)
} }
function onLogout (user: Contact) { function onLogout (user: Contact) {
console.log(`${user.name()} logouted`) console.info(`${user.name()} logouted`)
} }
function onError (e: Error) { function onError (e: Error) {
...@@ -108,10 +108,10 @@ function onError (e: Error) { ...@@ -108,10 +108,10 @@ function onError (e: Error) {
* *
*/ */
async function onMessage (msg: Message) { async function onMessage (msg: Message) {
console.log(msg.toString()) console.info(msg.toString())
if (msg.age() > 60) { if (msg.age() > 60) {
console.log('Message discarded because its TOO OLD(than 1 minute)') console.info('Message discarded because its TOO OLD(than 1 minute)')
return return
} }
...@@ -119,7 +119,7 @@ async function onMessage (msg: Message) { ...@@ -119,7 +119,7 @@ async function onMessage (msg: Message) {
|| !/^(ding|ping|bing|code)$/i.test(msg.text()) || !/^(ding|ping|bing|code)$/i.test(msg.text())
/*&& !msg.self()*/ /*&& !msg.self()*/
) { ) {
console.log('Message discarded because it does not match ding/ping/bing/code') console.info('Message discarded because it does not match ding/ping/bing/code')
return return
} }
...@@ -127,7 +127,7 @@ async function onMessage (msg: Message) { ...@@ -127,7 +127,7 @@ async function onMessage (msg: Message) {
* 1. reply 'dong' * 1. reply 'dong'
*/ */
await msg.say('dong') await msg.say('dong')
console.log('REPLY: dong') console.info('REPLY: dong')
/** /**
* 2. reply image(qrcode image) * 2. reply image(qrcode image)
...@@ -135,7 +135,7 @@ async function onMessage (msg: Message) { ...@@ -135,7 +135,7 @@ async function onMessage (msg: Message) {
const fileBox = FileBox.fromUrl('https://chatie.io/wechaty/images/bot-qr-code.png') const fileBox = FileBox.fromUrl('https://chatie.io/wechaty/images/bot-qr-code.png')
await msg.say(fileBox) await msg.say(fileBox)
console.log('REPLY: %s', fileBox.toString()) console.info('REPLY: %s', fileBox.toString())
/** /**
* 3. reply 'scan now!' * 3. reply 'scan now!'
...@@ -175,4 +175,4 @@ upgrade me to more superpowers! ...@@ -175,4 +175,4 @@ upgrade me to more superpowers!
Please wait... I'm trying to login in... Please wait... I'm trying to login in...
` `
console.log(welcome) console.info(welcome)
...@@ -21,9 +21,10 @@ ...@@ -21,9 +21,10 @@
"changelog": "github_changelog_generator -u chatie -p wechaty && sed -i'.bak' /greenkeeper/d CHANGELOG.md && sed -i'.bak' '/An in-range update of/d' CHANGELOG.md && ts-node scripts/sort-contributiveness.ts < CHANGELOG.md > CHANGELOG.new.md 2>/dev/null && cat CHANGELOG.md >> CHANGELOG.new.md && mv CHANGELOG.new.md CHANGELOG.md", "changelog": "github_changelog_generator -u chatie -p wechaty && sed -i'.bak' /greenkeeper/d CHANGELOG.md && sed -i'.bak' '/An in-range update of/d' CHANGELOG.md && ts-node scripts/sort-contributiveness.ts < CHANGELOG.md > CHANGELOG.new.md 2>/dev/null && cat CHANGELOG.md >> CHANGELOG.new.md && mv CHANGELOG.new.md CHANGELOG.md",
"doctor": "npm run check-node-version && ts-node bin/doctor", "doctor": "npm run check-node-version && ts-node bin/doctor",
"check-node-version": "check-node-version --node \">= 10\"", "check-node-version": "check-node-version --node \">= 10\"",
"lint": "npm run check-node-version && npm run lint:ts && npm run lint:sh", "lint": "npm run check-node-version && npm run lint:es && npm run lint:ts && npm run lint:sh",
"lint:es": "eslint --ignore-pattern fixtures/ src/**/*.ts tests/**/*.ts scripts/**/*.ts examples/**/*.ts bin/**/*.ts",
"lint:md": "markdownlint README.md", "lint:md": "markdownlint README.md",
"lint:ts": "tslint --project tsconfig.json && tsc --noEmit", "lint:ts": "tsc --noEmit",
"lint:sh": "bash -n bin/*.sh", "lint:sh": "bash -n bin/*.sh",
"puppet-install": "ts-node bin/puppet-install.ts", "puppet-install": "ts-node bin/puppet-install.ts",
"sloc": "sloc bin examples scripts src tests --details --format cli-table --keys total,source,comment && sloc bin examples scripts src tests", "sloc": "sloc bin examples scripts src tests --details --format cli-table --keys total,source,comment && sloc bin examples scripts src tests",
...@@ -93,16 +94,16 @@ ...@@ -93,16 +94,16 @@
"qr-image": "^3.2.0", "qr-image": "^3.2.0",
"raven": "^2.6.2", "raven": "^2.6.2",
"read-pkg-up": "^6.0.0", "read-pkg-up": "^6.0.0",
"semver": "^6.0.0",
"state-switch": "^0.6.2", "state-switch": "^0.6.2",
"watchdog": "^0.8.1", "watchdog": "^0.8.1",
"wechaty-puppet": "^0.15.9", "wechaty-puppet": "^0.15.9",
"ws": "^7.0.0" "ws": "^7.0.0"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.0.1", "@chatie/eslint-config": "^0.6.5",
"@babel/node": "^7.0.0", "@chatie/git-scripts": "^0.2.1",
"@babel/preset-env": "^7.0.0", "@chatie/tsconfig": "^0.4.5",
"@chatie/tsconfig": "^0.4.2",
"@types/blessed": "^0.1.10", "@types/blessed": "^0.1.10",
"@types/blue-tape": "^0.1.0", "@types/blue-tape": "^0.1.0",
"@types/cuid": "^1.3.0", "@types/cuid": "^1.3.0",
...@@ -120,7 +121,6 @@ ...@@ -120,7 +121,6 @@
"@types/semver": "^6.0.0", "@types/semver": "^6.0.0",
"@types/sinon": "^7.0.4", "@types/sinon": "^7.0.4",
"@types/ws": "^6.0.0", "@types/ws": "^6.0.0",
"@wwwouter/tslint-contrib": "^1.0.0",
"apiai": "^4.0.0", "apiai": "^4.0.0",
"blessed": "^0.1.81", "blessed": "^0.1.81",
"blessed-contrib": "^4.8.5", "blessed-contrib": "^4.8.5",
...@@ -130,7 +130,6 @@ ...@@ -130,7 +130,6 @@
"cross-env": "^5.1.6", "cross-env": "^5.1.6",
"finis": "^0.4.1", "finis": "^0.4.1",
"fluent-ffmpeg": "^2.1.0", "fluent-ffmpeg": "^2.1.0",
"git-scripts": "git+https://github.com/nkzawa/git-scripts.git",
"gl-matrix": "^3.0.0", "gl-matrix": "^3.0.0",
"glob": "^7.1.0", "glob": "^7.1.0",
"is-pr": "^1.0.0", "is-pr": "^1.0.0",
...@@ -139,15 +138,11 @@ ...@@ -139,15 +138,11 @@
"nyc": "^14.0.0", "nyc": "^14.0.0",
"qrcode-terminal": "^0.12.0", "qrcode-terminal": "^0.12.0",
"request": "^2.87.0", "request": "^2.87.0",
"semver": "^6.0.0",
"shx": "^0.3.0", "shx": "^0.3.0",
"sinon": "^7.2.3", "sinon": "^7.2.3",
"sloc": "^0.2.0", "sloc": "^0.2.0",
"ts-node": "^8.0.2", "tstest": "^0.2.4",
"tslint": "^5.11.0",
"tslint-config-standard": "^8.0.0",
"typedoc": "^0.14.0", "typedoc": "^0.14.0",
"typescript": "^3.4.5",
"wechaty-puppet-mock": "^0.15.5" "wechaty-puppet-mock": "^0.15.5"
}, },
"files_comment__whitelist_npm_publish": "http://stackoverflow.com/a/8617868/1123955", "files_comment__whitelist_npm_publish": "http://stackoverflow.com/a/8617868/1123955",
...@@ -162,17 +157,17 @@ ...@@ -162,17 +157,17 @@
"dist/src", "dist/src",
"src" "src"
], ],
"git": {
"scripts": {
"pre-push": "./scripts/pre-push.sh"
}
},
"publishConfig": { "publishConfig": {
"access": "public", "access": "public",
"tag": "latest" "tag": "next"
}, },
"collective": { "collective": {
"type": "opencollective", "type": "opencollective",
"url": "https://opencollective.com/wechaty" "url": "https://opencollective.com/wechaty"
},
"git": {
"scripts": {
"pre-push": "npx git-scripts-pre-push"
}
} }
} }
#!/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_
#!/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
#!/usr/bin/env ts-node #!/usr/bin/env ts-node
import {
createReadStream,
createWriteStream,
promises as fsPromises,
// link as linkCallback,
// unlink as unlinkCallback,
} from 'fs'
import {
Transform,
// TransformOptions,
} from 'stream'
import { promisify } from 'util'
import * as globCallback from 'glob'
const LICENSE = `/** const LICENSE = `/**
* Wechaty - https://github.com/chatie/wechaty * Wechaty - https://github.com/chatie/wechaty
* *
...@@ -19,32 +34,16 @@ const LICENSE = `/** ...@@ -19,32 +34,16 @@ const LICENSE = `/**
* *
*/` */`
import {
createReadStream,
createWriteStream,
promises as fsPromises,
// link as linkCallback,
// unlink as unlinkCallback,
} from 'fs'
import {
Transform,
TransformOptions,
} from 'stream'
import { promisify } from 'util'
import * as globCallback from 'glob'
class LicenseTransformer extends Transform { class LicenseTransformer extends Transform {
private lineBuf = '' private lineBuf = ''
private lineNum = 0 private lineNum = 0
private updating = false private updating = false
private updated = false private updated = false
constructor (options?: TransformOptions) { // constructor (options?: TransformOptions) {
super(options) // super(options)
} // }
public _transform (chunk: any, _: string /* encoding: string */, done: () => void) { public _transform (chunk: any, _: string /* encoding: string */, done: () => void) {
if (this.updated) { if (this.updated) {
...@@ -69,40 +68,40 @@ class LicenseTransformer extends Transform { ...@@ -69,40 +68,40 @@ class LicenseTransformer extends Transform {
const updatedLineList: string[] = [] const updatedLineList: string[] = []
buffer buffer
.split(/\n/) .split(/\n/)
.forEach(line => { .forEach(line => {
if (this.lineNum === 0 && line.startsWith('#!')) { if (this.lineNum === 0 && line.startsWith('#!')) {
updatedLineList.push(line)
} else if (this.updated) {
updatedLineList.push(line)
} else if (this.updating) {
if (/\*\//.test(line)) {
updatedLineList.push(line.replace(/.*\*\//, LICENSE))
this.updating = false
this.updated = true
} else {
// drop the old comments
}
} else { // not updating and not updated. searching...
if (!line) {
updatedLineList.push(line) updatedLineList.push(line)
} else if (/\s*\/\*\*/.test(line)) { // comment start } else if (this.updated) {
if (/\*\//.test(line)) { // comment end at the same line with start updatedLineList.push(line)
updatedLineList.push(line.replace(/\/\*\*.*\*\//, LICENSE)) } else if (this.updating) {
this.updated = true if (/\*\//.test(line)) {
updatedLineList.push(line.replace(/.*\*\//, LICENSE))
this.updating = false
this.updated = true
} else { } else {
this.updating = true // drop the old comments
}
} else { // not updating and not updated. searching...
if (!line) {
updatedLineList.push(line)
} else if (/\s*\/\*\*/.test(line)) { // comment start
if (/\*\//.test(line)) { // comment end at the same line with start
updatedLineList.push(line.replace(/\/\*\*.*\*\//, LICENSE))
this.updated = true
} else {
this.updating = true
}
} else { // not a comment. INSERT here
updatedLineList.push(LICENSE)
updatedLineList.push(line)
this.updated = true
} }
} else { // not a comment. INSERT here
updatedLineList.push(LICENSE)
updatedLineList.push(line)
this.updated = true
} }
}
this.lineBuf = line this.lineBuf = line
this.lineNum++ this.lineNum++
}) })
return updatedLineList.join('\n') return updatedLineList.join('\n')
} }
...@@ -122,7 +121,7 @@ async function updateLicense (file: string): Promise<void> { ...@@ -122,7 +121,7 @@ async function updateLicense (file: string): Promise<void> {
const writeStream = createWriteStream(tmpFile) const writeStream = createWriteStream(tmpFile)
const tranStream = new LicenseTransformer() const tranStream = new LicenseTransformer()
console.log(`Updating LICENSE for file ${file}...`) console.info(`Updating LICENSE for file ${file}...`)
await new Promise<void>((resolve, reject) => { await new Promise<void>((resolve, reject) => {
readStream readStream
.pipe(tranStream) .pipe(tranStream)
...@@ -152,8 +151,8 @@ async function main (): Promise<number> { ...@@ -152,8 +151,8 @@ async function main (): Promise<number> {
} }
main() main()
.then(process.exit) .then(process.exit)
.catch(e => { .catch(e => {
console.error(e) console.error(e)
process.exit(1) process.exit(1)
}) })
...@@ -25,7 +25,6 @@ import path from 'path' ...@@ -25,7 +25,6 @@ import path from 'path'
import qrImage from 'qr-image' import qrImage from 'qr-image'
import Raven from 'raven' import Raven from 'raven'
import readPkgUp from 'read-pkg-up'
import { log } from 'brolog' import { log } from 'brolog'
import { import {
...@@ -34,36 +33,34 @@ import { ...@@ -34,36 +33,34 @@ import {
import { import {
PuppetModuleName, PuppetModuleName,
} from './puppet-config' } from './puppet-config'
import { VERSION } from './version'
// https://github.com/Microsoft/TypeScript/issues/14151#issuecomment-280812617 // https://github.com/Microsoft/TypeScript/issues/14151#issuecomment-280812617
// if (!Symbol.asyncIterator) { // if (!Symbol.asyncIterator) {
// (Symbol as any).asyncIterator = Symbol.for('Symbol.asyncIterator') // (Symbol as any).asyncIterator = Symbol.for('Symbol.asyncIterator')
// } // }
const pkg = readPkgUp.sync({ cwd: __dirname })!.package
export const VERSION = pkg.version
/** /**
* Raven.io * Raven.io
*/ */
Raven.disableConsoleAlerts() Raven.disableConsoleAlerts()
Raven Raven
.config( .config(
isProduction() isProduction()
&& 'https://f6770399ee65459a82af82650231b22c:d8d11b283deb441e807079b8bb2c45cd@sentry.io/179672', && 'https://f6770399ee65459a82af82650231b22c:d8d11b283deb441e807079b8bb2c45cd@sentry.io/179672',
{ {
release: VERSION, release: VERSION,
tags: { tags: {
git_commit: '', git_commit: '',
platform: process.env.WECHATY_DOCKER platform: process.env.WECHATY_DOCKER
? 'docker' ? 'docker'
: os.platform(), : os.platform(),
},
}, },
}, )
) .install()
.install()
/* /*
try { try {
...@@ -248,6 +245,7 @@ export function isProduction (): boolean { ...@@ -248,6 +245,7 @@ export function isProduction (): boolean {
export { export {
log, log,
Raven, Raven,
VERSION,
} }
export const config = new Config() export const config = new Config()
#!/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')
})
/**
* This file will be overwrite when we publish NPM module
* by scripts/generate_version.sh
*/
export const VERSION = '0.0.0'
...@@ -3,7 +3,10 @@ ...@@ -3,7 +3,10 @@
// tslint:disable:no-var-requires // tslint:disable:no-var-requires
const isPR = require('is-pr') const isPR = require('is-pr')
import { Wechaty } from 'wechaty' import {
Wechaty,
VERSION,
} from 'wechaty'
function getBotList (): Wechaty[] { function getBotList (): Wechaty[] {
const botList = [ const botList = [
...@@ -25,6 +28,10 @@ function getBotList (): Wechaty[] { ...@@ -25,6 +28,10 @@ function getBotList (): Wechaty[] {
} }
async function main () { async function main () {
if (VERSION === '0.0.0') {
throw new Error('VERSION not set!')
}
const botList = getBotList() const botList = getBotList()
try { try {
await Promise.all( await Promise.all(
...@@ -46,8 +53,8 @@ async function main () { ...@@ -46,8 +53,8 @@ async function main () {
} }
main() main()
.then(process.exit) .then(process.exit)
.catch(e => { .catch(e => {
console.error(e) console.error(e)
process.exit(1) process.exit(1)
}) })
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册