diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 1287aa1..34ed6de 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -34,4 +34,4 @@ jobs: run: ni --frozen - name: Lint - run: nr check + run: nr checkAll diff --git a/bin/index.js b/bin/index.js new file mode 100644 index 0000000..1aba6d8 --- /dev/null +++ b/bin/index.js @@ -0,0 +1,20 @@ +#!/usr/bin/env node +import { release, changelog } from '../dist/index.js' +import { Command } from 'commander' + +const program = new Command() + +program + .command('release') + .option('-r --remote ', 'Remote name') + .description('Release all packages and generate changelogs') + .action(async (options) => release(options)) + +program + .command('changelog') + .option('-rc --releaseCount ', 'Release count') + .option('-f --file ', 'Changelog filename') + .description('Generate changelog') + .action(async (options) => changelog(options)) + +program.parse() diff --git a/bin/index.mjs b/bin/index.mjs deleted file mode 100644 index 752df43..0000000 --- a/bin/index.mjs +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env node -import { releaseCommand, changelogCommand } from '../dist/index.js' -import { Command } from 'commander' - -const program = new Command() - -releaseCommand(program) -changelogCommand(program) - -program.parse() diff --git a/package.json b/package.json index bbc0df2..9865310 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,14 @@ "name": "@varlet/release", "type": "module", "version": "0.0.0", - "description": "", + "description": "release all packages and generate changelogs", + "keywords": [ + "varlet", + "release", + "changelog" + ], + "author": "clencat <2091927351@qq.com>", + "license": "MIT", "main": "./dist/index.js", "module": "./dist/index.js", "types": "./dist/index.d.ts", @@ -14,17 +21,14 @@ } }, "bin": { - "vr": "bin/index.mjs" + "vr": "bin/index.js" }, "scripts": { "build": "tsc --noEmit && tsup", - "dev": "node bin/index.mjs", + "dev": "node bin/index.js", "test": "pnpm run build && pnpm run dev", - "check": "tsc --noEmit && eslint --ext .ts,.mjs" + "checkAll": "tsc --noEmit && eslint --ext .ts,.js" }, - "keywords": [], - "author": "", - "license": "MIT", "packageManager": "pnpm@8.7.5", "engines": { "node": ">=16.0.0", diff --git a/src/changelog.ts b/src/changelog.ts index 55d903a..b8c11ba 100644 --- a/src/changelog.ts +++ b/src/changelog.ts @@ -2,7 +2,6 @@ import conventionalChangelog from 'conventional-changelog' import fse from 'fs-extra' import { createSpinner } from 'nanospinner' import { resolve as resolvePath } from 'path' -import { CWD } from './constant' const { createWriteStream } = fse @@ -19,7 +18,7 @@ export function changelog({ releaseCount = 0, file = 'CHANGELOG.md' }: Changelog preset: 'angular', releaseCount, }) - .pipe(createWriteStream(resolvePath(CWD, file))) + .pipe(createWriteStream(resolvePath(process.cwd(), file))) .on('close', () => { s.success({ text: 'Changelog generated success!' }) resolve() diff --git a/src/constant.ts b/src/constant.ts deleted file mode 100644 index c1b5010..0000000 --- a/src/constant.ts +++ /dev/null @@ -1 +0,0 @@ -export const CWD = process.cwd() diff --git a/src/index.ts b/src/index.ts index 60d2f22..211b437 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,22 +1,4 @@ import { release } from './release' import { changelog } from './changelog' -import { type Command } from 'commander' -function releaseCommand(program: Command) { - program - .command('release') - .option('-r --remote ', 'Remote name') - .description('Release all packages and generate changelogs') - .action(async (options) => release(options)) -} - -function changelogCommand(program: Command) { - program - .command('changelog') - .option('-rc --releaseCount ', 'Release count') - .option('-f --file ', 'Changelog filename') - .description('Generate changelog') - .action(async (options) => changelog(options)) -} - -export { release, changelog, releaseCommand, changelogCommand } +export { release, changelog } diff --git a/src/release.ts b/src/release.ts index f243eb5..c91c5c8 100644 --- a/src/release.ts +++ b/src/release.ts @@ -7,8 +7,8 @@ import { glob } from 'glob' import inquirer from 'inquirer' import { resolve } from 'path' import { changelog } from './changelog.js' -import { CWD } from './constant' +const cwd = process.cwd() const { writeFileSync, readJSONSync } = fse const { prompt } = inquirer @@ -50,7 +50,7 @@ function updateVersion(version: string) { packageJsons.push('package.json') packageJsons.forEach((path: string) => { - const file = resolve(CWD, path) + const file = resolve(cwd, path) const config = readJSONSync(file) config.version = version @@ -123,7 +123,7 @@ export interface ReleaseCommandOptions { export async function release(options: ReleaseCommandOptions) { try { - const currentVersion = readJSONSync(resolve(CWD, 'package.json')).version + const currentVersion = readJSONSync(resolve(cwd, 'package.json')).version if (!currentVersion) { logger.error('Your package is missing the version field')