import { LowCodeModuleParser, IEvaledModule, LowcodeContext, getDefaultModule } from './base';

export class NormalModuleParser implements LowCodeModuleParser {
  common: any;

  onStart(context: LowcodeContext) {
    this.common = {};
  }

  parseModule(pageId: string, mod: IEvaledModule) {
    if (mod.name === '____index____') return;

    const [, , folder] = mod.path?.split('/');
    if (folder) {
      this.common[pageId] = this.common[pageId] || {};
      this.common[pageId][folder] = getDefaultModule(mod.exports);
    } else {
      this.common[pageId] = getDefaultModule(mod.exports);
    }
  }

  onEnd(context: LowcodeContext) {
    context.common = this.common;
  }
}
