Skip to content

Commit

Permalink
refactor: optimization flow
Browse files Browse the repository at this point in the history
  • Loading branch information
a145789 committed Nov 14, 2023
1 parent 15e8655 commit 6122090
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ jobs:
run: ni --frozen

- name: Lint
run: nr check
run: nr checkAll
20 changes: 20 additions & 0 deletions bin/index.js
Original file line number Diff line number Diff line change
@@ -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>', 'Remote name')
.description('Release all packages and generate changelogs')
.action(async (options) => release(options))

program
.command('changelog')
.option('-rc --releaseCount <releaseCount>', 'Release count')
.option('-f --file <file>', 'Changelog filename')
.description('Generate changelog')
.action(async (options) => changelog(options))

program.parse()
10 changes: 0 additions & 10 deletions bin/index.mjs

This file was deleted.

18 changes: 11 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>",
"license": "MIT",
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand All @@ -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": "[email protected]",
"engines": {
"node": ">=16.0.0",
Expand Down
3 changes: 1 addition & 2 deletions src/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()
Expand Down
1 change: 0 additions & 1 deletion src/constant.ts

This file was deleted.

20 changes: 1 addition & 19 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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>', 'Remote name')
.description('Release all packages and generate changelogs')
.action(async (options) => release(options))
}

function changelogCommand(program: Command) {
program
.command('changelog')
.option('-rc --releaseCount <releaseCount>', 'Release count')
.option('-f --file <file>', 'Changelog filename')
.description('Generate changelog')
.action(async (options) => changelog(options))
}

export { release, changelog, releaseCommand, changelogCommand }
export { release, changelog }
6 changes: 3 additions & 3 deletions src/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 6122090

Please sign in to comment.