Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: port to ts #272

Merged
merged 10 commits into from Oct 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions .vscode/settings.json
@@ -1,4 +1,3 @@
{
"xo.enable": true,
"eslint.enable": true
"typescript.tsdk": "node_modules/typescript/lib"
}
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -103,6 +103,7 @@
"prettier": "^1.6.1",
"rimraf": "^2.6.2",
"serve": "7",
"ttypescript": "^1.5.5",
"xo": "^0.18.2",
"yarn": "^1.3.2"
},
Expand Down
1 change: 1 addition & 0 deletions packages/api/index.d.ts
@@ -0,0 +1 @@
export * from "./lib/api";
25 changes: 21 additions & 4 deletions packages/api/package.json
Expand Up @@ -4,7 +4,7 @@
"description": "Patternplate JSON API",
"scripts": {
"start": "yarn build -w",
"build": "babel -D src -d lib --source-maps --ignore **/*.test.js",
"build": "ttsc",
"clean": "rimraf lib",
"watch": "yarn build -w",
"deps": "dependency-check . lib/compiler-worker.js --missing && dependency-check . lib/compiler-worker.js --extra --no-dev"
Expand Down Expand Up @@ -40,10 +40,17 @@
]
},
"devDependencies": {
"@babel/cli": "^7.0.0-beta.40",
"@patternplate/babel-preset": "^2.5.18",
"@types/jest": "^23.3.2",
"babel-core": "^7.0.0-0",
"babel-jest": "^22.4.1",
"dependency-check": "^3.1.0",
"rimraf": "^2.6.2"
"fixturez": "^1.1.0",
"jest": "^23.6.0",
"jest-cli": "^23.6.0",
"rimraf": "^2.6.2",
"ts-jest": "^23.10.3",
"ttypescript": "^1.5.5",
"typescript": "^3.1.1"
},
"dependencies": {
"@marionebl/sander": "^0.6.1",
Expand All @@ -52,6 +59,15 @@
"@patternplate/load-docs": "^2.5.18",
"@patternplate/load-meta": "^3.0.4",
"@patternplate/validate-config": "^3.0.3",
"@types/chokidar": "^1.7.5",
"@types/dargs": "^5.1.0",
"@types/express": "^4.16.0",
"@types/glob-parent": "^3.1.0",
"@types/memory-fs": "^0.3.2",
"@types/micromatch": "^3.1.0",
"@types/string-hash": "^1.1.1",
"@types/ws": "^6.0.1",
"@types/zen-observable": "^0.8.0",
"aggregate-error": "^1.0.0",
"arson": "^0.2.6",
"chokidar": "^1.7.0",
Expand All @@ -64,6 +80,7 @@
"require-from-string": "^2.0.1",
"resolve-pkg": "^1.0.0",
"string-hash": "^1.1.3",
"ts-transform-json-schema": "^1.1.2",
"unindent": "^2.0.0",
"ws": "^4.0.0",
"yargs-parser": "^9.0.2",
Expand Down
54 changes: 0 additions & 54 deletions packages/api/src/api.js

This file was deleted.

64 changes: 64 additions & 0 deletions packages/api/src/api.ts
@@ -0,0 +1,64 @@
import * as ws from "ws";
import * as express from "express";
import * as Http from "http";
import * as Types from "@patternplate/types";
import * as T from "./types";
import * as Routes from "./routes";
import { createSubscription } from "./create-subscription";
import { createCompiler } from "./create-compiler";

const { createWatcher } = require("./create-watcher");

export interface ApiApplication {
middleware: express.Express;
subscribe(h: (msg: T.QueueMessage) => void): void;
unsubscribe(): void;
}

export interface ApiOptions {
cwd: string;
config: Types.PatternplateConfig;
server: Http.Server;
}

export async function api({ server, config, cwd }: ApiOptions): Promise<ApiApplication> {
const [clientQueue, serverQueue] = await Promise.all([
createCompiler({ config, cwd, target: Types.CompileTarget.Web }),
createCompiler({ config, cwd, target: Types.CompileTarget.Node })
]);

const queues = {
client: clientQueue,
server: serverQueue
};

const watcher = await createWatcher({ config, cwd });
const wss = new ws.Server({ server });

const routeOptions = { config, cwd, queue: queues.server };

const middleware = express()
.get("/state.json", await Routes.main(routeOptions))
.get("/demo/*.html", await Routes.demo(routeOptions))
.get("/cover.html", await Routes.cover(routeOptions))
.use(await Routes.scripts({ config, cwd, queue: queues.client }));

return {
middleware,
subscribe: createSubscription({
cwd,
config,
queues,
wss,
watcher
}),
unsubscribe: () => {
watcher.stop();
serverQueue.stop();
clientQueue.stop();
wss.clients.forEach(client => {
client.close();
});
}
};
}
93 changes: 0 additions & 93 deletions packages/api/src/compiler-worker.js

This file was deleted.