Skip to content

Commit

Permalink
Make prettier happy in build.ts and App.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
georgestagg committed Sep 13, 2023
1 parent 0b0678b commit cf5455f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 31 deletions.
17 changes: 8 additions & 9 deletions scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { spawn } from "child_process";
import esbuild from "esbuild";
import * as fs from "fs";
import http from "http";
import process from "process";
import path from "path";
import process from "process";
import packageJson from "../package.json";
import type { AppEngine } from "../src/Components/App";
import buildExamples from "./build_examples_json";
import type { AppEngine } from '../src/Components/App';

const EXAMPLES_SOURCE_DIR = "./examples";
const BUILD_DIR = "./build";
Expand Down Expand Up @@ -91,12 +91,11 @@ function readdirSyncRecursive(dir: string, root: string = dir): string[] {

function buildSiteHtml(appEngine: AppEngine) {
console.log(`[${new Date().toISOString()}] Copying HTML templates...`);
readdirSyncRecursive('site_template')
.forEach((file) => {
const tmpl = fs.readFileSync(`site_template/${file}`, 'utf8');
const html = tmpl.replace('{{APP_ENGINE}}', appEngine);
fs.writeFileSync(`${SITE_DIR}/${file}`, html);
});
readdirSyncRecursive("site_template").forEach((file) => {
const tmpl = fs.readFileSync(`site_template/${file}`, "utf8");
const html = tmpl.replace("{{APP_ENGINE}}", appEngine);
fs.writeFileSync(`${SITE_DIR}/${file}`, html);
});
}

const buildmap = {
Expand Down Expand Up @@ -259,7 +258,7 @@ if (serve) {
http.request(
{ hostname: "0.0.0.0", port: 3001, path: url, method, headers },
(proxyRes) => {
if (appEngine === 'r') {
if (appEngine === "r") {
proxyRes.headers = {
...proxyRes.headers,
"cross-origin-opener-policy": "same-origin",
Expand Down
53 changes: 31 additions & 22 deletions src/Components/App.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import LZString from "lz-string";
import * as React from "react";
import { createRoot } from "react-dom/client";
import {
findExampleByTitle,
getExampleCategories,
sanitizeTitleForUrl,
} from "../examples";
import {
PyodideProxyHandle,
initPyodide,
initShiny,
PyodideProxyHandle,
usePyodide,
} from "../hooks/usePyodide";
import {
initWebR,
WebRProxyHandle,
initRShiny,
initWebR,
useWebR,
WebRProxyHandle
} from "../hooks/useWebR";
import { ProxyType } from "../pyodide-proxy";
import "./App.css";
Expand All @@ -26,9 +29,6 @@ import { Viewer, ViewerMethods } from "./Viewer";
import { FCorFCJSONtoFC, FileContent, FileContentJson } from "./filecontent";
import { fetchGist, gistApiResponseToFileContents } from "./gist";
import { editorUrlPrefix, fileContentsToUrlString } from "./share";
import LZString from "lz-string";
import * as React from "react";
import { createRoot } from "react-dom/client";

// Load Editor component dynamically and lazily because it's large and not
// needed for all configurations.
Expand Down Expand Up @@ -97,7 +97,6 @@ type AppOptions = {
showHeaderBar?: boolean;
};


export type ProxyHandle = PyodideProxyHandle | WebRProxyHandle;
let pyodideProxyHandlePromise: Promise<PyodideProxyHandle> | null = null;
let webRProxyHandlePromise: Promise<WebRProxyHandle> | null = null;
Expand Down Expand Up @@ -220,10 +219,10 @@ export function App({
useWasmEngine = () => usePyodide({ pyodideProxyHandlePromise: promise });
break;
}
case "r":{
const promise = webRProxyHandlePromise = ensureWebRProxyHandlePromise({
case "r": {
const promise = (webRProxyHandlePromise = ensureWebRProxyHandlePromise({
shiny: loadShiny,
});
}));
useWasmEngine = () => useWebR({ webRProxyHandlePromise: promise });
break;
}
Expand Down Expand Up @@ -310,7 +309,9 @@ export function App({
setHeaderBarCallbacks({
openEditorWindowFromViewer: () => {
window.open(
editorUrlPrefix(appEngine) + "#code=" + fileContentsToUrlString(startFiles),
editorUrlPrefix(appEngine) +
"#code=" +
fileContentsToUrlString(startFiles),
"_blank"
);
},
Expand Down Expand Up @@ -348,8 +349,11 @@ export function App({
terminalMethods={terminalMethods}
viewerMethods={viewerMethods}
utilityMethods={utilityMethods}
runOnLoad={currentFiles.some((file) =>
file.name === "app.py" || file.name === "app.R" || file.name === "server.R"
runOnLoad={currentFiles.some(
(file) =>
file.name === "app.py" ||
file.name === "app.R" ||
file.name === "server.R"
)}
appEngine={appEngine}
/>
Expand Down Expand Up @@ -391,8 +395,11 @@ export function App({
terminalMethods={terminalMethods}
viewerMethods={viewerMethods}
utilityMethods={utilityMethods}
runOnLoad={currentFiles.some((file) =>
file.name === "app.py" || file.name === "app.R" || file.name === "server.R"
runOnLoad={currentFiles.some(
(file) =>
file.name === "app.py" ||
file.name === "app.R" ||
file.name === "server.R"
)}
appEngine={appEngine}
/>
Expand Down Expand Up @@ -491,10 +498,7 @@ export function App({
appEngine={appEngine}
/>
</React.Suspense>
<Viewer
proxyHandle={proxyHandle}
setViewerMethods={setViewerMethods}
/>
<Viewer proxyHandle={proxyHandle} setViewerMethods={setViewerMethods} />
</ResizableGrid>
);
} else if (appMode === "viewer") {
Expand Down Expand Up @@ -542,7 +546,7 @@ export function runApp(
allowGistUrl?: boolean;
allowExampleUrl?: boolean;
} = {},
appEngine: AppEngine,
appEngine: AppEngine
) {
const optsDefaults = {
allowCodeUrl: false,
Expand Down Expand Up @@ -595,7 +599,7 @@ export function runApp(
if (value === "") exampleName = key;
}

const exampleCategories = (await getExampleCategories(appEngine));
const exampleCategories = await getExampleCategories(appEngine);
let pos = findExampleByTitle(exampleName, exampleCategories);
if (pos) {
opts.selectedExample = exampleName;
Expand Down Expand Up @@ -640,7 +644,12 @@ export function runApp(
const root = createRoot(domTarget);
root.render(
<React.StrictMode>
<App appMode={mode} startFiles={startFiles} appOptions={appOpts} appEngine={appEngine} />
<App
appMode={mode}
startFiles={startFiles}
appOptions={appOpts}
appEngine={appEngine}
/>
</React.StrictMode>
);
})();
Expand Down

0 comments on commit cf5455f

Please sign in to comment.