Remove remaining JSON requires (#20110)
* Remove remaining JSON requires * Lint * Update feature-flags.js
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
const featureFlags = require('../feature-flags')
|
const readJsonFile = require('./read-json-file')
|
||||||
|
const featureFlags = readJsonFile('./feature-flags.json')
|
||||||
|
|
||||||
// add feature flags as environment variables
|
// add feature flags as environment variables
|
||||||
Object.entries(featureFlags).forEach(([feature, value]) => {
|
Object.entries(featureFlags).forEach(([feature, value]) => {
|
||||||
|
|||||||
14
lib/read-json-file.js
Normal file
14
lib/read-json-file.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
const fs = require('fs')
|
||||||
|
const path = require('path')
|
||||||
|
|
||||||
|
module.exports = function readJsonFile (xpath) {
|
||||||
|
return JSON.parse(
|
||||||
|
fs.readFileSync(
|
||||||
|
path.join(
|
||||||
|
process.cwd(),
|
||||||
|
xpath
|
||||||
|
),
|
||||||
|
'utf8'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
const developerRedirects = require('../redirects/static/developer')
|
const readJsonFile = require('../read-json-file')
|
||||||
|
const developerRedirects = readJsonFile('./lib/redirects/static/developer.json')
|
||||||
const { latest } = require('../../lib/enterprise-server-releases')
|
const { latest } = require('../../lib/enterprise-server-releases')
|
||||||
const latestDevRedirects = {}
|
const latestDevRedirects = {}
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
const path = require('path')
|
const path = require('path')
|
||||||
const visit = require('unist-util-visit')
|
const visit = require('unist-util-visit')
|
||||||
const externalRedirects = Object.keys(require('../../redirects/external-sites'))
|
|
||||||
const { getPathWithoutLanguage, getVersionStringFromPath } = require('../../path-utils')
|
const { getPathWithoutLanguage, getVersionStringFromPath } = require('../../path-utils')
|
||||||
const { getNewVersionedPath } = require('../../old-versions-utils')
|
const { getNewVersionedPath } = require('../../old-versions-utils')
|
||||||
const patterns = require('../../patterns')
|
const patterns = require('../../patterns')
|
||||||
const { deprecated, latest } = require('../../enterprise-server-releases')
|
const { deprecated, latest } = require('../../enterprise-server-releases')
|
||||||
const nonEnterpriseDefaultVersion = require('../../non-enterprise-default-version')
|
const nonEnterpriseDefaultVersion = require('../../non-enterprise-default-version')
|
||||||
const allVersions = require('../../all-versions')
|
const allVersions = require('../../all-versions')
|
||||||
|
const removeFPTFromPath = require('../../remove-fpt-from-path')
|
||||||
const supportedVersions = Object.keys(allVersions)
|
const supportedVersions = Object.keys(allVersions)
|
||||||
const supportedPlans = Object.values(allVersions).map(v => v.plan)
|
const supportedPlans = Object.values(allVersions).map(v => v.plan)
|
||||||
const removeFPTFromPath = require('../../remove-fpt-from-path')
|
const readJsonFile = require('../../read-json-file')
|
||||||
|
const externalRedirects = Object.keys(readJsonFile('./lib/redirects/external-sites.json'))
|
||||||
|
|
||||||
|
|
||||||
// Matches any <a> tags with an href that starts with `/`
|
// Matches any <a> tags with an href that starts with `/`
|
||||||
const matcher = node => (
|
const matcher = node => (
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const externalRedirects = Object.keys(require('./redirects/external-sites'))
|
|
||||||
const { getPathWithoutLanguage, getVersionStringFromPath } = require('./path-utils')
|
const { getPathWithoutLanguage, getVersionStringFromPath } = require('./path-utils')
|
||||||
const { getNewVersionedPath } = require('./old-versions-utils')
|
const { getNewVersionedPath } = require('./old-versions-utils')
|
||||||
const patterns = require('./patterns')
|
const patterns = require('./patterns')
|
||||||
@@ -10,6 +9,8 @@ const allVersions = require('./all-versions')
|
|||||||
const supportedVersions = Object.keys(allVersions)
|
const supportedVersions = Object.keys(allVersions)
|
||||||
const supportedPlans = Object.values(allVersions).map(v => v.plan)
|
const supportedPlans = Object.values(allVersions).map(v => v.plan)
|
||||||
const removeFPTFromPath = require('./remove-fpt-from-path')
|
const removeFPTFromPath = require('./remove-fpt-from-path')
|
||||||
|
const readJsonFile = require('./read-json-file')
|
||||||
|
const externalRedirects = readJsonFile('./lib/redirects/external-sites.json')
|
||||||
|
|
||||||
// Content authors write links like `/some/article/path`, but they need to be
|
// Content authors write links like `/some/article/path`, but they need to be
|
||||||
// rewritten on the fly to match the current language and page version
|
// rewritten on the fly to match the current language and page version
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const algoliasearch = require('algoliasearch')
|
const algoliasearch = require('algoliasearch')
|
||||||
const { get } = require('lodash')
|
const { get } = require('lodash')
|
||||||
const { namePrefix } = require('./config')
|
const { namePrefix } = require('./config.js')
|
||||||
|
|
||||||
// https://www.algolia.com/apps/ZI5KPY1HBE/dashboard
|
// https://www.algolia.com/apps/ZI5KPY1HBE/dashboard
|
||||||
// This API key is public. There's also a private API key for writing to the Algolia API
|
// This API key is public. There's also a private API key for writing to the Algolia API
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ require('lunr-languages/lunr.pt')(lunr)
|
|||||||
require('lunr-languages/lunr.de')(lunr)
|
require('lunr-languages/lunr.de')(lunr)
|
||||||
const { get } = require('lodash')
|
const { get } = require('lodash')
|
||||||
const readFileAsync = require('../readfile-async')
|
const readFileAsync = require('../readfile-async')
|
||||||
const { namePrefix } = require('./config')
|
const { namePrefix } = require('./config.js')
|
||||||
const { decompress } = require('./compress')
|
const { decompress } = require('./compress')
|
||||||
|
|
||||||
const LUNR_DIR = './indexes'
|
const LUNR_DIR = './indexes'
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ const patterns = require('../lib/patterns')
|
|||||||
const versionSatisfiesRange = require('../lib/version-satisfies-range')
|
const versionSatisfiesRange = require('../lib/version-satisfies-range')
|
||||||
const isArchivedVersion = require('../lib/is-archived-version')
|
const isArchivedVersion = require('../lib/is-archived-version')
|
||||||
const got = require('got')
|
const got = require('got')
|
||||||
const archvivedRedirects = require('../lib/redirects/static/archived-redirects-from-213-to-217')
|
const readJsonFile = require('../lib/read-json-file')
|
||||||
const archivedFrontmatterFallbacks = require('../lib/redirects/static/archived-frontmatter-fallbacks')
|
const archvivedRedirects = readJsonFile('./lib/redirects/static/archived-redirects-from-213-to-217.json')
|
||||||
|
const archivedFrontmatterFallbacks = readJsonFile('./lib/redirects/static/archived-frontmatter-fallbacks.json')
|
||||||
|
|
||||||
// This module handles requests for deprecated GitHub Enterprise versions
|
// This module handles requests for deprecated GitHub Enterprise versions
|
||||||
// by routing them to static content in help-docs-archived-enterprise-versions
|
// by routing them to static content in help-docs-archived-enterprise-versions
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ const {
|
|||||||
} = require('../lib/path-utils')
|
} = require('../lib/path-utils')
|
||||||
const productNames = require('../lib/product-names')
|
const productNames = require('../lib/product-names')
|
||||||
const warmServer = require('../lib/warm-server')
|
const warmServer = require('../lib/warm-server')
|
||||||
const featureFlags = Object.keys(require('../feature-flags'))
|
const readJsonFile = require('../lib/read-json-file')
|
||||||
|
const featureFlags = Object.keys(readJsonFile('./feature-flags.json'))
|
||||||
const builtAssets = require('../lib/built-asset-urls')
|
const builtAssets = require('../lib/built-asset-urls')
|
||||||
const searchVersions = require('../lib/search/versions')
|
const searchVersions = require('../lib/search/versions')
|
||||||
const nonEnterpriseDefaultVersion = require('../lib/non-enterprise-default-version')
|
const nonEnterpriseDefaultVersion = require('../lib/non-enterprise-default-version')
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const previews = require('../../lib/graphql/static/previews')
|
const readJsonFile = require('../../lib/read-json-file')
|
||||||
const upcomingChanges = require('../../lib/graphql/static/upcoming-changes')
|
const previews = readJsonFile('./lib/graphql/static/previews.json')
|
||||||
const changelog = require('../../lib/graphql/static/changelog')
|
const upcomingChanges = readJsonFile('./lib/graphql/static/upcoming-changes.json')
|
||||||
const prerenderedObjects = require('../../lib/graphql/static/prerendered-objects')
|
const changelog = readJsonFile('./lib/graphql/static/changelog.json')
|
||||||
const prerenderedInputObjects = require('../../lib/graphql/static/prerendered-input-objects')
|
const prerenderedObjects = readJsonFile('./lib/graphql/static/prerendered-objects.json')
|
||||||
|
const prerenderedInputObjects = readJsonFile('./lib/graphql/static/prerendered-input-objects.json')
|
||||||
const allVersions = require('../../lib/all-versions')
|
const allVersions = require('../../lib/all-versions')
|
||||||
|
|
||||||
const explorerUrl = process.env.NODE_ENV === 'production'
|
const explorerUrl = process.env.NODE_ENV === 'production'
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
const externalSites = require('../../lib/redirects/external-sites')
|
const readJsonFile = require('../../lib/read-json-file')
|
||||||
|
const externalSites = readJsonFile('./lib/redirects/external-sites.json')
|
||||||
|
|
||||||
// blanket redirects to external websites
|
// blanket redirects to external websites
|
||||||
module.exports = function externalRedirects (req, res, next) {
|
module.exports = function externalRedirects (req, res, next) {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ const { execSync } = require('child_process')
|
|||||||
const graphqlDataDir = path.join(process.cwd(), 'data/graphql')
|
const graphqlDataDir = path.join(process.cwd(), 'data/graphql')
|
||||||
const graphqlStaticDir = path.join(process.cwd(), 'lib/graphql/static')
|
const graphqlStaticDir = path.join(process.cwd(), 'lib/graphql/static')
|
||||||
const { getContents, listMatchingRefs } = require('../helpers/git-utils')
|
const { getContents, listMatchingRefs } = require('../helpers/git-utils')
|
||||||
const dataFilenames = require('./utils/data-filenames')
|
const dataFilenames = JSON.parse(fs.readFileSync('./utils/data-filenames.json'))
|
||||||
const allVersions = require('../../lib/all-versions')
|
const allVersions = require('../../lib/all-versions')
|
||||||
const processPreviews = require('./utils/process-previews')
|
const processPreviews = require('./utils/process-previews')
|
||||||
const processUpcomingChanges = require('./utils/process-upcoming-changes')
|
const processUpcomingChanges = require('./utils/process-upcoming-changes')
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
const { sortBy } = require('lodash')
|
const { sortBy } = require('lodash')
|
||||||
const { parse, buildASTSchema } = require('graphql')
|
const { parse, buildASTSchema } = require('graphql')
|
||||||
const helpers = require('./schema-helpers')
|
const helpers = require('./schema-helpers')
|
||||||
|
const fs = require('fs')
|
||||||
|
|
||||||
const externalScalars = require('../../../lib/graphql/non-schema-scalars')
|
const externalScalars = JSON.parse(fs.readFileSync('../../../lib/graphql/non-schema-scalars.json'))
|
||||||
.map(scalar => {
|
.map(scalar => {
|
||||||
scalar.id = helpers.getId(scalar.name)
|
scalar.id = helpers.getId(scalar.name)
|
||||||
scalar.href = helpers.getFullLink('scalars', scalar.id)
|
scalar.href = helpers.getFullLink('scalars', scalar.id)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
const renderContent = require('../../../lib/render-content')
|
const renderContent = require('../../../lib/render-content')
|
||||||
const graphqlTypes = require('../../../lib/graphql/types')
|
const fs = require('fs')
|
||||||
|
const graphqlTypes = JSON.parse(fs.readFileSync('../../../lib/graphql/types.json'))
|
||||||
const {
|
const {
|
||||||
isScalarType,
|
isScalarType,
|
||||||
isObjectType,
|
isObjectType,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ const path = require('path')
|
|||||||
const sleep = require('await-sleep')
|
const sleep = require('await-sleep')
|
||||||
const { latest } = require('../../lib/enterprise-server-releases')
|
const { latest } = require('../../lib/enterprise-server-releases')
|
||||||
const languages = require('../../lib/languages')
|
const languages = require('../../lib/languages')
|
||||||
const featureFlags = JSON.parse(fs.readFileSync(path.join(process.cwd(), '/feature-flags.json')))
|
const featureFlags = JSON.parse(fs.readFileSync(path.join(process.cwd(), './feature-flags.json')))
|
||||||
|
|
||||||
describe('homepage', () => {
|
describe('homepage', () => {
|
||||||
jest.setTimeout(60 * 1000)
|
jest.setTimeout(60 * 1000)
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const previewsJson = require('../../lib/graphql/static/previews')
|
const readJsonFile = require('../../lib/read-json-file')
|
||||||
const upcomingChangesJson = require('../../lib/graphql/static/upcoming-changes')
|
const previewsJson = readJsonFile('./lib/graphql/static/previews.json')
|
||||||
const prerenderedObjectsJson = require('../../lib/graphql/static/prerendered-objects')
|
const upcomingChangesJson = readJsonFile('./lib/graphql/static/upcoming-changes.json')
|
||||||
|
const prerenderedObjectsJson = readJsonFile('./lib/graphql/static/prerendered-objects.json')
|
||||||
const { schemaValidator, previewsValidator, upcomingChangesValidator } = require('../../lib/graphql/validator')
|
const { schemaValidator, previewsValidator, upcomingChangesValidator } = require('../../lib/graphql/validator')
|
||||||
const revalidator = require('revalidator')
|
const revalidator = require('revalidator')
|
||||||
const allVersions = Object.values(require('../../lib/all-versions'))
|
const allVersions = Object.values(require('../../lib/all-versions'))
|
||||||
const graphqlVersions = allVersions.map(v => v.miscVersionName)
|
const graphqlVersions = allVersions.map(v => v.miscVersionName)
|
||||||
const graphqlTypes = require('../../lib/graphql/types').map(t => t.kind)
|
const graphqlTypes = readJsonFile('./lib/graphql/types.json').map(t => t.kind)
|
||||||
|
|
||||||
describe('graphql json files', () => {
|
describe('graphql json files', () => {
|
||||||
jest.setTimeout(3 * 60 * 1000)
|
jest.setTimeout(3 * 60 * 1000)
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ const { createChangelogEntry, cleanPreviewTitle, previewAnchor, prependDatedEntr
|
|||||||
const fs = require('fs').promises
|
const fs = require('fs').promises
|
||||||
const MockDate = require('mockdate')
|
const MockDate = require('mockdate')
|
||||||
const readFileAsync = require('../../lib/readfile-async')
|
const readFileAsync = require('../../lib/readfile-async')
|
||||||
const expectedChangelogEntry = require('../fixtures/changelog-entry')
|
const readJsonFile = require('../../lib/read-json-file')
|
||||||
const expectedUpdatedChangelogFile = require('../fixtures/updated-changelog-file')
|
const expectedChangelogEntry = readJsonFile('./tests/fixtures/changelog-entry.json')
|
||||||
|
const expectedUpdatedChangelogFile = readJsonFile('./tests/fixtures/updated-changelog-file.json')
|
||||||
|
|
||||||
describe('creating a changelog from old schema and new schema', () => {
|
describe('creating a changelog from old schema and new schema', () => {
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
|||||||
@@ -2,9 +2,10 @@ const path = require('path')
|
|||||||
const { eachOfLimit } = require('async')
|
const { eachOfLimit } = require('async')
|
||||||
const enterpriseServerReleases = require('../../lib/enterprise-server-releases')
|
const enterpriseServerReleases = require('../../lib/enterprise-server-releases')
|
||||||
const { get } = require('../helpers/supertest')
|
const { get } = require('../helpers/supertest')
|
||||||
const restRedirectFixtures = require('../fixtures/rest-redirects')
|
const readJsonFile = require('../../lib/read-json-file')
|
||||||
const graphqlRedirectFixtures = require('../fixtures/graphql-redirects')
|
const restRedirectFixtures = readJsonFile('./tests/fixtures/rest-redirects.json')
|
||||||
const developerRedirectFixtures = require('../fixtures/developer-redirects')
|
const graphqlRedirectFixtures = readJsonFile('./tests/fixtures/graphql-redirects.json')
|
||||||
|
const developerRedirectFixtures = readJsonFile('./tests/fixtures/developer-redirects.json')
|
||||||
|
|
||||||
const MAX_CONCURRENT_REQUESTS = 50
|
const MAX_CONCURRENT_REQUESTS = 50
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
const fs = require('fs')
|
|
||||||
const path = require('path')
|
|
||||||
const { head } = require('../helpers/supertest')
|
const { head } = require('../helpers/supertest')
|
||||||
const topOldDeveloperSitePaths = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'tests/fixtures/top-old-developer-site-paths.json')))
|
const readJsonFile = require('../../lib/read-json-file')
|
||||||
|
const topOldDeveloperSitePaths = readJsonFile('tests/fixtures/top-old-developer-site-paths.json')
|
||||||
|
|
||||||
jest.useFakeTimers()
|
jest.useFakeTimers()
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
require('../../lib/feature-flags')
|
require('../../lib/feature-flags')
|
||||||
const ffs = require('../../feature-flags')
|
const readJsonFile = require('../../lib/read-json-file')
|
||||||
|
const ffs = readJsonFile('./feature-flags.json')
|
||||||
|
|
||||||
describe('feature flags', () => {
|
describe('feature flags', () => {
|
||||||
Object.keys(ffs).forEach(featureName => {
|
Object.keys(ffs).forEach(featureName => {
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
const path = require('path')
|
const path = require('path')
|
||||||
const cheerio = require('cheerio')
|
const cheerio = require('cheerio')
|
||||||
const Page = require('../../lib/page')
|
const Page = require('../../lib/page')
|
||||||
const prerenderedObjects = require('../../lib/graphql/static/prerendered-objects')
|
const readJsonFile = require('../../lib/read-json-file')
|
||||||
|
const prerenderedObjects = readJsonFile('./lib/graphql/static/prerendered-objects.json')
|
||||||
const allVersions = require('../../lib/all-versions')
|
const allVersions = require('../../lib/all-versions')
|
||||||
const enterpriseServerReleases = require('../../lib/enterprise-server-releases')
|
const enterpriseServerReleases = require('../../lib/enterprise-server-releases')
|
||||||
const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version')
|
const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version')
|
||||||
|
|||||||
Reference in New Issue
Block a user