Skip to content

Commit 2dbb3e4

Browse files
committed
update to v0.0.10
1 parent 1e0a028 commit 2dbb3e4

File tree

7 files changed

+40
-75
lines changed

7 files changed

+40
-75
lines changed

.prettierrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"printWidth": 120,
3-
"tabWidth": 4
3+
"tabWidth": 4,
4+
"singleQuote": true
45
}

CHANGELOG.md

Lines changed: 0 additions & 52 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "commandkit",
3-
"version": "0.0.9",
3+
"version": "0.0.10",
44
"license": "MIT",
55
"main": "./dist/index.js",
66
"module": "./dist/index.mjs",

src/handlers/command-handler/CommandHandler.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { CommandHandlerData, CommandHandlerOptions } from "./typings";
2-
import { getFilePaths } from "../../utils/get-paths";
3-
import builtInValidations from "./validations";
4-
import registerCommands from "./functions/registerCommands";
5-
import handleCommands from "./functions/handleCommands";
6-
import "colors";
1+
import { CommandHandlerData, CommandHandlerOptions } from './typings';
2+
import { getFilePaths } from '../../utils/get-paths';
3+
import { toFileURL } from '../../utils/resolve-file-url';
4+
import builtInValidations from './validations';
5+
import registerCommands from './functions/registerCommands';
6+
import handleCommands from './functions/handleCommands';
7+
import 'colors';
78

89
export class CommandHandler {
910
_data: CommandHandlerData;
@@ -25,11 +26,14 @@ export class CommandHandler {
2526

2627
async #buildCommands() {
2728
const commandFilePaths = getFilePaths(this._data.commandsPath, true).filter(
28-
(path) => path.endsWith(".js") || path.endsWith(".ts")
29+
(path) => path.endsWith('.js') || path.endsWith('.ts')
2930
);
3031

3132
for (const commandFilePath of commandFilePaths) {
32-
let commandObj = await import(commandFilePath);
33+
const modulePath = toFileURL(commandFilePath);
34+
35+
let commandObj = await import(modulePath);
36+
3337
const compactFilePath = commandFilePath.split(process.cwd())[1] || commandFilePath;
3438

3539
if (commandObj.default) commandObj = commandObj.default;

src/handlers/event-handler/EventHandler.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { getFilePaths, getFolderPaths } from "../../utils/get-paths";
2-
import { EventHandlerOptions, EventHandlerData } from "./typings";
3-
import "colors";
1+
import { getFilePaths, getFolderPaths } from '../../utils/get-paths';
2+
import { toFileURL } from '../../utils/resolve-file-url';
3+
import { EventHandlerOptions, EventHandlerData } from './typings';
4+
import 'colors';
45

56
export class EventHandler {
67
#data: EventHandlerData;
@@ -21,10 +22,10 @@ export class EventHandler {
2122
const eventFolderPaths = getFolderPaths(this.#data.eventsPath);
2223

2324
for (const eventFolderPath of eventFolderPaths) {
24-
const eventName = eventFolderPath.replace(/\\/g, "/").split("/").pop() as string;
25+
const eventName = eventFolderPath.replace(/\\/g, '/').split('/').pop() as string;
2526

2627
const eventFilePaths = getFilePaths(eventFolderPath, true).filter(
27-
(path) => path.endsWith(".js") || path.endsWith(".ts")
28+
(path) => path.endsWith('.js') || path.endsWith('.ts')
2829
);
2930

3031
const eventObj = {
@@ -35,10 +36,12 @@ export class EventHandler {
3536
this.#data.events.push(eventObj);
3637

3738
for (const eventFilePath of eventFilePaths) {
38-
let eventFunction = (await import(eventFilePath)).default;
39+
const modulePath = toFileURL(eventFilePath);
40+
41+
let eventFunction = (await import(modulePath)).default;
3942
const compactFilePath = eventFilePath.split(process.cwd())[1] || eventFilePath;
4043

41-
if (typeof eventFunction !== "function") {
44+
if (typeof eventFunction !== 'function') {
4245
console.log(`⏩ Ignoring: Event ${compactFilePath} does not export a function.`.yellow);
4346
continue;
4447
}

src/handlers/validation-handler/ValidationHandler.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { ValidationHandlerData, ValidationHandlerOptions } from "./typings";
2-
import { getFilePaths } from "../../utils/get-paths";
3-
import "colors";
1+
import { ValidationHandlerData, ValidationHandlerOptions } from './typings';
2+
import { getFilePaths } from '../../utils/get-paths';
3+
import { toFileURL } from '../../utils/resolve-file-url';
4+
import 'colors';
45

56
export class ValidationHandler {
67
#data: ValidationHandlerData;
@@ -18,14 +19,16 @@ export class ValidationHandler {
1819

1920
async #buildValidations() {
2021
const validationFilePaths = getFilePaths(this.#data.validationsPath, true).filter(
21-
(path) => path.endsWith(".js") || path.endsWith(".ts")
22+
(path) => path.endsWith('.js') || path.endsWith('.ts')
2223
);
2324

2425
for (const validationFilePath of validationFilePaths) {
25-
let validationFunction = (await import(validationFilePath)).default;
26+
const modulePath = toFileURL(validationFilePath);
27+
28+
let validationFunction = (await import(modulePath)).default;
2629
const compactFilePath = validationFilePath.split(process.cwd())[1] || validationFilePath;
2730

28-
if (typeof validationFunction !== "function") {
31+
if (typeof validationFunction !== 'function') {
2932
console.log(`⏩ Ignoring: Validation ${compactFilePath} does not export a function.`.yellow);
3033
continue;
3134
}

src/utils/resolve-file-url.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import path from 'path';
2+
3+
export function toFileURL(filePath: string) {
4+
const resolvedPath = path.resolve(filePath);
5+
return 'file://' + resolvedPath.replace(/\\/g, '/');
6+
}

0 commit comments

Comments
 (0)