@noravel/command 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Command.d.ts +2 -1
- package/dist/Command.js +16 -1
- package/dist/Contracts/Command.d.ts +1 -1
- package/dist/Executor.d.ts +1 -1
- package/dist/Executor.js +2 -1
- package/dist/Kernel.d.ts +1 -1
- package/dist/Kernel.js +13 -12
- package/dist/MakerCommand.d.ts +1 -2
- package/dist/MakerCommand.js +1 -12
- package/dist/Outputs/ProgressBar/ProgressBar.d.ts +17 -0
- package/dist/Outputs/ProgressBar/StatusBarFactory.d.ts +2 -2
- package/dist/Outputs/ProgressBar/StatusBarVerbose.js +1 -1
- package/package.json +1 -1
package/dist/Command.d.ts
CHANGED
|
@@ -17,11 +17,12 @@ export default abstract class Command implements CommandContract {
|
|
|
17
17
|
constructor(argv: string[]);
|
|
18
18
|
bootstrap(): this;
|
|
19
19
|
detect(): this;
|
|
20
|
+
basePath(dirPath?: string): string;
|
|
20
21
|
getName(): string;
|
|
21
22
|
getDescription(): string;
|
|
22
23
|
getArgument(name?: string): unknown;
|
|
23
24
|
getOption(name?: string): unknown;
|
|
24
25
|
showHelp(): void;
|
|
25
26
|
exec(command: string): Promise<unknown>;
|
|
26
|
-
abstract handle():
|
|
27
|
+
abstract handle(): Promise<number>;
|
|
27
28
|
}
|
package/dist/Command.js
CHANGED
|
@@ -3,6 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
6
8
|
const node_child_process_1 = require("node:child_process");
|
|
7
9
|
const Parser_1 = __importDefault(require("./Parser"));
|
|
8
10
|
const Detector_1 = __importDefault(require("./Detector"));
|
|
@@ -29,7 +31,9 @@ class Command {
|
|
|
29
31
|
this.prompt = new Prompt_1.default();
|
|
30
32
|
}
|
|
31
33
|
bootstrap() {
|
|
32
|
-
this.signature =
|
|
34
|
+
this.signature =
|
|
35
|
+
this.signature +
|
|
36
|
+
' {--h|help : Display help for the given command} {--v|version : Display the version of Noravel Command}';
|
|
33
37
|
const [name, argumentDefinition, optionDefinition] = Parser_1.default.parse(this.signature);
|
|
34
38
|
this.name = name;
|
|
35
39
|
this.definition.setArguments(argumentDefinition);
|
|
@@ -42,6 +46,17 @@ class Command {
|
|
|
42
46
|
this.inputs.options = _options;
|
|
43
47
|
return this;
|
|
44
48
|
}
|
|
49
|
+
basePath(dirPath) {
|
|
50
|
+
const basePath = process.cwd();
|
|
51
|
+
if (!dirPath) {
|
|
52
|
+
return basePath;
|
|
53
|
+
}
|
|
54
|
+
dirPath = node_path_1.default.join(basePath, dirPath);
|
|
55
|
+
if (!node_fs_1.default.existsSync(dirPath)) {
|
|
56
|
+
node_fs_1.default.mkdirSync(dirPath, { recursive: true });
|
|
57
|
+
}
|
|
58
|
+
return dirPath;
|
|
59
|
+
}
|
|
45
60
|
getName() {
|
|
46
61
|
return this.name;
|
|
47
62
|
}
|
package/dist/Executor.d.ts
CHANGED
package/dist/Executor.js
CHANGED
|
@@ -3,7 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
class Executor {
|
|
4
4
|
static async call(command, argv) {
|
|
5
5
|
const commandInstance = new command(argv).bootstrap();
|
|
6
|
-
|
|
6
|
+
const exitCode = await commandInstance.handle();
|
|
7
|
+
return exitCode ? 1 : 0;
|
|
7
8
|
}
|
|
8
9
|
}
|
|
9
10
|
exports.default = Executor;
|
package/dist/Kernel.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export default class Kernel {
|
|
|
8
8
|
private output;
|
|
9
9
|
constructor(argv?: string[]);
|
|
10
10
|
register(commands: (new (argv: string[]) => CommandContract)[]): this;
|
|
11
|
-
run():
|
|
11
|
+
run(): Promise<0 | 1>;
|
|
12
12
|
setCallbackVersion(callback: () => void): this;
|
|
13
13
|
showVersion(): void;
|
|
14
14
|
getVersion(): any;
|
package/dist/Kernel.js
CHANGED
|
@@ -26,21 +26,21 @@ class Kernel {
|
|
|
26
26
|
this.registeredCommands = [...this.registeredCommands, ...commands];
|
|
27
27
|
return this;
|
|
28
28
|
}
|
|
29
|
-
run() {
|
|
29
|
+
async run() {
|
|
30
30
|
if (!this.name) {
|
|
31
31
|
const helper = new Helper_1.default();
|
|
32
|
-
helper.showHelpForMain(this.registeredCommands.map(
|
|
33
|
-
return;
|
|
32
|
+
helper.showHelpForMain(this.registeredCommands.map(command => new command(this.argv).bootstrap()));
|
|
33
|
+
return 0;
|
|
34
34
|
}
|
|
35
35
|
let signatures = [];
|
|
36
36
|
if (['--help', '-h'].includes(this.name)) {
|
|
37
37
|
const helper = new Helper_1.default();
|
|
38
|
-
helper.showHelpForMain(this.registeredCommands.map(
|
|
39
|
-
return;
|
|
38
|
+
helper.showHelpForMain(this.registeredCommands.map(command => new command(this.argv).bootstrap()));
|
|
39
|
+
return 0;
|
|
40
40
|
}
|
|
41
41
|
if (['--version', '-v'].includes(this.name)) {
|
|
42
42
|
this.showVersion();
|
|
43
|
-
return;
|
|
43
|
+
return 0;
|
|
44
44
|
}
|
|
45
45
|
for (const command of this.registeredCommands) {
|
|
46
46
|
const commandInstance = new command(this.argv).bootstrap();
|
|
@@ -50,23 +50,24 @@ class Kernel {
|
|
|
50
50
|
commandInstance.detect();
|
|
51
51
|
if (commandInstance.getOption('help')) {
|
|
52
52
|
commandInstance.showHelp();
|
|
53
|
-
return;
|
|
53
|
+
return 0;
|
|
54
54
|
}
|
|
55
55
|
if (commandInstance.getOption('version')) {
|
|
56
56
|
this.showVersion();
|
|
57
|
-
return;
|
|
57
|
+
return 0;
|
|
58
58
|
}
|
|
59
|
-
commandInstance.handle();
|
|
60
|
-
return;
|
|
59
|
+
const result = await commandInstance.handle();
|
|
60
|
+
return result ? 1 : 0;
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
const suggestions = (0, didyoumean2_1.default)(this.name, signatures);
|
|
64
64
|
if (suggestions) {
|
|
65
65
|
this.output.error(`Command "${this.name}" is not defined. Did you mean "${suggestions}"?`);
|
|
66
|
-
return;
|
|
66
|
+
return 1;
|
|
67
67
|
}
|
|
68
68
|
this.output.error(`Command "${this.name}" is not defined. Did you mean one of these?`);
|
|
69
|
-
signatures.forEach(
|
|
69
|
+
signatures.forEach(signature => this.output.comment(` ${signature}`));
|
|
70
|
+
return 1;
|
|
70
71
|
}
|
|
71
72
|
setCallbackVersion(callback) {
|
|
72
73
|
this.callbackVersion = callback.bind(this);
|
package/dist/MakerCommand.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import Command from './Command';
|
|
2
2
|
export default class MakerCommand extends Command {
|
|
3
|
-
basePath(dirPath?: string): string;
|
|
4
3
|
fileName(question?: string): Promise<string>;
|
|
5
4
|
makeFile(fileName: string, dirPath: string): void;
|
|
6
5
|
/**
|
|
@@ -23,5 +22,5 @@ export default class MakerCommand extends Command {
|
|
|
23
22
|
* @returns {string}
|
|
24
23
|
*/
|
|
25
24
|
protected contentFile(fileName: string): string;
|
|
26
|
-
handle(): Promise<
|
|
25
|
+
handle(): Promise<number>;
|
|
27
26
|
}
|
package/dist/MakerCommand.js
CHANGED
|
@@ -7,17 +7,6 @@ const node_path_1 = __importDefault(require("node:path"));
|
|
|
7
7
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
8
|
const Command_1 = __importDefault(require("./Command"));
|
|
9
9
|
class MakerCommand extends Command_1.default {
|
|
10
|
-
basePath(dirPath) {
|
|
11
|
-
const basePath = process.cwd();
|
|
12
|
-
if (!dirPath) {
|
|
13
|
-
return basePath;
|
|
14
|
-
}
|
|
15
|
-
dirPath = node_path_1.default.join(basePath, dirPath);
|
|
16
|
-
if (!node_fs_1.default.existsSync(dirPath)) {
|
|
17
|
-
node_fs_1.default.mkdirSync(dirPath, { recursive: true });
|
|
18
|
-
}
|
|
19
|
-
return dirPath;
|
|
20
|
-
}
|
|
21
10
|
async fileName(question = 'What should the file be named?') {
|
|
22
11
|
let name = this.getArgument('name');
|
|
23
12
|
if (!name) {
|
|
@@ -62,7 +51,7 @@ class MakerCommand extends Command_1.default {
|
|
|
62
51
|
return '';
|
|
63
52
|
}
|
|
64
53
|
async handle() {
|
|
65
|
-
|
|
54
|
+
return 0;
|
|
66
55
|
}
|
|
67
56
|
}
|
|
68
57
|
exports.default = MakerCommand;
|
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
declare const ARROW_PROGRESS_STYLE: {
|
|
2
|
+
complete: string;
|
|
3
|
+
incomplete: string;
|
|
4
|
+
head: string;
|
|
5
|
+
};
|
|
6
|
+
declare const SHAPE_PROGRESS_STYLE: {
|
|
7
|
+
complete: string;
|
|
8
|
+
incomplete: string;
|
|
9
|
+
head: string;
|
|
10
|
+
};
|
|
11
|
+
declare const BLOCK_PROGRESS_STYLE: {
|
|
12
|
+
complete: string;
|
|
13
|
+
incomplete: string;
|
|
14
|
+
head: string;
|
|
15
|
+
};
|
|
16
|
+
export type ProgressStyle = typeof ARROW_PROGRESS_STYLE | typeof SHAPE_PROGRESS_STYLE | typeof BLOCK_PROGRESS_STYLE;
|
|
1
17
|
export type ProgressBarFormat = 'normal' | 'verbose' | 'minimal';
|
|
2
18
|
export default class ProgressBar {
|
|
3
19
|
private total;
|
|
@@ -20,3 +36,4 @@ export default class ProgressBar {
|
|
|
20
36
|
useArrowProgress(): void;
|
|
21
37
|
useBlockProgress(): void;
|
|
22
38
|
}
|
|
39
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import ProgressBar, { ProgressBarFormat } from
|
|
2
|
-
import { StatusBar } from
|
|
1
|
+
import ProgressBar, { ProgressBarFormat } from './ProgressBar';
|
|
2
|
+
import { StatusBar } from './StatusBar';
|
|
3
3
|
export declare class StatusBarFactory {
|
|
4
4
|
static create(type: ProgressBarFormat, progressbar: ProgressBar): StatusBar;
|
|
5
5
|
}
|
|
@@ -6,7 +6,7 @@ class StatusBarVerbose extends StatusBar_1.StatusBar {
|
|
|
6
6
|
super(progressbar);
|
|
7
7
|
}
|
|
8
8
|
getInfo(perc) {
|
|
9
|
-
const elapsed =
|
|
9
|
+
const elapsed = new Date().getTime() / 1000 - this.progressbar.startTime;
|
|
10
10
|
const rate = this.progressbar.current > 0 ? elapsed / this.progressbar.current : 0;
|
|
11
11
|
const left = this.progressbar.getTotal() - this.progressbar.current;
|
|
12
12
|
const eta = (rate * left).toFixed(1);
|