Skip to content

Commit

Permalink
Migrated to rollbar
Browse files Browse the repository at this point in the history
  • Loading branch information
rw251 committed Jan 22, 2020
1 parent b435d6c commit 039a583
Show file tree
Hide file tree
Showing 18 changed files with 7,389 additions and 8,730 deletions.
9 changes: 9 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Rollup",
"program": "${workspaceFolder}/node_modules/rollup/dist/bin/rollup",
"args": [
"-c"
]
},
{
"type": "node",
"request": "launch",
Expand Down
7 changes: 7 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
presets: [
[
'@babel/preset-env', { targets: { ie: '11' } },
],
],
};
42 changes: 42 additions & 0 deletions lib/bundle-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import path from 'path';

const findFileFromName = (bundle, name) => Object
.values(bundle).find(desc => (desc.name || '') === name);

const findMapFromName = (bundle, name) => findFileFromName(bundle, name).map;

const findHashFromName = (bundle, name) => findFileFromName(bundle, name).fileName;

const findChunkWithName = (bundle, name) => Object
.values(bundle).find(desc => (desc.facadeModuleId || '').endsWith(name));

const getCodeAndDependencies = (bundle, name) => {
const chunk = findChunkWithName(bundle, name);
const output = [chunk.code];

chunk.imports.forEach(dep => output.push(bundle[dep].code));

return output.join('\n');
};

const findAssetWithName = (bundle, name) => {
const parsedName = path.parse(name);

return Object.values(bundle).find((desc) => {
if (!desc.isAsset) return false;
const parsedGraphName = path.parse(desc.fileName);
if (parsedGraphName.ext !== parsedName.ext) return false;
if (!parsedGraphName.name.startsWith(parsedName.name)) return false;
const expectedHash = parsedGraphName.name.slice(parsedName.name.length);
return /^-[0-9a-f]+$/.test(expectedHash);
});
};

export {
findFileFromName,
findMapFromName,
findHashFromName,
findChunkWithName,
getCodeAndDependencies,
findAssetWithName,
};
37 changes: 37 additions & 0 deletions lib/create-html.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Custom rollup plugin for creating html pages
import { readFileSync } from 'fs';
import mustache from 'mustache';
import { findHashFromName } from './bundle-utils';
import { version } from '../package.json';

// oddly this needs to be relative to root
const { rollbarClientToken } = require('./src/server/config.js');

function generateShell(bundle, { templatePath, isDev }) {
const template = readFileSync(templatePath, 'utf8');
return mustache.to_html(template, {
isProduction: !isDev,
isDev,
rollbarClientToken,
scriptFile: findHashFromName(bundle, 'main'),
title: 'Get Set',
version,
});
}

export default function createHTMLPlugin({ isDev }) {
const templatePath = 'src/client/index.mustache';
return {
name: 'create-html-plugin',
buildStart() {
this.addWatchFile(templatePath);
},
async generateBundle(options, bundle) {
bundle['index.html'] = {
fileName: 'index.html',
isAsset: true,
source: await generateShell(bundle, { templatePath, isDev }),
};
},
};
}
Loading

0 comments on commit 039a583

Please sign in to comment.