@lvfarias/fl-cli
Version:
Flutter CLI
50 lines (46 loc) • 992 B
JavaScript
const { spawn } = require('child_process');
const flutterCommands = [
'analyze',
'attach',
'bash',
'build',
'channel',
'clean',
'config',
'create',
'devices',
'doctor',
'drive',
'emulators',
'format',
'help',
'install',
'logs',
'make',
'precache',
'pub',
'run',
'screenshot',
'test',
'upgrade',
'version',
];
function isValidCommand(name) {
return flutterCommands.includes(name);
}
function execute(command) {
const args = typeof command === 'string' ? [command] : command;
return new Promise(resolve => {
const command = spawn(`flutter`, args);
command.stdout.on('data', data => {
process.stdout.write(''+data);
});
command.stderr.on('data', data => {
process.stdout.write(''+data);
});
command.on('close', code => {
resolve();
});
});
}
module.exports = { execute, isValidCommand };