Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async loadTemplateFromBuffer(buffer) {
this.setState({ loading: true });
console.log('Loading template from Buffer');
let template;
try {
template = await Template.fromArchive(buffer);
} catch (error) {
console.log(`LOAD FAILED! ${error.message}`); // Error!
this.handleLoadingFailed(error.message);
return false;
}
try {
const newState = {...this.state};
newState.clause = new Clause(template);
newState.templateName = newState.clause.getTemplate().getMetadata().getName();
newState.templateVersion = newState.clause.getTemplate().getMetadata().getVersion();
newState.templateType = newState.clause.getTemplate().getMetadata().getTemplateType();
newState.package = JSON.stringify(template.getMetadata().getPackageJson(), null, 2);
newState.grammar = template.getParserManager().getTemplatizedGrammar();
newState.model = template.getModelManager().getModels();
newState.logic = template.getScriptManager().getLogic();
newState.text = template.getMetadata().getSamples().default;
static loadTemplate(templatePath, options) {
if (Commands.isTemplateArchive(templatePath)) {
const buffer = fs.readFileSync(templatePath);
return Template.fromArchive(buffer, options);
} else {
return Template.fromDirectory(templatePath, options);
}
}