@makano/rew 1.1.81 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. package/lib/coffeescript/browser.js +144 -139
  2. package/lib/coffeescript/cake.js +132 -133
  3. package/lib/coffeescript/coffeescript.js +437 -381
  4. package/lib/coffeescript/command.js +806 -724
  5. package/lib/coffeescript/grammar.js +1908 -2474
  6. package/lib/coffeescript/helpers.js +509 -473
  7. package/lib/coffeescript/index.js +228 -215
  8. package/lib/coffeescript/lexer.js +2282 -1909
  9. package/lib/coffeescript/nodes.js +9782 -9202
  10. package/lib/coffeescript/optparse.js +255 -227
  11. package/lib/coffeescript/parser.js +20305 -1265
  12. package/lib/coffeescript/register.js +107 -87
  13. package/lib/coffeescript/repl.js +307 -284
  14. package/lib/coffeescript/rewriter.js +1389 -1079
  15. package/lib/coffeescript/scope.js +176 -172
  16. package/lib/coffeescript/sourcemap.js +242 -227
  17. package/lib/rew/cli/cli.js +296 -239
  18. package/lib/rew/cli/log.js +27 -27
  19. package/lib/rew/cli/run.js +8 -8
  20. package/lib/rew/cli/utils.js +353 -199
  21. package/lib/rew/const/config_path.js +2 -2
  22. package/lib/rew/const/default.js +38 -53
  23. package/lib/rew/const/files.js +11 -14
  24. package/lib/rew/const/opt.js +6 -6
  25. package/lib/rew/css/theme.css +1 -1
  26. package/lib/rew/functions/core.js +55 -55
  27. package/lib/rew/functions/curl.js +23 -0
  28. package/lib/rew/functions/emitter.js +52 -55
  29. package/lib/rew/functions/exec.js +25 -25
  30. package/lib/rew/functions/export.js +17 -17
  31. package/lib/rew/functions/fs.js +57 -59
  32. package/lib/rew/functions/future.js +29 -21
  33. package/lib/rew/functions/id.js +8 -9
  34. package/lib/rew/functions/import.js +106 -122
  35. package/lib/rew/functions/map.js +10 -10
  36. package/lib/rew/functions/match.js +35 -42
  37. package/lib/rew/functions/path.js +8 -8
  38. package/lib/rew/functions/require.js +32 -36
  39. package/lib/rew/functions/sleep.js +2 -2
  40. package/lib/rew/functions/stdout.js +18 -18
  41. package/lib/rew/functions/types.js +82 -106
  42. package/lib/rew/html/ui.html +12 -12
  43. package/lib/rew/html/ui.js +196 -201
  44. package/lib/rew/main.js +14 -14
  45. package/lib/rew/misc/bin.js +37 -0
  46. package/lib/rew/misc/findAppInfo.js +13 -13
  47. package/lib/rew/misc/findAppPath.js +15 -15
  48. package/lib/rew/misc/req.js +7 -0
  49. package/lib/rew/misc/seededid.js +8 -8
  50. package/lib/rew/models/enum.js +12 -12
  51. package/lib/rew/models/struct.js +30 -32
  52. package/lib/rew/modules/compiler.js +237 -209
  53. package/lib/rew/modules/fs.js +10 -10
  54. package/lib/rew/modules/runtime.js +17 -21
  55. package/lib/rew/modules/yaml.js +27 -30
  56. package/lib/rew/pkgs/conf.js +82 -92
  57. package/lib/rew/pkgs/data.js +10 -10
  58. package/lib/rew/pkgs/date.js +27 -27
  59. package/lib/rew/pkgs/env.js +5 -5
  60. package/lib/rew/pkgs/modules/data/bintree.js +51 -51
  61. package/lib/rew/pkgs/modules/data/doublylinked.js +84 -84
  62. package/lib/rew/pkgs/modules/data/linkedList.js +72 -72
  63. package/lib/rew/pkgs/modules/data/queue.js +18 -18
  64. package/lib/rew/pkgs/modules/data/stack.js +18 -18
  65. package/lib/rew/pkgs/modules/threads/worker.js +36 -36
  66. package/lib/rew/pkgs/modules/ui/classes.js +181 -184
  67. package/lib/rew/pkgs/pkgs.js +9 -9
  68. package/lib/rew/pkgs/rune.js +373 -410
  69. package/lib/rew/pkgs/threads.js +62 -66
  70. package/lib/rew/pkgs/ui.js +148 -160
  71. package/lib/rew/qrew/compile.js +12 -0
  72. package/package.json +4 -3
@@ -1,79 +1,75 @@
1
- const { Worker } = require("worker_threads");
2
- const emitter = require("../functions/emitter");
3
- const future = require("../functions/future");
4
- const { struct } = require("../models/struct");
5
- const path = require("path");
1
+ const { Worker } = require('worker_threads');
2
+ const emitter = require('../functions/emitter');
3
+ const future = require('../functions/future');
4
+ const { struct } = require('../models/struct');
5
+ const path = require('path');
6
6
 
7
7
  module.exports = (context) => ({
8
- thread: (cb) => {
9
- const workers = [];
8
+ thread: (cb) => {
9
+ const workers = [];
10
10
 
11
- const stopWorker = (worker) => {
12
- workers.splice(workers.indexOf(worker), 1);
13
- worker.terminate();
14
- };
11
+ const stopWorker = (worker) => {
12
+ workers.splice(workers.indexOf(worker), 1);
13
+ worker.terminate();
14
+ };
15
15
 
16
- const athread = {
17
- stopAll: () => {
18
- if (!run) return;
19
- workers.forEach(stopWorker);
20
- },
21
- start: (context) => {
22
- let dataResult = future(() => {}),
23
- listener = emitter();
24
- const worker = new Worker(
25
- path.resolve(__dirname, "./modules/threads/worker.js"),
26
- {
27
- workerData: { context, cb: cb.toString() },
28
- },
29
- );
30
- workers.push(worker);
16
+ const athread = {
17
+ stopAll: () => {
18
+ if (!run) return;
19
+ workers.forEach(stopWorker);
20
+ },
21
+ start: (context) => {
22
+ let dataResult = future(() => {}),
23
+ listener = emitter();
24
+ const worker = new Worker(path.resolve(__dirname, './modules/threads/worker.js'), {
25
+ workerData: { context, cb: cb.toString() },
26
+ });
27
+ workers.push(worker);
31
28
 
32
- const stop = () => stopWorker(worker);
29
+ const stop = () => stopWorker(worker);
33
30
 
34
- worker.on("message", (data) => {
35
- if (data.type === "result") {
36
- dataResult.resolve(data.result);
37
- stop();
38
- } else if (data.type === "error") {
39
- reject(new Error(data.error));
40
- stop();
41
- } else if (data.type === "event") {
42
- listener.emit(data.event, data.data);
43
- }
44
- });
31
+ worker.on('message', (data) => {
32
+ if (data.type === 'result') {
33
+ dataResult.resolve(data.result);
34
+ stop();
35
+ } else if (data.type === 'error') {
36
+ reject(new Error(data.error));
37
+ stop();
38
+ } else if (data.type === 'event') {
39
+ listener.emit(data.event, data.data);
40
+ }
41
+ });
45
42
 
46
- worker.on("error", (error) => {
47
- console.log(error);
48
- stop();
49
- });
43
+ worker.on('error', (error) => {
44
+ console.log(error);
45
+ stop();
46
+ });
50
47
 
51
- let exiting = false;
48
+ let exiting = false;
52
49
 
53
- worker.on("exit", (code) => {
54
- if (exiting) return;
55
- stop();
56
- if (code !== 0) {
57
- throw new Error(`Worker stopped with exit code ${code}`);
58
- }
59
- });
50
+ worker.on('exit', (code) => {
51
+ if (exiting) return;
52
+ stop();
53
+ if (code !== 0) {
54
+ throw new Error(`Worker stopped with exit code ${code}`);
55
+ }
56
+ });
60
57
 
61
- worker.postMessage({ type: "start" });
58
+ worker.postMessage({ type: 'start' });
62
59
 
63
- return {
64
- on: (e, cb) => listener.on(e, cb),
65
- off: (e, cb) => listener.off(e, cb),
66
- emit: (e, data) =>
67
- worker?.postMessage({ type: "event", event: e, data }),
68
- get: () => dataResult.wait(),
69
- stop: () => {
70
- exiting = true;
71
- stop();
72
- },
73
- };
74
- },
75
- };
60
+ return {
61
+ on: (e, cb) => listener.on(e, cb),
62
+ off: (e, cb) => listener.off(e, cb),
63
+ emit: (e, data) => worker?.postMessage({ type: 'event', event: e, data }),
64
+ get: () => dataResult.wait(),
65
+ stop: () => {
66
+ exiting = true;
67
+ stop();
68
+ },
69
+ };
70
+ },
71
+ };
76
72
 
77
- return athread;
78
- },
73
+ return athread;
74
+ },
79
75
  });
@@ -1,169 +1,157 @@
1
- const path = require("path");
2
- const { spawn, exec } = require("child_process");
3
- const fs = require("fs");
4
- const { uiClasses } = require("./modules/ui/classes");
5
- const { generateRandomID } = require("../functions/id");
6
- const { THEME_PATH } = require("../const/files");
7
- const readline = require("readline");
8
- const emitter = require("../functions/emitter");
9
-
10
- const BIN_PATH = path.resolve(__dirname, "../../../bin/ui");
11
- const HTML_STRING = fs.readFileSync(
12
- path.resolve(__dirname, "../html/ui.html"),
13
- { encoding: "utf-8" },
14
- );
15
- const JS_STRING = fs.readFileSync(path.resolve(__dirname, "../html/ui.js"), {
16
- encoding: "utf-8",
1
+ const path = require('path');
2
+ const { spawn, exec } = require('child_process');
3
+ const fs = require('fs');
4
+ const { uiClasses } = require('./modules/ui/classes');
5
+ const { generateRandomID } = require('../functions/id');
6
+ const { THEME_PATH } = require('../const/files');
7
+ const readline = require('readline');
8
+ const emitter = require('../functions/emitter');
9
+
10
+ const BIN_PATH = path.resolve(__dirname, '../../../bin/ui');
11
+ const HTML_STRING = fs.readFileSync(path.resolve(__dirname, '../html/ui.html'), { encoding: 'utf-8' });
12
+ const JS_STRING = fs.readFileSync(path.resolve(__dirname, '../html/ui.js'), {
13
+ encoding: 'utf-8',
17
14
  });
18
15
 
19
16
  const replaceString = (string, options) =>
20
- string.replace(/\$OPTIONS\(([^)]+)\)/g, (_, n) =>
21
- n.startsWith("json.")
22
- ? JSON.stringify(options[n.split("json.")[1]] || "{}")
23
- : options[n] || _,
24
- );
17
+ string.replace(/\$OPTIONS\(([^)]+)\)/g, (_, n) =>
18
+ n.startsWith('json.') ? JSON.stringify(options[n.split('json.')[1]] || '{}') : options[n] || _,
19
+ );
25
20
 
26
21
  const defaultOptions = {
27
- title: "Title",
28
- onExit: () => process.exit(),
29
- style: "",
30
- stylePath: THEME_PATH,
31
- exec: () => {},
32
- execContext: {},
22
+ title: 'Title',
23
+ onExit: () => process.exit(),
24
+ style: '',
25
+ stylePath: THEME_PATH,
26
+ exec: () => {},
27
+ execContext: {},
33
28
  };
34
29
 
35
30
  module.exports = (context) => ({
36
- start: (o = {}) => {
37
- const options = {
38
- ...defaultOptions,
39
- ...o,
40
- };
41
-
42
- const hookedSocketListeners = {};
43
-
44
- const runId = generateRandomID();
45
- const tmpFile = "/tmp/" + runId + ".ruw.ui.socket";
46
-
47
- options.runId = runId;
48
-
49
- if (fs.existsSync(options.stylePath))
50
- options.style =
51
- fs.readFileSync(options.stylePath, { encoding: "utf-8" }) +
52
- "\n" +
53
- options.style;
54
-
55
- options.style = " */\n" + options.style + "\n/* ";
56
-
57
- const HTML = replaceString(HTML_STRING, options);
58
- const JS = replaceString(JS_STRING, options);
59
-
60
- /**
61
- * Queue for future writes
62
- * @type {string[]}
63
- * */
64
- const queue = [];
65
-
66
- const send = (data) => {
67
- const content = fs.readFileSync(tmpFile, { encoding: "utf-8" });
68
- if (content) {
69
- queue.push(data);
70
- } else {
71
- fs.writeFileSync(
72
- tmpFile,
73
- typeof data !== "string" ? JSON.stringify(data) : data,
74
- );
75
- }
76
- };
77
-
78
- const sendEvent = (data) => {
79
- send({
80
- action: "JS",
81
- data: `window.recieveMessage(${JSON.stringify(data)})`,
82
- });
83
- };
84
-
85
- const g_emitter = emitter();
86
-
87
- const recieve = (data) => {
88
- g_emitter.emit("recieve", data);
89
- };
90
-
91
- const rl = readline.createInterface({
92
- input: process.stdin,
93
- output: process.stdout,
94
- });
95
-
96
- rl.question("", () => {});
97
-
98
- fs.writeFileSync(tmpFile, "");
99
-
100
- fs.watch(tmpFile, { encoding: "utf-8" }).on("change", () => {
101
- if (queue.length) {
102
- send(queue.pop());
103
- }
104
- });
105
-
106
- const p = spawn(options.bin || BIN_PATH, [runId]);
107
-
108
- p.on("close", (code) => {
109
- rl.close();
110
- options.onExit(code);
111
- });
112
-
113
- process.on("beforeExit", () => {
114
- p.kill();
115
- fs.unlinkSync(tmpFile);
116
- });
117
-
118
- g_emitter.on("recieve", (edata) => {
119
- if (edata.action.startsWith("hook:")) {
120
- const hook = hookedSocketListeners[edata.data.rid];
121
- const type = edata.action.split("hook:")[1];
122
- if (hook && hook.type == type) {
123
- hookedSocketListeners[edata.data.rid].cb(edata.data.object);
124
- if (hook.once) delete hookedSocketListeners[edata.data.rid];
125
- }
126
- }
127
- });
128
-
129
- return new Promise((r) => {
130
- p.stdout.on("data", (data) => {
131
- if (data.toString().startsWith("RESPONSE::")) {
132
- const d = data.toString().split("RESPONSE::")[1];
133
- const jd = JSON.parse(d);
134
- recieve(jd);
135
- } else if (data.toString().trim().endsWith("SETUP::READY")) {
136
- console.log("READY");
137
- r(
138
- uiClasses(
139
- context,
140
- options,
141
- sendEvent,
142
- (cb) => {
143
- g_emitter.on("recieve", cb);
144
- },
145
- (rid, type, cb, once = true) => {
146
- // Add hook
147
- hookedSocketListeners[rid] = { type, cb, once };
148
- },
149
- (rid) => {
150
- // Remove hook
151
- delete hookedSocketListeners[rid];
152
- },
153
- ),
154
- );
155
- } else if (data.toString().endsWith("SETUP::HTML")) {
156
- send({ action: "JS2", data: JS, isSetup: true });
157
- } else if (data.toString() == "INIT::READY") {
158
- send({ action: "HTML", data: HTML });
159
- } else {
160
- console.log(data.toString());
161
- }
162
- });
163
-
164
- p.stderr.on("data", (data) => {
165
- console.error(data.toString());
166
- });
167
- });
168
- },
31
+ start: (o = {}) => {
32
+ const options = {
33
+ ...defaultOptions,
34
+ ...o,
35
+ };
36
+
37
+ const hookedSocketListeners = {};
38
+
39
+ const runId = generateRandomID();
40
+ const tmpFile = '/tmp/' + runId + '.ruw.ui.socket';
41
+
42
+ options.runId = runId;
43
+
44
+ if (fs.existsSync(options.stylePath)) options.style = fs.readFileSync(options.stylePath, { encoding: 'utf-8' }) + '\n' + options.style;
45
+
46
+ options.style = ' */\n' + options.style + '\n/* ';
47
+
48
+ const HTML = replaceString(HTML_STRING, options);
49
+ const JS = replaceString(JS_STRING, options);
50
+
51
+ /**
52
+ * Queue for future writes
53
+ * @type {string[]}
54
+ * */
55
+ const queue = [];
56
+
57
+ const send = (data) => {
58
+ const content = fs.readFileSync(tmpFile, { encoding: 'utf-8' });
59
+ if (content) {
60
+ queue.push(data);
61
+ } else {
62
+ fs.writeFileSync(tmpFile, typeof data !== 'string' ? JSON.stringify(data) : data);
63
+ }
64
+ };
65
+
66
+ const sendEvent = (data) => {
67
+ send({
68
+ action: 'JS',
69
+ data: `window.recieveMessage(${JSON.stringify(data)})`,
70
+ });
71
+ };
72
+
73
+ const g_emitter = emitter();
74
+
75
+ const recieve = (data) => {
76
+ g_emitter.emit('recieve', data);
77
+ };
78
+
79
+ const rl = readline.createInterface({
80
+ input: process.stdin,
81
+ output: process.stdout,
82
+ });
83
+
84
+ rl.question('', () => {});
85
+
86
+ fs.writeFileSync(tmpFile, '');
87
+
88
+ fs.watch(tmpFile, { encoding: 'utf-8' }).on('change', () => {
89
+ if (queue.length) {
90
+ send(queue.pop());
91
+ }
92
+ });
93
+
94
+ const p = spawn(options.bin || BIN_PATH, [runId]);
95
+
96
+ p.on('close', (code) => {
97
+ rl.close();
98
+ options.onExit(code);
99
+ });
100
+
101
+ process.on('beforeExit', () => {
102
+ p.kill();
103
+ fs.unlinkSync(tmpFile);
104
+ });
105
+
106
+ g_emitter.on('recieve', (edata) => {
107
+ if (edata.action.startsWith('hook:')) {
108
+ const hook = hookedSocketListeners[edata.data.rid];
109
+ const type = edata.action.split('hook:')[1];
110
+ if (hook && hook.type == type) {
111
+ hookedSocketListeners[edata.data.rid].cb(edata.data.object);
112
+ if (hook.once) delete hookedSocketListeners[edata.data.rid];
113
+ }
114
+ }
115
+ });
116
+
117
+ return new Promise((r) => {
118
+ p.stdout.on('data', (data) => {
119
+ if (data.toString().startsWith('RESPONSE::')) {
120
+ const d = data.toString().split('RESPONSE::')[1];
121
+ const jd = JSON.parse(d);
122
+ recieve(jd);
123
+ } else if (data.toString().trim().endsWith('SETUP::READY')) {
124
+ console.log('READY');
125
+ r(
126
+ uiClasses(
127
+ context,
128
+ options,
129
+ sendEvent,
130
+ (cb) => {
131
+ g_emitter.on('recieve', cb);
132
+ },
133
+ (rid, type, cb, once = true) => {
134
+ // Add hook
135
+ hookedSocketListeners[rid] = { type, cb, once };
136
+ },
137
+ (rid) => {
138
+ // Remove hook
139
+ delete hookedSocketListeners[rid];
140
+ },
141
+ ),
142
+ );
143
+ } else if (data.toString().endsWith('SETUP::HTML')) {
144
+ send({ action: 'JS2', data: JS, isSetup: true });
145
+ } else if (data.toString() == 'INIT::READY') {
146
+ send({ action: 'HTML', data: HTML });
147
+ } else {
148
+ console.log(data.toString());
149
+ }
150
+ });
151
+
152
+ p.stderr.on('data', (data) => {
153
+ console.error(data.toString());
154
+ });
155
+ });
156
+ },
169
157
  });
@@ -0,0 +1,12 @@
1
+ const { deserializeData, serializeData, gen_key } = require("../misc/bin");
2
+
3
+
4
+
5
+
6
+ module.exports.to_qrew = (fileContent, secret) => {
7
+ return serializeData(Buffer.from(fileContent), gen_key(secret));
8
+ }
9
+
10
+ module.exports.from_qrew = (fileBuffer, secret) => {
11
+ return deserializeData(Buffer.from(fileBuffer), gen_key(secret));
12
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@makano/rew",
3
- "version": "1.1.81",
4
- "description": "A simple coffescript runtime",
3
+ "version": "1.2.0",
4
+ "description": "A simple coffescript runtime and app manager",
5
5
  "main": "lib/rew/main.js",
6
6
  "directories": {
7
7
  "lib": "lib"
@@ -34,9 +34,10 @@
34
34
  "dependencies": {
35
35
  "@babel/core": "^7.24.6",
36
36
  "@babel/preset-react": "^7.24.6",
37
+ "axios": "^1.7.2",
37
38
  "babel-plugin-jsx": "^1.2.0",
38
- "chalk": "^5.3.0",
39
39
  "chokidar": "^3.6.0",
40
+ "colors": "^1.4.0",
40
41
  "js-yaml": "^4.1.0",
41
42
  "tiny-msgpack": "^2.2.0",
42
43
  "uuid": "^9.0.1",