Skip to content

Commit

Permalink
[experiments] Fix up experiment paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
lgarron committed Jul 22, 2021
1 parent f1b28ff commit df01daa
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 31 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ jobs:
- run: make build
- run: make test-dist-esm-node-import
- run: make test-dist-esm-perf
- run: make build-experiments
- run: make build-site-twizzle
- run: make build-site-experiments
- run: make test-dist-experiments
# - run: make parcel-build-for-twizzle-net
- run: make test-dist-esm-parcel
- run: make clean
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# https://github.com/lgarron/Makefile-scripts

# Note: the first command becomes the default `make` target.
NPM_COMMANDS = build build-esm build-bundle-global build-types build-bin build-site-twizzle build-site-experiments build-search-worker generate-js generate-js-parsers generate-js-svg dev clean test test-dist-esm-node-import test-dist-esm-parcel test-dist-esm-perf test-dist-experiments test-import-restrictions test-jest test-tsc format setup lint prepack parcel-build-for-twizzle-net
NPM_COMMANDS = build build-esm build-bundle-global build-types build-bin build-site-twizzle build-sites build-site-experiments build-search-worker generate-js generate-js-parsers generate-js-svg dev clean test test-dist-esm-node-import test-dist-esm-parcel test-dist-esm-perf test-dist-experiments test-import-restrictions test-jest test-tsc format setup lint prepack parcel-build-for-twizzle-net

.PHONY: $(NPM_COMMANDS)
$(NPM_COMMANDS):
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
If you want to display algs or solves, the following code is a good way to get started:

```html
<script src="https://cdn.cubing.net/esm/cubing/twisty" type="module" defer></script>
<script
src="https://cdn.cubing.net/esm/cubing/twisty"
type="module"
defer
></script>
<twisty-player alg="R U R' U R U2' R'"></twisty-player>
```

Expand All @@ -29,7 +33,7 @@ npm install
make dev
```

This should open [the `experiments` root file](./src/experiments/index.html) at http://localhost:3333/ automatically. Any source code changes will refresh the browser. We don't yet have a development guide, so you'll have to search the code to find where features are implemented.
This should open [the `ites` root file](./src/sites/index.html) at http://localhost:3333/ automatically. Any source code changes will refresh the browser. We don't yet have a development guide, so you'll have to search the code to find where features are implemented.

The core library code for `cubing.js` is in [`src/cubing`](./src/cubing/) To test changes, use:

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"build-bundle-global": "node ./script/build/main.js bundle-global",
"build-types": "node ./script/build/main.js types",
"build-bin": "node ./script/build/main.js bin",
"build-sites": "npm run build-site-twizzle && npm run build-site-experiments",
"build-site-twizzle": "node ./script/build/main.js twizzle",
"build-site-experiments": "node ./script/build/main.js experiments",
"build-search-worker": "node ./script/build/main.js search-worker",
Expand Down
3 changes: 2 additions & 1 deletion script/bin/screenshot/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { startServer } from "../../lib/experiments-server/index.js";

const PAGE_URL = "http://localhost:4443/cubing.js/screenshot/index.html";
const PAGE_URL =
"http://localhost:4443/experiments.cubing.net/cubing.js/screenshot/";

startServer();

Expand Down
35 changes: 17 additions & 18 deletions script/lib/experiments-server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,30 @@ import { createServer } from "http";
import { extname, join } from "path";
import { needFolder } from "../need-folder.js";

const FILE_ROOT = "../../../dist/experiments/";
const DIST_SITES_ROOT = "../../../dist/sites/";

const FILE_ROOT_EXPANDED = new URL(FILE_ROOT, import.meta.url).pathname;
needFolder(FILE_ROOT_EXPANDED, "make build-experiments");
const DIST_SITES_ROOT_EXPANDED = new URL(DIST_SITES_ROOT, import.meta.url)
.pathname;
needFolder(
join(DIST_SITES_ROOT_EXPANDED, "alpha.twizzle.net"),
"make build-sites",
);
needFolder(
join(DIST_SITES_ROOT_EXPANDED, "experiments.cubing.net/cubing.js"),
"make build-sites",
);

export function startServer(port) {
port ??= 4443;
console.log("Starting server.");
createServer(function (request, response) {
console.log("request ", request.url);

const normalizedURL = new URL(request.url, "http://test/").pathname;
let segments = normalizedURL.split("/");
const topPath = segments.splice(1, 1)[0];
const remainingPath = segments.join("/");
const normalizedPath = new URL(request.url, "http://test/").pathname;

let filePath;
if (topPath === "cubing.js") {
filePath = new URL(join(FILE_ROOT, remainingPath), import.meta.url)
.pathname;
} else {
response.writeHead(404, { "Content-Type": "text/html" });
response.end("bad path", "utf-8");
return;
}
filePath = new URL(
join(DIST_SITES_ROOT_EXPANDED, normalizedPath),
import.meta.url,
).pathname;

if (filePath.endsWith("/")) {
filePath += "index.html";
Expand Down Expand Up @@ -58,7 +57,7 @@ export function startServer(port) {

readFile(filePath, function (error, content) {
if (error) {
if (error.code === "ENOENT") {
if (["ENOENT", "EISDIR"].includes(error.code)) {
readFile("./404.html", function (_error, content) {
response.writeHead(404, { "Content-Type": "text/html" });
response.end(content, "utf-8");
Expand Down
2 changes: 1 addition & 1 deletion script/test/dist/experiments/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async function runTest() {
height: 1024,
});

await page.goto("http://localhost:4443/cubing.js/twizzle/index.html?alg=R");
await page.goto("http://localhost:4443/alpha.twizzle.net/explore/?alg=R");
// await page.screenshot({
// path: "out.png",
// omitBackground: true,
Expand Down
13 changes: 7 additions & 6 deletions src/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
This folder contains:

| Folder | Contents |
| --------------------------------- | ----------------------------------------------------------------------------------------------- |
| [`./cubing`](./cubing/) | Source code for all `cubing/*` modules |
| [`./experiments`](./experiments/) | Source code for development code.<br>Also hosted at <https://experiments.cubing.net/cubing.js/> |
| [`./static`](./static/) | Code needed for `npm` module publication. |
| [`./bin`](./bin/) | Code for binaries developed in sync with the library code |
| Folder | Contents |
| --------------------------------------------------------------------------------------- | --------------------------------------------------------- |
| [`./cubing`](./cubing/) | Source code for all `cubing/*` modules |
| [`./sites/alpha.twizzle.net`](./sites/alpha.twizzle.net/) | Twizzle source. |
| [`./sites/experiments.cubing.net/cubing.js`](./sites/experiments.cubing.net/cubing.js/) | Dev experiments. |
| [`./static`](./static/) | Code needed for `npm` module publication. |
| [`./bin`](./bin/) | Code for binaries developed in sync with the library code |

0 comments on commit df01daa

Please sign in to comment.