Skip to content

Commit 75e8734

Browse files
author
MICHAEL JACKSON
committed
Keep files in modules dir
1 parent 5fe65b6 commit 75e8734

File tree

8 files changed

+42
-38
lines changed

8 files changed

+42
-38
lines changed

bin/react-stdio

-2
This file was deleted.
File renamed without changes.

__tests__/server-test.js modules/__tests__/server-test.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@ describe("server", () => {
55
let proc;
66

77
beforeEach(() => {
8-
proc = childProcess.spawn(
9-
path.join(__dirname, "..", "bin", "react-stdio"),
10-
{
11-
stdio: "pipe"
12-
}
13-
);
8+
proc = childProcess.spawn(path.join(__dirname, "..", "cli.js"), {
9+
stdio: "pipe"
10+
});
1411
});
1512

1613
afterEach(() => {

modules/cli.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env node
2+
3+
const EventStream = require("event-stream");
4+
const JSONStream = require("JSONStream");
5+
const createRequestHandler = require("./index").createRequestHandler;
6+
7+
// Redirect stdout to stderr, but save a reference so we can
8+
// still write to stdout.
9+
const stdout = process.stdout;
10+
Object.defineProperty(process, "stdout", {
11+
configurable: true,
12+
enumerable: true,
13+
value: process.stderr
14+
});
15+
16+
// Ensure console.log knows about the new stdout.
17+
const Console = require("console").Console;
18+
Object.defineProperty(global, "console", {
19+
configurable: true,
20+
enumerable: true,
21+
value: new Console(process.stdout, process.stderr)
22+
});
23+
24+
// Read JSON blobs from stdin, pipe output to stdout.
25+
process.stdin
26+
.pipe(JSONStream.parse())
27+
.pipe(EventStream.map(createRequestHandler(process.cwd())))
28+
.pipe(stdout);

server.js modules/index.js

+3-24
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
const path = require("path");
22
const invariant = require("invariant");
3-
const EventStream = require("event-stream");
4-
const JSONStream = require("JSONStream");
53
const ReactDOMServer = require("react-dom/server");
64
const React = require("react");
75

@@ -96,25 +94,6 @@ function createRequestHandler(workingDir) {
9694
};
9795
}
9896

99-
// Redirect stdout to stderr, but save a reference so we can
100-
// still write to stdout.
101-
const stdout = process.stdout;
102-
Object.defineProperty(process, "stdout", {
103-
configurable: true,
104-
enumerable: true,
105-
value: process.stderr
106-
});
107-
108-
// Ensure console.log knows about the new stdout.
109-
const Console = require("console").Console;
110-
Object.defineProperty(global, "console", {
111-
configurable: true,
112-
enumerable: true,
113-
value: new Console(process.stdout, process.stderr)
114-
});
115-
116-
// Read JSON blobs from stdin, pipe output to stdout.
117-
process.stdin
118-
.pipe(JSONStream.parse())
119-
.pipe(EventStream.map(createRequestHandler(process.cwd())))
120-
.pipe(stdout);
97+
module.exports = {
98+
createRequestHandler
99+
};

package.json

+7-5
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
"description": "Render React.js components on any backend",
55
"author": "Michael Jackson",
66
"license": "MIT",
7-
"bin": "./bin/react-stdio",
8-
"preferGlobal": true,
9-
"repository": "ReactTraining/react-stdio",
7+
"bin": {
8+
"react-stdio": "./modules/cli.js"
9+
},
1010
"files": [
11-
"bin",
12-
"server.js"
11+
"modules/cli.js",
12+
"modules/index.js"
1313
],
14+
"preferGlobal": true,
15+
"repository": "ReactTraining/react-stdio",
1416
"scripts": {
1517
"build": "./scripts/build.sh",
1618
"test": "jest"

scripts/build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ do
1313

1414
echo "Creating $archive build..."
1515

16-
pkg bin/react-stdio -t $platform -o build/$archive/react-stdio
16+
pkg modules/cli.js -t $platform -o build/$archive/react-stdio
1717
echo "$tag" > build/$archive/version
1818

1919
cd build

0 commit comments

Comments
 (0)