Repository: pmcelhaney/counterfact
Pull request #268 (2022-10-11 19:54:25)

move server src
- move the server code into a subdirectory
- remove the changeset that was created for testing



Patch:
diff --git a/.changeset/chilly-students-visit.md b/.changeset/chilly-students-visit.md
deleted file mode 100644
index 2a37357..0000000
--- a/.changeset/chilly-students-visit.md
+++ /dev/null
@@ -1,5 +0,0 @@
----
-"counterfact": patch
----
-
-(GH Actions is having issues. This is just to make sure the release workflow kicks off.)
diff --git a/bin/counterfact.js b/bin/counterfact.js
index 052e493..9fce2e6 100755
--- a/bin/counterfact.js
+++ b/bin/counterfact.js
@@ -6,7 +6,7 @@ import { program } from "commander";
 import open from "open";
 
 import { generate } from "../src/typescript-generator/generate.js";
-import { start } from "../src/start.js";
+import { start } from "../src/server/start.js";
 
 const DEFAULT_PORT = 3100;
 
diff --git a/src/context-registry.js b/src/server/context-registry.js
similarity index 100%
rename from src/context-registry.js
rename to src/server/context-registry.js
diff --git a/src/counterfact.js b/src/server/counterfact.js
similarity index 93%
rename from src/counterfact.js
rename to src/server/counterfact.js
index ef1993d..6d9bc19 100644
--- a/src/counterfact.js
+++ b/src/server/counterfact.js
@@ -6,7 +6,8 @@ import os from "node:os";
 import $RefParser from "json-schema-ref-parser";
 import yaml from "js-yaml";
 
-import { readFile } from "./read-file.js";
+import { readFile } from "../util/read-file.js";
+
 import { Registry } from "./registry.js";
 import { Dispatcher } from "./dispatcher.js";
 import { koaMiddleware } from "./koa-middleware.js";
@@ -39,7 +40,7 @@ export async function counterfact(
   )}/`;
 
   fs.copyFile(
-    nodePath.join(__dirname, "../templates/response-builder-factory.ts"),
+    nodePath.join(__dirname, "../../templates/response-builder-factory.ts"),
     nodePath.join(basePath, "response-builder-factory.ts")
   );
 
diff --git a/src/dispatcher.js b/src/server/dispatcher.js
similarity index 100%
rename from src/dispatcher.js
rename to src/server/dispatcher.js
diff --git a/src/koa-middleware.js b/src/server/koa-middleware.js
similarity index 100%
rename from src/koa-middleware.js
rename to src/server/koa-middleware.js
diff --git a/src/module-loader.js b/src/server/module-loader.js
similarity index 100%
rename from src/module-loader.js
rename to src/server/module-loader.js
diff --git a/src/registry.js b/src/server/registry.js
similarity index 100%
rename from src/registry.js
rename to src/server/registry.js
diff --git a/src/response-builder.js b/src/server/response-builder.js
similarity index 100%
rename from src/response-builder.js
rename to src/server/response-builder.js
diff --git a/src/start.js b/src/server/start.js
similarity index 98%
rename from src/start.js
rename to src/server/start.js
index aad2a50..97eaeef 100644
--- a/src/start.js
+++ b/src/server/start.js
@@ -5,8 +5,9 @@ import bodyParser from "koa-bodyparser";
 import { koaSwagger } from "koa2-swagger-ui";
 import yaml from "js-yaml";
 
+import { readFile } from "../util/read-file.js";
+
 import { counterfact } from "./counterfact.js";
-import { readFile } from "./read-file.js";
 
 const DEFAULT_PORT = 3100;
 
diff --git a/src/tools.js b/src/server/tools.js
similarity index 100%
rename from src/tools.js
rename to src/server/tools.js
diff --git a/src/transpiler.js b/src/server/transpiler.js
similarity index 100%
rename from src/transpiler.js
rename to src/server/transpiler.js
diff --git a/src/typescript-generator/specification.js b/src/typescript-generator/specification.js
index 8312d0c..541ed05 100644
--- a/src/typescript-generator/specification.js
+++ b/src/typescript-generator/specification.js
@@ -2,7 +2,7 @@ import nodePath from "node:path";
 
 import yaml from "js-yaml";
 
-import { readFile } from "../read-file.js";
+import { readFile } from "../util/read-file.js";
 
 import { Requirement } from "./requirement.js";
 


Test patch:
diff --git a/src/read-file.js b/src/util/read-file.js
similarity index 100%
rename from src/read-file.js
rename to src/util/read-file.js
diff --git a/test/context-registry.test.js b/test/server/context-registry.test.js
similarity index 95%
rename from test/context-registry.test.js
rename to test/server/context-registry.test.js
index 2713737..ba6a892 100644
--- a/test/context-registry.test.js
+++ b/test/server/context-registry.test.js
@@ -1,4 +1,7 @@
-import { ContextRegistry, parentPath } from "../src/context-registry.js";
+import {
+  ContextRegistry,
+  parentPath,
+} from "../../src/server/context-registry.js";
 
 describe("moduleRegistry", () => {
   it("finds a context that exactly matches the path", () => {
diff --git a/test/counterfact.test.js b/test/server/counterfact.test.js
similarity index 94%
rename from test/counterfact.test.js
rename to test/server/counterfact.test.js
index a2d5ba5..c6c6bdb 100644
--- a/test/counterfact.test.js
+++ b/test/server/counterfact.test.js
@@ -1,9 +1,8 @@
 import supertest from "supertest";
 import Koa from "koa";
 
-import { counterfact } from "../src/counterfact.js";
-
-import { withTemporaryFiles } from "./lib/with-temporary-files.js";
+import { counterfact } from "../../src/server/counterfact.js";
+import { withTemporaryFiles } from "../lib/with-temporary-files.js";
 
 describe("integration test", () => {
   it("finds a path", async () => {
diff --git a/test/dispatcher.test.js b/test/server/dispatcher.test.js
similarity index 98%
rename from test/dispatcher.test.js
rename to test/server/dispatcher.test.js
index af88fc4..30de506 100644
--- a/test/dispatcher.test.js
+++ b/test/server/dispatcher.test.js
@@ -1,6 +1,6 @@
-import { Dispatcher } from "../src/dispatcher.js";
-import { ContextRegistry } from "../src/context-registry.js";
-import { Registry } from "../src/registry.js";
+import { Dispatcher } from "../../src/server/dispatcher.js";
+import { ContextRegistry } from "../../src/server/context-registry.js";
+import { Registry } from "../../src/server/registry.js";
 
 describe("a dispatcher", () => {
   it("dispatches a get request to a server and returns the response", async () => {
diff --git a/test/koa-middleware.test.js b/test/server/koa-middleware.test.js
similarity index 81%
rename from test/koa-middleware.test.js
rename to test/server/koa-middleware.test.js
index 658446c..177027c 100644
--- a/test/koa-middleware.test.js
+++ b/test/server/koa-middleware.test.js
@@ -1,7 +1,7 @@
-import { Registry } from "../src/registry.js";
-import { Dispatcher } from "../src/dispatcher.js";
-import { koaMiddleware } from "../src/koa-middleware.js";
-import { ContextRegistry } from "../src/context-registry.js";
+import { Registry } from "../../src/server/registry.js";
+import { Dispatcher } from "../../src/server/dispatcher.js";
+import { koaMiddleware } from "../../src/server/koa-middleware.js";
+import { ContextRegistry } from "../../src/server/context-registry.js";
 
 describe("koa middleware", () => {
   it("passes the request to the dispatcher and returns the response", async () => {
diff --git a/test/module-loader.test.js b/test/server/module-loader.test.js
similarity index 94%
rename from test/module-loader.test.js
rename to test/server/module-loader.test.js
index 6be6770..82e4e24 100644
--- a/test/module-loader.test.js
+++ b/test/server/module-loader.test.js
@@ -1,10 +1,9 @@
 import { once } from "node:events";
 
-import { ModuleLoader } from "../src/module-loader.js";
-import { Registry } from "../src/registry.js";
-import { ContextRegistry } from "../src/context-registry.js";
-
-import { withTemporaryFiles } from "./lib/with-temporary-files.js";
+import { ModuleLoader } from "../../src/server/module-loader.js";
+import { Registry } from "../../src/server/registry.js";
+import { ContextRegistry } from "../../src/server/context-registry.js";
+import { withTemporaryFiles } from "../lib/with-temporary-files.js";
 
 describe("a module loader", () => {
   it("finds a file and adds it to the registry", async () => {
diff --git a/test/registry.test.js b/test/server/registry.test.js
similarity index 97%
rename from test/registry.test.js
rename to test/server/registry.test.js
index ae8791a..3e9cd65 100644
--- a/test/registry.test.js
+++ b/test/server/registry.test.js
@@ -1,4 +1,4 @@
-import { Registry } from "../src/registry.js";
+import { Registry } from "../../src/server/registry.js";
 
 describe("a scripted server", () => {
   it("knows if a handler exists for a request method at a path", () => {
diff --git a/test/response-builder.test.js b/test/server/response-builder.test.js
similarity index 97%
rename from test/response-builder.test.js
rename to test/server/response-builder.test.js
index 90eb575..b95ceb9 100644
--- a/test/response-builder.test.js
+++ b/test/server/response-builder.test.js
@@ -1,4 +1,4 @@
-import { createResponseBuilder } from "../src/response-builder.js";
+import { createResponseBuilder } from "../../src/server/response-builder.js";
 
 describe("a response builder", () => {
   it("starts building a response object when the status is selected", () => {
diff --git a/test/start.test.js b/test/server/start.test.js
similarity index 77%
rename from test/start.test.js
rename to test/server/start.test.js
index 7017d61..f7139c2 100644
--- a/test/start.test.js
+++ b/test/server/start.test.js
@@ -1,4 +1,4 @@
-import { landingPageBody } from "../src/start.js";
+import { landingPageBody } from "../../src/server/start.js";
 
 describe("start", () => {
   it("renders the landing page", () => {
diff --git a/test/tools.test.js b/test/server/tools.test.js
similarity index 96%
rename from test/tools.test.js
rename to test/server/tools.test.js
index ae59180..577fb45 100644
--- a/test/tools.test.js
+++ b/test/server/tools.test.js
@@ -1,4 +1,4 @@
-import { Tools } from "../src/tools.js";
+import { Tools } from "../../src/server/tools.js";
 
 describe("tools", () => {
   it("oneOf()", () => {
diff --git a/test/transpiler.test.js b/test/server/transpiler.test.js
similarity index 95%
rename from test/transpiler.test.js
rename to test/server/transpiler.test.js
index 8b811df..58154e8 100644
--- a/test/transpiler.test.js
+++ b/test/server/transpiler.test.js
@@ -2,9 +2,8 @@ import { once } from "node:events";
 import fs from "node:fs/promises";
 import { constants as fsConstants } from "node:fs";
 
-import { Transpiler } from "../src/transpiler.js";
-
-import { withTemporaryFiles } from "./lib/with-temporary-files.js";
+import { Transpiler } from "../../src/server/transpiler.js";
+import { withTemporaryFiles } from "../lib/with-temporary-files.js";
 
 const TYPESCRIPT_SOURCE = "const x:number = 1;\n";
 const JAVASCRIPT_SOURCE = "var x = 1;\n";