2021-10-14 10:38:45 +00:00
|
|
|
//
|
|
|
|
// Copyright 2021 Vulcanize, Inc.
|
|
|
|
//
|
|
|
|
|
|
|
|
import fs from 'fs';
|
|
|
|
import path from 'path';
|
|
|
|
import Handlebars from 'handlebars';
|
|
|
|
import { Writable } from 'stream';
|
|
|
|
|
2022-09-23 10:05:15 +00:00
|
|
|
const CHECKPOINT_TEMPLATE_FILE = './templates/checkpoint-template.handlebars';
|
|
|
|
const CREATE_TEMPLATE_FILE = './templates/checkpoint-create-template.handlebars';
|
|
|
|
const VERIFY_TEMPLATE_FILE = './templates/checkpoint-verify-template.handlebars';
|
2021-10-14 10:38:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Writes the checkpoint file generated from a template to a stream.
|
|
|
|
* @param outStream A writable output stream to write the checkpoint file to.
|
|
|
|
*/
|
2022-11-25 06:01:20 +00:00
|
|
|
export function exportCheckpoint (checkpointOutStream: Writable, checkpointCreateOutStream: Writable, checkpointVerifyOutStream: Writable | undefined): void {
|
2022-09-23 10:05:15 +00:00
|
|
|
const checkpointTemplateString = fs.readFileSync(path.resolve(__dirname, CHECKPOINT_TEMPLATE_FILE)).toString();
|
|
|
|
const checkpointTemplate = Handlebars.compile(checkpointTemplateString);
|
2022-11-25 06:01:20 +00:00
|
|
|
const checkpoint = checkpointTemplate({});
|
2022-09-23 10:05:15 +00:00
|
|
|
checkpointOutStream.write(checkpoint);
|
|
|
|
|
|
|
|
const createCheckpointTemplateString = fs.readFileSync(path.resolve(__dirname, CREATE_TEMPLATE_FILE)).toString();
|
|
|
|
const createCheckpointTemplate = Handlebars.compile(createCheckpointTemplateString);
|
2022-11-25 06:01:20 +00:00
|
|
|
const createCheckpoint = createCheckpointTemplate({});
|
2022-09-23 10:05:15 +00:00
|
|
|
checkpointCreateOutStream.write(createCheckpoint);
|
|
|
|
|
|
|
|
if (checkpointVerifyOutStream) {
|
|
|
|
const verifyCheckpointTemplateString = fs.readFileSync(path.resolve(__dirname, VERIFY_TEMPLATE_FILE)).toString();
|
|
|
|
const verifyCheckpointTemplate = Handlebars.compile(verifyCheckpointTemplateString);
|
|
|
|
const verifyCheckpointString = verifyCheckpointTemplate({});
|
|
|
|
checkpointVerifyOutStream.write(verifyCheckpointString);
|
|
|
|
}
|
2021-10-14 10:38:45 +00:00
|
|
|
}
|