-
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
Nenes
committed
Jan 6, 2023
1 parent
8e48f49
commit 9bf01fa
Showing
8 changed files
with
155 additions
and
0 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,16 @@ | ||
class BaseCommand { | ||
constructor(value) { | ||
this.name = value.name; | ||
this.description = value.description; | ||
} | ||
|
||
getName() { | ||
return this.name; | ||
} | ||
|
||
getDescription() { | ||
return this.description; | ||
} | ||
} | ||
|
||
module.exports = BaseCommand; |
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,65 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
class Kurami { | ||
constructor() { | ||
this.path = path.resolve() + '/Command' | ||
} | ||
|
||
getCommandsInfo() { | ||
const commands = fs.readdirSync(this.path) | ||
|
||
let cleanCommandsList = this.cleanCommandsList(commands) | ||
|
||
return cleanCommandsList.map(commandFile => { | ||
console.log(path.join(this.path, commandFile)) | ||
const command = require(path.join(this.path, commandFile)) | ||
return { | ||
name: new command().getName(), | ||
description: new command().getDescription(), | ||
fileName: commandFile | ||
} | ||
}) | ||
} | ||
|
||
cleanCommandsList(commands) { | ||
let cleanCommandsList = [] | ||
|
||
commands.map(file => { | ||
if (file !== 'BaseCommand.js') { | ||
cleanCommandsList.push(file) | ||
} | ||
}) | ||
|
||
return cleanCommandsList | ||
} | ||
|
||
run(args) { | ||
const commands = this.getCommandsInfo() | ||
|
||
if (args[0] === "help" || args.length === 0) { | ||
this.runHelp() | ||
} | ||
|
||
if (args.length > 0 && args[0] !== "help") { | ||
const command = commands.find(command => command.name === args[0]) | ||
|
||
if (command) { | ||
const commandFile = require(path.join(this.path, command.fileName)) | ||
new commandFile().run() | ||
} else { | ||
console.log('Command not found') | ||
} | ||
} | ||
} | ||
|
||
runHelp() { | ||
console.log('Kurami CLI') | ||
console.log('Available commands:') | ||
this.getCommandsInfo().map(command => { | ||
console.log(`- ${command.name} - ${command.description}`) | ||
}) | ||
} | ||
} | ||
|
||
module.exports = new Kurami(); |
Empty file.
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 @@ | ||
const { BaseCommand } = require('kurami'); | ||
|
||
class TestCommand extends BaseCommand { | ||
constructor() { | ||
super({ | ||
name: 'test:test', | ||
description: 'Test command' | ||
}); | ||
} | ||
|
||
async run() { | ||
console.log('Test command'); | ||
} | ||
} | ||
|
||
module.exports = TestCommand; |
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,3 @@ | ||
{ | ||
"commandsPath": "./Command" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "test", | ||
"version": "1.0.0", | ||
"description": "test project for show how work the command system", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"kurami": "kurami" | ||
}, | ||
"author": "Nenes", | ||
"license": "UNLICENSED", | ||
"dependencies": { | ||
"kurami": "file:./.." | ||
} | ||
} |