chore: add publish scripts

pull/165/head
tjz 7 years ago
parent c8d05944c8
commit f1588739b4

@ -1,27 +1,27 @@
'use strict' 'use strict'
// const install = require('./install') // const install = require('./install')
// const runCmd = require('./runCmd') const runCmd = require('./runCmd')
const getBabelCommonConfig = require('./getBabelCommonConfig') const getBabelCommonConfig = require('./getBabelCommonConfig')
const merge2 = require('merge2') const merge2 = require('merge2')
// const { execSync } = require('child_process') const { execSync } = require('child_process')
const through2 = require('through2') const through2 = require('through2')
const transformLess = require('./transformLess') const transformLess = require('./transformLess')
const webpack = require('webpack') const webpack = require('webpack')
const babel = require('gulp-babel') const babel = require('gulp-babel')
// const argv = require('minimist')(process.argv.slice(2)) const argv = require('minimist')(process.argv.slice(2))
// const GitHub = require('github') const GitHub = require('@octokit/rest')
// const packageJson = require(`${process.cwd()}/package.json`) const packageJson = require(`${process.cwd()}/package.json`)
// const getNpm = require('./getNpm') // const getNpm = require('./getNpm')
// const selfPackage = require('../package.json') // const selfPackage = require('../package.json')
// const chalk = require('chalk') const chalk = require('chalk')
// const getNpmArgs = require('./utils/get-npm-args') const getNpmArgs = require('./utils/get-npm-args')
const getChangelog = require('./utils/getChangelog')
const path = require('path') const path = require('path')
// const watch = require('gulp-watch') // const watch = require('gulp-watch')
const gulp = require('gulp') const gulp = require('gulp')
// const fs = require('fs') const fs = require('fs')
const rimraf = require('rimraf') const rimraf = require('rimraf')
const replaceLib = require('./replaceLib') const replaceLib = require('./replaceLib')
const stripCode = require('gulp-strip-code') const stripCode = require('gulp-strip-code')
@ -123,12 +123,118 @@ function compile (modules) {
const source = [ const source = [
'components/**/*.js', 'components/**/*.js',
'components/**/*.jsx', 'components/**/*.jsx',
// '!components/vc-slider/**/*', // exclude vc-slider
] ]
const jsFilesStream = babelify(gulp.src(source), modules) const jsFilesStream = babelify(gulp.src(source), modules)
return merge2([less, jsFilesStream, assets]) return merge2([less, jsFilesStream, assets])
} }
function tag () {
console.log('tagging')
const { version } = packageJson
execSync(`git tag ${version}`)
execSync(`git push origin ${version}:${version}`)
execSync('git push origin master:master')
console.log('tagged')
}
function githubRelease () {
const changlogFiles = [
path.join(cwd, 'CHANGELOG.en-US.md'),
path.join(cwd, 'CHANGELOG.zh-CN.md'),
]
console.log('creating release on GitHub')
if (!process.env.GITHUB_TOKEN) {
console.log('no GitHub token found, skip')
return
}
if (!changlogFiles.every(file => fs.existsSync(file))) {
console.log('no changelog found, skip')
return
}
const github = new GitHub()
github.authenticate({
type: 'oauth',
token: process.env.GITHUB_TOKEN,
})
const date = new Date()
const { version } = packageJson
const enChangelog = getChangelog(changlogFiles[0], version)
const cnChangelog = getChangelog(changlogFiles[1], version)
const changelog = [
`\`${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}\``,
enChangelog,
'\n',
'---',
'\n',
cnChangelog,
].join('\n')
const [_, owner, repo] = execSync('git remote get-url origin') // eslint-disable-line
.toString()
.match(/github.com[:/](.+)\/(.+)\.git/)
github.repos.createRelease({
owner,
repo,
tag_name: version,
name: version,
body: changelog,
})
}
gulp.task('check-git', (done) => {
runCmd('git', ['status', '--porcelain'], (code, result) => {
if (/^\?\?/m.test(result)) {
return done(`There are untracked files in the working tree.\n${result}
`)
}
if (/^([ADRM]| [ADRM])/m.test(result)) {
return done(`There are uncommitted changes in the working tree.\n${result}
`)
}
return done()
})
})
function publish (tagString, done) {
let args = ['publish', '--with-antd-tools']
if (tagString) {
args = args.concat(['--tag', tagString])
}
const publishNpm = process.env.PUBLISH_NPM_CLI || 'npm'
runCmd(publishNpm, args, (code) => {
tag()
githubRelease()
done(code)
})
}
function pub (done) {
dist((code) => {
if (code) {
done(code)
return
}
const notOk = !packageJson.version.match(/^\d+\.\d+\.\d+$/)
let tagString
if (argv['npm-tag']) {
tagString = argv['npm-tag']
}
if (!tagString && notOk) {
tagString = 'next'
}
if (packageJson.scripts['pre-publish']) {
runCmd('npm', ['run', 'pre-publish'], (code2) => {
if (code2) {
done(code2)
return
}
publish(tagString, done)
})
} else {
publish(tagString, done)
}
})
}
gulp.task('dist', ['compile'], (done) => { gulp.task('dist', ['compile'], (done) => {
dist(done) dist(done)
}) })
@ -138,3 +244,29 @@ gulp.task('compile', ['compile-with-es'], () => {
gulp.task('compile-with-es', () => { gulp.task('compile-with-es', () => {
compile(false) compile(false)
}) })
gulp.task('pub', ['check-git', 'compile'], (done) => {
pub(done)
})
function reportError () {
console.log(chalk.bgRed('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'))
console.log(chalk.bgRed('!! `npm publish` is forbidden for this package. !!'))
console.log(chalk.bgRed('!! Use `npm run pub` instead. !!'))
console.log(chalk.bgRed('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'))
}
gulp.task('guard', (done) => {
const npmArgs = getNpmArgs()
if (npmArgs) {
for (let arg = npmArgs.shift(); arg; arg = npmArgs.shift()) {
if (/^pu(b(l(i(sh?)?)?)?)?$/.test(arg) && npmArgs.indexOf('--with-antd-tools') < 0) {
reportError()
done(1)
return
}
}
}
done()
})

108
package-lock.json generated

@ -164,6 +164,22 @@
} }
} }
}, },
"@octokit/rest": {
"version": "15.2.6",
"resolved": "https://registry.npmjs.org/@octokit/rest/-/rest-15.2.6.tgz",
"integrity": "sha512-KcqG0zjnjzUqn7wczz/fKiueNpTLiAI7erhUG6bXWAsYKJJlqnwYonFSXrMW/nmes5y+qOk4uSyHBh1mdRXdVQ==",
"dev": true,
"requires": {
"before-after-hook": "1.1.0",
"btoa-lite": "1.0.0",
"debug": "3.1.0",
"http-proxy-agent": "2.1.0",
"https-proxy-agent": "2.2.1",
"lodash": "4.17.5",
"node-fetch": "2.1.2",
"url-template": "2.0.8"
}
},
"@types/node": { "@types/node": {
"version": "9.3.0", "version": "9.3.0",
"resolved": "http://registry.npm.taobao.org/@types/node/download/@types/node-9.3.0.tgz", "resolved": "http://registry.npm.taobao.org/@types/node/download/@types/node-9.3.0.tgz",
@ -297,6 +313,15 @@
"integrity": "sha1-/ts5T58OAqqXaOcCvaI7UF+ufh8=", "integrity": "sha1-/ts5T58OAqqXaOcCvaI7UF+ufh8=",
"dev": true "dev": true
}, },
"agent-base": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/agent-base/-/agent-base-4.2.0.tgz",
"integrity": "sha512-c+R/U5X+2zz2+UCrCFv6odQzJdoqI+YecuhnAJLa1zYaMc13zPfwMwZrr91Pd1DYNo/yPRbiM4WVf9whgwFsIg==",
"dev": true,
"requires": {
"es6-promisify": "5.0.0"
}
},
"ajv": { "ajv": {
"version": "5.5.2", "version": "5.5.2",
"resolved": "https://registry.npm.taobao.org/ajv/download/ajv-5.5.2.tgz", "resolved": "https://registry.npm.taobao.org/ajv/download/ajv-5.5.2.tgz",
@ -1644,6 +1669,12 @@
"integrity": "sha1-5tXqjF2tABMEpwsiY4RH9pyy+Ak=", "integrity": "sha1-5tXqjF2tABMEpwsiY4RH9pyy+Ak=",
"dev": true "dev": true
}, },
"before-after-hook": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-1.1.0.tgz",
"integrity": "sha512-VOMDtYPwLbIncTxNoSzRyvaMxtXmLWLUqr8k5AfC1BzLk34HvBXaQX8snOwQZ4c0aX8aSERqtJSiI9/m2u5kuA==",
"dev": true
},
"better-assert": { "better-assert": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/better-assert/-/better-assert-1.0.2.tgz", "resolved": "https://registry.npmjs.org/better-assert/-/better-assert-1.0.2.tgz",
@ -1852,6 +1883,12 @@
"electron-to-chromium": "1.3.31" "electron-to-chromium": "1.3.31"
} }
}, },
"btoa-lite": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/btoa-lite/-/btoa-lite-1.0.0.tgz",
"integrity": "sha1-M3dm2hWAEhD92VbCLpxokaudAzc=",
"dev": true
},
"buffer": { "buffer": {
"version": "4.9.1", "version": "4.9.1",
"resolved": "https://registry.npmjs.org/buffer/-/buffer-4.9.1.tgz", "resolved": "https://registry.npmjs.org/buffer/-/buffer-4.9.1.tgz",
@ -4038,6 +4075,15 @@
"integrity": "sha1-9yLXdpr4i9M7wT7GYF4fkpZrgtk=", "integrity": "sha1-9yLXdpr4i9M7wT7GYF4fkpZrgtk=",
"dev": true "dev": true
}, },
"es6-promisify": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/es6-promisify/-/es6-promisify-5.0.0.tgz",
"integrity": "sha1-UQnWLz5W6pZ8S2NQWu8IKRyKUgM=",
"dev": true,
"requires": {
"es6-promise": "4.2.2"
}
},
"es6-set": { "es6-set": {
"version": "0.1.5", "version": "0.1.5",
"resolved": "https://registry.npmjs.org/es6-set/-/es6-set-0.1.5.tgz", "resolved": "https://registry.npmjs.org/es6-set/-/es6-set-0.1.5.tgz",
@ -4678,6 +4724,14 @@
"dev": true, "dev": true,
"requires": { "requires": {
"minimist": "0.0.8" "minimist": "0.0.8"
},
"dependencies": {
"minimist": {
"version": "0.0.8",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=",
"dev": true
}
} }
} }
} }
@ -7429,6 +7483,16 @@
"requires-port": "1.0.0" "requires-port": "1.0.0"
} }
}, },
"http-proxy-agent": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-2.1.0.tgz",
"integrity": "sha512-qwHbBLV7WviBl0rQsOzH6o5lwyOIvwp/BdFnvVxXORldu5TmjFfjzBcWUWS5kWAZhmv+JtiDhSuQCp4sBfbIgg==",
"dev": true,
"requires": {
"agent-base": "4.2.0",
"debug": "3.1.0"
}
},
"http-proxy-middleware": { "http-proxy-middleware": {
"version": "0.17.4", "version": "0.17.4",
"resolved": "https://registry.npmjs.org/http-proxy-middleware/-/http-proxy-middleware-0.17.4.tgz", "resolved": "https://registry.npmjs.org/http-proxy-middleware/-/http-proxy-middleware-0.17.4.tgz",
@ -7475,6 +7539,16 @@
"integrity": "sha1-7AbBDgo0wPL68Zn3/X/Hj//QPHM=", "integrity": "sha1-7AbBDgo0wPL68Zn3/X/Hj//QPHM=",
"dev": true "dev": true
}, },
"https-proxy-agent": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.2.1.tgz",
"integrity": "sha512-HPCTS1LW51bcyMYbxUIOO4HEOlQ1/1qRaFWcyxvwaqUS9TY88aoEuHUY33kuAh1YhVVaDQhLZsnPd+XNARWZlQ==",
"dev": true,
"requires": {
"agent-base": "4.2.0",
"debug": "3.1.0"
}
},
"husky": { "husky": {
"version": "0.14.3", "version": "0.14.3",
"resolved": "https://registry.npmjs.org/husky/-/husky-0.14.3.tgz", "resolved": "https://registry.npmjs.org/husky/-/husky-0.14.3.tgz",
@ -9760,9 +9834,9 @@
} }
}, },
"minimist": { "minimist": {
"version": "0.0.8", "version": "1.2.0",
"resolved": "http://r.cnpmjs.org/minimist/download/minimist-0.0.8.tgz", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=",
"dev": true "dev": true
}, },
"minimist-options": { "minimist-options": {
@ -9803,6 +9877,14 @@
"dev": true, "dev": true,
"requires": { "requires": {
"minimist": "0.0.8" "minimist": "0.0.8"
},
"dependencies": {
"minimist": {
"version": "0.0.8",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=",
"dev": true
}
} }
}, },
"mocha": { "mocha": {
@ -10010,6 +10092,12 @@
"lower-case": "1.1.4" "lower-case": "1.1.4"
} }
}, },
"node-fetch": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.1.2.tgz",
"integrity": "sha1-q4hOjn5X44qUR1POxwb3iNF2i7U=",
"dev": true
},
"node-forge": { "node-forge": {
"version": "0.6.33", "version": "0.6.33",
"resolved": "https://registry.npm.taobao.org/node-forge/download/node-forge-0.6.33.tgz", "resolved": "https://registry.npm.taobao.org/node-forge/download/node-forge-0.6.33.tgz",
@ -10378,10 +10466,16 @@
"integrity": "sha1-2j6nRob6IaGaERwybpDrFaAZZoY=", "integrity": "sha1-2j6nRob6IaGaERwybpDrFaAZZoY=",
"dev": true, "dev": true,
"requires": { "requires": {
"minimist": "0.0.8", "minimist": "0.0.10",
"wordwrap": "0.0.3" "wordwrap": "0.0.3"
}, },
"dependencies": { "dependencies": {
"minimist": {
"version": "0.0.10",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz",
"integrity": "sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8=",
"dev": true
},
"wordwrap": { "wordwrap": {
"version": "0.0.3", "version": "0.0.3",
"resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.3.tgz", "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.3.tgz",
@ -16992,6 +17086,12 @@
} }
} }
}, },
"url-template": {
"version": "2.0.8",
"resolved": "https://registry.npmjs.org/url-template/-/url-template-2.0.8.tgz",
"integrity": "sha1-/FZaPMy/93MMd19WQflVV5FDnyE=",
"dev": true
},
"use": { "use": {
"version": "2.0.2", "version": "2.0.2",
"resolved": "https://registry.npm.taobao.org/use/download/use-2.0.2.tgz", "resolved": "https://registry.npm.taobao.org/use/download/use-2.0.2.tgz",

@ -27,6 +27,8 @@
"site": "node scripts/run.js site-dist", "site": "node scripts/run.js site-dist",
"copy": "node scripts/run.js copy-html", "copy": "node scripts/run.js copy-html",
"compile": "node antd-tools/cli/run.js compile", "compile": "node antd-tools/cli/run.js compile",
"pub": "node antd-tools/cli/run.js pub",
"prepublish": "node antd-tools/cli/run.js guard",
"dist": "node antd-tools/cli/run.js dist", "dist": "node antd-tools/cli/run.js dist",
"lint": "eslint -c ./.eslintrc --fix --ext .jsx,.js,.vue ./components", "lint": "eslint -c ./.eslintrc --fix --ext .jsx,.js,.vue ./components",
"lint:style": "stylelint \"./examples/**/*.less\" --fix --syntax less", "lint:style": "stylelint \"./examples/**/*.less\" --fix --syntax less",
@ -47,6 +49,7 @@
"lint" "lint"
], ],
"devDependencies": { "devDependencies": {
"@octokit/rest": "^15.2.6",
"autoprefixer": "^8.1.0", "autoprefixer": "^8.1.0",
"babel-cli": "^6.26.0", "babel-cli": "^6.26.0",
"babel-core": "^6.26.0", "babel-core": "^6.26.0",
@ -106,6 +109,7 @@
"markdown-it-anchor": "^4.0.0", "markdown-it-anchor": "^4.0.0",
"marked": "^0.3.7", "marked": "^0.3.7",
"merge2": "^1.2.1", "merge2": "^1.2.1",
"minimist": "^1.2.0",
"mkdirp": "^0.5.1", "mkdirp": "^0.5.1",
"mocha": "^3.2.0", "mocha": "^3.2.0",
"postcss": "^6.0.20", "postcss": "^6.0.20",

Loading…
Cancel
Save