creepercli 1.0.0 → 1.1.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/src/session.js CHANGED
@@ -1,58 +1,40 @@
1
- /*
2
- * Copyright 2026 DemonZDevelopment
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
-
17
- 'use strict';
18
-
19
- const fs = require('fs');
20
- const os = require('os');
21
- const path = require('path');
22
-
23
- const DIR = path.join(os.homedir(), '.creepercli');
24
- const CREDS_FILE = path.join(DIR, 'creds');
25
- const HISTORY_FILE = path.join(DIR, 'history');
26
-
27
- function ensureDir() {
28
- fs.mkdirSync(DIR, { recursive: true, mode: 0o700 });
29
- }
30
-
31
- function save(creds) {
32
- ensureDir();
33
- fs.writeFileSync(CREDS_FILE, JSON.stringify(creds, null, 2), { mode: 0o600 });
34
- }
35
-
36
- function load(host, port) {
37
- try {
38
- const raw = fs.readFileSync(CREDS_FILE, 'utf8');
39
- const creds = JSON.parse(raw);
40
- if (creds.host !== host || creds.port !== port) return null;
41
- if (creds.expiresAt && Date.now() > creds.expiresAt) {
42
- clear();
43
- return null;
44
- }
45
- return creds;
46
- } catch {
47
- return null;
48
- }
49
- }
50
-
51
- function clear() {
52
- try {
53
- fs.unlinkSync(CREDS_FILE);
54
- } catch {
55
- }
56
- }
57
-
58
- module.exports = { DIR, CREDS_FILE, HISTORY_FILE, save, load, clear };
1
+
2
+
3
+ 'use strict';
4
+
5
+ const fs = require('fs');
6
+ const os = require('os');
7
+ const path = require('path');
8
+
9
+ const DIR = path.join(os.homedir(), '.creepercli');
10
+ const CREDS_FILE = path.join(DIR, 'creds');
11
+ const HISTORY_FILE = path.join(DIR, 'history');
12
+
13
+ function ensureDir() {
14
+ fs.mkdirSync(DIR, { recursive: true, mode: 0o700 });
15
+ }
16
+
17
+ function save(creds) {
18
+ ensureDir();
19
+ fs.writeFileSync(CREDS_FILE, JSON.stringify(creds, null, 2), { mode: 0o600 });
20
+ }
21
+
22
+ function load(host, port) {
23
+ try {
24
+ const raw = fs.readFileSync(CREDS_FILE, 'utf8');
25
+ const creds = JSON.parse(raw);
26
+ if (creds.host !== host || creds.port !== port) return null;
27
+ return creds;
28
+ } catch {
29
+ return null;
30
+ }
31
+ }
32
+
33
+ function clear() {
34
+ try {
35
+ fs.unlinkSync(CREDS_FILE);
36
+ } catch {
37
+ }
38
+ }
39
+
40
+ module.exports = { DIR, CREDS_FILE, HISTORY_FILE, save, load, clear };
package/src/top.js CHANGED
@@ -1,53 +1,39 @@
1
- /*
2
- * Copyright 2026 DemonZDevelopment
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
-
17
- 'use strict';
18
-
19
- const readline = require('readline');
20
- const { formatStats, formatTps } = require('./formatters');
21
-
22
- function sleep(ms) {
23
- return new Promise((r) => setTimeout(r, ms));
24
- }
25
-
26
- async function runTop(client, refreshMs) {
27
- if (process.stdin.isTTY) {
28
- readline.emitKeypressEvents(process.stdin);
29
- process.stdin.setRawMode(true);
30
- }
31
- let stopped = false;
32
- const onKey = (str, key) => {
33
- if (key.name === 'q' || key.name === 'escape' || (key.ctrl && key.name === 'c')) stopped = true;
34
- };
35
- process.stdin.on('keypress', onKey);
36
- try {
37
- while (!stopped) {
38
- const res = await client.request('monitor.top', {});
39
- readline.cursorTo(process.stdout, 0, 0);
40
- readline.clearScreenDown(process.stdout);
41
- console.log('CreeperCLI top (q to quit)\n');
42
- console.log(formatStats(res.stats));
43
- console.log();
44
- console.log(formatTps(res.tps));
45
- await sleep(refreshMs);
46
- }
47
- } finally {
48
- process.stdin.removeListener('keypress', onKey);
49
- if (process.stdin.isTTY) process.stdin.setRawMode(false);
50
- }
51
- }
52
-
53
- module.exports = { runTop };
1
+
2
+
3
+ 'use strict';
4
+
5
+ const readline = require('readline');
6
+ const { formatStats, formatTps } = require('./formatters');
7
+
8
+ function sleep(ms) {
9
+ return new Promise((r) => setTimeout(r, ms));
10
+ }
11
+
12
+ async function runTop(client, refreshMs) {
13
+ if (process.stdin.isTTY) {
14
+ readline.emitKeypressEvents(process.stdin);
15
+ process.stdin.setRawMode(true);
16
+ }
17
+ let stopped = false;
18
+ const onKey = (str, key) => {
19
+ if (key.name === 'q' || key.name === 'escape' || (key.ctrl && key.name === 'c')) stopped = true;
20
+ };
21
+ process.stdin.on('keypress', onKey);
22
+ try {
23
+ while (!stopped) {
24
+ const res = await client.request('monitor.top', {});
25
+ readline.cursorTo(process.stdout, 0, 0);
26
+ readline.clearScreenDown(process.stdout);
27
+ console.log('CreeperCLI top (q to quit)\n');
28
+ console.log(formatStats(res.stats));
29
+ console.log();
30
+ console.log(formatTps(res.tps));
31
+ await sleep(refreshMs);
32
+ }
33
+ } finally {
34
+ process.stdin.removeListener('keypress', onKey);
35
+ if (process.stdin.isTTY) process.stdin.setRawMode(false);
36
+ }
37
+ }
38
+
39
+ module.exports = { runTop };