create-openfort 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.js +18 -18
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#117](https://github.com/openfort-xyz/openfort-react/pull/117) [`407ba5f`](https://github.com/openfort-xyz/openfort-react/commit/407ba5f23bca639d4bd9a8eef0b53deb73d00b05) Thanks [@martimayoral](https://github.com/martimayoral)! - update telemetry import
|
|
8
|
+
|
|
3
9
|
## 0.1.4
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
2
|
+
import Oe from"node:path";import j from"fs-extra";import*as p from"@clack/prompts";import De from"chalk";import{Command as Fe,Option as Ge}from"commander";import M from"node:path";import{fileURLToPath as we}from"node:url";var Ie=we(import.meta.url),ve=M.dirname(Ie),_=M.join(ve,"../"),z=` ___ ___ ___ _ _ ___ ___ ___ _____
|
|
3
3
|
/ _ \\| _ \\| __| \\| | __/ _ \\| _ \\_ _|
|
|
4
4
|
| (_) | _/| _|| | _| (_) | / | |
|
|
5
5
|
\\___/|_| |___|_|\\_|_| \\___/|_|_\\ |_|
|
|
6
|
-
`,b="openfort-project",B="create-openfort";var W=["openfort-ui","headless","firebase"],J=["auto","midnight","minimal","soft","web95","rounded","retro","nouns"];import
|
|
7
|
-
Learn more about Openfort at ${
|
|
8
|
-
`).parse(process.argv),o=e.args[0],i=e.opts();i.debug||(r.debug=()=>{}),g.enabled=!i.noTelemetry,r.debug("Telemetry enabled:",g.enabled),g.send({status:"started"});let t={...
|
|
9
|
-
using Git Bash. If that's that case, please use Git Bash from another terminal, such as Windows Terminal.`),new T("Non-interactive environment");let n=await p.group({...!o&&{name:()=>p.text({message:"What will your project be called?",defaultValue:b,validate:
|
|
10
|
-
${B} needs an interactive terminal to provide options`),await p.confirm({message:"Continue scaffolding a default Openfort app?",initialValue:!0})||(r.info("Exiting..."),process.exit(0)),r.info(`Bootstrapping a default Openfort app in ./${t.appName}`),{...t,template:"openfort-ui",createBackend:!1,openfortPublishableKey:"",shieldPublishableKey:""};throw n}};function
|
|
6
|
+
`,b="openfort-project",B="create-openfort";var W=["openfort-ui","headless","firebase"],J=["auto","midnight","minimal","soft","web95","rounded","retro","nouns"];import xe from"node:path";import Ne from"fs-extra";var y=()=>{let e=xe.join(_,"package.json");return Ne.readJSONSync(e).version??"unknown"};var T=class extends Error{};var r={error:(...e)=>console.error(...e),warn:(...e)=>console.warn(...e),info:(...e)=>console.log(...e),success:(...e)=>console.log(...e),debug:(...e)=>console.log(...e)};import ke,{createHash as q}from"node:crypto";import $e from"node:https";import{hostname as Ce,userInfo as Re}from"node:os";var X="https://analytics.openfort.io",Ae=()=>{let e=`${Ce()}-${Re().username}`;return q("sha256").update(e).digest("hex").slice(0,16)},L=class{constructor(){this.enabled=!0;this.send=async({properties:o={},status:i})=>{if(r.debug("Sending telemetry...",{status:i,properties:o}),!this.enabled)return;process.env.NODE_ENV!=="production"&&await import("dotenv/config");let t=process.env.POSTHOG_API_KEY;if(!t||!X){r.warn("Telemetry is not configured properly. Please contact openfort developers at support@openfort.xyz.");return}let n={session_id:this.sessionId,cli_version:y(),node_version:process.version,platform:process.platform,cli_status:i,projectId:this.projectId,projectName:this.projectName,template:this.template,...o},a=JSON.stringify({api_key:t,event:"cli_tool_used",distinct_id:this.anonymousId,properties:n}),s=new URL(`${X}/capture/`),c={hostname:s.hostname,port:s.port||443,path:s.pathname,method:"POST",headers:{"Content-Type":"application/json","Content-Length":a.length}};return new Promise(l=>{let f=$e.request(c,m=>{m.on("data",()=>{r.debug("Telemetry request response received",m.statusMessage)}),m.on("end",()=>{l()})});f.on("error",m=>{r.debug("Telemetry request error",m),l()}),f.write(a),f.end()})};this.anonymousId=Ae(),this.sessionId=q("sha256").update(ke.randomBytes(16)).digest("hex").slice(0,15)}},g=new L;var x=e=>(e.length>1&&e.endsWith("/")&&(e=e.slice(0,-1)),e);var Be=/^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/,Q=e=>{let o=x(e),i=o.split("/"),t=i.findIndex(a=>a.startsWith("@")),n=i[i.length-1];if(i.findIndex(a=>a.startsWith("@"))!==-1&&(n=i.slice(t).join("/")),!(o==="."||Be.test(n??"")))return"App name must consist of only lowercase alphanumeric characters, '-', and '_'"};var Z="[\\da-f]{8}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{12}",ee=`(test|live)_${Z}`,Le=new RegExp(`^sk_${ee}$`),Ke=new RegExp(`^pk_${ee}$`),He=new RegExp(`^${Z}$`),Ve=/^.{44}$/,S=({label:e,required:o=!0,regex:i,formatHint:t,customCheck:n})=>a=>{if(a!=="-"){if(o&&!a)return`${e} is required`;if(i&&a&&!i.test(a))return`${e} is invalid${t?` (${t})`:""}`;if(n)return n(a)}},te=S({label:"Openfort Publishable Key",regex:Ke,formatHint:"expected format: pk_test_... or pk_live_..."}),ne=S({label:"Openfort Secret Key",regex:Le,formatHint:"expected format: sk_test_... or sk_live_..."}),oe=S({label:"Shield Publishable Key",regex:He,formatHint:"expected UUID format"}),ie=S({label:"Shield Secret",required:!0}),re=S({label:"Shield Encryption Share",regex:Ve,formatHint:"expected 44 characters"}),ae=S({label:"API endpoint",customCheck:e=>{try{new URL(e);return}catch{return"API endpoint must be a valid URL"}}}),se=async e=>{try{return!!(await(await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"}})).json()).session}catch{return!1}};var Ye={appName:b,template:"openfort-ui",createBackend:!0},le=async()=>{let e=new Fe().name(B).description("A CLI for creating Openfort applications with embedded wallets").argument("[dir]","The name of the application, as well as the name of the directory to create").option("--noGit","Explicitly tell the CLI to not initialize a new git repo in the project",!1).option("--noInstall","Explicitly tell the CLI to not run the package manager's install command",!1).option("-y, --default","Bypass the CLI and use all default options to bootstrap a new Openfort app",!1).option("--CI","Boolean value if we're running in CI",!1).option("--template [string]","Specify the template to use").option("--theme [string]","Specify the theme to use (for openfort-ui template)").option("--noTelemetry","Disable sending anonymous usage data",!1).addOption(new Ge("--debug").hideHelp(!0)).version(y(),"-v, --version","Display the version number").addHelpText("afterAll",`
|
|
7
|
+
Learn more about Openfort at ${De.hex("#5B87F5").bold("https://www.openfort.xyz")}
|
|
8
|
+
`).parse(process.argv),o=e.args[0],i=e.opts();i.debug||(r.debug=()=>{}),g.enabled=!i.noTelemetry,r.debug("Telemetry enabled:",g.enabled),g.send({status:"started"});let t={...Ye,appName:o||b,flags:{noGit:i.noGit||!1,noInstall:i.noInstall||!1,default:i.default||!1,CI:i.CI||!1,template:i.template,theme:i.theme}};if(t.flags.CI)return t.template=i.template||"openfort-ui",t.theme=i.theme,t.createBackend=!1,t.openfortPublishableKey="pk_test_00000000-0000-0000-0000-000000000000",t.shieldPublishableKey="00000000-0000-0000-0000-000000000000",t;if(t.flags.default)return t.template="openfort-ui",t.createBackend=!1,t.openfortPublishableKey="",t.shieldPublishableKey="",t;try{if(process.env.TERM_PROGRAM?.toLowerCase().includes("mintty"))throw r.warn(` WARNING: It looks like you are using MinTTY, which is non-interactive. This is most likely because you are
|
|
9
|
+
using Git Bash. If that's that case, please use Git Bash from another terminal, such as Windows Terminal.`),new T("Non-interactive environment");let n=await p.group({...!o&&{name:()=>p.text({message:"What will your project be called?",defaultValue:b,validate:Q})},template:()=>p.select({message:"Select an Openfort template:",options:W.map(a=>({value:a,label:a==="openfort-ui"?"Openfort UI (default)":a,hint:je(a)})),initialValue:"openfort-ui"}),createBackend:()=>p.confirm({message:"Do you want to create a backend for automatic account recovery?",initialValue:!0}),apiEndpoint:async({results:a})=>{if(!a.createBackend){let s=await p.confirm({message:"Do you have an existing API endpoint for account recovery?",initialValue:!1});if(p.isCancel(s)&&process.exit(1),s){let c=!1,l="";for(;!c;){let f=await p.text({message:"Enter your API endpoint for creating encryption sessions:",placeholder:"http://localhost:3110/api/protected-create-encryption-session",validate:ae});p.isCancel(f)&&process.exit(1),l=f;let m=p.spinner();if(m.start("Testing API endpoint..."),await se(l))m.stop("API endpoint validated!"),c=!0;else{m.stop("API endpoint validation failed"),r.error("The endpoint did not return a valid session response");let h=await p.confirm({message:"Would you like to try another endpoint?",initialValue:!0});(p.isCancel(h)||!h)&&process.exit(1)}}return l}}},theme:({results:a})=>{if(a.template==="openfort-ui")return p.select({message:"Select a theme:",options:J.map(s=>({value:s,label:s==="auto"?"Auto (default)":s})),initialValue:"auto"})},openfortPublishableKey:()=>p.text({message:"Enter your Openfort Publishable Key:",placeholder:"pk_test_...",validate:te}),openfortSecretKey:({results:a})=>{if(a.createBackend)return p.text({message:"Enter your Openfort Secret Key:",placeholder:"sk_test_...",validate:ne})},shieldPublishableKey:()=>p.text({message:"Enter your Shield Publishable Key:",placeholder:"00000000-0000-0000-0000-000000000000",validate:oe}),shieldEncryptionShare:({results:a})=>{if(a.createBackend)return p.text({message:"Enter your Shield Encryption Share:",placeholder:"Your 44-character encryption share",validate:re})},shieldSecretKey:({results:a})=>{if(a.createBackend)return p.text({message:"Enter your Shield Secret Key:",placeholder:"Your Shield Secret",validate:ie})},...!t.flags.noGit&&{git:()=>p.confirm({message:"Should we initialize a Git repository and stage the changes?",initialValue:!0})}},{onCancel(){process.exit(1)}});return g.template=n.template,g.projectId=n.openfortPublishableKey,{appName:n.name||t.appName,template:n.template,theme:n.theme,createBackend:n.createBackend,apiEndpoint:n.apiEndpoint,openfortPublishableKey:n.openfortPublishableKey,openfortSecretKey:n.openfortSecretKey,shieldPublishableKey:n.shieldPublishableKey,shieldSecretKey:n.shieldSecretKey,shieldEncryptionShare:n.shieldEncryptionShare,flags:{...t.flags,noGit:!n.git||t.flags.noGit}}}catch(n){if(n instanceof T)return r.warn(`
|
|
10
|
+
${B} needs an interactive terminal to provide options`),await p.confirm({message:"Continue scaffolding a default Openfort app?",initialValue:!0})||(r.info("Exiting..."),process.exit(0)),r.info(`Bootstrapping a default Openfort app in ./${t.appName}`),{...t,template:"openfort-ui",createBackend:!1,openfortPublishableKey:"",shieldPublishableKey:""};throw n}};function je(e){switch(e){case"openfort-ui":return"Pre-built UI components";case"headless":return"Custom, unstyled components";case"firebase":return"With Firebase authentication";default:return""}}import ue from"node:path";import N from"node:path";import k from"fs-extra";import Ue from"ora";var pe=async({projectDir:e,openfortSecretKey:o,shieldSecretKey:i,shieldApiKey:t,shieldEncryptionShare:n,port:a=3110})=>{let s=Ue("Creating backend...").start();try{let c=N.join(_,"template/backend"),l=N.join(e,"backend");k.copySync(c,l);let f=N.join(l,".env.example"),m=N.join(l,".env");if(k.existsSync(f)){let h=k.readFileSync(f,"utf-8").replace(/OPENFORT_SECRET_KEY=.*/g,`OPENFORT_SECRET_KEY=${o}`).replace(/SHIELD_SECRET_KEY=.*/g,`SHIELD_SECRET_KEY=${i}`).replace(/SHIELD_API_KEY=.*/g,`SHIELD_API_KEY=${t}`).replace(/SHIELD_ENCRYPTION_SHARE=.*/g,`SHIELD_ENCRYPTION_SHARE=${n}`).replace(/PORT=.*/g,`PORT=${a}`);k.writeFileSync(m,h)}await new Promise(u=>setTimeout(u,250)),s.succeed("Backend created successfully!")}catch(c){throw s.fail("Failed to create backend"),r.error(c instanceof Error?c.message:String(c)),c}};import ce from"node:path";import*as E from"@clack/prompts";import P from"chalk";import O from"fs-extra";import Me from"ora";var de=async({projectName:e,projectDir:o,template:i,createBackend:t})=>{r.info("");let n=Me(`Scaffolding in: ${o}...
|
|
11
11
|
`).start();if(O.existsSync(o))if(O.readdirSync(o).length===0)e!=="."&&n.info(`${P.cyan.bold(e)} exists but is empty, continuing...
|
|
12
|
-
`);else{n.stopAndPersist();let l=await E.select({message:`${P.redBright.bold("Warning:")} ${P.cyan.bold(e)} already exists and isn't empty. How would you like to proceed?`,options:[{label:"Abort installation (recommended)",value:"abort"},{label:"Clear the directory and continue installation",value:"clear"},{label:"Continue installation and overwrite conflicting files",value:"overwrite"}],initialValue:"abort"});(E.isCancel(l)||l==="abort")&&(n.fail("Aborting installation..."),process.exit(1));let
|
|
13
|
-
`),O.emptyDirSync(o))}n.start(),O.mkdirSync(o,{recursive:!0});let a=
|
|
14
|
-
`)};import
|
|
12
|
+
`);else{n.stopAndPersist();let l=await E.select({message:`${P.redBright.bold("Warning:")} ${P.cyan.bold(e)} already exists and isn't empty. How would you like to proceed?`,options:[{label:"Abort installation (recommended)",value:"abort"},{label:"Clear the directory and continue installation",value:"clear"},{label:"Continue installation and overwrite conflicting files",value:"overwrite"}],initialValue:"abort"});(E.isCancel(l)||l==="abort")&&(n.fail("Aborting installation..."),process.exit(1));let f=await E.confirm({message:`Are you sure you want to ${l==="clear"?"clear the directory":"overwrite conflicting files"}?`,initialValue:!1});(E.isCancel(f)||!f)&&(n.fail("Aborting installation..."),process.exit(1)),l==="clear"&&(n.info(`Emptying ${P.cyan.bold(e)} and creating Openfort app..
|
|
13
|
+
`),O.emptyDirSync(o))}n.start(),O.mkdirSync(o,{recursive:!0});let a=ce.join(_,"template/openfort-templates",i),s=t?ce.join(o,"frontend"):o;O.copySync(a,s);let c=e==="."?"App":P.cyan.bold(e);await new Promise(l=>setTimeout(l,250)),n.succeed(`${c} ${P.green("scaffolded successfully!")}
|
|
14
|
+
`)};import fe from"node:path";import $ from"fs-extra";var me=({projectDir:e,openfortPublishableKey:o,shieldPublishableKey:i,apiEndpoint:t,theme:n})=>{let a=fe.join(e,".env.example"),s=fe.join(e,".env");if(!$.existsSync(a)){let f=ze({openfortPublishableKey:o,shieldPublishableKey:i,apiEndpoint:t,theme:n});$.writeFileSync(s,f);return}let l=$.readFileSync(a,"utf-8");l=l.replace(/VITE_OPENFORT_PUBLISHABLE_KEY=.*/g,`VITE_OPENFORT_PUBLISHABLE_KEY=${o}`).replace(/NEXT_PUBLIC_OPENFORT_PUBLISHABLE_KEY=.*/g,`NEXT_PUBLIC_OPENFORT_PUBLISHABLE_KEY=${o}`).replace(/OPENFORT_PUBLISHABLE_KEY=.*/g,`OPENFORT_PUBLISHABLE_KEY=${o}`),l=l.replace(/VITE_SHIELD_PUBLISHABLE_KEY=.*/g,`VITE_SHIELD_PUBLISHABLE_KEY=${i}`).replace(/NEXT_PUBLIC_SHIELD_PUBLISHABLE_KEY=.*/g,`NEXT_PUBLIC_SHIELD_PUBLISHABLE_KEY=${i}`).replace(/SHIELD_PUBLISHABLE_KEY=.*/g,`SHIELD_PUBLISHABLE_KEY=${i}`),t&&(l=l.replace(/VITE_CREATE_ENCRYPTED_SESSION_ENDPOINT=.*/g,`VITE_CREATE_ENCRYPTED_SESSION_ENDPOINT=${t}`).replace(/NEXT_PUBLIC_CREATE_ENCRYPTED_SESSION_ENDPOINT=.*/g,`NEXT_PUBLIC_CREATE_ENCRYPTED_SESSION_ENDPOINT=${t}`).replace(/CREATE_ENCRYPTED_SESSION_ENDPOINT=.*/g,`CREATE_ENCRYPTED_SESSION_ENDPOINT=${t}`)),n&&(l=l.replace(/VITE_OPENFORT_THEME=.*/g,`VITE_OPENFORT_THEME=${n}`).replace(/NEXT_PUBLIC_OPENFORT_THEME=.*/g,`NEXT_PUBLIC_OPENFORT_THEME=${n}`).replace(/OPENFORT_THEME=.*/g,`OPENFORT_THEME=${n}`)),$.writeFileSync(s,l)},ze=({openfortPublishableKey:e,shieldPublishableKey:o,apiEndpoint:i,theme:t})=>{let n=`# Openfort Configuration
|
|
15
15
|
VITE_OPENFORT_PUBLISHABLE_KEY=${e}
|
|
16
16
|
VITE_SHIELD_PUBLISHABLE_KEY=${o}
|
|
17
17
|
`;return i&&(n+=`VITE_CREATE_ENCRYPTED_SESSION_ENDPOINT=${i}
|
|
18
18
|
`),t&&(n+=`VITE_OPENFORT_THEME=${t}
|
|
19
|
-
`),n};var
|
|
20
|
-
`).start(),i=D(e),t=await F(e),n=K.parse(e).name;if(t&&i){if(o.stop(),!await H.confirm({message:`${w.redBright.bold("Warning:")} Git is already initialized in "${n}". Initializing a new git repository would delete the previous history. Would you like to continue anyways?`,initialValue:!1})){o.info("Skipping Git initialization.");return}
|
|
19
|
+
`),n};var ge=async({projectName:e,template:o,openfortPublishableKey:i,shieldPublishableKey:t,apiEndpoint:n,theme:a,createBackendOption:s,openfortSecretKey:c,shieldSecretKey:l,shieldApiKey:f,shieldEncryptionShare:m})=>{let u=ue.resolve(process.cwd(),e);await de({projectName:e,projectDir:u,template:o,createBackend:s});let h=s?ue.join(u,"frontend"):u;return me({projectDir:h,openfortPublishableKey:i,shieldPublishableKey:t,apiEndpoint:n,theme:a}),s&&c&&l&&f&&m&&await pe({projectDir:u,openfortSecretKey:c,shieldSecretKey:l,shieldApiKey:f,shieldEncryptionShare:m}),r.info("All done!"),u};import{execSync as V}from"node:child_process";import K from"node:path";import*as H from"@clack/prompts";import w from"chalk";import{execa as I}from"execa";import he from"fs-extra";import We from"ora";var Je=e=>{try{return V("git --version",{cwd:e}),!0}catch{return!1}},D=e=>he.existsSync(K.join(e,".git")),F=async e=>{try{return await I("git",["rev-parse","--is-inside-work-tree"],{cwd:e,stdout:"ignore"}),!0}catch{return!1}},Xe=()=>{let o=V("git --version").toString().trim().split(" ")[2],i=o?.split(".")[0],t=o?.split(".")[1];return{major:Number(i),minor:Number(t)}},qe=()=>V("git config --global init.defaultBranch || echo main").toString().trim(),ye=async e=>{if(r.info("Initializing Git..."),!Je(e)){r.warn("Git is not installed. Skipping Git initialization.");return}let o=We(`Creating a new git repo...
|
|
20
|
+
`).start(),i=D(e),t=await F(e),n=K.parse(e).name;if(t&&i){if(o.stop(),!await H.confirm({message:`${w.redBright.bold("Warning:")} Git is already initialized in "${n}". Initializing a new git repository would delete the previous history. Would you like to continue anyways?`,initialValue:!1})){o.info("Skipping Git initialization.");return}he.removeSync(K.join(e,".git"))}else if(t&&!i&&(o.stop(),!await H.confirm({message:`${w.redBright.bold("Warning:")} "${n}" is already in a git worktree. Would you still like to initialize a new git repository in this directory?`,initialValue:!1}))){o.info("Skipping Git initialization.");return}try{let a=qe(),{major:s,minor:c}=Xe();s<2||s===2&&c<28?(await I("git",["init"],{cwd:e}),await I("git",["symbolic-ref","HEAD",`refs/heads/${a}`],{cwd:e})):await I("git",["init",`--initial-branch=${a}`],{cwd:e}),await I("git",["add","."],{cwd:e}),o.succeed(`${w.green("Successfully initialized and staged")} ${w.green.bold("git")}
|
|
21
21
|
`)}catch{o.fail(`${w.bold.red("Failed:")} could not initialize git. Update git to the latest version!
|
|
22
|
-
`)}};import G from"node:path";import
|
|
23
|
-
${
|
|
24
|
-
Next steps:`),e!=="."&&r.info(` ${
|
|
25
|
-
${
|
|
26
|
-
${
|
|
27
|
-
${
|
|
28
|
-
${
|
|
22
|
+
`)}};import G from"node:path";import d from"chalk";import Y from"fs-extra";var C=()=>{let e=process.env.npm_config_user_agent;return e?e.startsWith("yarn")?"yarn":e.startsWith("pnpm")?"pnpm":e.startsWith("bun")?"bun":"npm":"npm"};var Ee=async({projectName:e=b,projectDir:o,createBackend:i})=>{let t=C();if(r.info(`
|
|
23
|
+
${d.green("Success! Your Openfort project is ready.")}`),r.info(`
|
|
24
|
+
Next steps:`),e!=="."&&r.info(` ${d.cyan(`cd ${e}`)}`),i){let n=G.join(o,"backend","node_modules"),a=G.join(o,"frontend","node_modules"),s=!Y.existsSync(n)||!Y.existsSync(a);r.info(`
|
|
25
|
+
${d.yellow("For the backend:")}`),r.info(` ${d.cyan("cd backend")}`),s&&(t==="yarn"?r.info(` ${d.cyan(t)}`):r.info(` ${d.cyan(`${t} install`)}`)),["npm","bun"].includes(t)?r.info(` ${d.cyan(`${t} run dev`)}`):r.info(` ${d.cyan(`${t} dev`)}`),r.info(`
|
|
26
|
+
${d.yellow("For the frontend (in a new terminal):")}`),r.info(` ${d.cyan("cd frontend")}`),s&&(t==="yarn"?r.info(` ${d.cyan(t)}`):r.info(` ${d.cyan(`${t} install`)}`)),["npm","bun"].includes(t)?r.info(` ${d.cyan(`${t} run dev`)}`):r.info(` ${d.cyan(`${t} dev`)}`)}else{let n=G.join(o,"node_modules");!Y.existsSync(n)&&(t==="yarn"?r.info(` ${d.cyan(t)}`):r.info(` ${d.cyan(`${t} install`)}`)),["npm","bun"].includes(t)?r.info(` ${d.cyan(`${t} run dev`)}`):r.info(` ${d.cyan(`${t} dev`)}`)}!await F(o)&&!D(o)&&(r.info(`
|
|
27
|
+
${d.cyan("git init")}`),r.info(` ${d.cyan('git commit -m "initial commit"')}`)),r.info(`
|
|
28
|
+
${d.blue("Learn more at https://www.openfort.xyz/docs")}`)};import _e from"node:path";var be=e=>{let i=x(e).split("/"),t=i[i.length-1];if(t==="."){let s=_e.resolve(process.cwd());t=_e.basename(s)}let n=i.findIndex(s=>s.startsWith("@"));i.findIndex(s=>s.startsWith("@"))!==-1&&(t=i.slice(n).join("/"));let a=i.filter(s=>!s.startsWith("@")).join("/");return[t,a]};import Qe from"gradient-string";var Ze=["#c3c3c3ff","#ff3b30"],Se=async()=>{let e=Qe(Ze),o=C();(o==="yarn"||o==="pnpm")&&console.log(""),console.log(e.multiline(z))};import{execSync as et}from"node:child_process";import tt from"node:https";var Pe=e=>{let o=y();o.includes("beta")?(r.warn(" You are using a beta version of create-openfort."),r.warn(" Please report any bugs you encounter.")):o.includes("next")?(r.warn(" You are running create-openfort with the @next tag which is no longer maintained."),r.warn(" Please run the CLI with @latest instead.")):o!==e&&(r.warn(" You are using an outdated version of create-openfort."),r.warn(" Your version:",`${o}.`,"Latest version in the npm registry:",e),r.warn(" Please run the CLI with @latest to get the latest updates."))};function nt(){return new Promise((e,o)=>{tt.get("https://registry.npmjs.org/-/package/create-openfort/dist-tags",i=>{if(i.statusCode===200){let t="";i.on("data",n=>{t+=n}),i.on("end",()=>{e(JSON.parse(t).latest)})}else o()}).on("error",()=>{o()})})}var Te=()=>nt().catch(()=>{try{return et("npm view create-openfort version").toString().trim()}catch{return null}});var ot=async()=>{let e=await Te();await Se(),e&&Pe(e);let{appName:o,template:i,theme:t,createBackend:n,apiEndpoint:a,openfortPublishableKey:s,openfortSecretKey:c,shieldPublishableKey:l,shieldSecretKey:f,shieldEncryptionShare:m,flags:{noGit:u}}=await le(),[h,U]=be(o);g.projectName=h;let v=await ge({projectName:U,template:i,openfortPublishableKey:s,shieldPublishableKey:l,apiEndpoint:a||(n?"http://localhost:3110/api/protected-create-encryption-session":void 0),theme:t,createBackendOption:n,openfortSecretKey:c,shieldSecretKey:f,shieldApiKey:l,shieldEncryptionShare:m}),R=n?Oe.join(v,"frontend","package.json"):Oe.join(v,"package.json");if(j.existsSync(R)){let A=j.readJSONSync(R);A.name=h,A.openfortMetadata={initVersion:y(),template:i},j.writeJSONSync(R,A,{spaces:2})}u||await ye(v),await Ee({projectName:U,projectDir:v,createBackend:n}),g.send({status:"completed"}),process.exit(0)};ot().catch(e=>{r.error("Aborting installation..."),e instanceof Error?r.error(e):r.error("An unknown error has occurred. Please open an issue on GitHub with the below:"),g.send({status:"error",properties:{error:e instanceof Error?e.message:String(e)}}),process.exit(1)});
|