-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
634ea7a
commit 7a1d972
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters