Skip to content

Commit b6db11e

Browse files
author
Demo User
committed
feat: Add npm package support with Node.js CLI and API
- Add package.json with npm configuration - Add lib/index.js with Node.js API wrapper - Add bin/cli.js with CLI commands (pto) - Add TypeScript type definitions in types/ - Add GitHub Actions for CI/CD - Add examples for JavaScript, React, and CLI usage - Add comprehensive documentation (API.md, CONTRIBUTING.md, CHANGELOG.md) - Update README.md with npm installation instructions - Add install scripts for automatic Python dependency setup
1 parent 127f0c7 commit b6db11e

26 files changed

Lines changed: 6037 additions & 1 deletion

.github/workflows/ci.yml

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
pull_request:
7+
branches: [main, master]
8+
9+
jobs:
10+
test:
11+
runs-on: ${{ matrix.os }}
12+
13+
strategy:
14+
matrix:
15+
os: [ubuntu-latest, macos-latest, windows-latest]
16+
node-version: [18, 20, 22]
17+
exclude:
18+
# Reduce matrix size for faster CI
19+
- os: macos-latest
20+
node-version: 18
21+
- os: windows-latest
22+
node-version: 18
23+
24+
steps:
25+
- name: Checkout code
26+
uses: actions/checkout@v4
27+
28+
- name: Setup Node.js ${{ matrix.node-version }}
29+
uses: actions/setup-node@v4
30+
with:
31+
node-version: ${{ matrix.node-version }}
32+
cache: 'npm'
33+
34+
- name: Setup Python
35+
uses: actions/setup-python@v5
36+
with:
37+
python-version: '3.11'
38+
39+
- name: Install Python dependencies (Ubuntu/macOS)
40+
if: runner.os != 'Windows'
41+
run: |
42+
python -m pip install --upgrade pip
43+
pip install Pillow numpy
44+
45+
- name: Install Python dependencies (Windows)
46+
if: runner.os == 'Windows'
47+
run: |
48+
python -m pip install --upgrade pip
49+
pip install Pillow numpy
50+
51+
- name: Install Node.js dependencies
52+
run: npm ci
53+
54+
- name: Run tests
55+
run: npm test
56+
57+
- name: Check code formatting
58+
run: |
59+
if [ -f .prettierrc ] || [ -f .prettierrc.json ] || [ -f .prettierrc.js ]; then
60+
npx prettier --check "**/*.js" || true
61+
fi
62+
if grep -q "eslint" package.json 2>/dev/null; then
63+
npx eslint . || true
64+
fi
65+
shell: bash
66+
67+
build:
68+
runs-on: ubuntu-latest
69+
needs: test
70+
71+
steps:
72+
- name: Checkout code
73+
uses: actions/checkout@v4
74+
75+
- name: Setup Node.js
76+
uses: actions/setup-node@v4
77+
with:
78+
node-version: '20'
79+
cache: 'npm'
80+
81+
- name: Setup Python
82+
uses: actions/setup-python@v5
83+
with:
84+
python-version: '3.11'
85+
86+
- name: Install Python dependencies
87+
run: |
88+
python -m pip install --upgrade pip
89+
pip install Pillow numpy
90+
91+
- name: Install dependencies
92+
run: npm ci
93+
94+
- name: Build package
95+
run: npm run build || echo "No build script found"
96+
97+
lint:
98+
runs-on: ubuntu-latest
99+
100+
steps:
101+
- name: Checkout code
102+
uses: actions/checkout@v4
103+
104+
- name: Setup Node.js
105+
uses: actions/setup-node@v4
106+
with:
107+
node-version: '20'
108+
cache: 'npm'
109+
110+
- name: Install dependencies
111+
run: npm ci
112+
113+
- name: Run ESLint
114+
run: |
115+
if grep -q "eslint" package.json 2>/dev/null; then
116+
npx eslint . || true
117+
else
118+
echo "ESLint not configured, skipping"
119+
fi
120+
shell: bash
121+
122+
- name: Check package.json
123+
run: |
124+
node -e "const pkg = require('./package.json'); console.log('Package name:', pkg.name); console.log('Version:', pkg.version);"

.github/workflows/publish.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Publish to NPM
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
15+
- name: Setup Node.js
16+
uses: actions/setup-node@v4
17+
with:
18+
node-version: '20'
19+
registry-url: 'https://registry.npmjs.org'
20+
cache: 'npm'
21+
22+
- name: Setup Python
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: '3.11'
26+
27+
- name: Install Python dependencies
28+
run: |
29+
python -m pip install --upgrade pip
30+
pip install Pillow numpy
31+
32+
- name: Install dependencies
33+
run: npm ci
34+
35+
- name: Run tests
36+
run: npm test
37+
38+
- name: Build package
39+
run: npm run build || echo "No build script found"
40+
41+
- name: Publish to NPM
42+
run: npm publish --access public
43+
env:
44+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
45+
46+
- name: Notify on success
47+
if: success()
48+
run: |
49+
echo "✅ Package published successfully to NPM!"
50+
echo "Package: $(node -p "require('./package.json').name")"
51+
echo "Version: $(node -p "require('./package.json').version")"
52+
53+
- name: Notify on failure
54+
if: failure()
55+
run: |
56+
echo "❌ Failed to publish package to NPM"
57+
echo "Please check the logs above for details"
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Release Please
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
9+
permissions:
10+
contents: write
11+
pull-requests: write
12+
13+
jobs:
14+
release-please:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Release Please
19+
uses: googleapis/release-please-action@v4
20+
with:
21+
token: ${{ secrets.GITHUB_TOKEN }}
22+
release-type: node
23+
package-name: perfect-text-overlay
24+
# 自动生成CHANGELOG.md
25+
changelog-types: |
26+
[
27+
{"type": "feat", "section": "Features", "hidden": false},
28+
{"type": "fix", "section": "Bug Fixes", "hidden": false},
29+
{"type": "docs", "section": "Documentation", "hidden": false},
30+
{"type": "style", "section": "Styles", "hidden": false},
31+
{"type": "refactor", "section": "Code Refactoring", "hidden": false},
32+
{"type": "perf", "section": "Performance Improvements", "hidden": false},
33+
{"type": "test", "section": "Tests", "hidden": false},
34+
{"type": "build", "section": "Build System", "hidden": false},
35+
{"type": "ci", "section": "CI/CD", "hidden": false},
36+
{"type": "chore", "section": "Chores", "hidden": false}
37+
]
38+
39+
- name: Checkout code (on release created)
40+
if: ${{ steps.release.outputs.release_created }}
41+
uses: actions/checkout@v4
42+
43+
- name: Setup Node.js (on release created)
44+
if: ${{ steps.release.outputs.release_created }}
45+
uses: actions/setup-node@v4
46+
with:
47+
node-version: '20'
48+
registry-url: 'https://registry.npmjs.org'
49+
50+
- name: Publish to NPM (on release created)
51+
if: ${{ steps.release.outputs.release_created }}
52+
run: npm publish --access public
53+
env:
54+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,9 @@ build/
2222
*.jpg
2323
*.jpeg
2424
!assets/font_preview.png
25+
26+
# Node.js
27+
node_modules/
28+
npm-debug.log*
29+
yarn-debug.log*
30+
yarn-error.log*

.npmignore

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Development files
2+
.git
3+
.gitignore
4+
node_modules/
5+
.DS_Store
6+
*.log
7+
npm-debug.log*
8+
yarn-debug.log*
9+
yarn-error.log*
10+
11+
# Test files
12+
test/
13+
tests/
14+
*.test.js
15+
*.spec.js
16+
__tests__/
17+
coverage/
18+
19+
# Documentation (keep README.md)
20+
docs/
21+
*.md
22+
!README.md
23+
24+
# CI/CD
25+
.github/
26+
.gitlab-ci.yml
27+
.travis.yml
28+
29+
# Editor files
30+
.vscode/
31+
.idea/
32+
*.swp
33+
*.swo
34+
*~
35+
.editorconfig
36+
37+
# Build artifacts
38+
dist/
39+
build/
40+
*.tgz
41+
42+
# Temporary files
43+
*.tmp
44+
*.temp
45+
tmp/
46+
temp/
47+
48+
# Python cache
49+
__pycache__/
50+
*.pyc
51+
*.pyo
52+
*.pyd
53+
.Python
54+
55+
# Don't ignore these (will be included)
56+
!lib/
57+
!bin/
58+
!scripts/
59+
!assets/

0 commit comments

Comments
 (0)