Skip to content

Commit 9d7b659

Browse files
authored
repo sync
2 parents c664330 + 93db306 commit 9d7b659

File tree

3 files changed

+101
-8
lines changed

3 files changed

+101
-8
lines changed

script/README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ The `ignore` array is for client-side or build-time stuff that doesn't get `requ
5959

6060
### [`check-english-links.js`](check-english-links.js)
6161

62-
This script runs once per day via a scheduled GitHub Action to check all links in English content, not including deprecated Enterprise Server content. It opens an issue if it finds broken links. To exclude a link, add it to `lib/excluded-links.js`.
62+
This script runs once per day via a scheduled GitHub Action to check all links in English content, not including deprecated Enterprise Server content. It opens an issue if it finds broken links. To exclude a link path, add it to `lib/excluded-links.js`.
6363

6464
---
6565

@@ -134,7 +134,14 @@ Run this script after an Enterprise deprecation to remove Liquid statements and
134134
---
135135

136136

137-
### [`enterprise-server-releases/create-webhooks-for-new-version.js`](enterprise-server-releases/create-webhooks-for-new-version.js)
137+
### [`enterprise-server-releases/create-graphql-files.js`](enterprise-server-releases/create-graphql-files.js)
138+
139+
This script creates the static GraphQL files for a new version.
140+
141+
---
142+
143+
144+
### [`enterprise-server-releases/create-webhook-files.js`](enterprise-server-releases/create-webhook-files.js)
138145

139146
This script creates new static webhook payload files for a new version.
140147

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/usr/bin/env node
2+
3+
const fs = require('fs')
4+
const path = require('path')
5+
const program = require('commander')
6+
const allVersions = require('../../lib/all-versions')
7+
const graphqlDir = path.join(process.cwd(), 'lib/graphql/static')
8+
9+
// [start-readme]
10+
//
11+
// This script creates the static GraphQL files for a new version.
12+
//
13+
// [end-readme]
14+
15+
program
16+
.description('Create GraphQL files in lib/graphql/static based on an existing version.')
17+
.option('-n, --newVersion <version>', 'The version to copy the files to. Must be in <plan@release> format.')
18+
.option('-o, --oldVersion <version>', 'The version to copy the files from. Must be in <plan@release> format.')
19+
.parse(process.argv)
20+
21+
const newVersion = program.newVersion
22+
const oldVersion = program.oldVersion
23+
24+
if (!(newVersion && oldVersion)) {
25+
console.log('Error! You must provide --newVersion and --oldVersion.')
26+
process.exit(1)
27+
}
28+
29+
if (!(Object.keys(allVersions).includes(newVersion) && Object.keys(allVersions).includes(oldVersion))) {
30+
console.log('Error! You must provide the full name of a currently supported version, e.g., [email protected].')
31+
process.exit(1)
32+
}
33+
34+
const newVersionId = allVersions[newVersion].miscVersionName
35+
const oldVersionId = allVersions[oldVersion].miscVersionName
36+
37+
// 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+
fs.copyFileSync(oldSchemaFile, newSchemaFile)
41+
42+
// check that it worked
43+
if (!fs.existsSync(newSchemaFile)) {
44+
console.log(`Error! Can't find ${newSchemaFile}.`)
45+
process.exit(1)
46+
}
47+
48+
// 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')
52+
53+
const previews = require(previewsFile)
54+
const changes = require(changesFile)
55+
const objects = require(objectsFile)
56+
57+
previews[newVersionId] = previews[oldVersionId]
58+
changes[newVersionId] = changes[oldVersionId]
59+
objects[newVersionId] = objects[oldVersionId]
60+
61+
// check that it worked
62+
if (!Object.keys(previews).includes(newVersionId)) {
63+
console.log(`Error! Can't find ${newVersionId} in ${previewsFile}.`)
64+
process.exit(1)
65+
}
66+
67+
if (!Object.keys(changes).includes(newVersionId)) {
68+
console.log(`Error! Can't find ${newVersionId} in ${changesFile}.`)
69+
process.exit(1)
70+
}
71+
72+
if (!Object.keys(objects).includes(newVersionId)) {
73+
console.log(`Error! Can't find ${newVersionId} in ${objectsFile}.`)
74+
process.exit(1)
75+
}
76+
77+
// write the new files
78+
fs.writeFileSync(previewsFile, JSON.stringify(previews, null, 2))
79+
fs.writeFileSync(changesFile, JSON.stringify(changes, null, 2))
80+
fs.writeFileSync(objectsFile, JSON.stringify(objects, null, 2))
81+
82+
// print success message
83+
console.log(`Done! Copied ${oldVersion} GraphQL files to ${newVersion} files.`)

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const mkdirp = require('mkdirp').sync
55
const path = require('path')
66
const program = require('commander')
77
const allVersions = require('../../lib/all-versions')
8+
const payloadsDir = 'lib/webhooks/static'
89

910
// [start-readme]
1011
//
@@ -18,20 +19,22 @@ program
1819
.option('-o, --oldVersion <version>', 'The version to copy the payloads from. Must be in <plan@release> format.')
1920
.parse(process.argv)
2021

21-
if (!(program.newVersion && program.oldVersion)) {
22+
const newVersion = program.newVersion
23+
const oldVersion = program.oldVersion
24+
25+
if (!(newVersion && oldVersion)) {
2226
console.log('Error! You must provide --newVersion and --oldVersion.')
2327
process.exit(1)
2428
}
2529

26-
if (!(Object.keys(allVersions).includes(program.newVersion) && Object.keys(allVersions).includes(program.oldVersion))) {
27-
console.log('Error! You must provide the full name of a supported version, e.g., [email protected].')
30+
if (!(Object.keys(allVersions).includes(newVersion) && Object.keys(allVersions).includes(oldVersion))) {
31+
console.log('Error! You must provide the full name of a currently supported version, e.g., [email protected].')
2832
process.exit(1)
2933
}
3034

31-
const newVersionDirName = allVersions[program.newVersion].miscVersionName
32-
const oldVersionDirName = allVersions[program.oldVersion].miscVersionName
35+
const newVersionDirName = allVersions[newVersion].miscVersionName
36+
const oldVersionDirName = allVersions[oldVersion].miscVersionName
3337

34-
const payloadsDir = 'lib/webhooks/static'
3538
const srcDir = path.join(payloadsDir, oldVersionDirName)
3639
const destDir = path.join(payloadsDir, newVersionDirName)
3740

0 commit comments

Comments
 (0)