Comparing version 1.0.7 to 1.0.8
@@ -5,2 +5,3 @@ import { Command } from './command'; | ||
export declare const addCommand: (command: Command) => void; | ||
export declare const run: () => void; | ||
export type bootTemp = (addCmd: typeof addCommand) => void; | ||
export declare const boot: (bootTemp: bootTemp) => void; |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.run = exports.addCommand = exports.getCommands = exports.Command = void 0; | ||
exports.boot = exports.addCommand = exports.getCommands = exports.Command = void 0; | ||
const chalk_1 = __importDefault(require("chalk")); | ||
@@ -12,3 +12,4 @@ const env_1 = require("./commands/env"); | ||
Object.defineProperty(exports, "Command", { enumerable: true, get: function () { return command_1.Command; } }); | ||
const args = process.argv; | ||
const yargs_1 = __importDefault(require("yargs")); | ||
const helpers_1 = require("yargs/helpers"); | ||
let commands = [ | ||
@@ -25,39 +26,31 @@ new env_1.BuildEnvCommand(), | ||
exports.addCommand = addCommand; | ||
// usage represents the help guide | ||
const usage = function () { | ||
const usageText = ` | ||
@@core helps you manage frontend project | ||
usage: | ||
yarn cli <command> | ||
commands can be: | ||
`; | ||
console.log(usageText); | ||
const start = () => { | ||
let instance = (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv)) | ||
.scriptName('') | ||
.usage('@cuww/cli is designed to provide a cool way to manage your applications'); | ||
(0, exports.getCommands)().map(command => { | ||
console.log(` ${chalk_1.default.green(command.cli)} – ${command.description}`); | ||
instance.command(chalk_1.default.green(command.cli), command.description); | ||
instance.command(command.cli, false, () => { }, command.handle); | ||
}); | ||
instance | ||
.demandCommand(1) | ||
.parse(); | ||
// if (args[2] == 'help') { | ||
// return usage() | ||
// } | ||
// let findCommands = getCommands().filter(command => { | ||
// return command.cli == args[2] | ||
// }); | ||
// if (findCommands.length == 0) { | ||
// errorLog('invalid command passed') | ||
// return usage() | ||
// } | ||
// return findCommands[0].handle(args.slice(3)) | ||
}; | ||
// used to log errors to the console in red color | ||
function errorLog(error) { | ||
console.log(chalk_1.default.red(error)); | ||
} | ||
const start = () => { | ||
if (args[2] == 'help') { | ||
return usage(); | ||
} | ||
let findCommands = (0, exports.getCommands)().filter(command => { | ||
return command.cli == args[2]; | ||
}); | ||
if (findCommands.length == 0) { | ||
errorLog('invalid command passed'); | ||
return usage(); | ||
} | ||
return findCommands[0].handle(args.slice(3)); | ||
}; | ||
const run = () => { | ||
const boot = (bootTemp) => { | ||
console.log(''); | ||
bootTemp(exports.addCommand); | ||
start(); | ||
console.log(''); | ||
}; | ||
exports.run = run; | ||
exports.boot = boot; |
{ | ||
"name": "@cuww/cli", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"main": "dist/index.js", | ||
@@ -25,5 +25,7 @@ "types": "dist/index.d.ts", | ||
"@cuww/runtime-env": "^1.0.4", | ||
"@types/yargs": "^17.0.24", | ||
"chalk": "4.1.2", | ||
"typescript": "^5.1.5" | ||
"typescript": "^5.1.5", | ||
"yargs": "^17.7.2" | ||
} | ||
} |
@@ -34,8 +34,9 @@ # Cuww Configuration | ||
```typescript | ||
import { run, addCommand } from '@cuww/cli'; | ||
import { boot } from '@cuww/cli'; | ||
import { HelloCommand } from './commands/hello.mjs'; | ||
addCommand(new HelloCommand()) | ||
run() | ||
boot((command) => { | ||
command(new HelloCommand()) | ||
}) | ||
``` | ||
@@ -42,0 +43,0 @@ |
5583
78
5
101
+ Added@types/yargs@^17.0.24
+ Addedyargs@^17.7.2
+ Added@types/yargs@17.0.33(transitive)
+ Added@types/yargs-parser@21.0.3(transitive)
+ Addedansi-regex@5.0.1(transitive)
+ Addedcliui@8.0.1(transitive)
+ Addedemoji-regex@8.0.0(transitive)
+ Addedescalade@3.2.0(transitive)
+ Addedget-caller-file@2.0.5(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedrequire-directory@2.1.1(transitive)
+ Addedstring-width@4.2.3(transitive)
+ Addedstrip-ansi@6.0.1(transitive)
+ Addedwrap-ansi@7.0.0(transitive)
+ Addedy18n@5.0.8(transitive)
+ Addedyargs@17.7.2(transitive)
+ Addedyargs-parser@21.1.1(transitive)