@makano/rew 1.1.72 → 1.1.81
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +1 -1
- package/build.sh +3 -1
- package/lib/rew/cli/cli.js +189 -144
- package/lib/rew/cli/log.js +18 -19
- package/lib/rew/cli/run.js +7 -9
- package/lib/rew/cli/utils.js +109 -95
- package/lib/rew/const/config_path.js +4 -0
- package/lib/rew/const/default.js +21 -3
- package/lib/rew/const/files.js +11 -8
- package/lib/rew/const/opt.js +6 -6
- package/lib/rew/css/theme.css +1 -1
- package/lib/rew/functions/core.js +7 -9
- package/lib/rew/functions/emitter.js +2 -2
- package/lib/rew/functions/exec.js +19 -15
- package/lib/rew/functions/export.js +4 -6
- package/lib/rew/functions/fs.js +21 -18
- package/lib/rew/functions/future.js +1 -1
- package/lib/rew/functions/import.js +55 -25
- package/lib/rew/functions/map.js +2 -5
- package/lib/rew/functions/match.js +21 -5
- package/lib/rew/functions/path.js +2 -2
- package/lib/rew/functions/require.js +16 -13
- package/lib/rew/functions/stdout.js +11 -11
- package/lib/rew/functions/types.js +67 -42
- package/lib/rew/html/ui.html +5 -6
- package/lib/rew/html/ui.js +100 -58
- package/lib/rew/main.js +3 -3
- package/lib/rew/misc/findAppInfo.js +16 -0
- package/lib/rew/misc/findAppPath.js +21 -0
- package/lib/rew/misc/seededid.js +13 -0
- package/lib/rew/models/struct.js +1 -1
- package/lib/rew/modules/compiler.js +90 -58
- package/lib/rew/modules/context.js +35 -22
- package/lib/rew/modules/runtime.js +1 -1
- package/lib/rew/pkgs/conf.js +50 -33
- package/lib/rew/pkgs/data.js +7 -2
- package/lib/rew/pkgs/date.js +8 -9
- package/lib/rew/pkgs/env.js +3 -5
- package/lib/rew/pkgs/modules/data/bintree.js +1 -1
- package/lib/rew/pkgs/modules/data/doublylinked.js +1 -1
- package/lib/rew/pkgs/modules/data/linkedList.js +1 -1
- package/lib/rew/pkgs/modules/data/queue.js +1 -2
- package/lib/rew/pkgs/modules/data/stack.js +1 -1
- package/lib/rew/pkgs/modules/threads/worker.js +31 -21
- package/lib/rew/pkgs/modules/ui/classes.js +68 -61
- package/lib/rew/pkgs/pkgs.js +5 -6
- package/lib/rew/pkgs/rune.js +437 -0
- package/lib/rew/pkgs/threads.js +30 -22
- package/lib/rew/pkgs/ui.js +68 -44
- package/meson.build +1 -1
- 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
|
-
|
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
|
package/lib/rew/cli/cli.js
CHANGED
@@ -1,205 +1,250 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
2
|
|
3
|
-
const yargs = require(
|
4
|
-
const path = require(
|
5
|
-
const { hideBin } = require(
|
6
|
-
const { fork, exec, execSync } = require(
|
7
|
-
const { watch } = require(
|
8
|
-
const utils = require(
|
9
|
-
const { existsSync, readFileSync, writeFileSync, mkdirSync } = require(
|
10
|
-
const { log } = require(
|
11
|
-
const {
|
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
|
-
|
16
|
-
|
16
|
+
"$0 <file>",
|
17
|
+
"Run the specified file",
|
17
18
|
(yargs) => {
|
18
19
|
yargs
|
19
|
-
.positional(
|
20
|
-
describe:
|
21
|
-
type:
|
20
|
+
.positional("file", {
|
21
|
+
describe: "File to run",
|
22
|
+
type: "string",
|
22
23
|
})
|
23
|
-
.option(
|
24
|
-
alias:
|
25
|
-
describe:
|
26
|
-
type:
|
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(
|
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(
|
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,
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
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
|
-
|
60
|
-
|
61
|
+
"conf <command> [path] [key] [value]",
|
62
|
+
"Configuration management",
|
61
63
|
(yargs) => {
|
62
64
|
yargs
|
63
|
-
.positional(
|
64
|
-
describe:
|
65
|
-
type:
|
66
|
-
choices: [
|
65
|
+
.positional("command", {
|
66
|
+
describe: "Configuration command (get, set, remove)",
|
67
|
+
type: "string",
|
68
|
+
choices: ["get", "set", "remove"],
|
67
69
|
})
|
68
|
-
.positional(
|
69
|
-
describe:
|
70
|
-
type:
|
71
|
-
default:
|
70
|
+
.positional("path", {
|
71
|
+
describe: "Configuration path",
|
72
|
+
type: "string",
|
73
|
+
default: "",
|
72
74
|
})
|
73
|
-
.positional(
|
74
|
-
describe:
|
75
|
-
type:
|
76
|
-
default:
|
75
|
+
.positional("key", {
|
76
|
+
describe: "Key to get/set/remove",
|
77
|
+
type: "string",
|
78
|
+
default: "",
|
77
79
|
})
|
78
|
-
.positional(
|
80
|
+
.positional("value", {
|
79
81
|
describe: 'Value to set (only used with "set" command)',
|
80
|
-
type:
|
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(
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
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(
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
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
|
-
|
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(
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
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(
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
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(
|
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(
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
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
|
-
|
149
|
-
|
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
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
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
|
-
|
163
|
-
|
164
|
-
|
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
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
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
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
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;
|
package/lib/rew/cli/log.js
CHANGED
@@ -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] ==
|
10
|
+
if (toPrint[toPrint.length - 1] == ":end") {
|
12
11
|
prefix = endPrefix;
|
13
12
|
toPrint.pop();
|
14
13
|
}
|
15
|
-
if(toPrint[toPrint.length-1] ==
|
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] ==
|
27
|
+
if (toPrint[toPrint.length - 1] == ":end") {
|
29
28
|
let l = args.pop();
|
30
|
-
args.push(
|
29
|
+
args.push(":returns", l);
|
31
30
|
} else {
|
32
|
-
args.push(
|
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;
|
package/lib/rew/cli/run.js
CHANGED
@@ -1,17 +1,15 @@
|
|
1
|
-
const { run } = require(
|
1
|
+
const { run } = require("../main");
|
2
2
|
|
3
|
-
|
4
|
-
|
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(
|
15
|
-
}
|
12
|
+
process.off("message", onmsg);
|
13
|
+
};
|
16
14
|
|
17
|
-
process.on(
|
15
|
+
process.on("message", onmsg);
|