@makano/rew 1.2.4 → 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/jsconfig.json +13 -0
- package/lib/rew/cli/cli.js +24 -1
- package/lib/rew/cli/log.js +5 -1
- package/lib/rew/cli/run.js +2 -2
- package/lib/rew/cli/utils.js +109 -53
- package/lib/rew/const/default.js +3 -0
- package/lib/rew/const/opt.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/modules/compiler.js +29 -2
- package/lib/rew/pkgs/conf.js +1 -1
- package/lib/rew/pkgs/rune.js +8 -1
- package/package.json +4 -1
- package/runtime.d.ts +371 -0
package/jsconfig.json
ADDED
package/lib/rew/cli/cli.js
CHANGED
@@ -48,6 +48,11 @@ yargs(hideBin(process.argv))
|
|
48
48
|
alias: 'w',
|
49
49
|
describe: 'Watch the file for changes',
|
50
50
|
type: 'boolean',
|
51
|
+
})
|
52
|
+
.option('compile', {
|
53
|
+
alias: 'c',
|
54
|
+
describe: 'Compile and output the javascript',
|
55
|
+
type: 'boolean',
|
51
56
|
});
|
52
57
|
},
|
53
58
|
(argv) => {
|
@@ -56,7 +61,7 @@ yargs(hideBin(process.argv))
|
|
56
61
|
log('File not found:'.red.bold, argv.file, ':end');
|
57
62
|
return;
|
58
63
|
}
|
59
|
-
utils.runFileWithArgv(filePath, { watch: argv.watch });
|
64
|
+
utils.runFileWithArgv(filePath, { onlyCompile: argv.compile, watch: argv.watch });
|
60
65
|
},
|
61
66
|
)
|
62
67
|
.command(
|
@@ -223,6 +228,10 @@ yargs(hideBin(process.argv))
|
|
223
228
|
alias: 'r',
|
224
229
|
describe: 'Install requirements of the app',
|
225
230
|
type: 'boolean',
|
231
|
+
}).option('verbose', {
|
232
|
+
alias: 'v',
|
233
|
+
describe: 'Verbose',
|
234
|
+
type: 'boolean',
|
226
235
|
}).option('update', {
|
227
236
|
alias: 'u',
|
228
237
|
describe: 'Update the app',
|
@@ -280,6 +289,20 @@ yargs(hideBin(process.argv))
|
|
280
289
|
}
|
281
290
|
},
|
282
291
|
)
|
292
|
+
|
293
|
+
.command(
|
294
|
+
'cache <command>',
|
295
|
+
'Manage cache',
|
296
|
+
(yargs) => {
|
297
|
+
yargs.positional('command', {
|
298
|
+
describe: 'Command to clear/list',
|
299
|
+
type: 'string',
|
300
|
+
});
|
301
|
+
},
|
302
|
+
async (argv) => {
|
303
|
+
utils.cache(argv.command)
|
304
|
+
},
|
305
|
+
)
|
283
306
|
.command(
|
284
307
|
'repo <command> [name] [url]',
|
285
308
|
'Manage install repositories',
|
package/lib/rew/cli/log.js
CHANGED
@@ -4,6 +4,8 @@ const middlePrefix = '├';
|
|
4
4
|
const separator = '│';
|
5
5
|
const endPrefix = '╰';
|
6
6
|
|
7
|
+
let last = '';
|
8
|
+
|
7
9
|
const log = (module.exports.log = function (...toPrint) {
|
8
10
|
let prefix = start ? startPrefix : middlePrefix;
|
9
11
|
let returns = false;
|
@@ -16,8 +18,10 @@ const log = (module.exports.log = function (...toPrint) {
|
|
16
18
|
toPrint.pop();
|
17
19
|
}
|
18
20
|
if (prefix == endPrefix && start) prefix = separator;
|
19
|
-
if
|
21
|
+
// if(last == endPrefix && prefix == separator) prefix = startPrefix;
|
22
|
+
if (!start) console.log(last == endPrefix ? startPrefix : separator);
|
20
23
|
if (start) start = false;
|
24
|
+
last = prefix;
|
21
25
|
if (returns) return [prefix, ...toPrint].join(' ');
|
22
26
|
else console.log(prefix, ...toPrint);
|
23
27
|
});
|
package/lib/rew/cli/run.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
// run.js
|
2
2
|
const { run } = require('../main');
|
3
3
|
|
4
|
-
function exec(filePath, argv) {
|
5
|
-
return run(filePath, { argv })?.context?.module?.imports || [];
|
4
|
+
function exec(filePath, argv, options = {}) {
|
5
|
+
return run(filePath, { argv, ...options })?.context?.module?.imports || [];
|
6
6
|
}
|
7
7
|
|
8
8
|
module.exports = { execRewFile: exec };
|
package/lib/rew/cli/utils.js
CHANGED
@@ -14,9 +14,14 @@ const { req } = require('../misc/req');
|
|
14
14
|
const { CONFIG_PATH } = require('../const/config_path');
|
15
15
|
const { watch } = require('chokidar');
|
16
16
|
const { execRewFile } = require('./run');
|
17
|
+
const { seededID } = require('../misc/seededid');
|
18
|
+
const loading = require('loading-cli');
|
19
|
+
const sleep = require('../functions/sleep');
|
20
|
+
const { gen_key } = require('../misc/bin');
|
17
21
|
|
18
22
|
const binpath = path.join(conf({}).create('').root, '.bin');
|
19
23
|
const logspath = path.join(conf({}).create('').root, '.logs');
|
24
|
+
const cachepath = path.join(conf({}).create('').root, '.cache');
|
20
25
|
const localBinPath = path.join(binpath, '../../../', 'bin');
|
21
26
|
|
22
27
|
module.exports = {
|
@@ -30,7 +35,7 @@ module.exports = {
|
|
30
35
|
|
31
36
|
const runIt = () => {
|
32
37
|
if (options.watch) console.clear();
|
33
|
-
const imports = execRewFile(filePath, [filePath, ...(argv || [])]);
|
38
|
+
const imports = execRewFile(filePath, [filePath, ...(argv || [])], { onlyCompile: options?.onlyCompile });
|
34
39
|
if (options.watch) {
|
35
40
|
imports.forEach((file) => {
|
36
41
|
watchIt(file);
|
@@ -59,15 +64,19 @@ module.exports = {
|
|
59
64
|
if (!fullPath || fullPath == 'list') {
|
60
65
|
return fs.readdirSync(con.CONFIG_PATH).join('\n');
|
61
66
|
} else {
|
62
|
-
|
63
|
-
|
67
|
+
let name = fullPath.indexOf('/') ? fullPath.split('/')[0] : fullPath;
|
68
|
+
let dpath = fullPath.indexOf('/') ? fullPath.split('/').slice(1).join('/') : '';
|
69
|
+
if(fullPath.startsWith('/')){
|
70
|
+
dpath = name;
|
71
|
+
name = '';
|
72
|
+
}
|
64
73
|
const root = con.create(name);
|
65
74
|
if (dpath) {
|
66
75
|
const fp = path.join(root.root, dpath);
|
67
|
-
if (fs.existsSync(fp) && fs.statSync(fp).isDirectory()) {
|
76
|
+
if (!fullPath.startsWith('/') && fs.existsSync(fp) && fs.statSync(fp).isDirectory()) {
|
68
77
|
return fs.readdirSync(fp).join('\n');
|
69
78
|
} else {
|
70
|
-
const o =
|
79
|
+
const o = dpath && dpath !== '/' ? root.optionCenter(dpath) : root.optionCenter('_default');
|
71
80
|
return key ? o.get(key) : o.getAll(true);
|
72
81
|
}
|
73
82
|
} else {
|
@@ -75,14 +84,18 @@ module.exports = {
|
|
75
84
|
}
|
76
85
|
}
|
77
86
|
} else {
|
78
|
-
|
79
|
-
|
80
|
-
if
|
87
|
+
let name = fullPath.indexOf('/') ? fullPath.split('/')[0] : fullPath;
|
88
|
+
let dpath = fullPath.indexOf('/') ? fullPath.split('/')[1] : '';
|
89
|
+
if(fullPath.startsWith('/')){
|
90
|
+
dpath = name == '/' ? '_default' : name;
|
91
|
+
name = '';
|
92
|
+
}
|
93
|
+
if (key) {
|
81
94
|
const root = con.create(name);
|
82
95
|
const o = dpath ? root.optionCenter(dpath) : root;
|
83
96
|
if (command == 'set') {
|
84
97
|
if (value) {
|
85
|
-
o.set(key, value);
|
98
|
+
o.set(key, value == 'false' || value == 'true' ? (value == 'true' ? true : false) : !isNaN(parseFloat(value)) ? parseFloat(value) : value);
|
86
99
|
} else {
|
87
100
|
log('Value not specified', ':end');
|
88
101
|
}
|
@@ -90,7 +103,7 @@ module.exports = {
|
|
90
103
|
o.remove(key);
|
91
104
|
}
|
92
105
|
} else {
|
93
|
-
log(
|
106
|
+
log('Key not specified', ':end');
|
94
107
|
}
|
95
108
|
}
|
96
109
|
},
|
@@ -113,6 +126,10 @@ module.exports = {
|
|
113
126
|
fs.writeFileSync(path.join(projectPath, '.gitignore'), `node_modules/\npackage-lock.json`);
|
114
127
|
execSync('cd ' + projectPath + ' && git init . && git branch -m main', { stdio: 'ignore' });
|
115
128
|
}
|
129
|
+
if(project.intellisense){
|
130
|
+
fs.copyFileSync(path.join(__dirname, '../../../jsconfig.json'), path.join(projectPath, 'jsconfig.json'));
|
131
|
+
fs.copyFileSync(path.join(__dirname, '../../../runtime.d.ts'), path.join(projectPath, 'runtime.d.ts'));
|
132
|
+
}
|
116
133
|
execSync('cd ' + projectPath + ' && npm init -y', { stdio: 'ignore' });
|
117
134
|
// log('Installing '+npm_package_name);
|
118
135
|
// exec('cd '+projectPath+' && npm i '+npm_package_name, (err) => {
|
@@ -130,9 +147,12 @@ module.exports = {
|
|
130
147
|
rl.question(logget(' Package Name: '.blue), (pkg) => {
|
131
148
|
if (pkg.trim()) {
|
132
149
|
project.package = pkg.trim();
|
133
|
-
rl.question(logget('
|
134
|
-
project.
|
135
|
-
|
150
|
+
rl.question(logget(' Use intellisense declarations ? (y/N): '.magenta.bold), (inteli) => {
|
151
|
+
project.intellisense = inteli.toLowerCase() == 'y' || inteli.toLowerCase() == 'yes';
|
152
|
+
rl.question(logget(' Use git ? (y/N): '.yellow.bold), (use_git) => {
|
153
|
+
project.git = use_git.toLowerCase() == 'y' || use_git.toLowerCase() == 'yes';
|
154
|
+
create();
|
155
|
+
});
|
136
156
|
});
|
137
157
|
} else {
|
138
158
|
rl.close();
|
@@ -195,28 +215,29 @@ module.exports = {
|
|
195
215
|
});
|
196
216
|
log(' Installing '.blue + pname.green.bold);
|
197
217
|
log(' Package'.blue + ': ' + p.name.green + '@' + p.version.yellow);
|
198
|
-
if (p.
|
199
|
-
log(' Description'.blue + '
|
218
|
+
if (p.description) {
|
219
|
+
log(' Description'.blue + '\n' + p.description.split('\n').map((i, ind, a) => ' '+(ind == 0 && a.length > 1 ? log.startPrefix : (a.length-1 == ind ? log.endPrefix : log.middlePrefix))+' '+i).join('\n'), ':end');
|
220
|
+
}
|
221
|
+
if (p.keywords && p.keywords.length) {
|
222
|
+
log(' Tags'.blue + '\n ' + log.endPrefix + p.keywords.map(i => '#'+i).join(' '), ':end')
|
200
223
|
}
|
201
224
|
const done = (f) => {
|
202
225
|
if (f.toLowerCase() == 'y' || f.toLowerCase() == 'yes') {
|
203
226
|
if (fs.existsSync(installPath)) {
|
204
227
|
execSync(`rm -r ${installPath}`);
|
205
228
|
}
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
execSync(`rm -r ${apppath}`);
|
210
|
-
}
|
211
|
-
log(' Installed '.green + pname.cyan.bold, c.install ? '' : ':end');
|
212
|
-
if (c.install) {
|
213
|
-
if (c.install.build) {
|
214
|
-
log(' Building'.blue);
|
229
|
+
if (c.install?.build) {
|
230
|
+
log(' Building'.blue);
|
231
|
+
try{
|
215
232
|
this.build({
|
216
233
|
...c.install.build,
|
217
|
-
file: path.join(
|
234
|
+
file: path.join(apppath, c.exec[c.install.build.file] || c.install.build.file)
|
218
235
|
});
|
219
|
-
}
|
236
|
+
} catch(e){}
|
237
|
+
}
|
238
|
+
execSync(`cp -r ${apppath} ${installPath}`);
|
239
|
+
execSync(`chmod 444 ${installPath}/app.yaml`);
|
240
|
+
if (c.install) {
|
220
241
|
if (c.install.commands) {
|
221
242
|
for (let command of c.install.commands) {
|
222
243
|
try{
|
@@ -224,7 +245,7 @@ module.exports = {
|
|
224
245
|
} catch(e){
|
225
246
|
const logFile = path.join(logspath, 'logs-'+Date.now()+'.log');
|
226
247
|
fs.writeFileSync(logFile, e.toString() +'\n'+ e.stack);
|
227
|
-
log(` Command Failed: ${command}, check logs at ${logFile}
|
248
|
+
log(` Command Failed: ${command}, check logs at ${logFile}`);
|
228
249
|
}
|
229
250
|
}
|
230
251
|
}
|
@@ -232,28 +253,32 @@ module.exports = {
|
|
232
253
|
this.runFileWithArgv(path.join(installPath, c.exec[c.install.file] || c.install.file), {}, []);
|
233
254
|
}
|
234
255
|
if (c.install.requirements) {
|
235
|
-
this.installReq(c);
|
256
|
+
this.installReq(c, opts);
|
236
257
|
}
|
237
258
|
if (c.install.exec) {
|
238
259
|
// this.installReq(c);
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
260
|
+
if(conf({}).create('').get('executables') == false){
|
261
|
+
log(' Ignoring executables'.blue);
|
262
|
+
} else {
|
263
|
+
for (let i in c.install.exec) {
|
264
|
+
let iff = c.install.exec[i];
|
265
|
+
if (iff in c.exec) iff = c.exec[iff];
|
266
|
+
const file = path.join(installPath, iff);
|
267
|
+
const filepath = path.join(binpath, i);
|
268
|
+
const binfp = path.join(localBinPath, i);
|
269
|
+
if (!fs.existsSync(localBinPath)) fs.mkdirSync(localBinPath, { recursive: true });
|
270
|
+
fs.writeFileSync(filepath, `#!/usr/bin/env bash\n#@app.${pname}\nrew ${file} $*`);
|
271
|
+
fs.chmodSync(filepath, '755');
|
272
|
+
if(fs.existsSync(binfp)) fs.unlinkSync(binfp);
|
273
|
+
fs.linkSync(filepath, binfp);
|
274
|
+
}
|
249
275
|
}
|
250
276
|
}
|
277
|
+
|
278
|
+
log(' Installed '.green + pname.cyan.bold, ':end');
|
251
279
|
}
|
252
280
|
rl.close();
|
253
281
|
} else {
|
254
|
-
if (rmidiri) {
|
255
|
-
execSync(`rm -rf ${apppath}`);
|
256
|
-
}
|
257
282
|
log(' Canceled install'.red.bold, ':end');
|
258
283
|
rl.close();
|
259
284
|
}
|
@@ -355,21 +380,51 @@ module.exports = {
|
|
355
380
|
processFile(filePath, importsArray);
|
356
381
|
log(' Compiled'.yellow, (importsArray.length + 1 + '').blue, `file${importsArray.length ? 's' : ''}.`.yellow, ':end');
|
357
382
|
},
|
358
|
-
|
383
|
+
cache(command){
|
384
|
+
if(command == 'list'){
|
385
|
+
console.log(fs.readdirSync(cachepath).join('\n').trim());
|
386
|
+
} else {
|
387
|
+
fs.readdirSync(cachepath).forEach(file => fs.rmSync(path.join(cachepath, file), { recursive: true }));
|
388
|
+
}
|
389
|
+
},
|
390
|
+
async cloneGit(gitpath, opts) {
|
359
391
|
const p = gitpath.split('github:')[1];
|
392
|
+
const clonePath = path.join(cachepath, 'rew-git-clone-'+gen_key(gitpath).substring(0, 12));
|
360
393
|
const url = `https://github.com/${p}`;
|
361
|
-
const apiurl = `https://api.github.com/repos/${p}`;
|
394
|
+
const apiurl = `https://api.github.com/repos/${p}/commits`;
|
395
|
+
const load = loading("Finding Repo...".yellow).start();
|
362
396
|
try {
|
363
397
|
const response = await req(apiurl);
|
364
|
-
if (response.status !== 200)
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
398
|
+
if (response.status !== 200) {
|
399
|
+
load.stop();
|
400
|
+
return log(' Package not found in github'.red.bold, ':end');
|
401
|
+
}
|
402
|
+
let pull = false;
|
403
|
+
if(fs.existsSync(clonePath)){
|
404
|
+
if(fs.existsSync(path.join(clonePath, response.data[0].sha))){
|
405
|
+
load.stop();
|
406
|
+
log('Found Cache'.yellow);
|
407
|
+
return clonePath+'/clone';
|
408
|
+
} else {
|
409
|
+
pull = true;
|
410
|
+
}
|
411
|
+
}
|
412
|
+
fs.mkdirSync(clonePath, { recursive: true });
|
413
|
+
fs.writeFileSync(path.join(clonePath, response.data[0].sha), '');
|
414
|
+
load.text = 'Cloning from github'.blue.bold;
|
415
|
+
await sleep(100)
|
416
|
+
if(pull) execSync(`cd ${clonePath}/clone && git pull`, { stdio: opts.verbose ? 'inherit' : 'ignore' });
|
417
|
+
else execSync(`git clone ${url} ${clonePath}/clone`, { stdio: opts.verbose ? 'pipe' : 'ignore' });
|
418
|
+
load.text = 'Installing npm packages'.green.bold;
|
419
|
+
await sleep(100)
|
420
|
+
execSync(`cd ${clonePath}/clone && npm i`, { stdio: opts.verbose ? 'inherit' : 'ignore' });
|
421
|
+
load.stop();
|
422
|
+
return clonePath+'/clone';
|
371
423
|
} catch (e) {
|
372
|
-
|
424
|
+
const logFile = path.join(logspath, 'logs-'+Date.now()+'.log');
|
425
|
+
fs.writeFileSync(logFile, e.toString() +'\n'+ e.stack);
|
426
|
+
load.stop();
|
427
|
+
log(' Something went wrong, check logs at'.red.bold, logFile.green, ':end');
|
373
428
|
}
|
374
429
|
},
|
375
430
|
findRepo(repo) {
|
@@ -377,7 +432,7 @@ module.exports = {
|
|
377
432
|
return repos.get(repo);
|
378
433
|
},
|
379
434
|
async installAppFrom(path, opts) {
|
380
|
-
if (path.startsWith('github:')) this.installApp(await this.cloneGit(path
|
435
|
+
if (path.startsWith('github:')) this.installApp(await this.cloneGit(path, opts), opts, true);
|
381
436
|
else if (path.startsWith('@')) this.fromRepo(path, opts);
|
382
437
|
else this.installApp(path, opts, null, null);
|
383
438
|
},
|
@@ -465,7 +520,7 @@ module.exports = {
|
|
465
520
|
console.log(Object.keys(confInstance.getAll()).join('\n'));
|
466
521
|
}
|
467
522
|
} else if (command === 'delete') {
|
468
|
-
confInstance.remove(
|
523
|
+
confInstance.remove(key);
|
469
524
|
} else {
|
470
525
|
log(' Invalid command'.red.bold, ':end');
|
471
526
|
}
|
@@ -474,6 +529,7 @@ module.exports = {
|
|
474
529
|
log('First time init')
|
475
530
|
conf({}).create('').optionCenter('repos').set('rewpkgs', '//raw.githubusercontent.com/kevinJ045/rewpkgs/main/main.yaml');
|
476
531
|
fs.mkdirSync(binpath, { recursive: true });
|
532
|
+
fs.mkdirSync(cachepath, { recursive: true });
|
477
533
|
fs.mkdirSync(logspath, { recursive: true });
|
478
534
|
}
|
479
535
|
};
|
package/lib/rew/const/default.js
CHANGED
@@ -12,6 +12,7 @@ const { curl } = require('../functions/curl');
|
|
12
12
|
const { wait } = require('../functions/wait');
|
13
13
|
const { scheduleFrame } = require('../functions/misc');
|
14
14
|
const { jsons, yaml, json, yamls } = require('../functions/json');
|
15
|
+
const { generateRandomID } = require('../functions/id');
|
15
16
|
|
16
17
|
module.exports = {
|
17
18
|
cenum,
|
@@ -49,6 +50,8 @@ module.exports = {
|
|
49
50
|
yaml,
|
50
51
|
yamls,
|
51
52
|
|
53
|
+
genID: generateRandomID,
|
54
|
+
|
52
55
|
curl,
|
53
56
|
|
54
57
|
print,
|
package/lib/rew/const/opt.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
const execOptions = {
|
2
2
|
sharedContext: true,
|
3
|
-
resolveExtensions: [{ ext: '.js', options: { type: 'js' } }, { ext: '.qrew', options: { qrew: true } }
|
3
|
+
resolveExtensions: ['.coffee', { ext: '.js', options: { type: 'js' } }, { ext: '.qrew', options: { qrew: true } }],
|
4
4
|
nativeRequire: false,
|
5
5
|
cwdAlias: '$',
|
6
6
|
jsxPragma: 'createElement',
|
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
|
};
|
@@ -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,
|
package/lib/rew/pkgs/conf.js
CHANGED
@@ -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),
|
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",
|
package/runtime.d.ts
ADDED
@@ -0,0 +1,371 @@
|
|
1
|
+
|
2
|
+
interface ImportOptions {
|
3
|
+
/**
|
4
|
+
* Determines how to import the given module
|
5
|
+
*/
|
6
|
+
type: 'js' | 'coffee' | 'yaml' | 'json' | 'qrew';
|
7
|
+
[key: string]: any;
|
8
|
+
}
|
9
|
+
|
10
|
+
interface ModuleConfOptionCenter {
|
11
|
+
/**
|
12
|
+
* Get a config key
|
13
|
+
* @param key The key of the config to get
|
14
|
+
* @param defaultValue The default value ig null
|
15
|
+
* @returns The value of the key or the defaultValue if it's null.
|
16
|
+
*/
|
17
|
+
get: <T = any>(key: string, defaultValue?: T) => T
|
18
|
+
/**
|
19
|
+
* Set a config key
|
20
|
+
* @param key The key of the config to set
|
21
|
+
* @param value The value to set it to
|
22
|
+
* @returns true if it was a success
|
23
|
+
*/
|
24
|
+
set: <T = any>(key: string, value: T) => boolean
|
25
|
+
/**
|
26
|
+
* Removes a key from the config
|
27
|
+
* @param key The key of the config to remove
|
28
|
+
* @returns true if it was a success
|
29
|
+
*/
|
30
|
+
remove: (key: string) => boolean
|
31
|
+
/**
|
32
|
+
* Resets the entire config option center to it's default value
|
33
|
+
*/
|
34
|
+
reset: () => boolean
|
35
|
+
/**
|
36
|
+
* Get all values in an option center
|
37
|
+
* @param str
|
38
|
+
* @returns
|
39
|
+
*/
|
40
|
+
getAll: (() => string) | ((str?: false) => Record<string, any>)
|
41
|
+
}
|
42
|
+
|
43
|
+
interface ModuleConf extends ModuleConfOptionCenter {
|
44
|
+
/**
|
45
|
+
* A separate options file for a related set of options
|
46
|
+
* @param name The option center full path
|
47
|
+
* @param defaults The default values
|
48
|
+
*
|
49
|
+
* @example
|
50
|
+
* conf = imp 'conf'
|
51
|
+
*
|
52
|
+
* animations = conf.optionCenter 'animations', enable: false, speed: '1x'
|
53
|
+
*
|
54
|
+
* if animations.get 'enable'
|
55
|
+
* animate animations.get 'speed'
|
56
|
+
*/
|
57
|
+
optionCenter: (name: string, defaults?: any) => ModuleConfOptionCenter;
|
58
|
+
/**
|
59
|
+
* Manage Static files
|
60
|
+
*/
|
61
|
+
staticFile: (name: string, defaults?: any) => {
|
62
|
+
write: (value: any, ifExists?: boolean) => this,
|
63
|
+
read: (to?: string | object) => string | object | Buffer,
|
64
|
+
fileRoot: string,
|
65
|
+
exists: boolean
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
interface ModuleEnv {
|
70
|
+
has: (key: string) => boolean,
|
71
|
+
get: (key: string) => string,
|
72
|
+
set: (key: string, value: string) => boolean,
|
73
|
+
rm: (key: string) => boolean,
|
74
|
+
is: (key: string, value: string) => boolean,
|
75
|
+
}
|
76
|
+
|
77
|
+
interface ModuleRuneDBCollcetion {
|
78
|
+
insert(record: object): any;
|
79
|
+
read(id: string | object, evaluate?: boolean): any;
|
80
|
+
update(caseRecord: string | object, newRecord: object): any;
|
81
|
+
remove(id: string | object): boolean;
|
82
|
+
find(criteria: string | object): any;
|
83
|
+
map(cb: (data: any[]) => any[], mutate?: boolean): any[];
|
84
|
+
transform(cb: (data: any[]) => any[], mutate?: boolean): any[];
|
85
|
+
filter(cb: (data: any[]) => boolean, mutate?: boolean): any[];
|
86
|
+
sort(cb: (a: any, b: any) => number, mutate?: boolean): any[];
|
87
|
+
list(): any[];
|
88
|
+
}
|
89
|
+
|
90
|
+
interface ModuleRuneDBMap {
|
91
|
+
set(key: string, value: any): void;
|
92
|
+
get(key: string): any | null;
|
93
|
+
remove(key: string): boolean;
|
94
|
+
transform(cb: (data: any) => any, mutate?: boolean): any;
|
95
|
+
list(): { [key: string]: any };
|
96
|
+
}
|
97
|
+
|
98
|
+
interface ModuleRuneDB {
|
99
|
+
collection: (name: string) => ModuleRuneDBCollcetion
|
100
|
+
map: (name: string) => ModuleRuneDBMap
|
101
|
+
findRef: (ref: string) => any
|
102
|
+
setData: (data: Record<string, any>) => void
|
103
|
+
getData: () => Record<string, any>
|
104
|
+
makeRef(value: object, props?: string): string | null;
|
105
|
+
}
|
106
|
+
|
107
|
+
interface ModuleRune {
|
108
|
+
db(dbname: string, data?: object, encryptionKey?: string): ModuleRuneDB;
|
109
|
+
genKey(secret: string): string;
|
110
|
+
push(...values: any[]): PushChange;
|
111
|
+
pop(...values: any[]): PopChange;
|
112
|
+
}
|
113
|
+
|
114
|
+
interface ModuleThreads {
|
115
|
+
thread: (cb: Function) => {
|
116
|
+
stopAll: () => void
|
117
|
+
start: (context: Record<string, any>) => {
|
118
|
+
on: (event: string, callback: (data) => void) => void;
|
119
|
+
off: (event: string, callback: (data) => void) => void;
|
120
|
+
emit: (event: string, data: any) => void;
|
121
|
+
get: () => Promise,
|
122
|
+
stop: () => void
|
123
|
+
}
|
124
|
+
}
|
125
|
+
}
|
126
|
+
|
127
|
+
declare function imp(path: "conf", options?: ImportOptions): ModuleConf;
|
128
|
+
declare function imp(path: "env", options?: ImportOptions): ModuleEnv;
|
129
|
+
declare function imp(path: "rune", options?: ImportOptions): ModuleRune;
|
130
|
+
declare function imp(path: "threads", options?: ImportOptions): ModuleThreads;
|
131
|
+
declare function imp(path: string, options?: ImportOptions): any;
|
132
|
+
|
133
|
+
declare const inc = imp;
|
134
|
+
|
135
|
+
declare function require(moduleName: string): any;
|
136
|
+
|
137
|
+
interface Module {
|
138
|
+
exports: any;
|
139
|
+
filepath: string;
|
140
|
+
main: boolean;
|
141
|
+
impots: string[];
|
142
|
+
compiled: string
|
143
|
+
}
|
144
|
+
|
145
|
+
declare const module: Module;
|
146
|
+
|
147
|
+
interface Imports {
|
148
|
+
meta: {},
|
149
|
+
assets: any
|
150
|
+
}
|
151
|
+
|
152
|
+
declare const imports: Imports;
|
153
|
+
|
154
|
+
declare const process: {
|
155
|
+
argv: string[],
|
156
|
+
target: ReturnType<typeof emitter>,
|
157
|
+
__execFile: string,
|
158
|
+
env: Record<string, any>,
|
159
|
+
cwd: () => string,
|
160
|
+
arch: string,
|
161
|
+
exit: () => void
|
162
|
+
};
|
163
|
+
|
164
|
+
interface AppConfig {
|
165
|
+
manifest: {
|
166
|
+
package: string
|
167
|
+
}
|
168
|
+
}
|
169
|
+
|
170
|
+
declare const app: {
|
171
|
+
path: string,
|
172
|
+
config: AppConfig
|
173
|
+
}
|
174
|
+
|
175
|
+
|
176
|
+
declare function read(filepath: string, options?: { encoding: string }): string;
|
177
|
+
|
178
|
+
declare function realpath(filepath: string, options?: { encoding: string }): string;
|
179
|
+
|
180
|
+
declare function write(filepath: string, content: any, options?: any): void;
|
181
|
+
|
182
|
+
declare function exists(filepath: string, options?: any): boolean;
|
183
|
+
|
184
|
+
declare function fstat(filepath: string, options?: any): any;
|
185
|
+
|
186
|
+
declare function rm(filepath: string, options?: any): void;
|
187
|
+
|
188
|
+
declare function chmod(filepath: string, mode: any, options?: any): void;
|
189
|
+
|
190
|
+
declare function mkdir(filepath: string, options?: any): void;
|
191
|
+
|
192
|
+
declare function ls(filepath: string, options?: any): string[];
|
193
|
+
|
194
|
+
declare function struct(template: { [key: string]: any }): (...args: any[]) => any;
|
195
|
+
|
196
|
+
declare function future(callback: (resolve: (data: any) => void, reject: (data: any) => void) => void, timeout?: number, defData?: any): {
|
197
|
+
pipe(callback: (data: any) => any): Promise<any>;
|
198
|
+
last(callback: (data: any) => any): Promise<any>;
|
199
|
+
catch(callback: (data: any) => any): Promise<any>;
|
200
|
+
resolve(data: any): void;
|
201
|
+
reject(data: any): void;
|
202
|
+
wait(): Promise<any>;
|
203
|
+
};
|
204
|
+
declare namespace future {
|
205
|
+
function promise(promse: Promise<any>, timeout?: number, defData?: any): ReturnType<typeof future>;
|
206
|
+
}
|
207
|
+
|
208
|
+
declare function emitter(): {
|
209
|
+
on(event: string | string[], callback: (...args: any[]) => void, props?: {}): ReturnType<typeof emitter>;
|
210
|
+
off(event: string | string[], callback: (...args: any[]) => void, removable?: (event: any) => void): ReturnType<typeof emitter>;
|
211
|
+
emit(event: string | string[], ...data: any[]): ReturnType<typeof emitter>;
|
212
|
+
};
|
213
|
+
declare function exec(command: string, options?: { output?: boolean }): any;
|
214
|
+
declare namespace exec {
|
215
|
+
function background(command: string, options?: any, callback?: (...args: any[]) => void): any;
|
216
|
+
}
|
217
|
+
declare function spawn(command: string, ...args: any[]): any;
|
218
|
+
|
219
|
+
declare function typedef(value: any, strict?: boolean): { strict: boolean; defaultValue: any; class: Function; type: string; isConstucted: boolean; isEmpty: boolean };
|
220
|
+
|
221
|
+
declare function typeis(obj: any, typeDef: any): boolean;
|
222
|
+
|
223
|
+
declare function typex(child: any, parent: any): boolean;
|
224
|
+
|
225
|
+
declare function typei(child: any, parent: any): boolean;
|
226
|
+
|
227
|
+
declare function int(str: string): number;
|
228
|
+
|
229
|
+
declare namespace int {
|
230
|
+
const type: { strict: boolean; defaultValue: number; class: Function; type: string; isConstucted: boolean; isEmpty: boolean };
|
231
|
+
}
|
232
|
+
declare function float(str: string): number;
|
233
|
+
declare namespace float {
|
234
|
+
const type: { strict: boolean; defaultValue: number; class: Function; type: string; isConstucted: boolean; isEmpty: boolean };
|
235
|
+
}
|
236
|
+
declare function num(str: string): number;
|
237
|
+
declare namespace num {
|
238
|
+
const type: { strict: boolean; defaultValue: number; class: Function; type: string; isConstucted: boolean; isEmpty: boolean };
|
239
|
+
}
|
240
|
+
declare function str(str: any): string;
|
241
|
+
declare namespace str {
|
242
|
+
const type: { strict: boolean; defaultValue: string; class: Function; type: string; isConstucted: boolean; isEmpty: boolean };
|
243
|
+
}
|
244
|
+
declare function bool(value: any): boolean;
|
245
|
+
declare namespace bool {
|
246
|
+
const type: { strict: boolean; defaultValue: boolean; class: Function; type: string; isConstucted: boolean; isEmpty: boolean };
|
247
|
+
}
|
248
|
+
declare function isEmpty(value: any): boolean;
|
249
|
+
declare function clone(value: any): any;
|
250
|
+
declare function deepClone(value: any): any;
|
251
|
+
declare function merge(obj1: any, obj2: any): any;
|
252
|
+
declare const uniqueId: () => string;
|
253
|
+
declare function filter(arr: any[], fn: (value: any) => boolean): any[];
|
254
|
+
declare function reduce(arr: any[], fn: (acc: any, value: any) => any, initial: any): any;
|
255
|
+
declare function compose(...fns: Function[]): (initialValue: any) => any;
|
256
|
+
declare function curry(fn: Function): (...args: any[]) => any;
|
257
|
+
declare function json(thing: string): any;
|
258
|
+
declare function jsons(thing: any): string;
|
259
|
+
declare function yaml(thing: any): any;
|
260
|
+
declare function yamls(thing: any): string;
|
261
|
+
|
262
|
+
|
263
|
+
/**
|
264
|
+
* Makes a HTTP request to the specified URL.
|
265
|
+
* @param url The URL to request.
|
266
|
+
* @param options The options for the request.
|
267
|
+
* @returns A promise resolving to the response or other specified output based on the options.
|
268
|
+
*/
|
269
|
+
declare function curl(url: string, options: {
|
270
|
+
/**
|
271
|
+
* Indicates whether to return a promise.
|
272
|
+
*/
|
273
|
+
a: true,
|
274
|
+
/**
|
275
|
+
* Indicates whether to return the response as plain text.
|
276
|
+
*/
|
277
|
+
text: true,
|
278
|
+
o?: string
|
279
|
+
}): Promise<string>;
|
280
|
+
/**
|
281
|
+
* Makes a HTTP request to the specified URL.
|
282
|
+
* @param url The URL to request.
|
283
|
+
* @param options The options for the request.
|
284
|
+
* @returns A promise resolving to the response or other specified output based on the options.
|
285
|
+
*/
|
286
|
+
declare function curl(url: string, options: {
|
287
|
+
/**
|
288
|
+
* Indicates whether to return a promise.
|
289
|
+
*/
|
290
|
+
a: true,
|
291
|
+
/**
|
292
|
+
* Indicates whether to return the response as JSON.
|
293
|
+
*/
|
294
|
+
json: true,
|
295
|
+
/**
|
296
|
+
* The file path to output the response.
|
297
|
+
*/
|
298
|
+
o?: string
|
299
|
+
}): Promise<object>;
|
300
|
+
/**
|
301
|
+
* Makes a HTTP request to the specified URL.
|
302
|
+
* @param url The URL to request.
|
303
|
+
* @param options The options for the request.
|
304
|
+
* @returns A promise resolving to the response or other specified output based on the options.
|
305
|
+
*/
|
306
|
+
declare function curl(url: string, options: {
|
307
|
+
/**
|
308
|
+
* Indicates whether to return a promise.
|
309
|
+
*/
|
310
|
+
a: true,
|
311
|
+
/**
|
312
|
+
* The file path to output the response.
|
313
|
+
*/
|
314
|
+
o?: string
|
315
|
+
}): Promise<Response>;
|
316
|
+
|
317
|
+
/**
|
318
|
+
* Makes a HTTP request to the specified URL.
|
319
|
+
* @param url The URL to request.
|
320
|
+
* @param options The options for the request.
|
321
|
+
* @returns A promise resolving to the response or other specified output based on the options.
|
322
|
+
*/
|
323
|
+
declare function curl(url: string, options?: {
|
324
|
+
/**
|
325
|
+
* Indicates whether to return a promise.
|
326
|
+
*/
|
327
|
+
a?: boolean,
|
328
|
+
/**
|
329
|
+
* The file path to output the response.
|
330
|
+
*/
|
331
|
+
o?: string,
|
332
|
+
/**
|
333
|
+
* Indicates whether to return the response as JSON.
|
334
|
+
*/
|
335
|
+
json?: boolean,
|
336
|
+
/**
|
337
|
+
* Indicates whether to return the response as plain text.
|
338
|
+
*/
|
339
|
+
text?: boolean
|
340
|
+
}): ReturnType<typeof future>;
|
341
|
+
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
declare function print(...args: any[]): void;
|
346
|
+
declare namespace print {
|
347
|
+
const stdout: WriteStream;
|
348
|
+
const stdin: ReadStream;
|
349
|
+
};
|
350
|
+
|
351
|
+
declare function input(prompt: string): string;
|
352
|
+
|
353
|
+
|
354
|
+
declare const basename: (path: string) => string;
|
355
|
+
declare const dirname: (path: string) => string;
|
356
|
+
declare const extname: (path: string) => string;
|
357
|
+
declare const pjoin: (...paths: string[]) => string;
|
358
|
+
declare const presolve: (...paths: string[]) => string;
|
359
|
+
|
360
|
+
declare function exports(value: any) : any;
|
361
|
+
|
362
|
+
declare function pub(value: any) : any;
|
363
|
+
declare function pub(name: string, value: any) : any;
|
364
|
+
|
365
|
+
declare const opt: {
|
366
|
+
set: (key: string, value: any) => void;
|
367
|
+
get: (key: string) => any,
|
368
|
+
push: (key: string, value: any) => any,
|
369
|
+
pop: (key: string) => any,
|
370
|
+
}
|
371
|
+
|