deprecate: mode (#325)

* test: add tests for context

* deprecate: mode

* revert docs for deprecated option
This commit is contained in:
Jacob Nguyen
2023-08-18 20:37:47 -05:00
committed by GitHub
parent e59e0b9d40
commit c9f2d75665
3 changed files with 35 additions and 54 deletions

View File

@@ -33,6 +33,7 @@ export async function importModule<T>(absPath: string) {
.wrap(() => module.getInstance())
.unwrapOr(module) as T;
}
export async function defaultModuleLoader<T extends Module>(absPath: string): ModuleResult<T> {
let module = await importModule<T>(absPath);
assert(module, `Found an undefined module: ${absPath}`);
@@ -53,7 +54,7 @@ export function buildModuleStream<T extends Module>(
return from(input).pipe(mergeMap(defaultModuleLoader<T>));
}
export const getFullPathTree = (dir: string, mode: boolean) => readPaths(resolve(dir), mode);
export const getFullPathTree = (dir: string) => readPaths(resolve(dir));
export const filename = (path: string) => fmtFileName(basename(path));
@@ -70,22 +71,18 @@ async function deriveFileInfo(dir: string, file: string) {
base: basename(file),
};
}
async function* readPaths(dir: string, shouldDebug: boolean): AsyncGenerator<string> {
async function* readPaths(dir: string): AsyncGenerator<string> {
try {
const files = await readdir(dir);
for (const file of files) {
const { fullPath, fileStats, base } = await deriveFileInfo(dir, file);
if (fileStats.isDirectory()) {
//Todo: refactor so that i dont repeat myself for files (line 71)
if (isSkippable(base)) {
if (shouldDebug) console.info(`ignored directory: ${fullPath}`);
} else {
yield* readPaths(fullPath, shouldDebug);
if (!isSkippable(base)) {
yield* readPaths(fullPath);
}
} else {
if (isSkippable(base)) {
if (shouldDebug) console.info(`ignored: ${fullPath}`);
} else {
if (!isSkippable(base)) {
yield 'file:///' + fullPath;
}
}
@@ -98,38 +95,30 @@ async function* readPaths(dir: string, shouldDebug: boolean): AsyncGenerator<str
const requir = createRequire(import.meta.url);
export function loadConfig(wrapper: Wrapper | 'file'): Wrapper {
if (wrapper === 'file') {
console.log('Experimental loading of sern.config.json');
const config = requir(resolve('sern.config.json')) as {
language: string;
defaultPrefix?: string;
mode?: 'PROD' | 'DEV';
paths: {
base: string;
commands: string;
events?: string;
};
};
const makePath = (dir: keyof typeof config.paths) =>
config.language === 'typescript'
? join('dist', config.paths[dir]!)
: join(config.paths[dir]!);
console.log('Loading config: ', config);
const commandsPath = makePath('commands');
console.log('Commands path is set to', commandsPath);
let eventsPath: string | undefined;
if (config.paths.events) {
eventsPath = makePath('events');
console.log('Events path is set to', eventsPath);
}
return {
defaultPrefix: config.defaultPrefix,
commands: commandsPath,
events: eventsPath,
mode: config.mode,
};
if (wrapper !== 'file') {
return wrapper;
}
return wrapper;
console.log('Experimental loading of sern.config.json');
const config = requir(resolve('sern.config.json'));
const makePath = (dir: PropertyKey) =>
config.language === 'typescript'
? join('dist', config.paths[dir]!)
: join(config.paths[dir]!);
console.log('Loading config: ', config);
const commandsPath = makePath('commands');
console.log('Commands path is set to', commandsPath);
let eventsPath: string | undefined;
if (config.paths.events) {
eventsPath = makePath('events');
console.log('Events path is set to', eventsPath);
}
return {
defaultPrefix: config.defaultPrefix,
commands: commandsPath,
events: eventsPath,
};
}