Skip to content

Commit e120774

Browse files
committed
fix(): carry over positionals parsing from jake
1 parent 72d6218 commit e120774

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

bin/cli.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,22 +94,26 @@ function run() {
9494
process.exit(0);
9595
}
9696

97-
const templatePath = argv._[0];
98-
// Ensure there's a template to render, throw if not
99-
if (!templatePath) {
100-
throw new Error('Please provide a template path. (Run ejs -h for help)');
101-
}
102-
10397
// Parse out any environment variables passed after the template path
104-
// Based on jake parseArgs envVars implementation
98+
// Based on jake parseArgs envVars implementation to ensure non-breaking changes in jake migration
10599
// @see https://github.com/jakejs/jake/blob/main/lib/parseargs.js#L111
106100
let envVars = {};
107-
argv._.slice(1).map(v => v.split('=')).forEach(pair => {
101+
let templatePaths = [];
102+
argv._.map(v => v.split('=')).forEach(pair => {
108103
if (pair.length > 1) {
109104
envVars[pair[0]] = pair[1];
105+
} else {
106+
templatePaths.push(pair[0]);
110107
}
111108
});
112109

110+
// Template path is always is first positional argument without "="
111+
// Template path is required and we will throw an error if it is not provided
112+
let templatePath = templatePaths[0];
113+
if (!templatePath) {
114+
throw new Error('Please provide a template path. (Run ejs -h for help)');
115+
}
116+
113117
// Grab and parse any input data, in order of precedence:
114118
// 1. Stdin
115119
// 2. CLI arg via -i

0 commit comments

Comments
 (0)