├── .babelrc
├── .gitignore
├── LICENSE.md
├── Readme.md
├── icons
├── logo.ico
└── logo256.png
├── main_process
├── config.json
├── context-menu.js
├── electron.js
├── file-manager.js
├── json-store.js
├── menu.js
├── preload.js
└── temp
├── package.json
├── render_process
└── index.html
├── src
├── App.js
├── components
│ ├── Editor.js
│ ├── Footer.js
│ ├── InputCheck.js
│ ├── Select.js
│ └── Snackbar.js
├── containers
│ ├── CodeEditor.js
│ ├── ResultPane.js
│ └── Settings.js
├── index.js
├── index.scss
├── providers
│ ├── GlobalContext.js
│ └── GlobalProvider.js
├── styles
│ ├── ResultPane.scss
│ ├── Settings.scss
│ └── footer.scss
└── util
│ ├── ExecCode.js
│ ├── FileManager.js
│ └── JsonStore.js
├── webpack.common.js
├── webpack.dev.js
├── webpack.prod.js
├── yarn-error.log
└── yarn.lock
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": ["@babel/preset-react"]
3 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 |
3 | dist/
4 | build/
5 |
6 | yarn-error.log
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2020 - present Haikel Fazzani
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 |
7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/Readme.md:
--------------------------------------------------------------------------------
1 | # PiJs: code playground for Javascript, typescript and Go
2 | 👍 Write and run
3 |
4 | ### [📑 Download for windows](https://github.com/haikelfazzani/pi-js/releases/download/v1.0.0-beta/pijs.Setup.1.0.0.exe)
5 |
6 | ### Languages
7 | - [x] Javascript (nodejs)
8 | - [x] Typescript
9 | - [x] Go
10 |
11 | ### Capture
12 | 
13 |
14 | ### Functionality
15 | - [x] Auto detect language using file extension
16 | - [x] themes (monokai, material, dracula)
17 | - [x] Format code
18 | - [x] Autosave
19 |
20 | ### Logo
21 | 
22 |
23 | ### Techs
24 | - Electron
25 | - React
26 | - Ace editor
27 | - JsBeauty
28 |
29 | ## Notes
30 | - All pull requests are welcome, feel free.
31 |
32 | ### Author
33 | - Haikel Fazzani
34 |
35 | ### License
36 | MIT
--------------------------------------------------------------------------------
/icons/logo.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/haikelfazzani/pi-js/97a560474bfe7d13828a74e4dcd195735855fe9c/icons/logo.ico
--------------------------------------------------------------------------------
/icons/logo256.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/haikelfazzani/pi-js/97a560474bfe7d13828a74e4dcd195735855fe9c/icons/logo256.png
--------------------------------------------------------------------------------
/main_process/config.json:
--------------------------------------------------------------------------------
1 | {"usercode":"console.log('ok')","language":"javascript","filename":null,"fileExtension":null,"currfilepath":"C:\\Users\\haike\\Documents\\2020\\electron\\pi-js\\main_process/temp","fontsize":"16","theme":"monokai","issaved":false,"wrapEnabled":false,"showPrintMargin":false,"autosave":false}
--------------------------------------------------------------------------------
/main_process/context-menu.js:
--------------------------------------------------------------------------------
1 | const { Menu, MenuItem, dialog } = require("electron");
2 | const ctxMenu = new Menu();
3 | const FileManager = require('./file-manager');
4 |
5 | const items = [
6 | {
7 | label: 'Run Code',
8 | accelerator: 'CmdOrCtrl+Enter',
9 | click: (menuItem, browserWindow, event) => {
10 | browserWindow.webContents.send('run-code', 'run-code');
11 | }
12 | },
13 | { type: 'separator' },
14 | {
15 | label: 'Open File',
16 | accelerator: 'CmdOrCtrl+l',
17 | click: async (menuItem, browserWindow, event) => {
18 | try {
19 | let result = await dialog.showOpenDialog();
20 | if (!result.canceled) {
21 | let fileContent = await FileManager.openFile(result.filePaths[0]);
22 | browserWindow.webContents.send('open-file', fileContent);
23 | }
24 | } catch (error) {
25 | await dialog.showMessageBox({ type: 'error', message: error.message });
26 | }
27 | }
28 | },
29 | {
30 | label: 'Save',
31 | accelerator: 'CmdOrCtrl+s',
32 | click: async (menuItem, browserWindow, event) => {
33 | try {
34 | let isSaved = await FileManager.saveFile();
35 | browserWindow.webContents.send('save-file', isSaved);
36 | } catch (error) {
37 | await dialog.showMessageBox({ type: 'error', message: error.message });
38 | }
39 | }
40 | },
41 | {
42 | label: 'Save As..',
43 | accelerator: 'CmdOrCtrl+Shift+s',
44 | click: async (menuItem, browserWindow, event) => {
45 | let result = await dialog.showSaveDialog();
46 | let isSaved = await FileManager.saveAsFile(result.filePath);
47 | browserWindow.webContents.send('save-as-file', isSaved);
48 | }
49 | },
50 | { type: 'separator' },
51 | {
52 | label: 'Format Code',
53 | accelerator: 'CmdOrCtrl+Shift+f',
54 | click: async (menuItem, browserWindow, event) => {
55 | browserWindow.webContents.send('format-code', 'format-code');
56 | }
57 | },
58 | { type: 'separator' },
59 | { role: 'cut' },
60 | { role: 'copy' },
61 | { role: 'paste' },
62 | { type: 'separator' },
63 | {
64 | label: 'Inspecter..',
65 | click: (menuItem, browserWindow, event) => {
66 | browserWindow.webContents.openDevTools();
67 | }
68 | }
69 | ];
70 |
71 | items.forEach(m => {
72 | ctxMenu.append(new MenuItem(m))
73 | });
74 |
75 | module.exports = ctxMenu;
--------------------------------------------------------------------------------
/main_process/electron.js:
--------------------------------------------------------------------------------
1 | const electron = require('electron');
2 | const { app, BrowserWindow, Menu } = electron;
3 | const ctxMenu = require('./context-menu');
4 | const menuTemplate = require('./menu')
5 |
6 | let mainWindow;
7 | let isProd = true;
8 |
9 | function createWindow () {
10 | mainWindow = new BrowserWindow({
11 | width: 1366, height: 768,
12 | webPreferences: {
13 | nodeIntegration: true,
14 | preload: __dirname + '/preload.js'
15 | }
16 | });
17 |
18 | isProd
19 | ? mainWindow.loadFile(__dirname + '/index.html')
20 | : mainWindow.loadURL('http://localhost:8080');
21 |
22 | Menu.setApplicationMenu(menuTemplate);
23 |
24 | mainWindow.on('closed', function () {
25 | mainWindow = null
26 | });
27 | }
28 |
29 | app.on('ready', createWindow);
30 |
31 | app.on('browser-window-created', function (event, win) {
32 | win.webContents.on('context-menu', (err, params) => {
33 | ctxMenu.popup(win, params.x, params.y);
34 | });
35 | });
36 |
37 | app.on('window-all-closed', function () {
38 | if (process.platform !== 'darwin') app.quit();
39 | });
40 |
41 | app.on('activate', function () {
42 | if (mainWindow === null) createWindow();
43 | });
--------------------------------------------------------------------------------
/main_process/file-manager.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const fsPromises = require('fs').promises;
3 | const TEMP_FILE_PATH = path.join(__dirname, 'temp');
4 | const STORE_PATH = path.join(__dirname, 'config.json');
5 | const JsonStore = require('./json-store');
6 |
7 | module.exports = class FileManager {
8 |
9 | static async openFile (filePath) {
10 |
11 | this.fileErros = '';
12 |
13 | let fileContent = null;
14 | try {
15 | let fileName = path.basename(filePath);
16 | let fileExt = path.extname(fileName);
17 |
18 | fileContent = await fsPromises.readFile(filePath, { encoding: 'utf8' });
19 | await fsPromises.writeFile(TEMP_FILE_PATH, fileContent, { encoding: 'utf8' });
20 |
21 | await this.updateConfigFile({
22 | currfilepath: filePath,
23 | filename: fileName,
24 | fileExtension: fileExt,
25 | language: this.getLanguage(fileExt)
26 | });
27 |
28 | } catch (error) {
29 | this.fileErros = error.message;
30 | }
31 | return fileContent;
32 | }
33 |
34 | static async saveFile () {
35 | try {
36 | let currfilepath = JsonStore.getPropVal('currfilepath');
37 | let fileContent = await fsPromises.readFile(TEMP_FILE_PATH, { encoding: 'utf8' });
38 | await fsPromises.writeFile(currfilepath, fileContent, { encoding: 'utf8' });
39 | return true;
40 | } catch (error) {
41 | return false;
42 | }
43 | }
44 |
45 | static async saveAsFile (filePathSave) {
46 | try {
47 | let fileContent = await fsPromises.readFile(TEMP_FILE_PATH, { encoding: 'utf8' });
48 | await fsPromises.writeFile(filePathSave, fileContent, { encoding: 'utf8', flag: 'w' });
49 |
50 | let fileName = path.basename(filePathSave);
51 | let fileExt = path.extname(fileName);
52 |
53 | await this.updateConfigFile({
54 | 'currfilepath': filePathSave,
55 | 'filename': fileName,
56 | 'fileExtension': fileExt,
57 | 'language': this.getLanguage(fileExt)
58 | });
59 |
60 | return true;
61 | } catch (error) {
62 | return false;
63 | }
64 | }
65 |
66 | static async updateConfigFile (configs) {
67 | let store = {};
68 | store = this.getStoreFile();
69 |
70 | Object.keys(configs).forEach(keys => {
71 | store[keys] = configs[keys];
72 | });
73 |
74 | await fsPromises.writeFile(STORE_PATH, JSON.stringify(store), { encoding: 'utf8' });
75 | }
76 |
77 | static getStoreFile () {
78 | return require(STORE_PATH);
79 | }
80 |
81 | static getLanguage (fileExtension) {
82 | return fileExtension === '.py'
83 | ? 'python' : fileExtension === '.js'
84 | ? 'javascript' : fileExtension === '.go'
85 | ? 'golang' : 'typescript';
86 | }
87 |
88 | static async getErrors () {
89 | return this.fileErros;
90 | }
91 | }
--------------------------------------------------------------------------------
/main_process/json-store.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const STORE_PATH = path.join(__dirname, 'config.json');
3 |
4 | module.exports = class JsonStore {
5 |
6 | static get () {
7 | return require(STORE_PATH);
8 | }
9 |
10 | static getPropVal (prop) {
11 | this.store = this.get();
12 | return this.store[prop];
13 | }
14 |
15 | static async pushOrUpdate (field, value) {
16 | try {
17 | this.store = this.get() || {};
18 | this.store[field] = value;
19 | await fsPromises.writeFile(STORE_PATH, JSON.stringify(this.store), { encoding: 'utf8' });
20 | } catch (error) {
21 | console.log(error);
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/main_process/menu.js:
--------------------------------------------------------------------------------
1 | const { app, Menu, dialog, shell } = require("electron");
2 | const isMac = process.platform === 'darwin';
3 | const FileManager = require('./file-manager');
4 |
5 | const Action = {
6 | label: 'Action',
7 | submenu: [
8 | {
9 | label: 'Run Code',
10 | accelerator: 'CmdOrCtrl+Enter',
11 | click: (menuItem, browserWindow, event) => {
12 | browserWindow.webContents.send('run-code', 'run code')
13 | }
14 | },
15 | { type: 'separator' },
16 | {
17 | label: 'Format Code',
18 | accelerator: 'CmdOrCtrl+Shift+f',
19 | click: async (menuItem, browserWindow, event) => {
20 | browserWindow.webContents.send('format-code', 'format-code');
21 | }
22 | }
23 | ]
24 | };
25 |
26 | const FileHandler = {
27 | label: 'File',
28 | submenu: [
29 | {
30 | label: 'Open File',
31 | accelerator: 'CmdOrCtrl+l',
32 | click: async (menuItem, browserWindow, event) => {
33 | try {
34 | let result = await dialog.showOpenDialog();
35 | if (!result.canceled) {
36 | let fileContent = await FileManager.openFile(result.filePaths[0]);
37 | browserWindow.webContents.send('open-file', fileContent);
38 | }
39 | } catch (error) {
40 | await dialog.showMessageBox({ type: 'error', message: error.message });
41 | }
42 | }
43 | },
44 | {
45 | label: 'Save',
46 | accelerator: 'CmdOrCtrl+s',
47 | click: async (menuItem, browserWindow, event) => {
48 | try {
49 | let isSaved = await FileManager.saveFile();
50 | browserWindow.webContents.send('save-file', isSaved);
51 | } catch (error) {
52 | await dialog.showMessageBox({ type: 'error', message: error.message });
53 | }
54 | }
55 | },
56 | {
57 | label: 'Save As..',
58 | accelerator: 'CmdOrCtrl+Shift+s',
59 | click: async (menuItem, browserWindow, event) => {
60 | let result = await dialog.showSaveDialog();
61 | let isSaved = await FileManager.saveAsFile(result.filePath);
62 | browserWindow.webContents.send('save-as-file', isSaved);
63 | }
64 | },
65 | { type: 'separator' },
66 | isMac ? { role: 'close' } : { role: 'quit' }
67 | ]
68 | };
69 |
70 | const template = [
71 | // { role: 'appMenu' }
72 | ...(isMac ? [{
73 | label: app.name,
74 | submenu: [
75 | { role: 'about' },
76 | { type: 'separator' },
77 | { role: 'services' },
78 | { type: 'separator' },
79 | { role: 'hide' },
80 | { role: 'hideothers' },
81 | { role: 'unhide' },
82 | { type: 'separator' },
83 | { role: 'quit' }
84 | ]
85 | }] : []),
86 | // { role: 'fileMenu' }
87 | FileHandler,
88 | // { role: 'editMenu' }
89 | {
90 | label: 'Edit',
91 | submenu: [
92 | { role: 'undo' },
93 | { role: 'redo' },
94 | { type: 'separator' },
95 | { role: 'cut' },
96 | { role: 'copy' },
97 | { role: 'paste' },
98 | ...(isMac ? [
99 | { role: 'pasteAndMatchStyle' },
100 | { role: 'delete' },
101 | { role: 'selectAll' },
102 | { type: 'separator' },
103 | {
104 | label: 'Speech',
105 | submenu: [
106 | { role: 'startspeaking' },
107 | { role: 'stopspeaking' }
108 | ]
109 | }
110 | ] : [
111 | { role: 'delete' },
112 | { type: 'separator' },
113 | { role: 'selectAll' }
114 | ])
115 | ]
116 | },
117 | Action,
118 | // { role: 'viewMenu' }
119 | {
120 | label: 'View',
121 | submenu: [
122 | { role: 'reload' },
123 | { role: 'forcereload' },
124 | { type: 'separator' },
125 | { role: 'resetzoom' },
126 | { role: 'zoomin' },
127 | { role: 'zoomout' },
128 | { type: 'separator' },
129 | { role: 'togglefullscreen' }
130 | ]
131 | },
132 | {
133 | role: 'help',
134 | submenu: [
135 | {
136 | label: 'Report issue',
137 | click: async () => {
138 | await shell.openExternal('https://github.com/haikelfazzani/picode-desktop-app')
139 | }
140 | },
141 | { type: 'separator' },
142 | {
143 | label: 'About',
144 | click: async (menuItem, browserWindow, event) => {
145 | await dialog.showMessageBox(browserWindow, {
146 | title: 'About',
147 | type: 'info',
148 | message: 'PiJs v1.0.0',
149 | detail: 'Copyright © 2020 - Haikel Fazzani'
150 | });
151 | }
152 | }
153 | ]
154 | }
155 | ];
156 |
157 | module.exports = Menu.buildFromTemplate(template);
--------------------------------------------------------------------------------
/main_process/preload.js:
--------------------------------------------------------------------------------
1 | window.ipcRenderer = require('electron').ipcRenderer;
2 |
3 | window.fs = require('fs');
4 | window.fsPromises = require('fs').promises;
5 |
6 | window.path = require('path');
7 |
8 | window.childProcess = require('child_process');
9 |
10 | window.dirName = __dirname;
--------------------------------------------------------------------------------
/main_process/temp:
--------------------------------------------------------------------------------
1 | console.log('ok')
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "pijs",
3 | "version": "1.0.0",
4 | "description": "Javascript and typescript playground",
5 | "icon": "icons/logo256.png",
6 | "main": "dist/electron.js",
7 | "scripts": {
8 | "start": "webpack-dev-server --config webpack.dev.js",
9 | "build": "webpack --config webpack.prod.js",
10 | "el": "electron .",
11 | "packager": "electron-packager . --ignore=^/src",
12 | "pack": "electron-builder --dir",
13 | "dist": "electron-builder"
14 | },
15 | "keywords": [
16 | "playground",
17 | "code",
18 | "editor"
19 | ],
20 | "author": "Haikel Fazzani",
21 | "license": "MIT",
22 | "dependencies": {
23 | "ts-node": "^8.6.2",
24 | "typescript": "^3.8.3"
25 | },
26 | "devDependencies": {
27 | "@babel/core": "^7.8.4",
28 | "@babel/preset-react": "^7.8.3",
29 | "babel-loader": "^8.0.6",
30 | "clean-webpack-plugin": "^3.0.0",
31 | "copy-webpack-plugin": "^5.1.1",
32 | "css-loader": "^3.4.2",
33 | "electron": "^13.6.6",
34 | "electron-builder": "^22.4.0",
35 | "file-loader": "^5.1.0",
36 | "html-loader": "^0.5.5",
37 | "html-webpack-plugin": "^3.2.0",
38 | "mini-css-extract-plugin": "^0.9.0",
39 | "node-sass": "^4.13.1",
40 | "optimize-css-assets-webpack-plugin": "^5.0.3",
41 | "sass-loader": "^8.0.2",
42 | "style-loader": "^1.1.3",
43 | "terser-webpack-plugin": "^2.3.5",
44 | "webpack": "^4.41.6",
45 | "webpack-cli": "^3.3.11",
46 | "webpack-dev-server": "^3.10.3",
47 | "webpack-merge": "^4.2.2",
48 | "ace-builds": "^1.4.8",
49 | "react": "^16.12.0",
50 | "react-ace": "^8.0.0",
51 | "react-dom": "^16.12.0",
52 | "react-split": "^2.0.7",
53 | "js-beautify": "^1.10.3"
54 | },
55 | "build": {
56 | "asar": false,
57 | "win": {
58 | "target": [
59 | {
60 | "target": "nsis",
61 | "arch": [
62 | "x64"
63 | ]
64 | }
65 | ]
66 | },
67 | "nsis": {
68 | "installerIcon": "icons/logo.ico",
69 | "uninstallerIcon": "icons/logo.ico",
70 | "license": "License.md"
71 | },
72 | "directories": {
73 | "buildResources": "dist",
74 | "output": "build"
75 | },
76 | "files": [
77 | "dist/electron.js",
78 | "dist/*",
79 | "dist/*/**",
80 | "!**/node_modules/*",
81 | "!icons/*"
82 | ]
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/render_process/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | PiJs - Playground
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/App.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import Split from 'react-split'
3 |
4 | import CodeEditor from "./containers/CodeEditor";
5 | import ResultPane from "./containers/ResultPane";
6 | import Footer from './components/Footer';
7 |
8 | import './index.scss';
9 |
10 | export default function App () {
11 |
12 | return (
13 | <>
14 |
21 |
22 |
23 |
24 |
25 |
26 | >
27 | );
28 | }
--------------------------------------------------------------------------------
/src/components/Editor.js:
--------------------------------------------------------------------------------
1 | import React, { useContext, useEffect, useRef } from 'react';
2 | import GlobalContext from '../providers/GlobalContext';
3 | import AceEditor from "react-ace";
4 |
5 | import "ace-builds/src-noconflict/mode-typescript";
6 |
7 | import "ace-builds/src-noconflict/theme-monokai";
8 | import "ace-builds/src-noconflict/theme-material";
9 | import "ace-builds/src-noconflict/theme-dracula";
10 |
11 | import "ace-builds/src-noconflict/ext-language_tools";
12 |
13 | export default function Editor ({ value, id = 'my-ace-editor', onChange, showLineNumbers = true }) {
14 |
15 | const { globalState } = useContext(GlobalContext);
16 | const aceEditor = useRef();
17 |
18 | useEffect(() => {
19 | let editor = aceEditor.current.editor;
20 | editor.commands.bindKeys({ "ctrl-l": null, "left": null });
21 | }, []);
22 |
23 | return ;
45 | }
--------------------------------------------------------------------------------
/src/components/Footer.js:
--------------------------------------------------------------------------------
1 | import React, { useState, useEffect } from 'react';
2 | import '../styles/footer.scss';
3 | import Snackbar from './Snackbar';
4 | import Settings from '../containers/Settings';
5 |
6 | export default function Footer () {
7 |
8 | const [showSettings, setShowSettings] = useState(false);
9 | const [isFileSaved, setIsFileSaved] = useState(false);
10 |
11 | useEffect(() => {
12 | window.ipcRenderer.on('save-file', async (channel, isSaved) => {
13 | setIsFileSaved(isSaved);
14 | });
15 | }, []);
16 |
17 | return ();
30 | }
--------------------------------------------------------------------------------
/src/components/InputCheck.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | export default function InputCheck ({ onChange, checked, name, text }) {
4 | return
5 |
11 |
12 |
;
13 | }
--------------------------------------------------------------------------------
/src/components/Select.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | export default function Select ({ onChange, data, clx }) {
4 | return ;
7 | }
--------------------------------------------------------------------------------
/src/components/Snackbar.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | export default function Snackbar ({ msg, show, setShow, position = 'snack-center ' }) {
4 | return
5 |
6 | {msg}
7 | { setShow(false) }}>×
8 |
9 |
;
10 | }
--------------------------------------------------------------------------------
/src/containers/CodeEditor.js:
--------------------------------------------------------------------------------
1 | import React, { useState, useEffect } from 'react';
2 | import Editor from '../components/Editor';
3 | import FileManager from '../util/FileManager';
4 |
5 | export default function CodeEditor () {
6 |
7 | const [editorValue, setEditorValue] = useState(FileManager.loadFileSync());
8 |
9 | useEffect(() => {
10 | window.ipcRenderer.on('open-file', async (channel, fileContent) => {
11 | if (fileContent) {
12 | setEditorValue(fileContent);
13 | }
14 | });
15 |
16 | window.ipcRenderer.on('format-code', async (channel, _) => {
17 | let fileContent = await FileManager.formatCode();
18 | setEditorValue(fileContent);
19 | });
20 | }, []);
21 |
22 | const onEditorChange = async (data) => {
23 | setEditorValue(data);
24 | await FileManager.writeFile(data);
25 | }
26 |
27 | return ;
28 | }
--------------------------------------------------------------------------------
/src/containers/ResultPane.js:
--------------------------------------------------------------------------------
1 | import React, { useState, useEffect } from 'react';
2 | import '../styles/ResultPane.scss';
3 | import Editor from '../components/Editor';
4 | import ExecCode from '../util/ExecCode';
5 | import GlobalContext from '../providers/GlobalContext';
6 |
7 | export default function ResultPane () {
8 |
9 | const [codeOutput, setCodeOutput] = useState();
10 |
11 | useEffect(() => {
12 | window.ipcRenderer.on('run-code', async (channel, data) => {
13 | try {
14 | let result = await ExecCode();
15 | setCodeOutput(result);
16 | } catch (error) {
17 | setCodeOutput(error);
18 | }
19 | });
20 | }, []);
21 |
22 | return ;
23 | }
--------------------------------------------------------------------------------
/src/containers/Settings.js:
--------------------------------------------------------------------------------
1 | import React, { useContext } from 'react';
2 | import Select from '../components/Select';
3 | import '../styles/Settings.scss';
4 | import GlobalContext from '../providers/GlobalContext';
5 | import InputCheck from '../components/InputCheck';
6 |
7 | const fontSizes = ['10', '12', '14', '16', '18', '20', '22', '24'];
8 | const themes = ['dracula', 'monokai', 'material'];
9 |
10 | export default function Settings ({ showSettings, setShowSettings }) {
11 |
12 | const { globalState, setGlobalState } = useContext(GlobalContext);
13 |
14 | const onFontSize = (e) => {
15 | setGlobalState({ ...globalState, fontsize: e.target.value });
16 | }
17 |
18 | const onThemes = (e) => {
19 | setGlobalState({ ...globalState, theme: e.target.value });
20 | }
21 |
22 | const onSettings = (e) => {
23 | setGlobalState({ ...globalState, [e.target.name]: e.target.checked });
24 | }
25 |
26 | return (
27 |
28 |
29 |
30 |
settings
31 | { setShowSettings(!showSettings) }} className="btn-close-settings">
32 | ✕
33 |
34 |
35 |
36 |
37 |
38 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
);
57 | }
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import App from './App';
4 | import GlobalProvider from './providers/GlobalProvider';
5 |
6 | ReactDOM.render(
7 |
8 |
9 | ,
10 | document.getElementById('root')
11 | );
12 |
--------------------------------------------------------------------------------
/src/index.scss:
--------------------------------------------------------------------------------
1 | *::after {
2 | box-sizing: border-box;
3 | }
4 |
5 | html {
6 | font-family: sans-serif;
7 | line-height: 1.15;
8 | -webkit-text-size-adjust: 100%;
9 | -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
10 | }
11 |
12 | body {
13 | margin: 0;
14 | width: 100vw;
15 | height: 100vh;
16 | font-size: 1rem;
17 | font-weight: 400;
18 | line-height: 1.5;
19 | background-color: #272822;
20 | color: #ffffff;
21 | text-align: left;
22 | overflow-x: hidden;
23 | }
24 |
25 | #root {
26 | height: 100%;
27 | width: 100%;
28 | }
29 |
30 | #root>div {
31 | display: flex;
32 | width: 100%;
33 | height: 97%;
34 | }
35 |
36 | .gutter {
37 | border-right: 1px solid #646464;
38 | cursor: col-resize;
39 | &:hover { background-color: #2255ff; }
40 | }
41 |
42 |
43 | .ace_editor,
44 | #my-ace-editor, #result-pane {
45 | height: 100% !important;
46 | overflow-x: hidden !important;
47 | }
48 |
49 | .ace_gutter {
50 | background-color: inherit !important;
51 | }
52 |
53 | /* util */
54 | .d-flex { display: flex; align-items: center;}
55 |
56 | .fs-12 {font-size: 12px !important;}
57 |
58 | .pt-10 {padding-top: 10px !important;}
59 | .py-15 {padding: 0 15px !important;}
60 |
61 | .m-0 {margin: 0 !important; }
62 | .mt-0 { margin-top: 0 !important;}
63 | .mt-5 { margin-top: 5px !important;}
64 |
65 | .mb-10 { margin-bottom: 10px !important;}
66 | .mr-10 {margin-right: 10px !important;}
67 |
68 | .border-top { border-top: 1px solid #212529; }
69 | /* snackbar */
70 | .snackbar {
71 | visibility: hidden;
72 | margin-left: -125px;
73 | font-size: 14px !important;
74 | background-color: #006192;
75 | color: #fff;
76 | padding: 5px 15px;
77 | border-radius: 7px;
78 | z-index: 999;
79 |
80 | .snackbar-content {
81 | width: 100px;
82 | display: flex;
83 | justify-content: space-between;
84 | align-items: center;
85 | .sn-btn-close {
86 | color: #dbdbdb;
87 | cursor: pointer;
88 | &:hover {color: #ffffff !important;}
89 | }
90 | }
91 | }
92 |
93 | .snack-right {
94 | position: fixed;
95 | right: 5%;
96 | bottom: 30px;
97 | }
98 |
99 | .snack-center {
100 | position: fixed;
101 | left: 50%;
102 | bottom: 30px;
103 | }
104 |
105 | .snackbar.show {
106 | visibility: visible;
107 | animation: fadein 0.5s, fadeout 0.5s 2.5s;
108 | }
109 |
110 | @keyframes fadein {
111 | from {
112 | bottom: 0;
113 | opacity: 0;
114 | }
115 |
116 | to {
117 | bottom: 40px;
118 | opacity: 1;
119 | }
120 | }
121 |
122 | @keyframes fadeout {
123 | from {
124 | bottom: 40px;
125 | opacity: 1;
126 | }
127 |
128 | to {
129 | bottom: 0;
130 | opacity: 0;
131 | }
132 | }
133 |
134 | ::-webkit-scrollbar {
135 | width: 5px;
136 | }
137 |
138 | ::-webkit-scrollbar-thumb {
139 | background: #555;
140 | }
141 |
142 | ::-webkit-scrollbar-thumb:hover {
143 | background: #363636;
144 | }
--------------------------------------------------------------------------------
/src/providers/GlobalContext.js:
--------------------------------------------------------------------------------
1 | import { createContext } from 'react';
2 | const GlobalContext = createContext();
3 | export default GlobalContext;
--------------------------------------------------------------------------------
/src/providers/GlobalProvider.js:
--------------------------------------------------------------------------------
1 | import React, { useState, useEffect } from 'react';
2 | import GlobalContext from './GlobalContext';
3 | import JsonStore from '../util/JsonStore';
4 |
5 | let configStore = JsonStore.get();
6 |
7 | /** init values global state */
8 | let initState = {
9 | usercode: configStore.usercode,
10 | language: configStore.language,
11 | fileExtension: configStore['fileExtension'],
12 | currfilepath: configStore['currfilepath'],
13 | fontsize: configStore.fontsize,
14 | theme: configStore.theme,
15 | wrapEnabled: configStore['wrapEnabled'],
16 | showPrintMargin: configStore['showPrintMargin'],
17 | autosave: configStore['autosave']
18 | };
19 |
20 | export default function GlobalProvider ({ children }) {
21 | const [globalState, setGlobalState] = useState(initState);
22 |
23 | useEffect(() => {
24 | JsonStore.updateConfigFile(globalState);
25 | }, [globalState]);
26 |
27 | return
28 | {children}
29 | ;
30 | }
--------------------------------------------------------------------------------
/src/styles/ResultPane.scss:
--------------------------------------------------------------------------------
1 | #result-pane {
2 | height: 100% !important;
3 | }
--------------------------------------------------------------------------------
/src/styles/Settings.scss:
--------------------------------------------------------------------------------
1 | .settings {
2 | width: 100%;
3 | height: 100%;
4 | background-color: #00000052;
5 | position: fixed;
6 | top: 0;
7 | left: 0;
8 | display: flex;
9 | justify-content: center;
10 | align-items: center;
11 | z-index: 999;
12 | }
13 |
14 | .settings-content {
15 | width: 400px;
16 | background-color: #1e1e1e;
17 | padding: 20px;
18 | border-radius: 4px;
19 | box-shadow: 0 0 20px rgba(0, 0, 0, .1), 0 20px 20px rgba(0, 0, 0, .2);
20 |
21 | .settings-header {
22 | width: 100%;
23 | display: flex;
24 | justify-content: space-between;
25 | align-items: center;
26 | padding-bottom: 10px;
27 | border-bottom: 1px solid #212529;
28 |
29 | h4 {
30 | margin: 0;
31 | text-transform: uppercase;
32 | }
33 |
34 | .btn-close-settings {
35 | color: #a0a0a0;
36 | cursor: pointer;
37 | transition: color .3s;
38 | &:hover {color: #ffffff;}
39 | }
40 | }
41 |
42 | input {margin: 0;}
43 | label {font-size: 12px;text-transform: uppercase;}
44 | p { color: #a0a0a0 !important;}
45 | select {width: 100%;padding: 5px 0;}
46 | }
--------------------------------------------------------------------------------
/src/styles/footer.scss:
--------------------------------------------------------------------------------
1 | footer {
2 | margin: 0;
3 | height: 3%;
4 | background-color: #2255ff;
5 | font-size: 12px;
6 | display: flex;
7 | justify-content: flex-end;
8 | align-items: center;
9 |
10 | button {
11 | height: 100%;
12 | background-color: #28292c;
13 | color: #ffffff;
14 | border: 0;
15 | padding: 0 15px;
16 | font-size: 12px;
17 | text-transform: uppercase;
18 | cursor: pointer;
19 | }
20 | }
--------------------------------------------------------------------------------
/src/util/ExecCode.js:
--------------------------------------------------------------------------------
1 | import JsonStore from "./JsonStore";
2 |
3 | let execFile = window.childProcess.execFile;
4 | let exec = window.childProcess.exec;
5 |
6 | export default async function ExecCode () {
7 |
8 | return new Promise((resolve, reject) => {
9 |
10 | let filePath = JsonStore.getPropVal('currfilepath');
11 | let language = JsonStore.getPropVal('language');
12 |
13 | switch (language) {
14 | case 'javascript':
15 | execFile('node', [filePath], (err, stdout, stderr) => {
16 | if (stderr) reject(stderr || error);
17 | else resolve(stdout);
18 | });
19 | break;
20 |
21 | case 'typescript':
22 | exec('ts-node ' + filePath, (error, stdout, stderr) => {
23 | if (stderr) { reject(stderr || error); }
24 | else resolve(stdout);
25 | });
26 | break;
27 |
28 | case 'golang':
29 | exec('go run ' + filePath, (error, stdout, stderr) => {
30 | if (stderr) { reject(stderr || error); }
31 | else resolve(stdout);
32 | });
33 | break;
34 |
35 | default:
36 | break;
37 | }
38 | });
39 | }
--------------------------------------------------------------------------------
/src/util/FileManager.js:
--------------------------------------------------------------------------------
1 | import js_beautify from 'js-beautify/js';
2 | import JsonStore from './JsonStore';
3 | const TEMP_FILE_PATH = window.path.join(window.dirName, 'temp');
4 |
5 | export default class FileManager {
6 |
7 | /**
8 | *
9 | * @param {string} filePath
10 | * @returns string
11 | */
12 | static async readWriteFile (filePath) {
13 |
14 | this.fileErros = '';
15 |
16 | let data = null;
17 | try {
18 | data = await window.fsPromises.readFile(filePath, { encoding: 'utf8' });
19 | await window.fsPromises.writeFile(TEMP_FILE_PATH, data, { encoding: 'utf8' });
20 | } catch (error) {
21 | this.fileErros = error.message;
22 | }
23 | return data;
24 | }
25 |
26 | /**
27 | * default temp file
28 | * @param {string} filePath
29 | * @returns {string}
30 | */
31 | static async loadFile (filePath = TEMP_FILE_PATH) {
32 |
33 | let data = null;
34 | try {
35 | data = await window.fsPromises.readFile(filePath, { encoding: 'utf8' });
36 | } catch (error) {
37 | this.fileErros = error.message;
38 | }
39 | return data;
40 | }
41 |
42 | /**
43 | * default temp file
44 | * @param {string} filePath
45 | */
46 | static async writeFile (data, filePath = TEMP_FILE_PATH) {
47 | try {
48 | await window.fsPromises.writeFile(filePath, data, { encoding: 'utf8' });
49 | } catch (error) {
50 | this.fileErros = error.message;
51 | }
52 | }
53 |
54 |
55 | /**
56 | * default temp file
57 | * @param {string} filePath
58 | * @returns {string}
59 | */
60 | static loadFileSync (filePath = TEMP_FILE_PATH) {
61 | let data = '';
62 | try {
63 | data = window.fs.readFileSync(filePath, 'utf8');
64 | } catch (error) {
65 | this.fileErros = error.message;
66 | }
67 | return data;
68 | }
69 |
70 | static async formatCode () {
71 | let tempFileContent = await this.loadFile();
72 | let lang = await JsonStore.getPropVal('language');
73 |
74 | return tempFileContent
75 | ? js_beautify.js(tempFileContent, { indent_size: 2, space_in_empty_paren: true })
76 | : tempFileContent;
77 | }
78 | }
--------------------------------------------------------------------------------
/src/util/JsonStore.js:
--------------------------------------------------------------------------------
1 | var STORE_PATH = window.path.join(window.dirName, 'config.json');
2 |
3 | export default class JsonStore {
4 |
5 | constructor () {
6 | this.storeContent = window.fs.readFileSync(STORE_PATH, 'utf8');
7 | this.store = JSON.parse(this.storeContent);
8 | }
9 |
10 | static get () {
11 | this.storeContent = window.fs.readFileSync(STORE_PATH, 'utf8');
12 | try {
13 | this.store = JSON.parse(this.storeContent);
14 | return this.store;
15 | } catch (error) {
16 | return {
17 | "usercode": "console.log('ok')",
18 | "language": "javascript",
19 | "filename": null,
20 | "fileExtension": null,
21 | "currfilepath": (window.dirName + '/temp'),
22 | "fontsize": "16",
23 | "theme": "monokai",
24 | "issaved": false,
25 | "wrapEnabled": false,
26 | "showPrintMargin": false,
27 | "autosave": false
28 | };
29 | }
30 | }
31 |
32 | static getPropVal (prop) {
33 | this.store = this.get();
34 | return this.store[prop];
35 | }
36 |
37 | static async pushOrUpdate (field, value) {
38 | try {
39 | this.store = this.get() || {};
40 | this.store[field] = value;
41 | await window.fsPromises.writeFile(STORE_PATH, JSON.stringify(this.store), { encoding: 'utf8' });
42 | } catch (error) {
43 | console.log(error);
44 | }
45 | }
46 |
47 | static async updateConfigFile (configs) {
48 | this.store = this.get();
49 |
50 | Object.keys(configs).forEach(keys => {
51 | this.store[keys] = configs[keys];
52 | });
53 |
54 | await window.fsPromises.writeFile(STORE_PATH, JSON.stringify(this.store), { encoding: 'utf8' });
55 | }
56 | }
--------------------------------------------------------------------------------
/webpack.common.js:
--------------------------------------------------------------------------------
1 | const path = require("path");
2 |
3 | module.exports = {
4 | entry: {
5 | main: "./src/index.js"
6 | },
7 | module: {
8 | rules: [
9 | {
10 | test: /\.js$/,
11 | exclude: /node_modules/,
12 | include: path.resolve(__dirname, 'src'),
13 | use: ["babel-loader"]
14 | },
15 | {
16 | test: /\.scss$/,
17 | use: ["style-loader", "css-loader", "sass-loader"]
18 | },
19 | {
20 | test: /\.html$/,
21 | use: ["html-loader"]
22 | },
23 | {
24 | test: /\.(svg|png|jpg|gif|ttf)$/,
25 | use: {
26 | loader: "file-loader",
27 | options: {
28 | name: "[name].[hash].[ext]",
29 | outputPath: "assets"
30 | }
31 | }
32 | }
33 | ]
34 | }
35 | };
--------------------------------------------------------------------------------
/webpack.dev.js:
--------------------------------------------------------------------------------
1 | const path = require("path");
2 | const common = require("./webpack.common");
3 | const merge = require("webpack-merge");
4 | var HtmlWebpackPlugin = require("html-webpack-plugin");
5 |
6 | module.exports = merge(common, {
7 | mode: "development",
8 | devServer:{disableHostCheck:true},
9 | output: {
10 | filename: "[name].bundle.js",
11 | path: path.resolve(__dirname, "dist")
12 | },
13 | devtool: 'inline-source-map',
14 | plugins: [
15 | new HtmlWebpackPlugin({ template: "./render_process/index.html", })
16 | ]
17 | });
--------------------------------------------------------------------------------
/webpack.prod.js:
--------------------------------------------------------------------------------
1 | const path = require("path");
2 | const common = require("./webpack.common");
3 | const merge = require("webpack-merge");
4 | const { CleanWebpackPlugin } = require('clean-webpack-plugin');
5 |
6 | const MiniCssExtractPlugin = require("mini-css-extract-plugin");
7 | const OptimizeCssAssetsPlugin = require("optimize-css-assets-webpack-plugin");
8 | const TerserPlugin = require("terser-webpack-plugin");
9 | var HtmlWebpackPlugin = require("html-webpack-plugin");
10 |
11 | const CopyPlugin = require('copy-webpack-plugin');
12 |
13 | module.exports = merge(common, {
14 | mode: "production",
15 | performance: {
16 | hints: false,
17 | maxEntrypointSize: 512000,
18 | maxAssetSize: 512000
19 | },
20 | output: {
21 | filename: "[name].[contentHash].bundle.js",
22 | path: path.resolve(__dirname, "dist")
23 | },
24 | devtool: false,
25 | optimization: {
26 | minimize: true,
27 | minimizer: [
28 | new OptimizeCssAssetsPlugin(),
29 | new TerserPlugin(),
30 | new HtmlWebpackPlugin({ template: "./render_process/index.html" })
31 | ]
32 | },
33 | plugins: [
34 | new MiniCssExtractPlugin({ filename: "[name].[contentHash].css" }),
35 | new CleanWebpackPlugin(),
36 | new CopyPlugin([{ from: 'main_process', to: '' }]),
37 | ],
38 | module: {
39 | rules: [
40 | {
41 | test: /\.(scss|css)$/,
42 | use: [MiniCssExtractPlugin.loader, "css-loader", "sass-loader"]
43 | }
44 | ]
45 | }
46 | });
--------------------------------------------------------------------------------