-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
195 lines (183 loc) · 5.29 KB
/
utils.js
File metadata and controls
195 lines (183 loc) · 5.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import CONSTANTS from './constants'
import path from 'path'
import Cryptr from 'cryptr'
const cryptr = new Cryptr('gtnexusisBest@123')
const {
createFile,
readFile,
writeToFile,
isFileExisting
} = require('./utility/fileUtility')
const {
getCustomerName,
getDocumentType,
getRulesetType,
setupCustomerDirectories,
setupCustomerFiles,
jirafy,
setupCutomerBaseCode,
setupCustomerAxusCode,
setupSampleData,
setupCustomerResources,
} = require('./utility/customerUtility')
let {
GENERAL: {
ENCODING_UTF8,
BASE_64,
BASIC
},
configFile,
writeOut,
fields: {
EXISTING,
PRESENT_WORKING_DIR,
CUSTOMER_DIRECTORY,
CUSTOMER_TEST_DIRECTORY,
CUSTOMER,
TEST,
FILE,
USER_NAME,
PASSWORD,
DATA_KEY,
USER,
AUTHORIZATION
},
rl,
QUESTIONS:{
QUESTION_USER_CREDENTIALS,
QUESTION_USER_CREDENTIALS_USERNAME,
QUESTION_USER_CREDENTIALS_PASSWORD
},
essentials
} = CONSTANTS
/**
* Initialize's module with config file
*/
let initModules = () => {
console.log(`HELP: npm start -- --h`)
return new Promise((resolve, reject) => {
isFileExisting(`.`, `${configFile}`, `ini`).then((isExisting) => {
readFile(`.`, `${configFile}`, `ini`).then((data) => {
essentials = JSON.parse(data)
essentials[EXISTING] = isExisting
resolve(essentials)
})
}).catch((nonExistent) => {
createFile(`.`, `${configFile}`, `.ini`).then(() => {
essentials[EXISTING] = nonExistent
resolve(essentials)
})
.catch((err) => {
console.log(err)
reject()
})
})
})
}
let getPlatformLocation = () => {
return new Promise((resolve, reject) => {
essentials[PRESENT_WORKING_DIR] = __dirname
let platformPath = essentials[PRESENT_WORKING_DIR].split(path.sep)
let customerDirectoryPath = ''
let customerTestDirectoryPath = ''
if(process.platform === 'win32'){
customerDirectoryPath = `${path.join(platformPath[0],platformPath[1],platformPath[2],platformPath[3],CUSTOMER)}`
customerTestDirectoryPath = `${path.join(platformPath[0],platformPath[1],platformPath[2],platformPath[3], TEST,CUSTOMER)}`
}else{
customerDirectoryPath = `/${path.join(platformPath[0],platformPath[1],platformPath[2],platformPath[3],CUSTOMER)}`
customerTestDirectoryPath = `/${path.join(platformPath[0],platformPath[1],platformPath[2],platformPath[3], TEST,CUSTOMER)}`
}
essentials[CUSTOMER_DIRECTORY] = `${customerDirectoryPath}`
essentials[CUSTOMER_TEST_DIRECTORY] = `${customerTestDirectoryPath}`
if (!essentials[EXISTING]) {
let file = {}
file[PRESENT_WORKING_DIR] = essentials[PRESENT_WORKING_DIR]
file[CUSTOMER_DIRECTORY] = essentials[CUSTOMER_DIRECTORY]
file[CUSTOMER_TEST_DIRECTORY] = essentials[CUSTOMER_TEST_DIRECTORY]
writeOut[FILE] = file
}
resolve()
})
}
let getUserCredentials = () => {
return new Promise((resolve, reject) => {
rl.question(`${QUESTION_USER_CREDENTIALS}${QUESTION_USER_CREDENTIALS_USERNAME}`, (username) => {
if (username) {
essentials[USER] = {}
console.log(`${QUESTION_USER_CREDENTIALS_PASSWORD}`)
rl.stdoutMuted = true;
rl.question(``, (password) => {
rl.stdoutMuted = false;
essentials[USER][USER_NAME] = username
essentials[USER][PASSWORD] = cryptr.encrypt(password)
console.log("Data Key:")
rl.question(``, (dataKey) => {
if (dataKey) {
essentials[USER][DATA_KEY] = dataKey
writeOut[USER] = essentials[USER]
resolve()
} else {
reject()
}
})
})
} else {
reject(`NO USERNAME PROVIDED.`)
}
})
})
}
let getUserPlatform = () => {
return new Promise((resolve, reject) => {
if(process.platform === 'win32'){
essentials[IS_WIN] = true
}else{
essentials[IS_WIN] = false
}
})
}
let getBasicKey = (essentials) => {
return new Promise((resolve, reject) => {
if (essentials[USER][USER_NAME] && essentials[USER][PASSWORD]) {
let username = essentials[USER][USER_NAME]
let password = cryptr.decrypt(essentials[USER][PASSWORD])
let buffer = new Buffer.from(`${username}:${password}`)
if (buffer) {
essentials[USER][AUTHORIZATION] = `${BASIC} ${buffer.toString(BASE_64)}`
resolve()
} else {
reject()
}
}
})
}
let writeUserData = async () => {
await getPlatformLocation()
await getUserCredentials()
await writeToFile(`.`, `${configFile}`, `.ini`, writeOut)
}
/**
* Process Customer - Gets all data required to setup TypeExtension and Axus
* @param {*} essentials
*/
let processCustomer = (essentials) => {
return new Promise(async (resolve, reject) => {
await getCustomerName(essentials)
await getDocumentType(essentials)
await getRulesetType(essentials)
await setupCustomerDirectories(essentials)
await setupCustomerFiles(essentials)
await jirafy(essentials)
await setupSampleData(essentials)
await setupCutomerBaseCode(essentials)
await setupCustomerAxusCode(essentials)
await setupCustomerResources(essentials)
resolve()
})
}
export default {
initModules,
writeUserData,
getBasicKey,
processCustomer
}