Skip to content

Commit

Permalink
release: v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
BIYUEHU committed Dec 31, 2023
1 parent d3eca13 commit 8c133fd
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 50 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## [1.0.1](https://github.com/kotorijs/kotori/compare/v1.0.0...v1.0.1) (2023-12-31)
# v1.1.0 (2023-12-31)


### Features
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@kotori-bot/root",
"description": "ChatBot Framework",
"version": "v1.0.1",
"version": "v1.0.0",
"packageManager": "[email protected]",
"private": true,
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kotori-bot/core",
"version": "v1.0.1",
"version": "v1.0.0",
"description": "Kotori Core",
"main": "lib/index.js",
"license": "GPL-3.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/loader/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kotori-bot/loader",
"version": "1.1.0",
"version": "v1.2.0",
"description": "Loader For KotoriBot",
"license": "GPL-3.0",
"main": "lib/index.js",
Expand Down
79 changes: 33 additions & 46 deletions scripts/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const config = {

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);
Expand Down Expand Up @@ -84,20 +83,20 @@ type Option = {
return handle.split('.').map(val => parseInt(val, 10));
}

function isUpdateVersion(pkgName: string, version: Version) {
function isUpdateVersion(version: Version) {
return prompt({
type: 'confirm',
name: 'value',
message: `For ${pkgName} : update ${version} version?`,
message: `Do you want to update ${version} version?`,
default: false,
});
}

async function getVersion(pkg: Package) {
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}`;
async function genVersion() {
if ((await isUpdateVersion(/* pkg.packageJson.name, */ 'Major')).value)
return (version: number[]) => `v${version[0] + 1}.0.0`;
if ((await isUpdateVersion('Minor')).value) return (version: number[]) => `v${version[0]}.${version[1] + 1}.0`;
return (version: number[]) => `v${version[0]}.${version[1]}.${version[2] + 1}`;
}

function setVersion(pkg: Package) {
Expand All @@ -106,32 +105,20 @@ type Option = {
}

async function setVersions(pkgs: Package[]) {
const getVersion = await genVersion();
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 extraPkgs = config.sync.map(pkgName => getTargetPackage(pkgName, WORKSPACE.packages));
extraPkgs.push(WORKSPACE.rootPackage as (typeof extraPkgs)[0]);
}
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));
pkgs.forEach(pkg => {
const pkgJson = pkg.packageJson;
pkgJson.version =
pkgJson.name === WORKSPACE.rootPackage?.packageJson.name || config.sync.includes(pkgJson.name)
? mainPkg!.packageJson.version
: getVersion(parseVersion(pkg.packageJson.version));
setVersion(pkg);
});
}

async function handleGit(version: string) {
Expand Down Expand Up @@ -165,25 +152,11 @@ type Option = {
log('Run eslint and prettier...');
await hooks(config.hooks.beforeAddcommit);

const answer = await prompt([
{
type: 'confirm',
name: 'push',
message: 'Do you need push to remote branch?',
default: true,
},
{
type: 'confirm',
name: 'publish',
message: 'Do you need publish all updated package?',
default: true,
},
]);
const mainPkg = getTargetPackage(config.main, packages);
if (mainPkg) {
/* Step: spawn tag */
log('Adding tag...');
await handleGit(`v${mainPkg.packageJson.version}`);
await handleGit(mainPkg.packageJson.version);
/* Step: zip main package */
const answer = await prompt({
type: 'confirm',
Expand All @@ -195,6 +168,20 @@ type Option = {
}

/* Step: push to remote branch */
const answer = await prompt([
{
type: 'confirm',
name: 'push',
message: 'Do you need push to remote branch?',
default: true,
},
{
type: 'confirm',
name: 'publish',
message: 'Do you need publish all updated package?',
default: true,
},
]);
const pushCommand = `git push ${config.remote} ${config.branch} ${mainPkg ? '--tags' : ''}`;
if (answer.push) await step(pushCommand);

Expand Down

0 comments on commit 8c133fd

Please sign in to comment.