UNPKG

next-firebase-auth

Version:

Simple Firebase authentication for all Next.js rendering strategies

2 lines 2.37 kB
#!/usr/bin/env node const childProcess=require("child_process"),{promises:fs}=require("fs"),path=require("path"),yargs=require("yargs"),jscodeshiftPackage=require("jscodeshift/package.json"),jscodeshiftDirectory=path.dirname(require.resolve("jscodeshift")),jscodeshiftExecutable=path.join(jscodeshiftDirectory,jscodeshiftPackage.bin.jscodeshift);async function runTransform(e,s,t,r){let o=[e];"all-v1"===e&&(o=["rename-authuser-withauthusertokenssr","rename-authuser-withauthuserssr","withauthuser-to-withuser","withauthusertokenssr-to-withusertokenssr","withauthuserssr-to-withuserssr","useauthuser-to-useuser","rename-authuser-setauthcookies"]);const a=[];for(const e of o){const s=path.resolve(__dirname,`${e}.js`),t=path.resolve(__dirname,`${e}.js`);let r;try{await fs.stat(s),r=s}catch(s){try{await fs.stat(t),r=t}catch(s){if("ENOENT"===s.code)throw new Error(`Transform '${e}' not found. Check out ${path.resolve(__dirname,"./MIGRATION.md for a list of available codemods.")}`);throw s}}a.push(r)}for(const e of a){const o=[jscodeshiftExecutable,"--transform",e,...r,"--extensions","js,ts,jsx,tsx","--parser",t.parser||"tsx","--ignore-pattern","**/node_modules/**"];t.dry&&o.push("--dry"),t.print&&o.push("--print"),t.jscodeshift&&o.push(t.jscodeshift),o.push(...s);const a=childProcess.spawnSync("node",o,{stdio:"inherit"});if(a.error)throw a.error}}function run(e){const{codemod:s,paths:t,...r}=e;return runTransform(s,t.map((e=>path.resolve(e))),r,e._)}yargs.command({command:"$0 <codemod> <paths...>",describe:"Applies a next-firebase-auth codemod to the specified paths",builder:e=>e.positional("codemod",{description:"The name of the codemod",type:"string"}).positional("paths",{array:!0,description:"Paths forwarded to `jscodeshift`",type:"string"}).option("dry",{description:"dry run (no changes are made to files)",default:!1,type:"boolean"}).option("parser",{description:"which parser for jscodeshift to use",default:"tsx",type:"string"}).option("print",{description:"print transformed files to stdout, useful for development",default:!1,type:"boolean"}).option("jscodeshift",{description:"(Advanced) Pass options directly to jscodeshift",default:!1,type:"string"}),handler:run}).scriptName("npx -p next-firebase-auth codemod").example("$0 rename-authuser-setauthcookies . --dry").example("$0 withauthusertokenssr-to-withusertokenssr src").help().parse();