1
0
Fork 0
Browse Source

refactor: post-process using nunjucks

Signed-off-by: André Jaenisch <andre.jaenisch@posteo.de>
combat-scorched-earth-from-outer-space
André Jaenisch 1 year ago
parent
commit
30b9e3949a
Signed by: ryuno-ki
GPG Key ID: 5A668E771F1ED854
  1. 0
      dist/css/.gitkeep
  2. 0
      dist/js/.gitkeep
  3. 283
      package-lock.json
  4. 8
      package.json
  5. 12
      rollup.config.js
  6. 152
      scripts/post-process.cjs
  7. 4
      src/index.njk

0
dist/css/.gitkeep vendored

0
dist/js/.gitkeep vendored

283
package-lock.json generated

@ -32,9 +32,9 @@
"markdownlint-cli": "0.28.1",
"mocha": "9.0.3",
"npm": "7.20.6",
"nunjucks": "3.2.3",
"nyc": "15.1.0",
"rollup": "2.56.2",
"rollup-plugin-copy": "3.4.0",
"rollup-plugin-license": "2.5.0",
"rollup-plugin-terser": "7.0.2",
"rollup-plugin-visualizer": "5.5.2",
@ -1184,37 +1184,12 @@
"integrity": "sha512-C6N5s2ZFtuZRj54k2/zyRhNDjJwwcViAM3Nbm8zjBpbqAdZ00mr0CFxvSKeO8Y/e03WVFLpQMdHYVfUd6SB+Hw==",
"dev": true
},
"node_modules/@types/fs-extra": {
"version": "8.1.2",
"resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-8.1.2.tgz",
"integrity": "sha512-SvSrYXfWSc7R4eqnOzbQF4TZmfpNSM9FrSWLU3EUnWBuyZqNBOrv1B1JA3byUDPUl9z4Ab3jeZG2eDdySlgNMg==",
"dev": true,
"dependencies": {
"@types/node": "*"
}
},
"node_modules/@types/glob": {
"version": "7.1.4",
"resolved": "https://registry.npmjs.org/@types/glob/-/glob-7.1.4.tgz",
"integrity": "sha512-w+LsMxKyYQm347Otw+IfBXOv9UWVjpHpCDdbBMt8Kz/xbvCYNjP+0qPh91Km3iKfSRLBB0P7fAMf0KHrPu+MyA==",
"dev": true,
"dependencies": {
"@types/minimatch": "*",
"@types/node": "*"
}
},
"node_modules/@types/json-schema": {
"version": "7.0.9",
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.9.tgz",
"integrity": "sha512-qcUXuemtEu+E5wZSJHNxUXeCZhAfXKQ41D+duX+VYPde7xyEVZci+/oXKJL13tnRs9lR2pr4fod59GT6/X1/yQ==",
"dev": true
},
"node_modules/@types/minimatch": {
"version": "3.0.5",
"resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.5.tgz",
"integrity": "sha512-Klz949h02Gz2uZCMGwDUSDS1YBlTdDDgbWHi+81l29tQALUtvz4rAYi5uoVhE5Lagoq6DeqAUlbrHvW/mXDgdQ==",
"dev": true
},
"node_modules/@types/minimist": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/@types/minimist/-/minimist-1.2.2.tgz",
@ -1245,6 +1220,12 @@
"integrity": "sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q==",
"dev": true
},
"node_modules/a-sync-waterfall": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/a-sync-waterfall/-/a-sync-waterfall-1.0.1.tgz",
"integrity": "sha512-RYTOHHdWipFUliRFMCS4X2Yn2X8M87V/OpSqWzKKOGhzqyUxzyVmhHDH9sAvG+ZuQf/TAOFsLCpMw09I1ufUnA==",
"dev": true
},
"node_modules/abab": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/abab/-/abab-2.0.5.tgz",
@ -1577,6 +1558,12 @@
"node": ">=0.10.0"
}
},
"node_modules/asap": {
"version": "2.0.6",
"resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz",
"integrity": "sha1-5QNHYR1+aQlDIIu9r+vLwvuGbUY=",
"dev": true
},
"node_modules/asn1": {
"version": "0.2.4",
"resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz",
@ -5062,15 +5049,6 @@
"node": ">=8"
}
},
"node_modules/is-plain-object": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-3.0.1.tgz",
"integrity": "sha512-Xnpx182SBMrr/aBik8y+GuR4U1L9FqMSojwDQwPMmxyC6bvEqly9UBCxhauBF5vNh2gwWJNX6oDV7O+OM4z34g==",
"dev": true,
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/is-potential-custom-element-name": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/is-potential-custom-element-name/-/is-potential-custom-element-name-1.0.1.tgz",
@ -9873,6 +9851,40 @@
"node": ">=0.10.0"
}
},
"node_modules/nunjucks": {
"version": "3.2.3",
"resolved": "https://registry.npmjs.org/nunjucks/-/nunjucks-3.2.3.tgz",
"integrity": "sha512-psb6xjLj47+fE76JdZwskvwG4MYsQKXUtMsPh6U0YMvmyjRtKRFcxnlXGWglNybtNTNVmGdp94K62/+NjF5FDQ==",
"dev": true,
"dependencies": {
"a-sync-waterfall": "^1.0.0",
"asap": "^2.0.3",
"commander": "^5.1.0"
},
"bin": {
"nunjucks-precompile": "bin/precompile"
},
"engines": {
"node": ">= 6.9.0"
},
"peerDependencies": {
"chokidar": "^3.3.0"
},
"peerDependenciesMeta": {
"chokidar": {
"optional": true
}
}
},
"node_modules/nunjucks/node_modules/commander": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-5.1.0.tgz",
"integrity": "sha512-P0CysNDQ7rtVw4QIQtm+MRxV66vKFSvlsQvGYXZWR3qFU0jlMKHZZZgw8e+8DSah4UDKMqnknRDQz+xuQXQ/Zg==",
"dev": true,
"engines": {
"node": ">= 6"
}
},
"node_modules/nwsapi": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/nwsapi/-/nwsapi-2.2.0.tgz",
@ -11363,82 +11375,6 @@
"fsevents": "~2.3.2"
}
},
"node_modules/rollup-plugin-copy": {
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/rollup-plugin-copy/-/rollup-plugin-copy-3.4.0.tgz",
"integrity": "sha512-rGUmYYsYsceRJRqLVlE9FivJMxJ7X6jDlP79fmFkL8sJs7VVMSVyA2yfyL+PGyO/vJs4A87hwhgVfz61njI+uQ==",
"dev": true,
"dependencies": {
"@types/fs-extra": "^8.0.1",
"colorette": "^1.1.0",
"fs-extra": "^8.1.0",
"globby": "10.0.1",
"is-plain-object": "^3.0.0"
},
"engines": {
"node": ">=8.3"
}
},
"node_modules/rollup-plugin-copy/node_modules/fs-extra": {
"version": "8.1.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz",
"integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==",
"dev": true,
"dependencies": {
"graceful-fs": "^4.2.0",
"jsonfile": "^4.0.0",
"universalify": "^0.1.0"
},
"engines": {
"node": ">=6 <7 || >=8"
}
},
"node_modules/rollup-plugin-copy/node_modules/globby": {
"version": "10.0.1",
"resolved": "https://registry.npmjs.org/globby/-/globby-10.0.1.tgz",
"integrity": "sha512-sSs4inE1FB2YQiymcmTv6NWENryABjUNPeWhOvmn4SjtKybglsyPZxFB3U1/+L1bYi0rNZDqCLlHyLYDl1Pq5A==",
"dev": true,
"dependencies": {
"@types/glob": "^7.1.1",
"array-union": "^2.1.0",
"dir-glob": "^3.0.1",
"fast-glob": "^3.0.3",
"glob": "^7.1.3",
"ignore": "^5.1.1",
"merge2": "^1.2.3",
"slash": "^3.0.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/rollup-plugin-copy/node_modules/ignore": {
"version": "5.1.8",
"resolved": "https://registry.npmjs.org/ignore/-/ignore-5.1.8.tgz",
"integrity": "sha512-BMpfD7PpiETpBl/A6S498BaIJ6Y/ABT93ETbby2fP00v4EbvPBXWEoaR1UBPKs3iR53pJY7EtZk5KACI57i1Uw==",
"dev": true,
"engines": {
"node": ">= 4"
}
},
"node_modules/rollup-plugin-copy/node_modules/jsonfile": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz",
"integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=",
"dev": true,
"optionalDependencies": {
"graceful-fs": "^4.1.6"
}
},
"node_modules/rollup-plugin-copy/node_modules/universalify": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",
"integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==",
"dev": true,
"engines": {
"node": ">= 4.0.0"
}
},
"node_modules/rollup-plugin-license": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/rollup-plugin-license/-/rollup-plugin-license-2.5.0.tgz",
@ -16907,37 +16843,12 @@
"integrity": "sha512-C6N5s2ZFtuZRj54k2/zyRhNDjJwwcViAM3Nbm8zjBpbqAdZ00mr0CFxvSKeO8Y/e03WVFLpQMdHYVfUd6SB+Hw==",
"dev": true
},
"@types/fs-extra": {
"version": "8.1.2",
"resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-8.1.2.tgz",
"integrity": "sha512-SvSrYXfWSc7R4eqnOzbQF4TZmfpNSM9FrSWLU3EUnWBuyZqNBOrv1B1JA3byUDPUl9z4Ab3jeZG2eDdySlgNMg==",
"dev": true,
"requires": {
"@types/node": "*"
}
},
"@types/glob": {
"version": "7.1.4",
"resolved": "https://registry.npmjs.org/@types/glob/-/glob-7.1.4.tgz",
"integrity": "sha512-w+LsMxKyYQm347Otw+IfBXOv9UWVjpHpCDdbBMt8Kz/xbvCYNjP+0qPh91Km3iKfSRLBB0P7fAMf0KHrPu+MyA==",
"dev": true,
"requires": {
"@types/minimatch": "*",
"@types/node": "*"
}
},
"@types/json-schema": {
"version": "7.0.9",
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.9.tgz",
"integrity": "sha512-qcUXuemtEu+E5wZSJHNxUXeCZhAfXKQ41D+duX+VYPde7xyEVZci+/oXKJL13tnRs9lR2pr4fod59GT6/X1/yQ==",
"dev": true
},
"@types/minimatch": {
"version": "3.0.5",
"resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.5.tgz",
"integrity": "sha512-Klz949h02Gz2uZCMGwDUSDS1YBlTdDDgbWHi+81l29tQALUtvz4rAYi5uoVhE5Lagoq6DeqAUlbrHvW/mXDgdQ==",
"dev": true
},
"@types/minimist": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/@types/minimist/-/minimist-1.2.2.tgz",
@ -16968,6 +16879,12 @@
"integrity": "sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q==",
"dev": true
},
"a-sync-waterfall": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/a-sync-waterfall/-/a-sync-waterfall-1.0.1.tgz",
"integrity": "sha512-RYTOHHdWipFUliRFMCS4X2Yn2X8M87V/OpSqWzKKOGhzqyUxzyVmhHDH9sAvG+ZuQf/TAOFsLCpMw09I1ufUnA==",
"dev": true
},
"abab": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/abab/-/abab-2.0.5.tgz",
@ -17223,6 +17140,12 @@
"integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=",
"dev": true
},
"asap": {
"version": "2.0.6",
"resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz",
"integrity": "sha1-5QNHYR1+aQlDIIu9r+vLwvuGbUY=",
"dev": true
},
"asn1": {
"version": "0.2.4",
"resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz",
@ -19834,12 +19757,6 @@
"integrity": "sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==",
"dev": true
},
"is-plain-object": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-3.0.1.tgz",
"integrity": "sha512-Xnpx182SBMrr/aBik8y+GuR4U1L9FqMSojwDQwPMmxyC6bvEqly9UBCxhauBF5vNh2gwWJNX6oDV7O+OM4z34g==",
"dev": true
},
"is-potential-custom-element-name": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/is-potential-custom-element-name/-/is-potential-custom-element-name-1.0.1.tgz",
@ -23297,6 +23214,25 @@
"integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=",
"dev": true
},
"nunjucks": {
"version": "3.2.3",
"resolved": "https://registry.npmjs.org/nunjucks/-/nunjucks-3.2.3.tgz",
"integrity": "sha512-psb6xjLj47+fE76JdZwskvwG4MYsQKXUtMsPh6U0YMvmyjRtKRFcxnlXGWglNybtNTNVmGdp94K62/+NjF5FDQ==",
"dev": true,
"requires": {
"a-sync-waterfall": "^1.0.0",
"asap": "^2.0.3",
"commander": "^5.1.0"
},
"dependencies": {
"commander": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-5.1.0.tgz",
"integrity": "sha512-P0CysNDQ7rtVw4QIQtm+MRxV66vKFSvlsQvGYXZWR3qFU0jlMKHZZZgw8e+8DSah4UDKMqnknRDQz+xuQXQ/Zg==",
"dev": true
}
}
},
"nwsapi": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/nwsapi/-/nwsapi-2.2.0.tgz",
@ -24417,69 +24353,6 @@
"fsevents": "~2.3.2"
}
},
"rollup-plugin-copy": {
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/rollup-plugin-copy/-/rollup-plugin-copy-3.4.0.tgz",
"integrity": "sha512-rGUmYYsYsceRJRqLVlE9FivJMxJ7X6jDlP79fmFkL8sJs7VVMSVyA2yfyL+PGyO/vJs4A87hwhgVfz61njI+uQ==",
"dev": true,
"requires": {
"@types/fs-extra": "^8.0.1",
"colorette": "^1.1.0",
"fs-extra": "^8.1.0",
"globby": "10.0.1",
"is-plain-object": "^3.0.0"
},
"dependencies": {
"fs-extra": {
"version": "8.1.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz",
"integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==",
"dev": true,
"requires": {
"graceful-fs": "^4.2.0",
"jsonfile": "^4.0.0",
"universalify": "^0.1.0"
}
},
"globby": {
"version": "10.0.1",
"resolved": "https://registry.npmjs.org/globby/-/globby-10.0.1.tgz",
"integrity": "sha512-sSs4inE1FB2YQiymcmTv6NWENryABjUNPeWhOvmn4SjtKybglsyPZxFB3U1/+L1bYi0rNZDqCLlHyLYDl1Pq5A==",
"dev": true,
"requires": {
"@types/glob": "^7.1.1",
"array-union": "^2.1.0",
"dir-glob": "^3.0.1",
"fast-glob": "^3.0.3",
"glob": "^7.1.3",
"ignore": "^5.1.1",
"merge2": "^1.2.3",
"slash": "^3.0.0"
}
},
"ignore": {
"version": "5.1.8",
"resolved": "https://registry.npmjs.org/ignore/-/ignore-5.1.8.tgz",
"integrity": "sha512-BMpfD7PpiETpBl/A6S498BaIJ6Y/ABT93ETbby2fP00v4EbvPBXWEoaR1UBPKs3iR53pJY7EtZk5KACI57i1Uw==",
"dev": true
},
"jsonfile": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz",
"integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=",
"dev": true,
"requires": {
"graceful-fs": "^4.1.6"
}
},
"universalify": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",
"integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==",
"dev": true
}
}
},
"rollup-plugin-license": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/rollup-plugin-license/-/rollup-plugin-license-2.5.0.tgz",

8
package.json

@ -7,7 +7,7 @@
"build": "rollup -c",
"check": "node ./scripts/zip-and-check.cjs",
"commit-msg": "commitlint -e",
"copy:css": "cleancss ./src/css/* -o ./dist/css/main.css && cp ./src/css/normalize.css ./dist/css/",
"copy:css": "cleancss ./src/css/* -o ./dist/main.css",
"copy:icons": "cp ./src/favicon.ico ./dist/ && cp ./src/icon.png ./dist",
"coverage": "nyc npm run test",
"deploy": "gh-pages -d ./dist -r git@github.com:Ryuno-Ki/js13kgames-2021.git",
@ -16,12 +16,14 @@
"lint:js": "eslint ./src",
"lint:md": "markdownlint --ignore ./node_modules **/*.md",
"postbuild": "npm run copy:css && npm run check",
"postpost-process": "rm ./dist/index.njk ./dist/main.css ./dist/app.js",
"posttest": "npm run tsd",
"post-process": "node ./scripts/post-process.cjs",
"post-process": "node -e \"var n=require('nunjucks');console.log(n.render('./dist/index.njk'))\" > ./dist/index.html",
"prebuild": "npm run docs",
"precheck": "npm run post-process",
"predeploy": "npm run build",
"prepare": "husky install",
"prepost-process": "cp ./src/index.njk ./dist",
"prestart": "npm run build",
"pre-commit": "npm run types && npm run lint && npm run test",
"start": "http-server -a 0.0.0.0 -p 8080 ./dist",
@ -67,9 +69,9 @@
"markdownlint-cli": "0.28.1",
"mocha": "9.0.3",
"npm": "7.20.6",
"nunjucks": "3.2.3",
"nyc": "15.1.0",
"rollup": "2.56.2",
"rollup-plugin-copy": "3.4.0",
"rollup-plugin-license": "2.5.0",
"rollup-plugin-terser": "7.0.2",
"rollup-plugin-visualizer": "5.5.2",

12
rollup.config.js

@ -1,5 +1,4 @@
import buble from '@rollup/plugin-buble'
import copy from 'rollup-plugin-copy'
import license from 'rollup-plugin-license'
import { terser } from 'rollup-plugin-terser'
@ -19,20 +18,11 @@ along with <insert name here>. If not, see <https://www.gnu.org/licenses/>.`
export default {
input: './src/js/app.js',
output: {
file: './dist/js/app.js',
file: './dist/app.js',
format: 'iife',
name: 'game'
},
plugins: [
copy({
flatten: true,
verbose: true,
targets: [{
src: './src/index.html',
dest: './dist/'
}]
}),
buble(),
terser({
output: {

152
scripts/post-process.cjs

@ -1,152 +0,0 @@
const fs = require('fs')
const path = require('path')
const jsdom = require('jsdom')
const { JSDOM } = jsdom
const distFolder = path.join(__dirname, '..', 'dist')
const indexHtmlFilePath = path.join(distFolder, 'index.html')
async function deleteFile (filePath) {
console.log('Clean up ', filePath)
return new Promise((resolve, reject) => {
fs.unlink(filePath, (error) => {
if (error) {
reject(error)
}
resolve()
})
})
}
async function cleanUp (scriptFileName, styleFileName) {
return Promise.all([
deleteFile(scriptFileName),
deleteFile(styleFileName)
])
}
async function extractScriptFileName (htmlString) {
const dom = new JSDOM(htmlString)
const document = dom.window.document
const scriptElement = document.querySelector('script')
const scriptSrc = scriptElement.getAttribute('src')
const scriptFileName = path.join(distFolder, scriptSrc)
return scriptFileName
}
async function inlineScript (htmlString, scriptSrc) {
const dom = new JSDOM(htmlString)
const document = dom.window.document
const scriptElement = document.querySelector('script')
const script = document.createElement('script')
const source = document.createTextNode(scriptSrc)
script.appendChild(source)
scriptElement.parentNode.replaceChild(script, scriptElement)
return Promise.resolve(document.documentElement.outerHTML)
}
async function extractStyleFileName (htmlString) {
const dom = new JSDOM(htmlString)
const document = dom.window.document
const linkElement = document.querySelector('link[rel="stylesheet"]')
const styleSrc = linkElement.getAttribute('href')
const styleFileName = path.join(distFolder, styleSrc)
return styleFileName
}
async function inlineStyle (htmlString, styleSrc) {
const dom = new JSDOM(htmlString)
const document = dom.window.document
const linkElement = document.querySelector('link[rel="stylesheet"]')
const style = document.createElement('style')
const source = document.createTextNode(styleSrc)
style.appendChild(source) // TODO: Should work with replaceChild, too?
linkElement.remove()
document.head.appendChild(style)
return Promise.resolve(document.documentElement.outerHTML)
}
async function updateFile (originalHtmlString, updatedHtmlString) {
const dom = new JSDOM(originalHtmlString)
const doctype = dom.window.document.doctype
const content = [
'<!DOCTYPE ',
doctype.name,
doctype.internalSubset,
doctype.publicId,
doctype.systemId,
'>'
].join('') + '\n' + updatedHtmlString
return new Promise((resolve, reject) => {
fs.writeFile(indexHtmlFilePath, content, (error) => {
if (error) {
return reject(error)
}
resolve(updatedHtmlString)
})
})
}
function parseFile (filePath) {
return new Promise((resolve, reject) => {
fs.readFile(filePath, 'utf8', (error, content) => {
if (error) {
return reject(error)
}
resolve(content)
})
})
}
async function run () {
let htmlString = ''
let updatedHtmlString = htmlString
try {
htmlString = await parseFile(indexHtmlFilePath)
} catch (exc) {
console.error(exc)
return process.exit(1)
}
const scriptFileName = await extractScriptFileName(htmlString)
const styleFileName = await extractStyleFileName(htmlString)
try {
const scriptSrc = await parseFile(scriptFileName)
updatedHtmlString = await inlineScript(htmlString, scriptSrc)
} catch (exc) {
console.error(exc)
return process.exit(2)
}
try {
const styleSrc = await parseFile(styleFileName)
updatedHtmlString = await inlineStyle(updatedHtmlString, styleSrc)
} catch (exc) {
console.error(exc)
return process.exit(3)
}
try {
await updateFile(htmlString, updatedHtmlString)
} catch (exc) {
console.error(exc)
process.exit(4)
}
try {
cleanUp(scriptFileName, styleFileName)
} catch (exc) {
console.error(exc)
return process.exit(5)
}
}
run()

4
src/index.html → src/index.njk

@ -10,7 +10,7 @@
<meta property="og:url" content="" />
<meta property="og:image" content="" />
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🚀</text></svg>">
<link rel="stylesheet" href="css/main.css" />
<style>{%- include './main.css' -%}</style>
</head>
<body>
<main>
@ -55,7 +55,7 @@
</p>
</section>
</main>
<script src="js/app.js"></script>
<script>{%- include './app.js' -%}</script>
<script>location.hash='#scene-title';window.game.app()</script>
</body>
</html>
Loading…
Cancel
Save