UNPKG

1.73 kBSource Map (JSON)View Raw
1{"version":3,"sources":["../../lib/find-pages-dir.ts"],"names":["existsSync","f","fs","accessSync","constants","F_OK","_","findPagesDir","dir","curDir","path","join","Error"],"mappings":"iGAAA,8CACA,kD,mFAEO,KAAMA,CAAAA,UAAU,CAAIC,CAAD,EAAwB,CAChD,GAAI,CACFC,YAAGC,UAAH,CAAcF,CAAd,CAAiBC,YAAGE,SAAH,CAAaC,IAA9B,EACA,MAAO,KAAP,CACD,CAAC,MAAOC,CAAP,CAAU,CACV,MAAO,MAAP,CACD,CACF,CAPM,C,8BASA,QAASC,CAAAA,YAAT,CAAsBC,GAAtB,CAA2C,CAChD;AACA,GAAIC,CAAAA,MAAM,CAAGC,cAAKC,IAAL,CAAUH,GAAV,CAAe,OAAf,CAAb,CACA,GAAIR,UAAU,CAACS,MAAD,CAAd,CAAwB,MAAOA,CAAAA,MAAP,CAExBA,MAAM,CAAGC,cAAKC,IAAL,CAAUH,GAAV,CAAe,WAAf,CAAT,CACA,GAAIR,UAAU,CAACS,MAAD,CAAd,CAAwB,MAAOA,CAAAA,MAAP,CAExB;AACA,GAAIT,UAAU,CAACU,cAAKC,IAAL,CAAUH,GAAV,CAAe,IAAf,CAAqB,OAArB,CAAD,CAAd,CAA+C,CAC7C,KAAM,IAAII,CAAAA,KAAJ,CACJ,2FADI,CAAN,CAGD,CAED,KAAM,IAAIA,CAAAA,KAAJ,CACJ,+EADI,CAAN,CAGD","sourcesContent":["import fs from 'fs'\nimport path from 'path'\n\nexport const existsSync = (f: string): boolean => {\n try {\n fs.accessSync(f, fs.constants.F_OK)\n return true\n } catch (_) {\n return false\n }\n}\n\nexport function findPagesDir(dir: string): string {\n // prioritize ./pages over ./src/pages\n let curDir = path.join(dir, 'pages')\n if (existsSync(curDir)) return curDir\n\n curDir = path.join(dir, 'src/pages')\n if (existsSync(curDir)) return curDir\n\n // Check one level up the tree to see if the pages directory might be there\n if (existsSync(path.join(dir, '..', 'pages'))) {\n throw new Error(\n '> No `pages` directory found. Did you mean to run `next` in the parent (`../`) directory?'\n )\n }\n\n throw new Error(\n \"> Couldn't find a `pages` directory. Please create one under the project root\"\n )\n}\n"]}
\No newline at end of file