gritty 9.0.4 → 10.0.1
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 +3075 -4373
- package/dist/gritty.js.map +1 -1
- package/dist-dev/gritty.js +168 -168
- package/package.json +6 -3
- package/server/gritty.js +46 -28
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gritty",
|
|
3
|
-
"version": "
|
|
4
|
-
"type": "
|
|
3
|
+
"version": "10.0.1",
|
|
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,9 @@ const choose = (a, b, options) => {
|
|
|
40
44
|
return options.default;
|
|
41
45
|
};
|
|
42
46
|
|
|
43
|
-
|
|
47
|
+
export default gritty;
|
|
48
|
+
|
|
49
|
+
export function gritty(options = {}) {
|
|
44
50
|
const router = Router();
|
|
45
51
|
const {prefix = '/gritty'} = options;
|
|
46
52
|
|
|
@@ -65,14 +71,21 @@ function _terminalFn(options, req, res, next) {
|
|
|
65
71
|
|
|
66
72
|
function staticFn(req, res) {
|
|
67
73
|
const file = path.normalize(DIR_ROOT + req.url);
|
|
74
|
+
|
|
68
75
|
res.sendFile(file, {
|
|
69
76
|
dotfiles: 'allow',
|
|
70
77
|
});
|
|
71
78
|
}
|
|
72
79
|
|
|
73
|
-
function createTerminal(
|
|
74
|
-
|
|
75
|
-
|
|
80
|
+
function createTerminal(overrides = {}) {
|
|
81
|
+
const {
|
|
82
|
+
command,
|
|
83
|
+
env,
|
|
84
|
+
cwd,
|
|
85
|
+
cols = 80,
|
|
86
|
+
rows = 24,
|
|
87
|
+
pty = _pty,
|
|
88
|
+
} = overrides;
|
|
76
89
|
|
|
77
90
|
const [cmd, ...args] = stringArgv(command);
|
|
78
91
|
const term = pty.spawn(cmd, args, {
|
|
@@ -91,7 +104,7 @@ function createTerminal({command, env, cwd, cols, rows, pty = _pty}) {
|
|
|
91
104
|
return term;
|
|
92
105
|
}
|
|
93
106
|
|
|
94
|
-
|
|
107
|
+
gritty.listen = (socket, options = {}) => {
|
|
95
108
|
check(socket, options);
|
|
96
109
|
|
|
97
110
|
const {prefix, auth} = options;
|
|
@@ -129,7 +142,10 @@ function connection(options, socket) {
|
|
|
129
142
|
const onResize = (size) => {
|
|
130
143
|
size = size || {};
|
|
131
144
|
|
|
132
|
-
const {
|
|
145
|
+
const {
|
|
146
|
+
cols = 80,
|
|
147
|
+
rows = 25,
|
|
148
|
+
} = size;
|
|
133
149
|
|
|
134
150
|
term.resize(cols, rows);
|
|
135
151
|
log(`Resized terminal ${term.pid} to ${cols} cols and ${rows} rows.`);
|
|
@@ -139,18 +155,20 @@ function connection(options, socket) {
|
|
|
139
155
|
term.write(msg);
|
|
140
156
|
};
|
|
141
157
|
|
|
142
|
-
function onTerminal(
|
|
143
|
-
params = params || {};
|
|
158
|
+
function onTerminal(overrides = {}) {
|
|
144
159
|
const {
|
|
145
160
|
env,
|
|
146
161
|
rows,
|
|
147
162
|
cols,
|
|
148
163
|
cwd,
|
|
149
|
-
|
|
164
|
+
platform,
|
|
165
|
+
} = overrides;
|
|
150
166
|
|
|
151
|
-
const command =
|
|
167
|
+
const command = overrides.command || options.command || getCMD({
|
|
168
|
+
platform,
|
|
169
|
+
});
|
|
152
170
|
|
|
153
|
-
const autoRestart = choose(
|
|
171
|
+
const autoRestart = choose(overrides.autoRestart, options.autoRestart, {
|
|
154
172
|
default: true,
|
|
155
173
|
});
|
|
156
174
|
|