dthree / dthree/vorpal

Run script of my vorpal commands does not work on async functions

Open
#346 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
5.6k
Forks
278
PR merge metrics
No merged PRs in 30d

Description

I tried to write a script runner, but it does not wait for async functions:
```js
vorpal
.command('run ', 'Run a script file')
.validate(function (args) {
if (fs.existsSync(args.file_name)) {
return true;
} else {
return `File does not exists '${args.file_name}'`;
}
})
.action(function (args, callback) {
const scriptLines = fs.readFileSync(args.file_name).toString().split('\n');
for (const line of scriptLines) {
if (line.trim() !== '') {
vorpal.execSync(line);
}
}
callback();
});
```
Tried that too, but it exits instantly:
```js
vorpal
.command('run ', 'Run a script file')
.validate(function (args) {
if (fs.existsSync(args.file_name)) {
return true;
} else {
return `File does not exists '${args.file_name}'`;
}
})
.action(async function (args, callback) {
const scriptLines = fs.readFileSync(args.file_name).toString().split('\n');
for (const line of scriptLines) {
if (line.trim() !== '') {
await vorpal.exec(line);
}
}
callback();
});
```
**Any ideas?**

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.