**chore(release): bump version to 0.10.0 and refactor project structure**
- Updated version to `0.10.0` in `README.md`, `cli-package/package.json`, and `src/utils/version.ts`. - Removed `CHANGELOG.md` from the root and `cli-package`, as GitHub auto-generates release notes. - Refactored `brainy-wrapper.js` to simplify utility methods (`isFloat32Array` and `isTypedArray`) by moving them to instance-level definitions. - Standardized Node.js version requirement to `>= 24.3.0` across documentation and configuration files. - Improved `textEncoding.ts` by introducing a unified `Platform` class for cross-environment compatibility (Node.js and browser). - Restructured scripts: - Replaced outdated commands (e.g., `test-cli` -> `test:cli` and `test-all` -> `test:all`) for consistency. - Removed changelog updates from `scripts/create-github-release.js` as part of simplification. - Enhanced `patch-textencoder.js` to also patch `worker.js` for both `TextEncoder` and `TextDecoder`. This release improves compatibility with Node.js 24, simplifies the deployment/changelog process, and refines text encoding and worker functionalities.
This commit is contained in:
parent
1a88aecdb6
commit
00039f836f
18 changed files with 183 additions and 292 deletions
|
|
@ -81,17 +81,15 @@ try {
|
|||
|
||||
console.log(`GitHub release v${version} created successfully!`)
|
||||
|
||||
// Update CHANGELOG.md with the release notes
|
||||
console.log('Updating CHANGELOG.md with release notes...')
|
||||
execSync('node scripts/update-changelog.js', { stdio: 'inherit', cwd: rootDir })
|
||||
// GitHub will automatically handle the changelog
|
||||
console.log('GitHub release created with auto-generated notes')
|
||||
} catch (error) {
|
||||
// If the release already exists, this is not a fatal error
|
||||
if (error.message.includes('already exists')) {
|
||||
console.log(`GitHub release v${version} already exists, skipping creation.`)
|
||||
|
||||
// Still update CHANGELOG.md with the release notes
|
||||
console.log('Updating CHANGELOG.md with release notes...')
|
||||
execSync('node scripts/update-changelog.js', { stdio: 'inherit', cwd: rootDir })
|
||||
// GitHub will automatically handle the changelog
|
||||
console.log('GitHub release already exists with auto-generated notes')
|
||||
} else {
|
||||
console.error('Error creating GitHub release:', error.message)
|
||||
// Don't exit with error to allow the npm publish to continue
|
||||
|
|
|
|||
|
|
@ -63,6 +63,28 @@ if (fs.existsSync(minifiedJsPath)) {
|
|||
}
|
||||
}
|
||||
|
||||
// Also patch the worker.js file if it exists
|
||||
const workerJsPath = path.join(__dirname, '..', 'dist', 'worker.js')
|
||||
if (fs.existsSync(workerJsPath)) {
|
||||
console.log(`Reading ${workerJsPath}...`)
|
||||
const workerContent = fs.readFileSync(workerJsPath, 'utf8')
|
||||
|
||||
// Apply the same replacement to the worker file
|
||||
const patchedWorkerContent = workerContent.replace(pattern, replacement)
|
||||
|
||||
// Check if the patch was applied
|
||||
if (patchedWorkerContent === workerContent) {
|
||||
console.warn(
|
||||
'No instances of "new this.util.TextEncoder()" found in the worker file.'
|
||||
)
|
||||
} else {
|
||||
// Write the patched file
|
||||
console.log('Writing patched worker file...')
|
||||
fs.writeFileSync(workerJsPath, patchedWorkerContent, 'utf8')
|
||||
console.log('Worker file patched successfully!')
|
||||
}
|
||||
}
|
||||
|
||||
// Also patch TextDecoder
|
||||
console.log('Patching TextDecoder references...')
|
||||
content = fs.readFileSync(unifiedJsPath, 'utf8')
|
||||
|
|
@ -99,3 +121,21 @@ if (fs.existsSync(minifiedJsPath)) {
|
|||
console.log('TextDecoder patch applied to minified file successfully!')
|
||||
}
|
||||
}
|
||||
|
||||
// Patch the worker.js file for TextDecoder as well
|
||||
if (fs.existsSync(workerJsPath)) {
|
||||
const workerContent = fs.readFileSync(workerJsPath, 'utf8')
|
||||
const patchedWorkerDecoderContent = workerContent.replace(
|
||||
decoderPattern,
|
||||
decoderReplacement
|
||||
)
|
||||
|
||||
if (patchedWorkerDecoderContent === workerContent) {
|
||||
console.warn(
|
||||
'No instances of "new this.util.TextDecoder()" found in the worker file.'
|
||||
)
|
||||
} else {
|
||||
fs.writeFileSync(workerJsPath, patchedWorkerDecoderContent, 'utf8')
|
||||
console.log('TextDecoder patch applied to worker file successfully!')
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -224,7 +224,7 @@ async function runAllTests() {
|
|||
// Run CLI tests
|
||||
log('Testing CLI package locally...', colors.yellow)
|
||||
try {
|
||||
runCommand('npm run test-cli')
|
||||
runCommand('npm run test:cli')
|
||||
log('CLI test completed!', colors.green)
|
||||
|
||||
// Run some basic CLI commands to verify functionality
|
||||
|
|
@ -245,7 +245,7 @@ async function runAllTests() {
|
|||
colors.yellow
|
||||
)
|
||||
log(
|
||||
'You can run the CLI tests separately with: npm run test-cli',
|
||||
'You can run the CLI tests separately with: npm run test:cli',
|
||||
colors.yellow
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,138 +0,0 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Update Changelog Script
|
||||
*
|
||||
* This script updates the CHANGELOG.md file with the latest release notes
|
||||
* from GitHub. It's designed to be called after creating a GitHub release.
|
||||
*
|
||||
* The script:
|
||||
* 1. Gets the current version from package.json
|
||||
* 2. Fetches the release notes from GitHub for that version
|
||||
* 3. Updates the CHANGELOG.md file with the new release notes
|
||||
*
|
||||
* This ensures that the CHANGELOG.md file is always up-to-date with the
|
||||
* latest release notes, which will be displayed on npmjs.com.
|
||||
*/
|
||||
|
||||
import { execSync } from 'child_process'
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
// Get the directory of the current module
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
const __dirname = path.dirname(__filename)
|
||||
|
||||
// Path to the root directory
|
||||
const rootDir = path.join(__dirname, '..')
|
||||
|
||||
// Path to package.json
|
||||
const packageJsonPath = path.join(rootDir, 'package.json')
|
||||
|
||||
// Path to CHANGELOG.md
|
||||
const changelogPath = path.join(rootDir, 'CHANGELOG.md')
|
||||
|
||||
// Read package.json
|
||||
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
|
||||
const version = packageJson.version
|
||||
|
||||
// Check if GitHub CLI is installed
|
||||
try {
|
||||
execSync('gh --version', { stdio: 'ignore' })
|
||||
} catch (error) {
|
||||
console.error('Error: GitHub CLI (gh) is not installed or not in PATH')
|
||||
console.error('Please install it from https://cli.github.com/ and authenticate with `gh auth login`')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
// Fetch release notes from GitHub
|
||||
try {
|
||||
console.log(`Fetching release notes for v${version} from GitHub...`)
|
||||
|
||||
// Get the release notes using GitHub CLI
|
||||
const releaseNotes = execSync(
|
||||
`gh release view v${version} --json body --jq .body`,
|
||||
{ encoding: 'utf8', cwd: rootDir }
|
||||
).trim()
|
||||
|
||||
// Create or update the CHANGELOG.md file
|
||||
let changelog = ''
|
||||
|
||||
// If CHANGELOG.md exists, read its content
|
||||
if (fs.existsSync(changelogPath)) {
|
||||
changelog = fs.readFileSync(changelogPath, 'utf8')
|
||||
} else {
|
||||
// Create a new CHANGELOG.md file with a header
|
||||
changelog = '# Changelog\n\nAll notable changes to this project will be documented in this file.\n\n'
|
||||
}
|
||||
|
||||
// Format the new entry
|
||||
const date = new Date().toISOString().split('T')[0]
|
||||
const newEntry = `## [${version}] - ${date}\n\n${releaseNotes}\n\n`
|
||||
|
||||
// Check if this version is already in the changelog
|
||||
if (changelog.includes(`## [${version}]`)) {
|
||||
// Replace the existing entry
|
||||
const versionRegex = new RegExp(`## \\[${version}\\].*?(?=## \\[|$)`, 's')
|
||||
changelog = changelog.replace(versionRegex, newEntry)
|
||||
} else {
|
||||
// Add the new entry after the header (before the first version entry)
|
||||
const firstVersionIndex = changelog.search(/## \[\d+\.\d+\.\d+\]/)
|
||||
|
||||
if (firstVersionIndex !== -1) {
|
||||
// Insert before the first version entry
|
||||
changelog = changelog.slice(0, firstVersionIndex) + newEntry + changelog.slice(firstVersionIndex)
|
||||
} else {
|
||||
// No existing version entries, append to the end
|
||||
changelog += newEntry
|
||||
}
|
||||
}
|
||||
|
||||
// Write the updated changelog
|
||||
fs.writeFileSync(changelogPath, changelog)
|
||||
|
||||
console.log(`CHANGELOG.md updated with release notes for v${version}`)
|
||||
|
||||
// Also update the CLI package's CHANGELOG.md
|
||||
const cliChangelogPath = path.join(rootDir, 'cli-package', 'CHANGELOG.md')
|
||||
|
||||
// Create or update the CLI CHANGELOG.md file
|
||||
let cliChangelog = ''
|
||||
|
||||
// If CLI CHANGELOG.md exists, read its content
|
||||
if (fs.existsSync(cliChangelogPath)) {
|
||||
cliChangelog = fs.readFileSync(cliChangelogPath, 'utf8')
|
||||
} else {
|
||||
// Create a new CHANGELOG.md file with a header
|
||||
cliChangelog = '# Changelog\n\nAll notable changes to this project will be documented in this file.\n\n'
|
||||
}
|
||||
|
||||
// Check if this version is already in the changelog
|
||||
if (cliChangelog.includes(`## [${version}]`)) {
|
||||
// Replace the existing entry
|
||||
const versionRegex = new RegExp(`## \\[${version}\\].*?(?=## \\[|$)`, 's')
|
||||
cliChangelog = cliChangelog.replace(versionRegex, newEntry)
|
||||
} else {
|
||||
// Add the new entry after the header (before the first version entry)
|
||||
const firstVersionIndex = cliChangelog.search(/## \[\d+\.\d+\.\d+\]/)
|
||||
|
||||
if (firstVersionIndex !== -1) {
|
||||
// Insert before the first version entry
|
||||
cliChangelog = cliChangelog.slice(0, firstVersionIndex) + newEntry + cliChangelog.slice(firstVersionIndex)
|
||||
} else {
|
||||
// No existing version entries, append to the end
|
||||
cliChangelog += newEntry
|
||||
}
|
||||
}
|
||||
|
||||
// Write the updated CLI changelog
|
||||
fs.writeFileSync(cliChangelogPath, cliChangelog)
|
||||
|
||||
console.log(`CLI package CHANGELOG.md updated with release notes for v${version}`)
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error updating CHANGELOG.md:', error.message)
|
||||
// Don't exit with error to allow the process to continue
|
||||
// process.exit(1)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue