File tree Expand file tree Collapse file tree 4 files changed +39
-2
lines changed
Expand file tree Collapse file tree 4 files changed +39
-2
lines changed Original file line number Diff line number Diff line change 55 "scripts" : {
66 "dev" : " next dev" ,
77 "build" : " next build" ,
8+ "i18n" : " replexica i18n" ,
89 "start" : " next start" ,
910 "lint" : " next lint"
1011 },
Original file line number Diff line number Diff line change 1+ import { Command } from "commander" ;
2+
3+ export default new Command ( )
4+ . command ( "auth" )
5+ . description ( "Authenticate with Replexica" )
6+ . helpOption ( "-h, --help" , "Show help" )
7+ . action ( async ( ) => {
8+ const message = `
9+ To obtain Replexica API key, please follow the following link:
10+
11+ https://replexica.com/app/settings
12+
13+ Once you have your API key, please save it in the .env file in the root of your project.
14+ ` . trim ( ) ;
15+
16+ console . log ( message ) ;
17+ } ) ;
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import dotenv from 'dotenv';
22import { Command } from 'commander' ;
33
44import i18nCmd from './i18n.js' ;
5+ import authCmd from './auth.js' ;
56
67dotenv . config ( ) ;
78
@@ -10,4 +11,5 @@ export default new Command()
1011 . description ( 'Replexica CLI' )
1112 . helpOption ( '-h, --help' , 'Show help' )
1213 . addCommand ( i18nCmd )
14+ . addCommand ( authCmd )
1315 . parse ( process . argv ) ;
Original file line number Diff line number Diff line change @@ -6,5 +6,22 @@ const EnvSchema = Z.object({
66} ) ;
77
88export function getEnv ( ) {
9- return EnvSchema . parse ( process . env ) ;
10- }
9+ try {
10+ return EnvSchema . parse ( process . env ) ;
11+ } catch ( error ) {
12+ if ( error instanceof Z . ZodError ) {
13+ // handle missing api key
14+ if (
15+ error . errors . some ( ( err ) => err . path . find ( ( p ) => p === 'REPLEXICA_API_KEY' ) &&
16+ err . message . toLowerCase ( ) . includes ( 'required' ) )
17+ ) {
18+ console . log ( `REPLEXICA_API_KEY is missing in env variables. Did you forget to run 'replexica auth'?` ) ;
19+ return process . exit ( 1 ) ;
20+ } else {
21+ throw error ;
22+ }
23+ } else {
24+ throw error ;
25+ }
26+ }
27+ }
You can’t perform that action at this time.
0 commit comments