Skip to content

Instantly share code, notes, and snippets.

@Souvikns
Last active February 12, 2022 12:11
Show Gist options
  • Save Souvikns/65838f8adc23734ed04b82c02b000c06 to your computer and use it in GitHub Desktop.
Save Souvikns/65838f8adc23734ed04b82c02b000c06 to your computer and use it in GitHub Desktop.
This is how the bundle command would look...
import {main, options} from '@asyncapi/bundler/cli';
import bundle from '@asyncapi/bundler';
import Command from './base';
import {Flags} from '@oclif/core';
export default class Bundle extends Command {
static strict = false;
static flags = options.getFlags(Flags);
async run(){
const {argv, flags} = this.parse(Bundle);
await main(argv, flags);
}
}
const bundle = require('./lib');
const fs = require('fs');
const path = require('path');
const main = async (args, flags) => {
let basepath;
if (flags['base']){
basepath = fs.readFile(path.resolve(process.cwd(), flags['base']), 'utf-8')
}
const document = await bundle(
args.map(filepath => fs.readFileSync(path.resolve(process.cwd(), filepath), 'utf-8')),
base: basepath
);
fs.writeFileSync(path.resolve(process.cwd(), flags['output']), document.yml());
}
const options = {
getFlags: (Flags) => ({
base: Flags.string({char: 'b'}),
output: Flags.string({char: 'o'})
})
}
module.exports = {
main,
options
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment