mirror of
https://github.com/cerc-io/watcher-ts
synced 2026-09-08 00:44:06 +00:00
Optional server port arg. for watcher generation (#284)
This commit is contained in:
@@ -12,14 +12,16 @@ const TEMPLATE_FILE = './templates/config-template.handlebars';
|
||||
/**
|
||||
* Writes the config file generated from a template to a stream.
|
||||
* @param watcherKind Watcher kind to be passed to the template.
|
||||
* @param port Port for the watcher server.
|
||||
* @param folderName Watcher folder name to be passed to the template.
|
||||
* @param outStream A writable output stream to write the config file to.
|
||||
*/
|
||||
export function exportConfig (watcherKind: string, folderName: string, outStream: Writable): void {
|
||||
export function exportConfig (watcherKind: string, port: number, folderName: string, outStream: Writable): void {
|
||||
const templateString = fs.readFileSync(path.resolve(__dirname, TEMPLATE_FILE)).toString();
|
||||
const template = Handlebars.compile(templateString);
|
||||
const config = template({
|
||||
watcherKind,
|
||||
port,
|
||||
folderName
|
||||
});
|
||||
outStream.write(config);
|
||||
|
||||
@@ -62,6 +62,12 @@ const main = async (): Promise<void> => {
|
||||
default: KIND_ACTIVE,
|
||||
choices: [KIND_ACTIVE, KIND_LAZY]
|
||||
})
|
||||
.option('port', {
|
||||
alias: 'p',
|
||||
describe: 'Server port.',
|
||||
type: 'number',
|
||||
default: 3008
|
||||
})
|
||||
.option('flatten', {
|
||||
alias: 'f',
|
||||
describe: 'Flatten the input contract file.',
|
||||
@@ -157,7 +163,7 @@ function generateWatcher (data: string, visitor: Visitor, argv: any) {
|
||||
outStream = outputDir
|
||||
? fs.createWriteStream(path.join(outputDir, 'environments/local.toml'))
|
||||
: process.stdout;
|
||||
exportConfig(argv.kind, path.basename(outputDir), outStream);
|
||||
exportConfig(argv.kind, argv.port, path.basename(outputDir), outStream);
|
||||
|
||||
outStream = outputDir
|
||||
? fs.createWriteStream(path.join(outputDir, 'src/artifacts/', `${inputFileName}.json`))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[server]
|
||||
host = "127.0.0.1"
|
||||
port = 3008
|
||||
port = {{port}}
|
||||
kind = "{{watcherKind}}"
|
||||
|
||||
# Checkpointing state.
|
||||
|
||||
Reference in New Issue
Block a user