gritty 9.0.3 → 10.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ChangeLog +11 -0
- package/README.md +5 -5
- package/bin/gritty.js +21 -16
- package/dist/gritty.js +3200 -4485
- package/dist/gritty.js.map +1 -1
- package/dist-dev/gritty.js +168 -168
- package/package.json +6 -3
- package/server/gritty.js +44 -28
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gritty",
|
|
3
|
-
"version": "
|
|
4
|
-
"type": "
|
|
3
|
+
"version": "10.0.0",
|
|
4
|
+
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "Web terminal emulator",
|
|
7
7
|
"bin": {
|
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
"type": "git",
|
|
13
13
|
"url": "git+https://github.com/cloudcmd/gritty.git"
|
|
14
14
|
},
|
|
15
|
+
"imports": {
|
|
16
|
+
"#gritty/client": "./client/gritty.js",
|
|
17
|
+
"#gritty/server": "./server/gritty.js"
|
|
18
|
+
},
|
|
15
19
|
"scripts": {
|
|
16
20
|
"start": "madrun start",
|
|
17
21
|
"start:dev": "madrun start:dev",
|
|
@@ -72,7 +76,6 @@
|
|
|
72
76
|
"eslint-plugin-putout": "^30.0.2",
|
|
73
77
|
"json-loader": "^0.5.4",
|
|
74
78
|
"madrun": "^12.1.0",
|
|
75
|
-
"mock-require": "^3.0.2",
|
|
76
79
|
"nodemon": "^3.0.1",
|
|
77
80
|
"optimize-css-assets-webpack-plugin": "^6.0.1",
|
|
78
81
|
"putout": "^41.0.8",
|
package/server/gritty.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
const stringArgv = require('string-to-argv');
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import path, {dirname} from 'node:path';
|
|
3
|
+
import {fileURLToPath} from 'node:url';
|
|
4
|
+
import debug from 'debug';
|
|
5
|
+
import Router from 'router';
|
|
6
|
+
import currify from 'currify';
|
|
7
|
+
import wraptile from 'wraptile';
|
|
8
|
+
import _pty from 'node-pty';
|
|
9
|
+
import stringArgv from 'string-to-argv';
|
|
10
|
+
|
|
11
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
12
|
+
const __dirname = dirname(__filename);
|
|
13
|
+
const log = debug('gritty');
|
|
15
14
|
const isFn = (a) => typeof a === 'function';
|
|
16
15
|
const isBool = (a) => typeof a === 'boolean';
|
|
17
16
|
|
|
@@ -20,11 +19,16 @@ const DIR_ROOT = `${__dirname}/..`;
|
|
|
20
19
|
const terminalFn = currify(_terminalFn);
|
|
21
20
|
const connectionWraped = wraptile(connection);
|
|
22
21
|
|
|
23
|
-
const
|
|
24
|
-
const
|
|
22
|
+
const getCMD = (overrides = {}) => {
|
|
23
|
+
const {platform = process.platform} = overrides;
|
|
24
|
+
|
|
25
|
+
return platform === 'win32' ? 'cmd.exe' : 'bash';
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const isDev = () => process.env.NODE_ENV === 'development';
|
|
25
29
|
|
|
26
30
|
const getDist = () => {
|
|
27
|
-
if (isDev)
|
|
31
|
+
if (isDev())
|
|
28
32
|
return '/dist-dev';
|
|
29
33
|
|
|
30
34
|
return '/dist';
|
|
@@ -40,7 +44,7 @@ const choose = (a, b, options) => {
|
|
|
40
44
|
return options.default;
|
|
41
45
|
};
|
|
42
46
|
|
|
43
|
-
|
|
47
|
+
export const gritty = (options = {}) => {
|
|
44
48
|
const router = Router();
|
|
45
49
|
const {prefix = '/gritty'} = options;
|
|
46
50
|
|
|
@@ -65,14 +69,21 @@ function _terminalFn(options, req, res, next) {
|
|
|
65
69
|
|
|
66
70
|
function staticFn(req, res) {
|
|
67
71
|
const file = path.normalize(DIR_ROOT + req.url);
|
|
72
|
+
|
|
68
73
|
res.sendFile(file, {
|
|
69
74
|
dotfiles: 'allow',
|
|
70
75
|
});
|
|
71
76
|
}
|
|
72
77
|
|
|
73
|
-
function createTerminal(
|
|
74
|
-
|
|
75
|
-
|
|
78
|
+
function createTerminal(overrides = {}) {
|
|
79
|
+
const {
|
|
80
|
+
command,
|
|
81
|
+
env,
|
|
82
|
+
cwd,
|
|
83
|
+
cols = 80,
|
|
84
|
+
rows = 24,
|
|
85
|
+
pty = _pty,
|
|
86
|
+
} = overrides;
|
|
76
87
|
|
|
77
88
|
const [cmd, ...args] = stringArgv(command);
|
|
78
89
|
const term = pty.spawn(cmd, args, {
|
|
@@ -91,7 +102,7 @@ function createTerminal({command, env, cwd, cols, rows, pty = _pty}) {
|
|
|
91
102
|
return term;
|
|
92
103
|
}
|
|
93
104
|
|
|
94
|
-
|
|
105
|
+
gritty.listen = (socket, options = {}) => {
|
|
95
106
|
check(socket, options);
|
|
96
107
|
|
|
97
108
|
const {prefix, auth} = options;
|
|
@@ -129,7 +140,10 @@ function connection(options, socket) {
|
|
|
129
140
|
const onResize = (size) => {
|
|
130
141
|
size = size || {};
|
|
131
142
|
|
|
132
|
-
const {
|
|
143
|
+
const {
|
|
144
|
+
cols = 80,
|
|
145
|
+
rows = 25,
|
|
146
|
+
} = size;
|
|
133
147
|
|
|
134
148
|
term.resize(cols, rows);
|
|
135
149
|
log(`Resized terminal ${term.pid} to ${cols} cols and ${rows} rows.`);
|
|
@@ -139,18 +153,20 @@ function connection(options, socket) {
|
|
|
139
153
|
term.write(msg);
|
|
140
154
|
};
|
|
141
155
|
|
|
142
|
-
function onTerminal(
|
|
143
|
-
params = params || {};
|
|
156
|
+
function onTerminal(overrides = {}) {
|
|
144
157
|
const {
|
|
145
158
|
env,
|
|
146
159
|
rows,
|
|
147
160
|
cols,
|
|
148
161
|
cwd,
|
|
149
|
-
|
|
162
|
+
platform,
|
|
163
|
+
} = overrides;
|
|
150
164
|
|
|
151
|
-
const command =
|
|
165
|
+
const command = overrides.command || options.command || getCMD({
|
|
166
|
+
platform,
|
|
167
|
+
});
|
|
152
168
|
|
|
153
|
-
const autoRestart = choose(
|
|
169
|
+
const autoRestart = choose(overrides.autoRestart, options.autoRestart, {
|
|
154
170
|
default: true,
|
|
155
171
|
});
|
|
156
172
|
|