This repository was archived by the owner on Apr 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuildFilesList.ts
202 lines (193 loc) · 7.24 KB
/
buildFilesList.ts
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
196
197
198
199
200
201
202
import fs from 'fs'
import { buildExcludedFile } from './buildExcludedFile'
import { getAddressBookConfig } from './config'
import { IChain, IExcludedFiles, IFileList, IFileSetting } from './types'
export const buildActivatedChainList = async () => {
const chainList: IChain[] = []
let fileSetting: IFileSetting = {}
const addressBookConfig = getAddressBookConfig()
if (fs.existsSync(addressBookConfig.fileHardhatAwesomeCLI)) {
const rawdata: any = fs.readFileSync(addressBookConfig.fileHardhatAwesomeCLI)
fileSetting = JSON.parse(rawdata)
}
if (fileSetting && fileSetting.activatedChain) {
if (fileSetting.activatedChain.length > 0) {
fileSetting.activatedChain.forEach((chain: IChain) => {
chainList.push(chain)
})
}
}
return chainList
}
export const buildAllTestsList = async () => {
const testList: IFileList[] = []
if (fs.existsSync('test')) {
testList.push({
name: 'All tests',
type: 'all',
filePath: ''
})
const files = fs.readdirSync('test')
files.map((file) => {
let fileName
if (fs.lstatSync('test/' + file).isFile()) {
fileName = file.replace(/\.[^/.]+$/, '').replace(/\.test/, ' - Test')
} else if (fs.lstatSync('test/' + file).isDirectory()) {
fileName = file + '/'
file = file + '/'
} else {
fileName = file
}
const words = fileName.split(' ')
for (let i = 0; i < words.length; i++) {
words[i] = words[i][0].toUpperCase() + words[i].substr(1)
}
fileName = words.join(' ')
testList.push({
name: fileName,
type: 'file',
filePath: file
})
})
}
return testList
}
export const buildAllScriptsList = async () => {
const scriptsList: IFileList[] = []
if (fs.existsSync('scripts')) {
const files = fs.readdirSync('scripts')
files.map((file) => {
let fileName
if (fs.lstatSync('scripts/' + file).isFile()) {
fileName = file.replace(/\.[^/.]+$/, '').replace(/\.test/, ' - Test')
} else if (fs.lstatSync('scripts/' + file).isDirectory()) {
fileName = file + '/'
file = file + '/'
} else {
fileName = file
}
const words = fileName.split(' ')
for (let i = 0; i < words.length; i++) {
words[i] = words[i][0].toUpperCase() + words[i].substr(1)
}
fileName = words.join(' ')
scriptsList.push({
name: fileName,
type: 'file',
filePath: file
})
})
}
return scriptsList
}
export const buildAllContractsList = async () => {
const scontractsList: IFileList[] = []
if (fs.existsSync('contracts')) {
const files = fs.readdirSync('contracts')
files.map((file) => {
let fileName
if (fs.lstatSync('contracts/' + file).isFile()) {
fileName = file.replace(/\.[^/.]+$/, '')
} else if (fs.lstatSync('contracts/' + file).isDirectory()) {
fileName = file + '/'
file = file + '/'
} else {
fileName = file
}
const words = fileName.split(' ')
for (let i = 0; i < words.length; i++) {
words[i] = words[i][0].toUpperCase() + words[i].substr(1)
}
fileName = words.join(' ')
scontractsList.push({
name: fileName,
type: 'file',
filePath: file
})
})
}
return scontractsList
}
export const buildAllForgeTestsList = async () => {
const testList: IFileList[] = []
if (fs.existsSync('test')) {
testList.push({
name: 'All tests',
type: 'all',
filePath: ''
})
const files = fs.readdirSync('contracts/test')
files.map((file) => {
let fileName
if (fs.lstatSync('contracts/test/' + file).isFile()) {
fileName = file.replace(/\.[^/.]+$/, '').replace(/\.test/, ' - Test')
} else if (fs.lstatSync('contracts/test/' + file).isDirectory()) {
fileName = file + '/'
} else {
fileName = file
}
const words = fileName.split(' ')
for (let i = 0; i < words.length; i++) {
words[i] = words[i][0].toUpperCase() + words[i].substr(1)
}
fileName = words.join(' ')
testList.push({
name: fileName,
type: 'file',
filePath: file
})
})
}
return testList
}
export const buildTestsList = async () => {
let allTestList: IFileList[] = await buildAllTestsList()
let excludedFiles: IExcludedFiles[] = await buildExcludedFile()
const buildFilePath: string[] = []
if (excludedFiles && excludedFiles.length > 0) {
excludedFiles = excludedFiles.filter((test: IExcludedFiles) => test.directory === 'test')
if (excludedFiles && excludedFiles.length > 0) {
excludedFiles.map((file: IExcludedFiles) => {
buildFilePath.push(file.filePath)
})
allTestList = allTestList.filter((script: IFileList) => {
return !buildFilePath.includes(script.filePath)
})
return allTestList
} else return allTestList
} else return allTestList
}
export const buildScriptsList = async () => {
let allScriptList: IFileList[] = await buildAllScriptsList()
let excludedFiles: IExcludedFiles[] = await buildExcludedFile()
const buildFilePath: string[] = []
if (excludedFiles && excludedFiles.length > 0) {
excludedFiles = excludedFiles.filter((test: any) => test.directory === 'scripts')
if (excludedFiles && excludedFiles.length > 0) {
excludedFiles.map((file: any) => {
buildFilePath.push(file.filePath)
})
allScriptList = allScriptList.filter((script: IFileList) => {
return !buildFilePath.includes(script.filePath)
})
return allScriptList
} else return allScriptList
} else return allScriptList
}
export const buildContractsList = async () => {
let allContractsList: IFileList[] = await buildAllContractsList()
let excludedFiles: IExcludedFiles[] = await buildExcludedFile()
const buildFilePath: string[] = []
if (excludedFiles !== undefined && excludedFiles.length > 0) {
excludedFiles = excludedFiles.filter((test: any) => test.directory === 'contracts')
if (excludedFiles !== undefined && excludedFiles.length > 0) {
excludedFiles.map((file: any) => {
buildFilePath.push(file.filePath)
})
allContractsList = allContractsList.filter((script: IFileList) => {
return !buildFilePath.includes(script.filePath)
})
return allContractsList
} else return allContractsList
} else return allContractsList
}