Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
n1ru4l committed Jul 27, 2022
1 parent 86b8d80 commit 5c739c7
Show file tree
Hide file tree
Showing 9 changed files with 461 additions and 36 deletions.
2 changes: 1 addition & 1 deletion examples/koa/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { buildApp } from './app.js'
import { buildApp } from './app'

const app = buildApp()

Expand Down
2 changes: 2 additions & 0 deletions packages/graphql-yoga/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src/graphiql-html.ts
src/landing-page.ts
14 changes: 0 additions & 14 deletions packages/graphql-yoga/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,6 @@
"default": "./dist/esm/index.js"
}
},
"./*": {
"require": {
"types": "./dist/typings/*.d.ts",
"default": "./dist/cjs/*.js"
},
"import": {
"types": "./dist/typings/*.d.ts",
"default": "./dist/esm/*.js"
},
"default": {
"types": "./dist/typings/*.d.ts",
"default": "./dist/esm/*.js"
}
},
"./package.json": "./package.json"
},
"typings": "dist/typings/index.d.ts",
Expand Down
57 changes: 38 additions & 19 deletions packages/graphql-yoga/scripts/generate-graphiql-html.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,58 @@
import { minify } from 'html-minifier-terser'
import { minify as minifyT } from 'html-minifier-terser'
import * as fs from 'fs'
import * as path from 'path'
import { fileURLToPath } from 'url'

const __dirname = path.dirname(fileURLToPath(import.meta.url))

async function main() {
async function minify(str) {
return (
await minifyT(str, {
minifyJS: true,
useShortDoctype: false,
removeAttributeQuotes: true,
collapseWhitespace: true,
minifyCSS: true,
})
).toString('utf-8')
}

async function minifyGraphiQLHTML() {
const graphiqlVersion = JSON.parse(
fs.readFileSync(
path.join(__dirname, '..', '..', 'graphiql', 'package.json'),
'utf-8',
),
).version

const minified = (
await minify(
fs
.readFileSync(
path.join(__dirname, '..', 'src', 'graphiql.html'),
'utf-8',
)
.replace(/__GRAPHIQL_VERSION__/g, graphiqlVersion),
{
minifyJS: true,
useShortDoctype: false,
removeAttributeQuotes: true,
collapseWhitespace: true,
},
)
).toString('utf-8')
const minified = await minify(
fs
.readFileSync(path.join(__dirname, '..', 'src', 'graphiql.html'), 'utf-8')
.replace(/__GRAPHIQL_VERSION__/g, graphiqlVersion),
)

fs.writeFileSync(
path.join(__dirname, '../src/graphiqlHTML.ts'),
path.join(__dirname, '../src/graphiql-html.ts'),
`export default ${JSON.stringify(minified)}`,
)
}

async function minifyLandingPageHTML() {
const minified = await minify(
fs.readFileSync(
path.join(__dirname, '..', 'src', 'landing-page.html'),
'utf-8',
),
)

fs.writeFileSync(
path.join(__dirname, '../src/landing-page-html.ts'),
`export default ${JSON.stringify(minified)}`,
)
}

async function main() {
await Promise.all([minifyGraphiQLHTML(), minifyLandingPageHTML()])
}

main()
1 change: 0 additions & 1 deletion packages/graphql-yoga/src/graphiqlHTML.ts

This file was deleted.

Loading

0 comments on commit 5c739c7

Please sign in to comment.