adding mostly readfilesync of path updates to require

This commit is contained in:
Grace Park 2021-06-17 20:22:04 -07:00
Родитель 0762734b43
Коммит 8154d3b701
8 изменённых файлов: 17 добавлений и 11 удалений

Просмотреть файл

@ -6,7 +6,7 @@ const operations = {}
fs.readdirSync(schemasPath) fs.readdirSync(schemasPath)
.forEach(filename => { .forEach(filename => {
const key = filename.replace('.json', '') const key = filename.replace('.json', '')
const value = require(path.join(schemasPath, filename)) const value = JSON.parse(fs.readFileSync(path.join(schemasPath, filename)))
operations[key] = value operations[key] = value
}) })
const allVersions = require('../all-versions') const allVersions = require('../all-versions')

Просмотреть файл

@ -19,7 +19,7 @@ versions.forEach(version => {
// payload file: /path/to/check_run.completed.payload.json // payload file: /path/to/check_run.completed.payload.json
// payload path: check_run.completed // payload path: check_run.completed
const payloadPath = path.basename(payloadFile).replace('.payload.json', '') const payloadPath = path.basename(payloadFile).replace('.payload.json', '')
set(payloadsPerVersion, payloadPath, formatAsJsonCodeBlock(require(payloadFile))) set(payloadsPerVersion, payloadPath, formatAsJsonCodeBlock(JSON.parse(fs.readFileSync(payloadFile))))
}) })
payloads[version] = payloadsPerVersion payloads[version] = payloadsPerVersion

Просмотреть файл

@ -1,3 +1,5 @@
const fs = require('fs')
const path = require('path')
const previews = require('../../lib/graphql/static/previews') const previews = require('../../lib/graphql/static/previews')
const upcomingChanges = require('../../lib/graphql/static/upcoming-changes') const upcomingChanges = require('../../lib/graphql/static/upcoming-changes')
const changelog = require('../../lib/graphql/static/changelog') const changelog = require('../../lib/graphql/static/changelog')
@ -23,7 +25,7 @@ module.exports = function graphqlContext (req, res, next) {
const graphqlVersion = currentVersionObj.miscVersionName const graphqlVersion = currentVersionObj.miscVersionName
req.context.graphql = { req.context.graphql = {
schemaForCurrentVersion: require(`../../lib/graphql/static/schema-${graphqlVersion}`), schemaForCurrentVersion: JSON.parse(fs.readFileSync(path.join(process.cwd(), '/lib/graphql/static/schema-' + graphqlVersion + '.json'))),
previewsForCurrentVersion: previews[graphqlVersion], previewsForCurrentVersion: previews[graphqlVersion],
upcomingChangesForCurrentVersion: upcomingChanges[graphqlVersion], upcomingChangesForCurrentVersion: upcomingChanges[graphqlVersion],
prerenderedObjectsForCurrentVersion: prerenderedObjects[graphqlVersion], prerenderedObjectsForCurrentVersion: prerenderedObjects[graphqlVersion],

Просмотреть файл

@ -63,7 +63,7 @@ async function main () {
fs.writeFileSync(newDereferencedFile, newDereferenceContent) fs.writeFileSync(newDereferencedFile, newDereferenceContent)
console.log(`Created ${newDereferencedFile}.`) console.log(`Created ${newDereferencedFile}.`)
const dereferencedSchema = require(path.join(process.cwd(), newDereferencedFile)) const dereferencedSchema = JSON.parse(fs.readFileSync(path.join(process.cwd(), newDereferencedFile)))
// Store all operations in an array of operation objects // Store all operations in an array of operation objects
const operations = await getOperations(dereferencedSchema) const operations = await getOperations(dereferencedSchema)

Просмотреть файл

@ -1,5 +1,6 @@
#!/usr/bin/env node #!/usr/bin/env node
const fs = require('fs')
const path = require('path')
const glob = require('glob') const glob = require('glob')
const program = require('commander') const program = require('commander')
const getOperations = require('./utils/get-operations') const getOperations = require('./utils/get-operations')
@ -28,8 +29,8 @@ if (filesToCheck.length) {
async function check (files) { async function check (files) {
console.log('Verifying OpenAPI files are valid with decorator') console.log('Verifying OpenAPI files are valid with decorator')
// Check this one to make sure it's reading the right files
const documents = files.map(filename => [filename, require(filename)]) const documents = files.map(filename => [filename, JSON.parse(fs.readFileSync(path.join(process.cwd(), filename)))])
for (const [filename, schema] of documents) { for (const [filename, schema] of documents) {
try { try {

Просмотреть файл

@ -75,7 +75,7 @@ async function getDereferencedFiles () {
// name of the `github/github` checkout. A CI test // name of the `github/github` checkout. A CI test
// checks the version and fails if it's not a semantic version. // checks the version and fails if it's not a semantic version.
schemas.forEach(filename => { schemas.forEach(filename => {
const schema = require(path.join(dereferencedPath, filename)) const schema = JSON.parse(fs.readFileSync(path.join(dereferencedPath, filename)))
schema.info.version = `${githubBranch} !!DEVELOPMENT MODE - DO NOT MERGE!!` schema.info.version = `${githubBranch} !!DEVELOPMENT MODE - DO NOT MERGE!!`
fs.writeFileSync(path.join(dereferencedPath, filename), JSON.stringify(schema, null, 2)) fs.writeFileSync(path.join(dereferencedPath, filename), JSON.stringify(schema, null, 2))
}) })
@ -85,7 +85,7 @@ async function decorate () {
console.log('\n🎄 Decorating the OpenAPI schema files in lib/rest/static/dereferenced.\n') console.log('\n🎄 Decorating the OpenAPI schema files in lib/rest/static/dereferenced.\n')
const dereferencedSchemas = schemas.reduce((acc, filename) => { const dereferencedSchemas = schemas.reduce((acc, filename) => {
const schema = require(path.join(dereferencedPath, filename)) const schema = JSON.parse(fs.readFileSync(path.join(dereferencedPath, filename)))
const key = filename.replace('.deref.json', '') const key = filename.replace('.deref.json', '')
return { ...acc, [key]: schema } return { ...acc, [key]: schema }
}, {}) }, {})

Просмотреть файл

@ -6,6 +6,7 @@ const httpStatusCodes = require('http-status-code')
const renderContent = require('../../../lib/render-content') const renderContent = require('../../../lib/render-content')
const createCodeSamples = require('./create-code-samples') const createCodeSamples = require('./create-code-samples')
const Ajv = require('ajv') const Ajv = require('ajv')
const operationSchema = require('./operation-schema')
// titles that can't be derived by sentence-casing the ID // titles that can't be derived by sentence-casing the ID
const categoryTitles = { scim: 'SCIM' } const categoryTitles = { scim: 'SCIM' }
@ -40,7 +41,7 @@ module.exports = class Operation {
} }
get schema () { get schema () {
return require('./operation-schema') return operationSchema
} }
async process () { async process () {

Просмотреть файл

@ -1,3 +1,5 @@
const fs = require('fs')
const path = require('path')
const previewsJson = require('../../lib/graphql/static/previews') const previewsJson = require('../../lib/graphql/static/previews')
const upcomingChangesJson = require('../../lib/graphql/static/upcoming-changes') const upcomingChangesJson = require('../../lib/graphql/static/upcoming-changes')
const prerenderedObjectsJson = require('../../lib/graphql/static/prerendered-objects') const prerenderedObjectsJson = require('../../lib/graphql/static/prerendered-objects')
@ -20,7 +22,7 @@ describe('graphql json files', () => {
test('schemas object validation', () => { test('schemas object validation', () => {
graphqlVersions.forEach(version => { graphqlVersions.forEach(version => {
const schemaJsonPerVersion = require(`../../lib/graphql/static/schema-${version}`) const schemaJsonPerVersion = JSON.parse(fs.readFileSync(path.join(process.cwd(), '/lib/graphql/static/schema-' + version + '.json')))
// all graphql types are arrays except for queries // all graphql types are arrays except for queries
graphqlTypes graphqlTypes
.filter(type => type !== 'queries') .filter(type => type !== 'queries')