let esbuild = require('esbuild') let formatName = 'Recital' var storyFormat = { name: formatName, version: '4.0.0', author: 'Amorphous', description: 'Format to export a story into a Recital .stage file.', image: 'icon.svg', url: '', license: 'MIT License', proofing: false, } let fs = require('fs') let uglifier = require('uglify-js') let minifier = require('html-minifier') esbuild.buildSync({ entryPoints: [`Recital.ts`], outfile: 'dist/Recital.js', bundle: true, }) let header = `// Recital format v${require('./package.json').version} // Icon by Delapouite (https://delapouite.com/), distributed as part of Game Icons. ` let script = fs.readFileSync('./dist/Recital.js').toString() let page = fs.readFileSync('./template.html').toString() let devStorySource = page.replace('{{SCRIPT}}', script) storyFormat.name = formatName + '-dev' storyFormat.source = devStorySource fs.writeFileSync( './dist/formatDev.js', header + 'window.storyFormat(' + JSON.stringify(storyFormat) + ')' ) let processedScript = uglifier.minify(script).code let processedPage = minifier.minify(page, { collapseWhitespace: true }) let storySource = processedPage.replace('{{SCRIPT}}', processedScript) storyFormat.name = formatName storyFormat.source = storySource fs.writeFileSync( './dist/format.js', header + 'window.storyFormat(' + JSON.stringify(storyFormat) + ')' ) // copy the icon fs.copyFileSync('./icon.svg', './dist/icon.svg')