-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(demos): use js files for the demo server code
Since ts-node does not support project references we use js files with jsdoc type annotations instead.
- Loading branch information
1 parent
07e1c57
commit a5d1fed
Showing
17 changed files
with
164 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import {Css} from '@feature-hub/react'; | ||
import express from 'express'; | ||
|
||
export interface AppRendererOptions { | ||
readonly port: number; | ||
readonly req: express.Request; | ||
} | ||
|
||
export interface AppRendererResult { | ||
readonly html: string; | ||
readonly serializedStates?: string; | ||
readonly stylesheetsForSsr?: Map<string, Css>; | ||
readonly urlsForHydration?: Set<string>; | ||
} | ||
|
||
export type AppRenderer = ( | ||
options: AppRendererOptions | ||
) => Promise<AppRendererResult>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// @ts-check | ||
|
||
/** | ||
* @param {string} source | ||
* @return {any} | ||
*/ | ||
function evalNodeSource(source) { | ||
const mod = {exports: {}}; | ||
|
||
// tslint:disable-next-line:function-constructor | ||
Function('module', 'exports', 'require', source)(mod, mod.exports, require); | ||
|
||
return mod.exports; | ||
} | ||
|
||
/** | ||
* @param {import('express').Response} res | ||
* @param {string} nodeIntegratorFilename | ||
* @return {import('./app-renderer').AppRenderer | undefined} | ||
*/ | ||
function loadNodeIntegrator(res, nodeIntegratorFilename) { | ||
try { | ||
/** @type {import('webpack').InputFileSystem & import('webpack').OutputFileSystem} */ | ||
const outputFileSystem = res.locals.webpack.devMiddleware.outputFileSystem; | ||
|
||
/** @type {import('webpack').Stats.ToJsonOutput} */ | ||
const {outputPath} = res.locals.webpack.devMiddleware.stats.toJson(); | ||
|
||
if (!outputPath) { | ||
return undefined; | ||
} | ||
|
||
const source = outputFileSystem | ||
.readFileSync(outputFileSystem.join(outputPath, nodeIntegratorFilename)) | ||
.toString(); | ||
|
||
return evalNodeSource(source).default; | ||
} catch { | ||
return undefined; | ||
} | ||
} | ||
|
||
module.exports = {loadNodeIntegrator}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// @ts-check | ||
|
||
const {startServer} = require('./start-server'); | ||
|
||
const demoName = process.argv[2]; | ||
|
||
/** | ||
* @return {import('webpack').Configuration[]} | ||
*/ | ||
function loadWebpackConfigs() { | ||
/** @type {import('webpack').Configuration[]} */ | ||
const configs = require(`./${demoName}/webpack-config`); | ||
|
||
for (const config of configs) { | ||
config.devtool = 'source-map'; | ||
} | ||
|
||
return configs; | ||
} | ||
|
||
/** | ||
* @return {import('webpack').Configuration | undefined} | ||
*/ | ||
function loadNodeIntegratorWebpackConfig() { | ||
try { | ||
/** @type {import('webpack').Configuration} */ | ||
const config = require(`./${demoName}/webpack-config.node`); | ||
|
||
config.devtool = 'source-map'; | ||
|
||
return config; | ||
} catch { | ||
return undefined; | ||
} | ||
} | ||
|
||
startServer(loadWebpackConfigs(), loadNodeIntegratorWebpackConfig(), demoName) | ||
.then((server) => { | ||
const {port} = /** @type {import('net').AddressInfo} */ (server.address()); | ||
|
||
console.log(`The ${demoName} demo is running at: http://localhost:${port}`); | ||
}) | ||
.catch((error) => { | ||
console.error(error); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.