import { stripIndent } from "common-tags"; import { IFileWriter, TFileWriterConfig } from "../../types"; import { FileWriter } from "../../base"; import { GlobalHelpers } from "../../../helpers"; import { AppConfig } from "../../../../app-config"; class HelperFileWriter extends FileWriter implements IFileWriter { constructor(protected config: TFileWriterConfig) { super(config); } private getThirdPartyImports() { let { collectionNameFromList } = this.config; if(typeof collectionNameFromList === 'string') { collectionNameFromList = collectionNameFromList.toLowerCase(); if (collectionNameFromList.includes('firestore')) { return `import firestore from '@react-native-firebase/firestore';`; } } return ""; } getFileContent() { const { isAsync, strategyName } = this.config; const typeDefString = `T${strategyName}Config`; if (isAsync) { return stripIndent` ${this.getThirdPartyImports()} import { ${AppConfig.ASYNC_INTERFACE_NAME} } from '../../../${AppConfig.ASYNC_INTERFACE_IMPORT_BASE_URI}'; import { ${typeDefString} } from "./types"; import { ENV } from './config'; class ${strategyName} implements ${AppConfig.ASYNC_INTERFACE_NAME} { constructor(private config?: ${typeDefString}){} async execute() { return new Promise((resolve, reject) => { resolve('example'); }); } } export {${strategyName}} `; } if (!isAsync) { return stripIndent` import { ${AppConfig.SYNC_INTERFACE_NAME} } from '../../../${AppConfig.SYNC_INTERFACE_IMPORT_BASE_URI}'; import { ${typeDefString} } from "./types"; import { ENV } from './config'; class ${strategyName} implements ${AppConfig.SYNC_INTERFACE_NAME} { constructor(private config: ${typeDefString}){} execute() { } } export {${strategyName}} `; } return ""; } execute() { try { this.write('wx'); } catch (error) { GlobalHelpers.showError(error); } } } export { HelperFileWriter };