Add more tests
This commit is contained in:
@ -4,13 +4,8 @@ import semver from 'semver';
|
||||
import AutoIndexApp from '../client/autoIndex/App.js';
|
||||
|
||||
import MainTemplate from './utils/MainTemplate.js';
|
||||
import getEntryPoint from './utils/getEntryPoint.js';
|
||||
import getGlobalScripts from './utils/getGlobalScripts.js';
|
||||
import {
|
||||
createElement,
|
||||
createHTML,
|
||||
createScript
|
||||
} from './utils/markupHelpers.js';
|
||||
import getScripts from './utils/getScripts.js';
|
||||
import { createElement, createHTML } from './utils/markupHelpers.js';
|
||||
|
||||
const doctype = '<!DOCTYPE html>';
|
||||
const globalURLs =
|
||||
@ -40,10 +35,7 @@ export default function serveAutoIndexPage(req, res) {
|
||||
entries: req.entries
|
||||
};
|
||||
const content = createHTML(renderToString(createElement(AutoIndexApp, data)));
|
||||
const entryPoint = getEntryPoint('autoIndex', 'iife');
|
||||
const elements = getGlobalScripts(entryPoint, globalURLs).concat(
|
||||
createScript(entryPoint.code)
|
||||
);
|
||||
const elements = getScripts('autoIndex', 'iife', globalURLs);
|
||||
|
||||
const html =
|
||||
doctype +
|
||||
|
||||
@ -3,13 +3,8 @@ import { renderToString, renderToStaticMarkup } from 'react-dom/server';
|
||||
import MainApp from '../client/main/App.js';
|
||||
|
||||
import MainTemplate from './utils/MainTemplate.js';
|
||||
import getEntryPoint from './utils/getEntryPoint.js';
|
||||
import getGlobalScripts from './utils/getGlobalScripts.js';
|
||||
import {
|
||||
createElement,
|
||||
createHTML,
|
||||
createScript
|
||||
} from './utils/markupHelpers.js';
|
||||
import getScripts from './utils/getScripts.js';
|
||||
import { createElement, createHTML } from './utils/markupHelpers.js';
|
||||
|
||||
const doctype = '<!DOCTYPE html>';
|
||||
const globalURLs =
|
||||
@ -27,10 +22,7 @@ const globalURLs =
|
||||
|
||||
export default function serveMainPage(req, res) {
|
||||
const content = createHTML(renderToString(createElement(MainApp)));
|
||||
const entryPoint = getEntryPoint('main', 'iife');
|
||||
const elements = getGlobalScripts(entryPoint, globalURLs).concat(
|
||||
createScript(entryPoint.code)
|
||||
);
|
||||
const elements = getScripts('main', 'iife', globalURLs);
|
||||
|
||||
const html =
|
||||
doctype +
|
||||
|
||||
@ -1,18 +0,0 @@
|
||||
// Virtual module id; see rollup.config.js
|
||||
// eslint-disable-next-line import/no-unresolved
|
||||
import entryManifest from 'entry-manifest';
|
||||
|
||||
export default function getEntryPoint(name, format) {
|
||||
let entryPoints;
|
||||
entryManifest.forEach(manifest => {
|
||||
if (name in manifest) {
|
||||
entryPoints = manifest[name];
|
||||
}
|
||||
});
|
||||
|
||||
if (entryPoints) {
|
||||
return entryPoints.find(e => e.format === format);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@ -1,13 +0,0 @@
|
||||
import { createElement } from './markupHelpers.js';
|
||||
|
||||
export default function getGlobalScripts(entryPoint, globalURLs) {
|
||||
return entryPoint.globalImports.map(id => {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
if (!globalURLs[id]) {
|
||||
throw new Error('Missing global URL for id "%s"', id);
|
||||
}
|
||||
}
|
||||
|
||||
return createElement('script', { src: globalURLs[id] });
|
||||
});
|
||||
}
|
||||
42
modules/actions/utils/getScripts.js
Normal file
42
modules/actions/utils/getScripts.js
Normal file
@ -0,0 +1,42 @@
|
||||
// Virtual module id; see rollup.config.js
|
||||
// eslint-disable-next-line import/no-unresolved
|
||||
import entryManifest from 'entry-manifest';
|
||||
|
||||
import { createElement, createScript } from './markupHelpers.js';
|
||||
|
||||
function getEntryPoint(name, format) {
|
||||
let entryPoints;
|
||||
entryManifest.forEach(manifest => {
|
||||
if (name in manifest) {
|
||||
entryPoints = manifest[name];
|
||||
}
|
||||
});
|
||||
|
||||
if (entryPoints) {
|
||||
return entryPoints.find(e => e.format === format);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function getGlobalScripts(entryPoint, globalURLs) {
|
||||
return entryPoint.globalImports.map(id => {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
if (!globalURLs[id]) {
|
||||
throw new Error('Missing global URL for id "%s"', id);
|
||||
}
|
||||
}
|
||||
|
||||
return createElement('script', { src: globalURLs[id] });
|
||||
});
|
||||
}
|
||||
|
||||
export default function getScripts(entryName, format, globalURLs) {
|
||||
const entryPoint = getEntryPoint(entryName, format);
|
||||
|
||||
if (!entryPoint) return [];
|
||||
|
||||
return getGlobalScripts(entryPoint, globalURLs).concat(
|
||||
createScript(entryPoint.code)
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user