From d3eca139b192c8317c8744d92571c1611054a127 Mon Sep 17 00:00:00 2001 From: Hotaru Date: Sun, 31 Dec 2023 18:53:22 +0800 Subject: [PATCH] release: vv1.1.0 --- CHANGELOG.md | 75 +++++++++++ modules/adapter-cmd/package.json | 2 +- modules/adapter-onebot/package.json | 2 +- modules/adapter-qq/package.json | 2 +- modules/core/package.json | 2 +- modules/helper/package.json | 2 +- modules/i18n-command/package.json | 2 +- modules/menu/package.json | 2 +- package.json | 9 +- packages/core/package.json | 4 +- packages/i18n/package.json | 2 +- packages/kotori/package.json | 4 +- packages/loader/package.json | 2 +- packages/logger/package.json | 2 +- packages/tools/package.json | 2 +- scripts/release.ts | 197 ++++++++++++++++------------ 16 files changed, 205 insertions(+), 106 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..3852868e --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,75 @@ +## [1.0.1](https://github.com/kotorijs/kotori/compare/v1.0.0...v1.0.1) (2023-12-31) + + +### Features + +* kotori-bot core ([ab3894e](https://github.com/kotorijs/kotori/commit/ab3894e54a391653b3169ddbb6770d17e85bd8d3)) + + + +# [1.0.0](https://github.com/kotorijs/kotori/compare/v0.7.8...v1.0.0) (2023-12-29) + + +### Features + +* add more callback type and querytool ([952d6fc](https://github.com/kotorijs/kotori/commit/952d6fc9e2bd34af3c7f77c63e8652c8ad7a14bb)) +* add some events and fix command,message ([a68b292](https://github.com/kotorijs/kotori/commit/a68b292b165b02707cce04818c0226adc9876e21)) +* cmd adapter and loader modules ([d698df1](https://github.com/kotorijs/kotori/commit/d698df1cdae524c43a39bd75aeebde8c32fdca39)) +* cmd adapter and loader modules ([f2b656a](https://github.com/kotorijs/kotori/commit/f2b656a3a367d74a1b16a058430d7027b539a2e4)) +* loader and modules && mixed && command ([c0a2abe](https://github.com/kotorijs/kotori/commit/c0a2abe5a27dbb7a3f5523861ca1310c76b1645f)) +* loader and modules && mixed && command ([9ba0bc9](https://github.com/kotorijs/kotori/commit/9ba0bc98a18aa193d588630c8c6ca8c9ab3a25e8)) +* loader and modules,mixed,command ([5d11c5f](https://github.com/kotorijs/kotori/commit/5d11c5f1e25fbd30a49a5333661e1c052bdf83d2)) +* loader updated, as subpack and core-18n ([1e5a6ec](https://github.com/kotorijs/kotori/commit/1e5a6ec12cc7a3ee697fc0d4249acc2e74fe4220)) +* new plugins and adapter-tencent-qq and some fixs ([5512975](https://github.com/kotorijs/kotori/commit/55129758c529cf7ac6cc446ed2202d14c6446a63)) +* new plugins,event.before and bug fix ([283d4c8](https://github.com/kotorijs/kotori/commit/283d4c8505b828151ff84e16bfdb23d7928135ae)) +* some changes about class static ([a440959](https://github.com/kotorijs/kotori/commit/a4409593f645004b2465af2cafe7304205262bff)) +* type checker i18n and error handle ([4596740](https://github.com/kotorijs/kotori/commit/45967408dcd3957a433d7f0aa0b01dd79931ef89)) +* v1 events,modules,message,content,api,adapter,core ([b6349cb](https://github.com/kotorijs/kotori/commit/b6349cb075f1caf7d1151e607e368f4e5de44c45)) + + + +## [0.7.8](https://github.com/kotorijs/kotori/compare/v0.7.7...v0.7.8) (2023-09-10) + + +### Features + +* grouper plugin and favicon ([3640024](https://github.com/kotorijs/kotori/commit/3640024d5a8b289826b2068a4a78b9397b9fdb5f)) + + + +## [0.7.7](https://github.com/kotorijs/kotori/compare/v0.7.6...v0.7.7) (2023-08-26) + + +### Features + +* grouper plugin and favicon ([6756cee](https://github.com/kotorijs/kotori/commit/6756cee88a5bf1e1b9e88a2becef1023ca401b3a)) + + + +## [0.7.6](https://github.com/kotorijs/kotori/compare/v0.7.5...v0.7.6) (2023-08-25) + + +### Features + +* **many plugins:** many plugins ([9e7464a](https://github.com/kotorijs/kotori/commit/9e7464ad6c0bc3e10a673063d762eb469b8cf74c)) + + + +## [0.7.5](https://github.com/kotorijs/kotori/compare/dba239dbd4f1c4fe0067e4b603aab62c31049063...v0.7.5) (2023-08-25) + + +### Bug Fixes + +* regiser plugin events ([6dbca7e](https://github.com/kotorijs/kotori/commit/6dbca7e436abc05842f51154af12a12d22e7c196)) + + +### Features + +* create module,requester ([dba239d](https://github.com/kotorijs/kotori/commit/dba239dbd4f1c4fe0067e4b603aab62c31049063)) +* framework ([18cbe84](https://github.com/kotorijs/kotori/commit/18cbe84ecb5cbbca91c009db5f2e2bd5db0a9351)) +* manger and hitokotos plugin ([20ee234](https://github.com/kotorijs/kotori/commit/20ee23496a209433c656032d300e5474da664945)) +* plugins ([ea644e8](https://github.com/kotorijs/kotori/commit/ea644e85641f39ddbe2fb0b3790cd401d2c758b8)) +* querytool plugin ([d2e5d7c](https://github.com/kotorijs/kotori/commit/d2e5d7c1465d58b84fb916d52c71985bd391f75f)) + + + diff --git a/modules/adapter-cmd/package.json b/modules/adapter-cmd/package.json index aeefc66c..24e55d15 100644 --- a/modules/adapter-cmd/package.json +++ b/modules/adapter-cmd/package.json @@ -15,4 +15,4 @@ "peerDependencies": { "kotori-bot": "workspace:^" } -} \ No newline at end of file +} diff --git a/modules/adapter-onebot/package.json b/modules/adapter-onebot/package.json index 4d453bd4..d4215e03 100644 --- a/modules/adapter-onebot/package.json +++ b/modules/adapter-onebot/package.json @@ -19,4 +19,4 @@ "@types/ws": "^8.5.8", "ws": "^8.14.2" } -} \ No newline at end of file +} diff --git a/modules/adapter-qq/package.json b/modules/adapter-qq/package.json index 6c08d115..945f58fa 100644 --- a/modules/adapter-qq/package.json +++ b/modules/adapter-qq/package.json @@ -19,4 +19,4 @@ "@types/ws": "^8.5.8", "ws": "^8.14.2" } -} \ No newline at end of file +} diff --git a/modules/core/package.json b/modules/core/package.json index aa8f5dee..62f880b6 100644 --- a/modules/core/package.json +++ b/modules/core/package.json @@ -15,4 +15,4 @@ "peerDependencies": { "kotori-bot": "workspace:^" } -} \ No newline at end of file +} diff --git a/modules/helper/package.json b/modules/helper/package.json index 4843ee6b..e3caaf01 100644 --- a/modules/helper/package.json +++ b/modules/helper/package.json @@ -15,4 +15,4 @@ "peerDependencies": { "kotori-bot": "workspace:^" } -} \ No newline at end of file +} diff --git a/modules/i18n-command/package.json b/modules/i18n-command/package.json index c57c0d13..b1e79d86 100644 --- a/modules/i18n-command/package.json +++ b/modules/i18n-command/package.json @@ -15,4 +15,4 @@ "peerDependencies": { "kotori-bot": "workspace:^" } -} \ No newline at end of file +} diff --git a/modules/menu/package.json b/modules/menu/package.json index a4be012f..a905f44e 100644 --- a/modules/menu/package.json +++ b/modules/menu/package.json @@ -15,4 +15,4 @@ "peerDependencies": { "kotori-bot": "workspace:^" } -} \ No newline at end of file +} diff --git a/package.json b/package.json index 60426d5e..33d5486e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@kotori-bot/root", "description": "ChatBot Framework", - "version": "1.0.0", + "version": "v1.0.1", "packageManager": "pnpm@8.7.4", "private": true, "scripts": { @@ -14,8 +14,7 @@ "lint": "eslint \"{packages,modules}/*/src/*.{ts,tsx}\" --fix", "format": "prettier --config .prettierrc \"{packages,modules}/*/src/*.ts\" --write", "version": "pnpm exec conventional-changelog -p angular -i CHANGELOG.md -s -r 0", - "release": "pnpm exec release", - "release:only": "pnpm exec release" + "release": "pnpm exec release" }, "license": "GPL-3.0", "author": "Hotaru ", @@ -34,6 +33,7 @@ "devDependencies": { "@manypkg/get-packages": "^2.2.0", "@types/inquirer": "^9.0.7", + "@types/js-beautify": "^1.14.3", "@types/node": "^20.8.7", "@typescript-eslint/eslint-plugin": "^6.4.0", "@typescript-eslint/parser": "^6.4.0", @@ -46,7 +46,8 @@ "eslint-plugin-prettier": "^5.0.0", "execa": "^8.0.1", "inquirer": "^9.2.12", + "js-beautify": "^1.14.11", "prettier": "^3.0.2", "tsconfig-paths": "^4.2.0" } -} \ No newline at end of file +} diff --git a/packages/core/package.json b/packages/core/package.json index 7c0efc58..140cc48e 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@kotori-bot/core", - "version": "1.0.0", + "version": "v1.0.1", "description": "Kotori Core", "main": "lib/index.js", "license": "GPL-3.0", @@ -27,4 +27,4 @@ "@kotori-bot/tools": "workspace:^", "tsukiko": "^1.2.1" } -} \ No newline at end of file +} diff --git a/packages/i18n/package.json b/packages/i18n/package.json index 55728ab5..0c15dbc5 100644 --- a/packages/i18n/package.json +++ b/packages/i18n/package.json @@ -25,4 +25,4 @@ "url": "git+https://github.com/kotorijs/kotori.git" }, "homepage": "https://kotori.js.org " -} \ No newline at end of file +} diff --git a/packages/kotori/package.json b/packages/kotori/package.json index 5b365f8e..ef045bff 100644 --- a/packages/kotori/package.json +++ b/packages/kotori/package.json @@ -1,6 +1,6 @@ { "name": "kotori-bot", - "version": "1.0.0", + "version": "v1.1.0", "description": "ChatBot Framework Base For NodeJS And TypeScript", "main": "lib/index.js", "license": "GPL-3.0", @@ -38,4 +38,4 @@ "@kotori-bot/loader": "workspace:^", "cac": "^6.7.14" } -} \ No newline at end of file +} diff --git a/packages/loader/package.json b/packages/loader/package.json index 2fc2bcbe..93b84058 100644 --- a/packages/loader/package.json +++ b/packages/loader/package.json @@ -15,4 +15,4 @@ "ts-node": "^10.9.2", "typescript": "^5.1.3" } -} \ No newline at end of file +} diff --git a/packages/logger/package.json b/packages/logger/package.json index b22328d5..0360489e 100644 --- a/packages/logger/package.json +++ b/packages/logger/package.json @@ -25,4 +25,4 @@ "url": "git+https://github.com/kotorijs/kotori.git" }, "homepage": "https://kotori.js.org " -} \ No newline at end of file +} diff --git a/packages/tools/package.json b/packages/tools/package.json index b5997773..6bfa8bcc 100644 --- a/packages/tools/package.json +++ b/packages/tools/package.json @@ -27,4 +27,4 @@ "url": "git+https://github.com/kotorijs/kotori.git" }, "homepage": "https://kotori.js.org " -} \ No newline at end of file +} diff --git a/scripts/release.ts b/scripts/release.ts index 8909fea6..7bf99072 100644 --- a/scripts/release.ts +++ b/scripts/release.ts @@ -8,16 +8,30 @@ import { resolve } from 'path'; const config = { branch: 'master', remote: 'origin', - registry: 'https://registry.npmjs.org/', + // registry: 'https://registry.npmjs.org/', main: 'kotori-bot', + root: '@kotori-bot/root', sync: ['@kotori-bot/core'], include: '{packages,modules}/*/src/*.{ts,tsx}', hooks: { - beforeAddcommit: ['pnpm run eslint', 'pnpm run format', 'pnpm run version'], + beforeAddcommit: [ + 'pnpm run lint', + 'pnpm run format', + 'pnpm run version', + 'prettier --config .prettierrc "{{packages,modules}/*/package.json,package.json}" --write', + ], }, }; const ROOT_DIR = resolve(__dirname, '../'); +const WORKSPACE = getPackagesSync(ROOT_DIR); +const MAIN_PACKAGE = getTargetPackage(config.main, WORKSPACE.packages); + +function getTargetPackage(pkgName: string, pkgs: Package[]) { + const filterPackages = pkgs.filter(pkg => pkg.packageJson.name === pkgName); + if (filterPackages.length === 0) return null; + return filterPackages[0]; +} type Version = 'Major' | 'Minor' | 'Patch'; @@ -29,14 +43,30 @@ type Option = { const { prompt } = (await import('inquirer')).default; const { execa } = await import('execa'); - function getTargetPackage(pkgs: Package[], pkgName: string = config.main) { - const filterPackages = pkgs.filter(pkg => pkg.packageJson.name === pkgName); - if (filterPackages.length === 0) return null; - return filterPackages[0]; + async function step(cmd: string, args?: string[], option: Option = { cwd: ROOT_DIR }, print: boolean = false) { + const entity = await execa(cmd, args, option); + const { stdout, stderr } = entity; + if (stderr) error('Error:', stderr, `\nAt "${cmd}"`); + log(print ? `Result: ${stdout}` : `Success: ${cmd}`); + } + + function hooks(hooks: string[]) { + return hooks.reduce(async (promise, cmd) => { + await promise; + return step(cmd); + }, Promise.resolve()); } - async function getFilterPackages(dir: string = ROOT_DIR) { - const { packages, rootPackage } = getPackagesSync(dir); + async function checkBranch() { + if (!(await execa('git branch')).stdout.includes(`* ${config.branch}`)) { + error(`Branch error! expected: ${config.branch}`); + return false; + } + return true; + } + + async function getFilterPackages() { + const { packages } = WORKSPACE; const { value } = await prompt({ type: 'checkbox', name: 'value', @@ -45,98 +75,94 @@ type Option = { .filter(pkg => !config.sync.includes(pkg.packageJson.name)) .map(pkg => ({ name: `${pkg.packageJson.name}@${pkg.packageJson.version}`, value: pkg.relativeDir })), }); - const filterPackages = packages.filter(pkg => value.includes(pkg.relativeDir)); - const mainPkgJson = getTargetPackage(filterPackages)?.packageJson; - if (!mainPkgJson) return filterPackages; - /* Sync packages version by main package */ - config.sync.forEach(async pkgName => { - const pkg = getTargetPackage(packages, pkgName); - if (!pkg) return; - pkg.packageJson.version = mainPkgJson.version; - filterPackages.push(pkg); - }); - if (!rootPackage) return filterPackages; - rootPackage.packageJson.version = mainPkgJson.version; - filterPackages.push(rootPackage); - return filterPackages; + return packages.filter(pkg => value.includes(pkg.relativeDir)); } - async function isUpdateVersion(pkgName: string, version: Version): Promise { - return ( - await prompt({ - type: 'confirm', - name: 'value', - message: `For ${pkgName} : update ${version} version?`, - default: false, - }) - ).value; + function parseVersion(version: string): number[] { + let handle = version; + if (handle.startsWith('v') || handle.startsWith('V')) handle = handle.substring(1); + return handle.split('.').map(val => parseInt(val, 10)); } - function setVersion(pkg: Package) { - writeFileSync(resolve(pkg.dir, 'package.json'), JSON.stringify(pkg.packageJson), 'utf-8'); - log(`New version: ${pkg.packageJson.name}@${[pkg.packageJson.version]}`); + function isUpdateVersion(pkgName: string, version: Version) { + return prompt({ + type: 'confirm', + name: 'value', + message: `For ${pkgName} : update ${version} version?`, + default: false, + }); } async function getVersion(pkg: Package) { - const version = pkg.packageJson.version.split('.'); - if (await isUpdateVersion(pkg.packageJson.name, 'Major')) return `v${version[0] + 1}.0.0`; - if (await isUpdateVersion(pkg.packageJson.name, 'Minor')) return `v${version[0]}.${version[1] + 1}.0`; + const version = parseVersion(pkg.packageJson.version); + if ((await isUpdateVersion(pkg.packageJson.name, 'Major')).value) return `v${version[0] + 1}.0.0`; + if ((await isUpdateVersion(pkg.packageJson.name, 'Minor')).value) return `v${version[0]}.${version[1] + 1}.0`; return `v${version[0]}.${version[1]}.${version[2] + 1}`; } - function publishPackages(pkgs: Package[]) { - return new Promise(resolve => { - pkgs.forEach(async (pkg, index) => { - await step('pnpm publish --access --access public', undefined, { cwd: pkg.dir }); - if (index === pkgs.length - 1) resolve(undefined); - }); - }); + function setVersion(pkg: Package) { + writeFileSync(resolve(pkg.dir, 'package.json'), JSON.stringify(pkg.packageJson), 'utf-8'); + log(`New version: ${pkg.packageJson.name}@${[pkg.packageJson.version]}`); } - async function step(cmd: string, args?: string[], option: Option = { cwd: ROOT_DIR }, print: boolean = false) { - try { - const entity = await execa(cmd, args, option); - const { stdout, stderr } = entity; - if (stderr) error('Error:', stderr, `\nAt "${cmd}"`); - log(print ? `Result: ${stdout}` : `Success: ${cmd}`); - } catch (err) { - error('Run Error:', error, `\nAt "${cmd}"`); + async function setVersions(pkgs: Package[]) { + const mainPkg = getTargetPackage(config.main, pkgs); + if (mainPkg) { + pkgs.push( + ...(config.sync + .map(pkgName => getTargetPackage(pkgName, WORKSPACE.packages)) + .filter(pkg => !!pkg) as Package[]), + ); + if (WORKSPACE.rootPackage) pkgs.push(WORKSPACE.rootPackage); } + const res = await Promise.all( + pkgs.map(async pkg => { + const handle = pkg; + /* Sync packages version by main package */ + if ( + config.sync.includes(pkg.packageJson.name) || + pkg.packageJson.name === WORKSPACE.rootPackage?.packageJson.name + ) { + handle.packageJson.version = MAIN_PACKAGE!.packageJson.version; + return handle; + } + handle.packageJson.version = await getVersion(pkg); + if (handle.packageJson.name === config.main) MAIN_PACKAGE!.packageJson.version = handle.packageJson.version; + return handle; + }), + ); + res.forEach(pkg => setVersion(pkg)); } - function hooks(hooks: string[]) { - return new Promise(resolve => { - hooks.forEach(async (cmd, index) => { - await step(cmd); - if (index === hooks.length - 1) resolve(undefined); - }); - }); + async function handleGit(version: string) { + if ((await execa('git tag -l')).stdout.includes(version)) { + error(`Error: tag ${version} already exists`); + } + await step('git add .'); + await step(`git commit -m "release: ${version}"`); + await step(`git tag ${version}`); + } + + function publishPackages(pkgs: Package[]) { + return pkgs.reduce(async (promise, pkg) => { + await promise; + return step('pnpm publish --access --access public', undefined, { cwd: pkg.dir }); + }, Promise.resolve()); } /* Main Program */ /* Step: check branch */ - if (!(await execa('git branch')).stdout.includes(`* ${config.branch}`)) { - error(`Branch error! expected: ${config.branch}`); - return; - } + if (!(await checkBranch())) return; /* Step: update version */ const packages = await getFilterPackages(); if (packages.length === 0) { log(`No package selected`); } - packages.forEach(async pkg => { - const handle = pkg; - handle.packageJson.version = await getVersion(pkg); - try { - setVersion(handle); - } catch (e) { - error(`Error: write failed at package ${pkg.packageJson.name}`); - } - }); - log('Update version and write successful'); + await setVersions(packages); /* Lifecycle: beforeAddcommit */ + log('Run eslint and prettier...'); await hooks(config.hooks.beforeAddcommit); const answer = await prompt([ @@ -153,16 +179,11 @@ type Option = { default: true, }, ]); - const mainPkg = getTargetPackage(packages); + const mainPkg = getTargetPackage(config.main, packages); if (mainPkg) { /* Step: spawn tag */ - const mainVersion = `v${mainPkg.packageJson.version}`; - if ((await execa('git tag -l')).stdout.includes(mainVersion)) { - console.error(`Error: tag ${mainVersion} already exists`); - } - await step('git add .'); - await step(`git commit -m "release: ${mainVersion}"`); - await step(`git tag ${mainVersion}`); + log('Adding tag...'); + await handleGit(`v${mainPkg.packageJson.version}`); /* Step: zip main package */ const answer = await prompt({ type: 'confirm', @@ -175,14 +196,16 @@ type Option = { /* Step: push to remote branch */ const pushCommand = `git push ${config.remote} ${config.branch} ${mainPkg ? '--tags' : ''}`; - if (answer.push) step(pushCommand); + if (answer.push) await step(pushCommand); /* Step: checkout registry and publish */ - const originRegistry = (await execa('pnpm config get registry')).stdout.replace(/(\n)|(\r)/g, ''); - await execa(`pnpm config set registry "${config.registry}"`); - await publishPackages(packages); - await execa(`pnpm config set registry "${originRegistry}"`); - + if (answer.publish) { + log('Publish...'); + // const originRegistry = (await execa('pnpm config get registry')).stdout.replace(/(\n)|(\r)/g, ''); + // await execa(`pnpm config set registry "${config.registry}"`); + await publishPackages(packages); + // await execa(`pnpm config set registry "${originRegistry}"`); + } /* ending */ if (!answer.push) log(`\nPlease enter "${pushCommand}"`); log(`All ok!`);