chore: add publish scripts
parent
c8d05944c8
commit
f1588739b4
|
@ -1,27 +1,27 @@
|
|||
'use strict'
|
||||
|
||||
// const install = require('./install')
|
||||
// const runCmd = require('./runCmd')
|
||||
const runCmd = require('./runCmd')
|
||||
const getBabelCommonConfig = require('./getBabelCommonConfig')
|
||||
const merge2 = require('merge2')
|
||||
// const { execSync } = require('child_process')
|
||||
const { execSync } = require('child_process')
|
||||
const through2 = require('through2')
|
||||
const transformLess = require('./transformLess')
|
||||
const webpack = require('webpack')
|
||||
const babel = require('gulp-babel')
|
||||
// const argv = require('minimist')(process.argv.slice(2))
|
||||
// const GitHub = require('github')
|
||||
const argv = require('minimist')(process.argv.slice(2))
|
||||
const GitHub = require('@octokit/rest')
|
||||
|
||||
// const packageJson = require(`${process.cwd()}/package.json`)
|
||||
const packageJson = require(`${process.cwd()}/package.json`)
|
||||
// const getNpm = require('./getNpm')
|
||||
// const selfPackage = require('../package.json')
|
||||
// const chalk = require('chalk')
|
||||
// const getNpmArgs = require('./utils/get-npm-args')
|
||||
|
||||
const chalk = require('chalk')
|
||||
const getNpmArgs = require('./utils/get-npm-args')
|
||||
const getChangelog = require('./utils/getChangelog')
|
||||
const path = require('path')
|
||||
// const watch = require('gulp-watch')
|
||||
const gulp = require('gulp')
|
||||
// const fs = require('fs')
|
||||
const fs = require('fs')
|
||||
const rimraf = require('rimraf')
|
||||
const replaceLib = require('./replaceLib')
|
||||
const stripCode = require('gulp-strip-code')
|
||||
|
@ -123,12 +123,118 @@ function compile (modules) {
|
|||
const source = [
|
||||
'components/**/*.js',
|
||||
'components/**/*.jsx',
|
||||
// '!components/vc-slider/**/*', // exclude vc-slider
|
||||
]
|
||||
const jsFilesStream = babelify(gulp.src(source), modules)
|
||||
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) => {
|
||||
dist(done)
|
||||
})
|
||||
|
@ -138,3 +244,29 @@ gulp.task('compile', ['compile-with-es'], () => {
|
|||
gulp.task('compile-with-es', () => {
|
||||
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()
|
||||
})
|
||||
|
||||
|
|
|
@ -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": {
|
||||
"version": "9.3.0",
|
||||
"resolved": "http://registry.npm.taobao.org/@types/node/download/@types/node-9.3.0.tgz",
|
||||
|
@ -297,6 +313,15 @@
|
|||
"integrity": "sha1-/ts5T58OAqqXaOcCvaI7UF+ufh8=",
|
||||
"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": {
|
||||
"version": "5.5.2",
|
||||
"resolved": "https://registry.npm.taobao.org/ajv/download/ajv-5.5.2.tgz",
|
||||
|
@ -1644,6 +1669,12 @@
|
|||
"integrity": "sha1-5tXqjF2tABMEpwsiY4RH9pyy+Ak=",
|
||||
"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": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/better-assert/-/better-assert-1.0.2.tgz",
|
||||
|
@ -1852,6 +1883,12 @@
|
|||
"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": {
|
||||
"version": "4.9.1",
|
||||
"resolved": "https://registry.npmjs.org/buffer/-/buffer-4.9.1.tgz",
|
||||
|
@ -4038,6 +4075,15 @@
|
|||
"integrity": "sha1-9yLXdpr4i9M7wT7GYF4fkpZrgtk=",
|
||||
"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": {
|
||||
"version": "0.1.5",
|
||||
"resolved": "https://registry.npmjs.org/es6-set/-/es6-set-0.1.5.tgz",
|
||||
|
@ -4678,6 +4724,14 @@
|
|||
"dev": true,
|
||||
"requires": {
|
||||
"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"
|
||||
}
|
||||
},
|
||||
"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": {
|
||||
"version": "0.17.4",
|
||||
"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=",
|
||||
"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": {
|
||||
"version": "0.14.3",
|
||||
"resolved": "https://registry.npmjs.org/husky/-/husky-0.14.3.tgz",
|
||||
|
@ -9760,9 +9834,9 @@
|
|||
}
|
||||
},
|
||||
"minimist": {
|
||||
"version": "0.0.8",
|
||||
"resolved": "http://r.cnpmjs.org/minimist/download/minimist-0.0.8.tgz",
|
||||
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=",
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
|
||||
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=",
|
||||
"dev": true
|
||||
},
|
||||
"minimist-options": {
|
||||
|
@ -9803,6 +9877,14 @@
|
|||
"dev": true,
|
||||
"requires": {
|
||||
"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": {
|
||||
|
@ -10010,6 +10092,12 @@
|
|||
"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": {
|
||||
"version": "0.6.33",
|
||||
"resolved": "https://registry.npm.taobao.org/node-forge/download/node-forge-0.6.33.tgz",
|
||||
|
@ -10378,10 +10466,16 @@
|
|||
"integrity": "sha1-2j6nRob6IaGaERwybpDrFaAZZoY=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"minimist": "0.0.8",
|
||||
"minimist": "0.0.10",
|
||||
"wordwrap": "0.0.3"
|
||||
},
|
||||
"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": {
|
||||
"version": "0.0.3",
|
||||
"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": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npm.taobao.org/use/download/use-2.0.2.tgz",
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
"site": "node scripts/run.js site-dist",
|
||||
"copy": "node scripts/run.js copy-html",
|
||||
"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",
|
||||
"lint": "eslint -c ./.eslintrc --fix --ext .jsx,.js,.vue ./components",
|
||||
"lint:style": "stylelint \"./examples/**/*.less\" --fix --syntax less",
|
||||
|
@ -47,6 +49,7 @@
|
|||
"lint"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@octokit/rest": "^15.2.6",
|
||||
"autoprefixer": "^8.1.0",
|
||||
"babel-cli": "^6.26.0",
|
||||
"babel-core": "^6.26.0",
|
||||
|
@ -106,6 +109,7 @@
|
|||
"markdown-it-anchor": "^4.0.0",
|
||||
"marked": "^0.3.7",
|
||||
"merge2": "^1.2.1",
|
||||
"minimist": "^1.2.0",
|
||||
"mkdirp": "^0.5.1",
|
||||
"mocha": "^3.2.0",
|
||||
"postcss": "^6.0.20",
|
||||
|
@ -157,4 +161,4 @@
|
|||
"vue-types": "^1.0.2",
|
||||
"warning": "^3.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue