@makano/rew 1.1.72 → 1.1.81

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.
Files changed (51) hide show
  1. package/README.md +1 -1
  2. package/build.sh +3 -1
  3. package/lib/rew/cli/cli.js +189 -144
  4. package/lib/rew/cli/log.js +18 -19
  5. package/lib/rew/cli/run.js +7 -9
  6. package/lib/rew/cli/utils.js +109 -95
  7. package/lib/rew/const/config_path.js +4 -0
  8. package/lib/rew/const/default.js +21 -3
  9. package/lib/rew/const/files.js +11 -8
  10. package/lib/rew/const/opt.js +6 -6
  11. package/lib/rew/css/theme.css +1 -1
  12. package/lib/rew/functions/core.js +7 -9
  13. package/lib/rew/functions/emitter.js +2 -2
  14. package/lib/rew/functions/exec.js +19 -15
  15. package/lib/rew/functions/export.js +4 -6
  16. package/lib/rew/functions/fs.js +21 -18
  17. package/lib/rew/functions/future.js +1 -1
  18. package/lib/rew/functions/import.js +55 -25
  19. package/lib/rew/functions/map.js +2 -5
  20. package/lib/rew/functions/match.js +21 -5
  21. package/lib/rew/functions/path.js +2 -2
  22. package/lib/rew/functions/require.js +16 -13
  23. package/lib/rew/functions/stdout.js +11 -11
  24. package/lib/rew/functions/types.js +67 -42
  25. package/lib/rew/html/ui.html +5 -6
  26. package/lib/rew/html/ui.js +100 -58
  27. package/lib/rew/main.js +3 -3
  28. package/lib/rew/misc/findAppInfo.js +16 -0
  29. package/lib/rew/misc/findAppPath.js +21 -0
  30. package/lib/rew/misc/seededid.js +13 -0
  31. package/lib/rew/models/struct.js +1 -1
  32. package/lib/rew/modules/compiler.js +90 -58
  33. package/lib/rew/modules/context.js +35 -22
  34. package/lib/rew/modules/runtime.js +1 -1
  35. package/lib/rew/pkgs/conf.js +50 -33
  36. package/lib/rew/pkgs/data.js +7 -2
  37. package/lib/rew/pkgs/date.js +8 -9
  38. package/lib/rew/pkgs/env.js +3 -5
  39. package/lib/rew/pkgs/modules/data/bintree.js +1 -1
  40. package/lib/rew/pkgs/modules/data/doublylinked.js +1 -1
  41. package/lib/rew/pkgs/modules/data/linkedList.js +1 -1
  42. package/lib/rew/pkgs/modules/data/queue.js +1 -2
  43. package/lib/rew/pkgs/modules/data/stack.js +1 -1
  44. package/lib/rew/pkgs/modules/threads/worker.js +31 -21
  45. package/lib/rew/pkgs/modules/ui/classes.js +68 -61
  46. package/lib/rew/pkgs/pkgs.js +5 -6
  47. package/lib/rew/pkgs/rune.js +437 -0
  48. package/lib/rew/pkgs/threads.js +30 -22
  49. package/lib/rew/pkgs/ui.js +68 -44
  50. package/meson.build +1 -1
  51. package/package.json +8 -2
package/README.md CHANGED
@@ -12,7 +12,7 @@ Rew
12
12
  <a href="https://www.npmjs.com/package/rayous"> <img src="https://img.shields.io/npm/v/@makano/rew?style=for-the-badge&logo=npm&color=b4befe&logoColor=9399b2&labelColor=181825" alt="npm version" /></a>
13
13
  </p>
14
14
 
15
- Rayous is a simple lightweight coffeescript runtime, made to simply using coffescript and revive it
15
+ Rew is a simple lightweight coffeescript runtime, made to simply using coffescript and revive it
16
16
  in the process.
17
17
 
18
18
  ## Getting Started
package/build.sh CHANGED
@@ -3,4 +3,6 @@ opath=./bin/ui
3
3
  if [ $1 ]; then
4
4
  opath=$1
5
5
  fi
6
- g++ ./cpp/ui.cpp -o $opath `pkg-config --cflags --libs gtk+-3.0 webkit2gtk-4.0 libwebsockets jsoncpp`
6
+ # g++ ./cpp/ui.cpp -o $opath `pkg-config --cflags --libs gtk+-3.0 webkit2gtk-4.0 libwebsockets jsoncpp`
7
+ meson build
8
+ cd build && ninja && mv ./ui $opath && cd ../ && rm -r ./build
@@ -1,205 +1,250 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const yargs = require('yargs/yargs');
4
- const path = require('path');
5
- const { hideBin } = require('yargs/helpers');
6
- const { fork, exec, execSync } = require('child_process');
7
- const { watch } = require('chokidar');
8
- const utils = require('./utils');
9
- const { existsSync, readFileSync, writeFileSync, mkdirSync } = require('fs');
10
- const { log } = require('./log');
11
- const { compileFile, compile } = require('../modules/compiler');
3
+ const yargs = require("yargs/yargs");
4
+ const path = require("path");
5
+ const { hideBin } = require("yargs/helpers");
6
+ const { fork, exec, execSync } = require("child_process");
7
+ const { watch } = require("chokidar");
8
+ const utils = require("./utils");
9
+ const { existsSync, readFileSync, writeFileSync, mkdirSync } = require("fs");
10
+ const { log } = require("./log");
11
+ const { compile } = require("../modules/compiler");
12
+ const crypto = require("crypto");
12
13
 
13
14
  yargs(hideBin(process.argv))
14
15
  .command(
15
- '$0 <file>',
16
- 'Run the specified file',
16
+ "$0 <file>",
17
+ "Run the specified file",
17
18
  (yargs) => {
18
19
  yargs
19
- .positional('file', {
20
- describe: 'File to run',
21
- type: 'string',
20
+ .positional("file", {
21
+ describe: "File to run",
22
+ type: "string",
22
23
  })
23
- .option('watch', {
24
- alias: 'w',
25
- describe: 'Watch the file for changes',
26
- type: 'boolean',
24
+ .option("watch", {
25
+ alias: "w",
26
+ describe: "Watch the file for changes",
27
+ type: "boolean",
27
28
  });
28
29
  },
29
30
  (argv) => {
30
31
  const filePath = path.resolve(process.cwd(), argv.file);
31
- if(!existsSync(filePath)){
32
- log('File not found:', argv.file, ':end');
32
+ if (!existsSync(filePath)) {
33
+ log("File not found:", argv.file, ":end");
33
34
  return;
34
35
  }
35
36
  const watching = [];
36
37
  const watchIt = (file) => {
37
- if(watching.includes(file)) return;
38
- watch(file).on('change', () => runIt());
38
+ if (watching.includes(file)) return;
39
+ watch(file).on("change", () => runIt());
39
40
  watching.push(file);
40
- }
41
+ };
41
42
  let prevFork;
42
43
  const runIt = () => {
43
- if(argv.watch) console.clear();
44
- if(prevFork && !prevFork.killed) prevFork.kill?.();
45
- prevFork = fork(path.resolve(__dirname, './run.js'))
46
- .on('message', (data) => {
47
- if(argv.watch){
48
- data.forEach(file => {
49
- watchIt(file);
50
- });
51
- }
52
- }).send({ filePath, watch: argv.watch });
53
- if(argv.watch) watchIt(filePath);
54
- }
44
+ if (argv.watch) console.clear();
45
+ if (prevFork && !prevFork.killed) prevFork.kill?.();
46
+ prevFork = fork(path.resolve(__dirname, "./run.js"))
47
+ .on("message", (data) => {
48
+ if (argv.watch) {
49
+ data.forEach((file) => {
50
+ watchIt(file);
51
+ });
52
+ }
53
+ })
54
+ .send({ filePath, watch: argv.watch });
55
+ if (argv.watch) watchIt(filePath);
56
+ };
55
57
  runIt();
56
- }
58
+ },
57
59
  )
58
60
  .command(
59
- 'conf <command> [path] [key] [value]',
60
- 'Configuration management',
61
+ "conf <command> [path] [key] [value]",
62
+ "Configuration management",
61
63
  (yargs) => {
62
64
  yargs
63
- .positional('command', {
64
- describe: 'Configuration command (get, set, remove)',
65
- type: 'string',
66
- choices: ['get', 'set', 'remove'],
65
+ .positional("command", {
66
+ describe: "Configuration command (get, set, remove)",
67
+ type: "string",
68
+ choices: ["get", "set", "remove"],
67
69
  })
68
- .positional('path', {
69
- describe: 'Configuration path',
70
- type: 'string',
71
- default: '',
70
+ .positional("path", {
71
+ describe: "Configuration path",
72
+ type: "string",
73
+ default: "",
72
74
  })
73
- .positional('key', {
74
- describe: 'Key to get/set/remove',
75
- type: 'string',
76
- default: '',
75
+ .positional("key", {
76
+ describe: "Key to get/set/remove",
77
+ type: "string",
78
+ default: "",
77
79
  })
78
- .positional('value', {
80
+ .positional("value", {
79
81
  describe: 'Value to set (only used with "set" command)',
80
- type: 'string',
81
- default: '',
82
+ type: "string",
83
+ default: "",
82
84
  });
83
85
  },
84
86
  (argv) => {
85
87
  const { command, path, key, value } = argv;
86
88
  const result = utils.conf(command, path, key, value);
87
- if(result) console.log(result);
88
- }
89
+ if (result) console.log(result);
90
+ },
89
91
  )
90
- .command('create <path>', 'Create a new project', (yargs) => {
91
- yargs
92
- .positional('path', {
93
- describe: 'Path of the project to create',
94
- type: 'string',
92
+ .command(
93
+ "create <path>",
94
+ "Create a new project",
95
+ (yargs) => {
96
+ yargs.positional("path", {
97
+ describe: "Path of the project to create",
98
+ type: "string",
95
99
  });
96
100
  },
97
101
  (argv) => {
98
102
  utils.createProject(argv.path);
99
- }
103
+ },
100
104
  )
101
- .command('ui-bin <path>', 'Build the UI bin for your own app', (yargs) => {
102
- yargs
103
- .positional('path', {
104
- describe: 'Path of the output bin',
105
- type: 'string',
105
+ .command(
106
+ "rune-keygen <secret>",
107
+ "Generate a rune encryption key",
108
+ (yargs) => {
109
+ yargs.option("secret", {
110
+ describe: "Secret used to generate encryption key",
111
+ type: "string",
106
112
  });
107
113
  },
108
114
  (argv) => {
109
- execSync('sh '+path.resolve(__dirname, '../../../build.sh')+' '+argv.path);
110
- }
115
+ const generateEncryptionKey = (secret) => {
116
+ if (secret) {
117
+ return crypto.createHash("sha256").update(secret).digest("hex");
118
+ } else {
119
+ return crypto.randomBytes(32).toString("hex");
120
+ }
121
+ };
122
+
123
+ const encryptionKey = generateEncryptionKey(argv.secret);
124
+ console.log("Encryption Key:", encryptionKey);
125
+ },
111
126
  )
112
- .command('run <path | package>', 'Run an app', (yargs) => {
113
- yargs
114
- .positional('path', {
115
- describe: 'Path of the app to run',
116
- type: 'string',
127
+ .command(
128
+ "ui-bin <path>",
129
+ "Build the UI bin for your own app",
130
+ (yargs) => {
131
+ yargs.positional("path", {
132
+ describe: "Path of the output bin",
133
+ type: "string",
134
+ });
135
+ },
136
+ (argv) => {
137
+ execSync(
138
+ "sh " + path.resolve(__dirname, "../../../build.sh") + " " + argv.path,
139
+ );
140
+ },
141
+ )
142
+ .command(
143
+ "run <path | package>",
144
+ "Run an app",
145
+ (yargs) => {
146
+ yargs.positional("path", {
147
+ describe: "Path of the app to run",
148
+ type: "string",
117
149
  });
118
150
  },
119
151
  (argv) => {
120
152
  utils.runApp(argv.path);
121
- }
153
+ },
122
154
  )
123
- .command('install <path>', 'Install an app', (yargs) => {
124
- yargs
125
- .positional('path', {
126
- describe: 'Path of the app to install',
127
- type: 'string',
155
+ .command(
156
+ "install <path>",
157
+ "Install an app",
158
+ (yargs) => {
159
+ yargs.positional("path", {
160
+ describe: "Path of the app to install",
161
+ type: "string",
128
162
  });
129
163
  },
130
164
  async (argv) => {
131
- if(argv.path.startsWith('github:')) utils.installApp(await utils.cloneGit(argv.path), true, true);
165
+ if (argv.path.startsWith("github:"))
166
+ utils.installApp(await utils.cloneGit(argv.path), true, true);
132
167
  else utils.installApp(argv.path);
133
- }
168
+ },
134
169
  )
135
- .command('build <file>', 'Build the specified file', (yargs) => {
136
- yargs
137
- .positional('file', {
138
- describe: 'File to build',
139
- type: 'string',
140
- })
141
- .option('output', {
142
- alias: 'o',
143
- describe: 'Output directory',
144
- type: 'string',
145
- });
146
- }, (argv) => {
170
+ .command(
171
+ "build <file>",
172
+ "Build the specified file",
173
+ (yargs) => {
174
+ yargs
175
+ .positional("file", {
176
+ describe: "File to build",
177
+ type: "string",
178
+ })
179
+ .option("output", {
180
+ alias: "o",
181
+ describe: "Output directory",
182
+ type: "string",
183
+ });
184
+ },
185
+ (argv) => {
186
+ function readFile(filePath) {
187
+ return readFileSync(filePath, { encoding: "utf-8" });
188
+ }
147
189
 
148
- function readFile(filePath) {
149
- return readFileSync(filePath, { encoding: 'utf-8' });
150
- }
190
+ function extractImports(content) {
191
+ const importRegex = /(\w+)\s*=\s*imp\s*['"](.+?)['"]/g;
192
+ const imports = [];
193
+ let match;
194
+ while ((match = importRegex.exec(content)) !== null) {
195
+ imports.push({ variable: match[1], url: match[2] });
196
+ }
197
+ return imports;
198
+ }
151
199
 
152
- function extractImports(content) {
153
- const importRegex = /(\w+)\s*=\s*imp\s*['"](.+?)['"]/g;
154
- const imports = [];
155
- let match;
156
- while ((match = importRegex.exec(content)) !== null) {
157
- imports.push({ variable: match[1], url: match[2] });
200
+ function writeCompiledFile(filePath, compiledCode) {
201
+ const dirName = outputDir ? outputDir : path.dirname(filePath);
202
+ if (!existsSync(dirName)) mkdirSync(dirName, { recursive: true });
203
+ const baseName = path.basename(filePath, path.extname(filePath));
204
+ const newFilePath = path.join(dirName, `${baseName}.js`);
205
+ writeFileSync(newFilePath, compiledCode, { encoding: "utf-8" });
206
+ log(`Compiled: ${newFilePath}`);
158
207
  }
159
- return imports;
160
- }
161
208
 
162
- function writeCompiledFile(filePath, compiledCode) {
163
- const dirName = outputDir ? outputDir : path.dirname(filePath);
164
- if(!existsSync(dirName)) mkdirSync(dirName, { recursive: true });
165
- const baseName = path.basename(filePath, path.extname(filePath));
166
- const newFilePath = path.join(dirName, `${baseName}.js`);
167
- writeFileSync(newFilePath, compiledCode, { encoding: 'utf-8' });
168
- log(`Compiled: ${newFilePath}`);
169
- }
209
+ function processFile(filePath, importsArray) {
210
+ const content = readFile(filePath);
211
+ const imports = extractImports(content);
170
212
 
171
- function processFile(filePath, importsArray) {
172
- const content = readFile(filePath);
173
- const imports = extractImports(content);
174
-
175
- imports.forEach(importStatement => {
176
- const importedFilePath = path.resolve(path.dirname(filePath), importStatement.url);
177
- if (!importsArray.some(importObj => importObj.url === importStatement.url)) {
178
-
179
- if(existsSync(importedFilePath)){
180
- importsArray.push(importStatement);
181
- processFile(importedFilePath, importsArray);
182
- } else if(existsSync(importedFilePath+'.coffee')){
183
- importsArray.push(importStatement);
184
- processFile(importedFilePath+'.coffee', importsArray);
185
- } else if(existsSync(importedFilePath+'.js')){
186
- importsArray.push(importStatement);
187
- processFile(importedFilePath+'.js', importsArray);
213
+ imports.forEach((importStatement) => {
214
+ const importedFilePath = path.resolve(
215
+ path.dirname(filePath),
216
+ importStatement.url,
217
+ );
218
+ if (
219
+ !importsArray.some(
220
+ (importObj) => importObj.url === importStatement.url,
221
+ )
222
+ ) {
223
+ if (existsSync(importedFilePath)) {
224
+ importsArray.push(importStatement);
225
+ processFile(importedFilePath, importsArray);
226
+ } else if (existsSync(importedFilePath + ".coffee")) {
227
+ importsArray.push(importStatement);
228
+ processFile(importedFilePath + ".coffee", importsArray);
229
+ } else if (existsSync(importedFilePath + ".js")) {
230
+ importsArray.push(importStatement);
231
+ processFile(importedFilePath + ".js", importsArray);
232
+ }
188
233
  }
234
+ });
189
235
 
190
- }
191
- });
192
-
193
- const compiled = compile({ content }, {});
194
- writeCompiledFile(filePath, compiled);
195
- }
236
+ const compiled = compile({ content }, {});
237
+ writeCompiledFile(filePath, compiled);
238
+ }
196
239
 
197
- const filePath = path.resolve(process.cwd(), argv.file);
198
- const importsArray = [];
199
- const outputDir = argv.output ? path.resolve(process.cwd(), argv.output) : null;
200
- log('Start compile at', outputDir || 'default path');
201
- processFile(filePath, importsArray);
202
- log('Compiled', importsArray.length + 1, 'files.', ':end');
203
- })
204
- .help()
205
- .argv;
240
+ const filePath = path.resolve(process.cwd(), argv.file);
241
+ const importsArray = [];
242
+ const outputDir = argv.output
243
+ ? path.resolve(process.cwd(), argv.output)
244
+ : null;
245
+ log("Start compile at", outputDir || "default path");
246
+ processFile(filePath, importsArray);
247
+ log("Compiled", importsArray.length + 1, "files.", ":end");
248
+ },
249
+ )
250
+ .help().argv;
@@ -1,40 +1,39 @@
1
-
2
1
  let start = true;
3
- const startPrefix = '';
4
- const middlePrefix = '';
5
- const separator = '';
6
- const endPrefix = '';
2
+ const startPrefix = "";
3
+ const middlePrefix = "";
4
+ const separator = "";
5
+ const endPrefix = "";
7
6
 
8
- const log = module.exports.log = function(...toPrint){
7
+ const log = (module.exports.log = function (...toPrint) {
9
8
  let prefix = start ? startPrefix : middlePrefix;
10
9
  let returns = false;
11
- if(toPrint[toPrint.length-1] == ':end') {
10
+ if (toPrint[toPrint.length - 1] == ":end") {
12
11
  prefix = endPrefix;
13
12
  toPrint.pop();
14
13
  }
15
- if(toPrint[toPrint.length-1] == ':returns') {
14
+ if (toPrint[toPrint.length - 1] == ":returns") {
16
15
  returns = true;
17
16
  toPrint.pop();
18
17
  }
19
- if(prefix == endPrefix && start) prefix = separator;
20
- if(!start) console.log(separator);
21
- if(start) start = false;
22
- if(returns) return [prefix, ...toPrint].join(' ');
18
+ if (prefix == endPrefix && start) prefix = separator;
19
+ if (!start) console.log(separator);
20
+ if (start) start = false;
21
+ if (returns) return [prefix, ...toPrint].join(" ");
23
22
  else console.log(prefix, ...toPrint);
24
- }
23
+ });
25
24
 
26
- module.exports.logget = function(...toPrint){
25
+ module.exports.logget = function (...toPrint) {
27
26
  let args = [...toPrint];
28
- if(toPrint[toPrint.length-1] == ':end') {
27
+ if (toPrint[toPrint.length - 1] == ":end") {
29
28
  let l = args.pop();
30
- args.push(':returns', l);
29
+ args.push(":returns", l);
31
30
  } else {
32
- args.push(':returns');
31
+ args.push(":returns");
33
32
  }
34
33
  return log(...args);
35
- }
34
+ };
36
35
 
37
36
  log.startPrefix = startPrefix;
38
37
  log.middlePrefix = middlePrefix;
39
38
  log.separator = separator;
40
- log.endPrefix = endPrefix;
39
+ log.endPrefix = endPrefix;
@@ -1,17 +1,15 @@
1
- const { run } = require('../main');
1
+ const { run } = require("../main");
2
2
 
3
-
4
- function exec(filePath){
5
- return run(filePath)
6
- .context.module.imports;
3
+ function exec(filePath) {
4
+ return run(filePath).context.module.imports;
7
5
  }
8
6
 
9
7
  const onmsg = ({ filePath, watch }) => {
10
8
  const imports = exec(filePath);
11
- if(watch){
9
+ if (watch) {
12
10
  process.send(imports);
13
11
  }
14
- process.off('message', onmsg);
15
- }
12
+ process.off("message", onmsg);
13
+ };
16
14
 
17
- process.on('message', onmsg);
15
+ process.on("message", onmsg);