-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from izelnakri/fastboot-enchancements
fastboot enchancements
- Loading branch information
Showing
4 changed files
with
37 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,55 @@ | ||
#! /usr/bin/env node | ||
|
||
import chalk from 'ansi-colors'; | ||
import Console from './lib/utils/console.js'; | ||
import printCommand from './lib/commands/index.js'; | ||
import compileCommand from './lib/commands/compile.js'; | ||
import serveCommand from './lib/commands/serve.js'; | ||
import testCommand from './lib/commands/test.js'; | ||
import buildCommand from './lib/commands/build.js'; | ||
import consoleCommand from './lib/commands/console.js'; | ||
import newCommand from './lib/commands/new.js'; | ||
import generateCommand from './lib/commands/generate.js'; | ||
import deleteCommand from './lib/commands/delete.js'; | ||
|
||
process.title = 'mber'; | ||
global.mainContext = global; // NOTE: needed for ember-template-compiler | ||
|
||
let shouldRunCommand = false; | ||
|
||
const CLI = { | ||
default(commandHandler) { | ||
async default(commandHandler) { | ||
if (!process.argv[2]) { | ||
shouldRunCommand = true; | ||
|
||
return commandHandler(); | ||
return await commandHandler(); | ||
} | ||
}, | ||
command(commandName, commandHandler) { | ||
async command(commandName, commandHandler) { | ||
const commandMatchesArray = Array.isArray(commandName) && commandName.includes(process.argv[2]); | ||
|
||
if (commandMatchesArray || commandName === process.argv[2]) { | ||
shouldRunCommand = true; | ||
|
||
return commandHandler(); | ||
return await commandHandler(); | ||
} | ||
} | ||
}; | ||
|
||
CLI.default(() => printCommand()); | ||
CLI.command(['serve', 'server', 's'], () => serveCommand()); // TODO: add proxy | ||
CLI.command(['test', 't'], () => testCommand()); // TODO: add --proxy | ||
CLI.command(['build', 'b'], () => buildCommand()); // TODO: add --proxy | ||
CLI.command(['compile', 'transpile', 'c'], () => compileCommand()); | ||
CLI.command(['console'], () => consoleCommand()); | ||
CLI.command(['help', 'h', 'print', 'p'], () => printCommand()); | ||
CLI.command(['init', 'new'], () => newCommand()); | ||
CLI.command(['generate', 'g', 'create'], () => generateCommand(process.argv[3], process.argv[4])); | ||
CLI.command(['delete', 'd', 'destroy', 'remove'], () => | ||
deleteCommand(process.argv[3], process.argv[4]) | ||
); | ||
|
||
if (!shouldRunCommand) { | ||
Console.log(chalk.red('unknown command. Available options are:')); | ||
printCommand(); | ||
setTimeout(() => process.exit(1), 100); | ||
} | ||
(async () => { | ||
CLI.default(async () => await runCommand('./lib/commands/index.js')); | ||
CLI.command(['serve', 'server', 's'], async () => await runCommand('./lib/commands/serve.js')); // TODO: add proxy | ||
CLI.command(['test', 't'], async () => await runCommand('./lib/commands/test.js')); // TODO: add --proxy | ||
CLI.command(['build', 'b'], async () => await runCommand('./lib/commands/build.js')); // TODO: add --proxy | ||
CLI.command(['compile', 'transpile', 'c'], async () => await runCommand('./lib/commands/compile.js')); | ||
CLI.command(['console'], async () => await runCommand('./lib/commands/console.js')); | ||
CLI.command(['help', 'h', 'print', 'p'], async () => await runCommand('./lib/commands/index.js')); | ||
CLI.command(['init', 'new'], async () => await runCommand('./lib/commands/new.js')); | ||
CLI.command(['generate', 'g', 'create'], async () => { | ||
return (await import('./lib/commands/generate.js')).default(process.argv[3], process.argv[4]) | ||
}); | ||
CLI.command(['delete', 'd', 'destroy', 'remove'], async () => { | ||
(await import('./lib/commands/delete.js')).default(process.argv[3], process.argv[4]); | ||
}); | ||
|
||
if (!shouldRunCommand) { | ||
Console.log(chalk.red('unknown command. Available options are:')); | ||
await runCommand('./lib/commands/index.js'); | ||
setTimeout(() => process.exit(1), 100); | ||
} | ||
})(); | ||
|
||
async function runCommand(commandPath) { | ||
return (await import(commandPath)).default(); | ||
} | ||
// NOTE: maybe merge server and console commands in future? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters