Skip to content
This repository was archived by the owner on Dec 7, 2021. It is now read-only.

Commit 502c5d9

Browse files
committed
Merge pull request #171 from Polymer/workaround-inquirer
Workaround buggy window terminal prompts
2 parents d84185a + 82a840f commit 502c5d9

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/commands/init.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
import {Command} from './command';
12+
import {execSync} from 'child_process';
1213
import {ArgDescriptor} from 'command-line-args';
1314
import * as fs from 'fs';
1415
import * as logging from 'plylog';
@@ -118,18 +119,32 @@ export class InitCommand implements Command {
118119
short: name,
119120
};
120121
});
121-
inquirer.prompt([{
122-
type: 'list',
122+
// Some windows emulators (mingw) don't handle arrows correctly
123+
// https://github.com/SBoudrias/Inquirer.js/issues/266
124+
// Fall back to rawlist and use number input
125+
// Credit to https://gist.github.com/geddski/c42feb364f3c671d22b6390d82b8af8f
126+
let isWindows = /^win/.test(process.platform);
127+
let isMinGW = false;
128+
if (isWindows) {
129+
// uname might not exist if using cmd or powershell,
130+
// which would throw an exception
131+
try {
132+
let uname = execSync('uname -s').toString();
133+
isMinGW = /^mingw/i.test(uname);
134+
} catch (e) {}
135+
}
136+
let prompt = {
137+
type: isMinGW ? 'rawlist' : 'list',
123138
name: 'generatorName',
124139
message: 'Which starter template would you like to use?',
125140
choices: choices,
126-
}]).then((answers) => {
141+
};
142+
inquirer.prompt([prompt]).then((answers) => {
127143
let generatorName = answers.generatorName;
128144
runGenerator(generatorName, getDisplayName(generatorName));
129145
});
130146
}
131147
});
132-
133148
});
134149
}
135150
}

0 commit comments

Comments
 (0)