sf-agent-framework
Version:
AI Agent Orchestration Framework for Salesforce Development - Two-phase architecture with 70% context reduction
149 lines (122 loc) โข 5.14 kB
JavaScript
/**
* Build script for SF-Agent Framework CLI npm package
* Prepares the tools directory for npm publishing
*/
const fs = require('fs-extra');
const path = require('path');
async function buildNpmPackage() {
// Dynamic import for chalk ESM module
const chalk = (await import('chalk')).default;
console.log(chalk.blue('๐จ Building SF-Agent Framework CLI package for npm...'));
const rootDir = path.join(__dirname, '..');
const toolsDir = path.join(rootDir, 'tools');
const distDir = path.join(rootDir, 'dist-npm');
try {
// Clean dist directory
console.log(chalk.cyan('Cleaning distribution directory...'));
await fs.remove(distDir);
await fs.ensureDir(distDir);
// Copy tools directory contents
console.log(chalk.cyan('Copying CLI tools...'));
const filesToCopy = [
'cli.js',
'sf-agent-npx-wrapper.js',
'agent-creator.js',
'agent-handoff-protocol.js',
'codebase-flattener.js',
'document-sharder.js',
'interactive-workflow-builder.js',
'metrics-tracker.js',
'story-queue-manager.js',
'template-converter.js',
'template-processor.js',
'version-bump.js',
'workflow-visualizer.js',
'yaml-format.js',
'README-CLI.md',
];
for (const file of filesToCopy) {
const src = path.join(toolsDir, file);
const dest = path.join(distDir, file);
if (await fs.pathExists(src)) {
await fs.copy(src, dest);
console.log(chalk.gray(` โ ${file}`));
} else {
console.log(chalk.yellow(` โ ${file} not found`));
}
}
// Copy directories
const dirsToCopy = ['installer', 'builders', 'lib', 'md-assets', 'upgraders'];
for (const dir of dirsToCopy) {
const src = path.join(toolsDir, dir);
const dest = path.join(distDir, dir);
if (await fs.pathExists(src)) {
await fs.copy(src, dest);
console.log(chalk.gray(` โ ${dir}/`));
}
}
// Copy and rename package-cli.json to package.json
console.log(chalk.cyan('Creating package.json...'));
const packageCliPath = path.join(rootDir, 'package-cli.json');
const packageDestPath = path.join(distDir, 'package.json');
await fs.copy(packageCliPath, packageDestPath);
// Copy README as main README
const readmePath = path.join(distDir, 'README-CLI.md');
const mainReadmePath = path.join(distDir, 'README.md');
await fs.copy(readmePath, mainReadmePath);
// Create .npmrc for publishing configuration
console.log(chalk.cyan('Creating .npmrc...'));
const npmrcContent = `# NPM Publishing Configuration
registry=https://registry.npmjs.org/
access=public
`;
await fs.writeFile(path.join(distDir, '.npmrc'), npmrcContent);
// Create minimal LICENSE file
console.log(chalk.cyan('Creating LICENSE...'));
const licensePath = path.join(rootDir, 'LICENSE');
if (await fs.pathExists(licensePath)) {
await fs.copy(licensePath, path.join(distDir, 'LICENSE'));
} else {
const mitLicense = `MIT License
Copyright (c) 2024 SF-Agent Framework
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.`;
await fs.writeFile(path.join(distDir, 'LICENSE'), mitLicense);
}
console.log(chalk.green('\nโ
NPM package built successfully!'));
console.log(chalk.blue(`๐ฆ Package location: ${distDir}`));
console.log(chalk.cyan('\n๐ To publish to npm:'));
console.log(' 1. cd dist-npm');
console.log(' 2. npm login (if not already logged in)');
console.log(' 3. npm publish --dry-run (to test)');
console.log(' 4. npm publish (to publish)');
console.log(chalk.cyan('\n๐งช To test locally:'));
console.log(' 1. cd dist-npm');
console.log(' 2. npm link');
console.log(' 3. In another project: npm link sf-agent-framework');
console.log(' 4. Test: npx sf-agent-framework install');
return distDir;
} catch (error) {
console.error(chalk.red('โ Build failed:'), error.message);
process.exit(1);
}
}
// Run if called directly
if (require.main === module) {
buildNpmPackage();
}
module.exports = buildNpmPackage;