mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-05 19:41:42 +08:00
refactor(cli): rewrite release command (#12133)
* refactor(cli): rewrite release command * fix: duplicated build * fix: no git check * feat: rollback version * chore: release config * chore: add release config
This commit is contained in:
parent
2513ad1217
commit
e6a0694807
@ -9,7 +9,7 @@
|
||||
"scripts": {
|
||||
"dev": "tsc --watch",
|
||||
"build": "rimraf ./lib && tsc",
|
||||
"release": "pnpm build & release-it",
|
||||
"release": "vant-cli release",
|
||||
"prepare": "pnpm build"
|
||||
},
|
||||
"files": [
|
||||
@ -32,7 +32,6 @@
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/fs-extra": "^11.0.1",
|
||||
"release-it": "^16.1.3",
|
||||
"rimraf": "^5.0.0",
|
||||
"typescript": "^5.0.4"
|
||||
},
|
||||
@ -42,11 +41,5 @@
|
||||
"fs-extra": "^11.1.0",
|
||||
"enquirer": "2.3.6",
|
||||
"picocolors": "^1.0.0"
|
||||
},
|
||||
"release-it": {
|
||||
"git": {
|
||||
"tag": false,
|
||||
"commitMessage": "release: create-vant-cli-app v${version}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
5
packages/create-vant-cli-app/vant.config.mjs
Normal file
5
packages/create-vant-cli-app/vant.config.mjs
Normal file
@ -0,0 +1,5 @@
|
||||
export default {
|
||||
build: {
|
||||
packageManager: 'pnpm',
|
||||
},
|
||||
};
|
@ -21,7 +21,7 @@
|
||||
"build:types": "tsc -p ./tsconfig.json --emitDeclarationOnly",
|
||||
"build:bundle": "node ./build.js",
|
||||
"build": "pnpm clean && pnpm build:bundle && pnpm build:types",
|
||||
"release": "pnpm build && release-it",
|
||||
"release": "vant-cli release",
|
||||
"prepare": "pnpm build"
|
||||
},
|
||||
"publishConfig": {
|
||||
@ -38,14 +38,7 @@
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"esbuild": "^0.18.11",
|
||||
"release-it": "^16.1.3",
|
||||
"rimraf": "^5.0.0",
|
||||
"typescript": "^5.0.4"
|
||||
},
|
||||
"release-it": {
|
||||
"git": {
|
||||
"tag": false,
|
||||
"commitMessage": "release: @vant/area-data v${version}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
5
packages/vant-area-data/vant.config.mjs
Normal file
5
packages/vant-area-data/vant.config.mjs
Normal file
@ -0,0 +1,5 @@
|
||||
export default {
|
||||
build: {
|
||||
packageManager: 'pnpm',
|
||||
},
|
||||
};
|
@ -50,7 +50,7 @@ npx vant-cli dev
|
||||
|
||||
### release
|
||||
|
||||
发布组件库,发布前会自动执行 build 和 changelog 命令,并通过 [release-it](https://github.com/release-it/release-it) 发布 npm 包。
|
||||
发布组件库,发布前会自动执行 build 和 changelog 命令,并按照流程发布 npm 包。
|
||||
|
||||
### changelog
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
"scripts": {
|
||||
"dev": "tsc --watch",
|
||||
"build": "rimraf ./lib && tsc",
|
||||
"release": "pnpm build & release-it",
|
||||
"release": "vant-cli release",
|
||||
"prepare": "pnpm build"
|
||||
},
|
||||
"files": [
|
||||
@ -63,6 +63,7 @@
|
||||
"esbuild": "^0.18.11",
|
||||
"eslint": "^8.31.0",
|
||||
"execa": "^6.1.0",
|
||||
"enquirer": "2.3.6",
|
||||
"fast-glob": "^3.2.11",
|
||||
"fs-extra": "^11.1.0",
|
||||
"hash-sum": "^2.0.0",
|
||||
@ -82,18 +83,11 @@
|
||||
"postcss": "^8.4.23",
|
||||
"postcss-load-config": "^4.0.1",
|
||||
"prettier": "^3.0.0",
|
||||
"release-it": "^16.1.3",
|
||||
"terser": "^5.16.1",
|
||||
"transliteration": "^2.3.5",
|
||||
"typescript": "^5.0.4",
|
||||
"vite": "^4.4.2",
|
||||
"vite-plugin-md": "^0.11.9",
|
||||
"vue-router": "^4.1.6"
|
||||
},
|
||||
"release-it": {
|
||||
"git": {
|
||||
"tag": false,
|
||||
"commitMessage": "release: @vant/cli v${version}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,103 @@
|
||||
/* eslint-disable no-template-curly-in-string */
|
||||
import releaseIt from 'release-it';
|
||||
import { join, dirname } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import fse from 'fs-extra';
|
||||
import { join } from 'node:path';
|
||||
import color from 'picocolors';
|
||||
import enquirer from 'enquirer';
|
||||
import { consola } from '../common/logger.js';
|
||||
import { getPackageManager } from '../common/manager.js';
|
||||
import { execSync } from 'child_process';
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const PLUGIN_PATH = join(__dirname, '../compiler/vant-cli-release-plugin.js');
|
||||
function logCurrentVersion(cwd: string) {
|
||||
const pkgJson = join(cwd, 'package.json');
|
||||
const pkg = fse.readJSONSync(pkgJson);
|
||||
consola.success(`${color.bold('Current package:')} ${color.green(pkg.name)}`);
|
||||
consola.success(
|
||||
`${color.bold('Current version:')} ${color.green(pkg.version)}`,
|
||||
);
|
||||
return {
|
||||
pkgName: pkg.name,
|
||||
currentVersion: pkg.version,
|
||||
};
|
||||
}
|
||||
|
||||
async function getNewVersion() {
|
||||
const { version } = await enquirer.prompt<{ version: string }>({
|
||||
type: 'input',
|
||||
name: 'version',
|
||||
message: 'Version to release:',
|
||||
});
|
||||
return version;
|
||||
}
|
||||
|
||||
function getNpmTag(version: string, forceTag?: string) {
|
||||
let tag: string;
|
||||
|
||||
if (forceTag) {
|
||||
tag = forceTag;
|
||||
} else if (version.includes('beta')) {
|
||||
tag = 'beta';
|
||||
} else if (version.includes('alpha')) {
|
||||
tag = 'alpha';
|
||||
} else if (version.includes('rc')) {
|
||||
tag = 'rc';
|
||||
} else {
|
||||
tag = 'latest';
|
||||
}
|
||||
|
||||
consola.success(`${color.bold('Npm tag:')} ${color.green(tag)}`);
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
function setPkgVersion(version: string, cwd: string) {
|
||||
const pkgJson = join(cwd, 'package.json');
|
||||
const pkg = fse.readJSONSync(pkgJson);
|
||||
pkg.version = version;
|
||||
fse.writeJSONSync(pkgJson, pkg, { spaces: 2 });
|
||||
}
|
||||
|
||||
function buildPackage(packageManager: string) {
|
||||
const command = `${packageManager} run build`;
|
||||
consola.success(`${color.bold('Build package:')} ${color.green(command)}`);
|
||||
execSync(command, { stdio: 'inherit' });
|
||||
}
|
||||
|
||||
function generateChangelog() {
|
||||
execSync('vant-cli changelog', { stdio: 'inherit' });
|
||||
}
|
||||
|
||||
function publishPackage(packageManager: string, tag: string) {
|
||||
let command = `${packageManager} publish --tag ${tag}`;
|
||||
|
||||
if (packageManager === 'pnpm') {
|
||||
command += ' --no-git-checks';
|
||||
}
|
||||
|
||||
execSync(command, { stdio: 'inherit' });
|
||||
}
|
||||
|
||||
function commitChanges(pkgName: string, version: string) {
|
||||
const message = `release: ${pkgName} v${version}`;
|
||||
execSync(`git add -A && git commit -m "${message}"`, { stdio: 'inherit' });
|
||||
}
|
||||
|
||||
export async function release(command: { tag?: string }) {
|
||||
await releaseIt({
|
||||
plugins: {
|
||||
[PLUGIN_PATH]: {},
|
||||
},
|
||||
npm: {
|
||||
tag: command.tag,
|
||||
},
|
||||
git: {
|
||||
tagName: 'v${version}',
|
||||
commitMessage: 'release: ${version}',
|
||||
},
|
||||
});
|
||||
const cwd = process.cwd();
|
||||
const { pkgName, currentVersion } = logCurrentVersion(cwd);
|
||||
const version = await getNewVersion();
|
||||
const tag = getNpmTag(version, command.tag);
|
||||
const packageManager = getPackageManager();
|
||||
|
||||
setPkgVersion(version, cwd);
|
||||
|
||||
try {
|
||||
buildPackage(packageManager);
|
||||
generateChangelog();
|
||||
} catch (err) {
|
||||
consola.error('Failed to build package, rollback to the previous version.');
|
||||
setPkgVersion(currentVersion, cwd);
|
||||
throw err;
|
||||
}
|
||||
|
||||
publishPackage(packageManager, tag);
|
||||
commitChanges(pkgName, version);
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ export function hasYarn() {
|
||||
return hasYarnCache;
|
||||
}
|
||||
|
||||
function getPackageManager() {
|
||||
export function getPackageManager() {
|
||||
const { build } = getVantConfig();
|
||||
|
||||
if (build?.packageManager) {
|
||||
|
@ -1,14 +0,0 @@
|
||||
import { Plugin } from 'release-it';
|
||||
import { execSync } from 'child_process';
|
||||
|
||||
class VantCliReleasePlugin extends Plugin {
|
||||
async beforeRelease() {
|
||||
// log an empty line
|
||||
console.log('');
|
||||
|
||||
execSync('vant-cli build', { stdio: 'inherit' });
|
||||
execSync('vant-cli changelog', { stdio: 'inherit' });
|
||||
}
|
||||
}
|
||||
|
||||
export default VantCliReleasePlugin;
|
1
packages/vant-cli/src/module.d.ts
vendored
1
packages/vant-cli/src/module.d.ts
vendored
@ -1,5 +1,4 @@
|
||||
// some modules with missing type definitions
|
||||
declare module 'hash-sum';
|
||||
declare module '@babel/core';
|
||||
declare module 'release-it';
|
||||
declare module 'conventional-changelog';
|
||||
|
5
packages/vant-cli/vant.config.mjs
Normal file
5
packages/vant-cli/vant.config.mjs
Normal file
@ -0,0 +1,5 @@
|
||||
export default {
|
||||
build: {
|
||||
packageManager: 'pnpm',
|
||||
},
|
||||
};
|
@ -25,7 +25,7 @@
|
||||
"build:types": "tsc -p ./tsconfig.json --emitDeclarationOnly",
|
||||
"build:bundle": "node ./build.js",
|
||||
"build": "pnpm clean && pnpm build:bundle && pnpm build:types",
|
||||
"release": "pnpm build && release-it"
|
||||
"release": "vant-cli release"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -40,14 +40,7 @@
|
||||
"vant": "workspace:*",
|
||||
"vue": "^3.3.4",
|
||||
"esbuild": "^0.18.11",
|
||||
"release-it": "^16.1.3",
|
||||
"rimraf": "^5.0.0",
|
||||
"typescript": "^5.0.4"
|
||||
},
|
||||
"release-it": {
|
||||
"git": {
|
||||
"tag": false,
|
||||
"commitMessage": "release: @vant/compat v${version}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
5
packages/vant-compat/vant.config.mjs
Normal file
5
packages/vant-compat/vant.config.mjs
Normal file
@ -0,0 +1,5 @@
|
||||
export default {
|
||||
build: {
|
||||
packageManager: 'pnpm',
|
||||
},
|
||||
};
|
@ -8,6 +8,7 @@
|
||||
"registry": "https://registry.npmjs.org/"
|
||||
},
|
||||
"scripts": {
|
||||
"release": "vant-cli release",
|
||||
"update:deps": "pnpm update --latest --interactive"
|
||||
},
|
||||
"repository": {
|
||||
|
5
packages/vant-eslint-config/vant.config.mjs
Normal file
5
packages/vant-eslint-config/vant.config.mjs
Normal file
@ -0,0 +1,5 @@
|
||||
export default {
|
||||
build: {
|
||||
packageManager: 'pnpm',
|
||||
},
|
||||
};
|
@ -8,7 +8,7 @@
|
||||
"src"
|
||||
],
|
||||
"scripts": {
|
||||
"release": "release-it"
|
||||
"release": "vant-cli release"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public",
|
||||
@ -21,16 +21,5 @@
|
||||
},
|
||||
"bugs": "https://github.com/vant-ui/vant/issues",
|
||||
"author": "chenjiahan",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"release-it": "^16.1.3"
|
||||
},
|
||||
"release-it": {
|
||||
"git": {
|
||||
"tag": false,
|
||||
"commitMessage": "release: @vant/icons v${version}",
|
||||
"addUntrackedFiles": true,
|
||||
"requireCleanWorkingDir": false
|
||||
}
|
||||
}
|
||||
"license": "MIT"
|
||||
}
|
||||
|
5
packages/vant-icons/vant.config.mjs
Normal file
5
packages/vant-icons/vant.config.mjs
Normal file
@ -0,0 +1,5 @@
|
||||
export default {
|
||||
build: {
|
||||
packageManager: 'pnpm',
|
||||
},
|
||||
};
|
@ -25,7 +25,7 @@
|
||||
"build:types": "tsc -p ./tsconfig.json --emitDeclarationOnly",
|
||||
"build:bundle": "node ./build.js",
|
||||
"build": "pnpm clean && pnpm build:bundle && pnpm build:types",
|
||||
"release": "pnpm build && release-it",
|
||||
"release": "vant-cli release",
|
||||
"prepare": "pnpm build"
|
||||
},
|
||||
"repository": {
|
||||
@ -39,14 +39,7 @@
|
||||
"devDependencies": {
|
||||
"@popperjs/core": "^2.11.6",
|
||||
"esbuild": "^0.18.11",
|
||||
"release-it": "^16.1.3",
|
||||
"rimraf": "^5.0.0",
|
||||
"typescript": "^5.0.4"
|
||||
},
|
||||
"release-it": {
|
||||
"git": {
|
||||
"tag": false,
|
||||
"commitMessage": "release: @vant/popperjs v${version}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
5
packages/vant-popperjs/vant.config.mjs
Normal file
5
packages/vant-popperjs/vant.config.mjs
Normal file
@ -0,0 +1,5 @@
|
||||
export default {
|
||||
build: {
|
||||
packageManager: 'pnpm',
|
||||
},
|
||||
};
|
5
packages/vant-touch-emulator/vant.config.mjs
Normal file
5
packages/vant-touch-emulator/vant.config.mjs
Normal file
@ -0,0 +1,5 @@
|
||||
export default {
|
||||
build: {
|
||||
packageManager: 'pnpm',
|
||||
},
|
||||
};
|
@ -22,7 +22,7 @@
|
||||
"build:types": "tsc -p ./tsconfig.json --emitDeclarationOnly",
|
||||
"build:bundle": "node ./build.js",
|
||||
"build": "pnpm clean && pnpm build:bundle && pnpm build:types",
|
||||
"release": "pnpm build && release-it",
|
||||
"release": "vant-cli release",
|
||||
"prepare": "pnpm build"
|
||||
},
|
||||
"publishConfig": {
|
||||
@ -39,18 +39,11 @@
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"esbuild": "^0.18.11",
|
||||
"release-it": "^16.1.3",
|
||||
"rimraf": "^5.0.0",
|
||||
"typescript": "^5.0.4",
|
||||
"vue": "^3.3.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"vue": "^3.0.0"
|
||||
},
|
||||
"release-it": {
|
||||
"git": {
|
||||
"tag": false,
|
||||
"commitMessage": "release: @vant/use v${version}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
5
packages/vant-use/vant.config.mjs
Normal file
5
packages/vant-use/vant.config.mjs
Normal file
@ -0,0 +1,5 @@
|
||||
export default {
|
||||
build: {
|
||||
packageManager: 'pnpm',
|
||||
},
|
||||
};
|
@ -70,10 +70,5 @@
|
||||
"lib/**/style/*",
|
||||
"*.css"
|
||||
],
|
||||
"release-it": {
|
||||
"git": {
|
||||
"commitMessage": "release: vant v${version}"
|
||||
}
|
||||
},
|
||||
"web-types": "lib/web-types.json"
|
||||
}
|
||||
|
1669
pnpm-lock.yaml
generated
1669
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user