11const { diff, ChangeType } = require ( '@graphql-inspector/core' )
22const { loadSchema } = require ( '@graphql-tools/load' )
33const fs = require ( 'fs' )
4- const yaml = require ( 'js-yaml' )
54
65/**
76 * Tag `changelogEntry` with `date: YYYY-mm-dd`, then prepend it to the JSON
@@ -10,7 +9,7 @@ const yaml = require('js-yaml')
109 * @param {string } targetPath
1110 * @return {void }
1211 */
13- function prependDatedEntry ( changelogEntry , targetPath ) {
12+ function prependDatedEntry ( changelogEntry , targetPath ) {
1413 // Build a `yyyy-mm-dd`-formatted date string
1514 // and tag the changelog entry with it
1615 const today = new Date ( )
@@ -39,7 +38,7 @@ function prependDatedEntry(changelogEntry, targetPath) {
3938 * @param {Array<object> } [newUpcomingChanges]
4039 * @return {object? }
4140 */
42- async function createChangelogEntry ( oldSchemaString , newSchemaString , previews , oldUpcomingChanges , newUpcomingChanges ) {
41+ async function createChangelogEntry ( oldSchemaString , newSchemaString , previews , oldUpcomingChanges , newUpcomingChanges ) {
4342 // Create schema objects out of the strings
4443 const oldSchema = await loadSchema ( oldSchemaString )
4544 const newSchema = await loadSchema ( newSchemaString )
@@ -53,7 +52,7 @@ async function createChangelogEntry(oldSchemaString, newSchemaString, previews,
5352 } else if ( CHANGES_TO_IGNORE . includes ( change . type ) ) {
5453 // Do nothing
5554 } else {
56- throw " This change type should be added to CHANGES_TO_REPORT or CHANGES_TO_IGNORE: " + change . type
55+ throw new Error ( ' This change type should be added to CHANGES_TO_REPORT or CHANGES_TO_IGNORE: ' + change . type )
5756 }
5857 } )
5958
@@ -63,9 +62,9 @@ async function createChangelogEntry(oldSchemaString, newSchemaString, previews,
6362 // Manually check each of `newUpcomingChanges` for an equivalent entry
6463 // in `oldUpcomingChanges`.
6564 return ! oldUpcomingChanges . find ( function ( oldChange ) {
66- return ( oldChange . location == change . location &&
67- oldChange . date == change . date &&
68- oldChange . description == change . description
65+ return ( oldChange . location === change . location &&
66+ oldChange . date === change . date &&
67+ oldChange . description === change . description
6968 )
7069 } )
7170 } )
@@ -75,7 +74,7 @@ async function createChangelogEntry(oldSchemaString, newSchemaString, previews,
7574 const changelogEntry = {
7675 schemaChanges : [ ] ,
7776 previewChanges : [ ] ,
78- upcomingChanges : [ ] ,
77+ upcomingChanges : [ ]
7978 }
8079
8180 const schemaChange = {
@@ -86,23 +85,23 @@ async function createChangelogEntry(oldSchemaString, newSchemaString, previews,
8685 changelogEntry . schemaChanges . push ( schemaChange )
8786
8887 for ( const previewTitle in previewChangesToReport ) {
89- let previewChanges = previewChangesToReport [ previewTitle ]
90- let cleanTitle = cleanPreviewTitle ( previewTitle )
91- let entryTitle = " The [" + cleanTitle + " ](/graphql/overview/schema-previews#" + previewAnchor ( cleanTitle ) + " ) includes these changes:"
88+ const previewChanges = previewChangesToReport [ previewTitle ]
89+ const cleanTitle = cleanPreviewTitle ( previewTitle )
90+ const entryTitle = ' The [' + cleanTitle + ' ](/graphql/overview/schema-previews#' + previewAnchor ( cleanTitle ) + ' ) includes these changes:'
9291 changelogEntry . previewChanges . push ( {
9392 title : entryTitle ,
94- changes : cleanMessagesFromChanges ( previewChanges . changes ) ,
93+ changes : cleanMessagesFromChanges ( previewChanges . changes )
9594 } )
9695 }
9796
9897 if ( addedUpcomingChanges . length > 0 ) {
9998 changelogEntry . upcomingChanges . push ( {
100- title : " The following changes will be made to the schema:" ,
99+ title : ' The following changes will be made to the schema:' ,
101100 changes : addedUpcomingChanges . map ( function ( change ) {
102101 const location = change . location
103102 const description = change . description
104- const date = change . date . split ( "T" ) [ 0 ]
105- return " On member `" + location + "`:" + description + " **Effective " + date + " **."
103+ const date = change . date . split ( 'T' ) [ 0 ]
104+ return ' On member `' + location + '`:' + description + ' **Effective ' + date + ' **.'
106105 } )
107106 } )
108107 }
@@ -119,13 +118,13 @@ async function createChangelogEntry(oldSchemaString, newSchemaString, previews,
119118 * @param {string } title
120119 * @return {string }
121120 */
122- function cleanPreviewTitle ( title ) {
123- if ( title == " UpdateRefsPreview" ) {
124- title = " Update refs preview"
125- } else if ( title == " MergeInfoPreview" ) {
126- title = " Merge info preview"
127- } else if ( ! title . endsWith ( " preview" ) ) {
128- title = title + " preview"
121+ function cleanPreviewTitle ( title ) {
122+ if ( title === ' UpdateRefsPreview' ) {
123+ title = ' Update refs preview'
124+ } else if ( title === ' MergeInfoPreview' ) {
125+ title = ' Merge info preview'
126+ } else if ( ! title . endsWith ( ' preview' ) ) {
127+ title = title + ' preview'
129128 }
130129 return title
131130}
@@ -136,7 +135,7 @@ function cleanPreviewTitle(title) {
136135 * @param {string } [previewTitle]
137136 * @return {string }
138137*/
139- function previewAnchor ( previewTitle ) {
138+ function previewAnchor ( previewTitle ) {
140139 return previewTitle
141140 . toLowerCase ( )
142141 . replace ( / / g, '-' )
@@ -148,11 +147,11 @@ function previewAnchor(previewTitle) {
148147 * @param {Array<object> } changes
149148 * @return {Array<string> }
150149 */
151- function cleanMessagesFromChanges ( changes ) {
150+ function cleanMessagesFromChanges ( changes ) {
152151 return changes . map ( function ( change ) {
153152 // replace single quotes around graphql names with backticks,
154153 // to match previous behavior from graphql-schema-comparator
155- return change . message . replace ( / ' ( [ a - z A - Z \ . : ! ] + ) ' / g, '`$1`' )
154+ return change . message . replace ( / ' ( [ a - z A - Z . : ! ] + ) ' / g, '`$1`' )
156155 } )
157156}
158157
@@ -165,7 +164,7 @@ function cleanMessagesFromChanges(changes) {
165164 * @param {object } previews
166165 * @return {object }
167166 */
168- function segmentPreviewChanges ( changesToReport , previews ) {
167+ function segmentPreviewChanges ( changesToReport , previews ) {
169168 // Build a map of `{ path => previewTitle` }
170169 // for easier lookup of change to preview
171170 const pathToPreview = { }
@@ -180,12 +179,12 @@ function segmentPreviewChanges(changesToReport, previews) {
180179 changesToReport . forEach ( function ( change ) {
181180 // For each change, see if its path _or_ one of its ancestors
182181 // is covered by a preview. If it is, mark this change as belonging to a preview
183- const pathParts = change . path . split ( "." )
182+ const pathParts = change . path . split ( '.' )
184183 let testPath = null
185184 let previewTitle = null
186185 let previewChanges = null
187186 while ( pathParts . length > 0 && ! previewTitle ) {
188- testPath = pathParts . join ( "." )
187+ testPath = pathParts . join ( '.' )
189188 previewTitle = pathToPreview [ testPath ]
190189 // If that path didn't find a match, then we'll
191190 // check the next ancestor.
@@ -227,7 +226,7 @@ const CHANGES_TO_REPORT = [
227226 ChangeType . UnionMemberAdded ,
228227 ChangeType . SchemaQueryTypeChanged ,
229228 ChangeType . SchemaMutationTypeChanged ,
230- ChangeType . SchemaSubscriptionTypeChanged ,
229+ ChangeType . SchemaSubscriptionTypeChanged
231230]
232231
233232const CHANGES_TO_IGNORE = [
@@ -259,7 +258,7 @@ const CHANGES_TO_IGNORE = [
259258 ChangeType . InputFieldDescriptionChanged ,
260259 ChangeType . TypeDescriptionChanged ,
261260 ChangeType . TypeDescriptionRemoved ,
262- ChangeType . TypeDescriptionAdded ,
261+ ChangeType . TypeDescriptionAdded
263262]
264263
265264module . exports = { createChangelogEntry, cleanPreviewTitle, previewAnchor, prependDatedEntry }
0 commit comments