**feat(cli): add local testing script for CLI and update versions**
- Introduced `scripts/test-cli-locally.js` to streamline local testing of the CLI package before publishing. - Builds main and CLI packages, creates local tarballs, and installs the CLI package globally for testing. - Ensures version synchronization between main and CLI packages during testing. - Updated `cli-package/package.json` version to `0.9.23` and synchronized `@soulcraft/brainy` dependency to `0.9.22`. - Patched `TextEncoder` fallback for Node.js v24 in `cli-wrapper.js` to ensure overall CLI compatibility. - Added new `test-cli` npm script to `package.json`. This update simplifies the CLI local testing process, maintains version alignment, and improves readiness for Node.js v24.
This commit is contained in:
parent
8488f77087
commit
cac58ac0b2
6 changed files with 118 additions and 11 deletions
|
|
@ -12,6 +12,21 @@ import { fileURLToPath } from 'url'
|
|||
import { dirname, join } from 'path'
|
||||
import fs from 'fs'
|
||||
|
||||
// Fix for TextEncoder in Node.js v24
|
||||
// In Node.js v24, TextEncoder is a global object and not part of the util module
|
||||
// This patch ensures that the util module has TextEncoder available for TensorFlow.js
|
||||
if (process.versions.node.startsWith('24')) {
|
||||
try {
|
||||
const util = await import('util')
|
||||
if (!util.TextEncoder && typeof TextEncoder !== 'undefined') {
|
||||
util.TextEncoder = TextEncoder
|
||||
util.TextDecoder = TextDecoder
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Warning: Failed to patch TextEncoder for Node.js v24:', error.message)
|
||||
}
|
||||
}
|
||||
|
||||
// Get the directory of the current module
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
const __dirname = dirname(__filename)
|
||||
|
|
|
|||
12
cli-package/package-lock.json
generated
12
cli-package/package-lock.json
generated
|
|
@ -1,16 +1,16 @@
|
|||
{
|
||||
"name": "@soulcraft/brainy-cli",
|
||||
"version": "0.9.21",
|
||||
"version": "0.9.22",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@soulcraft/brainy-cli",
|
||||
"version": "0.9.21",
|
||||
"version": "0.9.22",
|
||||
"hasInstallScript": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@soulcraft/brainy": "0.9.21",
|
||||
"@soulcraft/brainy": "0.9.22",
|
||||
"commander": "^14.0.0",
|
||||
"omelette": "^0.4.17"
|
||||
},
|
||||
|
|
@ -2086,9 +2086,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@soulcraft/brainy": {
|
||||
"version": "0.9.21",
|
||||
"resolved": "https://registry.npmjs.org/@soulcraft/brainy/-/brainy-0.9.21.tgz",
|
||||
"integrity": "sha512-UimglEpucGsiRXZlsSx4jZis0cIGKAxPU7lk/m6LvygRm01r9NPTCpsrT3mp38JMbEkzm4JpmP8vHaC5hWzXZQ==",
|
||||
"version": "0.9.22",
|
||||
"resolved": "https://registry.npmjs.org/@soulcraft/brainy/-/brainy-0.9.22.tgz",
|
||||
"integrity": "sha512-hzEky/l4IncMIp2dMspykYD903ynft2pn6Lw9eJjZ22WhOH0pvmdX8G6sYk+7IBwY5CSSw5dm3T4EPJc53gegA==",
|
||||
"hasInstallScript": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@soulcraft/brainy-cli",
|
||||
"version": "0.9.21",
|
||||
"version": "0.9.23",
|
||||
"description": "Command-line interface for the Brainy vector graph database",
|
||||
"type": "module",
|
||||
"bin": {
|
||||
|
|
@ -39,7 +39,7 @@
|
|||
"url": "https://github.com/soulcraft-research/brainy.git"
|
||||
},
|
||||
"dependencies": {
|
||||
"@soulcraft/brainy": "0.9.21",
|
||||
"@soulcraft/brainy": "0.9.22",
|
||||
"commander": "^14.0.0",
|
||||
"omelette": "^0.4.17"
|
||||
},
|
||||
|
|
@ -57,4 +57,4 @@
|
|||
"engines": {
|
||||
"node": ">=24.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,8 @@
|
|||
"deploy:cloud:cloudflare": "cd cloud-wrapper && npm run build && npm run deploy:cloudflare",
|
||||
"deploy:cloud": "echo 'Please use one of the following commands to deploy to a specific cloud provider:' && echo ' npm run deploy:cloud:aws' && echo ' npm run deploy:cloud:gcp' && echo ' npm run deploy:cloud:cloudflare'",
|
||||
"postinstall": "echo 'Note: If you encounter dependency conflicts with TensorFlow.js packages, please use: npm install --legacy-peer-deps'",
|
||||
"dry-run": "npm pack --dry-run"
|
||||
"dry-run": "npm pack --dry-run",
|
||||
"test-cli": "node scripts/test-cli-locally.js"
|
||||
},
|
||||
"keywords": [
|
||||
"vector-database",
|
||||
|
|
|
|||
91
scripts/test-cli-locally.js
Executable file
91
scripts/test-cli-locally.js
Executable file
|
|
@ -0,0 +1,91 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Test CLI Package Locally
|
||||
*
|
||||
* This script allows testing the CLI package locally before publishing to npm.
|
||||
* It builds both packages, creates local tarballs, and installs the CLI package
|
||||
* globally for testing.
|
||||
*/
|
||||
|
||||
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);
|
||||
const rootDir = path.join(__dirname, '..');
|
||||
const cliPackageDir = path.join(rootDir, 'cli-package');
|
||||
|
||||
// Ensure the CLI package directory exists
|
||||
if (!fs.existsSync(cliPackageDir)) {
|
||||
console.error(`Error: CLI package directory not found at ${cliPackageDir}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
// Step 1: Ensure versions are in sync
|
||||
console.log('Ensuring versions are in sync...');
|
||||
execSync('node scripts/generate-version.js', { stdio: 'inherit', cwd: rootDir });
|
||||
|
||||
// Step 2: Build the main package
|
||||
console.log('Building main package...');
|
||||
execSync('npm run build', { stdio: 'inherit', cwd: rootDir });
|
||||
|
||||
// Step 3: Create a local tarball of the main package
|
||||
console.log('Creating local tarball of main package...');
|
||||
const mainPackOutput = execSync('npm pack', { cwd: rootDir }).toString().trim();
|
||||
const mainPackageTarball = path.join(rootDir, mainPackOutput);
|
||||
console.log(`Main package tarball created: ${mainPackageTarball}`);
|
||||
|
||||
// Step 4: Build the CLI package
|
||||
console.log('Building CLI package...');
|
||||
execSync('npm run build', { stdio: 'inherit', cwd: cliPackageDir });
|
||||
|
||||
// Step 5: Verify the CLI was built successfully
|
||||
const cliPath = path.join(cliPackageDir, 'dist', 'cli.js');
|
||||
if (!fs.existsSync(cliPath)) {
|
||||
console.error(`Error: CLI build failed. File not found at ${cliPath}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Step 6: Temporarily update the CLI package.json to use the local main package
|
||||
console.log('Updating CLI package.json to use local main package...');
|
||||
const cliPackageJsonPath = path.join(cliPackageDir, 'package.json');
|
||||
const cliPackageJson = JSON.parse(fs.readFileSync(cliPackageJsonPath, 'utf8'));
|
||||
|
||||
// Save the original dependency for restoration later
|
||||
const originalDependency = cliPackageJson.dependencies['@soulcraft/brainy'];
|
||||
|
||||
// Update to use the local tarball
|
||||
cliPackageJson.dependencies['@soulcraft/brainy'] = `file:${mainPackageTarball}`;
|
||||
|
||||
// Write the updated package.json
|
||||
fs.writeFileSync(cliPackageJsonPath, JSON.stringify(cliPackageJson, null, 2));
|
||||
|
||||
// Step 7: Create a local tarball of the CLI package
|
||||
console.log('Creating local tarball of CLI package...');
|
||||
const cliPackOutput = execSync('npm pack', { cwd: cliPackageDir }).toString().trim();
|
||||
const cliPackageTarball = path.join(cliPackageDir, cliPackOutput);
|
||||
console.log(`CLI package tarball created: ${cliPackageTarball}`);
|
||||
|
||||
// Step 8: Restore the original dependency in CLI package.json
|
||||
console.log('Restoring original dependency in CLI package.json...');
|
||||
cliPackageJson.dependencies['@soulcraft/brainy'] = originalDependency;
|
||||
fs.writeFileSync(cliPackageJsonPath, JSON.stringify(cliPackageJson, null, 2));
|
||||
|
||||
// Step 9: Install the CLI package globally for testing
|
||||
console.log('Installing CLI package globally for testing...');
|
||||
execSync(`npm install -g ${cliPackageTarball}`, { stdio: 'inherit' });
|
||||
|
||||
console.log('\nCLI package installed globally for testing!');
|
||||
console.log('You can now run the CLI using the "brainy" command.');
|
||||
console.log('\nTo uninstall after testing:');
|
||||
console.log('npm uninstall -g @soulcraft/brainy-cli');
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error:', error.message);
|
||||
process.exit(1);
|
||||
}
|
||||
|
|
@ -3,4 +3,4 @@
|
|||
* Do not modify this file directly.
|
||||
*/
|
||||
|
||||
export const VERSION = '0.9.21';
|
||||
export const VERSION = '0.9.22';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue