Skip to content

Commit

Permalink
fix: release
Browse files Browse the repository at this point in the history
  • Loading branch information
shijinn520 committed Sep 28, 2024
1 parent 634ea7a commit 7a1d972
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Release and Publish
on:
push:
branches:
- main
permissions:
contents: write
pull-requests: write
jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: google-github-actions/release-please-action@v4
id: release
with:
release-type: node
default-branch: main
# Checkout
- uses: actions/checkout@v4
if: ${{ steps.release.outputs.release_created }}
# Setup node
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: "https://registry.npmjs.org"
if: ${{ steps.release.outputs.release_created }}
# Install dependencies
- run: npm install
env:
NODE_AUTH_TOKEN: ${{ secrets.RELEASE }}
if: ${{ steps.release.outputs.release_created }}
# Build output
- run: npm run build:npm
if: ${{ steps.release.outputs.release_created }}
# Publish to npm
- run: npm run pub
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
if: ${{ steps.release.outputs.release_created }}
21 changes: 21 additions & 0 deletions init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env node

import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'

const file = path.join(process.cwd(), 'package.json')
/** 获取当前文件的路径 */
const filePath = fileURLToPath(import.meta.url)

/** 如果不处于npm包环境 不修改 */
if (filePath.includes('node_modules')) {
const main = './' + path.relative(process.cwd(), path.join(path.dirname(filePath), './lib/index.js'))
const pkg = JSON.parse(fs.readFileSync(file, 'utf-8'))
pkg.type = 'module'
pkg.main = main
pkg.types = main.replace(/js$/, 'd.ts')
if (!pkg.scripts) pkg.scripts = {}
pkg.scripts.start = 'node ' + main
fs.writeFileSync(file, JSON.stringify(pkg, null, 2))
}
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@
"LICENSE",
"package.json"
],
"bin": {
"init": "init.js"
},
"scripts": {
"build": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json",
"postinstall": "node init.js",
"pub": "npm publish --access public",
"sort": "npx sort-package-json"
},
Expand Down

0 comments on commit 7a1d972

Please sign in to comment.