//noPage import { appjson, configjson, configlivejson } from 'esoftplay/bin/files'; import { EspAssets } from 'esoftplay/cache/assets'; import cacheConfig from 'esoftplay/cache/config.json'; import { LibLocale } from 'esoftplay/cache/lib/locale/import'; import { EspRouterPropertyInterface } from 'esoftplay/cache/properties'; import { EspRouterInterface } from 'esoftplay/cache/routers'; import * as Application from 'expo-application'; import { LogBox, Platform } from 'react-native'; import 'react-native-reanimated'; import './oneplusfixfont'; type ConfigType = typeof cacheConfig const ignoreWarns = [ "Setting a timer for a long period of time", "VirtualizedLists should never be nested inside plain ScrollViews with the same orientation", "ViewPropTypes will be removed", "AsyncStorage has been extracted from react-native", "EventEmitter.removeListener", "Got a component with the name 'm'", "Did not receive response to shouldStartLoad in time", "startLoadWithResult invoked with invalid lockldentifier", ]; const err = console.error; console.error = (...arg) => { for (let i = 0; i < ignoreWarns.length; i++) { if (arg?.[0]?.startsWith?.(ignoreWarns[i])) return; } err(...arg); }; const warn = console.warn; console.warn = (...arg) => { for (let i = 0; i < ignoreWarns.length; i++) { if (arg?.[0]?.startsWith?.(ignoreWarns[i])) return; } warn(...arg); }; LogBox.ignoreLogs(ignoreWarns); if (!__DEV__) { if (Platform.OS == 'web') { configjson.config.domain = window.location.hostname } } let lconf: any try { lconf = configlivejson; } catch (error) { } if (configjson?.config?.isDebug == 0) LogBox.ignoreAllLogs(); /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/esp.md) untuk melihat dokumentasi*/ const esp = { mergeDeep(target, ...sources) { target = Object(target); for (const source of sources) { const sourceObj = Object(source); for (const [key, value] of Object.entries(sourceObj)) { if (value !== undefined && value !== null) { if (Array.isArray(value)) { // Overwrite arrays completely target[key] = value.slice(); // shallow copy } else if (typeof value === "object") { target[key] = esp.mergeDeep(target[key] ?? {}, value); } else { target[key] = value; } } } } return target; }, appjson(): any { return esp.mergeDeep(appjson, configjson) }, assets(path: EspAssets): any { const _assets = require('esoftplay/cache/assets') return _assets(path) }, versionName(): string { return (Application.nativeBuildVersion) + '-' + esp.config('publish_id') }, config(param?: keyof ConfigType, ...params: string[]): T { let out: any = this._config(); if (param) { const _params = [param, ...params]; for (let i = 0; i < _params.length; i++) { const key = _params[i]; if (out && typeof out === 'object' && out.hasOwnProperty(key)) { out = out[key]; } else { return {} as T; // Return empty object if key doesn't exist } } } return out as T; }, isDebug(message: string): boolean { if (!lconf) { return false } return configjson.config.domain != lconf.config.domain }, readDeepObj(obj: any) { return function (param?: string, ...params: string[]): any { let out: any = obj if (param) { var _params = [param, ...params] if (_params.length > 0) for (let i = 0; i < _params.length; i++) { out = out?.[_params[i]]; if (out == undefined) { break; } } } return out; } }, lang(moduleTask: T, langName: string, ...stringToBe: string[]): string { let string = LibLocale.stateLang().get()?.[esp.langId()]?.[moduleTask]?.[langName] if (!string) { string = esp.assets("locale/id.json")?.[moduleTask]?.[langName] } function sprintf(string: string, index: number): string { if (stringToBe[index] != undefined) { string = string?.replace?.("%s", stringToBe[index]) if (string?.includes?.("%s")) { return sprintf(string, index + 1) } } return string } if (string.includes("%s")) { string = sprintf(string, 0) } return string }, langId(): string { const LibLocale = esp.mod('lib/locale'); return LibLocale.state().get() }, mod(path: T): EspRouterInterface[T] { var modtast = path.split("/"); if (modtast[1] == "") { modtast[1] = "index"; } const routers = require('esoftplay/cache/routers') return routers(modtast.join("/")); }, modProp(path: T): EspRouterPropertyInterface[T] { var modtast = path.split("/"); if (modtast[1] == "") { modtast[1] = "index"; } const properties = require('esoftplay/cache/properties') return properties(modtast.join("/")); }, _config(): typeof cacheConfig { let app = esp.mergeDeep(appjson, configjson) var msg = '' if (!app.hasOwnProperty('config')) { msg = "tidak ada config" } else if (!app.config.hasOwnProperty('domain') || app.config.domain.length == 0) { msg = "config tidak ada domain" } else if (!app.config.hasOwnProperty('salt') || app.config.salt.length == 0) { msg = "config tidak ada salt" } else if (!app.config.hasOwnProperty("experienceId") || app.config.experienceId.length == 0) { msg = "config experienceId harus diisi dengan @esoftplay/[slug]" } if (msg != '') { let error = new Error(msg); throw error; } const config = { // default config timezone: "Asia/Jakarta", protocol: "http", uri: "/", api: "api", data: "data", home: { member: "content/index", public: "content/index" }, group_id: 0, langIds: ["id", "en"], theme: ["light", "dark"], comment_login: 1, notification: 0, ...app.config } if (!config.hasOwnProperty('url') || config.url.length == 0) { config.url = config.protocol + "://" + config.api + "." + config.domain + config.uri; } if (!config.hasOwnProperty('content') || config.content.length == 0) { config.content = config.protocol + "://" + config.data + "." + config.domain + config.uri; } config.webviewOpen = ' '; config.webviewClose = ' '; return config; }, navigations(): string[] { const navs = require('esoftplay/cache/navs').default return navs; }, home(): any { return esp.mod('user/index'); }, routes(): any { const UserRoutes = esp.mod('user/routes'); return UserRoutes.state().get(); }, log(message?: any, ...optionalParams: any[]) { if (esp.config()?.isDebug == 1) { let out = [message] if (optionalParams) out.push(...optionalParams) out.forEach((x) => { if (x != undefined) console.log(JSON.stringify(x, undefined, 2), "\x1b[0m"); else console.log(x, "\x1b[0m") }) } }, condition() { let result: any = undefined; function ifFunc(condition: boolean, value: any) { if (result === undefined && condition) result = value; return api; } function elseFunc(value: any) { if (result === undefined) result = value; return api; } function valueFunc() { return result; } const api = { if: ifFunc, elseif: ifFunc, else: elseFunc, getValue: valueFunc, }; return api; }, logColor: { reset: "\x1b[0m", black: "\x1b[30m", red: "\x1b[31m", green: "\x1b[32m", yellow: "\x1b[33m", blue: "\x1b[34m", magenta: "\x1b[35m", cyan: "\x1b[36m", white: "\x1b[37m", backgroundBlack: "\x1b[40m", backgroundRed: "\x1b[41m", backgroundGreen: "\x1b[42m", backgroundYellow: "\x1b[43m", backgroundBlue: "\x1b[44m", backgroundMagenta: "\x1b[45m", backgroundCyan: "\x1b[46m", backgroundWhite: "\x1b[47m", } } export default esp // var a = esp.assets("bacground") // mengambil file dari folder images // var b = esp.config("data", "name") // mengambil value dari config (bisa ditentukan di app.json) // var c = esp.mod("module/task") // mengeksekusi module/task // var e = esp.home() // mengkesekusi module/task untuk halaman pertama // var f = esp.log("pesan") // log yang tampil jika di app.json -> isDebug == 1 // var g = esp.routes() // mengambil history status navigasi yang sedang berjalan