Optional server port arg. for watcher generation (#284)

This commit is contained in:
prathamesh0 2021-10-22 14:47:56 +05:30 committed by nabarun
parent c349b23f29
commit 27104f9d74
4 changed files with 13 additions and 4 deletions

View File

@ -21,7 +21,7 @@
* Run the following command to generate a watcher from a contract file:
```bash
yarn codegen --input-file <input-file-path> --contract-name <contract-name> --output-folder [output-folder] --mode [eth_call | storage | all] --flatten [true | false] --kind [lazy | active]
yarn codegen --input-file <input-file-path> --contract-name <contract-name> --output-folder [output-folder] --mode [eth_call | storage | all] --flatten [true | false] --kind [lazy | active] --port [server-port]
```
* `input-file`(alias: `i`): Input contract file path or an URL (required).
@ -30,6 +30,7 @@
* `mode`(alias: `m`): Code generation mode (default: `all`).
* `flatten`(alias: `f`): Flatten the input contract file (default: `true`).
* `kind` (alias: `k`): Kind of watcher (default: `active`).
* `port` (alias: `p`): Server port (default: `3008`).
**Note**: When passed an *URL* as `input-file`, it is assumed that it points to an already flattened contract file.

View File

@ -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);

View File

@ -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`))

View File

@ -1,6 +1,6 @@
[server]
host = "127.0.0.1"
port = 3008
port = {{port}}
kind = "{{watcherKind}}"
# Checkpointing state.