├── .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 | ![Capture](https://i.ibb.co/zQq6jBt/Nouvelle-image-bitmap.png) 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 | ![](icons/logo.ico) 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 |