terminal: Added eval command

This commit is contained in:
Prozilla 2024-07-23 11:41:36 +02:00
parent 95048d1212
commit 6f7043d547
No known key found for this signature in database
GPG key ID: 5858DFE71CAF31EE
7 changed files with 44 additions and 5 deletions

View file

@ -1,5 +1,11 @@
# @prozilla-os/terminal # @prozilla-os/terminal
## 1.1.1
### Patch Changes
- Added eval command
## 1.1.0 ## 1.1.0
### Minor Changes ### Minor Changes

View file

@ -1,7 +1,7 @@
{ {
"name": "@prozilla-os/terminal", "name": "@prozilla-os/terminal",
"description": "A terminal/shell application for ProzillaOS.", "description": "A terminal/shell application for ProzillaOS.",
"version": "1.1.0", "version": "1.1.1",
"homepage": "https://os.prozilla.dev/terminal", "homepage": "https://os.prozilla.dev/terminal",
"author": { "author": {
"name": "Prozilla", "name": "Prozilla",

View file

@ -142,7 +142,7 @@ export function Terminal({ app, path: startPath, input, setTitle, close: exit, a
if (value === "") return; if (value === "") return;
// Parse arguments // Parse arguments
const args = value.match(/(?:[^\s"]+|"[^"]*")+/g); let args: string[] | null = value.match(/(?:[^\s"]+|"[^"]*")+/g);
if (args == null) return; if (args == null) return;
if (args[0].toLowerCase() === "sudo" && args.length >= 2) args.shift(); if (args[0].toLowerCase() === "sudo" && args.length >= 2) args.shift();
@ -153,6 +153,13 @@ export function Terminal({ app, path: startPath, input, setTitle, close: exit, a
if (!command) return formatError(commandName, "Command not found"); if (!command) return formatError(commandName, "Command not found");
args = args.map((arg) => {
if (arg.startsWith("\"") && arg.endsWith("\""))
return arg.slice(1, -1);
return arg;
});
// Get options // Get options
const options: string[] = []; const options: string[] = [];
const inputs: Record<string, string> = {}; const inputs: Record<string, string> = {};

View file

@ -0,0 +1,18 @@
import { Command, CommandResponse } from "../command";
const evalCommand = new Command()
.setRequireArgs(true)
.setManual({
purpose: "Evaluate and execute JavaScript code",
usage: "eval [input]",
})
.setRequireArgs(true)
.setExecute(function(this: Command, args) {
if (args == null || args.length == 0)
return;
const output = eval(args[0]) as CommandResponse ?? { blank: true };
return output;
});
export { evalCommand as eval };

View file

@ -54,6 +54,7 @@ function generateAliases() {
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig(({ command }) => { export default defineConfig(({ command }) => {
const devMode = command == "serve"; const devMode = command == "serve";
const aliases = generateAliases();
return { return {
base: "/", base: "/",
@ -67,13 +68,13 @@ export default defineConfig(({ command }) => {
outDir: BUILD_DIR outDir: BUILD_DIR
}, },
resolve: { resolve: {
alias: devMode ? generateAliases() : {}, alias: devMode ? aliases : {},
}, },
server: { server: {
port: 3000, port: 3000,
}, },
optimizeDeps: { optimizeDeps: {
exclude: devMode ? ["prozilla-os"] : [] exclude: devMode ? Object.keys(aliases) : []
} }
}; };
}); });

View file

@ -1,5 +1,12 @@
# prozilla-os # prozilla-os
## 1.2.1
### Patch Changes
- Updated dependencies
- @prozilla-os/terminal@1.1.1
## 1.2.0 ## 1.2.0
### Minor Changes ### Minor Changes

View file

@ -1,7 +1,7 @@
{ {
"name": "prozilla-os", "name": "prozilla-os",
"description": "a React component library written in TypeScript for building web-based operating systems, made by Prozilla.", "description": "a React component library written in TypeScript for building web-based operating systems, made by Prozilla.",
"version": "1.2.0", "version": "1.2.1",
"homepage": "https://os.prozilla.dev", "homepage": "https://os.prozilla.dev",
"author": { "author": {
"name": "Prozilla", "name": "Prozilla",