/** * Package command * * Creates distributable .netapp packages from module source directories */ import { resolve } from 'node:path'; import { buildModule } from '../../module/packaging/build'; import { getArg, getFlag, validateRequiredArgs } from '../parser'; import type { CommandResult } from '../types'; /** * Handle package command * * Usage: * celilo package [--output ] * * @param args - Command arguments * @param flags - Command flags * @returns Command result */ export async function handlePackage( args: string[], flags: Record, ): Promise { // Validate arguments const error = validateRequiredArgs(args, 1); if (error) { return { success: false, error: `${error}\n\nUsage:\n celilo package [--output ]`, }; } const sourceDir = getArg(args, 0); if (!sourceDir) { return { success: false, error: 'Source directory is required', }; } // Resolve paths relative to the user's original cwd, not the backend directory const originalCwd = process.env.CELILO_ORIGINAL_CWD || process.cwd(); const resolvedSourceDir = resolve(originalCwd, sourceDir); const outputPath = getFlag(flags, 'output'); const resolvedOutputPath = outputPath ? resolve(originalCwd, outputPath as string) : undefined; const result = await buildModule({ sourceDir: resolvedSourceDir, outputPath: resolvedOutputPath, }); if (!result.success) { return { success: false, error: result.error || 'Package creation failed', }; } return { success: true, message: `Successfully created module package: ${result.packagePath}`, data: { packagePath: result.packagePath, }, }; }