File tree 8 files changed +1387
-1436
lines changed
8 files changed +1387
-1436
lines changed Original file line number Diff line number Diff line change
1
+ TEST=
2
+ TEST1=
Original file line number Diff line number Diff line change @@ -77,10 +77,19 @@ program
77
77
78
78
program
79
79
. command ( 'restore-env' )
80
- . description ( `${ chalk . yellow ( 'RESTORE' ) } the . env file based on the latest changes in the version.json file. ` )
80
+ . description ( `${ chalk . yellow ( 'RESTORE' ) } env file if u remove your env ` )
81
81
. action ( async ( ) => {
82
82
const command : Command | null = factory . createCommand ( CommandTypes . RESTORE_ENV )
83
83
command !== null && CommandInvoker . executeCommands ( command )
84
84
} )
85
85
86
+ program
87
+ . command ( 'generate' )
88
+ . description ( `${ chalk . yellow ( 'GENERATE' ) } the .env-example file based on ypur env file.` )
89
+ . alias ( 'g' )
90
+ . action ( async ( ) => {
91
+ const command : Command | null = factory . createCommand ( CommandTypes . GENERATE_EXAMPLE_ENV )
92
+ command !== null && CommandInvoker . executeCommands ( command )
93
+ } )
94
+
86
95
program . parse ( process . argv )
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import RevertCommand from './commandTypes/revertCommand'
7
7
import SyncCommand from './commandTypes/syncCommand'
8
8
import UpdateAllCommand from './commandTypes/updateAllCommand'
9
9
import UpdateCommand from './commandTypes/updateCommand'
10
+ import GenerateCommand from './commandTypes/generateCommand'
10
11
11
12
export default class CommandFactory {
12
13
createCommand ( commandType : number , ...params : any [ ] ) : Command | null {
@@ -25,6 +26,8 @@ export default class CommandFactory {
25
26
return new RevertCommand ( params )
26
27
case CommandTypes . RESTORE_ENV :
27
28
return new RestoreCommand ( params )
29
+ case CommandTypes . GENERATE_EXAMPLE_ENV :
30
+ return new GenerateCommand ( params )
28
31
29
32
default :
30
33
return null
Original file line number Diff line number Diff line change
1
+ import Command from '../command'
2
+ import { generateEnvExampleFile } from '../../handler/envHandler'
3
+ import chalk from 'chalk'
4
+ import { consola } from 'consola'
5
+
6
+ export default class RestoreCommand extends Command {
7
+ protected async beforeExecute ( ) : Promise < any > {
8
+ const isConfirmed = await this . askForConfirmation ( )
9
+
10
+ if ( ! isConfirmed ) {
11
+ console . log ( `Operation is ${ chalk . red ( 'cancelled!' ) } ` )
12
+ }
13
+ }
14
+
15
+ protected async onExecute ( beforeExecuteReturnValue : any ) : Promise < void > {
16
+ const isSuccess = await generateEnvExampleFile ( )
17
+
18
+ isSuccess
19
+ ? consola . success ( 'Env example was creating successfully. You are ready to go!' )
20
+ : consola . error ( 'There was a problem generate .env-example file.' )
21
+ }
22
+ }
Original file line number Diff line number Diff line change @@ -5,5 +5,6 @@ export enum CommandTypes {
5
5
COMPARE = 4 ,
6
6
UPDATE = 5 ,
7
7
REVERT = 6 ,
8
- RESTORE_ENV = 7
8
+ RESTORE_ENV = 7 ,
9
+ GENERATE_EXAMPLE_ENV = 8 ,
9
10
}
Original file line number Diff line number Diff line change @@ -336,3 +336,21 @@ export async function restoreEnvFile (): Promise<boolean> {
336
336
337
337
return true
338
338
}
339
+
340
+ export async function generateEnvExampleFile ( ) : Promise < boolean > {
341
+ const currentDirectory = process . cwd ( )
342
+
343
+ const currentPathDoesContainEnvFile = await doesFileExist ( path . join ( currentDirectory , '.env' ) )
344
+
345
+ if ( ! currentPathDoesContainEnvFile ) {
346
+ return false
347
+ }
348
+
349
+ const envValues = await getValuesInEnv ( { targetPath : path . join ( currentDirectory , '.env' ) } )
350
+
351
+ const result = envValues . data . map ( innerArr => innerArr [ 0 ] + '=' ) . join ( '\n' )
352
+
353
+ await writeFile ( path . join ( currentDirectory , '.env-example' ) , result )
354
+
355
+ return true
356
+ }
You can’t perform that action at this time.
0 commit comments