mirror of
https://github.com/sern-handler/handler
synced 2026-06-11 02:12:15 +00:00
* step 1 * Refactorings * command modules do not depend on anything but itself * tearing it up * Remove module store, manager, and Intializable type * consolidate interfaces in single file * consolidate default services in single file * TEAR IT UP * fix text compile * the end of sern init?? * Presence namespaced types removed * internal namespace * clean up dependencies * fix test * fix circular dependency * still broken but progress * remove barrel for core/structs * reffactor * refactor allat * more refactoring * prototyping linking static handler * cleanup tests, codegen, and importing handler * some refactor * generify partition * for now copy paste new ioc system * removeiti * fdsfD * ensure container is init'd * fix absPath gen * working on bun compat * refactor and clean up and reenter v3 module loading * dsfsd * refactor, add cron types, reinstante module loader * ready handler revamped so much cleaner * fdssdf * refactor deps list * add more tests, polish up ioc * up to speed with event modules * i think cron works * cron works now, poc * ksdjkldsfld * updating ioc api, experimenting with cron * save b4 thunder and lightning * plugin data reduction & args changes * freeze module after plugins, updateModule, and more * simplify plugin args and prepare for reduction among plugins * add deps to plugin calls and execute * plugin system loking better, tbd type * porg * initplugins inject deps, inconspicuos * fix faiklling test * fix initPlugins not reassigning * parsingParams kinda * proper mapping * dynamic customIds * handling customId params working * testing n shi * inlineinignsd * consolidate fmt * once on eventModules * refact,simplf * readd vitest and Asset fn * fix typings * assets fn complete * more intuitive context.options and Asset typings * add init hooks not firing * -file,-updateModule,publish? * fix: ioc deps not created correctly * documentation, add json for Asset * remove asset * ss * finish ioc transition * nvm, now i did * s * update locals api, docs, tests * fix tests * fix up tests and cleanup * fix * Update src/core/functions.ts Co-authored-by: Evo <85353424+EvolutionX-10@users.noreply.github.com> * better documentation * temp fix * namespace presence types again * revising cron modules and better error messages * scheduler ids * more descriptive errors * refactor to not type leak and job cancellation * refactor n better signatures for task scheduler * documentation * fix swap not accepting functions * change task signature --------- Co-authored-by: Evo <85353424+EvolutionX-10@users.noreply.github.com>
71 lines
2.2 KiB
TypeScript
71 lines
2.2 KiB
TypeScript
import path from 'node:path';
|
|
import { existsSync } from 'node:fs';
|
|
import { readdir } from 'fs/promises';
|
|
import assert from 'node:assert';
|
|
import * as Id from './id'
|
|
import { Module } from '../types/core-modules';
|
|
|
|
export const parseCallsite = (site: string) => {
|
|
const pathobj = path.posix.parse(site.replace(/file:\\?/, "")
|
|
.split(path.sep)
|
|
.join(path.posix.sep))
|
|
return { name: pathobj.name,
|
|
absPath : path.posix.format(pathobj) }
|
|
}
|
|
|
|
export const shouldHandle = (pth: string, filenam: string) => {
|
|
const file_name = filenam+path.extname(pth);
|
|
let newPath = path.join(path.dirname(pth), file_name)
|
|
.replace(/file:\\?/, "");
|
|
return { exists: existsSync(newPath),
|
|
path: 'file://'+newPath };
|
|
}
|
|
|
|
|
|
/**
|
|
* Import any module based on the absolute path.
|
|
* This can accept four types of exported modules
|
|
* commonjs, javascript :
|
|
* ```js
|
|
* exports = commandModule({ })
|
|
* //or
|
|
* exports.default = commandModule({ })
|
|
* ```
|
|
* esm javascript, typescript, and commonjs typescript
|
|
* export default commandModule({})
|
|
*/
|
|
export async function importModule<T>(absPath: string) {
|
|
let fileModule = await import(absPath);
|
|
|
|
let commandModule: Module = fileModule.default;
|
|
|
|
assert(commandModule , `No default export @ ${absPath}`);
|
|
if ('default' in commandModule) {
|
|
commandModule = commandModule.default as Module;
|
|
}
|
|
const p = path.parse(absPath)
|
|
commandModule.name ??= p.name; commandModule.description ??= "...";
|
|
commandModule.meta = {
|
|
id: Id.create(commandModule.name, commandModule.type),
|
|
absPath,
|
|
};
|
|
return { module: commandModule as T };
|
|
}
|
|
|
|
|
|
export async function* readRecursive(dir: string): AsyncGenerator<string> {
|
|
const files = await readdir(dir, { withFileTypes: true });
|
|
for (const file of files) {
|
|
const fullPath = path.posix.join(dir, file.name);
|
|
if (file.isDirectory()) {
|
|
if (!file.name.startsWith('!')) {
|
|
yield* readRecursive(fullPath);
|
|
}
|
|
} else if (!file.name.startsWith('!')) {
|
|
yield "file:///"+path.resolve(fullPath);
|
|
}
|
|
}
|
|
}
|
|
|
|
|