firmament
Version:
Modularized shell for NodeJS CLI applications
35 lines (31 loc) • 1.13 kB
text/typescript
import {injectable, inject} from 'inversify';
import {CommandUtil, Spawn} from 'firmament-yargs';
import {Package} from '../interfaces/Package';
import * as path from 'path';
import * as fs from 'fs';
()
export class PackageImpl implements Package {
constructor(('CommandUtil') private commandUtil: CommandUtil,
('Spawn') private spawn: Spawn) {
}
tar(argv: any) {
const me = this;
const serviceFolderToSend = path.resolve(__dirname, '../..');
fs.stat(serviceFolderToSend, (err) => {
me.commandUtil.processExitIfError(err);
me.commandUtil.log(`Packaging folder ${serviceFolderToSend} ...`);
try {
const writer = fs.createWriteStream(argv.output);
const pack = require('tar-pack').pack;
const packStream = pack(serviceFolderToSend, {ignoreFiles: ['.tar-packignore']});
writer
.on('finish', () => {
me.commandUtil.processExit(0, `${argv.output} written.`)
});
packStream.pipe(writer);
} catch(err) {
me.commandUtil.processExitWithError(err);
}
});
}
}