Skip to content

Commit

Permalink
Fix placement of module.exports and stanadlone function
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperupcall committed Jun 8, 2024
1 parent 36a6ccc commit 707dc9a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 50 deletions.
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@

# style: Format YAML files at project root
d7eacc4d28028b906e505d21101ec904d8a3ceb8

# Deindent standalone functions (in Gruntfile)
36a6cccf396db9ac67937b4d0720548aa1868f7f
99 changes: 49 additions & 50 deletions Gruntfile.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const jsoncParser = require('jsonc-parser')
const chalk = require('chalk')
const minimist = require('minimist')

'use strict'
const temporaryCoverageDir = './temp'
const schemaDir = './src/schemas/json'
const testPositiveDir = './src/test'
Expand Down Expand Up @@ -58,9 +59,6 @@ const argv = minimist(process.argv.slice(2), {
boolean: ['lint']
})

module.exports = function (/** @type {import('grunt')} */ grunt) {
'use strict'

function skipThisFileName(/** @type {string} */ name) {
// This macOS file must always be ignored.
return name === '.DS_Store'
Expand Down Expand Up @@ -680,6 +678,54 @@ function ajv() {
}
}

function showSchemaVersions() {
let countSchemaVersionUnknown = 0

const getObj_ = (schemaJson) => {
const schemaVersion = schemaJson.$schema
return SCHEMA_DIALECTS.find((obj) => schemaVersion === obj.url)
}

/** @type {Map<string, number>} */
const schemaDialectCounts = new Map(
SCHEMA_DIALECTS.map((schemaDialect) => [schemaDialect.url, 0]),
)

return {
getObj: getObj_,
process_data: (/** @type {Schema} */ schema) => {
let obj
try {
obj = getObj_(schema.jsonObj)
} catch (err) {
// suppress possible JSON.parse exception. It will be processed as obj = undefined
}
if (obj) {
schemaDialectCounts.set(obj.url, schemaDialectCounts.get(obj.url) + 1)
} else {
countSchemaVersionUnknown++
log.error(
`$schema is unknown in the file: ${schema.urlOrFilePath}`,
)
}
},
process_data_done: () => {
// Show the all the schema version count.
for (const obj of SCHEMA_DIALECTS) {
log.ok(
`Schemas using (${
obj.schemaName
}) Total files: ${schemaDialectCounts.get(obj.url)}`,
)
}
log.ok(
`$schema unknown. Total files: ${countSchemaVersionUnknown}`,
)
},
}
}

module.exports = function (/** @type {import('grunt')} */ grunt) {
grunt.registerTask(
'new_schema',
'Create a new schemas and associated files',
Expand Down Expand Up @@ -1419,53 +1465,6 @@ function ajv() {
},
)

function showSchemaVersions() {
let countSchemaVersionUnknown = 0

const getObj_ = (schemaJson) => {
const schemaVersion = schemaJson.$schema
return SCHEMA_DIALECTS.find((obj) => schemaVersion === obj.url)
}

/** @type {Map<string, number>} */
const schemaDialectCounts = new Map(
SCHEMA_DIALECTS.map((schemaDialect) => [schemaDialect.url, 0]),
)

return {
getObj: getObj_,
process_data: (/** @type {Schema} */ schema) => {
let obj
try {
obj = getObj_(schema.jsonObj)
} catch (err) {
// suppress possible JSON.parse exception. It will be processed as obj = undefined
}
if (obj) {
schemaDialectCounts.set(obj.url, schemaDialectCounts.get(obj.url) + 1)
} else {
countSchemaVersionUnknown++
log.error(
`$schema is unknown in the file: ${schema.urlOrFilePath}`,
)
}
},
process_data_done: () => {
// Show the all the schema version count.
for (const obj of SCHEMA_DIALECTS) {
log.ok(
`Schemas using (${
obj.schemaName
}) Total files: ${schemaDialectCounts.get(obj.url)}`,
)
}
log.ok(
`$schema unknown. Total files: ${countSchemaVersionUnknown}`,
)
},
}
}

grunt.registerTask(
'local_print_count_schema_versions',
'Print the schema versions and their usage frequencies',
Expand Down

0 comments on commit 707dc9a

Please sign in to comment.