Skip to content

Commit

Permalink
Merge pull request #60 from webxdc/adb/check-with-prettier
Browse files Browse the repository at this point in the history
enforce prettier
  • Loading branch information
adbenitez authored Nov 16, 2024
2 parents a8f641d + 3a94b89 commit 6aab7a3
Show file tree
Hide file tree
Showing 37 changed files with 391 additions and 318 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: npm ci --ignore-scripts
- run: npm run check
- run: npm run build
- name: Publish package to NPM
if: startsWith(github.ref, 'refs/tags/v')
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
dist
*~
2 changes: 0 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,6 @@ release date when you use `npm version` (see `README.md`).
[0.15.0]: https://github.com/webxdc/webxdc-dev/tree/v0.15.0
[unreleased]: https://github.com/webxdc/webxdc-dev/compare/v0.15.1...HEAD
[0.15.1]: https://github.com/webxdc/webxdc-dev/tree/v0.15.1


[Unreleased]: https://github.com/webxdc/webxdc-dev/compare/v0.18.0...HEAD
[0.18.0]: https://github.com/webxdc/webxdc-dev/compare/v0.17.0...v0.18.0
[0.17.0]: https://github.com/webxdc/webxdc-dev/compare/v0.16.0...v0.17.0
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# webxdc-dev

[![CI](https://github.com/webxdc/webxdc-dev/actions/workflows/ci.yml/badge.svg)](https://github.com/webxdc/webxdc-dev/actions/workflows/ci.yml)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)

webxdc-dev is a development server for [webxdc apps](https://webxdc.org).
Easily test your app's behavior as if it was shared in a real chat with
multiple people.

![example screenshot](https://raw.githubusercontent.com/webxdc/webxdc-dev/main/screenshot.png)


In contrast to [hello](https://github.com/webxdc/hello), each "user"'s app
instance gets its own isolated state (e.g. `localStorage`), since each is
served from a separate port (therefore a separate origin).
Expand Down Expand Up @@ -80,7 +80,7 @@ to see full information. You can also filter messages. There is also a "chat"
tab which you can use to see `info` contained in updates as well as any
`summary` text contained in an update.

The sidebar can be closed with `Close Messages` button within the sidebar and
The sidebar can be closed with `Close Messages` button within the sidebar and
expanded by clicking on `Open Messages` within the devices tab.
The sidebars width can also be adjusted by moving the separating line between
devices and sidebar.
Expand Down
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
## Node version

- Can I warn when the node version is too old upon installation.

## Messages

- Perhaps default message filter should see connect & sent at the same time?
Expand Down
18 changes: 8 additions & 10 deletions backend/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function createFrontend(
appInfo: AppInfo,
instances: Instances,
injectFrontend: InjectExpress,
getIndexHtml: () => string
getIndexHtml: () => string,
): expressWs.Application {
const expressApp = express();
const wsInstance = expressWs(expressApp);
Expand Down Expand Up @@ -57,9 +57,7 @@ export function createFrontend(
res.send(appInfo.icon.buffer);
});
app.get<{}, Instance[]>("/instances", (req, res) => {
res.json(
instances.list()
);
res.json(instances.list());
});
app.post<{}, Instance>("/instances", (req, res) => {
const instance = instances.add();
Expand All @@ -71,9 +69,9 @@ export function createFrontend(
color: instance.color,
});
});
app.delete<{id: string}, Instance[]>("/instances/:id", (req, res) => {
app.delete<{ id: string }, Instance[]>("/instances/:id", (req, res) => {
instances.delete(parseInt(req.params.id));
res.json(instances.list())
res.json(instances.list());
});

app.post<{}, { status: string }>("/clear", (req, res) => {
Expand Down Expand Up @@ -126,7 +124,7 @@ export function createPeer(options: PeerOptions): expressWs.Instance {
wsInstance.app.use((req, res, next) => {
const contentSecurityPolicy = getContentSecurityPolicy(
location,
options.instanceUrl
options.instanceUrl,
);
res.setHeader("Content-Security-Policy", contentSecurityPolicy);
next();
Expand All @@ -144,7 +142,7 @@ export function createPeer(options: PeerOptions): expressWs.Instance {
createProxyMiddleware(filter, {
target: location.url,
ws: false,
})
}),
);
} else {
// serve webxdc project from directory
Expand All @@ -155,7 +153,7 @@ export function createPeer(options: PeerOptions): expressWs.Instance {

function getContentSecurityPolicy(
location: Location,
instanceUrl: string
instanceUrl: string,
): string {
const connectSrcUrls = [];

Expand All @@ -180,7 +178,7 @@ function getContentSecurityPolicy(

return policy.replace(
/connect-src (.*?);/,
`connect-src $1 ${connectSrcUrls.join(" ")} ;`
`connect-src $1 ${connectSrcUrls.join(" ")} ;`,
);
}

Expand Down
10 changes: 5 additions & 5 deletions backend/appInfo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test("minimal directory app info", async () => {

test("directory app info with manifest", async () => {
const location = getLocation(
path.resolve(__dirname, "fixtures", "withManifest")
path.resolve(__dirname, "fixtures", "withManifest"),
);
const appInfo = await getAppInfo(location);
expect(appInfo.location).toEqual(location);
Expand All @@ -31,7 +31,7 @@ test("directory app info with manifest", async () => {

test("directory app info with manifest but no name entry", async () => {
const location = getLocation(
path.resolve(__dirname, "fixtures", "withManifestWithoutName")
path.resolve(__dirname, "fixtures", "withManifestWithoutName"),
);
const appInfo = await getAppInfo(location);
expect(appInfo.location).toEqual(location);
Expand Down Expand Up @@ -64,7 +64,7 @@ test("directory app info with manifest but no name entry", async () => {

test("directory app info with jpg icon", async () => {
const location = getLocation(
path.resolve(__dirname, "fixtures", "withJpgIcon")
path.resolve(__dirname, "fixtures", "withJpgIcon"),
);
const appInfo = await getAppInfo(location);
expect(appInfo.location).toEqual(location);
Expand All @@ -83,7 +83,7 @@ test("directory app info with jpg icon", async () => {

test("directory app info with png icon", async () => {
const location = getLocation(
path.resolve(__dirname, "fixtures", "withPngIcon")
path.resolve(__dirname, "fixtures", "withPngIcon"),
);
const appInfo = await getAppInfo(location);
expect(appInfo.location).toEqual(location);
Expand Down Expand Up @@ -210,7 +210,7 @@ test("url app info with broken manifest", async () => {
} catch (e) {
if (e instanceof AppInfoError) {
expect(e.message).toEqual(
"Invalid manifest.toml, please check the format"
"Invalid manifest.toml, please check the format",
);
} else {
throw e;
Expand Down
10 changes: 5 additions & 5 deletions backend/appInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export async function getAppInfo(location: Location): Promise<AppInfo> {

export async function getAppInfoUrl(
location: UrlLocation,
fetch: typeof nodeFetch
fetch: typeof nodeFetch,
): Promise<AppInfo> {
return {
location,
Expand All @@ -65,7 +65,7 @@ export function getToolVersion(): string {

async function getManifestInfoFromUrl(
url: string,
fetch: typeof nodeFetch
fetch: typeof nodeFetch,
): Promise<ManifestInfo> {
if (!url.endsWith("/")) {
url = url + "/";
Expand All @@ -89,7 +89,7 @@ async function getManifestInfoFromUrl(

async function getIconInfoFromUrl(
url: string,
fetch: typeof nodeFetch
fetch: typeof nodeFetch,
): Promise<IconInfo | null> {
if (!url.endsWith("/")) {
url = url + "/";
Expand All @@ -113,7 +113,7 @@ async function getIconInfoFromUrl(

function getManifestInfoFromDir(
dir: string,
fallbackName: string
fallbackName: string,
): ManifestInfo {
const tomlBuffer = readFileBuffer(path.join(dir, "manifest.toml"));
if (tomlBuffer === null) {
Expand Down Expand Up @@ -165,7 +165,7 @@ function readFileBuffer(location: string): Buffer | null {

async function readUrlBuffer(
url: string,
fetch: typeof nodeFetch
fetch: typeof nodeFetch,
): Promise<Buffer | null> {
const response = await fetch(url);
if (!response.ok) {
Expand Down
6 changes: 4 additions & 2 deletions backend/fixtures/minimal/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<html>
<body>Hello, world!</body>
</html>
<body>
Hello, world!
</body>
</html>
6 changes: 4 additions & 2 deletions backend/fixtures/notXdcDir.xdc/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<html>
<body>Hello, world!</body>
</html>
<body>
Hello, world!
</body>
</html>
6 changes: 4 additions & 2 deletions backend/fixtures/withJpgIcon/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<html>
<body>Hello, world!</body>
</html>
<body>
Hello, world!
</body>
</html>
6 changes: 4 additions & 2 deletions backend/fixtures/withManifest/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<html>
<body>Hello, world!</body>
</html>
<body>
Hello, world!
</body>
</html>
6 changes: 4 additions & 2 deletions backend/fixtures/withManifestWithoutName/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<html>
<body>Hello, world!</body>
</html>
<body>
Hello, world!
</body>
</html>
6 changes: 4 additions & 2 deletions backend/fixtures/withPngIcon/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<html>
<body>Hello, world!</body>
</html>
<body>
Hello, world!
</body>
</html>
24 changes: 13 additions & 11 deletions backend/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Location } from "./location";
import { createPeer, InjectExpress } from "./app";
import { AppInfo } from "./appInfo";
import { getColorForId } from "./color";
import { Instance as FrontendInstance } from '../types/instance';
import { Instance as FrontendInstance } from "../types/instance";

export type Options = {
basePort: number;
Expand Down Expand Up @@ -39,7 +39,7 @@ class Instance {
public app: expressWs.Application,
public port: number,
public url: string,
public webXdc: WebXdcMulti
public webXdc: WebXdcMulti,
) {
this.id = port.toString();
this.color = getColorForId(this.id);
Expand All @@ -52,7 +52,7 @@ class Instance {
}

close() {
this.server.close()
this.server.close();
}
}

Expand Down Expand Up @@ -107,7 +107,7 @@ export class Instances {
app,
port,
instanceUrl,
this.processor.createClient(port.toString())
this.processor.createClient(port.toString()),
);

const wss = wsInstance.getWss();
Expand All @@ -117,7 +117,7 @@ export class Instances {
ws.on("message", (msg: string) => {
if (typeof msg !== "string") {
console.error(
"webxdc: Don't know how to handle unexpected non-string data"
"webxdc: Don't know how to handle unexpected non-string data",
);
return;
}
Expand All @@ -133,7 +133,7 @@ export class Instances {
JSON.stringify({
type: "updates",
updates: updates.map(([update]) => update),
})
}),
);
},
parsed.serial,
Expand All @@ -152,7 +152,7 @@ export class Instances {
name: this.appInfo.manifest.name,
color: instance.color,
},
})
}),
);
} else {
throw new Error(`Unknown message: ${JSON.stringify(parsed)}`);
Expand All @@ -166,7 +166,9 @@ export class Instances {
delete(id: number) {
let instance = this.instances.get(id);
if (instance == null) {
throw new Error(`Instance with id ${id} can't be deleted because it does not exist`);
throw new Error(
`Instance with id ${id} can't be deleted because it does not exist`,
);
}
instance.close();
this.processor.removeClient(instance.id);
Expand All @@ -187,13 +189,13 @@ export class Instances {
this._onMessage = onMessage;
}

list(): FrontendInstance[]{
list(): FrontendInstance[] {
return Array.from(this.instances.values()).map((instance) => ({
id: instance.id,
port: instance.port,
url: instance.url,
color: instance.color,
}))
}));
}
}

Expand All @@ -215,7 +217,7 @@ function isSendUpdateMessage(value: any): value is SendUpdateMessage {
}

function isSetUpdateListenerMessage(
value: any
value: any,
): value is SetUpdateListenerMessage {
return value.type === "setUpdateListener";
}
Expand Down
4 changes: 2 additions & 2 deletions backend/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function getLocation(location: string): Location {
}
if (!hasIndexHtml(path)) {
throw new LocationError(
`Invalid xdc file (no index.html file inside): ${location}`
`Invalid xdc file (no index.html file inside): ${location}`,
);
}
return {
Expand All @@ -65,7 +65,7 @@ export function getLocation(location: string): Location {

if (!hasIndexHtml(location)) {
throw new LocationError(
`Invalid xdc dir (no index.html file): ${location}`
`Invalid xdc dir (no index.html file): ${location}`,
);
}
return {
Expand Down
Loading

0 comments on commit 6aab7a3

Please # to comment.