@@ -8,23 +8,28 @@ import path from "path";
88import fs from "fs" ;
99import consola from "consola" ;
1010
11- import Constants from "./util/constants" ;
11+ import Constants , { type ConfigPathResolvable } from "./util/constants" ;
1212
13- export interface MessageConfiguration {
14- emoji : string ;
13+ export type MessageConfiguration = {
1514 message : string ;
15+ emoji ?: string ;
1616 insertAtIndex ?: number ;
1717 replaceAtIndex ?: number ;
1818}
1919
20+ export type DefaultMessageOptions = {
21+ emoji ?: string ;
22+ fileName ?: string ;
23+ } ;
24+
2025class Configurator {
2126 static getNearestConfigurationFilePath (
2227 currentDirectory : string ,
2328 level : number = 0
2429 ) : string {
2530 const currentDir = fs . readdirSync ( currentDirectory ) ;
2631 const query = currentDir . find ( ( item ) =>
27- Constants . ACCEPTED_CONFIG_FILENAMES . includes ( item )
32+ ( [ ... Constants . ACCEPTED_CONFIG_FILENAMES ] as string [ ] ) . includes ( item )
2833 ) ;
2934 if ( query ) return path . join ( currentDirectory , query ) ;
3035 else if ( level <= Constants . CONFIG_FILE_MAX_DEPTH ) {
@@ -41,12 +46,31 @@ class Configurator {
4146 }
4247 }
4348
49+ static getGitRootPath ( currentDirectory : string , level : number = 0 ) {
50+ // TODO: Recursive find for the nearest directory with a .git path
51+ // Perhaps make this cacheable? Update at every change?
52+ // Maybe ENV Vars?
53+ currentDirectory ; level ;
54+ }
55+
4456 static addMessageConfiguration (
45- filePath : string ,
57+ configFilePath : ConfigPathResolvable ,
4658 message : MessageConfiguration
4759 ) : boolean {
4860 if ( message . insertAtIndex && message . replaceAtIndex )
4961 throw new Error ( "You cannot insert and replace at the same time." ) ;
62+
63+ loadFile ( configFilePath )
64+
65+ return true ;
66+ }
67+
68+ static addDefaultMessageConfiguration ( message : string , options : DefaultMessageOptions ) : boolean {
69+ const newMessage = {
70+ message,
71+ ...options ,
72+ }
73+ newMessage
5074 return true ;
5175 }
5276}
0 commit comments