From 25c581c7e485ec9a8abf0114fb6647bbffbe70ec Mon Sep 17 00:00:00 2001 From: "guo.xu" Date: Fri, 21 May 2021 10:55:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20release=E6=94=AF=E6=8C=81=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=BA=90=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/cli-types/src/types.ts | 2 ++ .../src/plugin/command/lint.ts | 13 ++++++--- .../src/plugin/command/release.ts | 29 ++++++++++++++----- .../src/plugin/config/release.ts | 4 +++ 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/packages/cli-types/src/types.ts b/packages/cli-types/src/types.ts index ca29e49..f765600 100644 --- a/packages/cli-types/src/types.ts +++ b/packages/cli-types/src/types.ts @@ -163,6 +163,8 @@ export interface IConfig extends IProjectConfig { release: { // before hooks for run lint test build... beforeRelease: ICmd[] + changelog: boolean + registry: string // in lenra mode to ensure pkg publish order order: string[] branch: string diff --git a/packages/preset-built-in/src/plugin/command/lint.ts b/packages/preset-built-in/src/plugin/command/lint.ts index be29c68..787f706 100644 --- a/packages/preset-built-in/src/plugin/command/lint.ts +++ b/packages/preset-built-in/src/plugin/command/lint.ts @@ -9,9 +9,12 @@ export default createPlugin({ 'lint', { desc: 'a command for lint js/css', - usage: `xus lint ` + usage: `xus lint `, + options: { + '--fix': 'lint and fix' + } }, - async () => { + async (cmdArgs) => { const lintConfig = api.projectConfig.lint let eslintRes = true let stylelintRes = true @@ -25,7 +28,7 @@ export default createPlugin({ cext.length > 0 ? cext : ['.js', '.jsx', '.ts', '.tsx', '.vue'] const args = [ 'eslint', - '--fix', + cmdArgs?.fix && '--fix', '--ext', ext.join(','), ...include @@ -46,7 +49,9 @@ export default createPlugin({ const ic = stylelint?.include || [] const include = ic.length > 0 ? ic : [] // ['./**/*.css', './**/*.vue', './**/*.less', './**/*.sass'] - const args = ['stylelint', ...include].concat(['--fix']) + const args = ['stylelint', ...include].concat( + [cmdArgs?.fix && '--fix'].filter(Boolean) + ) api.logger.debug(`run stylelint with `) api.logger.debug(args) stylelintRes = await runCmd('npx', args, { diff --git a/packages/preset-built-in/src/plugin/command/release.ts b/packages/preset-built-in/src/plugin/command/release.ts index ad3bb0c..bff2fc3 100644 --- a/packages/preset-built-in/src/plugin/command/release.ts +++ b/packages/preset-built-in/src/plugin/command/release.ts @@ -184,8 +184,8 @@ async function publish(targets: string[], ops: IReleaseOps) { // 3. generate changelog // 4. commit changes - const runRes = await [ - { + const cmds = [ + ops?.changelog && { bin: 'npx', args: ['xus', 'changelog'], message: { @@ -222,7 +222,16 @@ async function publish(targets: string[], ops: IReleaseOps) { failed: 'commit changes failed' } } - ].reduce((p, cmd) => { + ].filter(Boolean) as { + bin: string + args: string[] + message: { + start: string + succeed: string + failed: string + } + }[] + const runRes = await cmds.reduce((p, cmd) => { return p.then(() => runCmd(cmd.bin, cmd.args, cmd.message)) }, Promise.resolve(true)) if (!runRes) return @@ -311,11 +320,15 @@ async function workForPublish(pkgDir: string, ops: IReleaseOps) { const pkgname = pkgdir2pkgname[pkgDir] const saveCwd = process.cwd() process.chdir(root) - await runCmd('npm', ['publish', '--access', 'public'], { - start: `publish ${pkgname} start`, - succeed: `publish ${pkgname} succeed`, - failed: `publish ${pkgname} failed` - }) + await runCmd( + 'npm', + ['publish', '--access', 'public', '--registry', ops.registry], + { + start: `publish ${pkgname} start`, + succeed: `publish ${pkgname} succeed`, + failed: `publish ${pkgname} failed` + } + ) process.chdir(saveCwd) } diff --git a/packages/preset-built-in/src/plugin/config/release.ts b/packages/preset-built-in/src/plugin/config/release.ts index aab213e..603408a 100644 --- a/packages/preset-built-in/src/plugin/config/release.ts +++ b/packages/preset-built-in/src/plugin/config/release.ts @@ -10,6 +10,8 @@ type ICmd = { export type IReleaseConfig = { // before hooks for run lint test build... beforeRelease: ICmd[] + changelog: boolean + registry: string // in lenra mode to ensure pkg publish order order: string[] branch: string @@ -36,6 +38,8 @@ export const releaseSchema = createSchema((joi) => { export function defaultReleaseConfig(): IReleaseConfig { return { beforeRelease: [], + changelog: false, + registry: 'https://registry.npmjs.org/', order: [], branch: 'master' }