提交 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:
- npm test
# - if [ "$TRAVIS_OS_NAME" == 'linux' ]; then npm run coverage; fi
- echo "Testing Finished"
- echo "TRAVIS_TEST_RESULT=$TRAVIS_TEST_RESULT"
jobs:
include:
......@@ -45,18 +44,18 @@ jobs:
script:
- echo "NPM Pack Testing Started ..."
- npm version
- ./scripts/generate-version.sh
- npm run test:pack
- echo "NPM Pack Testing Finished."
- echo "TRAVIS_TEST_RESULT=$TRAVIS_TEST_RESULT"
- 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."
- echo "TRAVIS_TEST_RESULT=$TRAVIS_TEST_RESULT"
deploy:
provider: npm
......
......@@ -56,7 +56,7 @@
"alignment": {
"operatorPadding": "right",
"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.
"assignment": [1, 1], // The same as above.
"arrow": [1, 1], // The same as above.
......@@ -66,4 +66,8 @@
},
"editor.formatOnSave": false,
"python.pythonPath": "python3",
"eslint.validate": [
"javascript",
"typescript",
],
}
......@@ -52,7 +52,7 @@ if (!token) {
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)
const client = new IoClient({
......@@ -61,7 +61,7 @@ const client = new IoClient({
})
client.start()
.catch(onError.bind(client))
.catch(onError.bind(client))
// client.initWeb()
// .catch(onError.bind(client))
......
......@@ -3,7 +3,7 @@
import { PuppetManager } from '../src/puppet-manager'
PuppetManager.installAll()
.catch(e => {
console.error(e)
process.exit(1)
})
.catch(e => {
console.error(e)
process.exit(1)
})
......@@ -20,4 +20,4 @@
import { Wechaty } from '../src/wechaty'
console.log(Wechaty.version())
console.info(Wechaty.version())
......@@ -40,11 +40,11 @@ const bot = new Wechaty({
*
*/
bot
.on('logout', onLogout)
.on('login', onLogin)
.on('scan', onScan)
.on('error', onError)
.on('message', onMessage)
.on('logout', onLogout)
.on('login', onLogin)
.on('scan', onScan)
.on('error', onError)
.on('message', onMessage)
/**
*
......@@ -52,11 +52,11 @@ bot
*
*/
bot.start()
.catch(async e => {
console.error('Bot start() fail:', e)
await bot.stop()
process.exit(-1)
})
.catch(async e => {
console.error('Bot start() fail:', e)
await bot.stop()
process.exit(-1)
})
/**
*
......@@ -80,16 +80,16 @@ function onScan (qrcode: string, status: number) {
encodeURIComponent(qrcode),
].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) {
console.log(`${user.name()} login`)
console.info(`${user.name()} login`)
bot.say('Wechaty login').catch(console.error)
}
function onLogout (user: Contact) {
console.log(`${user.name()} logouted`)
console.info(`${user.name()} logouted`)
}
function onError (e: Error) {
......@@ -108,10 +108,10 @@ function onError (e: Error) {
*
*/
async function onMessage (msg: Message) {
console.log(msg.toString())
console.info(msg.toString())
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
}
......@@ -119,7 +119,7 @@ async function onMessage (msg: Message) {
|| !/^(ding|ping|bing|code)$/i.test(msg.text())
/*&& !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
}
......@@ -127,7 +127,7 @@ async function onMessage (msg: Message) {
* 1. reply 'dong'
*/
await msg.say('dong')
console.log('REPLY: dong')
console.info('REPLY: dong')
/**
* 2. reply image(qrcode image)
......@@ -135,7 +135,7 @@ async function onMessage (msg: Message) {
const fileBox = FileBox.fromUrl('https://chatie.io/wechaty/images/bot-qr-code.png')
await msg.say(fileBox)
console.log('REPLY: %s', fileBox.toString())
console.info('REPLY: %s', fileBox.toString())
/**
* 3. reply 'scan now!'
......@@ -175,4 +175,4 @@ upgrade me to more superpowers!
Please wait... I'm trying to login in...
`
console.log(welcome)
console.info(welcome)
......@@ -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",
"doctor": "npm run check-node-version && ts-node bin/doctor",
"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:ts": "tslint --project tsconfig.json && tsc --noEmit",
"lint:ts": "tsc --noEmit",
"lint:sh": "bash -n bin/*.sh",
"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",
......@@ -93,16 +94,16 @@
"qr-image": "^3.2.0",
"raven": "^2.6.2",
"read-pkg-up": "^6.0.0",
"semver": "^6.0.0",
"state-switch": "^0.6.2",
"watchdog": "^0.8.1",
"wechaty-puppet": "^0.15.9",
"ws": "^7.0.0"
},
"devDependencies": {
"@babel/core": "^7.0.1",
"@babel/node": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@chatie/tsconfig": "^0.4.2",
"@chatie/eslint-config": "^0.6.5",
"@chatie/git-scripts": "^0.2.1",
"@chatie/tsconfig": "^0.4.5",
"@types/blessed": "^0.1.10",
"@types/blue-tape": "^0.1.0",
"@types/cuid": "^1.3.0",
......@@ -120,7 +121,6 @@
"@types/semver": "^6.0.0",
"@types/sinon": "^7.0.4",
"@types/ws": "^6.0.0",
"@wwwouter/tslint-contrib": "^1.0.0",
"apiai": "^4.0.0",
"blessed": "^0.1.81",
"blessed-contrib": "^4.8.5",
......@@ -130,7 +130,6 @@
"cross-env": "^5.1.6",
"finis": "^0.4.1",
"fluent-ffmpeg": "^2.1.0",
"git-scripts": "git+https://github.com/nkzawa/git-scripts.git",
"gl-matrix": "^3.0.0",
"glob": "^7.1.0",
"is-pr": "^1.0.0",
......@@ -139,15 +138,11 @@
"nyc": "^14.0.0",
"qrcode-terminal": "^0.12.0",
"request": "^2.87.0",
"semver": "^6.0.0",
"shx": "^0.3.0",
"sinon": "^7.2.3",
"sloc": "^0.2.0",
"ts-node": "^8.0.2",
"tslint": "^5.11.0",
"tslint-config-standard": "^8.0.0",
"tstest": "^0.2.4",
"typedoc": "^0.14.0",
"typescript": "^3.4.5",
"wechaty-puppet-mock": "^0.15.5"
},
"files_comment__whitelist_npm_publish": "http://stackoverflow.com/a/8617868/1123955",
......@@ -162,17 +157,17 @@
"dist/src",
"src"
],
"git": {
"scripts": {
"pre-push": "./scripts/pre-push.sh"
}
},
"publishConfig": {
"access": "public",
"tag": "latest"
"tag": "next"
},
"collective": {
"type": "opencollective",
"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
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 = `/**
* Wechaty - https://github.com/chatie/wechaty
*
......@@ -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 {
private lineBuf = ''
private lineNum = 0
private updating = false
private updated = false
constructor (options?: TransformOptions) {
super(options)
}
// constructor (options?: TransformOptions) {
// super(options)
// }
public _transform (chunk: any, _: string /* encoding: string */, done: () => void) {
if (this.updated) {
......@@ -69,40 +68,40 @@ class LicenseTransformer extends Transform {
const updatedLineList: string[] = []
buffer
.split(/\n/)
.forEach(line => {
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) {
.split(/\n/)
.forEach(line => {
if (this.lineNum === 0 && line.startsWith('#!')) {
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 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 {
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.lineNum++
})
this.lineBuf = line
this.lineNum++
})
return updatedLineList.join('\n')
}
......@@ -122,7 +121,7 @@ async function updateLicense (file: string): Promise<void> {
const writeStream = createWriteStream(tmpFile)
const tranStream = new LicenseTransformer()
console.log(`Updating LICENSE for file ${file}...`)
console.info(`Updating LICENSE for file ${file}...`)
await new Promise<void>((resolve, reject) => {
readStream
.pipe(tranStream)
......@@ -152,8 +151,8 @@ async function main (): Promise<number> {
}
main()
.then(process.exit)
.catch(e => {
console.error(e)
process.exit(1)
})
.then(process.exit)
.catch(e => {
console.error(e)
process.exit(1)
})
......@@ -25,7 +25,6 @@ import path from 'path'
import qrImage from 'qr-image'
import Raven from 'raven'
import readPkgUp from 'read-pkg-up'
import { log } from 'brolog'
import {
......@@ -34,36 +33,34 @@ import {
import {
PuppetModuleName,
} from './puppet-config'
} from './puppet-config'
import { VERSION } from './version'
// https://github.com/Microsoft/TypeScript/issues/14151#issuecomment-280812617
// if (!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.disableConsoleAlerts()
Raven
.config(
isProduction()
&& 'https://f6770399ee65459a82af82650231b22c:d8d11b283deb441e807079b8bb2c45cd@sentry.io/179672',
{
release: VERSION,
tags: {
git_commit: '',
platform: process.env.WECHATY_DOCKER
? 'docker'
: os.platform(),
.config(
isProduction()
&& 'https://f6770399ee65459a82af82650231b22c:d8d11b283deb441e807079b8bb2c45cd@sentry.io/179672',
{
release: VERSION,
tags: {
git_commit: '',
platform: process.env.WECHATY_DOCKER
? 'docker'
: os.platform(),
},
},
},
)
.install()
)
.install()
/*
try {
......@@ -248,6 +245,7 @@ export function isProduction (): boolean {
export {
log,
Raven,
VERSION,
}
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 @@
// tslint:disable:no-var-requires
const isPR = require('is-pr')
import { Wechaty } from 'wechaty'
import {
Wechaty,
VERSION,
} from 'wechaty'
function getBotList (): Wechaty[] {
const botList = [
......@@ -25,6 +28,10 @@ function getBotList (): Wechaty[] {
}
async function main () {
if (VERSION === '0.0.0') {
throw new Error('VERSION not set!')
}
const botList = getBotList()
try {
await Promise.all(
......@@ -46,8 +53,8 @@ async function main () {
}
main()
.then(process.exit)
.catch(e => {
console.error(e)
process.exit(1)
})
.then(process.exit)
.catch(e => {
console.error(e)
process.exit(1)
})
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册