import fs from "fs"; import path from "path"; export enum AppType { UNKNOWN, NATIVE, GATSBY, } export function probeAppType(pwd: string): [AppType, boolean] { try { console.log('path', path.join(pwd, "gatsby-config.js")); fs.statSync(path.join(pwd, "gatsby-config.js")); try { if ( fs .readdirSync(path.join(pwd, "src")) .find((dir) => dir === "components") ) { return [AppType.GATSBY, false]; } } catch (ex) { // bypass } return [AppType.GATSBY, true]; } catch (ex) { // bypass } for (const idxFile of ["index.js", "index.ts"]) { try { const rnExp = /import.*AppRegistry.*react-native/g; const idxContent = fs.readFileSync(path.join(pwd, idxFile)).toString(); if (idxContent.match(rnExp)) { try { if ( fs .readdirSync(path.join(pwd, "src")) .find((dir) => dir === "components") ) { return [AppType.GATSBY, false]; } } catch (ex) { // bypass } } return [AppType.NATIVE, true]; } catch (ex) { // bypass } } return [AppType.UNKNOWN, false]; }