Skip to content

Commit

Permalink
fix(scanner): add app options for config func (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
noahziheng authored Aug 12, 2022
1 parent 5a8d278 commit c1dfe1e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/scanner/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ import { BasePlugin, PluginFactory } from '../plugin';
import { ScanUtils } from './utils';
import { PluginConfigItem, PluginMetadata } from '../plugin/types';
import { getConfigMetaFromFilename } from '../loader/utils/config_file_meta';
import { Application } from '../types';
import { ArtusApplication } from '../application';

export class Scanner {
private moduleExtensions = ['.js', '.json', '.node'];
private options: ScannerOptions;
private itemMap: Map<string, ManifestItem[]> = new Map();
private tmpConfigStore: Map<string, ConfigObject[]> = new Map();
private configHandle: ConfigurationHandler = new ConfigurationHandler();
private app: Application;

constructor(options: Partial<ScannerOptions> = {}) {
this.options = {
Expand All @@ -38,6 +41,7 @@ export class Scanner {
exclude: DEFAULT_EXCLUDES.concat(options.exclude ?? []),
extensions: [...new Set(this.moduleExtensions.concat(options.extensions ?? []))],
};
this.app = options.app ?? new ArtusApplication();
}

private async initItemMap(): Promise<void> {
Expand Down Expand Up @@ -155,6 +159,10 @@ export class Scanner {
const configFileList = await fs.readdir(root);
const container = new Container(ArtusInjectEnum.DefaultContainerName);
container.set({ type: ConfigurationHandler });
container.set({
id: ArtusInjectEnum.Application,
value: this.app,
});
const loaderFactory = LoaderFactory.create(container);
const configItemList: (ManifestItem | null)[] = await Promise.all(configFileList.map(async filename => {
const extname = path.extname(filename);
Expand Down
2 changes: 2 additions & 0 deletions src/scanner/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BaseLoader, ManifestItem } from "../loader";
import { FrameworkConfig } from "../framework";
import { PluginConfigItem } from "../plugin/types";
import { Application } from "../types";

export interface ScannerOptions {
appName: string;
Expand All @@ -13,6 +14,7 @@ export interface ScannerOptions {
framework?: FrameworkConfig;
plugin?: Record<string, Partial<PluginConfigItem>>;
loaderListGenerator: (defaultLoaderList: string[]) => (string | typeof BaseLoader)[];
app?: Application;
}

export interface WalkOptions {
Expand Down

0 comments on commit c1dfe1e

Please sign in to comment.