├── .erb ├── mocks │ └── fileMock.js ├── configs │ ├── .eslintrc │ ├── webpack.config.eslint.js │ ├── webpack.config.base.js │ ├── webpack.config.renderer.dev.dll.babel.js │ ├── webpack.config.main.prod.babel.js │ ├── webpack.config.renderer.prod.babel.js │ └── webpack.config.renderer.dev.babel.js ├── scripts │ ├── .eslintrc │ ├── BabelRegister.js │ ├── DeleteSourceMaps.js │ ├── CheckNodeEnv.js │ ├── CheckPortInUse.js │ ├── ElectronRebuild.js │ ├── CheckBuildsExist.js │ ├── Notarize.js │ └── CheckNativeDep.js └── ELECTRON_REACT_BOILERPLATE_LICENSE ├── shortcut-examples ├── sp └── sp.cmd ├── assets ├── icon.icns ├── icon.ico ├── icon.png ├── icons │ ├── 128x128.png │ ├── 16x16.png │ ├── 24x24.png │ ├── 256x256.png │ ├── 32x32.png │ ├── 48x48.png │ ├── 512x512.png │ ├── 64x64.png │ ├── 96x96.png │ └── 1024x1024.png ├── assets.d.ts ├── entitlements.mac.plist └── icon.svg ├── src ├── main.prod.js.LICENSE.txt ├── yarn.lock ├── CommandStatus.ts ├── __mocks__ │ └── electron.js ├── Components │ ├── App │ │ ├── App.test.tsx │ │ ├── CommandsPanel │ │ │ ├── CacheBar │ │ │ │ ├── Constants.ts │ │ │ │ ├── CacheBarButton.tsx │ │ │ │ └── CoolButHardcodedCacheBar.tsx │ │ │ ├── CuteRightPointingButton.tsx │ │ │ ├── PlusDivider.tsx │ │ │ ├── CommandsPanel.tsx │ │ │ └── SingleCommandPanel.tsx │ │ ├── App.global.css │ │ ├── BrowseButton.tsx │ │ ├── OutputPanel.tsx │ │ ├── App.tsx │ │ └── SettingsPanel.tsx │ ├── Common │ │ ├── CopiedSuccessfulySnackbar.tsx │ │ ├── MousetrapWrapper.tsx │ │ ├── CircularProgress.tsx │ │ └── HelpPopup.tsx │ └── ThemeStuff │ │ ├── ThemeTypeFixes.ts │ │ └── theme.tsx ├── index.tsx ├── package.json ├── TypeDeclarations │ └── ReactResizePanel.d.ts ├── index.html ├── JssUtils.ts ├── PiperStore.test.ts ├── utils.test.ts ├── main.dev.ts ├── utils.ts ├── Command.ts ├── menu.ts └── PiperStore.ts ├── bash pipe helper.bmpr ├── pictures └── shellpiper1.png ├── .vscode ├── extensions.json ├── tasks.json ├── settings.json └── launch.json ├── .gitattributes ├── .editorconfig ├── .github └── workflows │ ├── test.yml │ └── publish.yml ├── tsconfig.json ├── .gitignore ├── .eslintignore ├── babel.config.js ├── .eslintrc.js ├── README.md ├── package.json └── LICENSE /.erb/mocks/fileMock.js: -------------------------------------------------------------------------------- 1 | export default 'test-file-stub'; 2 | -------------------------------------------------------------------------------- /shortcut-examples/sp: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | "/path/to/ShellPiper.exe" 3 | -------------------------------------------------------------------------------- /shortcut-examples/sp.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | start "" "C:\path\to\ShellPiper.exe" 3 | -------------------------------------------------------------------------------- /assets/icon.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheYarin/ShellPiper/HEAD/assets/icon.icns -------------------------------------------------------------------------------- /assets/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheYarin/ShellPiper/HEAD/assets/icon.ico -------------------------------------------------------------------------------- /assets/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheYarin/ShellPiper/HEAD/assets/icon.png -------------------------------------------------------------------------------- /src/main.prod.js.LICENSE.txt: -------------------------------------------------------------------------------- 1 | /*! http://mths.be/fromcodepoint v0.1.0 by @mathias */ 2 | -------------------------------------------------------------------------------- /bash pipe helper.bmpr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheYarin/ShellPiper/HEAD/bash pipe helper.bmpr -------------------------------------------------------------------------------- /assets/icons/128x128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheYarin/ShellPiper/HEAD/assets/icons/128x128.png -------------------------------------------------------------------------------- /assets/icons/16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheYarin/ShellPiper/HEAD/assets/icons/16x16.png -------------------------------------------------------------------------------- /assets/icons/24x24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheYarin/ShellPiper/HEAD/assets/icons/24x24.png -------------------------------------------------------------------------------- /assets/icons/256x256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheYarin/ShellPiper/HEAD/assets/icons/256x256.png -------------------------------------------------------------------------------- /assets/icons/32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheYarin/ShellPiper/HEAD/assets/icons/32x32.png -------------------------------------------------------------------------------- /assets/icons/48x48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheYarin/ShellPiper/HEAD/assets/icons/48x48.png -------------------------------------------------------------------------------- /assets/icons/512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheYarin/ShellPiper/HEAD/assets/icons/512x512.png -------------------------------------------------------------------------------- /assets/icons/64x64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheYarin/ShellPiper/HEAD/assets/icons/64x64.png -------------------------------------------------------------------------------- /assets/icons/96x96.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheYarin/ShellPiper/HEAD/assets/icons/96x96.png -------------------------------------------------------------------------------- /pictures/shellpiper1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheYarin/ShellPiper/HEAD/pictures/shellpiper1.png -------------------------------------------------------------------------------- /assets/icons/1024x1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheYarin/ShellPiper/HEAD/assets/icons/1024x1024.png -------------------------------------------------------------------------------- /src/yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | -------------------------------------------------------------------------------- /.erb/configs/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "no-console": "off", 4 | "global-require": "off", 5 | "import/no-dynamic-require": "off" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "dbaeumer.vscode-eslint", 4 | "EditorConfig.EditorConfig", 5 | "msjsdiag.debugger-for-chrome" 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /.erb/scripts/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "no-console": "off", 4 | "global-require": "off", 5 | "import/no-dynamic-require": "off", 6 | "import/no-extraneous-dependencies": "off" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /.erb/configs/webpack.config.eslint.js: -------------------------------------------------------------------------------- 1 | /* eslint import/no-unresolved: off, import/no-self-import: off */ 2 | require('@babel/register'); 3 | 4 | module.exports = require('./webpack.config.renderer.dev.babel').default; 5 | -------------------------------------------------------------------------------- /.erb/scripts/BabelRegister.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | 3 | require('@babel/register')({ 4 | extensions: ['.es6', '.es', '.jsx', '.js', '.mjs', '.ts', '.tsx'], 5 | cwd: path.join(__dirname, '../..'), 6 | }); 7 | -------------------------------------------------------------------------------- /src/CommandStatus.ts: -------------------------------------------------------------------------------- 1 | enum CommandStatus { 2 | NEW, 3 | RUNNING, 4 | KILLED_UNKNOWN_REASON, 5 | KILLED_MANUALLY, 6 | KILLED_NEXT_COMMAND_CLOSED, 7 | ERROR, 8 | EXITED, 9 | } 10 | 11 | export default CommandStatus; 12 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text eol=lf 2 | *.exe binary 3 | *.png binary 4 | *.jpg binary 5 | *.jpeg binary 6 | *.ico binary 7 | *.icns binary 8 | *.eot binary 9 | *.otf binary 10 | *.ttf binary 11 | *.woff binary 12 | *.woff2 binary 13 | -------------------------------------------------------------------------------- /src/__mocks__/electron.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | // require: jest.fn(), 3 | // match: jest.fn(), 4 | // app: jest.fn(), 5 | remote: { 6 | // app: { 7 | // getPath: jest.fn(), 8 | // }, 9 | dialog: jest.fn(), 10 | }, 11 | }; 12 | -------------------------------------------------------------------------------- /.erb/scripts/DeleteSourceMaps.js: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import rimraf from 'rimraf'; 3 | 4 | export default function deleteSourceMaps() { 5 | rimraf.sync(path.join(__dirname, '../../src/dist/*.js.map')); 6 | rimraf.sync(path.join(__dirname, '../../src/*.js.map')); 7 | } 8 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | max_line_length = 130 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /assets/assets.d.ts: -------------------------------------------------------------------------------- 1 | declare module "*.svg" { 2 | const content: any; 3 | export default content; 4 | } 5 | 6 | declare module "*.png" { 7 | const content: any; 8 | export default content; 9 | } 10 | 11 | declare module "*.jpg" { 12 | const content: any; 13 | export default content; 14 | } 15 | -------------------------------------------------------------------------------- /src/Components/App/App.test.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import "@testing-library/jest-dom"; 3 | import { render } from "@testing-library/react"; 4 | import App from "./App"; 5 | 6 | describe("App", () => { 7 | it("should render", () => { 8 | expect(render()).toBeTruthy(); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /src/Components/App/CommandsPanel/CacheBar/Constants.ts: -------------------------------------------------------------------------------- 1 | import { lighten, Theme } from "@material-ui/core"; 2 | 3 | export const availableCacheBarColor = (theme: Theme) => lighten(theme.palette.primary.main, 0.81); 4 | // lighten(theme.palette.primary.main, 0.76); 5 | export const cacheToUseBarColor = (theme: Theme) => lighten(theme.palette.primary.main, 0.42); 6 | -------------------------------------------------------------------------------- /src/index.tsx: -------------------------------------------------------------------------------- 1 | import "@fontsource/roboto/300.css"; 2 | import "@fontsource/roboto/400.css"; 3 | import "@fontsource/roboto/500.css"; 4 | import "@fontsource/roboto/700.css"; 5 | 6 | import React from "react"; 7 | import { render } from "react-dom"; 8 | import App from "./Components/App/App"; 9 | 10 | render(, document.getElementById("root")); 11 | -------------------------------------------------------------------------------- /assets/entitlements.mac.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.cs.allow-unsigned-executable-memory 6 | 7 | com.apple.security.cs.allow-jit 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.erb/scripts/CheckNodeEnv.js: -------------------------------------------------------------------------------- 1 | import chalk from 'chalk'; 2 | 3 | export default function CheckNodeEnv(expectedEnv) { 4 | if (!expectedEnv) { 5 | throw new Error('"expectedEnv" not set'); 6 | } 7 | 8 | if (process.env.NODE_ENV !== expectedEnv) { 9 | console.log( 10 | chalk.whiteBright.bgRed.bold( 11 | `"process.env.NODE_ENV" must be "${expectedEnv}" to use this webpack config` 12 | ) 13 | ); 14 | process.exit(2); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /.erb/scripts/CheckPortInUse.js: -------------------------------------------------------------------------------- 1 | import chalk from 'chalk'; 2 | import detectPort from 'detect-port'; 3 | 4 | const port = process.env.PORT || '1212'; 5 | 6 | detectPort(port, (err, availablePort) => { 7 | if (port !== String(availablePort)) { 8 | throw new Error( 9 | chalk.whiteBright.bgRed.bold( 10 | `Port "${port}" on "localhost" is already in use. Please use another port. ex: PORT=4343 yarn start` 11 | ) 12 | ); 13 | } else { 14 | process.exit(0); 15 | } 16 | }); 17 | -------------------------------------------------------------------------------- /src/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "shell-piper", 3 | "productName": "ShellPiper", 4 | "description": "The shell piping editor", 5 | "version": "1.0.3", 6 | "main": "./main.prod.js", 7 | "author": { 8 | "name": "Yarin", 9 | "url": "https://github.com/TheYarin" 10 | }, 11 | "scripts": { 12 | "electron-rebuild": "node -r ../.erb/scripts/BabelRegister.js ../.erb/scripts/ElectronRebuild.js", 13 | "postinstall": "yarn electron-rebuild" 14 | }, 15 | "dependencies": {} 16 | } 17 | -------------------------------------------------------------------------------- /src/TypeDeclarations/ReactResizePanel.d.ts: -------------------------------------------------------------------------------- 1 | declare module "react-resize-panel" { 2 | import { CSSProperties } from "react"; 3 | 4 | interface ResizePanelProps { 5 | direction: "s" | "e" | "w" | "n"; 6 | containerClass?: string; 7 | handleClass?: string; 8 | borderClass?: string; 9 | style?: CSSProperties; 10 | } 11 | 12 | // eslint-disable-next-line react/prefer-stateless-function 13 | export default class ResizePanel extends React.Component {} 14 | } 15 | -------------------------------------------------------------------------------- /src/Components/App/App.global.css: -------------------------------------------------------------------------------- 1 | /* 2 | * @NOTE: Prepend a `~` to css file paths that are in your node_modules 3 | * See https://github.com/webpack-contrib/sass-loader#imports 4 | */ 5 | body { 6 | height: 100vh; 7 | 8 | /* min-height: min-content; */ /*I'm not sure this one actually do anything*/ 9 | /* min-width: min-content; */ 10 | 11 | font-family: sans-serif; 12 | overflow-y: hidden; 13 | 14 | margin: 0; 15 | } 16 | #root { 17 | width: 100%; 18 | height: 100%; 19 | } 20 | 21 | div[tabindex="-1"]:focus, 22 | pre[tabindex="-1"]:focus { 23 | outline: 0; 24 | } /*because MousetrapWrapper's `tabIndex=-1` causes an annoying outline to appear*/ 25 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "type": "npm", 6 | "label": "Start Webpack Dev", 7 | "script": "start:renderer", 8 | "options": { 9 | "cwd": "${workspaceFolder}" 10 | }, 11 | "isBackground": true, 12 | "problemMatcher": { 13 | "owner": "custom", 14 | "pattern": { 15 | "regexp": "____________" 16 | }, 17 | "background": { 18 | "activeOnStart": true, 19 | "beginsPattern": "Compiling\\.\\.\\.$", 20 | "endsPattern": "(Compiled successfully|Failed to compile)\\.$" 21 | } 22 | } 23 | } 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /.erb/scripts/ElectronRebuild.js: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import { execSync } from 'child_process'; 3 | import fs from 'fs'; 4 | import { dependencies } from '../../src/package.json'; 5 | 6 | const nodeModulesPath = path.join(__dirname, '../../src/node_modules'); 7 | 8 | if ( 9 | Object.keys(dependencies || {}).length > 0 && 10 | fs.existsSync(nodeModulesPath) 11 | ) { 12 | const electronRebuildCmd = 13 | '../node_modules/.bin/electron-rebuild --parallel --force --types prod,dev,optional --module-dir .'; 14 | const cmd = 15 | process.platform === 'win32' 16 | ? electronRebuildCmd.replace(/\//g, '\\') 17 | : electronRebuildCmd; 18 | execSync(cmd, { 19 | cwd: path.join(__dirname, '../../src'), 20 | stdio: 'inherit', 21 | }); 22 | } 23 | -------------------------------------------------------------------------------- /.erb/scripts/CheckBuildsExist.js: -------------------------------------------------------------------------------- 1 | // Check if the renderer and main bundles are built 2 | import path from 'path'; 3 | import chalk from 'chalk'; 4 | import fs from 'fs'; 5 | 6 | const mainPath = path.join(__dirname, '../../src/main.prod.js'); 7 | const rendererPath = path.join( 8 | __dirname, '../../src/dist/renderer.prod.js' 9 | ); 10 | 11 | if (!fs.existsSync(mainPath)) { 12 | throw new Error( 13 | chalk.whiteBright.bgRed.bold( 14 | 'The main process is not built yet. Build it by running "yarn build:main"' 15 | ) 16 | ); 17 | } 18 | 19 | if (!fs.existsSync(rendererPath)) { 20 | throw new Error( 21 | chalk.whiteBright.bgRed.bold( 22 | 'The renderer process is not built yet. Build it by running "yarn build:renderer"' 23 | ) 24 | ); 25 | } 26 | -------------------------------------------------------------------------------- /src/Components/Common/CopiedSuccessfulySnackbar.tsx: -------------------------------------------------------------------------------- 1 | import { Fade, makeStyles, Snackbar } from "@material-ui/core"; 2 | import { FileCopy as CopyIcon } from "@material-ui/icons"; 3 | import Alert from "@material-ui/lab/Alert"; 4 | import React from "react"; 5 | 6 | const useStyles = makeStyles((_theme) => ({ copyToast: {} })); 7 | 8 | export default function CopiedSuccessfulySnackbar({ open, onClose }: { open: boolean; onClose: () => void }) { 9 | const cls = useStyles(); 10 | 11 | return ( 12 | 13 | } variant="filled" className={cls.copyToast}> 14 | Copied successfuly 15 | 16 | 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | ".babelrc": "jsonc", 4 | ".eslintrc": "jsonc", 5 | ".prettierrc": "jsonc", 6 | ".eslintignore": "ignore" 7 | }, 8 | 9 | "javascript.validate.enable": false, 10 | "javascript.format.enable": false, 11 | "typescript.format.enable": false, 12 | 13 | "search.exclude": { 14 | ".git": true, 15 | ".eslintcache": true, 16 | "src/dist": true, 17 | "src/main.prod.js": true, 18 | "src/main.prod.js.map": true, 19 | "bower_components": true, 20 | "dll": true, 21 | "release": true, 22 | "node_modules": true, 23 | "npm-debug.log.*": true, 24 | "test/**/__snapshots__": true, 25 | "yarn.lock": true, 26 | "*.{css,sass,scss}.d.ts": true 27 | }, 28 | "prettier.printWidth": 130 29 | } 30 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | release: 7 | runs-on: ${{ matrix.os }} 8 | 9 | strategy: 10 | matrix: 11 | os: [macos-latest, windows-latest, ubuntu-latest] 12 | 13 | steps: 14 | - name: Check out Git repository 15 | uses: actions/checkout@v1 16 | 17 | - name: Install Node.js, NPM and Yarn 18 | uses: actions/setup-node@v1 19 | with: 20 | node-version: 15 21 | 22 | - name: yarn install 23 | run: | 24 | yarn install --frozen-lockfile --network-timeout 300000 25 | 26 | - name: yarn test 27 | env: 28 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 29 | run: | 30 | yarn package 31 | yarn lint 32 | yarn tsc 33 | yarn test 34 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2018", 4 | "module": "CommonJS", 5 | "lib": ["dom", "esnext"], 6 | "declaration": true, 7 | "declarationMap": true, 8 | "noEmit": true, 9 | "jsx": "react", 10 | "strict": true, 11 | "pretty": true, 12 | "sourceMap": true, 13 | /* Additional Checks */ 14 | // "noUnusedLocals": true, // Enforced by eslint 15 | // "noUnusedParameters": true, // Enforced by eslint 16 | "noImplicitReturns": true, 17 | "noFallthroughCasesInSwitch": true, 18 | /* Module Resolution Options */ 19 | "moduleResolution": "node", 20 | "esModuleInterop": true, 21 | "allowSyntheticDefaultImports": true, 22 | "resolveJsonModule": true, 23 | "allowJs": true 24 | }, 25 | "exclude": ["test", "release", "src/main.prod.js", "src/renderer.prod.js", "src/dist", ".erb/dll"] 26 | } 27 | -------------------------------------------------------------------------------- /.erb/scripts/Notarize.js: -------------------------------------------------------------------------------- 1 | const { notarize } = require('electron-notarize'); 2 | const { build } = require('../../package.json'); 3 | 4 | exports.default = async function notarizeMacos(context) { 5 | const { electronPlatformName, appOutDir } = context; 6 | if (electronPlatformName !== 'darwin') { 7 | return; 8 | } 9 | 10 | if (!process.env.CI) { 11 | console.warn('Skipping notarizing step. Packaging is not running in CI'); 12 | return; 13 | } 14 | 15 | if (!('APPLE_ID' in process.env && 'APPLE_ID_PASS' in process.env)) { 16 | console.warn('Skipping notarizing step. APPLE_ID and APPLE_ID_PASS env variables must be set'); 17 | return; 18 | } 19 | 20 | const appName = context.packager.appInfo.productFilename; 21 | 22 | await notarize({ 23 | appBundleId: build.appId, 24 | appPath: `${appOutDir}/${appName}.app`, 25 | appleId: process.env.APPLE_ID, 26 | appleIdPassword: process.env.APPLE_ID_PASS, 27 | }); 28 | }; 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # ShellPiper 2 | old.git 3 | 4 | # Logs 5 | logs 6 | *.log 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | 13 | # Directory for instrumented libs generated by jscoverage/JSCover 14 | lib-cov 15 | 16 | # Coverage directory used by tools like istanbul 17 | coverage 18 | 19 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 20 | .grunt 21 | 22 | # node-waf configuration 23 | .lock-wscript 24 | 25 | # Compiled binary addons (http://nodejs.org/api/addons.html) 26 | build/Release 27 | .eslintcache 28 | 29 | # Dependency directory 30 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 31 | node_modules 32 | 33 | # OSX 34 | .DS_Store 35 | 36 | # App packaged 37 | release 38 | src/main.prod.js 39 | src/main.prod.js.map 40 | src/renderer.prod.js 41 | src/renderer.prod.js.map 42 | src/style.css 43 | src/style.css.map 44 | dist 45 | dll 46 | main.js 47 | main.js.map 48 | 49 | .idea 50 | npm-debug.log.* 51 | *.css.d.ts 52 | *.sass.d.ts 53 | *.scss.d.ts 54 | -------------------------------------------------------------------------------- /src/Components/App/BrowseButton.tsx: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import { Button, ButtonProps, makeStyles } from "@material-ui/core"; 3 | import { remote, OpenDialogOptions } from "electron"; 4 | 5 | const { dialog } = remote; 6 | 7 | const useStyles = makeStyles({ root: {} }); 8 | 9 | type BrowseButtonProps = Omit & { 10 | onValue: (value: Electron.OpenDialogReturnValue) => void; 11 | dialogOptions: OpenDialogOptions; 12 | }; 13 | 14 | export default function BrowseButton({ onValue, dialogOptions, ...rest }: BrowseButtonProps) { 15 | const [isDialogOpen, setIsDialogOpen] = useState(false); 16 | 17 | const classes = useStyles(); 18 | 19 | return ( 20 | 34 | ); 35 | } 36 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # node-waf configuration 20 | .lock-wscript 21 | 22 | # Compiled binary addons (http://nodejs.org/api/addons.html) 23 | build/Release 24 | .eslintcache 25 | 26 | # Dependency directory 27 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 28 | node_modules 29 | 30 | # OSX 31 | .DS_Store 32 | 33 | # App packaged 34 | release 35 | src/*.main.prod.js 36 | src/main.prod.js 37 | src/main.prod.js.map 38 | src/renderer.prod.js 39 | src/renderer.prod.js.map 40 | src/style.css 41 | src/style.css.map 42 | dist 43 | dll 44 | main.js 45 | main.js.map 46 | 47 | .idea 48 | npm-debug.log.* 49 | __snapshots__ 50 | 51 | # Package.json 52 | package.json 53 | .travis.yml 54 | *.css.d.ts 55 | *.sass.d.ts 56 | *.scss.d.ts 57 | -------------------------------------------------------------------------------- /src/Components/Common/MousetrapWrapper.tsx: -------------------------------------------------------------------------------- 1 | import React, { HTMLProps, useEffect, useRef } from "react"; 2 | import Mousetrap from "mousetrap"; 3 | 4 | export default function MousetrapWrapper({ 5 | shortcutsAndHandlers, 6 | ...rest 7 | }: { 8 | shortcutsAndHandlers: [string | string[], () => void][]; 9 | } & HTMLProps) { 10 | const ref = useRef(null); 11 | 12 | useEffect(() => { 13 | if (!ref.current) throw new Error("This shouldn't happen, `ref.current` shouldn't be null once the component is mounted."); 14 | 15 | const mousetrap = Mousetrap(ref.current); 16 | 17 | for (const [shortcut, handler] of shortcutsAndHandlers) { 18 | mousetrap.bind(shortcut, handler); 19 | } 20 | 21 | return () => { 22 | for (const [shortcut, _handler] of shortcutsAndHandlers) { 23 | mousetrap.unbind(shortcut); 24 | } 25 | }; 26 | }); 27 | return
; // tabIndex is set so shortcuts will work on all children and not only focusable ones. A value of -1 was chosen so it won't actually mess with the tab order. 28 | } 29 | -------------------------------------------------------------------------------- /.erb/configs/webpack.config.base.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Base webpack config used across other specific configs 3 | */ 4 | 5 | import path from 'path'; 6 | import webpack from 'webpack'; 7 | import { dependencies as externals } from '../../src/package.json'; 8 | 9 | export default { 10 | externals: [...Object.keys(externals || {})], 11 | 12 | module: { 13 | rules: [ 14 | { 15 | test: /\.tsx?$/, 16 | exclude: /node_modules/, 17 | use: { 18 | loader: 'babel-loader', 19 | options: { 20 | cacheDirectory: true, 21 | }, 22 | }, 23 | }, 24 | ], 25 | }, 26 | 27 | output: { 28 | path: path.join(__dirname, '../../src'), 29 | // https://github.com/webpack/webpack/issues/1114 30 | libraryTarget: 'commonjs2', 31 | }, 32 | 33 | /** 34 | * Determine the array of extensions that should be used to resolve modules. 35 | */ 36 | resolve: { 37 | extensions: ['.js', '.jsx', '.json', '.ts', '.tsx'], 38 | modules: [path.join(__dirname, '../src'), 'node_modules'], 39 | }, 40 | 41 | plugins: [ 42 | new webpack.EnvironmentPlugin({ 43 | NODE_ENV: 'production', 44 | }), 45 | ], 46 | }; 47 | -------------------------------------------------------------------------------- /.erb/ELECTRON_REACT_BOILERPLATE_LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015-present Electron React Boilerplate 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "Electron: Main", 6 | "type": "node", 7 | "request": "launch", 8 | "protocol": "inspector", 9 | "runtimeExecutable": "yarn", 10 | "runtimeArgs": ["start:main --inspect=5858 --remote-debugging-port=9223"], 11 | "preLaunchTask": "Start Webpack Dev" 12 | }, 13 | { 14 | "name": "Electron: Renderer", 15 | "type": "chrome", 16 | "request": "attach", 17 | "port": 9223, 18 | "webRoot": "${workspaceFolder}", 19 | "timeout": 15000 20 | }, 21 | { 22 | "type": "node", 23 | "request": "launch", 24 | "name": "Jest Tests", 25 | "program": "${workspaceRoot}\\node_modules\\jest\\bin\\jest.js", 26 | "args": [ 27 | "-i" 28 | ], 29 | // "preLaunchTask": "build", 30 | "internalConsoleOptions": "openOnSessionStart", 31 | "outFiles": [ 32 | "${workspaceRoot}/dist/**/*" 33 | ], 34 | // "envFile": "${workspaceRoot}/.env" 35 | }, 36 | ], 37 | "compounds": [ 38 | { 39 | "name": "Electron: All", 40 | "configurations": ["Electron: Main", "Electron: Renderer"] 41 | } 42 | ] 43 | } 44 | -------------------------------------------------------------------------------- /src/Components/ThemeStuff/ThemeTypeFixes.ts: -------------------------------------------------------------------------------- 1 | // Shamelessly stolen from N1TZANKL's kippa-aduma 2 | 3 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 4 | import { PaletteColor } from "@material-ui/core/styles/createPalette"; // For some reason tsc shows seemingly unrelated issues if I comment out this import. 5 | 6 | // declare module '@material-ui/core/styles/createPalette' { 7 | // interface Palette { 8 | // primary: PaletteColor; 9 | // secondary: PaletteColor; 10 | // } 11 | // interface SimplePaletteColorOptions { 12 | // main: string; 13 | // dark?: string; 14 | // light?: string; 15 | // veryLight?: string; 16 | // superLight?: string; 17 | // } 18 | // } 19 | 20 | declare module "@material-ui/core/styles/createMuiTheme" { 21 | interface Theme { 22 | constants: { 23 | consoleBackground: string; 24 | consoleTextColor: string; 25 | lowProfileButtonColor: string; 26 | lowProfileButtonHoverColor: string; 27 | // appBackgroundDark: string; 28 | // appBackgroundHighlight: string; 29 | }; 30 | } 31 | interface ThemeOptions { 32 | constants: { 33 | consoleBackground: string; 34 | consoleTextColor: string; 35 | lowProfileButtonColor: string; 36 | lowProfileButtonHoverColor: string; 37 | // appBackgroundDark: string; 38 | // appBackgroundHighlight: string; 39 | }; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ShellPiper 6 | 17 | 18 | 19 |
20 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /src/JssUtils.ts: -------------------------------------------------------------------------------- 1 | import { lighten, Theme } from "@material-ui/core"; 2 | import { CSSProperties } from "@material-ui/core/styles/withStyles"; 3 | 4 | export function notLastChild(attributes: CSSProperties = {}): CSSProperties { 5 | return { "& > *:not(:last-child)": attributes }; 6 | } 7 | 8 | export function spaceChildren( 9 | spaceSize: string | number, 10 | direction: "vertically" | "horizontally" = "horizontally" 11 | ): CSSProperties { 12 | let relevantMargin; 13 | switch (direction) { 14 | case "vertically": 15 | relevantMargin = "marginBottom"; 16 | break; 17 | case "horizontally": 18 | relevantMargin = "marginRight"; 19 | break; 20 | default: 21 | throw new Error("Invalid direction value supplied"); 22 | } 23 | 24 | return notLastChild({ 25 | [relevantMargin]: spaceSize, 26 | }); 27 | } 28 | 29 | export const flexCol: CSSProperties = { 30 | display: "flex", 31 | flexDirection: "column", 32 | }; 33 | export const flexColCentered: CSSProperties = { 34 | ...flexCol, 35 | alignItems: "center", 36 | }; 37 | 38 | export function directChildren(attributes: CSSProperties = {}): CSSProperties { 39 | return { "& >": attributes }; 40 | } 41 | 42 | export function lowProfileButtonColors(theme: Theme, lightenCoefficient = 0) { 43 | return { 44 | color: lighten(theme.constants.lowProfileButtonColor, lightenCoefficient), 45 | "&:hover": { 46 | color: lighten(theme.constants.lowProfileButtonHoverColor, lightenCoefficient), 47 | }, 48 | }; 49 | } 50 | -------------------------------------------------------------------------------- /src/Components/Common/CircularProgress.tsx: -------------------------------------------------------------------------------- 1 | // Shamelessly stolen from Material UI's demo 2 | 3 | import { 4 | CircularProgress as MuiCircularProgress, 5 | CircularProgressProps, 6 | createStyles, 7 | makeStyles, 8 | Theme, 9 | } from "@material-ui/core"; 10 | import React from "react"; 11 | 12 | // Inspired by the former Facebook spinners. 13 | const useStylesFacebook = makeStyles((theme: Theme) => 14 | createStyles({ 15 | root: { 16 | position: "relative", 17 | paddingTop: 4, // To compensate for the div ending up with an extra 4 pixels in the bottom for some reason 18 | }, 19 | bottom: { 20 | color: theme.palette.grey[theme.palette.type === "light" ? 200 : 700], 21 | }, 22 | top: { 23 | color: "#1a90ff", 24 | animationDuration: "550ms", 25 | position: "absolute", 26 | left: 0, 27 | }, 28 | circle: { 29 | strokeLinecap: "round", 30 | }, 31 | }) 32 | ); 33 | 34 | export default function CircularProgress(props: CircularProgressProps) { 35 | const classes = useStylesFacebook(); 36 | 37 | return ( 38 |
39 | 40 | 51 |
52 | ); 53 | } 54 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | jobs: 9 | publish: 10 | runs-on: ${{ matrix.os }} 11 | 12 | strategy: 13 | matrix: 14 | os: [macos-latest] 15 | 16 | steps: 17 | - name: Checkout git repo 18 | uses: actions/checkout@v1 19 | 20 | - name: Install Node, NPM and Yarn 21 | uses: actions/setup-node@v1 22 | with: 23 | node-version: 15 24 | 25 | - name: Get yarn cache directory path 26 | id: yarn-cache-dir-path 27 | run: echo "::set-output name=dir::$(yarn cache dir)" 28 | 29 | - uses: actions/cache@v1 30 | id: yarn-cache 31 | with: 32 | path: ${{ steps.yarn-cache-dir-path.outputs.dir }} 33 | key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} 34 | restore-keys: | 35 | ${{ runner.os }}-yarn- 36 | 37 | - name: Install dependencies 38 | run: yarn install --prefer-offline 39 | 40 | - name: Publish releases 41 | env: 42 | # These values are used for auto updates signing 43 | # APPLE_ID: ${{ secrets.APPLE_ID }} 44 | # APPLE_ID_PASS: ${{ secrets.APPLE_ID_PASS }} 45 | # CSC_LINK: ${{ secrets.CSC_LINK }} 46 | # CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }} 47 | # This is used for uploading release assets to github 48 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 49 | run: | 50 | yarn postinstall && yarn build && yarn electron-builder --publish always --win --mac --linux 51 | -------------------------------------------------------------------------------- /src/Components/Common/HelpPopup.tsx: -------------------------------------------------------------------------------- 1 | import { Dialog, DialogContent, DialogTitle, IconButton, lighten, makeStyles, Typography } from "@material-ui/core"; 2 | import { Close, HelpOutline } from "@material-ui/icons"; 3 | import React, { useState } from "react"; 4 | 5 | const useStyles = makeStyles((theme) => ({ 6 | dialogPanel: { padding: 10 }, 7 | helpButton: { 8 | color: lighten(theme.constants.lowProfileButtonColor, 0.7), 9 | "&:hover": { 10 | color: theme.palette.primary.light, 11 | }, 12 | padding: 0, 13 | }, 14 | closeButton: { 15 | float: "right", 16 | padding: 4, 17 | }, 18 | dialogTitle: { 19 | padding: "4px 24px", 20 | }, 21 | dialogContent: { 22 | // padding: '8px 7px', 23 | }, 24 | })); 25 | 26 | export default function HelpPopup({ title, text }: { title: string; text: string }) { 27 | // eslint-disable-next-line @typescript-eslint/naming-convention 28 | const [open, setOpen] = useState(false); 29 | 30 | const cls = useStyles(); 31 | 32 | return ( 33 | <> 34 | setOpen(true)}> 35 | 36 | 37 | setOpen(false)}> 38 |
39 | setOpen(false)}> 40 | 41 | 42 | {title} 43 | 44 | {text} 45 | 46 |
47 |
48 | 49 | ); 50 | } 51 | -------------------------------------------------------------------------------- /src/Components/App/CommandsPanel/CuteRightPointingButton.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { Button, ButtonProps, makeStyles } from "@material-ui/core"; 3 | import { ChevronRightRounded as ChevronRightRoundedIcon } from "@material-ui/icons"; 4 | import clsx from "clsx"; 5 | 6 | const useStyles = makeStyles((theme) => ({ 7 | root: { 8 | textTransform: "none", 9 | borderRadius: 999, 10 | paddingLeft: 8, 11 | paddingRight: 6, 12 | transition: theme.transitions.create("all", { 13 | duration: theme.transitions.duration.shorter, 14 | }), 15 | }, 16 | arrow: { 17 | "&$iconSizeSmall": { 18 | marginLeft: -2, 19 | marginRight: -4, 20 | }, 21 | }, 22 | iconSizeSmall: {}, 23 | selected: { 24 | pointerEvents: "none", 25 | boxShadow: "none", 26 | border: "1px solid transparent", // This fucker is necessary so the border won't flicker 27 | }, 28 | backgroundDiv: { 29 | backgroundColor: "white", 30 | borderRadius: 999, 31 | }, 32 | })); 33 | 34 | export default function CuteRightPointingButton({ 35 | children, 36 | selected, 37 | className, 38 | classes, 39 | ...rest 40 | }: Omit & { selected: boolean }) { 41 | const cls = useStyles(); 42 | 43 | return ( 44 |
45 | 60 |
61 | ); 62 | } 63 | -------------------------------------------------------------------------------- /.erb/configs/webpack.config.renderer.dev.dll.babel.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Builds the DLL for development electron renderer process 3 | */ 4 | 5 | import webpack from 'webpack'; 6 | import path from 'path'; 7 | import { merge } from 'webpack-merge'; 8 | import baseConfig from './webpack.config.base'; 9 | import { dependencies } from '../../package.json'; 10 | import CheckNodeEnv from '../scripts/CheckNodeEnv'; 11 | 12 | CheckNodeEnv('development'); 13 | 14 | const dist = path.join(__dirname, '../dll'); 15 | 16 | export default merge(baseConfig, { 17 | context: path.join(__dirname, '../..'), 18 | 19 | devtool: 'eval', 20 | 21 | mode: 'development', 22 | 23 | target: 'electron-renderer', 24 | 25 | externals: ['fsevents', 'crypto-browserify'], 26 | 27 | /** 28 | * Use `module` from `webpack.config.renderer.dev.js` 29 | */ 30 | module: require('./webpack.config.renderer.dev.babel').default.module, 31 | 32 | entry: { 33 | renderer: Object.keys(dependencies || {}), 34 | }, 35 | 36 | output: { 37 | library: 'renderer', 38 | path: dist, 39 | filename: '[name].dev.dll.js', 40 | libraryTarget: 'var', 41 | }, 42 | 43 | plugins: [ 44 | new webpack.DllPlugin({ 45 | path: path.join(dist, '[name].json'), 46 | name: '[name]', 47 | }), 48 | 49 | /** 50 | * Create global constants which can be configured at compile time. 51 | * 52 | * Useful for allowing different behaviour between development builds and 53 | * release builds 54 | * 55 | * NODE_ENV should be production so that modules do not perform certain 56 | * development checks 57 | */ 58 | new webpack.EnvironmentPlugin({ 59 | NODE_ENV: 'development', 60 | }), 61 | 62 | new webpack.LoaderOptionsPlugin({ 63 | debug: true, 64 | options: { 65 | context: path.join(__dirname, '../../src'), 66 | output: { 67 | path: path.join(__dirname, '../dll'), 68 | }, 69 | }, 70 | }), 71 | ], 72 | }); 73 | -------------------------------------------------------------------------------- /.erb/configs/webpack.config.main.prod.babel.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Webpack config for production electron main process 3 | */ 4 | 5 | import path from 'path'; 6 | import webpack from 'webpack'; 7 | import { merge } from 'webpack-merge'; 8 | import TerserPlugin from 'terser-webpack-plugin'; 9 | import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'; 10 | import baseConfig from './webpack.config.base'; 11 | import CheckNodeEnv from '../scripts/CheckNodeEnv'; 12 | import DeleteSourceMaps from '../scripts/DeleteSourceMaps'; 13 | 14 | CheckNodeEnv('production'); 15 | DeleteSourceMaps(); 16 | 17 | const devtoolsConfig = process.env.DEBUG_PROD === 'true' ? { 18 | devtool: 'source-map' 19 | } : {}; 20 | 21 | export default merge(baseConfig, { 22 | ...devtoolsConfig, 23 | 24 | mode: 'production', 25 | 26 | target: 'electron-main', 27 | 28 | entry: './src/main.dev.ts', 29 | 30 | output: { 31 | path: path.join(__dirname, '../../'), 32 | filename: './src/main.prod.js', 33 | }, 34 | 35 | optimization: { 36 | minimizer: [ 37 | new TerserPlugin({ 38 | parallel: true, 39 | }), 40 | ] 41 | }, 42 | 43 | plugins: [ 44 | new BundleAnalyzerPlugin({ 45 | analyzerMode: 46 | process.env.OPEN_ANALYZER === 'true' ? 'server' : 'disabled', 47 | openAnalyzer: process.env.OPEN_ANALYZER === 'true', 48 | }), 49 | 50 | /** 51 | * Create global constants which can be configured at compile time. 52 | * 53 | * Useful for allowing different behaviour between development builds and 54 | * release builds 55 | * 56 | * NODE_ENV should be production so that modules do not perform certain 57 | * development checks 58 | */ 59 | new webpack.EnvironmentPlugin({ 60 | NODE_ENV: 'production', 61 | DEBUG_PROD: false, 62 | START_MINIMIZED: false, 63 | }), 64 | ], 65 | 66 | /** 67 | * Disables webpack processing of __dirname and __filename. 68 | * If you run the bundle in node.js it falls back to these values of node.js. 69 | * https://github.com/webpack/webpack/issues/2010 70 | */ 71 | node: { 72 | __dirname: false, 73 | __filename: false, 74 | }, 75 | }); 76 | -------------------------------------------------------------------------------- /.erb/scripts/CheckNativeDep.js: -------------------------------------------------------------------------------- 1 | import fs from 'fs'; 2 | import chalk from 'chalk'; 3 | import { execSync } from 'child_process'; 4 | import { dependencies } from '../../package.json'; 5 | 6 | if (dependencies) { 7 | const dependenciesKeys = Object.keys(dependencies); 8 | const nativeDeps = fs 9 | .readdirSync('node_modules') 10 | .filter((folder) => fs.existsSync(`node_modules/${folder}/binding.gyp`)); 11 | if (nativeDeps.length === 0) { 12 | process.exit(0); 13 | } 14 | try { 15 | // Find the reason for why the dependency is installed. If it is installed 16 | // because of a devDependency then that is okay. Warn when it is installed 17 | // because of a dependency 18 | const { dependencies: dependenciesObject } = JSON.parse( 19 | execSync(`npm ls ${nativeDeps.join(' ')} --json`).toString() 20 | ); 21 | const rootDependencies = Object.keys(dependenciesObject); 22 | const filteredRootDependencies = rootDependencies.filter((rootDependency) => 23 | dependenciesKeys.includes(rootDependency) 24 | ); 25 | if (filteredRootDependencies.length > 0) { 26 | const plural = filteredRootDependencies.length > 1; 27 | console.log(` 28 | ${chalk.whiteBright.bgYellow.bold( 29 | 'Webpack does not work with native dependencies.' 30 | )} 31 | ${chalk.bold(filteredRootDependencies.join(', '))} ${ 32 | plural ? 'are native dependencies' : 'is a native dependency' 33 | } and should be installed inside of the "./src" folder. 34 | First, uninstall the packages from "./package.json": 35 | ${chalk.whiteBright.bgGreen.bold('yarn remove your-package')} 36 | ${chalk.bold( 37 | 'Then, instead of installing the package to the root "./package.json":' 38 | )} 39 | ${chalk.whiteBright.bgRed.bold('yarn add your-package')} 40 | ${chalk.bold('Install the package to "./src/package.json"')} 41 | ${chalk.whiteBright.bgGreen.bold('cd ./src && yarn add your-package')} 42 | Read more about native dependencies at: 43 | ${chalk.bold( 44 | 'https://electron-react-boilerplate.js.org/docs/adding-dependencies/#module-structure' 45 | )} 46 | `); 47 | process.exit(1); 48 | } 49 | } catch (e) { 50 | console.log('Native dependencies could not be checked'); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Components/App/CommandsPanel/PlusDivider.tsx: -------------------------------------------------------------------------------- 1 | import { makeStyles, Divider, Paper } from "@material-ui/core"; 2 | import AddIcon from "@material-ui/icons/Add"; 3 | import clsx from "clsx"; 4 | import React from "react"; 5 | 6 | const useStyles = makeStyles((theme) => ({ 7 | root: { 8 | position: "relative", 9 | display: "flex", 10 | justifyContent: "center", 11 | margin: "6px 0", 12 | cursor: "pointer", 13 | "&:hover $divider": { 14 | backgroundColor: "#44444470", 15 | height: 2, 16 | }, 17 | "&:hover $plus": { 18 | boxShadow: "0px 3px 5px -1px rgba(0,0,0,0.2), 0px 5px 8px 0px rgba(0,0,0,0.14), 0px 1px 14px 0px rgba(0,0,0,0.12)", // Shamelessly stolen from Material-UI Paper's elevation-5 styling 19 | }, 20 | "&$disabled": { 21 | pointerEvents: "none", 22 | }, 23 | }, 24 | divider: { 25 | position: "absolute", 26 | top: 0, 27 | bottom: 0, 28 | marginTop: "auto", 29 | marginBottom: "auto", 30 | // top: "50%", 31 | width: "100%", 32 | backgroundColor: "#44444444", 33 | borderRadius: 99999999, 34 | }, 35 | plus: { 36 | padding: 0, 37 | borderRadius: 12, 38 | minWidth: 0, 39 | width: 24, 40 | height: 24, 41 | 42 | backgroundColor: theme.palette.grey.A100, 43 | zIndex: 1, 44 | transition: "box-shadow 0ms cubic-bezier(0.4, 0, 0.2, 1) 0ms", 45 | 46 | "&$disabled": { 47 | color: theme.palette.grey[400], 48 | }, 49 | }, 50 | disabled: {}, 51 | })); 52 | 53 | const PlusDivider = ({ 54 | onClick, 55 | title, 56 | disabled, 57 | }: { 58 | onClick: React.MouseEventHandler; 59 | title: string | undefined; 60 | disabled: boolean | undefined; 61 | }) => { 62 | const cls = useStyles(); 63 | 64 | return ( 65 | // eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/interactive-supports-focus 66 |
67 | 68 | 69 | 70 | 71 |
72 | ); 73 | }; 74 | 75 | export default PlusDivider; 76 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | /* eslint global-require: off, import/no-extraneous-dependencies: off */ 2 | 3 | const developmentEnvironments = ["development", "test"]; 4 | 5 | const developmentPlugins = [require("@babel/plugin-transform-runtime")]; 6 | 7 | const productionPlugins = [ 8 | require("babel-plugin-dev-expression"), 9 | 10 | // babel-preset-react-optimize 11 | require("@babel/plugin-transform-react-constant-elements"), 12 | require("@babel/plugin-transform-react-inline-elements"), 13 | require("babel-plugin-transform-react-remove-prop-types"), 14 | ]; 15 | 16 | module.exports = (api) => { 17 | // See docs about api at https://babeljs.io/docs/en/config-files#apicache 18 | 19 | const development = api.env(developmentEnvironments); 20 | 21 | return { 22 | presets: [ 23 | // @babel/preset-env will automatically target our browserslist targets 24 | require("@babel/preset-env"), 25 | require("@babel/preset-typescript"), 26 | [require("@babel/preset-react"), { development }], 27 | ], 28 | plugins: [ 29 | // Stage 0 30 | require("@babel/plugin-proposal-function-bind"), 31 | 32 | // Stage 1 33 | require("@babel/plugin-proposal-export-default-from"), 34 | require("@babel/plugin-proposal-logical-assignment-operators"), 35 | [require("@babel/plugin-proposal-optional-chaining"), { loose: false }], 36 | [require("@babel/plugin-proposal-pipeline-operator"), { proposal: "minimal" }], 37 | [require("@babel/plugin-proposal-nullish-coalescing-operator"), { loose: false }], 38 | require("@babel/plugin-proposal-do-expressions"), 39 | 40 | // Stage 2 41 | [require("@babel/plugin-proposal-decorators"), { legacy: true }], 42 | require("@babel/plugin-proposal-function-sent"), 43 | require("@babel/plugin-proposal-export-namespace-from"), 44 | require("@babel/plugin-proposal-numeric-separator"), 45 | require("@babel/plugin-proposal-throw-expressions"), 46 | 47 | // Stage 3 48 | require("@babel/plugin-syntax-dynamic-import"), 49 | require("@babel/plugin-syntax-import-meta"), 50 | [require("@babel/plugin-proposal-class-properties"), { loose: true }], 51 | require("@babel/plugin-proposal-json-strings"), 52 | 53 | ...(development ? developmentPlugins : productionPlugins), 54 | ], 55 | }; 56 | }; 57 | -------------------------------------------------------------------------------- /src/PiperStore.test.ts: -------------------------------------------------------------------------------- 1 | import { when } from "mobx"; 2 | import Command from "./Command"; 3 | import CommandStatus from "./CommandStatus"; 4 | import { PiperStore } from "./PiperStore"; 5 | 6 | function generateTestingStore(...commands: string[]) { 7 | const store = new PiperStore(); 8 | 9 | store.commands = []; 10 | 11 | for (const commandText of commands) { 12 | const newCommand = new Command(store); 13 | newCommand.commandText = commandText; 14 | store.commands.push(newCommand); 15 | } 16 | 17 | return store; 18 | } 19 | 20 | async function whenAllCommandsAreFinished(store: PiperStore) { 21 | return new Promise((resolve) => { 22 | when( 23 | () => store.commands.every((cmd) => ![CommandStatus.RUNNING, CommandStatus.NEW].includes(cmd.status)), 24 | () => resolve() 25 | ); 26 | }); 27 | } 28 | 29 | async function runCommandsAndWaitForThemToFinish(...commands: string[]): Promise { 30 | const store = generateTestingStore(...commands); 31 | 32 | store.runCommands(); 33 | 34 | await whenAllCommandsAreFinished(store); 35 | 36 | return store; 37 | } 38 | 39 | test("simple scenario sanity", async () => { 40 | const store = await runCommandsAndWaitForThemToFinish("seq 100", "grep 5", "grep 3"); 41 | expect(store.commands[store.commands.length - 1].stdout).toEqual("35\n53\n"); 42 | }); 43 | 44 | test("write after stream close shouldn't happen", async () => { 45 | const store = await runCommandsAndWaitForThemToFinish("seq 1000", "asd"); 46 | 47 | expect(store.commands[0].process?.exitCode).toEqual(0); 48 | expect(store.commands[1].process?.exitCode).not.toEqual(0); 49 | }); 50 | 51 | // eslint-disable-next-line jest/no-commented-out-tests 52 | // test('cache triggering', () => { 53 | // const store = new PiperStore(); 54 | // store.insertNewCommand(0); 55 | // store.insertNewCommand(0); 56 | // store.insertNewCommand(0); 57 | // store.insertNewCommand(0); 58 | // store.insertNewCommand(0); 59 | 60 | // store.setShouldCache(2, true); 61 | 62 | // expect(store.commands.map((cmd) => cmd._shouldCache)).toEqual([ 63 | // true, 64 | // true, 65 | // true, 66 | // false, 67 | // false, 68 | // ]); 69 | 70 | // store.setShouldCache(1, false); 71 | 72 | // expect(store.commands.map((cmd) => cmd._shouldCache)).toEqual([ 73 | // true, 74 | // false, 75 | // false, 76 | // false, 77 | // false, 78 | // ]); 79 | // }); 80 | -------------------------------------------------------------------------------- /src/Components/App/OutputPanel.tsx: -------------------------------------------------------------------------------- 1 | import { Fab, makeStyles } from "@material-ui/core"; 2 | import { Theme } from "@material-ui/core/styles/createMuiTheme"; 3 | import { FileCopy as CopyIcon } from "@material-ui/icons"; 4 | import { observer } from "mobx-react"; 5 | import React, { useState } from "react"; 6 | import { piperStore } from "../../PiperStore"; 7 | import { copyToClipboard } from "../../utils"; 8 | import CopiedSuccessfulySnackbar from "../Common/CopiedSuccessfulySnackbar"; 9 | 10 | const useStyles = makeStyles((theme: Theme) => ({ 11 | root: { 12 | position: "relative", 13 | height: "100%", 14 | // backgroundColor: '#333333', 15 | // color: 'white', 16 | backgroundColor: theme.constants.consoleBackground, 17 | color: theme.constants.consoleTextColor, 18 | boxSizing: "border-box", 19 | }, 20 | pre: { 21 | paddingBottom: 55, // So the fab won't cover some text in an unevadable way 22 | height: "100%", 23 | overflowY: "auto", 24 | boxSizing: "border-box", 25 | padding: 10, 26 | margin: 0, 27 | }, 28 | fab: { 29 | position: "absolute", 30 | bottom: 25, 31 | right: 25, 32 | }, 33 | copyIcon: { 34 | fontSize: "1.1rem", 35 | }, 36 | })); 37 | 38 | const OutputPanel = observer((/* { output }: { output: string } */) => { 39 | // eslint-disable-next-line @typescript-eslint/naming-convention 40 | const [openCopySnackbar, setOpenCopySnackbar] = useState(false); 41 | 42 | let output: string | undefined; 43 | 44 | // const output = piperStore.commands.lastOrUndefined()?.stdout || ''; 45 | 46 | if (piperStore.whatToDisplay) { 47 | const { commandId, outputType } = piperStore.whatToDisplay; 48 | output = piperStore.getCommandById(commandId)[outputType]; 49 | } 50 | 51 | const cls = useStyles(); 52 | 53 | return ( 54 |
55 |
56 |         {output}
57 |       
58 | { 64 | if (!output) throw new Error("Shouldn't happen because of the 'disabled' prop"); 65 | 66 | copyToClipboard(output); 67 | setOpenCopySnackbar(true); 68 | }} 69 | > 70 | 71 | 72 | setOpenCopySnackbar(false)} /> 73 |
74 | ); 75 | }); 76 | 77 | export default OutputPanel; 78 | -------------------------------------------------------------------------------- /src/Components/ThemeStuff/theme.tsx: -------------------------------------------------------------------------------- 1 | // Shamelessly stolen from N1TZANKL's kippa-aduma 2 | 3 | import { lighten } from "@material-ui/core"; 4 | import { red } from "@material-ui/core/colors"; 5 | import createMuiTheme from "@material-ui/core/styles/createMuiTheme"; 6 | // import * as muiColors from '@material-ui/core/colors'; 7 | // import { lighten } from '@material-ui/core'; 8 | 9 | // const primaryColor = muiColors.red; 10 | // const secondaryColor = muiColors.lightBlue; 11 | 12 | export const theme = createMuiTheme({ 13 | palette: { 14 | // type: 'dark', 15 | // primary: { 16 | // main: primaryColor[600], 17 | // dark: primaryColor[900], 18 | // light: primaryColor[400], 19 | // veryLight: primaryColor[200], 20 | // superLight: primaryColor[100], 21 | // }, 22 | // secondary: { 23 | // main: secondaryColor[500], 24 | // dark: secondaryColor[700], 25 | // light: secondaryColor[300], 26 | // veryLight: secondaryColor[200], 27 | // superLight: secondaryColor[100], 28 | // }, 29 | }, 30 | constants: { 31 | consoleBackground: "#1E1E1E", 32 | consoleTextColor: "#D4D4D4", 33 | lowProfileButtonColor: lighten("#000", 0.76), 34 | lowProfileButtonHoverColor: lighten("#000", 0.46), 35 | // appBackgroundDark: muiColors.blueGrey[900], 36 | // appBackgroundHighlight: muiColors.blueGrey[700], 37 | }, 38 | }); 39 | 40 | // export default createMuiTheme({ 41 | // ...customTheme, 42 | // // overrides: { 43 | // // MuiPaper: { 44 | // // root: { 45 | // // backgroundColor: customTheme.constants.appBackground, 46 | // // }, 47 | // // }, 48 | // // MuiPopover: { 49 | // // paper: { 50 | // // backgroundColor: customTheme.constants.appBackgroundHighlight, 51 | // // }, 52 | // // }, 53 | // // MuiIconButton: { 54 | // // root: { 55 | // // padding: 6, 56 | // // }, 57 | // // }, 58 | // // MuiFilledInput: { 59 | // // root: { borderRadius: '0 !important ' }, 60 | // // input: { padding: '10px 12px' }, 61 | // // }, 62 | // // MuiButton: { 63 | // // root: { 64 | // // fontFamily: 'Inconsolata', 65 | // // letterSpacing: 1.15, 66 | // // fontSize: 16, 67 | // // }, 68 | // // contained: { 69 | // // backgroundColor: lighten( 70 | // // customTheme.constants.appBackgroundHighlight, 71 | // // 0.5 72 | // // ), 73 | // // '&:hover': { 74 | // // backgroundColor: lighten( 75 | // // customTheme.constants.appBackgroundHighlight, 76 | // // 0.3 77 | // // ), 78 | // // }, 79 | // // }, 80 | // // containedPrimary: { color: 'white' }, 81 | // // containedSecondary: { color: 'white' }, 82 | // // }, 83 | // // }, 84 | // }); 85 | 86 | export const errorTheme = createMuiTheme({ 87 | // Because MUI is annoying. 88 | ...theme, 89 | palette: { primary: red }, 90 | }); 91 | -------------------------------------------------------------------------------- /src/Components/App/CommandsPanel/CacheBar/CacheBarButton.tsx: -------------------------------------------------------------------------------- 1 | import { Button, ButtonProps, lighten, makeStyles, Tooltip } from "@material-ui/core"; 2 | import clsx from "clsx"; 3 | import React from "react"; 4 | 5 | export const BUTTON_RADIUS = 10; 6 | export const BUTTON_HEIGHT = BUTTON_RADIUS * 2; 7 | export const BUTTON_WIDTH = BUTTON_HEIGHT; 8 | const SMALL_BUTTON_DIFF = 6; 9 | const SMALL_BUTTON_HEIGHT = BUTTON_HEIGHT - SMALL_BUTTON_DIFF; 10 | const SMALL_BUTTON_WIDTH = BUTTON_WIDTH - SMALL_BUTTON_DIFF; 11 | 12 | const useStyles = makeStyles((theme) => ({ 13 | button: { 14 | padding: 0, 15 | borderRadius: BUTTON_RADIUS, 16 | minWidth: 0, 17 | width: SMALL_BUTTON_WIDTH, 18 | height: SMALL_BUTTON_HEIGHT, 19 | transition: theme.transitions.create(["all"], { 20 | duration: theme.transitions.duration.shortest, 21 | }), 22 | }, 23 | buttonContained: { 24 | "&$disabled": { backgroundColor: theme.palette.grey.A100 }, 25 | }, 26 | disabled: {}, 27 | selected: { 28 | cursor: "default", 29 | pointerEvents: "none", 30 | height: BUTTON_HEIGHT, 31 | width: BUTTON_WIDTH, 32 | }, 33 | available: { 34 | backgroundColor: lighten(theme.palette.primary.main, 0.21), 35 | "&:hover": { 36 | backgroundColor: lighten(theme.palette.primary.main, 0.1), 37 | }, 38 | }, 39 | containerPadding: { 40 | padding: SMALL_BUTTON_DIFF / 2, 41 | transition: theme.transitions.create(["padding"], { 42 | duration: theme.transitions.duration.shortest, 43 | }), 44 | }, 45 | noPadding: { padding: 0 }, 46 | })); 47 | 48 | export type CacheBarButtonState = "disabled" | "available" | "selected"; 49 | 50 | type CacheBarButtonProps = Omit & { 51 | state: CacheBarButtonState; 52 | tooltipText: string; 53 | }; 54 | 55 | export function CacheBarButton({ state, className, classes, tooltipText, ...rest }: CacheBarButtonProps) { 56 | const cls = useStyles(); 57 | 58 | return ( 59 |
60 | 61 | 67 |
89 | ); 90 | } 91 | -------------------------------------------------------------------------------- /assets/icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/utils.test.ts: -------------------------------------------------------------------------------- 1 | import { yieldPairs } from "./utils"; 2 | 3 | test("Array.prototype.skip basic case", () => { 4 | expect([1, 2, 3, 4, 5].skip((item) => item < 3)).toEqual([[3, 4, 5], 2]); 5 | }); 6 | 7 | test("Array.prototype.skip returns an empty array when all items meet the predicate", () => { 8 | expect([1, 2, 3, 4, 5].skip((item) => item < 100)).toEqual([[], 5]); 9 | }); 10 | 11 | test("Array.prototype.skip returns the original array when none of the items meet the predicate", () => { 12 | expect([1, 2, 3, 4, 5].skip((item) => item > 100)).toEqual([[1, 2, 3, 4, 5], 0]); 13 | }); 14 | 15 | test("Array.prototype.skip stops skipping on first item that fails to meet the condition", () => { 16 | expect([1, 2, 3, 2, 1].skip((item) => item < 3)).toEqual([[3, 2, 1], 2]); 17 | }); 18 | 19 | test("yieldPairs #1", () => { 20 | expect(Array.from(yieldPairs([1, 2, 3, 4]))).toEqual([ 21 | [1, 2], 22 | [2, 3], 23 | [3, 4], 24 | ]); 25 | }); 26 | 27 | test("yieldPairs #2", () => { 28 | expect(Array.from(yieldPairs([1, 2, 3]))).toEqual([ 29 | [1, 2], 30 | [2, 3], 31 | ]); 32 | }); 33 | 34 | test("yieldPairs #3", () => { 35 | expect(Array.from(yieldPairs([1, 2]))).toEqual([[1, 2]]); 36 | }); 37 | 38 | test("yieldPairs #4", () => { 39 | expect(Array.from(yieldPairs([1]))).toEqual([]); 40 | }); 41 | 42 | test("yieldPairs #5", () => { 43 | expect(Array.from(yieldPairs([]))).toEqual([]); 44 | }); 45 | 46 | // eslint-disable-next-line jest/no-commented-out-tests 47 | // test('splitting string to chunks #1', () => { 48 | // expect(splitToChunks('12345678901234567890', 10)).toEqual([ 49 | // '1234567890', 50 | // '1234567890', 51 | // ]); 52 | // }); 53 | 54 | // eslint-disable-next-line jest/no-commented-out-tests 55 | // test('splitting string to chunks #2', () => { 56 | // expect(splitToChunks('123456789012345678', 5)).toEqual([ 57 | // '12345', 58 | // '67890', 59 | // '12345', 60 | // '678', 61 | // ]); 62 | // }); 63 | 64 | test("Array.equals #1", () => { 65 | expect([].equals([])).toEqual(true); 66 | }); 67 | 68 | test("Array.equals #2", () => { 69 | expect([1].equals([])).toEqual(false); 70 | }); 71 | 72 | test("Array.equals #3", () => { 73 | expect(([] as number[]).equals([1])).toEqual(false); 74 | }); 75 | 76 | test("Array.equals #4", () => { 77 | expect(([1, 2, 3] as number[]).equals([1, 2])).toEqual(false); 78 | }); 79 | 80 | test("Array.equals #5", () => { 81 | expect([1, 2, 3].equals([1, 2, 3])).toEqual(true); 82 | }); 83 | 84 | test("Array.equals #6", () => { 85 | expect([1, 2].equals([1, 2, 3])).toEqual(false); 86 | }); 87 | 88 | test("Array.splitByPredicate #1", () => { 89 | expect([1, 2, 3].splitByPredicate((item) => item % 2 === 0)).toEqual([[2], [1, 3]]); 90 | }); 91 | 92 | test("Array.splitByPredicate #2", () => { 93 | expect([].splitByPredicate((item) => item % 2 === 0)).toEqual([[], []]); 94 | }); 95 | 96 | test("Array.splitByPredicate #3", () => { 97 | expect([1].splitByPredicate((item) => item % 2 === 0)).toEqual([[], [1]]); 98 | }); 99 | 100 | test("Array.splitByPredicate #4", () => { 101 | expect([2].splitByPredicate((item) => item % 2 === 0)).toEqual([[2], []]); 102 | }); 103 | 104 | test("Array.splitByPredicate #5", () => { 105 | expect([1, 2, 3, 4, 5].splitByPredicate((_item, index) => index > 2)).toEqual([ 106 | [4, 5], 107 | [1, 2, 3], 108 | ]); 109 | }); 110 | -------------------------------------------------------------------------------- /src/Components/App/App.tsx: -------------------------------------------------------------------------------- 1 | import { Divider, makeStyles, ThemeProvider } from "@material-ui/core"; 2 | import React from "react"; 3 | import ResizePanel from "react-resize-panel"; 4 | import { BrowserRouter as Router, Route, Switch } from "react-router-dom"; 5 | import { flexCol } from "../../JssUtils"; 6 | import { piperStore } from "../../PiperStore"; 7 | import MousetrapWrapper from "../Common/MousetrapWrapper"; 8 | import { theme } from "../ThemeStuff/theme"; 9 | // import icon from '../assets/icon.svg'; 10 | import "./App.global.css"; 11 | import CommandsPanel from "./CommandsPanel/CommandsPanel"; 12 | import OutputPanel from "./OutputPanel"; 13 | import SettingsPanel from "./SettingsPanel"; 14 | 15 | const maxWidthOfCommandsPanel = 800; 16 | 17 | const useStyles = makeStyles({ 18 | root: { 19 | width: "100%", 20 | height: "100%", 21 | display: "flex", 22 | }, 23 | commandsPanel: { 24 | // flexGrow: 1, 25 | padding: "0 10px 10px 10px", 26 | ...flexCol, 27 | backgroundColor: "#F0F2F5", 28 | width: maxWidthOfCommandsPanel, 29 | boxSizing: "border-box", 30 | minWidth: 400, // Limits the minimal size of the resizable panel 31 | }, 32 | commandsPanelResizableContainer: { 33 | // flexGrow: 2, 34 | maxWidth: maxWidthOfCommandsPanel, 35 | width: 500, // Initial width of the resizable commands panel 36 | minWidth: "fit-content", // Makes sure the commands panel isn't truncated by the manual resizing 37 | }, 38 | resizeHandle: { 39 | // "&:active": { 40 | // width: 10, 41 | // height: "100%", 42 | // backgroundColor: "blue", 43 | // }, 44 | }, 45 | outputPanel: { 46 | flex: "1 1 0", 47 | minWidth: 200, 48 | overflowY: "auto", 49 | overflowX: "auto", 50 | }, 51 | divider: {}, 52 | mousetrapContainer: { width: "100%", height: "100%" }, 53 | }); 54 | 55 | const Main = () => { 56 | const cls = useStyles(); 57 | return ( 58 | 59 | piperStore.clearWhatToDisplay()]]} 62 | > 63 |
64 | 65 |
{ 68 | // For debugging 69 | if (e.target !== e.currentTarget) return; // Don't run when clicked on children, only when clicked directly on this div 70 | 71 | if (e.ctrlKey) { 72 | const windowAny = window as any; 73 | windowAny.piperStore = windowAny.ps = piperStore; 74 | // eslint-disable-next-line no-console 75 | console.log(`piperStore set: `, piperStore); 76 | } 77 | }} 78 | > 79 | 80 | 81 |
82 |
83 | 84 |
85 | 88 |
89 |
90 |
91 |
92 | ); 93 | }; 94 | 95 | export default function App() { 96 | return ( 97 | 98 | 99 | 100 | 101 | 102 | ); 103 | } 104 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: "erb", 3 | rules: { 4 | // A temporary hack related to IDE not resolving correct package.json 5 | "import/no-extraneous-dependencies": "off", 6 | "class-methods-use-this": "warn", 7 | "no-restricted-syntax": [ 8 | // Copied from $ eslint --print-config file.js 9 | "error", 10 | { 11 | selector: "ForInStatement", 12 | message: 13 | "for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.", 14 | }, 15 | // { 16 | // selector: 'ForOfStatement', 17 | // message: 18 | // 'iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations.', 19 | // }, 20 | { 21 | selector: "LabeledStatement", 22 | message: "Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.", 23 | }, 24 | { 25 | selector: "WithStatement", 26 | message: "`with` is disallowed in strict mode because it makes code impossible to predict and optimize.", 27 | }, 28 | ], 29 | "import/prefer-default-export": "off", 30 | "@typescript-eslint/lines-between-class-members": "warn", 31 | "@typescript-eslint/no-inferrable-types": "warn", 32 | 33 | // ShellPiper eslint adjustments 34 | yoda: ["warn", "never", { exceptRange: true }], 35 | "no-underscore-dangle": ["error", { allowAfterThis: true }], 36 | "no-unused-vars": "off", 37 | "@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_", varsIgnorePattern: "^_" }], 38 | "no-extend-native": "off", // Extending the lame native prototype is highly encouraged 39 | "no-plusplus": ["error", { allowForLoopAfterthoughts: true }], 40 | "react/jsx-props-no-spreading": "off", 41 | "react/jsx-no-duplicate-props": ["error", { ignoreCase: false }], 42 | "no-alert": "off", 43 | "no-multi-assign": ["warn", { ignoreNonDeclaration: true }], 44 | "prefer-destructuring": [ 45 | "warn", 46 | { 47 | array: false, 48 | object: true, 49 | }, 50 | { 51 | enforceForRenamedProperties: false, 52 | }, 53 | ], 54 | "@typescript-eslint/naming-convention": [ 55 | "warn", 56 | { 57 | // Enforce that boolean variables are prefixed with an allowed verb 58 | selector: "variable", 59 | types: ["boolean"], 60 | format: ["PascalCase"], 61 | prefix: ["is", "should", "has", "can", "did", "will"], 62 | }, 63 | { 64 | // Allow underscore for parameters (indicates unused) 65 | selector: "parameter", 66 | format: ["camelCase"], 67 | leadingUnderscore: "allow", 68 | }, 69 | ], 70 | "prettier/prettier": "warn", 71 | "import/no-cycle": "warn", 72 | "@typescript-eslint/no-explicit-any": "off", 73 | "no-console": ["warn", { allow: ["warn", "error"] }], 74 | "spaced-comment": "warn", 75 | }, 76 | parserOptions: { 77 | ecmaVersion: 2020, 78 | sourceType: "module", 79 | project: "./tsconfig.json", 80 | tsconfigRootDir: __dirname, 81 | createDefaultProgram: true, 82 | }, 83 | settings: { 84 | "import/resolver": { 85 | // See https://github.com/benmosher/eslint-plugin-import/issues/1396#issuecomment-575727774 for line below 86 | node: {}, 87 | webpack: { 88 | config: require.resolve("./.erb/configs/webpack.config.eslint.js"), 89 | }, 90 | }, 91 | "import/parsers": { 92 | "@typescript-eslint/parser": [".ts", ".tsx"], 93 | }, 94 | }, 95 | }; 96 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ShellPiper - The Piping Editor 2 | 3 | ShellPiper is an editor for writing long pipe one-liners in the shell. 4 | Instead of tweaking a long pipe chain in the terminal, use ShellPiper to create and tweak it with ease (and caching!). 5 | 6 | ![shellpiper](/pictures/shellpiper1.png) 7 | 8 | ## Caching 9 | 10 | ShellPiper saves the stdout of every command in the chain and lets you re-use this output later. 11 | The cache bar is pretty smart, it will only let you use the cached output of a command if all the commands above it are the same as they were the last time the command was executed. 12 | To enable caching, check the box at the top of the cache bar on the left. 13 | 14 | ## Installation 15 | 16 | ### Windows 17 | 18 | 1. Download the latest `.exe` version from the [releases page](https://github.com/TheYarin/ShellPiper/releases) 19 | 20 | 1. Running it will install ShellPiper on your machine. 21 | 22 | 1. You might get a "Windows protected your PC" pop up. I never told Microsoft I was making ShellPiper so it makes sense they won't recognize it. You can continue to the installation process by clicking on `More info` and then the `Run anyway` button will appear. 23 | 24 | 1. Now ShellPiper will automatically be installed on your machine, probably in the following path: 25 | `C:\Users\\AppData\Local\Programs\shell-piper` 26 | 27 | ### Linux 28 | 29 | 1. Download the latest `.AppImage` version from the [releases page](https://github.com/TheYarin/ShellPiper/releases) 30 | 1. `chmod +x` the downloaded `.AppImage` file to allow its execution 31 | 1. That's it, now you can run this ShellPiper binary. 32 | 33 | ## Adding a shortcut to PATH 34 | 35 | Usage is most fun when you can simply run `sp` in your terminal and ShellPiper starts running from your current directory. This is how you configure it: 36 | 37 | ### Windows 38 | 39 | #### CMD 40 | 41 | Put [`sp.cmd`](/shortcut-examples/sp.cmd) in a directory that is in your Path and edit it so the path points to the installed exe. 42 | 43 | #### Git Bash 44 | 45 | Put [`sp`](/shortcut-examples/sp) in a directory that is in your Path and edit it so the path points to the installed exe. 46 | 47 | ### Linux 48 | 49 | Put [`sp`](/shortcut-examples/sp) in a directory that is in your Path and edit it so the path points to the downloaded AppImage file. 50 | 51 | ## Mac Support 52 | 53 | ShellPiper works on Mac using the `.dmg` version from the [releases page](https://github.com/TheYarin/ShellPiper/releases). I didn't test it as thoroughly on Mac though, so... try it yourself and let me know if there are any issues 😁 54 | 55 | ## Changing the default shell 56 | 57 | The default shell is `/bin/sh` on Unix, and `%COMSPEC%` (CMD, unless you changed it) on Windows. 58 | You can change the shell by changing the "Shell Program" option in the settings panel. 59 | 60 | ## Known Issues 61 | 62 | ### No output is produced 63 | 64 | Some programs buffer their output when they detect their output is piped. For now I only noticed this behavior on Git Bash's (Windows) implementations of `grep`, `find` etc. This will look like the command is producing no output, but the output will appear once the buffer is flushed, either when enough output is written or when the process exits. 65 | 66 | Workaround is program dependant. For example, `grep` can take a `--line-buffered` argument that tells it to flush output on every line. 67 | If this occurs on Linux, The `unbuffer` command (which comes as part of the `expect` package) might be able to do the trick for you. 68 | 69 | ### The ShellPiper UI is super laggy when a command outputs a ton of output 70 | 71 | Yeah, sorry about that. Didn't get to fix this one yet. An easy workaround is simply to close the output window until the heavy command is finished. You can do this by double tapping the `Esc` key on your keyboard. 72 | 73 | --- 74 | 75 | ### Special Thanks 76 | 77 | I want to thank [electron-react-boilerplate](https://electron-react-boilerplate.js.org/) for saving me a ton of drudgery and helping me focus on the fun parts. 78 | -------------------------------------------------------------------------------- /src/main.dev.ts: -------------------------------------------------------------------------------- 1 | /* eslint global-require: off, no-console: off */ 2 | 3 | /** 4 | * This module executes inside of electron's main process. You can start 5 | * electron renderer process from here and communicate with the other processes 6 | * through IPC. 7 | * 8 | * When running `yarn build` or `yarn build:main`, this file is compiled to 9 | * `./src/main.prod.js` using webpack. This gives us some performance wins. 10 | */ 11 | import "core-js/stable"; 12 | import "regenerator-runtime/runtime"; 13 | import path from "path"; 14 | import { app, BrowserWindow, shell } from "electron"; 15 | // import { autoUpdater } from "electron-updater"; 16 | // import log from "electron-log"; 17 | // import MenuBuilder from "./menu"; 18 | 19 | // export default class AppUpdater { 20 | // constructor() { 21 | // log.transports.file.level = "info"; 22 | // autoUpdater.logger = log; 23 | // autoUpdater.checkForUpdatesAndNotify(); 24 | // } 25 | // } 26 | 27 | let mainWindow: BrowserWindow | null = null; 28 | 29 | if (process.env.NODE_ENV === "production") { 30 | const sourceMapSupport = require("source-map-support"); 31 | sourceMapSupport.install(); 32 | } 33 | 34 | if (process.env.NODE_ENV === "development" || process.env.DEBUG_PROD === "true") { 35 | require("electron-debug")(); 36 | } 37 | 38 | const installExtensions = async () => { 39 | const installer = require("electron-devtools-installer"); 40 | const shouldForceDownload = !!process.env.UPGRADE_EXTENSIONS; 41 | const extensions = ["REACT_DEVELOPER_TOOLS"]; 42 | 43 | return installer 44 | .default( 45 | extensions.map((name) => installer[name]), 46 | shouldForceDownload 47 | ) 48 | .catch(console.log); 49 | }; 50 | 51 | const createWindow = async () => { 52 | if (process.env.NODE_ENV === "development" || process.env.DEBUG_PROD === "true") { 53 | await installExtensions(); 54 | } 55 | 56 | const RESOURCES_PATH = app.isPackaged ? path.join(process.resourcesPath, "assets") : path.join(__dirname, "../assets"); 57 | 58 | const getAssetPath = (...paths: string[]): string => { 59 | return path.join(RESOURCES_PATH, ...paths); 60 | }; 61 | 62 | mainWindow = new BrowserWindow({ 63 | show: false, 64 | width: 1024, 65 | // minWidth: 820, // Completely hardcoded number, the approximate width of command panel + output panel with some extra 66 | height: 728, 67 | icon: getAssetPath("icon.png"), 68 | webPreferences: { 69 | enableRemoteModule: true, 70 | contextIsolation: false, 71 | nodeIntegration: true, 72 | }, 73 | }); 74 | 75 | mainWindow.loadURL(`file://${__dirname}/index.html`); 76 | 77 | // @TODO: Use 'ready-to-show' event 78 | // https://github.com/electron/electron/blob/master/docs/api/browser-window.md#using-ready-to-show-event 79 | mainWindow.webContents.on("did-finish-load", () => { 80 | if (!mainWindow) { 81 | throw new Error('"mainWindow" is not defined'); 82 | } 83 | if (process.env.START_MINIMIZED) { 84 | mainWindow.minimize(); 85 | } else { 86 | mainWindow.show(); 87 | mainWindow.focus(); 88 | } 89 | }); 90 | 91 | mainWindow.on("closed", () => { 92 | mainWindow = null; 93 | }); 94 | 95 | // const menuBuilder = new MenuBuilder(mainWindow); 96 | // menuBuilder.buildMenu(); 97 | 98 | mainWindow.removeMenu(); 99 | 100 | // Open urls in the user's browser 101 | mainWindow.webContents.on("new-window", (event, url) => { 102 | event.preventDefault(); 103 | shell.openExternal(url); 104 | }); 105 | 106 | // Remove this if your app does not use auto updates 107 | // eslint-disable-next-line 108 | // new AppUpdater(); 109 | }; 110 | 111 | /** 112 | * Add event listeners... 113 | */ 114 | 115 | app.on("window-all-closed", () => { 116 | // Respect the OSX convention of having the application in memory even 117 | // after all windows have been closed 118 | if (process.platform !== "darwin") { 119 | app.quit(); 120 | } 121 | }); 122 | 123 | app.whenReady().then(createWindow).catch(console.log); 124 | 125 | app.on("activate", () => { 126 | // On macOS it's common to re-create a window in the app when the 127 | // dock icon is clicked and there are no other windows open. 128 | if (mainWindow === null) createWindow(); 129 | }); 130 | -------------------------------------------------------------------------------- /.erb/configs/webpack.config.renderer.prod.babel.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Build config for electron renderer process 3 | */ 4 | 5 | import path from 'path'; 6 | import webpack from 'webpack'; 7 | import MiniCssExtractPlugin from 'mini-css-extract-plugin'; 8 | import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'; 9 | import CssMinimizerPlugin from 'css-minimizer-webpack-plugin'; 10 | import { merge } from 'webpack-merge'; 11 | import TerserPlugin from 'terser-webpack-plugin'; 12 | import baseConfig from './webpack.config.base'; 13 | import CheckNodeEnv from '../scripts/CheckNodeEnv'; 14 | import DeleteSourceMaps from '../scripts/DeleteSourceMaps'; 15 | 16 | CheckNodeEnv('production'); 17 | DeleteSourceMaps(); 18 | 19 | const devtoolsConfig = process.env.DEBUG_PROD === 'true' ? { 20 | devtool: 'source-map' 21 | } : {}; 22 | 23 | export default merge(baseConfig, { 24 | ...devtoolsConfig, 25 | 26 | mode: 'production', 27 | 28 | target: 'electron-renderer', 29 | 30 | entry: [ 31 | 'core-js', 32 | 'regenerator-runtime/runtime', 33 | path.join(__dirname, '../../src/index.tsx'), 34 | ], 35 | 36 | output: { 37 | path: path.join(__dirname, '../../src/dist'), 38 | publicPath: './dist/', 39 | filename: 'renderer.prod.js', 40 | }, 41 | 42 | module: { 43 | rules: [ 44 | { 45 | test: /.s?css$/, 46 | use: [ 47 | { 48 | loader: MiniCssExtractPlugin.loader, 49 | options: { 50 | // `./dist` can't be inerhited for publicPath for styles. Otherwise generated paths will be ./dist/dist 51 | publicPath: './', 52 | }, 53 | }, 54 | 'css-loader', 55 | 'sass-loader' 56 | ], 57 | }, 58 | // WOFF Font 59 | { 60 | test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, 61 | use: { 62 | loader: 'url-loader', 63 | options: { 64 | limit: 10000, 65 | mimetype: 'application/font-woff', 66 | }, 67 | }, 68 | }, 69 | // WOFF2 Font 70 | { 71 | test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/, 72 | use: { 73 | loader: 'url-loader', 74 | options: { 75 | limit: 10000, 76 | mimetype: 'application/font-woff', 77 | }, 78 | }, 79 | }, 80 | // OTF Font 81 | { 82 | test: /\.otf(\?v=\d+\.\d+\.\d+)?$/, 83 | use: { 84 | loader: 'url-loader', 85 | options: { 86 | limit: 10000, 87 | mimetype: 'font/otf', 88 | }, 89 | }, 90 | }, 91 | // TTF Font 92 | { 93 | test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, 94 | use: { 95 | loader: 'url-loader', 96 | options: { 97 | limit: 10000, 98 | mimetype: 'application/octet-stream', 99 | }, 100 | }, 101 | }, 102 | // EOT Font 103 | { 104 | test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, 105 | use: 'file-loader', 106 | }, 107 | // SVG Font 108 | { 109 | test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, 110 | use: { 111 | loader: 'url-loader', 112 | options: { 113 | limit: 10000, 114 | mimetype: 'image/svg+xml', 115 | }, 116 | }, 117 | }, 118 | // Common Image Formats 119 | { 120 | test: /\.(?:ico|gif|png|jpg|jpeg|webp)$/, 121 | use: 'url-loader', 122 | }, 123 | ], 124 | }, 125 | 126 | optimization: { 127 | minimize: true, 128 | minimizer: 129 | [ 130 | new TerserPlugin({ 131 | parallel: true, 132 | }), 133 | new CssMinimizerPlugin(), 134 | ], 135 | }, 136 | 137 | plugins: [ 138 | /** 139 | * Create global constants which can be configured at compile time. 140 | * 141 | * Useful for allowing different behaviour between development builds and 142 | * release builds 143 | * 144 | * NODE_ENV should be production so that modules do not perform certain 145 | * development checks 146 | */ 147 | new webpack.EnvironmentPlugin({ 148 | NODE_ENV: 'production', 149 | DEBUG_PROD: false, 150 | }), 151 | 152 | new MiniCssExtractPlugin({ 153 | filename: 'style.css', 154 | }), 155 | 156 | new BundleAnalyzerPlugin({ 157 | analyzerMode: 158 | process.env.OPEN_ANALYZER === 'true' ? 'server' : 'disabled', 159 | openAnalyzer: process.env.OPEN_ANALYZER === 'true', 160 | }), 161 | ], 162 | }); 163 | -------------------------------------------------------------------------------- /src/utils.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable react/no-this-in-sfc */ 2 | 3 | import { clipboard } from "electron"; 4 | import fs from "fs"; 5 | 6 | /** 7 | * 8 | * @param iterable 9 | * @returns All consecutive pairs, or an empty iterable if there aren't any 10 | */ 11 | export function* yieldPairs(iterable: Iterable): Iterable<[T, T]> { 12 | const iterator = iterable[Symbol.iterator](); 13 | let current = iterator.next(); 14 | let next = iterator.next(); 15 | 16 | while (!next.done) { 17 | yield [current.value, next.value]; 18 | current = next; 19 | next = iterator.next(); 20 | } 21 | } 22 | 23 | export function copyToClipboard(text: string): void { 24 | clipboard.writeText(text); 25 | } 26 | 27 | export function doesDirectoryExist(path: string): boolean { 28 | return fs.existsSync(path) && fs.lstatSync(path).isDirectory(); 29 | } 30 | export function doesFileExist(path: string): boolean { 31 | return fs.existsSync(path) && fs.lstatSync(path).isFile(); 32 | } 33 | 34 | // export function splitToChunks(str: string, chunkSize: number): string[] { 35 | // const numChunks = Math.ceil(str.length / chunkSize); 36 | // const chunks = new Array(numChunks); 37 | 38 | // for (let i = 0, o = 0; i < numChunks; ++i, o += chunkSize) { 39 | // chunks[i] = str.substr(o, chunkSize); 40 | // } 41 | 42 | // return chunks; 43 | // } 44 | 45 | // #region Array prototype overrides 46 | 47 | declare global { 48 | interface Array { 49 | insert(index: number, item: T): void; 50 | removeByIndex(index: number): void; 51 | skip(predicate: (item: T) => boolean): [Array, number]; 52 | 53 | /** @throws {Error} if empty. */ 54 | last(): T; 55 | lastOrUndefined(): T | undefined; 56 | equals(array: Array): boolean; 57 | isEmpty(): boolean; 58 | 59 | /** @throws {Error} if empty. */ 60 | indexOfLastItem(): number; 61 | 62 | /** 63 | * @returns {null} if no item that fulfills the condition could be found. 64 | */ 65 | findLastIndex(predicate: (item: T, index: number) => boolean): number | null; 66 | 67 | splitByPredicate(predicate: (item: T, index: number) => boolean): [T[] /* true */, T[] /* false */]; 68 | } 69 | } 70 | 71 | Array.prototype.insert = function ArrayInsert(index: number, item: T) { 72 | this.splice(index, 0, item); 73 | }; 74 | 75 | Array.prototype.removeByIndex = function ArrayRemoveByIndex(index: number) { 76 | this.splice(index, 1); 77 | }; 78 | 79 | Array.prototype.isEmpty = function ArrayIsEmpty() { 80 | return this.length === 0; 81 | }; 82 | 83 | Array.prototype.indexOfLastItem = function ArrayIndexOfLastItem() { 84 | if (this.isEmpty()) throw new Error("Can't get you the index of the last item, the array is empty."); 85 | 86 | return this.length - 1; 87 | }; 88 | 89 | Array.prototype.skip = function ArraySkip(predicate: (item: T) => boolean): [Array, number] { 90 | for (let i = 0; i < this.length; i++) { 91 | const item = this[i]; 92 | 93 | if (!predicate(item)) return [this.slice(i), i]; 94 | } 95 | 96 | return [[], this.length]; 97 | }; 98 | 99 | Array.prototype.lastOrUndefined = function ArrayLastOrUndefined() { 100 | return this[this.length - 1]; 101 | }; 102 | 103 | Array.prototype.last = function ArrayLast() { 104 | if (this.isEmpty()) throw new Error("Last item could not be retrieved, array is empty."); 105 | 106 | return this[this.length - 1]; 107 | }; 108 | 109 | // Copied from https://stackoverflow.com/a/14853974/7009364 110 | Array.prototype.equals = function ArrayEquals(array) { 111 | // if the other array is a falsy value, return 112 | if (!array) return false; 113 | 114 | // compare lengths - can save a lot of time 115 | if (this.length !== array.length) return false; 116 | 117 | for (let i = 0, l = this.length; i < l; i++) { 118 | // Check if we have nested arrays 119 | if (this[i] instanceof Array && array[i] instanceof Array) { 120 | // recurse into the nested arrays 121 | if (!this[i].equals(array[i])) return false; 122 | } else if (this[i] !== array[i]) { 123 | // Warning - two different object instances will never be equal: {x:20} != {x:20} 124 | return false; 125 | } 126 | } 127 | return true; 128 | }; 129 | 130 | Array.prototype.findLastIndex = function ArrayFindLastIndex(predicate: (item: T, index: number) => boolean) { 131 | for (let i = this.indexOfLastItem(); i >= 0; i--) { 132 | const item = this[i]; 133 | 134 | if (predicate(item, i)) return i; 135 | } 136 | 137 | return null; 138 | }; 139 | 140 | Array.prototype.splitByPredicate = function ArraySplitByPredicate(predicate: (item: T, index: number) => boolean) { 141 | const trues = []; 142 | const falses = []; 143 | for (let i = 0; i < this.length; i++) { 144 | const item = this[i]; 145 | 146 | if (predicate(item, i)) trues.push(item); 147 | else falses.push(item); 148 | } 149 | 150 | return [trues, falses]; 151 | }; 152 | 153 | // #endregion 154 | -------------------------------------------------------------------------------- /src/Components/App/SettingsPanel.tsx: -------------------------------------------------------------------------------- 1 | import { Button, Checkbox, Collapse, FormControlLabel, makeStyles, Paper, TextField, Theme } from "@material-ui/core"; 2 | import { ExpandMore as ExpandMoreIcon, Settings as SettingsIcon } from "@material-ui/icons"; 3 | import clsx from "clsx"; 4 | import { observer } from "mobx-react"; 5 | import React, { useState } from "react"; 6 | import { flexCol, spaceChildren } from "../../JssUtils"; 7 | import { piperStore } from "../../PiperStore"; 8 | import { doesDirectoryExist, doesFileExist } from "../../utils"; 9 | import HelpPopup from "../Common/HelpPopup"; 10 | import BrowseButton from "./BrowseButton"; 11 | 12 | const useStyles = makeStyles((theme: Theme) => ({ 13 | root: { 14 | padding: "15px 5px", 15 | position: "relative", 16 | marginBottom: 20, 17 | paddingBottom: 25, 18 | ...flexCol, 19 | marginTop: 0, 20 | borderTopLeftRadius: 0, 21 | borderTopRightRadius: 0, 22 | }, 23 | expandArrow: { 24 | transition: theme.transitions.create("transform", { 25 | duration: theme.transitions.duration.shortest, 26 | }), 27 | }, 28 | expandButton: { 29 | position: "absolute", 30 | bottom: 0, 31 | 32 | // Align to the center 33 | left: 0, 34 | right: 0, 35 | marginLeft: "auto", 36 | marginRight: "auto", 37 | textAlign: "center", 38 | 39 | // Make it exceed the parent justttt right 40 | transform: "translateY(50%)", 41 | 42 | backgroundColor: "#f7f7f7", 43 | borderRadius: 9999, // Couldn't find a more elegant way 44 | 45 | paddingLeft: 5, 46 | paddingRight: 5, 47 | }, 48 | expandedPart: { 49 | marginTop: 15, 50 | ...flexCol, 51 | ...spaceChildren(15, "vertically"), 52 | }, 53 | rotated: { 54 | transform: "rotate(-180deg)", 55 | }, 56 | killCheckboxContainer: { 57 | paddingLeft: 5, 58 | display: "flex", 59 | alignItems: "center", 60 | }, 61 | checkboxFormControllLabel: { 62 | marginRight: 4, 63 | }, 64 | })); 65 | 66 | const SettingsPanel = observer(() => { 67 | // eslint-disable-next-line @typescript-eslint/naming-convention 68 | const [panelExpanded, setPanelExpanded] = useState(false); 69 | 70 | const cls = useStyles(); 71 | 72 | // eslint-disable-next-line @typescript-eslint/naming-convention 73 | const workingDirectoryDoesntExist = 74 | piperStore.workingDirectory !== undefined && !doesDirectoryExist(piperStore.workingDirectory); 75 | 76 | // eslint-disable-next-line @typescript-eslint/naming-convention 77 | const shellProgramExists = piperStore.shellProgram !== undefined && !doesFileExist(piperStore.shellProgram); 78 | 79 | return ( 80 | 81 | { 86 | piperStore.workingDirectory = e.target.value || undefined; 87 | }} 88 | error={workingDirectoryDoesntExist} 89 | helperText={workingDirectoryDoesntExist ? "This directory doesn't exist." : ""} 90 | inputProps={{ tabIndex: 1 }} 91 | InputProps={{ 92 | endAdornment: ( 93 | { 98 | piperStore.workingDirectory = ret.filePaths[0]; 99 | }} 100 | /> 101 | ), 102 | }} 103 | /> 104 | 105 |
106 | { 111 | piperStore.shellProgram = e.target.value || undefined; 112 | }} 113 | error={shellProgramExists} 114 | helperText={shellProgramExists ? "This file doesn't exist." : ""} 115 | inputProps={{ tabIndex: 1 }} 116 | InputProps={{ 117 | endAdornment: ( 118 | { 123 | piperStore.shellProgram = ret.filePaths[0]; 124 | }} 125 | /> 126 | ), 127 | }} 128 | /> 129 | { 134 | piperStore.pathEnvVar = e.target.value || undefined; 135 | }} 136 | inputProps={{ tabIndex: 1 }} 137 | /> 138 |
139 | { 146 | piperStore.killPredecessorOnClose = e.target.checked; 147 | }} 148 | /> 149 | } 150 | label="Kill preceding command(s) when a command is done" 151 | /> 152 | 156 |
157 |
158 |
159 | 163 |
164 | ); 165 | }); 166 | 167 | export default SettingsPanel; 168 | -------------------------------------------------------------------------------- /src/Components/App/CommandsPanel/CommandsPanel.tsx: -------------------------------------------------------------------------------- 1 | import { Button, makeStyles, Tooltip } from "@material-ui/core"; 2 | import { observer } from "mobx-react"; 3 | import React, { useState } from "react"; 4 | import { spaceChildren } from "../../../JssUtils"; 5 | import { piperStore } from "../../../PiperStore"; 6 | import { copyToClipboard } from "../../../utils"; 7 | import CoolButHardcodedCacheBar from "./CacheBar/CoolButHardcodedCacheBar"; 8 | import PlusDivider from "./PlusDivider"; 9 | import SingleCommandPanel from "./SingleCommandPanel"; 10 | import MousetrapWrapper from "../../Common/MousetrapWrapper"; 11 | import CopiedSuccessfulySnackbar from "../../Common/CopiedSuccessfulySnackbar"; 12 | 13 | const useStyles = makeStyles({ 14 | root: { display: "flex", overflowY: "auto" }, 15 | commandsWrapper: { flexGrow: 1 }, 16 | // disabledButton: {}, 17 | actionButtons: { display: "flex", flexWrap: "wrap", gap: 10, justifyContent: "space-between" }, 18 | mainActionButtons: { ...spaceChildren(10) }, 19 | }); 20 | 21 | const CommandsPanel = observer(() => { 22 | const cls = useStyles(); 23 | 24 | const commandsExceptSkippedOnes = piperStore.commands.filter((cmd) => !cmd.skipThisCommand); 25 | let entireCommandText = ""; 26 | 27 | if (!commandsExceptSkippedOnes.isEmpty()) { 28 | entireCommandText = commandsExceptSkippedOnes 29 | .map((cmd) => cmd.commandText) 30 | .reduce((accumulator, cmdText) => `${accumulator} | ${cmdText}`); 31 | } 32 | 33 | const shouldDisableRunButton = 34 | commandsExceptSkippedOnes.isEmpty() || 35 | !piperStore.areCommandsValidToRun || 36 | piperStore.everythingIsCachedNoNeedToRun || 37 | piperStore.isAnythingRunning; 38 | let runButtonTooltip = ""; 39 | 40 | const someCommandsAreNotValid = "Some commands are not valid"; 41 | if (shouldDisableRunButton) { 42 | if (commandsExceptSkippedOnes.isEmpty()) runButtonTooltip = "All commands are commented out"; 43 | else if (piperStore.everythingIsCachedNoNeedToRun) runButtonTooltip = "Everything is already cached"; 44 | else if (!piperStore.areCommandsValidToRun) runButtonTooltip = someCommandsAreNotValid; 45 | else if (piperStore.isAnythingRunning) runButtonTooltip = "Some commands are still running"; 46 | } 47 | 48 | const [shouldOpenCopySnackbar, setShouldOpenCopySnackbar] = useState(false); 49 | const copyFinalCommandButtonTooltip = !piperStore.areCommandsValidToRun ? someCommandsAreNotValid : ""; 50 | const shouldDisableCopyFinalCommandButton = !piperStore.areCommandsValidToRun; 51 | const copyFinalCommand = () => { 52 | copyToClipboard(entireCommandText); 53 | setShouldOpenCopySnackbar(true); 54 | }; 55 | 56 | const shouldDisableRemoveAllCommandsButton = piperStore.isAnythingRunning; 57 | const plusDividersTitle = 58 | "Insert a new command here. When focused on a command, hitting `Enter` or `Ctrl+Alt+Down` will insert a new command below and hitting `Shift+Enter`, `Alt+Enter` or `Ctrl+Alt+Up` will insert a new command above."; 59 | 60 | return ( 61 |
62 | 63 |
64 | { 70 | if (!shouldDisableRunButton) piperStore.runCommands(); 71 | }, 72 | ], 73 | [ 74 | // Remove all commands 75 | ["ctrl+alt+d", "ctrl+shift+d" /* Because ctrl+alt+d is already taken in Ubuntu */], 76 | () => { 77 | if (!shouldDisableRemoveAllCommandsButton) piperStore.removeAllCommands(); 78 | }, 79 | ], 80 | [ 81 | // Copy final command 82 | "ctrl+alt+c", 83 | () => { 84 | if (!shouldDisableCopyFinalCommandButton) copyFinalCommand(); 85 | }, 86 | ], 87 | ]} 88 | > 89 | piperStore.insertNewCommand(0)} 91 | disabled={piperStore.isAnythingRunning} 92 | title={plusDividersTitle} 93 | /> 94 | {piperStore.commands.map((cmd, index) => { 95 | const insertCommandAbove = () => piperStore.insertNewCommand(index); 96 | const insertCommandBelow = () => piperStore.insertNewCommand(index + 1); 97 | 98 | return ( 99 |
100 | 106 | 107 | 108 | 109 |
110 | ); 111 | })} 112 |
113 | 114 |
115 |
116 | 117 | 118 | 127 | 128 | 129 | 130 | 131 | 139 | setShouldOpenCopySnackbar(false)} /> 140 | 141 | 142 |
143 | 144 | 145 | 153 | 154 | 155 |
156 |
157 |
158 | ); 159 | }); 160 | 161 | export default CommandsPanel; 162 | -------------------------------------------------------------------------------- /src/Components/App/CommandsPanel/CacheBar/CoolButHardcodedCacheBar.tsx: -------------------------------------------------------------------------------- 1 | import { Checkbox, makeStyles, Tooltip } from "@material-ui/core"; 2 | import { CSSProperties } from "@material-ui/core/styles/withStyles"; 3 | import clsx from "clsx"; 4 | import { observer } from "mobx-react"; 5 | import React from "react"; 6 | import { flexCol, flexColCentered, spaceChildren } from "../../../../JssUtils"; 7 | import { piperStore } from "../../../../PiperStore"; 8 | import { theme as appTheme } from "../../../ThemeStuff/theme"; 9 | import { BUTTON_HEIGHT, BUTTON_WIDTH, CacheBarButton, CacheBarButtonState } from "./CacheBarButton"; 10 | import { availableCacheBarColor, cacheToUseBarColor } from "./Constants"; 11 | 12 | // const BUTTON_MARGIN = 61; 13 | const COMMAND_HEIGHT = 106; 14 | const DISTANCE_BETWEEN_BUTTONS = COMMAND_HEIGHT - BUTTON_HEIGHT + 6; /* the 6 is necessary, no idea why. */ 15 | const BAR_WIDTH = BUTTON_WIDTH + 10; 16 | const ALIGNMENT_BUFFER = 34; // pure magic. // 0.5 * COMMAND_HEIGHT - 19 ? 17 | const CHECKBOX_HEIGHT = 24; 18 | 19 | const barStyles: CSSProperties = { 20 | position: "absolute", 21 | top: 0, 22 | right: 0, 23 | left: 0, 24 | // marginLeft: "auto", 25 | // marginRight: "auto", 26 | width: BAR_WIDTH, 27 | borderTopLeftRadius: 5, 28 | borderTopRightRadius: 5, 29 | borderBottomLeftRadius: BAR_WIDTH / 2, 30 | borderBottomRightRadius: BAR_WIDTH / 2, 31 | transition: appTheme.transitions.create(["all"], { 32 | duration: appTheme.transitions.duration.shortest, 33 | }), 34 | marginTop: 2, 35 | }; 36 | 37 | const useStyles = makeStyles((theme) => ({ 38 | root: { 39 | position: "relative", 40 | minWidth: BAR_WIDTH, 41 | marginRight: 5, 42 | height: "fit-content", 43 | 44 | // backgroundColor: 'white', 45 | // borderStyle: 'solid', 46 | // borderBottomLeftRadius: 20, 47 | // borderBottomRightRadius: 20, 48 | // borderTopLeftRadius: 5, 49 | // borderTopRightRadius: 5, 50 | // borderWidth: 2, 51 | // borderColor: darken(theme.palette.grey['300'], 0.1), 52 | // paddingLeft: 2, 53 | // paddingRight: 2, 54 | // "&$useCache": { 55 | // borderColor: theme.palette.primary.light, 56 | // }, 57 | paddingTop: 2, 58 | paddingBottom: 7, 59 | }, 60 | buttonsAndCheckboxWrapper: { 61 | // marginTop: ALIGNMENT_BUFFER, 62 | ...flexColCentered, 63 | }, 64 | availableCacheBar: { 65 | ...barStyles, 66 | // backgroundColor: theme.palette.grey['300'], 67 | backgroundColor: availableCacheBarColor(theme), 68 | }, 69 | cacheToUseBar: { 70 | ...barStyles, 71 | // backgroundColor: lighten(theme.palette.primary.light, 0.6), 72 | backgroundColor: cacheToUseBarColor(theme), 73 | }, 74 | buttonsWrapper: { 75 | marginTop: ALIGNMENT_BUFFER, 76 | ...spaceChildren(DISTANCE_BETWEEN_BUTTONS, "vertically"), 77 | // ...notLastChild({ marginBottom: BUTTON_MARGIN }), 78 | // ...directChildren({ marginTop: BUTTON_MARGIN }), 79 | ...flexCol, 80 | zIndex: 0, // To allow the tooltip to work for buttons with pointer events set to none 81 | }, 82 | button: {}, 83 | checkbox: { 84 | padding: 2, 85 | height: CHECKBOX_HEIGHT, 86 | }, 87 | useCache: {}, 88 | pointerEventsNone: { pointerEvents: "none" }, 89 | })); 90 | 91 | function calculateBarHeight(numberOfButtons: number) { 92 | if (numberOfButtons === 0) return 0; 93 | 94 | return ( 95 | CHECKBOX_HEIGHT + 96 | ALIGNMENT_BUFFER + 97 | DISTANCE_BETWEEN_BUTTONS * (numberOfButtons - 1) + 98 | numberOfButtons * BUTTON_HEIGHT + 99 | (BAR_WIDTH - BUTTON_WIDTH) / 2 + 100 | 4 101 | // 1 // Pure magicnumber to make it prettier. Without it, it appears too short for some reason. 102 | ); 103 | } 104 | 105 | function CoolButHardcodedCacheBar() { 106 | const cls = useStyles(); 107 | 108 | const { shouldUseCache, indexOfCacheToUse, indexOfDesiredCacheToUse, indexOfLastCommandWithValidCache } = piperStore; 109 | 110 | const availableCacheBarHeight = calculateBarHeight( 111 | indexOfLastCommandWithValidCache === null ? 0 : indexOfLastCommandWithValidCache + 1 112 | ); 113 | 114 | const cacheToUseBarHeight = calculateBarHeight(indexOfCacheToUse === null ? 0 : indexOfCacheToUse + 1); 115 | 116 | const buttons = piperStore.commands.map((command, commandIndex) => { 117 | let buttonState: CacheBarButtonState; 118 | let buttonTooltipText: string; 119 | 120 | if (piperStore.shouldUseCache === false) { 121 | buttonState = "disabled"; 122 | buttonTooltipText = ""; 123 | } else if (command.skipThisCommand) { 124 | buttonState = "disabled"; 125 | buttonTooltipText = "Can't use this cache, this command is commented out"; 126 | } else if (commandIndex === indexOfCacheToUse) { 127 | buttonState = "selected"; 128 | buttonTooltipText = "This command's cache will be used for the next run"; 129 | } else if (command.isValidCacheAvailable) { 130 | buttonState = "available"; 131 | buttonTooltipText = "Click to use command's cache for the next run"; 132 | } else { 133 | buttonState = "disabled"; 134 | buttonTooltipText = "There's no valid cache available for this command yet"; 135 | } 136 | 137 | return ( 138 | { 144 | piperStore.indexOfDesiredCacheToUse = commandIndex; 145 | }} 146 | /> 147 | ); 148 | }); 149 | 150 | return ( 151 | 152 |
{ 159 | // For debugging 160 | if (e.ctrlKey) 161 | // eslint-disable-next-line no-console 162 | console.log(`Cache info: `, { 163 | useCache: shouldUseCache, 164 | indexOfCacheToUse, 165 | indexOfDesiredCacheToUse, 166 | indexOfLastCommandWithValidCache, 167 | }); 168 | }} 169 | > 170 | {/* Cache */} 171 |
177 |
184 |
185 | 186 | { 191 | piperStore.shouldUseCache = e.target.checked; 192 | }} 193 | /> 194 | 195 |
{buttons}
196 |
197 |
198 | 199 | ); 200 | } 201 | 202 | export default observer(CoolButHardcodedCacheBar); 203 | -------------------------------------------------------------------------------- /src/Command.ts: -------------------------------------------------------------------------------- 1 | import { ChildProcess, exec } from "child_process"; 2 | import crypto from "crypto"; 3 | import { action, makeAutoObservable } from "mobx"; 4 | import React from "react"; 5 | import treeKill from "tree-kill"; 6 | import CommandStatus from "./CommandStatus"; 7 | // eslint-disable-next-line import/no-cycle 8 | import { PiperStore } from "./PiperStore"; 9 | 10 | export default class Command { 11 | // #region id property 12 | 13 | private _id = crypto.randomBytes(16).toString("hex"); 14 | 15 | public get id(): string { 16 | return this._id; 17 | } 18 | 19 | // #endregion 20 | 21 | // #region commandText 22 | 23 | private _commandText = ""; 24 | 25 | public get commandText(): string { 26 | return this._commandText; 27 | } 28 | 29 | public set commandText(v: string) { 30 | this._commandText = v; 31 | } 32 | 33 | // #endregion 34 | 35 | stdout?: string = undefined; 36 | 37 | stderr?: string = undefined; 38 | 39 | /** 40 | * Contains the text of the command from when it was last executed. 41 | */ 42 | private _lastCommandRun?: string; 43 | 44 | private _precedingCommandsOnLastRun: string[] | null = null; 45 | 46 | public get precedingCommandsOnLastRun(): string[] | null { 47 | return this._precedingCommandsOnLastRun; 48 | } 49 | 50 | private _piperStore: PiperStore; 51 | 52 | // #region skipThisCommand 53 | 54 | private _skipThisCommand = false; 55 | 56 | public get skipThisCommand(): boolean { 57 | return this._skipThisCommand; 58 | } 59 | 60 | public set skipThisCommand(v: boolean) { 61 | this._skipThisCommand = v; 62 | } 63 | 64 | // #endregion 65 | 66 | // #region Execution error 67 | 68 | private _executionError: string | undefined; 69 | 70 | public get executionError(): string | undefined { 71 | return this._executionError; 72 | } 73 | // public set executionError(v : string | undefined) { 74 | // this._executionError = v; 75 | // } 76 | 77 | // #endregion 78 | 79 | // #region status property 80 | 81 | /** 82 | * Status is managed independently for two reasons: 83 | * 1. Because the ChildProcess class doesn't supply a proper API to get the process's status 84 | * 2. So Mobx can work it's magic with the status, which would probable not be straight-forward if the value was managed by the ChildProcess class. 85 | */ 86 | private _status: CommandStatus = CommandStatus.NEW; 87 | 88 | public get status(): CommandStatus { 89 | return this._status; 90 | } 91 | 92 | /** 93 | * Not using a setter because Mobx is raising a warning when using a setter even though it doesn't seem like the warning is in place. The warning is: [MobX] Since strict-mode is enabled, changing (observed) observable values without using an action is not allowed. 94 | */ 95 | private setStatus(newStatus: CommandStatus) { 96 | this._status = newStatus; 97 | } 98 | 99 | // #endregion 100 | 101 | public get killed(): boolean { 102 | return [ 103 | CommandStatus.KILLED_MANUALLY, 104 | CommandStatus.KILLED_NEXT_COMMAND_CLOSED, 105 | CommandStatus.KILLED_UNKNOWN_REASON, 106 | ].includes(this.status); 107 | } 108 | 109 | // #region wasLastKilled property 110 | 111 | // private _wasManuallyKilled: boolean = false; 112 | // public get wasManuallyKilled(): boolean { 113 | // return this._wasManuallyKilled; 114 | // } 115 | // private setWasManuallyKilled(v: boolean) { 116 | // this._wasManuallyKilled = v; 117 | // } 118 | 119 | // #endregion 120 | 121 | get isCommandDifferentThanWhenLastExecuted() { 122 | return this._lastCommandRun !== this.commandText; 123 | } 124 | 125 | public get isValidCacheAvailable(): boolean { 126 | return ( 127 | this.status !== CommandStatus.RUNNING && 128 | this.stdout !== undefined && 129 | !this.isCommandDifferentThanWhenLastExecuted && 130 | this.precedingCommandsOnLastRun !== null && 131 | this.precedingCommandsOnLastRun.equals(this._piperStore.getCommandsThatAreGoingToRunBeforeTheGivenCommand(this.id)) 132 | ); 133 | } 134 | 135 | process?: ChildProcess; 136 | 137 | constructor(piperStore: PiperStore) { 138 | this._piperStore = piperStore; 139 | makeAutoObservable(this); 140 | } 141 | 142 | killIfProcessStillRunning(killReason: "manual" | "next-command-closed", signal: string | number | undefined = undefined) { 143 | if (this.status !== CommandStatus.RUNNING) return; 144 | 145 | if (!this.process) throw new Error("Something went horribly wrong. This command's process member is falsey."); 146 | 147 | treeKill(this.process.pid, signal); 148 | 149 | switch (killReason) { 150 | case "manual": 151 | this.setStatus(CommandStatus.KILLED_MANUALLY); 152 | break; 153 | case "next-command-closed": 154 | this.setStatus(CommandStatus.KILLED_NEXT_COMMAND_CLOSED); 155 | break; 156 | 157 | default: 158 | throw new Error(`killReason value "${killReason}" is not supported.`); 159 | } 160 | } 161 | 162 | /** 163 | * @throws {Error} if starting the process failed. 164 | */ 165 | startCommandAndRecordOutput(precedingCommands: string[] | null): void { 166 | this._resetExecutionData(); 167 | 168 | const { workingDirectory, shellProgram, pathEnvVar } = this._piperStore; 169 | 170 | try { 171 | this.process = exec(this.commandText, { 172 | cwd: workingDirectory, 173 | shell: shellProgram, 174 | env: { PATH: pathEnvVar }, 175 | maxBuffer: Infinity, 176 | }); 177 | } catch (e) { 178 | this.setStatus(CommandStatus.ERROR); 179 | this._executionError = "Failed to even start the command. Did you mess with the 'Shell Program' config?"; 180 | console.error(e); 181 | throw e; 182 | } 183 | 184 | this.setStatus(CommandStatus.RUNNING); 185 | 186 | // this.process?.on("error", (e) => { 187 | // this.setStatus(CommandStatus.ERROR); 188 | // alert( 189 | // "Failed to even start the process. Something's very wrong. Make sure you didn't put any garbage in the Shell Program field." 190 | // ); 191 | // }); 192 | 193 | const saveCommandStdout = action((data: string) => { 194 | if (this.stdout === undefined) this.stdout = ""; 195 | this.stdout += data; 196 | }); 197 | 198 | const saveCommandStderr = action((data: string) => { 199 | if (this.stderr === undefined) this.stderr = ""; 200 | this.stderr += data; 201 | }); 202 | 203 | this.process.stdout?.on("data", saveCommandStdout); 204 | this.process.stderr?.on("data", saveCommandStderr); 205 | // this.process.stdin?.on('data', this.saveCommandStderr); 206 | this.process.on("exit", (exitCode) => { 207 | if ([CommandStatus.KILLED_MANUALLY, CommandStatus.KILLED_NEXT_COMMAND_CLOSED].includes(this.status)) { 208 | // Status already set, do nothing. 209 | } else if (exitCode !== null) { 210 | if (exitCode === 0) this.setStatus(CommandStatus.EXITED); 211 | else this.setStatus(CommandStatus.ERROR); 212 | } else if (this.process?.killed) this.setStatus(CommandStatus.KILLED_UNKNOWN_REASON); 213 | else console.error("Something weird is going on: the exitCode is null but this.process.killed is not true."); 214 | }); 215 | 216 | this.process.on("error", (...e: unknown[]) => { 217 | console.warn(`error occured when running command "${this.commandText}"`, e); 218 | this.setStatus(CommandStatus.ERROR); 219 | }); 220 | 221 | this._lastCommandRun = this.commandText; 222 | this._precedingCommandsOnLastRun = precedingCommands ?? []; 223 | } 224 | 225 | // #region input ref stuff 226 | 227 | private _inputRef?: React.RefObject; 228 | 229 | public setInputRef(ref: React.RefObject) { 230 | this._inputRef = ref; 231 | } 232 | 233 | public focusOnThisCommandIfPossible() { 234 | this._inputRef?.current?.focus(); 235 | } 236 | 237 | // #endregion 238 | 239 | private _resetExecutionData() { 240 | this.stdout = undefined; 241 | this.stderr = undefined; 242 | this.setStatus(CommandStatus.NEW); 243 | this.process = undefined; 244 | this._executionError = undefined; 245 | } 246 | } 247 | -------------------------------------------------------------------------------- /.erb/configs/webpack.config.renderer.dev.babel.js: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import fs from 'fs'; 3 | import webpack from 'webpack'; 4 | import chalk from 'chalk'; 5 | import { merge } from 'webpack-merge'; 6 | import { spawn, execSync } from 'child_process'; 7 | import baseConfig from './webpack.config.base'; 8 | import CheckNodeEnv from '../scripts/CheckNodeEnv'; 9 | import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin'; 10 | 11 | // When an ESLint server is running, we can't set the NODE_ENV so we'll check if it's 12 | // at the dev webpack config is not accidentally run in a production environment 13 | if (process.env.NODE_ENV === 'production') { 14 | CheckNodeEnv('development'); 15 | } 16 | 17 | const port = process.env.PORT || 1212; 18 | const publicPath = `http://localhost:${port}/dist`; 19 | const dllDir = path.join(__dirname, '../dll'); 20 | const manifest = path.resolve(dllDir, 'renderer.json'); 21 | const requiredByDLLConfig = module.parent.filename.includes( 22 | 'webpack.config.renderer.dev.dll' 23 | ); 24 | 25 | /** 26 | * Warn if the DLL is not built 27 | */ 28 | if (!requiredByDLLConfig && !(fs.existsSync(dllDir) && fs.existsSync(manifest))) { 29 | console.log( 30 | chalk.black.bgYellow.bold( 31 | 'The DLL files are missing. Sit back while we build them for you with "yarn build-dll"' 32 | ) 33 | ); 34 | execSync('yarn build-dll'); 35 | } 36 | 37 | export default merge(baseConfig, { 38 | devtool: 'inline-source-map', 39 | 40 | mode: 'development', 41 | 42 | target: 'electron-renderer', 43 | 44 | entry: [ 45 | 'core-js', 46 | 'regenerator-runtime/runtime', 47 | require.resolve('../../src/index.tsx'), 48 | ], 49 | 50 | output: { 51 | publicPath: `http://localhost:${port}/dist/`, 52 | filename: 'renderer.dev.js', 53 | }, 54 | 55 | module: { 56 | rules: [ 57 | { 58 | test: /\.[jt]sx?$/, 59 | exclude: /node_modules/, 60 | use: [ 61 | { 62 | loader: require.resolve('babel-loader'), 63 | options: { 64 | plugins: [ 65 | require.resolve('react-refresh/babel'), 66 | ].filter(Boolean), 67 | }, 68 | }, 69 | ], 70 | }, 71 | { 72 | test: /\.global\.css$/, 73 | use: [ 74 | { 75 | loader: 'style-loader', 76 | }, 77 | { 78 | loader: 'css-loader', 79 | options: { 80 | sourceMap: true, 81 | }, 82 | }, 83 | ], 84 | }, 85 | { 86 | test: /^((?!\.global).)*\.css$/, 87 | use: [ 88 | { 89 | loader: 'style-loader', 90 | }, 91 | { 92 | loader: 'css-loader', 93 | options: { 94 | modules: { 95 | localIdentName: '[name]__[local]__[hash:base64:5]', 96 | }, 97 | sourceMap: true, 98 | importLoaders: 1, 99 | }, 100 | }, 101 | ], 102 | }, 103 | // SASS support - compile all .global.scss files and pipe it to style.css 104 | { 105 | test: /\.global\.(scss|sass)$/, 106 | use: [ 107 | { 108 | loader: 'style-loader', 109 | }, 110 | { 111 | loader: 'css-loader', 112 | options: { 113 | sourceMap: true, 114 | }, 115 | }, 116 | { 117 | loader: 'sass-loader', 118 | }, 119 | ], 120 | }, 121 | // SASS support - compile all other .scss files and pipe it to style.css 122 | { 123 | test: /^((?!\.global).)*\.(scss|sass)$/, 124 | use: [ 125 | { 126 | loader: 'style-loader', 127 | }, 128 | { 129 | loader: '@teamsupercell/typings-for-css-modules-loader', 130 | }, 131 | { 132 | loader: 'css-loader', 133 | options: { 134 | modules: { 135 | localIdentName: '[name]__[local]__[hash:base64:5]', 136 | }, 137 | sourceMap: true, 138 | importLoaders: 1, 139 | }, 140 | }, 141 | { 142 | loader: 'sass-loader', 143 | }, 144 | ], 145 | }, 146 | // WOFF Font 147 | { 148 | test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, 149 | use: { 150 | loader: 'url-loader', 151 | options: { 152 | limit: 10000, 153 | mimetype: 'application/font-woff', 154 | }, 155 | }, 156 | }, 157 | // WOFF2 Font 158 | { 159 | test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/, 160 | use: { 161 | loader: 'url-loader', 162 | options: { 163 | limit: 10000, 164 | mimetype: 'application/font-woff', 165 | }, 166 | }, 167 | }, 168 | // OTF Font 169 | { 170 | test: /\.otf(\?v=\d+\.\d+\.\d+)?$/, 171 | use: { 172 | loader: 'url-loader', 173 | options: { 174 | limit: 10000, 175 | mimetype: 'font/otf', 176 | }, 177 | }, 178 | }, 179 | // TTF Font 180 | { 181 | test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, 182 | use: { 183 | loader: 'url-loader', 184 | options: { 185 | limit: 10000, 186 | mimetype: 'application/octet-stream', 187 | }, 188 | }, 189 | }, 190 | // EOT Font 191 | { 192 | test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, 193 | use: 'file-loader', 194 | }, 195 | // SVG Font 196 | { 197 | test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, 198 | use: { 199 | loader: 'url-loader', 200 | options: { 201 | limit: 10000, 202 | mimetype: 'image/svg+xml', 203 | }, 204 | }, 205 | }, 206 | // Common Image Formats 207 | { 208 | test: /\.(?:ico|gif|png|jpg|jpeg|webp)$/, 209 | use: 'url-loader', 210 | }, 211 | ], 212 | }, 213 | plugins: [ 214 | 215 | requiredByDLLConfig 216 | ? null 217 | : new webpack.DllReferencePlugin({ 218 | context: path.join(__dirname, '../dll'), 219 | manifest: require(manifest), 220 | sourceType: 'var', 221 | }), 222 | 223 | new webpack.NoEmitOnErrorsPlugin(), 224 | 225 | /** 226 | * Create global constants which can be configured at compile time. 227 | * 228 | * Useful for allowing different behaviour between development builds and 229 | * release builds 230 | * 231 | * NODE_ENV should be production so that modules do not perform certain 232 | * development checks 233 | * 234 | * By default, use 'development' as NODE_ENV. This can be overriden with 235 | * 'staging', for example, by changing the ENV variables in the npm scripts 236 | */ 237 | new webpack.EnvironmentPlugin({ 238 | NODE_ENV: 'development', 239 | }), 240 | 241 | new webpack.LoaderOptionsPlugin({ 242 | debug: true, 243 | }), 244 | 245 | new ReactRefreshWebpackPlugin(), 246 | ], 247 | 248 | node: { 249 | __dirname: false, 250 | __filename: false, 251 | }, 252 | 253 | devServer: { 254 | port, 255 | publicPath, 256 | compress: true, 257 | noInfo: false, 258 | stats: 'errors-only', 259 | inline: true, 260 | lazy: false, 261 | hot: true, 262 | headers: { 'Access-Control-Allow-Origin': '*' }, 263 | contentBase: path.join(__dirname, 'dist'), 264 | watchOptions: { 265 | aggregateTimeout: 300, 266 | ignored: /node_modules/, 267 | poll: 100, 268 | }, 269 | historyApiFallback: { 270 | verbose: true, 271 | disableDotRule: false, 272 | }, 273 | before() { 274 | console.log('Starting Main Process...'); 275 | spawn('npm', ['run', 'start:main'], { 276 | shell: true, 277 | env: process.env, 278 | stdio: 'inherit', 279 | }) 280 | .on('close', (code) => process.exit(code)) 281 | .on('error', (spawnError) => console.error(spawnError)); 282 | }, 283 | }, 284 | }); 285 | -------------------------------------------------------------------------------- /src/menu.ts: -------------------------------------------------------------------------------- 1 | import { app, Menu, shell, BrowserWindow, MenuItemConstructorOptions } from "electron"; 2 | 3 | interface DarwinMenuItemConstructorOptions extends MenuItemConstructorOptions { 4 | selector?: string; 5 | submenu?: DarwinMenuItemConstructorOptions[] | Menu; 6 | } 7 | 8 | export default class MenuBuilder { 9 | mainWindow: BrowserWindow; 10 | 11 | constructor(mainWindow: BrowserWindow) { 12 | this.mainWindow = mainWindow; 13 | } 14 | 15 | buildMenu(): Menu { 16 | if (process.env.NODE_ENV === "development" || process.env.DEBUG_PROD === "true") { 17 | this.setupDevelopmentEnvironment(); 18 | } 19 | 20 | const template = process.platform === "darwin" ? this.buildDarwinTemplate() : this.buildDefaultTemplate(); 21 | 22 | const menu = Menu.buildFromTemplate(template); 23 | Menu.setApplicationMenu(menu); 24 | 25 | return menu; 26 | } 27 | 28 | setupDevelopmentEnvironment(): void { 29 | this.mainWindow.webContents.on("context-menu", (_, props) => { 30 | const { x, y } = props; 31 | 32 | Menu.buildFromTemplate([ 33 | { 34 | label: "Inspect element", 35 | click: () => { 36 | this.mainWindow.webContents.inspectElement(x, y); 37 | }, 38 | }, 39 | ]).popup({ window: this.mainWindow }); 40 | }); 41 | } 42 | 43 | buildDarwinTemplate(): MenuItemConstructorOptions[] { 44 | const subMenuAbout: DarwinMenuItemConstructorOptions = { 45 | label: "Electron", 46 | submenu: [ 47 | { 48 | label: "About ElectronReact", 49 | selector: "orderFrontStandardAboutPanel:", 50 | }, 51 | { type: "separator" }, 52 | { label: "Services", submenu: [] }, 53 | { type: "separator" }, 54 | { 55 | label: "Hide ElectronReact", 56 | accelerator: "Command+H", 57 | selector: "hide:", 58 | }, 59 | { 60 | label: "Hide Others", 61 | accelerator: "Command+Shift+H", 62 | selector: "hideOtherApplications:", 63 | }, 64 | { label: "Show All", selector: "unhideAllApplications:" }, 65 | { type: "separator" }, 66 | { 67 | label: "Quit", 68 | accelerator: "Command+Q", 69 | click: () => { 70 | app.quit(); 71 | }, 72 | }, 73 | ], 74 | }; 75 | const subMenuEdit: DarwinMenuItemConstructorOptions = { 76 | label: "Edit", 77 | submenu: [ 78 | { label: "Undo", accelerator: "Command+Z", selector: "undo:" }, 79 | { label: "Redo", accelerator: "Shift+Command+Z", selector: "redo:" }, 80 | { type: "separator" }, 81 | { label: "Cut", accelerator: "Command+X", selector: "cut:" }, 82 | { label: "Copy", accelerator: "Command+C", selector: "copy:" }, 83 | { label: "Paste", accelerator: "Command+V", selector: "paste:" }, 84 | { 85 | label: "Select All", 86 | accelerator: "Command+A", 87 | selector: "selectAll:", 88 | }, 89 | ], 90 | }; 91 | const subMenuViewDev: MenuItemConstructorOptions = { 92 | label: "View", 93 | submenu: [ 94 | { 95 | label: "Reload", 96 | accelerator: "Command+R", 97 | click: () => { 98 | this.mainWindow.webContents.reload(); 99 | }, 100 | }, 101 | { 102 | label: "Toggle Full Screen", 103 | accelerator: "Ctrl+Command+F", 104 | click: () => { 105 | this.mainWindow.setFullScreen(!this.mainWindow.isFullScreen()); 106 | }, 107 | }, 108 | { 109 | label: "Toggle Developer Tools", 110 | accelerator: "Alt+Command+I", 111 | click: () => { 112 | this.mainWindow.webContents.toggleDevTools(); 113 | }, 114 | }, 115 | ], 116 | }; 117 | const subMenuViewProd: MenuItemConstructorOptions = { 118 | label: "View", 119 | submenu: [ 120 | { 121 | label: "Toggle Full Screen", 122 | accelerator: "Ctrl+Command+F", 123 | click: () => { 124 | this.mainWindow.setFullScreen(!this.mainWindow.isFullScreen()); 125 | }, 126 | }, 127 | ], 128 | }; 129 | const subMenuWindow: DarwinMenuItemConstructorOptions = { 130 | label: "Window", 131 | submenu: [ 132 | { 133 | label: "Minimize", 134 | accelerator: "Command+M", 135 | selector: "performMiniaturize:", 136 | }, 137 | { label: "Close", accelerator: "Command+W", selector: "performClose:" }, 138 | { type: "separator" }, 139 | { label: "Bring All to Front", selector: "arrangeInFront:" }, 140 | ], 141 | }; 142 | const subMenuHelp: MenuItemConstructorOptions = { 143 | label: "Help", 144 | submenu: [ 145 | { 146 | label: "Learn More", 147 | click() { 148 | shell.openExternal("https://electronjs.org"); 149 | }, 150 | }, 151 | { 152 | label: "Documentation", 153 | click() { 154 | shell.openExternal("https://github.com/electron/electron/tree/master/docs#readme"); 155 | }, 156 | }, 157 | { 158 | label: "Community Discussions", 159 | click() { 160 | shell.openExternal("https://www.electronjs.org/community"); 161 | }, 162 | }, 163 | { 164 | label: "Search Issues", 165 | click() { 166 | shell.openExternal("https://github.com/electron/electron/issues"); 167 | }, 168 | }, 169 | ], 170 | }; 171 | 172 | const subMenuView = 173 | process.env.NODE_ENV === "development" || process.env.DEBUG_PROD === "true" ? subMenuViewDev : subMenuViewProd; 174 | 175 | return [subMenuAbout, subMenuEdit, subMenuView, subMenuWindow, subMenuHelp]; 176 | } 177 | 178 | buildDefaultTemplate() { 179 | const templateDefault = [ 180 | { 181 | label: "&File", 182 | submenu: [ 183 | { 184 | label: "&Open", 185 | accelerator: "Ctrl+O", 186 | }, 187 | { 188 | label: "&Close", 189 | accelerator: "Ctrl+W", 190 | click: () => { 191 | this.mainWindow.close(); 192 | }, 193 | }, 194 | ], 195 | }, 196 | { 197 | label: "&View", 198 | submenu: 199 | process.env.NODE_ENV === "development" || process.env.DEBUG_PROD === "true" 200 | ? [ 201 | { 202 | label: "&Reload", 203 | accelerator: "Ctrl+R", 204 | click: () => { 205 | this.mainWindow.webContents.reload(); 206 | }, 207 | }, 208 | { 209 | label: "Toggle &Full Screen", 210 | accelerator: "F11", 211 | click: () => { 212 | this.mainWindow.setFullScreen(!this.mainWindow.isFullScreen()); 213 | }, 214 | }, 215 | { 216 | label: "Toggle &Developer Tools", 217 | accelerator: "Alt+Ctrl+I", 218 | click: () => { 219 | this.mainWindow.webContents.toggleDevTools(); 220 | }, 221 | }, 222 | ] 223 | : [ 224 | { 225 | label: "Toggle &Full Screen", 226 | accelerator: "F11", 227 | click: () => { 228 | this.mainWindow.setFullScreen(!this.mainWindow.isFullScreen()); 229 | }, 230 | }, 231 | ], 232 | }, 233 | { 234 | label: "Help", 235 | submenu: [ 236 | { 237 | label: "Learn More", 238 | click() { 239 | shell.openExternal("https://electronjs.org"); 240 | }, 241 | }, 242 | { 243 | label: "Documentation", 244 | click() { 245 | shell.openExternal("https://github.com/electron/electron/tree/master/docs#readme"); 246 | }, 247 | }, 248 | { 249 | label: "Community Discussions", 250 | click() { 251 | shell.openExternal("https://www.electronjs.org/community"); 252 | }, 253 | }, 254 | { 255 | label: "Search Issues", 256 | click() { 257 | shell.openExternal("https://github.com/electron/electron/issues"); 258 | }, 259 | }, 260 | ], 261 | }, 262 | ]; 263 | 264 | return templateDefault; 265 | } 266 | } 267 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "shell-piper", 3 | "productName": "ShellPiper", 4 | "description": "The shell piping editor", 5 | "version": "1.0.0", 6 | "scripts": { 7 | "build": "concurrently \"yarn build:main\" \"yarn build:renderer\"", 8 | "build:main": "cross-env NODE_ENV=production webpack --config ./.erb/configs/webpack.config.main.prod.babel.js", 9 | "build:renderer": "cross-env NODE_ENV=production webpack --config ./.erb/configs/webpack.config.renderer.prod.babel.js", 10 | "rebuild": "electron-rebuild --parallel --types prod,dev,optional --module-dir src", 11 | "lint": "cross-env NODE_ENV=development eslint . --cache --ext .js,.jsx,.ts,.tsx", 12 | "package": "rm -rf src/dist && yarn build && electron-builder build --publish never", 13 | "postinstall": "node -r @babel/register .erb/scripts/CheckNativeDep.js && electron-builder install-app-deps && yarn cross-env NODE_ENV=development webpack --config ./.erb/configs/webpack.config.renderer.dev.dll.babel.js && opencollective-postinstall && yarn-deduplicate yarn.lock", 14 | "start": "node -r @babel/register ./.erb/scripts/CheckPortInUse.js && cross-env yarn start:renderer", 15 | "start:main": "cross-env NODE_ENV=development electron -r ./.erb/scripts/BabelRegister ./src/main.dev.ts", 16 | "start:renderer": "cross-env NODE_ENV=development webpack serve --config ./.erb/configs/webpack.config.renderer.dev.babel.js", 17 | "test": "jest" 18 | }, 19 | "lint-staged": { 20 | "*.{js,jsx,ts,tsx}": [ 21 | "cross-env NODE_ENV=development eslint --cache" 22 | ], 23 | "{*.json,.{babelrc,eslintrc,prettierrc}}": [ 24 | "prettier --ignore-path .eslintignore --parser json --write" 25 | ], 26 | "*.{css,scss}": [ 27 | "prettier --ignore-path .eslintignore --single-quote --write" 28 | ], 29 | "*.{html,md,yml}": [ 30 | "prettier --ignore-path .eslintignore --single-quote --write" 31 | ] 32 | }, 33 | "build": { 34 | "productName": "ShellPiper", 35 | "appId": "org.TheYarin.ShellPiper", 36 | "files": [ 37 | "dist/", 38 | "node_modules/", 39 | "index.html", 40 | "main.prod.js", 41 | "main.prod.js.map", 42 | "package.json" 43 | ], 44 | "afterSign": ".erb/scripts/Notarize.js", 45 | "mac": { 46 | "target": [ 47 | "dmg" 48 | ], 49 | "type": "distribution", 50 | "hardenedRuntime": true, 51 | "entitlements": "assets/entitlements.mac.plist", 52 | "entitlementsInherit": "assets/entitlements.mac.plist", 53 | "gatekeeperAssess": false 54 | }, 55 | "dmg": { 56 | "contents": [ 57 | { 58 | "x": 130, 59 | "y": 220 60 | }, 61 | { 62 | "x": 410, 63 | "y": 220, 64 | "type": "link", 65 | "path": "/Applications" 66 | } 67 | ] 68 | }, 69 | "win": { 70 | "target": [ 71 | "nsis" 72 | ] 73 | }, 74 | "linux": { 75 | "target": [ 76 | "AppImage" 77 | ], 78 | "category": "Development" 79 | }, 80 | "directories": { 81 | "app": "src", 82 | "buildResources": "assets", 83 | "output": "release" 84 | }, 85 | "extraResources": [ 86 | "./assets/**" 87 | ], 88 | "publish": { 89 | "provider": "github", 90 | "owner": "TheYarin", 91 | "repo": "ShellPiper" 92 | } 93 | }, 94 | "repository": { 95 | "type": "git", 96 | "url": "git+https://github.com/TheYarin/ShellPiper.git" 97 | }, 98 | "author": { 99 | "name": "Yarin", 100 | "url": "https://github.com/TheYarin" 101 | }, 102 | "contributors": [], 103 | "bugs": { 104 | "url": "https://github.com/TheYarin/ShellPiper/issues" 105 | }, 106 | "keywords": [ 107 | "shellpiper", 108 | "shell", 109 | "piper", 110 | "pipe", 111 | "piping", 112 | "editor" 113 | ], 114 | "homepage": "https://github.com/TheYarin/ShellPiper", 115 | "jest": { 116 | "testURL": "http://localhost/", 117 | "moduleNameMapper": { 118 | "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "/.erb/mocks/fileMock.js", 119 | "\\.(css|less|sass|scss)$": "identity-obj-proxy" 120 | }, 121 | "moduleFileExtensions": [ 122 | "js", 123 | "jsx", 124 | "ts", 125 | "tsx", 126 | "json" 127 | ], 128 | "moduleDirectories": [ 129 | "node_modules", 130 | "src/node_modules" 131 | ], 132 | "setupFiles": [ 133 | "./.erb/scripts/CheckBuildsExist.js" 134 | ], 135 | "testPathIgnorePatterns": [ 136 | ".history" 137 | ] 138 | }, 139 | "devDependencies": { 140 | "@babel/core": "^7.12.9", 141 | "@babel/plugin-proposal-class-properties": "^7.12.1", 142 | "@babel/plugin-proposal-decorators": "^7.12.1", 143 | "@babel/plugin-proposal-do-expressions": "^7.12.1", 144 | "@babel/plugin-proposal-export-default-from": "^7.12.1", 145 | "@babel/plugin-proposal-export-namespace-from": "^7.12.1", 146 | "@babel/plugin-proposal-function-bind": "^7.12.1", 147 | "@babel/plugin-proposal-function-sent": "^7.12.1", 148 | "@babel/plugin-proposal-json-strings": "^7.12.1", 149 | "@babel/plugin-proposal-logical-assignment-operators": "^7.12.1", 150 | "@babel/plugin-proposal-nullish-coalescing-operator": "^7.12.1", 151 | "@babel/plugin-proposal-optional-chaining": "^7.12.7", 152 | "@babel/plugin-proposal-pipeline-operator": "^7.12.1", 153 | "@babel/plugin-proposal-throw-expressions": "^7.12.1", 154 | "@babel/plugin-syntax-dynamic-import": "^7.8.3", 155 | "@babel/plugin-syntax-import-meta": "^7.10.4", 156 | "@babel/plugin-transform-react-constant-elements": "^7.12.1", 157 | "@babel/plugin-transform-react-inline-elements": "^7.12.1", 158 | "@babel/plugin-transform-runtime": "^7.12.1", 159 | "@babel/preset-env": "^7.12.7", 160 | "@babel/preset-react": "^7.12.7", 161 | "@babel/preset-typescript": "^7.12.7", 162 | "@babel/register": "^7.12.1", 163 | "@pmmmwh/react-refresh-webpack-plugin": "^0.4.3", 164 | "@teamsupercell/typings-for-css-modules-loader": "^2.4.0", 165 | "@testing-library/jest-dom": "^5.11.6", 166 | "@testing-library/react": "^11.2.2", 167 | "@types/enzyme": "^3.10.5", 168 | "@types/enzyme-adapter-react-16": "^1.0.6", 169 | "@types/history": "4.7.6", 170 | "@types/jest": "^26.0.15", 171 | "@types/mousetrap": "^1.6.8", 172 | "@types/node": "14.14.10", 173 | "@types/react": "^16.9.44", 174 | "@types/react-dom": "^16.9.9", 175 | "@types/react-router-dom": "^5.1.6", 176 | "@types/react-test-renderer": "^16.9.3", 177 | "@types/webpack-env": "^1.15.2", 178 | "@typescript-eslint/eslint-plugin": "^4.8.1", 179 | "@typescript-eslint/parser": "^4.8.1", 180 | "babel-eslint": "^10.1.0", 181 | "babel-jest": "^26.1.0", 182 | "babel-loader": "^8.2.2", 183 | "babel-plugin-dev-expression": "^0.2.2", 184 | "babel-plugin-transform-react-remove-prop-types": "^0.4.24", 185 | "browserslist-config-erb": "^0.0.1", 186 | "chalk": "^4.1.0", 187 | "concurrently": "^5.3.0", 188 | "core-js": "^3.6.5", 189 | "cross-env": "^7.0.2", 190 | "css-loader": "^5.0.1", 191 | "css-minimizer-webpack-plugin": "^1.1.5", 192 | "detect-port": "^1.3.0", 193 | "electron": "^11.0.1", 194 | "electron-builder": "^22.3.6", 195 | "electron-devtools-installer": "^3.1.1", 196 | "electron-notarize": "^1.0.0", 197 | "electron-rebuild": "^2.3.2", 198 | "enzyme": "^3.11.0", 199 | "enzyme-adapter-react-16": "^1.15.3", 200 | "enzyme-to-json": "^3.5.0", 201 | "eslint": "^7.5.0", 202 | "eslint-config-airbnb": "^18.2.0", 203 | "eslint-config-airbnb-typescript": "^12.0.0", 204 | "eslint-config-erb": "^2.0.0", 205 | "eslint-config-prettier": "^6.11.0", 206 | "eslint-import-resolver-webpack": "^0.13.0", 207 | "eslint-plugin-compat": "^3.8.0", 208 | "eslint-plugin-import": "^2.22.0", 209 | "eslint-plugin-jest": "^24.1.3", 210 | "eslint-plugin-jsx-a11y": "6.4.1", 211 | "eslint-plugin-prettier": "^3.1.4", 212 | "eslint-plugin-promise": "^4.2.1", 213 | "eslint-plugin-react": "^7.20.6", 214 | "eslint-plugin-react-hooks": "^4.0.8", 215 | "file-loader": "^6.0.0", 216 | "husky": "^4.2.5", 217 | "identity-obj-proxy": "^3.0.0", 218 | "jest": "^26.1.0", 219 | "lint-staged": "^10.2.11", 220 | "mini-css-extract-plugin": "^1.3.1", 221 | "node-sass": "^5.0.0", 222 | "opencollective-postinstall": "^2.0.3", 223 | "prettier": "^2.0.5", 224 | "react-refresh": "^0.9.0", 225 | "react-test-renderer": "^17.0.1", 226 | "rimraf": "^3.0.0", 227 | "sass-loader": "^10.1.0", 228 | "style-loader": "^2.0.0", 229 | "terser-webpack-plugin": "^5.0.3", 230 | "typescript": "^4.0.5", 231 | "url-loader": "^4.1.0", 232 | "webpack": "^5.5.1", 233 | "webpack-bundle-analyzer": "^4.1.0", 234 | "webpack-cli": "^4.2.0", 235 | "webpack-dev-server": "^3.11.0", 236 | "webpack-merge": "^5.4.0", 237 | "yarn-deduplicate": "^3.1.0" 238 | }, 239 | "dependencies": { 240 | "@fontsource/roboto": "^4.2.2", 241 | "@material-ui/core": "^4.11.3", 242 | "@material-ui/icons": "^4.11.2", 243 | "@material-ui/lab": "^4.0.0-alpha.58", 244 | "clsx": "^1.1.1", 245 | "electron-debug": "^3.1.0", 246 | "electron-log": "^4.2.4", 247 | "electron-updater": "^4.3.4", 248 | "history": "^5.0.0", 249 | "mobx": "^6.1.8", 250 | "mobx-react": "^7.1.0", 251 | "mousetrap": "^1.6.5", 252 | "react": "^17.0.1", 253 | "react-dom": "^17.0.1", 254 | "react-resize-panel": "^0.3.5", 255 | "react-router-dom": "^5.2.0", 256 | "regenerator-runtime": "^0.13.5", 257 | "source-map-support": "^0.5.19", 258 | "tree-kill": "^1.2.2" 259 | }, 260 | "devEngines": { 261 | "node": ">=10.x", 262 | "npm": ">=6.x", 263 | "yarn": ">=1.21.3" 264 | }, 265 | "browserslist": [], 266 | "prettier": { 267 | "overrides": [ 268 | { 269 | "files": [ 270 | ".prettierrc", 271 | ".babelrc", 272 | ".eslintrc" 273 | ], 274 | "options": { 275 | "parser": "json" 276 | } 277 | } 278 | ] 279 | }, 280 | "renovate": { 281 | "extends": [ 282 | "bliss" 283 | ], 284 | "baseBranches": [ 285 | "next" 286 | ] 287 | }, 288 | "husky": { 289 | "hooks": { 290 | "pre-commit": "lint-staged" 291 | } 292 | } 293 | } 294 | -------------------------------------------------------------------------------- /src/Components/App/CommandsPanel/SingleCommandPanel.tsx: -------------------------------------------------------------------------------- 1 | import { TextField, makeStyles, IconButton, Tooltip, Paper, ThemeProvider, fade, lighten, Icon } from "@material-ui/core"; 2 | import { 3 | Error as ErrorIcon, 4 | Delete as DeleteIcon, 5 | Check as CheckIcon, 6 | PanToolOutlined, 7 | PanToolTwoTone, 8 | KeyboardArrowUpRounded as KeyboardArrowUpRoundedIcon, 9 | KeyboardArrowDownRounded as KeyboardArrowDownRoundedIcon, 10 | } from "@material-ui/icons"; 11 | import clsx from "clsx"; 12 | 13 | import { observer } from "mobx-react"; 14 | import React, { useEffect, useRef } from "react"; 15 | import Command from "../../../Command"; 16 | import CommandStatus from "../../../CommandStatus"; 17 | import { flexCol, lowProfileButtonColors, spaceChildren } from "../../../JssUtils"; 18 | import { piperStore } from "../../../PiperStore"; 19 | import CircularProgress from "../../Common/CircularProgress"; 20 | import MousetrapWrapper from "../../Common/MousetrapWrapper"; 21 | import { errorTheme } from "../../ThemeStuff/theme"; 22 | import CuteRightPointingButton from "./CuteRightPointingButton"; 23 | 24 | function confirmTheUserWantsToKillTheProcess() { 25 | return window.confirm("Are you sure you want to stop this running process?"); 26 | } 27 | 28 | const skipColor = "#6A9955"; 29 | const useStyles = makeStyles((theme) => ({ 30 | // commandAndOutputStuff: { 31 | // display: "flex", 32 | // flexDirection: "column", 33 | // flexGrow: 1, 34 | // }, 35 | container: { 36 | display: "flex", 37 | alignItems: "center", 38 | padding: 5, 39 | ...spaceChildren(5), 40 | }, 41 | removeButton: { 42 | // margin: 10, 43 | ...lowProfileButtonColors(theme), 44 | padding: 2, 45 | }, 46 | removeButtonDisabled: { 47 | color: "rgba(0, 0, 0, 0.15)", // To better contrast with the normal mode 48 | }, 49 | errorButton: { color: "red", padding: 0 }, 50 | stopCommandButton: { paddingRight: 16 }, // to make up for the thumb sticking out, feels unnatural 51 | commandStoppedButton: { color: lighten("#000", 0.55) }, 52 | colorRed: { 53 | color: "red", 54 | }, 55 | successfulExitAdornment: { color: "green" }, 56 | adornmentsContainer: { 57 | display: "flex", 58 | alignItems: "center", 59 | ...spaceChildren(5), 60 | }, 61 | outputButtons: { 62 | ...flexCol, 63 | justifyContent: "center", 64 | ...spaceChildren(6, "vertically"), 65 | }, 66 | textField: { 67 | flexGrow: 1, 68 | // fontFamily: 'monospace', 69 | }, 70 | outputButton: { height: 30, width: 67 }, 71 | buttonDimmedOutline: { 72 | border: "1px solid rgba(0, 0, 0, 0.15)", 73 | }, 74 | buttonOutlinedPrimaryEnhanced: { 75 | // Stolen and modified from material-ui's source code 76 | color: theme.palette.primary.main, 77 | // border: `1px solid ${lighten(theme.palette.primary.main, 0.25)}`, 78 | border: `1px solid ${theme.palette.primary.main}`, 79 | "&:hover": { 80 | border: `1px solid ${theme.palette.primary.main}`, 81 | backgroundColor: fade(theme.palette.primary.main, theme.palette.action.hoverOpacity), 82 | // Reset on touch devices, it doesn't add specificity 83 | "@media (hover: none)": { 84 | backgroundColor: "transparent", 85 | }, 86 | }, 87 | }, 88 | skipButton: { 89 | padding: 0, 90 | color: lighten("#000", 0.9), 91 | "&:hover": { 92 | color: lighten(skipColor, 0.5), 93 | cursor: "pointer", 94 | }, 95 | // transform: 'translateY(-1px)', 96 | marginLeft: -8, 97 | marginRight: 4, 98 | height: "unset", 99 | width: "unset", 100 | 101 | "&$disableChanges": { 102 | pointerEvents: "none", 103 | }, 104 | }, 105 | skipColor: { color: skipColor }, 106 | skipBackgroundColor: { backgroundColor: lighten("#000", 0.93) }, 107 | moveArrowsContainer: { ...flexCol }, 108 | moveArrow: { padding: 0, ...lowProfileButtonColors(theme) }, 109 | 110 | disableChanges: {}, 111 | })); 112 | 113 | const SingleCommandPanel = observer( 114 | ({ command, commandIndex, disableChanges }: { command: Command; commandIndex: number; disableChanges: boolean }) => { 115 | const cls = useStyles(); 116 | 117 | const inputRef = useRef(null); 118 | 119 | useEffect(() => command.setInputRef(inputRef)); // Wrapped in useEffect because inputRef.current is only guaranteed to not be null when the component is mounted 120 | 121 | const askKillRunningCommand = () => { 122 | if (!confirmTheUserWantsToKillTheProcess()) return; 123 | 124 | command.killIfProcessStillRunning("manual"); 125 | }; 126 | 127 | // #region figure out the endAdornment 128 | 129 | let endAdornments; 130 | 131 | if (command.skipThisCommand) endAdornments = ""; 132 | else if (command.status === CommandStatus.RUNNING) 133 | endAdornments = ( 134 | <> 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | ); 143 | else if (command.status === CommandStatus.ERROR) 144 | endAdornments = ( 145 | 146 | {command.stderr ? ( 147 | { 150 | piperStore.whatToDisplay = { 151 | commandId: command.id, 152 | outputType: "stderr", 153 | }; 154 | }} 155 | > 156 | 157 | 158 | ) : ( 159 | 160 | )} 161 | 162 | ); 163 | else if (command.killed) { 164 | let tooltipTitle: string; 165 | 166 | switch (command.status) { 167 | case CommandStatus.KILLED_MANUALLY: 168 | tooltipTitle = "You stopped this command."; 169 | break; 170 | case CommandStatus.KILLED_UNKNOWN_REASON: 171 | tooltipTitle = "This command was stopped for an unknown reason."; 172 | break; 173 | case CommandStatus.KILLED_NEXT_COMMAND_CLOSED: 174 | tooltipTitle = "This command was automatically stopped because the next command's stdin stream was closed."; 175 | break; 176 | 177 | default: 178 | throw new Error(`Unsupported kill status "${command.status}" is not supported.`); 179 | } 180 | 181 | endAdornments = ( 182 | 183 | 186 | 187 | ); 188 | } else if (command.status === CommandStatus.EXITED) 189 | endAdornments = ( 190 | 191 | 192 | 193 | ); 194 | 195 | // #endregion 196 | 197 | const askRemoveCommand = () => { 198 | if (command.status === CommandStatus.RUNNING) { 199 | if (confirmTheUserWantsToKillTheProcess()) command.killIfProcessStillRunning("manual"); 200 | else return; 201 | } 202 | 203 | piperStore.removeCommand(commandIndex); 204 | 205 | piperStore.commands[Math.min(commandIndex, piperStore.commands.indexOfLastItem())].focusOnThisCommandIfPossible(); 206 | }; 207 | 208 | const toggleSkip = () => { 209 | command.skipThisCommand = !command.skipThisCommand; 210 | }; 211 | 212 | let selectedButton: "stdout" | "stderr" | null = null; 213 | 214 | const { whatToDisplay } = piperStore; 215 | if (!whatToDisplay || whatToDisplay.commandId !== command.id) selectedButton = null; 216 | else selectedButton = whatToDisplay.outputType; 217 | 218 | const shouldDisableArrowUp = commandIndex === 0 || disableChanges; 219 | const shouldDisableArrowDown = commandIndex === piperStore.commands.indexOfLastItem() || disableChanges; 220 | const moveUp = () => piperStore.moveCommandOnePositionUp(commandIndex); 221 | const moveDown = () => piperStore.moveCommandOnePositionDown(commandIndex); 222 | const focusOnPreviousCommand = () => { 223 | if (commandIndex !== 0) piperStore.commands[commandIndex - 1].focusOnThisCommandIfPossible(); 224 | }; 225 | const focusOnNextCommand = () => { 226 | if (commandIndex !== piperStore.commands.indexOfLastItem()) 227 | piperStore.commands[commandIndex + 1].focusOnThisCommandIfPossible(); 228 | }; 229 | 230 | return ( 231 | 241 | { 245 | // For debugging 246 | if (e.ctrlKey) { 247 | (window as any).cmd = command; 248 | // eslint-disable-next-line no-console 249 | console.log(`Command #${commandIndex + 1}, "${command.commandText}" saved as "cmd": `, command); 250 | } 251 | }} 252 | > 253 | {/* = 262 | commandIndex 263 | } 264 | onClick={() => (piperStore.indexOfDesiredCacheToUse = commandIndex)} 265 | style={{ paddingLeft: 0 }} 266 | /> */} 267 | { 280 | command.commandText = e.target.value; 281 | }} 282 | inputProps={{ 283 | className: clsx(command.skipThisCommand && cls.skipColor), 284 | }} 285 | InputProps={{ 286 | className: clsx(command.skipThisCommand && cls.skipBackgroundColor), 287 | title: command.skipThisCommand ? "This command will be skipped" : "", 288 | startAdornment: ( 289 | 294 | # 295 | 296 | ), 297 | endAdornment:
{endAdornments}
, 298 | }} 299 | inputRef={inputRef} 300 | /> 301 |
302 | 309 | 310 | 311 | 318 | 319 | 320 |
321 | 328 | 329 | 330 |
331 | { 336 | piperStore.whatToDisplay = { 337 | commandId: command.id, 338 | outputType: "stdout", 339 | }; 340 | }} 341 | classes={ 342 | command.stdout ? { outlinedPrimary: cls.buttonOutlinedPrimaryEnhanced } : { outlined: cls.buttonDimmedOutline } 343 | } 344 | title="From the last run" 345 | > 346 | stdout 347 | 348 | 349 | { 354 | piperStore.whatToDisplay = { 355 | commandId: command.id, 356 | outputType: "stderr", 357 | }; 358 | }} 359 | classes={command.stderr ? {} : { outlined: cls.buttonDimmedOutline }} 360 | title="From the last run" 361 | > 362 | stderr 363 | 364 | 365 |
366 |
367 |
368 | ); 369 | } 370 | ); 371 | 372 | export default SingleCommandPanel; 373 | -------------------------------------------------------------------------------- /src/PiperStore.ts: -------------------------------------------------------------------------------- 1 | import { makeAutoObservable } from "mobx"; 2 | // eslint-disable-next-line import/no-cycle 3 | import Command from "./Command"; 4 | import CommandStatus from "./CommandStatus"; 5 | import { yieldPairs } from "./utils"; 6 | 7 | export class PiperStore { 8 | // shellProgram: string; 9 | 10 | // #region workingDirectory 11 | 12 | private _workingDirectory?: string; 13 | 14 | public get workingDirectory(): string | undefined { 15 | return this._workingDirectory; 16 | } 17 | 18 | public set workingDirectory(v: string | undefined) { 19 | this._workingDirectory = v; 20 | } 21 | 22 | // #endregion 23 | 24 | // #region shellProgram 25 | 26 | private _shellProgram?: string; 27 | 28 | public get shellProgram(): string | undefined { 29 | return this._shellProgram; 30 | } 31 | 32 | public set shellProgram(v: string | undefined) { 33 | this._shellProgram = v; 34 | } 35 | 36 | // #endregion 37 | 38 | // #region killPredecessorOnClose 39 | 40 | private _killPredecessorOnClose?: boolean = false; 41 | 42 | public get killPredecessorOnClose(): boolean | undefined { 43 | return this._killPredecessorOnClose; 44 | } 45 | 46 | public set killPredecessorOnClose(v: boolean | undefined) { 47 | this._killPredecessorOnClose = v; 48 | } 49 | 50 | // #endregion 51 | 52 | // #region pathEnvVar 53 | 54 | private _pathEnvVar?: string; 55 | 56 | public get pathEnvVar(): string | undefined { 57 | return this._pathEnvVar; 58 | } 59 | 60 | public set pathEnvVar(v: string | undefined) { 61 | this._pathEnvVar = v; 62 | } 63 | 64 | // #endregion 65 | 66 | public commands: Command[] = [new Command(this)]; 67 | 68 | // #region WhatToDisplay stuff 69 | 70 | private _whatToDisplay: { commandId: string; outputType: "stdout" | "stderr" } | undefined; 71 | 72 | public get whatToDisplay(): { commandId: string; outputType: "stdout" | "stderr" } | undefined { 73 | return this._whatToDisplay; 74 | } 75 | 76 | public set whatToDisplay(v: { commandId: string; outputType: "stdout" | "stderr" } | undefined) { 77 | this._whatToDisplay = v; 78 | } 79 | 80 | clearWhatToDisplay() { 81 | this.whatToDisplay = undefined; 82 | } 83 | 84 | // #endregion 85 | 86 | constructor() { 87 | makeAutoObservable(this); 88 | } 89 | 90 | get areCommandsValidToRun(): boolean { 91 | const commandsExcludingSkippedOnes = this.commands.filter((cmd) => !cmd.skipThisCommand); 92 | 93 | return commandsExcludingSkippedOnes.length > 0 && commandsExcludingSkippedOnes.every((cmd) => cmd.commandText !== ""); 94 | } 95 | 96 | get isAnythingRunning(): boolean { 97 | return this.commands.length > 0 && this.commands.some((cmd) => cmd.status === CommandStatus.RUNNING); 98 | } 99 | 100 | /** 101 | * @throws {Error} if any of the commands are still running. 102 | */ 103 | removeAllCommands(): void { 104 | if (this.isAnythingRunning) throw new Error("Can't remove all commands while some of them are still running."); 105 | 106 | this.clearWhatToDisplay(); 107 | 108 | this.commands = [new Command(this)]; 109 | } 110 | 111 | insertNewCommand(index: number): void { 112 | if (!(this.commands.isEmpty() && index === 0) && !(0 <= index && index <= this.commands.indexOfLastItem() + 1)) 113 | throw new Error("Invalid index supplied"); 114 | 115 | const newCommand = new Command(this); 116 | this.commands.insert(index, newCommand); 117 | } 118 | 119 | removeCommand(index: number): void { 120 | this.validateExistingIndex(index); 121 | 122 | const commandToRemove = this.commands[index]; 123 | 124 | if (this.whatToDisplay?.commandId === commandToRemove.id) this.clearWhatToDisplay(); 125 | 126 | this.commands.removeByIndex(index); 127 | 128 | // There commands list should never be empty (for user experience reasons) 129 | if (this.commands.isEmpty()) this.insertNewCommand(0); 130 | } 131 | 132 | moveCommandOnePositionUp(index: number): void { 133 | // Validate index 134 | if (index === 0) return; // Already at the top, no need to move. 135 | 136 | if (!(0 < index && index <= this.commands.indexOfLastItem())) throw new Error("Invalid index supplied"); 137 | 138 | const commandToMove = this.commands[index]; 139 | this.commands.removeByIndex(index); 140 | this.commands.insert(index - 1, commandToMove); 141 | } 142 | 143 | moveCommandOnePositionDown(index: number): void { 144 | // Validate index 145 | if (index === this.commands.indexOfLastItem()) return; // Already at the bottom, no need to move. 146 | 147 | if (!(0 <= index && index < this.commands.indexOfLastItem())) throw new Error("Invalid index supplied"); 148 | 149 | const commandToMove = this.commands[index]; 150 | this.commands.removeByIndex(index); 151 | this.commands.insert(index + 1, commandToMove); 152 | } 153 | 154 | // setShouldCache = (commandIndex: number, newValue: boolean) => { 155 | // this.validateExistingIndex(commandIndex); 156 | 157 | // this.commands.forEach((currentCommand, currentIndex) => { 158 | // if (currentIndex <= commandIndex && newValue === true) 159 | // currentCommand._shouldCache = true; 160 | // else if (currentIndex >= commandIndex && newValue === false) 161 | // currentCommand._shouldCache = false; 162 | // }); 163 | // }; 164 | 165 | async runCommands(): Promise { 166 | let commandsToRun: Command[]; 167 | 168 | let precedingCommandsOfFirstCommandToRun: string[]; 169 | let cacheToPassToFirstCommandToRun: string | undefined; 170 | 171 | const handleStdinError = (error: Error & { code: string; errno: string; syscall: string }, targetCommandName: string) => { 172 | if (error.code === "EPIPE" || error.code === "EOF") { 173 | // This happens when a write operation takes place after the writable stream (next command's stdin) is closed. Just ignore it. 174 | } else console.warn(`Error caught when passing output to the command "${targetCommandName}"`, { error, name: error.name }); 175 | }; 176 | 177 | const { indexOfCacheToUse } = this; // Extracted for use in lambda 178 | 179 | if (this.shouldUseCache && indexOfCacheToUse !== null) { 180 | if (this.indexOfCacheToUse === this.indexOfLastCommandThatIsntMarkedForSkip) { 181 | // eslint-disable-next-line no-console 182 | console.log("All commands already cached, no need to run, right?"); 183 | return; 184 | } 185 | 186 | const [commandsAfterCache, _cachedCommands] = this.commands.splitByPredicate( 187 | (_cmd, cmdIndex) => cmdIndex > indexOfCacheToUse 188 | ); 189 | 190 | commandsToRun = commandsAfterCache.filter((cmd) => !cmd.skipThisCommand); 191 | 192 | const cachedCommandToStartFrom = this.commands[indexOfCacheToUse]; 193 | 194 | // Just an assertion 195 | if (cachedCommandToStartFrom.skipThisCommand) 196 | throw new Error( 197 | "Tried to use the cache of a command marked for skipping. This is a bug, please report it to the developer." 198 | ); 199 | 200 | if (cachedCommandToStartFrom.precedingCommandsOnLastRun === null) 201 | throw new Error( 202 | "This command was run already, it's preceding commands list shouldn't be null. This is a bug, please report it to the developer." 203 | ); 204 | 205 | precedingCommandsOfFirstCommandToRun = [ 206 | ...cachedCommandToStartFrom.precedingCommandsOnLastRun, 207 | cachedCommandToStartFrom.commandText, 208 | ]; 209 | cacheToPassToFirstCommandToRun = cachedCommandToStartFrom.stdout; 210 | 211 | // console.log(`used cached output of command #${indexOfCacheToUse + 1}: ${cachedCommandToStartFrom.commandText}`); 212 | } else { 213 | commandsToRun = this.commands.filter((cmd) => !cmd.skipThisCommand); 214 | precedingCommandsOfFirstCommandToRun = []; 215 | } 216 | 217 | const firstCommandToRun = commandsToRun[0]; 218 | 219 | try { 220 | firstCommandToRun.startCommandAndRecordOutput(precedingCommandsOfFirstCommandToRun); 221 | } catch (e) { 222 | return; 223 | } 224 | 225 | if (cacheToPassToFirstCommandToRun) { 226 | // #region The shit I had to go through to capture errors that occur when writing to a process's stdin. 227 | // async function safelyWriteCacheToFirstCommandStdinAndEndTheStream( 228 | // stdin: Writable, 229 | // data: string 230 | // ) { 231 | // /** 232 | // * Simply calling `stdin.write(data)` can throw an uncatchable error if the stdin is closed in the middle of a long write operation. 233 | // * Failed attempts: 234 | // * - Checking the `stdin.destroyed` flag before writing 235 | // * - Checking the `stdin.writeableEnded` flag before writing 236 | // * - Chunking the input and checking `stdin.writeableEnded` before each chunk. This one lead to undeterministic behavior. 237 | // * - Wrapping the `stdin.write(data)` line with try-catch 238 | // * - Pass `stdin.write()` a callback that should get any error that occurs. The callback got the error, but didn't prevent it from being thrown. 239 | // * - Calling `stdin.end(data)` instead of `stdin.write(data)` 240 | // */ 241 | 242 | // // Register an awaitable callback that will capture any error occuring during the write operation 243 | // const promise = new Promise((resolve, _reject) => { 244 | // // Using once() and not on() to remove the listener after the first catch. 245 | // stdin.once('error', (error) => resolve(error)); 246 | 247 | // // stdin.end(data, callback) can probably be used here, but I keep the `write()` just in case `end()`'s callback is called before the 'error' event, since the docs are not clear about that. (docs say: "The callback is invoked before 'finish' or on error." for node version 15.0.0. Is "on error" how node people say "after error"? idk.) 248 | // stdin.write( 249 | // data, 250 | // (error) => { 251 | // if (!error) resolve(null); // The condition is necessary because when an error occurs, the callback is called before the 'error' event handler 252 | // } // Signal the promise to complete when the write operation is complete with no errors. I don't simply use this `error` parameter because the exception will still be thrown if I don't listen to the 'error' event, and the docs say: "If an error occurs, the callback may or may not be called with the error as its first argument. To reliably detect write errors, add a listener for the 'error' event.". If not resolved, the following `await promise` call will never finish if no error was thrown. 253 | // ); 254 | // }); 255 | 256 | // const maybeError = await promise; // Should be null if no error was thrown. 257 | 258 | // if (!maybeError) stdin.end(); 259 | // } 260 | 261 | // if (firstCommandToRun.process?.stdin && lastCachedCommand.stdout) 262 | // await safelyWriteCacheToFirstCommandStdinAndEndTheStream( 263 | // firstCommandToRun.process.stdin, 264 | // lastCachedCommand.stdout 265 | // ); 266 | // #endregion 267 | firstCommandToRun.process?.stdin?.on("error", (error: Error & { code: string; errno: string; syscall: string }) => 268 | handleStdinError(error, firstCommandToRun.commandText) 269 | ); 270 | process.nextTick(() => firstCommandToRun.process?.stdin?.end(cacheToPassToFirstCommandToRun)); // If I don't wrap it with `nextTick()`, the call to `end()` doesn't properly trigger the "finish" behavior of stdin on Ubuntu. Unfortunately I couldn't reproduce this issue in a unit test, nor in a nodejs interpreter. It feels like a bug, but I couldn't narrow it down to child_process/WritableStream/nodejs/electron. 271 | } 272 | 273 | let lastCommandRun = firstCommandToRun; 274 | 275 | for (const [currentCommand, nextCommand] of yieldPairs(commandsToRun)) { 276 | nextCommand.startCommandAndRecordOutput([...(currentCommand.precedingCommandsOnLastRun ?? []), currentCommand.commandText]); 277 | 278 | lastCommandRun = nextCommand; 279 | 280 | if (!(currentCommand.process?.stdout && nextCommand.process?.stdin)) throw new Error("Something went wrong"); 281 | 282 | // #region Doing the following because calling currentCommand.process.stdout.pipe(nextCommand.process.stdin) might throw "Cannot call write after a stream was destroyed" 283 | const pipeToNextCommand = (chunk: any) => { 284 | if (!nextCommand.process?.stdin?.destroyed) 285 | // This condition is not necessary since the error will be caught somewhere else but it saves the log some unnecessary warnings. 286 | nextCommand.process?.stdin?.write(chunk); 287 | }; 288 | nextCommand.process.stdin.on("close", () => { 289 | currentCommand.process?.stdout?.removeListener("data", pipeToNextCommand); 290 | 291 | if (this.killPredecessorOnClose) { 292 | // Kill the preceding process, to mimick the behavior of the shell's pipe operation. This also saves unnecessary run time of preceding commands. 293 | currentCommand.killIfProcessStillRunning("next-command-closed", "SIGPIPE"); // Technically signals don't work on Windows but the underlying 'kill-tree' package simply ignores the signal given if it's running on Windows. Git Bash somehow manages to pass SIGPIPE, I don't know how.} 294 | } 295 | }); 296 | 297 | nextCommand.process.stdin.on("error", (error: Error & { code: string; errno: string; syscall: string }) => 298 | handleStdinError(error, nextCommand.commandText) 299 | ); 300 | 301 | currentCommand.process.stdout.on("data", pipeToNextCommand); 302 | 303 | currentCommand.process.stdout.on("close", () => { 304 | nextCommand.process?.stdin?.end(); 305 | }); 306 | // #endregion 307 | } 308 | 309 | this.whatToDisplay = { commandId: lastCommandRun.id, outputType: "stdout" }; 310 | } 311 | 312 | // #region Cache stuff 313 | 314 | private _shouldUseCache = false; 315 | 316 | public get shouldUseCache(): boolean { 317 | return this._shouldUseCache; 318 | } 319 | 320 | public set shouldUseCache(v: boolean) { 321 | this._shouldUseCache = v; 322 | } 323 | 324 | private _indexOfDesiredCacheToUse = 0; 325 | 326 | public get indexOfDesiredCacheToUse(): number { 327 | return this._indexOfDesiredCacheToUse; 328 | } 329 | 330 | public set indexOfDesiredCacheToUse(v: number) { 331 | this._indexOfDesiredCacheToUse = v; 332 | } 333 | 334 | /** @returns {null} if no cache is available or if there are no commands (which should never happen, remember?) */ 335 | public get indexOfLastCommandWithValidCache(): number | null { 336 | return this.commands.findLastIndex((cmd) => cmd.isValidCacheAvailable && !cmd.skipThisCommand); 337 | 338 | /* for (let i = this.commands.indexOfLastItem(); i >= 0; i--) { 339 | const command = this.commands[i]; 340 | 341 | if (command.isValidCacheAvailable) return i; 342 | } 343 | 344 | return null; */ 345 | 346 | // const [_, skippedCount] = this.commands.skip( 347 | // (cmd) => cmd.isValidCacheAvailable 348 | // ); 349 | 350 | // if (skippedCount === 0) return null; 351 | 352 | // return skippedCount - 1; 353 | } 354 | 355 | /** @returns {null} if no cache is available */ 356 | public get indexOfCacheToUse() { 357 | if (this.indexOfLastCommandWithValidCache === null) return null; 358 | 359 | return this.commands.findLastIndex( 360 | (cmd, index) => index <= this.indexOfDesiredCacheToUse && cmd.isValidCacheAvailable && !cmd.skipThisCommand 361 | ); 362 | } 363 | 364 | public get everythingIsCachedNoNeedToRun() { 365 | return this.shouldUseCache && this.indexOfCacheToUse === this.indexOfLastCommandThatIsntMarkedForSkip; 366 | } 367 | 368 | // #endregion 369 | 370 | public getCommandById(id: string): Command { 371 | const commandFound = this.commands.find((cmd) => cmd.id === id); 372 | 373 | if (!commandFound) throw new Error(`The command id "${id}" could not be found in the piperStore.`); 374 | 375 | return commandFound; 376 | } 377 | 378 | public getCommandsThatAreGoingToRunBeforeTheGivenCommand(givenCommandId: string): string[] { 379 | const result = []; 380 | 381 | for (const command of this.commands.filter((cmd) => !cmd.skipThisCommand)) { 382 | if (command.id === givenCommandId) break; 383 | else result.push(command.commandText); 384 | } 385 | 386 | return result; 387 | } 388 | 389 | /** 390 | * @throws {Error} if index is invalid 391 | */ 392 | private validateExistingIndex(index: number) { 393 | if (!(0 <= index && index <= this.commands.indexOfLastItem())) throw new Error("Invalid index supplied"); 394 | } 395 | 396 | private get indexOfLastCommandThatIsntMarkedForSkip() { 397 | return this.commands.findLastIndex((cmd) => !cmd.skipThisCommand); 398 | } 399 | } 400 | 401 | export const piperStore = new PiperStore(); 402 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------