@makano/rew 1.2.3 → 1.2.5
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/bin/rew +1 -0
- package/jsconfig.json +13 -0
- package/lib/rew/cli/cli.js +83 -39
- package/lib/rew/cli/log.js +5 -1
- package/lib/rew/cli/run.js +2 -2
- package/lib/rew/cli/utils.js +140 -65
- package/lib/rew/const/default.js +9 -0
- package/lib/rew/const/opt.js +1 -1
- package/lib/rew/functions/curl.js +1 -1
- package/lib/rew/functions/exec.js +2 -2
- package/lib/rew/functions/id.js +2 -2
- package/lib/rew/functions/import.js +19 -3
- package/lib/rew/functions/json.js +27 -0
- package/lib/rew/functions/require.js +34 -14
- package/lib/rew/modules/compiler.js +29 -2
- package/lib/rew/modules/context.js +16 -13
- package/lib/rew/modules/yaml.js +1 -1
- package/lib/rew/pkgs/conf.js +3 -2
- package/lib/rew/pkgs/rune.js +8 -1
- package/package.json +4 -1
- package/runtime.d.ts +371 -0
@@ -17,7 +17,7 @@ module.exports.curl = function curl(options, url){
|
|
17
17
|
}).then(async r => {
|
18
18
|
if(options.o) fs.writeFileSync(options.o, Buffer.from(await r.clone().arrayBuffer()));
|
19
19
|
return r;
|
20
|
-
}).then(r => options.json ? r.clone().json() : r));
|
20
|
+
}).then(r => options.json ? r.clone().json() : options.text ? r.clone().text() : r));
|
21
21
|
if(options.a) return f.wait();
|
22
22
|
else return f;
|
23
23
|
}
|
package/lib/rew/functions/id.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
module.exports.generateRandomID = function generateRandomID(length = 12) {
|
2
|
-
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
1
|
+
module.exports.generateRandomID = function generateRandomID(length = 12, _characters) {
|
2
|
+
const characters = _characters || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
3
3
|
const charactersLength = characters.length;
|
4
4
|
let randomID = '';
|
5
5
|
|
@@ -57,7 +57,7 @@ module.exports.imp = function (runPath, context) {
|
|
57
57
|
exports = foundCache.exports;
|
58
58
|
}
|
59
59
|
|
60
|
-
if (!ispkg && !existsSync(filepath)) {
|
60
|
+
if (!ispkg && !existsSync(filepath) && !foundCache) {
|
61
61
|
if (Array.isArray(execOptions.resolveExtensions) && execOptions.resolveExtensions.length) {
|
62
62
|
const resolve = execOptions.resolveExtensions.find((ext) =>
|
63
63
|
typeof ext == 'string' ? existsSync(filepath + ext) : existsSync(filepath + (ext.ext || '')),
|
@@ -119,8 +119,24 @@ module.exports.imp = function (runPath, context) {
|
|
119
119
|
}
|
120
120
|
}
|
121
121
|
|
122
|
-
|
123
|
-
|
122
|
+
// Hehe, i just had an idea for a
|
123
|
+
// descriptive code
|
124
|
+
// you put them in comment blocks
|
125
|
+
// and name it something
|
126
|
+
// then you can simple see
|
127
|
+
// which part of a code contains a certain
|
128
|
+
// task. cool right?
|
129
|
+
|
130
|
+
//** If is not package, post exec section
|
131
|
+
/**/ if (!ispkg) context.module.imports.push(filepath);
|
132
|
+
/**/ if (!ispkg) cachedFiles.push({ filepath, exports });
|
133
|
+
//**
|
134
|
+
|
135
|
+
//** Mock imports section
|
136
|
+
/**/ if(!exports) exports = options.mock;
|
137
|
+
/**/ if(options.mock == null) return null;
|
138
|
+
/**/ if(!exports) throw new Error('Import '+filename+' does not export anything. Use the "mock" option to mock a value.');
|
139
|
+
//**
|
124
140
|
|
125
141
|
return exports;
|
126
142
|
};
|
@@ -0,0 +1,27 @@
|
|
1
|
+
const jsYaml = require("js-yaml");
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
function json(thing){
|
6
|
+
return JSON.parse(thing);
|
7
|
+
}
|
8
|
+
|
9
|
+
function jsons(thing){
|
10
|
+
return JSON.stringify(thing);
|
11
|
+
}
|
12
|
+
|
13
|
+
|
14
|
+
function yaml(thing){
|
15
|
+
return jsYaml.loadAll(thing)[0];
|
16
|
+
}
|
17
|
+
|
18
|
+
function yamls(thing){
|
19
|
+
return jsYaml.dump(thing);
|
20
|
+
}
|
21
|
+
|
22
|
+
module.exports = {
|
23
|
+
yaml,
|
24
|
+
yamls,
|
25
|
+
json,
|
26
|
+
jsons
|
27
|
+
}
|
@@ -3,6 +3,7 @@ const path = require('path');
|
|
3
3
|
|
4
4
|
module.exports.customRequire = function customRequire(modulePath, filePath) {
|
5
5
|
const resolvedPath = resolveModulePath(modulePath, filePath);
|
6
|
+
if(!resolvedPath) throw new Error('Module '+modulePath+' not found');
|
6
7
|
return require(resolvedPath);
|
7
8
|
};
|
8
9
|
|
@@ -20,21 +21,40 @@ function resolveModulePath(modulePath, filePath) {
|
|
20
21
|
if (fs.existsSync(fullPath + '.json')) {
|
21
22
|
return fullPath + '.json';
|
22
23
|
}
|
24
|
+
|
23
25
|
if (fs.existsSync(fullPath) && fs.statSync(fullPath).isDirectory()) {
|
24
|
-
|
25
|
-
if (fs.existsSync(packageJsonPath)) {
|
26
|
-
const main = require(packageJsonPath).main || 'index.js';
|
27
|
-
const mainPath = path.join(fullPath, main);
|
28
|
-
if (fs.existsSync(mainPath)) {
|
29
|
-
return mainPath;
|
30
|
-
}
|
31
|
-
}
|
32
|
-
const indexPath = path.join(fullPath, 'index.js');
|
33
|
-
if (fs.existsSync(indexPath)) {
|
34
|
-
return indexPath;
|
35
|
-
}
|
26
|
+
return searchInPath(fullPath);
|
36
27
|
}
|
37
|
-
}
|
38
28
|
|
39
|
-
|
29
|
+
const rootPath = modulePath.split('/').shift();
|
30
|
+
const halfFullPath = path.join(basePath, rootPath);
|
31
|
+
if (fs.existsSync(halfFullPath) && fs.statSync(halfFullPath).isDirectory()) {
|
32
|
+
return searchInPath(halfFullPath, ['.'].concat(fullPath.split('/').slice(1)).join('/'));
|
33
|
+
}
|
34
|
+
}
|
40
35
|
}
|
36
|
+
|
37
|
+
function searchInPath(fullPath, exportses){
|
38
|
+
const packageJsonPath = path.join(fullPath, 'package.json');
|
39
|
+
if (fs.existsSync(packageJsonPath)) {
|
40
|
+
const packageJson = require(packageJsonPath);
|
41
|
+
let main = packageJson.main || 'index.js';
|
42
|
+
if(exportses){
|
43
|
+
if(packageJson.exports){
|
44
|
+
if(exportses in packageJson.exports) main = packageJson.exports[exportses];
|
45
|
+
}
|
46
|
+
}
|
47
|
+
if(typeof main == "object"){
|
48
|
+
if(Array.isArray(main)) main = main[0].require;
|
49
|
+
else main = main.require;
|
50
|
+
}
|
51
|
+
const mainPath = path.join(fullPath, main);
|
52
|
+
if (fs.existsSync(mainPath)) {
|
53
|
+
return mainPath;
|
54
|
+
}
|
55
|
+
}
|
56
|
+
const indexPath = path.join(fullPath, 'index.js');
|
57
|
+
if (fs.existsSync(indexPath)) {
|
58
|
+
return indexPath;
|
59
|
+
}
|
60
|
+
}
|
@@ -145,6 +145,19 @@ function compileRewStuff(content, options) {
|
|
145
145
|
continue;
|
146
146
|
}
|
147
147
|
|
148
|
+
|
149
|
+
if (token.type === 'IDENTIFIER' && token.value === 'let') {
|
150
|
+
result += '`'
|
151
|
+
hooks.push({
|
152
|
+
index: fnextToken(i, tokens, 'OTHER', ';').ti,
|
153
|
+
value: `\``,
|
154
|
+
});
|
155
|
+
}
|
156
|
+
|
157
|
+
if (token.type === 'IDENTIFIER' && token.value === 'export') {
|
158
|
+
token.value = 'pub';
|
159
|
+
}
|
160
|
+
|
148
161
|
if (token.type === 'IDENTIFIER' && token.value === 'import') {
|
149
162
|
// console.log(nextToken.type);
|
150
163
|
let ind = i + n + 2;
|
@@ -213,9 +226,16 @@ function compileRewStuff(content, options) {
|
|
213
226
|
nextToken.value &&
|
214
227
|
nextToken.value !== 'undefined'
|
215
228
|
) {
|
229
|
+
let next = {...nextToken};
|
230
|
+
if(next.value == 'default'){
|
231
|
+
i += 2;
|
232
|
+
}
|
233
|
+
if(next.value == 'class'){
|
234
|
+
next.value = gnextToken(i, n + 1, tokens)?.token.value || "default";
|
235
|
+
}
|
216
236
|
hooks.push({
|
217
237
|
index: i + 1,
|
218
|
-
value: `"${
|
238
|
+
value: `"${next.value}", `,
|
219
239
|
});
|
220
240
|
}
|
221
241
|
|
@@ -254,13 +274,20 @@ const cpl = (module.exports.compile = function (file, options = {}) {
|
|
254
274
|
|
255
275
|
module.exports.compileFile = function (filepath, options = {}) {
|
256
276
|
const f = getFile(filepath);
|
277
|
+
let qrew = false;
|
257
278
|
|
258
279
|
if(options.qrew || path.extname(filepath) == '.qrew') {
|
280
|
+
qrew = true
|
259
281
|
f.content = from_qrew(readFileSync(f.path), options.package || findAppInfo(filepath)?.config.manifest.package || path.basename(filepath).split('.').slice(0, -1).join('.')).toString();
|
260
|
-
}
|
282
|
+
}
|
261
283
|
|
262
284
|
let compiled_code = cpl(f, { ...options });
|
263
285
|
|
286
|
+
if(options.onlyCompile && !qrew){
|
287
|
+
console.log(compiled_code);
|
288
|
+
process.exit();
|
289
|
+
}
|
290
|
+
|
264
291
|
return {
|
265
292
|
compiled_code,
|
266
293
|
file: f,
|
@@ -42,19 +42,6 @@ module.exports.prepareContext = function (
|
|
42
42
|
...defaultContext,
|
43
43
|
...pathLib(filepath),
|
44
44
|
...execLib(filepath),
|
45
|
-
require: (package) => {
|
46
|
-
try {
|
47
|
-
return execOptions.nativeRequire || package.startsWith("node:")
|
48
|
-
? require(
|
49
|
-
package.startsWith("node:")
|
50
|
-
? package.split("node:")[1]
|
51
|
-
: package,
|
52
|
-
)
|
53
|
-
: customRequire(package, filepath);
|
54
|
-
} catch (e) {
|
55
|
-
throw new Error("Module " + package + " not found");
|
56
|
-
}
|
57
|
-
},
|
58
45
|
...custom_context,
|
59
46
|
};
|
60
47
|
}
|
@@ -66,6 +53,7 @@ module.exports.prepareContext = function (
|
|
66
53
|
off: (event, listener) => process.off(event, listener),
|
67
54
|
emit: (event, code) => process.emit(event, code),
|
68
55
|
},
|
56
|
+
__execFile: global.fileName,
|
69
57
|
env: process.env,
|
70
58
|
cwd: () => process.cwd(),
|
71
59
|
arch: process.arch,
|
@@ -74,6 +62,21 @@ module.exports.prepareContext = function (
|
|
74
62
|
context.global = context;
|
75
63
|
context.imports.assert = options.import ?? {};
|
76
64
|
context.imp = imp(runPath, context);
|
65
|
+
context.require = (package) => {
|
66
|
+
try {
|
67
|
+
const search = execOptions.nativeRequire || package.startsWith("node:")
|
68
|
+
? require(
|
69
|
+
package.startsWith("node:")
|
70
|
+
? package.split("node:")[1]
|
71
|
+
: package,
|
72
|
+
)
|
73
|
+
: customRequire(package, filepath);
|
74
|
+
if(!search) throw new Error("Module " + package + " not found");
|
75
|
+
return search;
|
76
|
+
} catch (e) {
|
77
|
+
throw e;
|
78
|
+
}
|
79
|
+
};
|
77
80
|
context.inc = (package, asserts) => {
|
78
81
|
try {
|
79
82
|
if (package.startsWith("node:") || package.startsWith("pkg:"))
|
package/lib/rew/modules/yaml.js
CHANGED
@@ -22,7 +22,7 @@ function yamlFile(file) {
|
|
22
22
|
}),
|
23
23
|
]);
|
24
24
|
|
25
|
-
return yaml.load(file.content, { schema });
|
25
|
+
return file.content.startsWith('---') ? yaml.loadAll(file.content, { schema })[0] : yaml.load(file.content, { schema });
|
26
26
|
}
|
27
27
|
|
28
28
|
const importYaml = (module.exports.importYaml = function importYaml(filepath, file) {
|
package/lib/rew/pkgs/conf.js
CHANGED
@@ -14,7 +14,7 @@ module.exports = (context) => ({
|
|
14
14
|
CONFIG_PATH,
|
15
15
|
_onImport() {
|
16
16
|
if (context.app) {
|
17
|
-
return this.create(context.app.config.package);
|
17
|
+
return this.create(context.app.config.manifest.package);
|
18
18
|
} else {
|
19
19
|
return this.create(seededID(path.basename(context.module.filepath).replace(/[-_/\.]/g, '')));
|
20
20
|
}
|
@@ -82,7 +82,7 @@ module.exports = (context) => ({
|
|
82
82
|
};
|
83
83
|
|
84
84
|
return {
|
85
|
-
get: (key, defaultValue) => getData(optionCenter, key)
|
85
|
+
get: (key, defaultValue) => getData(optionCenter, key) ?? defaultValue,
|
86
86
|
set: (key, value) => setData(optionCenter, key, value),
|
87
87
|
remove: (key) => removeData(optionCenter, key),
|
88
88
|
reset: () => fs.writeFileSync(optionCenter.root, dumpYaml(defaults)) && (conf[name] = defaults),
|
@@ -101,6 +101,7 @@ module.exports = (context) => ({
|
|
101
101
|
remove: (key) => defaultCenter.remove(key),
|
102
102
|
root: rootPath,
|
103
103
|
package: packageName,
|
104
|
+
loadYaml: (file) => jsYaml.load(fs.readFileSync(file, { encoding: 'utf-8' }))
|
104
105
|
};
|
105
106
|
},
|
106
107
|
});
|
package/lib/rew/pkgs/rune.js
CHANGED
@@ -169,6 +169,7 @@ const createDB = (dbName, dirname, dbData = {}, encryptionKey) => {
|
|
169
169
|
};
|
170
170
|
|
171
171
|
const update = (caseRecord, newRecord) => {
|
172
|
+
|
172
173
|
let id;
|
173
174
|
if (typeof caseRecord === 'string') {
|
174
175
|
id = caseRecord;
|
@@ -224,6 +225,9 @@ const createDB = (dbName, dirname, dbData = {}, encryptionKey) => {
|
|
224
225
|
if (typeof criteria == 'string') return read(criteria);
|
225
226
|
if (!criteria || typeof criteria !== 'object') return null;
|
226
227
|
|
228
|
+
|
229
|
+
if (!fs.existsSync(collectionFilePath)) writeDataFile(collectionFilePath, []);
|
230
|
+
|
227
231
|
const data = readDataFile(collectionFilePath);
|
228
232
|
const record =
|
229
233
|
data.find((record) => {
|
@@ -240,7 +244,6 @@ const createDB = (dbName, dirname, dbData = {}, encryptionKey) => {
|
|
240
244
|
|
241
245
|
const remove = (id) => {
|
242
246
|
if ('@rune.id' in id) id = id['@rune.id'];
|
243
|
-
if (!fs.existsSync(collectionFilePath)) return false;
|
244
247
|
let data = readDataFile(collectionFilePath);
|
245
248
|
const index = data.findIndex((record) => record['@rune.id'] === id);
|
246
249
|
if (index !== -1) {
|
@@ -293,6 +296,8 @@ const createDB = (dbName, dirname, dbData = {}, encryptionKey) => {
|
|
293
296
|
return sortedData;
|
294
297
|
};
|
295
298
|
|
299
|
+
if (!fs.existsSync(collectionFilePath)) writeDataFile(collectionFilePath, []);
|
300
|
+
|
296
301
|
return {
|
297
302
|
insert,
|
298
303
|
read,
|
@@ -377,6 +382,8 @@ const createDB = (dbName, dirname, dbData = {}, encryptionKey) => {
|
|
377
382
|
return data;
|
378
383
|
};
|
379
384
|
|
385
|
+
if (!fs.existsSync(mapFilePath)) writeDataFile(mapFilePath, {});
|
386
|
+
|
380
387
|
return { set, get, remove, list, transform };
|
381
388
|
};
|
382
389
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@makano/rew",
|
3
|
-
"version": "1.2.
|
3
|
+
"version": "1.2.5",
|
4
4
|
"description": "A simple coffescript runtime and app manager",
|
5
5
|
"main": "main.js",
|
6
6
|
"directories": {
|
@@ -11,6 +11,8 @@
|
|
11
11
|
},
|
12
12
|
"files": [
|
13
13
|
"lib/",
|
14
|
+
"runtime.d.ts",
|
15
|
+
"jsconfig.json",
|
14
16
|
"main.js",
|
15
17
|
"README.md"
|
16
18
|
],
|
@@ -38,6 +40,7 @@
|
|
38
40
|
"colors": "^1.4.0",
|
39
41
|
"deasync": "^0.1.30",
|
40
42
|
"js-yaml": "^4.1.0",
|
43
|
+
"loading-cli": "^1.1.2",
|
41
44
|
"tiny-msgpack": "^2.2.0",
|
42
45
|
"uuid": "^9.0.1",
|
43
46
|
"vm": "^0.1.0",
|