Skip to content

Commit

Permalink
fix: make preview work
Browse files Browse the repository at this point in the history
  • Loading branch information
Niek Nijland authored and NiekBetty committed Nov 14, 2019
1 parent 30f652c commit 19c0bf7
Show file tree
Hide file tree
Showing 4 changed files with 5,489 additions and 11,669 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@babel/parser": "^7.5.5",
"@babel/traverse": "^7.5.5",
"@babel/types": "^7.5.5",
"@betty-blocks/preview": "^1.0.3",
"@betty-blocks/preview": "^1.0.4",
"@hapi/joi": "^16.1.4",
"@semantic-release/changelog": "^3.0.4",
"@semantic-release/git": "^7.0.16",
Expand Down
7 changes: 3 additions & 4 deletions src/bb-components-preview.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* npm dependencies */

import program, { CommanderStatic } from 'commander';
import { parseDir, parsePort } from './utils/arguments';
import { parsePort } from './utils/arguments';

import servePreview from './utils/servePreview';

Expand All @@ -13,9 +13,8 @@ program
.option('-p, --port [port]', 'Serve on a custom port. Defaults to 3001.')
.parse(process.argv);

const { args, port: portRaw }: CommanderStatic = program;
const rootDir: string = parseDir(args);
const { port: portRaw }: CommanderStatic = program;
const port: number = parsePort(portRaw, 3001);

/* execute command */
servePreview(rootDir, port);
servePreview(port);
8 changes: 6 additions & 2 deletions src/utils/servePreview.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { createServer, Server, IncomingMessage, ServerResponse } from 'http';
import handler from 'serve-handler';
import path from 'path';

export default (rootDir: string, port: number): void => {
export default (port: number): void => {
const server: Server = createServer(
(response: IncomingMessage, request: ServerResponse): Promise<void> =>
handler(response, request, {
public: `${rootDir}/node_modules/@betty-blocks/preview/build`,
public: path.join(
__dirname,
'../../node_modules/@betty-blocks/preview/build',
),
}),
);

Expand Down
Loading

0 comments on commit 19c0bf7

Please sign in to comment.