1
- import * as fs from 'fs ' ;
2
- import importFresh from 'import-fresh ' ;
3
- import * as path from 'path' ;
4
- import { SECTIONS } from './content/ordering' ;
1
+ import { execSync } from 'child_process ' ;
2
+ import fs from 'fs ' ;
3
+ import path from 'path' ;
4
+ import * as freshOrdering from './content/ordering' ;
5
5
import { createXdmNode } from './src/gatsby/create-xdm-node' ;
6
6
import {
7
7
checkInvalidUsacoMetadata ,
8
8
getProblemInfo ,
9
9
getProblemURL ,
10
10
ProblemMetadata ,
11
11
} from './src/models/problem' ;
12
- const { execSync } = require ( 'child_process' ) ;
13
12
14
13
// Questionable hack to get full commit history so that timestamps work
15
14
try {
28
27
exports . onCreateNode = async api => {
29
28
const { node, actions, loadNodeContent, createContentDigest, createNodeId } =
30
29
api ;
31
-
32
30
const { createNodeField, createNode, createParentChildLink } = actions ;
33
-
34
31
if ( node . internal . type === `File` && node . ext === '.mdx' ) {
35
32
const content = await loadNodeContent ( node ) ;
36
33
const xdmNode = await createXdmNode (
@@ -44,7 +41,6 @@ exports.onCreateNode = async api => {
44
41
createNode ( xdmNode ) ;
45
42
createParentChildLink ( { parent : node , child : xdmNode } ) ;
46
43
}
47
-
48
44
function transformObject ( obj , id ) {
49
45
const problemInfoNode = {
50
46
...obj ,
@@ -59,7 +55,6 @@ exports.onCreateNode = async api => {
59
55
createNode ( problemInfoNode ) ;
60
56
createParentChildLink ( { parent : node , child : problemInfoNode } ) ;
61
57
}
62
-
63
58
const isExtraProblems =
64
59
node . internal . mediaType === 'application/json' &&
65
60
node . sourceInstanceName === 'content' &&
@@ -79,15 +74,15 @@ exports.onCreateNode = async api => {
79
74
: `in node ${ node . id } ` ;
80
75
throw new Error ( `Unable to parse JSON: ${ hint } ` ) ;
81
76
}
82
-
83
77
const moduleId = parsedContent [ 'MODULE_ID' ] ;
84
78
if ( ! moduleId && ! isExtraProblems ) {
85
79
throw new Error (
86
80
'Module ID not found in problem JSON file: ' + node . absolutePath
87
81
) ;
88
82
}
89
-
90
- const freshOrdering = importFresh < any > ( './content/ordering' ) ;
83
+ //const freshOrdering = importFresh<any>(
84
+ // path.join(__dirname, './content/ordering.ts')
85
+ //);
91
86
if ( ! isExtraProblems && ! ( moduleId in freshOrdering . moduleIDToSectionMap ) ) {
92
87
throw new Error (
93
88
'.problems.json moduleId does not correspond to module: ' +
@@ -96,13 +91,14 @@ exports.onCreateNode = async api => {
96
91
node . absolutePath
97
92
) ;
98
93
}
99
-
100
94
Object . keys ( parsedContent ) . forEach ( tableId => {
101
95
if ( tableId === 'MODULE_ID' ) return ;
102
96
try {
103
97
parsedContent [ tableId ] . forEach ( ( metadata : ProblemMetadata ) => {
104
98
checkInvalidUsacoMetadata ( metadata ) ;
105
- const freshOrdering = importFresh < any > ( './content/ordering' ) ;
99
+ //const freshOrdering = importFresh<any>(
100
+ // path.join(__dirname, './content/ordering.ts')
101
+ //);
106
102
transformObject (
107
103
{
108
104
...getProblemInfo ( metadata , freshOrdering ) ,
@@ -121,7 +117,6 @@ exports.onCreateNode = async api => {
121
117
throw new Error ( e ) ;
122
118
}
123
119
} ) ;
124
-
125
120
if ( moduleId ) {
126
121
// create a node that contains all of a module's problems
127
122
const id = createNodeId ( `${ node . id } >>> ModuleProblemLists` ) ;
@@ -130,8 +125,9 @@ exports.onCreateNode = async api => {
130
125
. map ( listId => ( {
131
126
listId,
132
127
problems : parsedContent [ listId ] . map ( x => {
133
- const freshOrdering = importFresh < any > ( './content/ordering' ) ;
134
-
128
+ //const freshOrdering = importFresh<any>(
129
+ // path.join(__dirname, './content/ordering.ts')
130
+ //);
135
131
return {
136
132
...getProblemInfo ( x , freshOrdering ) ,
137
133
} ;
@@ -158,8 +154,8 @@ exports.onCreateNode = async api => {
158
154
node . internal . type === 'Xdm' &&
159
155
node . fileAbsolutePath . includes ( 'content' )
160
156
) {
161
- const ordering = importFresh < any > ( './content/ordering' ) ;
162
- if ( ! ( node . frontmatter . id in ordering . moduleIDToSectionMap ) ) {
157
+ // const ordering = importFresh<any>('./content/ordering.ts ');
158
+ if ( ! ( node . frontmatter . id in freshOrdering . moduleIDToSectionMap ) ) {
163
159
throw new Error (
164
160
'module id does not show up in ordering: ' +
165
161
node . frontmatter . id +
@@ -170,9 +166,8 @@ exports.onCreateNode = async api => {
170
166
createNodeField ( {
171
167
name : 'division' ,
172
168
node,
173
- value : ordering . moduleIDToSectionMap [ node . frontmatter . id ] ,
169
+ value : freshOrdering . moduleIDToSectionMap [ node . frontmatter . id ] ,
174
170
} ) ;
175
-
176
171
// https://angelos.dev/2019/09/add-support-for-modification-times-in-gatsby/
177
172
const gitAuthorTime = execSync (
178
173
`git log -1 --pretty=format:%aI ${ node . fileAbsolutePath } `
@@ -208,7 +203,6 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
208
203
} ) ;
209
204
} ) ;
210
205
} ) ;
211
-
212
206
const result = await graphql ( `
213
207
query {
214
208
modules: allXdm(filter: { fileAbsolutePath: { regex: "/content/" } }) {
@@ -226,7 +220,6 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
226
220
}
227
221
}
228
222
}
229
-
230
223
solutions: allXdm(
231
224
filter: { fileAbsolutePath: { regex: "/solutions/" } }
232
225
) {
@@ -240,7 +233,6 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
240
233
}
241
234
}
242
235
}
243
-
244
236
problems: allProblemInfo {
245
237
edges {
246
238
node {
@@ -271,7 +263,6 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
271
263
if ( result . errors ) {
272
264
reporter . panicOnBuild ( '🚨 ERROR: Loading "createPages" query' ) ;
273
265
}
274
-
275
266
// Check to make sure problems with the same unique ID have consistent information, and that there aren't duplicate slugs
276
267
const problems = result . data . problems . edges ;
277
268
let problemSlugs = { } ; // maps slug to problem unique ID
@@ -328,13 +319,11 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
328
319
problemURLToUniqueID [ node . url ] = node . uniqueId ;
329
320
} ) ;
330
321
// End problems check
331
-
332
- const moduleTemplate = require . resolve ( `./src/templates/moduleTemplate.tsx` ) ;
322
+ const moduleTemplate = path . resolve ( `./src/templates/moduleTemplate.tsx` ) ;
333
323
const modules = result . data . modules . edges ;
334
324
modules . forEach ( ( { node } ) => {
335
325
if ( ! node . fields ?. division ) return ;
336
326
const path = `/${ node . fields . division } /${ node . frontmatter . id } ` ;
337
-
338
327
if ( node . frontmatter . redirects ) {
339
328
node . frontmatter . redirects . forEach ( fromPath => {
340
329
createRedirect ( {
@@ -345,7 +334,6 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
345
334
} ) ;
346
335
} ) ;
347
336
}
348
-
349
337
createPage ( {
350
338
path,
351
339
component : moduleTemplate ,
@@ -354,7 +342,9 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
354
342
} ,
355
343
} ) ;
356
344
357
- const freshOrdering = importFresh < any > ( './content/ordering' ) ;
345
+ // const freshOrdering = importFresh<any>(
346
+ // path.join(__dirname, './content/ordering.ts')
347
+ // );
358
348
if ( node . frontmatter . prerequisites )
359
349
for ( const prereq of node . frontmatter . prerequisites ) {
360
350
if ( ! ( prereq in freshOrdering . moduleIDToSectionMap ) ) {
@@ -368,9 +358,7 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
368
358
}
369
359
}
370
360
} ) ;
371
- const solutionTemplate = require . resolve (
372
- `./src/templates/solutionTemplate.tsx`
373
- ) ;
361
+ const solutionTemplate = path . resolve ( `./src/templates/solutionTemplate.tsx` ) ;
374
362
const solutions = result . data . solutions . edges ;
375
363
solutions . forEach ( ( { node } ) => {
376
364
try {
@@ -437,12 +425,9 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
437
425
throw e ;
438
426
}
439
427
} ) ;
440
-
441
428
// Generate Syllabus Pages //
442
- const syllabusTemplate = require . resolve (
443
- `./src/templates/syllabusTemplate.tsx`
444
- ) ;
445
- SECTIONS . forEach ( division => {
429
+ const syllabusTemplate = path . resolve ( `./src/templates/syllabusTemplate.tsx` ) ;
430
+ freshOrdering . SECTIONS . forEach ( division => {
446
431
createPage ( {
447
432
path : `/${ division } ` ,
448
433
component : syllabusTemplate ,
@@ -538,7 +523,7 @@ exports.onCreateWebpackConfig = ({ actions, stage, loaders, plugins }) => {
538
523
actions . setWebpackConfig ( {
539
524
resolve : {
540
525
alias : {
541
- path : require . resolve ( 'path-browserify' ) ,
526
+ path : path . resolve ( 'path-browserify' ) ,
542
527
} ,
543
528
fallback : {
544
529
fs : false ,
0 commit comments