@langgraph-js/bundler
Version:
Build tool for LangGraph.js applications that packages graph configurations into deployable modules
76 lines (72 loc) • 2.31 kB
JavaScript
import { buildLanggraph } from './build.js';
import path from 'path';
import { readFile } from 'fs/promises';
import { fileURLToPath } from 'url';
// 解析命令行参数
const args = process.argv.slice(2);
const options = {
cwd: process.cwd(),
help: false,
version: false,
db: 'postgres', // 默认数据库类型为 postgres
};
// 获取当前文件的目录
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// 读取package.json获取版本号
const packagePath = path.resolve(__dirname, '../package.json');
const packageJson = JSON.parse(await readFile(packagePath, 'utf-8'));
const { version } = packageJson;
// 解析命令行参数
for (let i = 0; i < args.length; i++) {
const arg = args[i];
if (arg === '--help' || arg === '-h') {
options.help = true;
}
else if (arg === '--version' || arg === '-v') {
options.version = true;
}
else if (arg === '--cwd' && i + 1 < args.length) {
options.cwd = path.resolve(process.cwd(), args[++i]);
}
else if (arg.startsWith('--db=')) {
const dbType = arg.split('=')[1];
if (dbType === 'sqlite' || dbType === 'postgres') {
options.db = dbType;
}
else {
console.warn(`不支持的数据库类型: ${dbType},使用默认值 sqlite`);
}
}
}
// 显示帮助信息
if (options.help) {
console.log(`
@langgraph-js/bundler v${version}
A build tool for LangGraph.js applications that packages graph configurations into deployable modules.
USAGE:
npx @langgraph-js/bundler [OPTIONS]
OPTIONS:
--help, -h 显示帮助信息
--version, -v 显示版本信息
--cwd <path> 指定工作目录 (默认: 当前目录)
--db=<type> 指定数据库类型,可选值: sqlite, postgres (默认: postgres)
EXAMPLES:
npx @langgraph-js/bundler
npx @langgraph-js/bundler --cwd ./my-project
npx @langgraph-js/bundler --db=postgres
`);
process.exit(0);
}
// 显示版本信息
if (options.version) {
console.log(`@langgraph-js/bundler v${version}`);
process.exit(0);
}
// 执行构建
buildLanggraph(options.cwd, options.db).catch((err) => {
console.error('构建失败:', err);
process.exit(1);
});
//# sourceMappingURL=cli.js.map