cli-stash
Version:
CLI application to manage and work with Atlassian Stash. Work with your Stash project and repositories from Command lines.
68 lines (67 loc) • 2.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@oclif/core");
const stash_connector_1 = require("stash-connector");
const baseCommand_1 = require("../../libs/core/baseCommand");
const stashResponse_1 = require("../../libs/core/stashResponse");
const fileSystem_1 = require("../../libs/fileSystem");
class Download extends baseCommand_1.BaseCommand {
async run() {
const response = new stashResponse_1.StashCLIResponse();
const connector = new stash_connector_1.StashConnector(this.localConfig.getConnectorOptions(this.flags.alias));
try {
const markupPreview = await connector.markup.preview(this.getInputData(), {
hardwrap: this.flags.hardwrap,
htmlEscape: this.flags.escape,
urlMode: this.flags.mode,
});
response.result = markupPreview.html;
response.status = 0;
response.message = this.getRecordRetrievedText('Markup Preview');
if (!this.flags['output-file']) {
this.ux.log(markupPreview.html);
}
else {
const absolutePath = fileSystem_1.PathUtils.getAbsolutePath(this.flags['output-file']);
const basePath = fileSystem_1.PathUtils.getDirname(absolutePath);
if (!fileSystem_1.FileChecker.isExists(basePath)) {
fileSystem_1.FileWriter.createFolderSync(basePath);
}
fileSystem_1.FileWriter.createFileSync(absolutePath, markupPreview.html);
}
}
catch (error) {
this.processError(response, error);
}
return response;
}
}
exports.default = Download;
Download.description = 'Preview the generated html for given markdown contents';
Download.examples = [
`$ stash markup:prewiew -a MyStashAlias --data "#My Markdown Content to preview"`,
`$ stash markup:prewiew -a MyStashAlias --file "path/to/markdown/file"`,
`$ stash markup:prewiew -a MyStashAlias --data "#My Markdown Content to preview" --output-file "path/to/the/output/file.html" --json`,
];
Download.flags = {
...baseCommand_1.BaseCommand.flags,
alias: baseCommand_1.BuildFlags.alias,
data: baseCommand_1.BuildFlags.input.data('', false),
file: baseCommand_1.BuildFlags.input.file('', false),
mode: core_1.Flags.string({
description: 'The URL Mode.',
required: false,
name: 'Mode'
}),
hardwrap: core_1.Flags.boolean({
description: 'Hardwrap.',
required: false,
name: 'Hardwrap'
}),
escape: core_1.Flags.string({
description: 'Escape HTML.',
required: false,
name: 'HTML Escape'
}),
'output-file': baseCommand_1.BuildFlags.output.file('', false),
};