-
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.
- Loading branch information
Florian Weber
committed
Apr 27, 2019
1 parent
bb2e83d
commit b363f2f
Showing
12 changed files
with
214 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# @averjs/cli | ||
|
||
> TODO: description | ||
## Usage | ||
|
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env node | ||
|
||
const requireModule = require('esm')(module); | ||
const Cli = requireModule('../lib').default; | ||
const cli = new Cli(); | ||
cli.run(); |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import Command from './command'; | ||
import Core from '@averjs/core'; | ||
|
||
export default class BuildCommand extends Command { | ||
constructor() { | ||
super(); | ||
|
||
this.name = 'build'; | ||
this.description = 'Build for production usage.'; | ||
} | ||
|
||
async run() { | ||
if (typeof process.env.NODE_ENV === 'undefined') process.env.NODE_ENV = 'production'; | ||
|
||
const core = new Core(); | ||
await core.build(); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* This class serves as an interface | ||
*/ | ||
export default class Command { | ||
constructor() { | ||
this.name = ''; | ||
this.description = ''; | ||
this.aliases = []; | ||
this.args = []; | ||
} | ||
|
||
run() {} | ||
|
||
generateCommandLineUsage() {} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import Command from './command'; | ||
import Core from '@averjs/core'; | ||
|
||
export default class DevCommand extends Command { | ||
constructor() { | ||
super(); | ||
|
||
this.name = 'dev'; | ||
this.description = 'Start averjs in development mode.'; | ||
} | ||
|
||
run() { | ||
if (typeof process.env.NODE_ENV === 'undefined') process.env.NODE_ENV = 'development'; | ||
|
||
const core = new Core(); | ||
core.run(); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import Command from './command'; | ||
import commandLineUsage from 'command-line-usage'; | ||
|
||
export default class HelpCommand extends Command { | ||
constructor(commands = []) { | ||
super(); | ||
|
||
this.name = 'help'; | ||
this.aliases = [ | ||
'h' | ||
]; | ||
this.description = 'Shows this help or for a specific command.'; | ||
this.commands = commands; | ||
} | ||
|
||
getLogo() { | ||
return ` | ||
.........\\\\~~~~~\\\\....../~~~~\\\\....../~~~~~/......... | ||
..........\\\\ \\\\..../ \\\\..../ /.......... | ||
...........\\\\ \\\\~~/ \\\\~~/ /........... | ||
............\\\\ \\\\/ \\\\/ /............ | ||
.............\\\\ / /\\\\ \\\\ /............. | ||
..............\\\\ / / \\\\ \\\\ /.............. {bold.underline averjs-CLI} | ||
...............\\\\/ / \\\\ \\\\/............... | ||
.............../ / \\\\ \\\\............... The cli tool for averjs | ||
............../ / \\\\ / \\\\ \\\\.............. | ||
............./ / \\\\~~/ \\\\ \\\\............. Usage: \`aver <command> [options ...]\` | ||
............/ /\\\\ /.\\\\ \\\\............ | ||
.........../ /..\\\\ /...\\\\ \\\\........... | ||
........../ /....\\\\ /.....\\\\ \\\\.......... | ||
........./ /......\\\\ /.......\\\\ \\\\......... | ||
......../~~~~~/........\\\\ /.........\\\\~~~~~\\\\........ | ||
`.trim(); | ||
} | ||
|
||
generateCommandLineUsage() { | ||
return commandLineUsage([ | ||
{ | ||
content: this.getLogo(), | ||
raw: true | ||
}, | ||
{ | ||
header: 'Available Commands', | ||
content: this.commands.map(command => ({ | ||
name: command.name, | ||
summary: command.description | ||
})) | ||
} | ||
]); | ||
} | ||
|
||
run() { | ||
console.log(this.generateCommandLineUsage()); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import Command from './command'; | ||
import Core from '@averjs/core'; | ||
|
||
export default class InitCommand extends Command { | ||
constructor() { | ||
super(); | ||
|
||
this.name = 'init'; | ||
this.description = 'Initialize the project by creating all necessary files in the working directory.'; | ||
} | ||
|
||
run() { | ||
const core = new Core(); | ||
core.init(); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import HelpCommand from './commands/help'; | ||
import DevCommand from './commands/dev'; | ||
import InitCommand from './commands/init'; | ||
import BuildCommand from './commands/build'; | ||
import parseArgs from 'minimist'; | ||
|
||
export default class Usage { | ||
constructor() { | ||
this.aliases = {}; | ||
this.availableCommands = []; | ||
|
||
this.addCommand(new HelpCommand(this.availableCommands)); | ||
this.addCommand(new DevCommand()); | ||
this.addCommand(new InitCommand()); | ||
this.addCommand(new BuildCommand()); | ||
|
||
this.argv = parseArgs(process.argv.slice(2), { | ||
alias: this.aliases | ||
}); | ||
} | ||
|
||
addCommand(command) { | ||
this.availableCommands.push(command); | ||
|
||
for (const alias of command.aliases) { | ||
this.aliases[alias] = command.name; | ||
} | ||
} | ||
|
||
async run() { | ||
for (const command of this.availableCommands) { | ||
if (this.argv._.indexOf(command.name) !== -1) { | ||
try { | ||
await command.run(); | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "@averjs/cli", | ||
"version": "1.5.2", | ||
"description": "cli package vor averjs", | ||
"author": "Florian Weber", | ||
"homepage": "https://github.com/exreplay/aver.js#readme", | ||
"license": "MIT", | ||
"main": "lib/index.js", | ||
"bin": { | ||
"aver": "./bin/aver.js" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/exreplay/aver.js.git", | ||
"directory": "packages/cli" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/exreplay/aver.js/issues" | ||
}, | ||
"dependencies": { | ||
"command-line-usage": "5.0.5" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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