import * as fs from 'fs'; import {command, defaultValue, help, namespace, param} from 'oo-cli'; import * as path from 'path'; import {appContext} from '../../lib/AppContext'; import {AppPackager} from '../../lib/AppPackager'; import {die} from '../../lib/die'; import {directoryExists} from '../../lib/directoryExists'; import {formatError} from '../../lib/formatError'; @namespace('app') export class PackageCommand { @param @help('The root directory of the app') @defaultValue('./') public path!: string; @command @help('Prepare a package for manual upload') public async package() { try { const workingDir = process.cwd(); if (!directoryExists(this.path)) { die('Specified path to app does not exist'); return; } process.chdir(this.path); const context = appContext(); if (!context.appId || !context.version) { die('Unable to read App ID or version info. Ensure you are uploading the right directory.'); return; } if (context) { const packageData = await new AppPackager('./').package(); const zipFileName = `${context.appId}@${context.version}.zip`; fs.writeFileSync(path.join(workingDir, zipFileName), packageData); console.log(`Created package ${zipFileName}`); } } catch (e: any) { die(formatError(e)); } } }