From 2ea2ad130fa5d55073fecb5b098218bfcf3a1845 Mon Sep 17 00:00:00 2001 From: Sarah Schneider Date: Tue, 24 Nov 2020 14:45:29 -0500 Subject: [PATCH] add data/graphql copying step --- .../create-graphql-files.js | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/script/enterprise-server-releases/create-graphql-files.js b/script/enterprise-server-releases/create-graphql-files.js index 1688c016cbf0..80c911a0f531 100755 --- a/script/enterprise-server-releases/create-graphql-files.js +++ b/script/enterprise-server-releases/create-graphql-files.js @@ -3,8 +3,10 @@ const fs = require('fs') const path = require('path') const program = require('commander') +const mkdirp = require('mkdirp').sync const allVersions = require('../../lib/all-versions') -const graphqlDir = path.join(process.cwd(), 'lib/graphql/static') +const graphqlStaticDir = path.join(process.cwd(), 'lib/graphql/static') +const graphqlDataDir = path.join(process.cwd(), 'data/graphql') // [start-readme] // @@ -35,8 +37,8 @@ const newVersionId = allVersions[newVersion].miscVersionName const oldVersionId = allVersions[oldVersion].miscVersionName // copy the schema file wholesale (there are separate schema files per version) -const newSchemaFile = path.join(graphqlDir, `schema-${newVersionId}.json`) -const oldSchemaFile = path.join(graphqlDir, `schema-${oldVersionId}.json`) +const newSchemaFile = path.join(graphqlStaticDir, `schema-${newVersionId}.json`) +const oldSchemaFile = path.join(graphqlStaticDir, `schema-${oldVersionId}.json`) fs.copyFileSync(oldSchemaFile, newSchemaFile) // check that it worked @@ -46,9 +48,9 @@ if (!fs.existsSync(newSchemaFile)) { } // the other files are objects with vers3091iuions as keys, so we need to require them -const previewsFile = path.join(graphqlDir, 'previews.json') -const changesFile = path.join(graphqlDir, 'upcoming-changes.json') -const objectsFile = path.join(graphqlDir, 'prerendered-objects.json') +const previewsFile = path.join(graphqlStaticDir, 'previews.json') +const changesFile = path.join(graphqlStaticDir, 'upcoming-changes.json') +const objectsFile = path.join(graphqlStaticDir, 'prerendered-objects.json') const previews = require(previewsFile) const changes = require(changesFile) @@ -79,5 +81,28 @@ fs.writeFileSync(previewsFile, JSON.stringify(previews, null, 2)) fs.writeFileSync(changesFile, JSON.stringify(changes, null, 2)) fs.writeFileSync(objectsFile, JSON.stringify(objects, null, 2)) +// now create the new version directory in data/graphql +const srcDir = path.join(graphqlDataDir, oldVersionId) +const destDir = path.join(graphqlDataDir, newVersionId) +mkdirp(destDir) + +// copy the files +fs.readdirSync(srcDir).forEach(file => { + const srcFile = path.join(srcDir, file) + const destFile = path.join(destDir, file) + fs.copyFileSync(srcFile, destFile) +}) + +// check that it worked +if (!fs.existsSync(destDir)) { + console.log(`Error! A new directory was not successfully created at ${destDir}.`) + process.exit(1) +} + +if (!fs.readdirSync(destDir).length) { + console.log(`Error! The directory created at ${destDir} is empty.`) + process.exit(1) +} + // print success message console.log(`Done! Copied ${oldVersion} GraphQL files to ${newVersion} files.`)