Skip to content

Commit

Permalink
Merge pull request #2 from kanade-k-1228/main
Browse files Browse the repository at this point in the history
release 0.0.0
  • Loading branch information
kanade-k-1228 authored Feb 15, 2024
2 parents be2be62 + 5230d0a commit e1a7d6b
Show file tree
Hide file tree
Showing 85 changed files with 2,070 additions and 1,703 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Next Micon IDE

![](img/ide_home.png)

![](img/ide_hw.png)

![](img/ide_sw.png)

## TODO

- add registor
- add parameter
- add logging
Binary file added img/ide_home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/ide_hw.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/ide_sw.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
625 changes: 569 additions & 56 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,37 @@
]
},
"dependencies": {
"@codemirror/basic-setup": "^0.20.0",
"@codemirror/commands": "^6.3.3",
"@codemirror/gutter": "^0.19.9",
"@codemirror/lang-cpp": "^6.0.2",
"@mui/icons-material": "^5.15.0",
"@types/js-yaml": "^4.0.9",
"@uiw/react-codemirror": "^4.21.21",
"allotment": "^1.19.3",
"codemirror": "^6.0.1",
"directory-tree": "^3.5.1",
"electron-store": "^8.1.0",
"execa": "^8.0.1",
"js-yaml": "^4.1.0",
"log4js": "^6.9.1",
"react": "^18.2.0",
"react-ace": "^10.1.0",
"react-dom": "^18.2.0",
"recoil": "^0.7.7"
"recoil": "^0.7.7",
"unzipper": "^0.10.14"
},
"devDependencies": {
"@types/node": "^20.10.5",
"@types/react": "^18.2.45",
"@types/react-dom": "^18.2.18",
"@types/unzipper": "^0.10.9",
"cross-env": "^7.0.3",
"css-loader": "^6.8.1",
"electron": "^28.0.0",
"electron-builder": "^24.9.1",
"electronmon": "^2.0.2",
"html-webpack-plugin": "^5.5.4",
"mini-css-extract-plugin": "^2.7.6",
"monaco-editor-webpack-plugin": "^7.1.0",
"npm-run-all": "^4.1.5",
"prettier": "^3.1.1",
"rimraf": "^5.0.5",
Expand Down
6 changes: 3 additions & 3 deletions src/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ export const WIRE_WIDTH = 3;

export const GRID = 20;

export const URL_HELP = "https://github.com/NextMicon";
export const URL_NEXT_MICON = "https://github.com/NextMicon";
export const URL_PACK_REPO = "https://raw.githubusercontent.com/NextMicon/Registory/main/Package";
export const URL_BOARD_REPO = "https://raw.githubusercontent.com/NextMicon/Registory/main/Board";

export const SW_INIT = `// main.cpp
#include "firmware.hpp"
void init(){
// Code Here!
// Code Here!
}
void loop(){
// Code Here!
// Code Here!
}
`;
2 changes: 1 addition & 1 deletion src/files/board.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ export interface Board {

size: [number, number];
}[];
tools: { name: string; cmd: string }[];
tools: { name: string; cmd: string; inst: string }[];
cmd: { name: string; src: string[]; out: string[]; cmd: string; arg: string[] }[];
}
14 changes: 8 additions & 6 deletions src/files/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ export interface Package {

params: {
name: string;
valid: (
| { type: "num"; num: number }
| { type: "range"; from: number; to: number }
| { type: "enum"; num: number; str: string }
)[];
valid: ({ type: "num"; num: number } | { type: "range"; from: number; to: number } | { type: "enum"; num: number; str: string })[];
}[];

size: [number, number];
Expand All @@ -21,6 +17,12 @@ export interface Package {
software?: {
className: string;
memSize: number;
member: { doc: string; copy: string }[];
methods: ({ note: string } & Func)[];
};
}

export interface Func {
type: string;
name: string;
args: { type: string; name: string }[];
}
2 changes: 2 additions & 0 deletions src/ipckey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ export const IPCKeys = {
FS_GET_TREE: "FS_GET_TREE",
FS_EXIST: "FS_EXIST",
FS_MKDIR: "FS_MKDIR",
FS_UNZIP: "FS_UNZIP",

WEB_OPEN: "WEB_OPEN",
WEB_FETCH: "WEB_FETCH",
WEB_CLONE: "WEB_CLONE",
WEB_DL: "WEB_DL",

GITHUB_FETCH: "GITHUB_FETCH",
GITHUB_CLONE: "GITHUB_CLONE", // TODO
Expand Down
20 changes: 18 additions & 2 deletions src/main/ipc/fs.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import directoryTree from "directory-tree";
import { OpenDialogOptions, dialog, ipcMain } from "electron";
import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "fs";
import { createReadStream, existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "fs";
import { getLogger } from "log4js";
import { dirname, join, sep } from "path";
import { IPCKeys } from "~/ipckey";
import { mainWindow } from "~/main/main";
import unzip from "unzipper";

const log = getLogger("IPC");

Expand Down Expand Up @@ -78,10 +79,25 @@ export const fsHandler = () => {
log.trace(IPCKeys.FS_MKDIR, path);
try {
const exist = existsSync(path);
if (!exist) mkdirSync(path);
if (!exist) mkdirSync(path, { recursive: true });
return true;
} catch (e) {
throw e;
}
});

ipcMain.handle(IPCKeys.FS_UNZIP, (_, zipPaths: string[], outPaths: string[]) => {
const zipPath = join(...zipPaths);
const outPath = join(...outPaths);
log.trace(IPCKeys.FS_UNZIP, zipPath, outPath);
try {
if (!zipPaths.at(-1)?.endsWith(".zip")) {
throw `Zipfile required: ${zipPath}`;
}
const stream = createReadStream(zipPath);
stream.pipe(unzip.Extract({ path: outPath }));
} catch (e) {
throw e;
}
});
};
17 changes: 15 additions & 2 deletions src/main/ipc/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,21 @@ const log = getLogger("IPC");
export const runHandler = () => {
ipcMain.handle(IPCKeys.RUN_EXECA, async (_, command: string, args: string[], cwd: string[], options: Options) => {
log.trace(IPCKeys.RUN_EXECA, command, args, cwd, options);
const proc = execa(command, args, { cwd: join(...cwd), ...options });
const result = await proc;
const result = await execa(command, args, { cwd: join(...cwd), ...options })
.then((r) => {
return {
exitCode: r.exitCode,
stdout: r.stdout,
stderr: r.stderr,
};
})
.catch((e) => {
return {
exitCode: e.exitCode,
stderr: e.stderr,
stdout: e.stdout,
};
});
return result;
});
};
15 changes: 12 additions & 3 deletions src/main/ipc/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,17 @@ export const webHandler = () => {
// Fetch File and Write Local
ipcMain.handle(IPCKeys.WEB_CLONE, async (_, remotePaths: string[], localPaths: string[]) => {
log.trace(IPCKeys.WEB_FETCH, join(...remotePaths), join(...localPaths));
return fetch(join(...remotePaths))
.then((res) => res.text())
.then((str) => writeFileSync(join(...localPaths), str));
const res = await fetch(join(...remotePaths));
const txt = await res.text();
writeFileSync(join(...localPaths), txt);
return txt;
});

ipcMain.handle(IPCKeys.WEB_DL, async (_, remotePaths: string[], localPaths: string[]) => {
log.trace(IPCKeys.WEB_FETCH, join(...remotePaths), join(...localPaths));
const res = await fetch(join(...remotePaths));
const arrBuf = await res.arrayBuffer();
const buf = Buffer.from(arrBuf);
writeFileSync(join(...localPaths), buf);
});
};
13 changes: 12 additions & 1 deletion src/preload/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,29 @@ declare global {
tree: (paths: string[]) => Promise<directoryTree.DirectoryTree<Record<string, any>>>;
exist: (paths: string[]) => Promise<boolean>;
mkdir: (paths: string[]) => Promise<boolean>;
unzip: (zipPaths: string[], outPaths: string[]) => Promise<void>;
};
github: {
fetch: (owner: string, repo: string, branch: string, path: string[]) => Promise<string>;
clone: (owner: string, repo: string, branch: string, local: string[]) => Promise<string>;
};
run: {
execa: (command: string, args: string[], cwd: string[], options?: Options) => Promise<ExecaReturnValue<string>>;
execa: (
command: string,
args: string[],
cwd: string[],
options?: Options,
) => Promise<{
exitCode: number;
stdout: string;
stderr: string;
}>;
};
web: {
open: (url: string) => Promise<void>;
fetch: (url: string) => Promise<string>;
clone: (remotePaths: string[], localPaths: string[]) => Promise<string>;
dl: (remotePaths: string[], localPaths: string[]) => Promise<void>;
};
config: {
getColor: () => Promise<ConfigJSON["color"]>;
Expand Down
2 changes: 2 additions & 0 deletions src/preload/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ contextBridge.exposeInMainWorld("ipc", {
tree: (paths: string[]) => ipcRenderer.invoke(IPCKeys.FS_GET_TREE, paths),
exist: (paths: string[]) => ipcRenderer.invoke(IPCKeys.FS_EXIST, paths),
mkdir: (paths: string[]) => ipcRenderer.invoke(IPCKeys.FS_MKDIR, paths),
unzip: (zipPaths: string[], outPaths: string[]) => ipcRenderer.invoke(IPCKeys.FS_UNZIP, zipPaths, outPaths),
},
github: {
fetch: (owner: string, repo: string, branch: string, path: string[]) =>
Expand All @@ -41,6 +42,7 @@ contextBridge.exposeInMainWorld("ipc", {
open: (url: string) => ipcRenderer.invoke(IPCKeys.WEB_OPEN, url),
fetch: (url: string) => ipcRenderer.invoke(IPCKeys.WEB_FETCH, url),
clone: (remotePaths: string[], localPaths: string[]) => ipcRenderer.invoke(IPCKeys.WEB_CLONE, remotePaths, localPaths),
dl: (remotePaths: string[], localPaths: string[]) => ipcRenderer.invoke(IPCKeys.WEB_DL, remotePaths, localPaths),
},
config: {
getColor: () => ipcRenderer.invoke(IPCKeys.CONFIG_GET_COLOR),
Expand Down
8 changes: 2 additions & 6 deletions src/pub/index.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
<!doctype html>
<html lang="en" style="height: 100%; width: 100%; font-family: sans-serif">
<html>
<head>
<meta charset="UTF-8" />
<meta
http-equiv="Content-Security-Policy"
content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'"
/>
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" href="assets/logo.png" />
<link rel="style" href="./destyle.min.css" />
<title>Next Micon IDE</title>
</head>
<body>
Expand Down
3 changes: 1 addition & 2 deletions src/web/1_type/0_Pack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ export interface PackKey {
}

export const packToString = (pack: PackKey) => `${pack.owner}/${pack.name}/${pack.version}`;
export const packEq = (lhs: PackKey, rhs: PackKey) =>
lhs.owner === rhs.owner && lhs.name === rhs.name && lhs.version === rhs.version;
export const packEq = (lhs: PackKey, rhs: PackKey) => lhs.owner === rhs.owner && lhs.name === rhs.name && lhs.version === rhs.version;
4 changes: 2 additions & 2 deletions src/web/1_type/2_Ioport.ts → src/web/1_type/2_Primitive.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Board, Project } from "~/files";
import { Position } from "~/utils";

export interface Ioport {
export interface Primitive {
name: string;
pack: Board["ioifs"][number];
params: [string, string | number][];
Expand All @@ -10,5 +10,5 @@ export interface Ioport {
}

export type IoportKey = string;
export const getIoportKey = (ioport: Ioport | Project["ioports"][number]) => ioport.name;
export const getIoportKey = (ioport: Primitive | Project["ioports"][number]) => ioport.name;
export const ioportKeyEq = (lhs: IoportKey, rhs: IoportKey) => lhs === rhs;
2 changes: 1 addition & 1 deletion src/web/1_type/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from "./0_Pack";
export * from "./1_Instance";
export * from "./2_Ioport";
export * from "./2_Primitive";
export * from "./3_Port";
export * from "./4_Wire";
2 changes: 1 addition & 1 deletion src/web/2_route/0_route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ type Route = { page: "home" } | { page: "editor"; project: string[] };

export const routeState = atom<Route>({ key: "route", default: { page: "home" } });

type Dialog = "createProject" | "setting" | "package" | "board";
type Dialog = "createProject" | "setting" | "package" | "board" | "build";

export const dialogState = atom<Dialog | undefined>({ key: "dialog", default: undefined });
2 changes: 1 addition & 1 deletion src/web/2_store/0_sys/message.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { atom, useRecoilState } from "recoil";

type MessageType = "error" | "warn" | "info";
type MessageType = "error" | "warn" | "sucsess" | "info";

export interface Message {
id: string;
Expand Down
13 changes: 13 additions & 0 deletions src/web/2_store/1_library/1_packs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,16 @@ export const mergedPackList = selector({
return ret;
},
});

// --------------------------------------------------------------------------------
// パッケージをダウンロード

export const useDownloadPackage = () => {
const { home } = useRecoilValue(pathState);
return async (pack: PackInfo) => {
const path = [pack.owner, pack.name, pack.version];
const files = [PACK_FILE, `${pack.name}.cpp`, `${pack.name}.hpp`, `${pack.name}.sv`];
await window.ipc.fs.mkdir([...home, PACK_DIR, ...path]);
await Promise.all(files.map((file) => window.ipc.web.clone([URL_PACK_REPO, ...path, file], [...home, PACK_DIR, ...path, file])));
};
};
19 changes: 17 additions & 2 deletions src/web/2_store/1_library/2_boards.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { load } from "js-yaml";
import { selector } from "recoil";
import { BOARD_DIR, BOARD_FILE } from "~/consts";
import { selector, useRecoilValue } from "recoil";
import { BOARD_DIR, BOARD_FILE, URL_BOARD_REPO, URL_PACK_REPO } from "~/consts";
import { Board } from "~/files";
import { pathState } from "../0_sys/directory";
import { flatten } from "./util";
Expand Down Expand Up @@ -45,3 +45,18 @@ export const boardsState = selector({
return boards;
},
});

// --------------------------------------------------------------------------------
// ボードをダウンロード

export const useDownloadBoard = () => {
const { home } = useRecoilValue(pathState);
return async (owner: string, name: string, version: string) => {
const path = [owner, name, version];
const zip = `${name}.zip`;
await window.ipc.fs.mkdir([...home, BOARD_DIR, ...path]);
await window.ipc.web.clone([URL_BOARD_REPO, ...path, zip], [...home, BOARD_DIR, ...path, zip]);
// TODO: Unzip
// await window.ipc.fs.unzip([...home, BOARD_DIR, ...path, zip], [...home, BOARD_DIR, ...path]);
};
};
Loading

0 comments on commit e1a7d6b

Please sign in to comment.