Skip to content

Commit 6223032

Browse files
authored
Merge pull request #16618 from github/update-enterprise-graphql-script
Update GraphQL Enterprise release script
2 parents 6a833ac + 2ea2ad1 commit 6223032

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

script/enterprise-server-releases/create-graphql-files.js

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
const fs = require('fs')
44
const path = require('path')
55
const program = require('commander')
6+
const mkdirp = require('mkdirp').sync
67
const allVersions = require('../../lib/all-versions')
7-
const graphqlDir = path.join(process.cwd(), 'lib/graphql/static')
8+
const graphqlStaticDir = path.join(process.cwd(), 'lib/graphql/static')
9+
const graphqlDataDir = path.join(process.cwd(), 'data/graphql')
810

911
// [start-readme]
1012
//
@@ -35,8 +37,8 @@ const newVersionId = allVersions[newVersion].miscVersionName
3537
const oldVersionId = allVersions[oldVersion].miscVersionName
3638

3739
// copy the schema file wholesale (there are separate schema files per version)
38-
const newSchemaFile = path.join(graphqlDir, `schema-${newVersionId}.json`)
39-
const oldSchemaFile = path.join(graphqlDir, `schema-${oldVersionId}.json`)
40+
const newSchemaFile = path.join(graphqlStaticDir, `schema-${newVersionId}.json`)
41+
const oldSchemaFile = path.join(graphqlStaticDir, `schema-${oldVersionId}.json`)
4042
fs.copyFileSync(oldSchemaFile, newSchemaFile)
4143

4244
// check that it worked
@@ -46,9 +48,9 @@ if (!fs.existsSync(newSchemaFile)) {
4648
}
4749

4850
// the other files are objects with vers3091iuions as keys, so we need to require them
49-
const previewsFile = path.join(graphqlDir, 'previews.json')
50-
const changesFile = path.join(graphqlDir, 'upcoming-changes.json')
51-
const objectsFile = path.join(graphqlDir, 'prerendered-objects.json')
51+
const previewsFile = path.join(graphqlStaticDir, 'previews.json')
52+
const changesFile = path.join(graphqlStaticDir, 'upcoming-changes.json')
53+
const objectsFile = path.join(graphqlStaticDir, 'prerendered-objects.json')
5254

5355
const previews = require(previewsFile)
5456
const changes = require(changesFile)
@@ -79,5 +81,28 @@ fs.writeFileSync(previewsFile, JSON.stringify(previews, null, 2))
7981
fs.writeFileSync(changesFile, JSON.stringify(changes, null, 2))
8082
fs.writeFileSync(objectsFile, JSON.stringify(objects, null, 2))
8183

84+
// now create the new version directory in data/graphql
85+
const srcDir = path.join(graphqlDataDir, oldVersionId)
86+
const destDir = path.join(graphqlDataDir, newVersionId)
87+
mkdirp(destDir)
88+
89+
// copy the files
90+
fs.readdirSync(srcDir).forEach(file => {
91+
const srcFile = path.join(srcDir, file)
92+
const destFile = path.join(destDir, file)
93+
fs.copyFileSync(srcFile, destFile)
94+
})
95+
96+
// check that it worked
97+
if (!fs.existsSync(destDir)) {
98+
console.log(`Error! A new directory was not successfully created at ${destDir}.`)
99+
process.exit(1)
100+
}
101+
102+
if (!fs.readdirSync(destDir).length) {
103+
console.log(`Error! The directory created at ${destDir} is empty.`)
104+
process.exit(1)
105+
}
106+
82107
// print success message
83108
console.log(`Done! Copied ${oldVersion} GraphQL files to ${newVersion} files.`)

0 commit comments

Comments
 (0)