@@ -9,7 +9,7 @@ const ASSETS_SOURCE_DIR = `${__dirname}/../assets/`;
99const ASSETS_DEST_DIR = `${ __dirname } /../src/assets/` ;
1010
1111async function main ( ) {
12- console . log ( " ... Making sponsors.json" ) ;
12+ console . log ( ' ... Making sponsors.json' ) ;
1313 const sponsorsMd = fs . readFileSync ( `${ __dirname } /../SPONSORS.md` , 'utf8' ) ;
1414 const lines = sponsorsMd . split ( '\n' ) ;
1515 const tiers = [ ] ;
@@ -24,10 +24,11 @@ async function main() {
2424 }
2525 tiers . reverse ( ) ;
2626 const sponsors = [ ] ;
27+ let repeats = 0 ;
2728 for ( let tier = 0 ; tier < tiers . length ; tier ++ ) {
29+ repeats += tier + 1 ;
2830 for ( const sponsor of tiers [ tier ] ) {
2931 // Higher tiers are more likely to appear
30- const repeats = ( tier + 1 ) ;
3132 for ( let i = 0 ; i < repeats ; i ++ ) {
3233 sponsors . push ( sponsor ) ;
3334 }
@@ -36,112 +37,119 @@ async function main() {
3637 sponsors . sort ( ) ;
3738 fs . writeFileSync ( `${ __dirname } /../sponsors.json` , JSON . stringify ( sponsors , null , 2 ) ) ;
3839
39-
40- console . log ( "... Building GraphiQL" ) ;
40+ console . log ( '... Building GraphiQL' ) ;
4141
4242 // Step 1: compile GraphiQL
4343 await new Promise ( ( resolve , reject ) => {
4444 // Install the older version of GraphQL for GraphiQL
4545 execSync ( 'yarn' , {
46- cwd : `${ __dirname } /../postgraphiql`
46+ cwd : `${ __dirname } /../postgraphiql` ,
4747 } ) ;
4848 // Webpack up everything
49- webpack ( {
50- mode : 'production' ,
51- target : 'web' ,
52- entry : `${ __dirname } /../postgraphiql/src/index.js` ,
53- node : {
54- dgram : 'empty' ,
55- fs : 'empty' ,
56- net : 'empty' ,
57- tls : 'empty' ,
58- child_process : 'empty' ,
59- } ,
60- output : {
61- path : ASSETS_SOURCE_DIR ,
62- filename : 'graphiql.js'
63- } ,
64- module : {
65- rules : [
66- {
67- test : / \. j s x ? $ / ,
68- exclude : / n o d e _ m o d u l e s / ,
69- use : {
70- loader : 'babel-loader' ,
71- options : {
72- presets : [ '@babel/preset-env' , '@babel/preset-react' ] ,
73- plugins : [ '@babel/plugin-proposal-class-properties' , '@babel/plugin-transform-runtime' ] ,
49+ webpack (
50+ {
51+ mode : 'production' ,
52+ target : 'web' ,
53+ entry : `${ __dirname } /../postgraphiql/src/index.js` ,
54+ node : {
55+ dgram : 'empty' ,
56+ fs : 'empty' ,
57+ net : 'empty' ,
58+ tls : 'empty' ,
59+ child_process : 'empty' ,
60+ } ,
61+ output : {
62+ path : ASSETS_SOURCE_DIR ,
63+ filename : 'graphiql.js' ,
64+ } ,
65+ module : {
66+ rules : [
67+ {
68+ test : / \. j s x ? $ / ,
69+ exclude : / n o d e _ m o d u l e s / ,
70+ use : {
71+ loader : 'babel-loader' ,
72+ options : {
73+ presets : [ '@babel/preset-env' , '@babel/preset-react' ] ,
74+ plugins : [
75+ '@babel/plugin-proposal-class-properties' ,
76+ '@babel/plugin-transform-runtime' ,
77+ ] ,
78+ } ,
7479 } ,
7580 } ,
76- } ,
77- {
78- test : / \. c s s $ / ,
79- use : [
80- { loader : 'style-loader' } ,
81- { loader : 'css-loader' } ,
82- ] ,
83- } ,
81+ {
82+ test : / \. c s s $ / ,
83+ use : [ { loader : 'style-loader' } , { loader : 'css-loader' } ] ,
84+ } ,
85+ ] ,
86+ } ,
87+ plugins : [
88+ new webpack . DefinePlugin ( {
89+ // Hack required due to https://unpkg.com/[email protected] /jsutils/instanceOf.js 90+ process : 'false' ,
91+ 'process.env' : {
92+ NODE_ENV : '"production"' ,
93+ } ,
94+ } ) ,
95+ // Prevent webpack from attempting to import flow stuff (dynamic requires in GraphiQL)
96+ new webpack . ContextReplacementPlugin (
97+ / g r a p h q l - l a n g u a g e - s e r v i c e - i n t e r f a c e [ \\ / ] d i s t $ / ,
98+ / ^ \. \/ .* \. j s $ /
99+ ) ,
100+ new HtmlWebpackPlugin ( {
101+ filename : 'graphiql.html' ,
102+ template : `${ __dirname } /../postgraphiql/public/index.html` ,
103+ inlineSource : '.(js|css)$' , // embed all javascript and css inline
104+ inject : 'body' ,
105+ } ) ,
106+ new HtmlWebpackInlineSourcePlugin ( ) ,
84107 ] ,
85108 } ,
86- plugins : [
87- new webpack . DefinePlugin ( {
88- // Hack required due to https://unpkg.com/[email protected] /jsutils/instanceOf.js 89- 'process' : 'false' ,
90- 'process.env' : {
91- NODE_ENV : '"production"' ,
92- } ,
93- } ) ,
94- // Prevent webpack from attempting to import flow stuff (dynamic requires in GraphiQL)
95- new webpack . ContextReplacementPlugin (
96- / g r a p h q l - l a n g u a g e - s e r v i c e - i n t e r f a c e [ \\ / ] d i s t $ / ,
97- / ^ \. \/ .* \. j s $ /
98- ) ,
99- new HtmlWebpackPlugin ( {
100- filename : 'graphiql.html' ,
101- template : `${ __dirname } /../postgraphiql/public/index.html` ,
102- inlineSource : '.(js|css)$' , // embed all javascript and css inline
103- inject : 'body' ,
104- } ) ,
105- new HtmlWebpackInlineSourcePlugin ( )
106- ]
107- } , ( err , stats ) => {
108- if ( err ) {
109- console . error ( err ) ;
110- process . exit ( 1 ) ;
111- }
112- if ( stats . hasErrors ( ) ) {
113- console . log ( stats . toString ( "minimal" ) ) ;
114- process . exit ( 2 ) ;
109+ ( err , stats ) => {
110+ if ( err ) {
111+ console . error ( err ) ;
112+ process . exit ( 1 ) ;
113+ }
114+ if ( stats . hasErrors ( ) ) {
115+ console . log ( stats . toString ( 'minimal' ) ) ;
116+ process . exit ( 2 ) ;
117+ }
118+ // We only want the HTML file
119+ fs . unlinkSync ( `${ ASSETS_SOURCE_DIR } /graphiql.js` ) ;
120+ console . log ( stats . toString ( 'minimal' ) ) ;
121+ resolve ( ) ;
115122 }
116- // We only want the HTML file
117- fs . unlinkSync ( `${ ASSETS_SOURCE_DIR } /graphiql.js` ) ;
118- console . log ( stats . toString ( "minimal" ) ) ;
119- resolve ( ) ;
120- } ) ;
123+ ) ;
121124 } ) ;
122125
123126 const shouldBeBinary = filename => ! filename . match ( / \. h t m l $ / ) ;
124127
125- console . log ( " ... Compiling the assets" ) ;
128+ console . log ( ' ... Compiling the assets' ) ;
126129 // Step 2: compile the assets
127130 const files = fs . readdirSync ( ASSETS_SOURCE_DIR ) ;
128- files . filter ( f => f [ 0 ] !== '.' ) . map ( filename => {
129- const fileContent = fs . readFileSync ( `${ ASSETS_SOURCE_DIR } /${ filename } ` ) ;
130- let output ;
131- if ( shouldBeBinary ( filename ) ) {
132- output = `Buffer.from(\n '${ fileContent . toString (
133- 'base64' ,
134- ) } ',\n 'base64'\n)`;
135- } else {
136- output = `${ JSON . stringify ( fileContent . toString ( 'utf8' ) ) } ` ;
137- }
138- fs . writeFileSync ( `${ ASSETS_DEST_DIR } /${ filename } .ts` , `export default process.env.POSTGRAPHILE_OMIT_ASSETS === '1'\n ? null\n : ${ output } ;\n` ) ;
139- } ) ;
131+ files
132+ . filter ( f => f [ 0 ] !== '.' )
133+ . map ( filename => {
134+ const fileContent = fs . readFileSync ( `${ ASSETS_SOURCE_DIR } /${ filename } ` ) ;
135+ let output ;
136+ if ( shouldBeBinary ( filename ) ) {
137+ output = `Buffer.from(\n '${ fileContent . toString ( 'base64' ) } ',\n 'base64'\n)` ;
138+ } else {
139+ output = `${ JSON . stringify ( fileContent . toString ( 'utf8' ) ) } ` ;
140+ }
141+ fs . writeFileSync (
142+ `${ ASSETS_DEST_DIR } /${ filename } .ts` ,
143+ `export default process.env.POSTGRAPHILE_OMIT_ASSETS === '1'\n ? null\n : ${ output } ;\n`
144+ ) ;
145+ } ) ;
140146}
141147
142-
143- main ( ) . then ( ( ) => { } , err => {
144- console . error ( "An error occurred" ) ;
145- console . error ( err ) ;
146- process . exit ( 3 ) ;
147- } ) ;
148+ main ( ) . then (
149+ ( ) => { } ,
150+ err => {
151+ console . error ( 'An error occurred' ) ;
152+ console . error ( err ) ;
153+ process . exit ( 3 ) ;
154+ }
155+ ) ;
0 commit comments