mirror of
https://github.com/WeBankFinTech/fes.js.git
synced 2025-10-13 18:22:13 +08:00
chore: 优化发布流程
This commit is contained in:
parent
720296fc82
commit
c1fa59fcf8
2
.npmrc
2
.npmrc
@ -1,2 +1,4 @@
|
|||||||
registry=https://registry.npmmirror.com
|
registry=https://registry.npmmirror.com
|
||||||
|
link-workspace-packages=true
|
||||||
|
prefer-workspace-packages=true
|
||||||
shamefully-hoist=true
|
shamefully-hoist=true
|
||||||
|
@ -32,11 +32,11 @@
|
|||||||
"hooks:sync": "simple-git-hooks"
|
"hooks:sync": "simple-git-hooks"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chalk": "^5.0.1",
|
"consola": "^3.4.2",
|
||||||
"conventional-changelog-cli": "^4.1.0",
|
"conventional-changelog-cli": "^5.0.0",
|
||||||
"enquirer": "^2.3.6",
|
|
||||||
"execa": "^6.1.0",
|
"execa": "^6.1.0",
|
||||||
"minimist": "^1.2.6",
|
"minimist": "^1.2.6",
|
||||||
|
"picocolors": "^1.1.1",
|
||||||
"semver": "^7.3.6",
|
"semver": "^7.3.6",
|
||||||
"tsup": "^8.5.0",
|
"tsup": "^8.5.0",
|
||||||
"turbo": "^2.5.6"
|
"turbo": "^2.5.6"
|
||||||
@ -55,8 +55,7 @@
|
|||||||
"simple-git-hooks": "^2.9.0",
|
"simple-git-hooks": "^2.9.0",
|
||||||
"typescript": "^5.9.2",
|
"typescript": "^5.9.2",
|
||||||
"vitepress": "1.0.0-alpha.73",
|
"vitepress": "1.0.0-alpha.73",
|
||||||
"vue": "^3.5.21",
|
"vue": "^3.5.21"
|
||||||
"yargs-parser": "^21.1.1"
|
|
||||||
},
|
},
|
||||||
"simple-git-hooks": {
|
"simple-git-hooks": {
|
||||||
"pre-commit": "npx lint-staged",
|
"pre-commit": "npx lint-staged",
|
||||||
|
@ -15,14 +15,14 @@
|
|||||||
"access": "public"
|
"access": "public"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fesjs/builder-vite": "file:../../../builder-vite",
|
"@fesjs/builder-vite": "workspace:*",
|
||||||
"@fesjs/fes": "file:../../../fes",
|
"@fesjs/fes": "workspace:*",
|
||||||
"@fesjs/fes-design": "^0.8.0",
|
"@fesjs/fes-design": "^0.8.0",
|
||||||
"@fesjs/plugin-access": "file:../../../plugin-access",
|
"@fesjs/plugin-access": "workspace:*",
|
||||||
"@fesjs/plugin-layout": "file:../../../plugin-layout",
|
"@fesjs/plugin-layout": "workspace:*",
|
||||||
"@fesjs/plugin-model": "file:../../../plugin-model",
|
"@fesjs/plugin-model": "workspace:*",
|
||||||
"@fesjs/plugin-qiankun": "file:../../../plugin-qiankun",
|
"@fesjs/plugin-qiankun": "workspace:*",
|
||||||
"@fesjs/plugin-watermark": "file:../../../plugin-watermark",
|
"@fesjs/plugin-watermark": "workspace:*",
|
||||||
"vue": "^3.5.21"
|
"vue": "^3.5.21"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,11 +14,11 @@
|
|||||||
"access": "public"
|
"access": "public"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fesjs/builder-vite": "file:../../../builder-vite",
|
"@fesjs/builder-vite": "workspace:*",
|
||||||
"@fesjs/fes": "file:../../../fes",
|
"@fesjs/fes": "workspace:*",
|
||||||
"@fesjs/fes-design": "^0.8.0",
|
"@fesjs/fes-design": "^0.8.0",
|
||||||
"@fesjs/plugin-qiankun": "file:../../../plugin-qiankun",
|
"@fesjs/plugin-qiankun": "workspace:*",
|
||||||
"@fesjs/plugin-watermark": "file:../../../plugin-watermark",
|
"@fesjs/plugin-watermark": "workspace:*",
|
||||||
"vue": "^3.5.21"
|
"vue": "^3.5.21"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,14 +16,14 @@
|
|||||||
"access": "public"
|
"access": "public"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fesjs/builder-webpack": "file:../../../builder-webpack",
|
"@fesjs/builder-webpack": "workspace:*",
|
||||||
"@fesjs/fes": "file:../../../fes",
|
"@fesjs/fes": "workspace:*",
|
||||||
"@fesjs/fes-design": "^0.8.0",
|
"@fesjs/fes-design": "^0.8.0",
|
||||||
"@fesjs/plugin-access": "file:../../../plugin-access",
|
"@fesjs/plugin-access": "workspace:*",
|
||||||
"@fesjs/plugin-layout": "file:../../../plugin-layout",
|
"@fesjs/plugin-layout": "workspace:*",
|
||||||
"@fesjs/plugin-model": "file:../../../plugin-model",
|
"@fesjs/plugin-model": "workspace:*",
|
||||||
"@fesjs/plugin-qiankun": "file:../../../plugin-qiankun",
|
"@fesjs/plugin-qiankun": "workspace:*",
|
||||||
"@fesjs/plugin-watermark": "file:../../../plugin-watermark",
|
"@fesjs/plugin-watermark": "workspace:*",
|
||||||
"vue": "^3.5.21"
|
"vue": "^3.5.21"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,11 @@
|
|||||||
"access": "public"
|
"access": "public"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fesjs/builder-webpack": "file:../../../builder-webpack",
|
"@fesjs/builder-webpack": "workspace:*",
|
||||||
"@fesjs/fes": "file:../../../fes",
|
"@fesjs/fes": "workspace:*",
|
||||||
"@fesjs/fes-design": "^0.8.0",
|
"@fesjs/fes-design": "^0.8.0",
|
||||||
"@fesjs/plugin-qiankun": "file:../../../plugin-qiankun",
|
"@fesjs/plugin-qiankun": "workspace:*",
|
||||||
"@fesjs/plugin-watermark": "file:../../../plugin-watermark",
|
"@fesjs/plugin-watermark": "workspace:*",
|
||||||
"vue": "^3.5.21"
|
"vue": "^3.5.21"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1089
pnpm-lock.yaml
generated
1089
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -2,19 +2,18 @@ import fs from 'node:fs';
|
|||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import process from 'node:process';
|
import process from 'node:process';
|
||||||
import * as url from 'node:url';
|
import * as url from 'node:url';
|
||||||
import chalk from 'chalk';
|
import consola from 'consola';
|
||||||
import enquirer from 'enquirer';
|
|
||||||
import { execa } from 'execa';
|
import { execa } from 'execa';
|
||||||
import minimist from 'minimist';
|
import minimist from 'minimist';
|
||||||
|
import pc from 'picocolors';
|
||||||
import semver from 'semver';
|
import semver from 'semver';
|
||||||
|
import { getPublicPkgs } from './shared.mjs';
|
||||||
|
|
||||||
import buildConfig from '../build.config.js';
|
|
||||||
|
|
||||||
const { prompt } = enquirer;
|
|
||||||
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
|
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
|
||||||
|
|
||||||
const { preid: preId, dry: isDryRun } = minimist(process.argv.slice(2));
|
const { preid: preId, dry: isDryRun } = minimist(process.argv.slice(2));
|
||||||
const packages = buildConfig.pkgs;
|
|
||||||
|
const packages = getPublicPkgs();
|
||||||
|
|
||||||
const versionIncrements = ['patch', 'minor', 'major', 'prepatch', 'preminor', 'premajor', 'prerelease'];
|
const versionIncrements = ['patch', 'minor', 'major', 'prepatch', 'preminor', 'premajor', 'prerelease'];
|
||||||
|
|
||||||
@ -35,10 +34,10 @@ function autoIncVersion(version) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const run = (bin, args, opts = {}) => execa(bin, args, { stdio: 'inherit', ...opts });
|
const run = (bin, args, opts = {}) => execa(bin, args, { stdio: 'inherit', ...opts });
|
||||||
const dryRun = (bin, args, opts = {}) => console.log(chalk.blue(`[dryrun] ${bin} ${args.join(' ')}`), opts);
|
const dryRun = (bin, args, opts = {}) => consola.info(`[dryrun] ${bin} ${args.join(' ')}`, opts);
|
||||||
const runIfNotDry = isDryRun ? dryRun : run;
|
const runIfNotDry = isDryRun ? dryRun : run;
|
||||||
const getPkgRoot = pkg => path.resolve(__dirname, `../packages/${pkg}`);
|
const getPkgRoot = pkg => path.resolve(__dirname, `../packages/${pkg}`);
|
||||||
const step = msg => console.log(chalk.cyan(msg));
|
const step = msg => consola.log(msg);
|
||||||
function arrToObj(arr, key) {
|
function arrToObj(arr, key) {
|
||||||
return arr.reduce((acc, cur) => {
|
return arr.reduce((acc, cur) => {
|
||||||
acc[cur[key]] = cur;
|
acc[cur[key]] = cur;
|
||||||
@ -55,8 +54,6 @@ async function publishPackage(pkg, runIfNotDry) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await runIfNotDry(
|
await runIfNotDry(
|
||||||
// note: use of pnpm is intentional here as we rely on its publishing
|
|
||||||
// behavior.
|
|
||||||
'npm',
|
'npm',
|
||||||
['publish', ...(_releaseTag ? ['--tag', _releaseTag] : []), '--access', 'public', '--registry', 'https://registry.npmjs.org'],
|
['publish', ...(_releaseTag ? ['--tag', _releaseTag] : []), '--access', 'public', '--registry', 'https://registry.npmjs.org'],
|
||||||
{
|
{
|
||||||
@ -64,11 +61,11 @@ async function publishPackage(pkg, runIfNotDry) {
|
|||||||
stdio: 'pipe',
|
stdio: 'pipe',
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
console.log('Successfully published :', chalk.green(`${pkg.name}@${pkg.newVersion}`));
|
console.log('Successfully published :', pc.green(`${pkg.name}@${pkg.newVersion}`));
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
if (e.stderr.match(/previously published/)) {
|
if (e.stderr.match(/previously published/)) {
|
||||||
console.log(chalk.red(`Skipping already published: ${pkg.name}`));
|
console.log(pc.red(`Skipping already published: ${pkg.name}`));
|
||||||
}
|
}
|
||||||
|
|
||||||
else { throw e; }
|
else { throw e; }
|
||||||
@ -143,26 +140,25 @@ async function filterChangedPackages() {
|
|||||||
|
|
||||||
async function createPackageNewVersion(name, version) {
|
async function createPackageNewVersion(name, version) {
|
||||||
// no explicit version, offer suggestions
|
// no explicit version, offer suggestions
|
||||||
const { release } = await prompt({
|
const release = await consola.prompt(`Select release type: ${name}`, {
|
||||||
type: 'select',
|
type: 'select',
|
||||||
name: 'release',
|
options: versionIncrements.map((i) => {
|
||||||
message: `Select release type: ${name}`,
|
return {
|
||||||
choices: versionIncrements.map(i => `${i} (${incVersion(version, i)})`).concat(['custom']),
|
value: incVersion(version, i),
|
||||||
|
label: `${i} (${incVersion(version, i)})`,
|
||||||
|
};
|
||||||
|
}).concat({
|
||||||
|
value: 'custom',
|
||||||
|
label: 'custom',
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
let newVersion;
|
let newVersion = release;
|
||||||
if (release === 'custom') {
|
if (release === 'custom') {
|
||||||
newVersion = (
|
newVersion = await consola.prompt(`Input custom version: ${name}`, {
|
||||||
await prompt({
|
type: 'text',
|
||||||
type: 'input',
|
default: version,
|
||||||
name: 'version',
|
});
|
||||||
message: `Input custom version: ${name}`,
|
|
||||||
initial: version,
|
|
||||||
})
|
|
||||||
).version;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
newVersion = release.match(/\((.*)\)/)[1];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!semver.valid(newVersion)) {
|
if (!semver.valid(newVersion)) {
|
||||||
@ -217,7 +213,7 @@ async function main() {
|
|||||||
const changedPackages = await filterChangedPackages();
|
const changedPackages = await filterChangedPackages();
|
||||||
|
|
||||||
if (!changedPackages.length) {
|
if (!changedPackages.length) {
|
||||||
console.log(chalk.yellow(`No changes to commit.`));
|
consola.warn(`No changes to commit.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,12 +231,10 @@ async function main() {
|
|||||||
const passiveUpdatePkgs = genOtherPkgsVersion(updatedPkgs);
|
const passiveUpdatePkgs = genOtherPkgsVersion(updatedPkgs);
|
||||||
const packagesVersion = passiveUpdatePkgs.concat(updatedPkgs);
|
const packagesVersion = passiveUpdatePkgs.concat(updatedPkgs);
|
||||||
|
|
||||||
const { yes } = await prompt({
|
const yes = await consola.prompt(`These packages will be released: \n${packagesVersion
|
||||||
|
.map(pkg => `${pc.magenta(pkg.name)}: v${pkg.version} > ${pc.green(`v${pkg.newVersion}`)}`)
|
||||||
|
.join('\n')}\nConfirm?`, {
|
||||||
type: 'confirm',
|
type: 'confirm',
|
||||||
name: 'yes',
|
|
||||||
message: `These packages will be released: \n${packagesVersion
|
|
||||||
.map(pkg => `${chalk.magenta(pkg.name)}: v${pkg.version} > ${chalk.green(`v${pkg.newVersion}`)}`)
|
|
||||||
.join('\n')}\nConfirm?`,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!yes) {
|
if (!yes) {
|
||||||
|
@ -1,5 +1,31 @@
|
|||||||
import { copyFileSync, mkdirSync, readdirSync } from 'node:fs';
|
import { copyFileSync, mkdirSync, readdirSync, readFileSync } from 'node:fs';
|
||||||
import { dirname, join } from 'node:path';
|
import { dirname, join } from 'node:path';
|
||||||
|
import process from 'node:process';
|
||||||
|
|
||||||
|
export function getPublicPkgs() {
|
||||||
|
const packagesDir = join(process.cwd(), 'packages');
|
||||||
|
const dirs = readdirSync(packagesDir, { withFileTypes: true })
|
||||||
|
.filter(dirent => dirent.isDirectory())
|
||||||
|
.map(dirent => dirent.name);
|
||||||
|
|
||||||
|
const publicPkgs = [];
|
||||||
|
for (const dir of dirs) {
|
||||||
|
const pkgJsonPath = join(packagesDir, dir, 'package.json');
|
||||||
|
try {
|
||||||
|
const pkgJson = JSON.parse(readFileSync(pkgJsonPath, 'utf8'));
|
||||||
|
// 如果没有 private 字段或者 private 为 false,则是需要发布的包
|
||||||
|
if (!pkgJson.private) {
|
||||||
|
publicPkgs.push(dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
// 如果读取或解析 package.json 失败,跳过该目录
|
||||||
|
console.warn(`Warning: Could not read package.json for ${dir}`, error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return publicPkgs;
|
||||||
|
}
|
||||||
|
|
||||||
export function copyTplFiles(srcDir, dstDir) {
|
export function copyTplFiles(srcDir, dstDir) {
|
||||||
function walk(currentSrc, currentDst) {
|
function walk(currentSrc, currentDst) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user