1
1
"use strict" ;
2
+ var __awaiter = ( this && this . __awaiter ) || function ( thisArg , _arguments , P , generator ) {
3
+ function adopt ( value ) { return value instanceof P ? value : new P ( function ( resolve ) { resolve ( value ) ; } ) ; }
4
+ return new ( P || ( P = Promise ) ) ( function ( resolve , reject ) {
5
+ function fulfilled ( value ) { try { step ( generator . next ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
6
+ function rejected ( value ) { try { step ( generator [ "throw" ] ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
7
+ function step ( result ) { result . done ? resolve ( result . value ) : adopt ( result . value ) . then ( fulfilled , rejected ) ; }
8
+ step ( ( generator = generator . apply ( thisArg , _arguments || [ ] ) ) . next ( ) ) ;
9
+ } ) ;
10
+ } ;
2
11
var __importDefault = ( this && this . __importDefault ) || function ( mod ) {
3
12
return ( mod && mod . __esModule ) ? mod : { "default" : mod } ;
4
13
} ;
@@ -10,7 +19,7 @@ const clear_1 = __importDefault(require("clear"));
10
19
const chalk_1 = __importDefault ( require ( "chalk" ) ) ;
11
20
const figlet_1 = __importDefault ( require ( "figlet" ) ) ;
12
21
const cryptify_1 = __importDefault ( require ( "cryptify" ) ) ;
13
- const edit = ( argv ) => {
22
+ const edit = ( argv ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
14
23
const CONFIG_DIR_PATH = path_1 . default . join ( process . cwd ( ) , argv . p ? argv . p : "config" ) ;
15
24
const ENCRYPTION_KEY_PATH = path_1 . default . join ( CONFIG_DIR_PATH , `${ argv . e } .key` ) ;
16
25
const ENCRYPTED_FILE_PATH = path_1 . default . join ( CONFIG_DIR_PATH , `${ argv . e } .yml.enc` ) ;
@@ -29,49 +38,45 @@ const edit = (argv) => {
29
38
fs_1 . default . copyFileSync ( ENCRYPTED_FILE_PATH , DECRYPTED_FILE_PATH ) ;
30
39
const secretKeyData = fs_1 . default . readFileSync ( ENCRYPTION_KEY_PATH ) . toString ( ) ;
31
40
const decryptedFileInstance = new cryptify_1 . default ( DECRYPTED_FILE_PATH , secretKeyData , undefined , undefined , true , true ) ;
32
- decryptedFileInstance . decrypt ( ) . then ( ( files ) => {
33
- fs_1 . default . unlinkSync ( DECRYPTED_FILE_PATH ) ;
34
- if ( ! files )
35
- return ;
36
- const parsedObj = JSON . parse ( files [ 0 ] ) ;
37
- if ( Object . keys ( parsedObj ) . length === 0 ) {
38
- return console . log ( chalk_1 . default . red ( "Nothing to edit. Please add some keys first." ) ) ;
39
- }
40
- inquirer_1 . default
41
- . prompt ( [
41
+ const files = yield decryptedFileInstance . decrypt ( ) ;
42
+ fs_1 . default . unlinkSync ( DECRYPTED_FILE_PATH ) ;
43
+ if ( ! files )
44
+ return ;
45
+ const parsedObj = JSON . parse ( files [ 0 ] ) ;
46
+ if ( Object . keys ( parsedObj ) . length === 0 ) {
47
+ return console . log ( chalk_1 . default . red ( "Nothing to edit. Please add some keys first." ) ) ;
48
+ }
49
+ try {
50
+ const listAnswers = yield inquirer_1 . default . prompt ( [
42
51
{
43
52
name : "keyToEdit" ,
44
53
type : "list" ,
45
54
message : "Which key would you like to edit?" ,
46
55
choices : Object . keys ( parsedObj ) ,
47
56
} ,
48
- ] )
49
- . then ( ( listAnswers ) => {
50
- inquirer_1 . default
51
- . prompt ( [
52
- {
53
- name : "keyEditedValue" ,
54
- type : "input" ,
55
- message : "What is the new value of this key?" ,
56
- default : parsedObj [ listAnswers . keyToEdit ] ,
57
- validate : ( value ) => {
58
- if ( value . length ) {
59
- return true ;
60
- }
61
- return "Please enter the new value of the key you would like to edit." ;
62
- } ,
57
+ ] ) ;
58
+ const inputAnswers = yield inquirer_1 . default . prompt ( [
59
+ {
60
+ name : "keyEditedValue" ,
61
+ type : "input" ,
62
+ message : "What is the new value of this key?" ,
63
+ default : parsedObj [ listAnswers . keyToEdit ] ,
64
+ validate : ( value ) => {
65
+ if ( value . length ) {
66
+ return true ;
67
+ }
68
+ return "Please enter the new value of the key you would like to edit." ;
63
69
} ,
64
- ] )
65
- . then ( ( inputAnswers ) => {
66
- parsedObj [ listAnswers . keyToEdit ] = inputAnswers . keyEditedValue ;
67
- const encryptedFileInstance = new cryptify_1 . default ( ENCRYPTED_FILE_PATH , secretKeyData , undefined , undefined , true , true ) ;
68
- fs_1 . default . writeFileSync ( ENCRYPTED_FILE_PATH , JSON . stringify ( parsedObj ) ) ;
69
- encryptedFileInstance . encrypt ( ) ;
70
- } )
71
- . then ( ( ) => {
72
- console . log ( "Done! 🌟" ) ;
73
- } ) ;
74
- } ) ;
75
- } ) ;
76
- } ;
70
+ } ,
71
+ ] ) ;
72
+ parsedObj [ listAnswers . keyToEdit ] = inputAnswers . keyEditedValue ;
73
+ const encryptedFileInstance = new cryptify_1 . default ( ENCRYPTED_FILE_PATH , secretKeyData , undefined , undefined , true , true ) ;
74
+ fs_1 . default . writeFileSync ( ENCRYPTED_FILE_PATH , JSON . stringify ( parsedObj ) ) ;
75
+ yield encryptedFileInstance . encrypt ( ) ;
76
+ console . log ( "Done! 🌟" ) ;
77
+ }
78
+ catch ( e ) {
79
+ console . log ( "🚫 Cooler-Env 🚫" ) ;
80
+ }
81
+ } ) ;
77
82
exports . default = edit ;
0 commit comments