import * as AdmZip from 'adm-zip'; import * as chalk from 'chalk'; import * as fs from 'fs'; import * as path from 'path'; import * as globby from 'globby'; export class AppPackager { private rootPath: string; constructor(rootPath: string) { this.rootPath = path.resolve(rootPath); } public async package() { console.log(chalk.gray(`Packaging files in ${this.rootPath}`)); const files = await globby(['**/*'], { gitignore: true, // respects .gitignore ignore: ['node_modules/**/*', '*.zip', '.git/**/*', '.ocp-local/**/*'], cwd: this.rootPath, dot: true, onlyFiles: true, }); return this.createZip(this.rootPath, files); } private createZip(srcPath: string, files: string[]): Buffer { const zip = new AdmZip(); files.forEach((file) => { const filePath = path.join(srcPath, file); if (fs.existsSync(filePath)) { console.log(chalk.gray(`${file}`)); zip.addFile(file, fs.readFileSync(filePath)); } }); return zip.toBuffer(); } }