MCPcopy Index your code
hub / github.com/SchemaStore/schemastore / forEachFile

Function forEachFile

cli.js:222–320  ·  view source on GitHub ↗

* @typedef {Object} ExtraParams @property {any} spinner } * @typedef {Object} ForEachTestFile * @property {string} [actionName] * @property {(arg0: SchemaFile, arg1: ExtraParams) => Promise } [onSchemaFile] * @property {(arg0: SchemaFile, arg1: DataFile, data: any, arg2: ExtraParams) => P

(/** @type {ForEachTestFile} */ obj)

Source from the content-addressed store, hash-verified

220 * @property {(arg0: SchemaFile, arg1: ExtraParams) => Promise<void>} [afterSchemaFile]
221 */
222async function forEachFile(/** @type {ForEachTestFile} */ obj) {
223 const spinner = ora()
224 if (obj.actionName) {
225 spinner.start()
226 }
227
228 let hasValidatedAtLeastOneFile = false
229 for (const dirent1 of await fs.readdir(SchemaDir, { withFileTypes: true })) {
230 if (isIgnoredFile(dirent1.name)) continue
231
232 const schemaName = dirent1.name
233 const schemaId = schemaName.replace('.json', '')
234
235 if (argv['schema-name'] && argv['schema-name'] !== schemaName) {
236 continue
237 }
238
239 if (SchemaValidation.skiptest.includes(schemaName)) {
240 continue
241 }
242
243 hasValidatedAtLeastOneFile = true
244
245 const schemaPath = path.join(SchemaDir, schemaName)
246 const schemaFile = await toFile(schemaPath)
247 if (obj.actionName) {
248 if (process.env.CI) {
249 console.info(
250 `Running "${obj.actionName}" on file "./${schemaFile.path}"`,
251 )
252 } else {
253 spinner.text = `Running "${obj.actionName}" on file "./${schemaFile.path}"`
254 }
255 }
256 const data = await obj?.onSchemaFile?.(schemaFile, { spinner })
257
258 if (obj?.onPositiveTestFile) {
259 const positiveTestDir = path.join(TestPositiveDir, schemaId)
260 for (const testfile of await fs
261 .readdir(positiveTestDir)
262 .catch(ignoreOnlyENOENT)) {
263 if (isIgnoredFile(testfile)) continue
264
265 const testfilePath = path.join(TestPositiveDir, schemaId, testfile)
266 let file = await toFile(testfilePath)
267 await obj.onPositiveTestFile(schemaFile, file, data, { spinner })
268 }
269 }
270
271 if (obj?.onNegativeTestFile) {
272 const negativeTestDir = path.join(TestNegativeDir, schemaId)
273 for (const testfile of await fs
274 .readdir(negativeTestDir)
275 .catch(ignoreOnlyENOENT)) {
276 if (isIgnoredFile(testfile)) continue
277
278 const testfilePath = path.join(TestNegativeDir, schemaId, testfile)
279 let file = await toFile(testfilePath)

Callers 5

taskLintFunction · 0.85
taskCheckFunction · 0.85
taskCheckStrictFunction · 0.85
printSimpleStatisticsFunction · 0.85

Calls 4

isIgnoredFileFunction · 0.85
toFileFunction · 0.85
printErrorAndExitFunction · 0.85
existsFunction · 0.70

Tested by

no test coverage detected