Skip to content

Commit 623213c

Browse files
committed
stand-alone codepod app with all kernels working
1 parent 3ab699b commit 623213c

File tree

21 files changed

+850
-172
lines changed

21 files changed

+850
-172
lines changed

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,54 @@ docker stop $(docker ps -a | grep cpkernel_ | awk '{print $1}')
77
docker rm $(docker ps -a | grep cpkernel_ | awk '{print $1}')
88
```
99

10+
# User Guide
11+
Install kernels:
12+
13+
python:
14+
15+
```
16+
python -m pip install ipykernel
17+
python -m ipykernel install --user
18+
```
19+
20+
racket:
21+
22+
```
23+
brew install zmq
24+
raco pkg install --auto iracket
25+
raco iracket install
26+
```
27+
28+
On mac, zeromq lib cannot be found by racket due to [a known
29+
issue](https://github.com/rmculpepper/racket-zeromq/issues/6). To side-step it
30+
(replace the version numbers with your installation):
31+
32+
```
33+
cp /opt/homebrew/Cellar/zeromq/4.3.4/lib/libzmq.5.dylib ~/Library/Racket/8.2/lib
34+
```
35+
36+
julia:
37+
38+
```
39+
julia
40+
]add add IJulia
41+
import IJulia
42+
IJulia.installkernel("Julia nodeps", "--depwarn=no")
43+
```
44+
45+
Or just
46+
47+
```
48+
julia -e 'import Pkg; Pkg.add("IJulia"); using IJulia; installkernel("Julia nodeps", "--depwarn=no")'
49+
```
50+
51+
Javascript
52+
53+
```
54+
npm install -g ijavascript
55+
ijsinstall
56+
```
57+
1058
# About electron:
1159

1260
- electron does not support ES6 modules

app/README.md

Lines changed: 31 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,37 @@
22

33
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
44

5+
# Development
6+
7+
1. run `npm run start` in cpkernel
8+
2. run `npm run start` in ui
9+
3. run `npm run ele` in app
10+
- so the app is only a manager session to launch kernel and ui in the
11+
package. It is completely useless during development.
12+
13+
UPDATE: now just run `npm run dev`
14+
15+
The cpkernel is linked, so need to run `npm link ../cpkernel`. Otherwise, the
16+
cpkernel is copied to node_modules and won't be built.
17+
18+
# Build
19+
20+
1. run `npm run build` in cpkernel
21+
2. run `npm run bulid` in ui
22+
3. run `npm run build` in app
23+
4. run `npm run package` in app
24+
- the packaged app is in dist/
25+
26+
Since electron app cannot console.log to stdout, I need a way to see the errors.
27+
Currently I log into a file /tmp/a.txt and use `tail -f /tmp/a.txt` to monitor
28+
the results.
29+
30+
To extract app.asar:
31+
32+
```
33+
npx asar extract app.asar destfolder
34+
```
35+
536
## Available Scripts
637

738
In the project directory, you can run:
@@ -28,43 +59,3 @@ The build is minified and the filenames include the hashes.\
2859
Your app is ready to be deployed!
2960

3061
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
31-
32-
### `yarn eject`
33-
34-
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
35-
36-
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
37-
38-
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
39-
40-
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
41-
42-
## Learn More
43-
44-
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
45-
46-
To learn React, check out the [React documentation](https://reactjs.org/).
47-
48-
### Code Splitting
49-
50-
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
51-
52-
### Analyzing the Bundle Size
53-
54-
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
55-
56-
### Making a Progressive Web App
57-
58-
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
59-
60-
### Advanced Configuration
61-
62-
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
63-
64-
### Deployment
65-
66-
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
67-
68-
### `yarn build` fails to minify
69-
70-
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)

app/package-lock.json

Lines changed: 52 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/package.json

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "codepod-app",
2+
"name": "codepod",
33
"version": "0.1.0",
44
"private": true,
55
"main": "./public/electron.js",
@@ -10,17 +10,25 @@
1010
"@testing-library/jest-dom": "^5.11.4",
1111
"@testing-library/react": "^11.1.0",
1212
"@testing-library/user-event": "^12.1.10",
13+
"cpkernel": "file:../cpkernel",
1314
"react": "^17.0.2",
1415
"react-dom": "^17.0.2",
1516
"react-scripts": "4.0.3",
1617
"web-vitals": "^1.0.1"
1718
},
1819
"build": {
1920
"appId": "com.electron.myapp",
20-
"productName": "My Electron App",
21+
"productName": "CodePod",
2122
"files": [
2223
"build/**/*",
23-
"node_modules/**/*"
24+
"node_modules/**/*",
25+
{
26+
"from": "../ui/build",
27+
"to": "build/ui",
28+
"filter": [
29+
"**/*"
30+
]
31+
}
2432
],
2533
"directories": {
2634
"buildResources": "public"
@@ -36,14 +44,17 @@
3644
}
3745
},
3846
"scripts": {
39-
"start": "react-scripts start",
47+
"start": "PORT=13001 react-scripts start",
4048
"build": "react-scripts build",
4149
"test": "react-scripts test",
4250
"eject": "react-scripts eject",
43-
"electron:start": "concurrently -k \"cross-env BROWSER=none yarn start\" \"wait-on http://localhost:3000 && electronmon .\"",
44-
"electron:package:mac": "yarn build && electron-builder -m -c.extraMetadata.main=build/electron.js",
45-
"electron:package:win": "yarn build && electron-builder -w -c.extraMetadata.main=build/electron.js",
46-
"electron:package:linux": "yarn build && electron-builder -l -c.extraMetadata.main=build/electron.js"
51+
"package": "electron-builder -m -c.extraMetadata.main=build/electron.js",
52+
"electron:start": "concurrently -k \"cross-env BROWSER=none yarn start\" \"wait-on http://localhost:13001 && electronmon .\"",
53+
"electron:package:mac": "npm run build && electron-builder -m -c.extraMetadata.main=build/electron.js",
54+
"electron:package:win": "npm run build && electron-builder -w -c.extraMetadata.main=build/electron.js",
55+
"electron:package:linux": "npm run build && electron-builder -l -c.extraMetadata.main=build/electron.js",
56+
"dev": "concurrently -k \"cd ../ui && BROWSER=none npm run start\" \"cd ../cpkernel && npm run dev\" \"cross-env BROWSER=none npm run start\" \"wait-on http://127.0.0.1:13001 && wait-on http://127.0.0.1:14322 && electronmon .\"",
57+
"build:all": "cd ../cpkernel && npm run build && cd ../ui && npm run build && cd ../app && npm run build && npm run package"
4758
},
4859
"eslintConfig": {
4960
"extends": [
@@ -71,4 +82,4 @@
7182
"electronmon": "^2.0.2",
7283
"wait-on": "^6.0.0"
7384
}
74-
}
85+
}

app/public/electron.js

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,38 @@
11
// Module to control the application lifecycle and the native browser window.
2-
const { app, BrowserWindow, protocol } = require("electron");
2+
const {
3+
app,
4+
BrowserWindow,
5+
protocol,
6+
Tray,
7+
Menu,
8+
nativeImage,
9+
} = require("electron");
310
const path = require("path");
411
const url = require("url");
512

13+
14+
if (app.isPackaged) {
15+
const { startServer } = require("cpkernel");
16+
const express = require("express");
17+
18+
// if packaged, run the backend:
19+
// 1. the graphql on :14321
20+
// 2. the static UI on :14322
21+
22+
// during development, I'm going to start the two server manually
23+
console.log("Starting repo/kernel server ..")
24+
startServer(path.join(app.getPath("userData"), "repos"));
25+
26+
const static_dir = path.join(__dirname, "ui");
27+
console.log("===", static_dir);
28+
const expapp = express();
29+
expapp.use("/", express.static(static_dir));
30+
console.log("starting UI server ..")
31+
expapp.listen(14322, () => {
32+
console.log("UI server started on port :14322");
33+
});
34+
}
35+
636
// Create the native browser window.
737
function createWindow() {
838
const mainWindow = new BrowserWindow({
@@ -18,13 +48,19 @@ function createWindow() {
1848
// In production, set the initial browser path to the local bundle generated
1949
// by the Create React App build process.
2050
// In development, set it to localhost to allow live/hot-reloading.
51+
const indexurl = url.format({
52+
pathname: path.join(__dirname, "index.html"),
53+
protocol: "file:",
54+
slashes: true,
55+
});
2156
const appURL = app.isPackaged
2257
? url.format({
23-
pathname: path.join(__dirname, "index.html"),
24-
protocol: "file:",
25-
slashes: true,
26-
})
27-
: "http://localhost:3000";
58+
pathname: path.join(__dirname, "ui/index.html"),
59+
protocol: "file:",
60+
slashes: true,
61+
})
62+
: // : "http://localhost:13001";
63+
"http://localhost:14322";
2864
mainWindow.loadURL(appURL);
2965

3066
// Automatically open Chrome's DevTools in development mode.
@@ -48,13 +84,39 @@ function setupLocalFilesNormalizerProxy() {
4884
);
4985
}
5086

87+
let tray;
88+
5189
// This method will be called when Electron has finished its initialization and
5290
// is ready to create the browser windows.
5391
// Some APIs can only be used after this event occurs.
5492
app.whenReady().then(() => {
5593
createWindow();
5694
setupLocalFilesNormalizerProxy();
5795

96+
const icon = nativeImage.createFromPath("./favicon.ico");
97+
tray = new Tray(icon);
98+
const contextMenu = Menu.buildFromTemplate([
99+
{
100+
label: "Open in Browser",
101+
type: "normal",
102+
click: () => {
103+
require("electron").shell.openExternal("http://localhost:14322");
104+
},
105+
},
106+
{ label: "Preference", type: "normal" },
107+
{ label: "Dashboard" },
108+
{ label: "Public Access", type: "checkbox" },
109+
{
110+
label: "Quit", click: () => {
111+
app.quit();
112+
}
113+
},
114+
]);
115+
116+
tray.setContextMenu(contextMenu);
117+
// tray.setToolTip("This is my application");
118+
tray.setTitle("CP");
119+
58120
app.on("activate", function () {
59121
// On macOS it's common to re-create a window in the app when the
60122
// dock icon is clicked and there are no other windows open.

app/src/App.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ function App() {
66
<div className="App">
77
<header className="App-header">
88
<img src={logo} className="App-logo" alt="logo" />
9+
<p>Go to http://localhost:14322 with your browser.</p>
910
<p>
1011
Edit <code>src/App.js</code> and save to reload.
1112
</p>

0 commit comments

Comments
 (0)