()
| 16 | } |
| 17 | |
| 18 | export async function copyComponents() { |
| 19 | var isUsingSrc = false; |
| 20 | |
| 21 | // COPY THE COMPONENTS |
| 22 | |
| 23 | const cwd = process.cwd(); |
| 24 | var source = path.join(cwd, 'node_modules/firebase-nextjs/dist/components/firebase-nextjs'); |
| 25 | var target = path.join(cwd, ''); |
| 26 | |
| 27 | // If @/src exists, copy to @/src/components |
| 28 | const srcTarget = path.join(target, 'src'); |
| 29 | if (fs.existsSync(srcTarget)) { |
| 30 | target = srcTarget; |
| 31 | isUsingSrc = true; |
| 32 | } |
| 33 | |
| 34 | var routerPath = path.join(cwd, ''); |
| 35 | if (fs.existsSync(path.join(routerPath, 'src'))) routerPath = path.join(routerPath, 'src'); |
| 36 | |
| 37 | const appRouterPath = path.join(routerPath, 'app'); |
| 38 | const pagesRouterPath = path.join(routerPath, 'pages'); |
| 39 | |
| 40 | if (fs.existsSync(appRouterPath)) { |
| 41 | console.log("App router detected"); |
| 42 | const nextFireTarget = path.join(appRouterPath, '(authpages)'); |
| 43 | const nextFireSource = path.join(cwd, 'node_modules/firebase-nextjs/dist/authpages'); |
| 44 | if (!fs.existsSync(nextFireTarget)) fs.mkdirSync(nextFireTarget); |
| 45 | copyFiles(nextFireSource, nextFireTarget); |
| 46 | console.log("Files copied to app router"); |
| 47 | } |
| 48 | else { |
| 49 | console.error("Pages router not supported yet.") |
| 50 | console.error("See progress here : https://github.com/NirmalScaria/firebase-nextjs/issues/3") |
| 51 | throw new Error("Pages router not supported yet."); |
| 52 | } |
| 53 | |
| 54 | // COPY THE MIDDLEWARE |
| 55 | source = path.join(cwd, 'node_modules/firebase-nextjs/dist/middleware.js'); |
| 56 | if (isUsingSrc) { |
| 57 | target = path.join(cwd, 'src/middleware.js'); |
| 58 | } |
| 59 | else { |
| 60 | target = path.join(cwd, 'middleware.js'); |
| 61 | } |
| 62 | if (fs.existsSync(target)) { |
| 63 | target = path.join(cwd, 'middleware-example.js'); |
| 64 | } |
| 65 | |
| 66 | fs.copyFileSync(source, target); |
| 67 | } |
no test coverage detected