@makano/rew 1.2.2 → 1.2.4
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/README.md +3 -0
- package/bin/rew +2 -8
- package/lib/rew/cli/cli.js +85 -72
- package/lib/rew/cli/run.js +4 -11
- package/lib/rew/cli/utils.js +158 -62
- package/lib/rew/const/default.js +12 -1
- package/lib/rew/const/files.js +3 -9
- package/lib/rew/const/pre-exec.js +3 -0
- package/lib/rew/functions/curl.js +1 -1
- package/lib/rew/functions/import.js +4 -3
- package/lib/rew/functions/json.js +27 -0
- package/lib/rew/functions/misc.js +5 -0
- package/lib/rew/functions/require.js +34 -14
- package/lib/rew/functions/sleep.js +1 -1
- package/lib/rew/functions/stdout.js +7 -4
- package/lib/rew/functions/wait.js +11 -0
- package/lib/rew/modules/compiler.js +9 -7
- package/lib/rew/modules/context.js +17 -14
- package/lib/rew/modules/runtime.js +21 -2
- package/lib/rew/modules/yaml.js +1 -1
- package/lib/rew/pkgs/conf.js +10 -2
- package/lib/rew/pkgs/rune.js +12 -6
- package/main.js +13 -0
- package/package.json +5 -6
- package/bin/ui +0 -0
- package/bin/ui_ws +0 -0
- package/bin/webkit_app +0 -0
- package/build.sh +0 -8
- package/cpp/ui.cpp +0 -217
- package/cpp/ui1.cpp +0 -101
- package/cpp/ui2.cpp +0 -105
- package/lib/rew/css/theme.css +0 -3
- package/lib/rew/html/ui.html +0 -18
- package/lib/rew/html/ui.js +0 -245
- package/lib/rew/pkgs/modules/ui/classes.js +0 -184
- package/lib/rew/pkgs/ui.js +0 -157
- package/meson.build +0 -13
package/lib/rew/cli/utils.js
CHANGED
@@ -4,7 +4,7 @@ const conf = require('../pkgs/conf');
|
|
4
4
|
const jsYaml = require('js-yaml');
|
5
5
|
const readline = require('readline');
|
6
6
|
const { log, logget } = require('./log');
|
7
|
-
const { execSync, exec } = require('child_process');
|
7
|
+
const { fork, execSync, exec } = require('child_process');
|
8
8
|
const { run } = require('../main');
|
9
9
|
const { generateRandomID } = require('../functions/id');
|
10
10
|
const { compile } = require('../modules/compiler');
|
@@ -12,10 +12,47 @@ const { to_qrew } = require('../qrew/compile');
|
|
12
12
|
const { findAppInfo } = require('../misc/findAppInfo');
|
13
13
|
const { req } = require('../misc/req');
|
14
14
|
const { CONFIG_PATH } = require('../const/config_path');
|
15
|
+
const { watch } = require('chokidar');
|
16
|
+
const { execRewFile } = require('./run');
|
15
17
|
|
16
|
-
const
|
18
|
+
const binpath = path.join(conf({}).create('').root, '.bin');
|
19
|
+
const logspath = path.join(conf({}).create('').root, '.logs');
|
20
|
+
const localBinPath = path.join(binpath, '../../../', 'bin');
|
17
21
|
|
18
22
|
module.exports = {
|
23
|
+
runFile(filePath, options = {}, argv) {
|
24
|
+
const watching = [];
|
25
|
+
const watchIt = (file) => {
|
26
|
+
if (watching.includes(file)) return;
|
27
|
+
watch(file).on('change', () => runIt());
|
28
|
+
watching.push(file);
|
29
|
+
};
|
30
|
+
|
31
|
+
const runIt = () => {
|
32
|
+
if (options.watch) console.clear();
|
33
|
+
const imports = execRewFile(filePath, [filePath, ...(argv || [])]);
|
34
|
+
if (options.watch) {
|
35
|
+
imports.forEach((file) => {
|
36
|
+
watchIt(file);
|
37
|
+
});
|
38
|
+
watchIt(filePath);
|
39
|
+
}
|
40
|
+
};
|
41
|
+
|
42
|
+
runIt();
|
43
|
+
},
|
44
|
+
runFileWithArgv(filePath, options = {}, cargv) {
|
45
|
+
const argv = cargv || process.argv;
|
46
|
+
argv.shift();
|
47
|
+
if (argv[0].endsWith('rew')) {
|
48
|
+
if (argv[1] == 'run') {
|
49
|
+
argv.splice(0, 3);
|
50
|
+
} else if(argv[1] == '-w' || argv[1] == '--watch'){
|
51
|
+
argv.splice(0, 3);
|
52
|
+
} else argv.splice(0, 2);
|
53
|
+
}
|
54
|
+
this.runFile(filePath, options, argv)
|
55
|
+
},
|
19
56
|
conf(command, fullPath, key, value) {
|
20
57
|
const con = conf({});
|
21
58
|
if (command == 'get') {
|
@@ -69,8 +106,9 @@ module.exports = {
|
|
69
106
|
fs.mkdirSync(projectPath, { recursive: true });
|
70
107
|
const confPath = path.join(projectPath, 'app.yaml');
|
71
108
|
const entryFile = path.join(projectPath, 'main.coffee');
|
72
|
-
fs.writeFileSync(confPath, jsYaml.dump({ package: project.package, entry: 'main.coffee' }));
|
109
|
+
fs.writeFileSync(confPath, jsYaml.dump({ manifest: { package: project.package, private: false }, exec: { entry: 'main.coffee' }, assets: { icon: 'assets/icon.png', folder: './assets' }, install: { requirements: [] } }));
|
73
110
|
fs.writeFileSync(entryFile, `print("Hello World!")`);
|
111
|
+
fs.mkdirSync(path.join(projectPath, 'assets'), { recursive: true });
|
74
112
|
if (project.git) {
|
75
113
|
fs.writeFileSync(path.join(projectPath, '.gitignore'), `node_modules/\npackage-lock.json`);
|
76
114
|
execSync('cd ' + projectPath + ' && git init . && git branch -m main', { stdio: 'ignore' });
|
@@ -111,22 +149,20 @@ module.exports = {
|
|
111
149
|
|
112
150
|
const runAppRoot = (root, confPath, byPath) => {
|
113
151
|
const c = jsYaml.load(fs.readFileSync(confPath, { encoding: 'utf-8' }));
|
114
|
-
if (
|
115
|
-
|
116
|
-
|
117
|
-
|
152
|
+
if (options.entry) {
|
153
|
+
c.exec.entry = c.exec[options.entry] || c.exec.entry;
|
154
|
+
}
|
155
|
+
if (c.exec.entry) {
|
156
|
+
if (byPath && options.dev) c.exec.entry = c.entry.endsWith('.qrew') ? c.exec.entry.replace(/\.qrew$/, '.coffee') : c.exec.entry;
|
157
|
+
let r = path.resolve(root, c.exec.entry);
|
158
|
+
if (options.build) {
|
118
159
|
this.build({
|
119
160
|
file: r,
|
120
161
|
translate: options.translate || false
|
121
162
|
});
|
122
|
-
r = path.resolve(root, c.entry.replace(new RegExp(path.extname(c.entry).replace('.', '\\.') + '$'), options.translate ? '.js' : '.qrew'));
|
163
|
+
r = path.resolve(root, c.exec.entry.replace(new RegExp(path.extname(c.exec.entry).replace('.', '\\.') + '$'), options.translate ? '.js' : '.qrew'));
|
123
164
|
}
|
124
|
-
|
125
|
-
const mod_path_lib = path.join(mod_path, 'lib/rew/cli');
|
126
|
-
if (fs.existsSync(mod_path) && __dirname !== mod_path_lib) {
|
127
|
-
const mod_path_utilsjs = path.join(mod_path_lib, '../main.js');
|
128
|
-
require(mod_path_utilsjs).run(r);
|
129
|
-
} else run(r);
|
165
|
+
this.runFileWithArgv(r);
|
130
166
|
}
|
131
167
|
};
|
132
168
|
|
@@ -141,7 +177,7 @@ module.exports = {
|
|
141
177
|
}
|
142
178
|
}
|
143
179
|
},
|
144
|
-
installApp(pathname, rmidir, rmidiri) {
|
180
|
+
installApp(pathname, opts, rmidir, rmidiri) {
|
145
181
|
if (!pathname) {
|
146
182
|
return;
|
147
183
|
}
|
@@ -151,7 +187,7 @@ module.exports = {
|
|
151
187
|
if (fs.existsSync(apppath) && fs.existsSync(appConfpath)) {
|
152
188
|
const c = jsYaml.load(fs.readFileSync(appConfpath, { encoding: 'utf-8' }));
|
153
189
|
const p = JSON.parse(fs.readFileSync(appPackagepath, { encoding: 'utf-8' }));
|
154
|
-
const pname = c.package;
|
190
|
+
const pname = c.manifest.package;
|
155
191
|
const installPath = path.join(conf({}).create(pname).root, 'app');
|
156
192
|
const rl = readline.createInterface({
|
157
193
|
input: process.stdin,
|
@@ -159,11 +195,11 @@ module.exports = {
|
|
159
195
|
});
|
160
196
|
log(' Installing '.blue + pname.green.bold);
|
161
197
|
log(' Package'.blue + ': ' + p.name.green + '@' + p.version.yellow);
|
162
|
-
if (p.
|
198
|
+
if (p.descriptiondescription) {
|
163
199
|
log(' Description'.blue + ': ' + p.description);
|
164
200
|
}
|
165
|
-
|
166
|
-
if (f.toLowerCase() == 'y') {
|
201
|
+
const done = (f) => {
|
202
|
+
if (f.toLowerCase() == 'y' || f.toLowerCase() == 'yes') {
|
167
203
|
if (fs.existsSync(installPath)) {
|
168
204
|
execSync(`rm -r ${installPath}`);
|
169
205
|
}
|
@@ -173,21 +209,44 @@ module.exports = {
|
|
173
209
|
execSync(`rm -r ${apppath}`);
|
174
210
|
}
|
175
211
|
log(' Installed '.green + pname.cyan.bold, c.install ? '' : ':end');
|
176
|
-
if(c.install){
|
177
|
-
if(c.install.build){
|
212
|
+
if (c.install) {
|
213
|
+
if (c.install.build) {
|
178
214
|
log(' Building'.blue);
|
179
215
|
this.build({
|
180
216
|
...c.install.build,
|
181
217
|
file: path.join(installPath, c.install.build.file)
|
182
218
|
});
|
183
219
|
}
|
184
|
-
if(c.install.commands){
|
185
|
-
for(let command of c.install.commands){
|
186
|
-
|
220
|
+
if (c.install.commands) {
|
221
|
+
for (let command of c.install.commands) {
|
222
|
+
try{
|
223
|
+
execSync(command.replace(/\$installPath/g, installPath), { stdio: 'inherit' });
|
224
|
+
} catch(e){
|
225
|
+
const logFile = path.join(logspath, 'logs-'+Date.now()+'.log');
|
226
|
+
fs.writeFileSync(logFile, e.toString() +'\n'+ e.stack);
|
227
|
+
log(` Command Failed: ${command}, check logs at ${logFile}`, ':end');
|
228
|
+
}
|
187
229
|
}
|
188
230
|
}
|
189
|
-
if(c.install.file){
|
190
|
-
|
231
|
+
if (c.install.file) {
|
232
|
+
this.runFileWithArgv(path.join(installPath, c.exec[c.install.file] || c.install.file), {}, []);
|
233
|
+
}
|
234
|
+
if (c.install.requirements) {
|
235
|
+
this.installReq(c);
|
236
|
+
}
|
237
|
+
if (c.install.exec) {
|
238
|
+
// this.installReq(c);
|
239
|
+
for (let i in c.install.exec) {
|
240
|
+
let iff = c.install.exec[i];
|
241
|
+
if (iff in c.exec) iff = c.exec[iff];
|
242
|
+
const file = path.join(installPath, iff);
|
243
|
+
const filepath = path.join(binpath, i);
|
244
|
+
const binfp = path.join(localBinPath, i);
|
245
|
+
if (!fs.existsSync(localBinPath)) fs.mkdirSync(localBinPath, { recursive: true });
|
246
|
+
fs.writeFileSync(filepath, `#!/usr/bin/env bash\n#@app.${pname}\nrew ${file} $*`);
|
247
|
+
fs.chmodSync(filepath, '755');
|
248
|
+
fs.linkSync(filepath, binfp);
|
249
|
+
}
|
191
250
|
}
|
192
251
|
}
|
193
252
|
rl.close();
|
@@ -198,12 +257,33 @@ module.exports = {
|
|
198
257
|
log(' Canceled install'.red.bold, ':end');
|
199
258
|
rl.close();
|
200
259
|
}
|
201
|
-
}
|
260
|
+
};
|
261
|
+
if (fs.existsSync(installPath) && !opts.update) {
|
262
|
+
rl.close();
|
263
|
+
log(` App Already Installed`.green.bold);
|
264
|
+
return log(` Run With --update or -u to update.`.green.bold, ':end');
|
265
|
+
}
|
266
|
+
if(opts.yes) done('y');
|
267
|
+
else rl.question(logget('Install '.blue + pname.green.bold + '? (y/N) '), done);
|
202
268
|
} else {
|
203
269
|
log(' Path is not a rew app'.red.bold, ':end');
|
204
270
|
}
|
205
271
|
},
|
206
|
-
|
272
|
+
installReq(config, opts) {
|
273
|
+
if (typeof config !== "object") {
|
274
|
+
const confPath = path.join(config, './app.yaml');
|
275
|
+
if (!fs.existsSync(confPath)) return log(' Path is not a rew app'.red.bold, ':end');
|
276
|
+
config = jsYaml.load(fs.readFileSync(confPath, { encoding: 'utf-8' }));
|
277
|
+
}
|
278
|
+
if (config.install?.requirements) {
|
279
|
+
if (!Array.isArray(config.install.requirements)) return log(' Requirements must be an array'.red.bold, ':end');
|
280
|
+
config.install.requirements.forEach(req => {
|
281
|
+
log('Finding '.cyan + req.green);
|
282
|
+
this.installAppFrom(req, opts);
|
283
|
+
});
|
284
|
+
}
|
285
|
+
},
|
286
|
+
build(argv) {
|
207
287
|
function readFile(filePath) {
|
208
288
|
return fs.readFileSync(filePath, { encoding: 'utf-8' });
|
209
289
|
}
|
@@ -236,7 +316,7 @@ module.exports = {
|
|
236
316
|
const newFilePath = path.join(dirName, `${baseName}.${argv.translate ? 'js' : 'qrew'}`);
|
237
317
|
fs.writeFileSync(newFilePath, compiledCode);
|
238
318
|
log(`${'Compiled'.green.bold}: ${newFilePath.yellow}`);
|
239
|
-
if(argv.remove){
|
319
|
+
if (argv.remove) {
|
240
320
|
fs.unlinkSync(filePath);
|
241
321
|
log(`${'Removed'.red.bold}: ${filePath.yellow}`);
|
242
322
|
}
|
@@ -264,7 +344,7 @@ module.exports = {
|
|
264
344
|
|
265
345
|
const appPath = findAppInfo(filePath);
|
266
346
|
|
267
|
-
const compiled = argv.translate ? compile({ content }, {}) : to_qrew(content, appPath?.config?.package || path.basename(filePath).split('.').slice(0, -1).join('.'));
|
347
|
+
const compiled = argv.translate ? compile({ content }, {}) : to_qrew(content, appPath?.config?.manifest?.package || path.basename(filePath).split('.').slice(0, -1).join('.'));
|
268
348
|
writeCompiledFile(filePath, compiled);
|
269
349
|
}
|
270
350
|
|
@@ -279,7 +359,7 @@ module.exports = {
|
|
279
359
|
const p = gitpath.split('github:')[1];
|
280
360
|
const url = `https://github.com/${p}`;
|
281
361
|
const apiurl = `https://api.github.com/repos/${p}`;
|
282
|
-
try{
|
362
|
+
try {
|
283
363
|
const response = await req(apiurl);
|
284
364
|
if (response.status !== 200) return log(' Repo not found'.red.bold, ':end');
|
285
365
|
log(''.blue, 'Cloning from github'.yellow);
|
@@ -288,39 +368,49 @@ module.exports = {
|
|
288
368
|
log(''.blue, 'Installing deps...'.yellow);
|
289
369
|
execSync(`cd ${tempPath} && npm i`);
|
290
370
|
return tempPath;
|
291
|
-
} catch(e){
|
371
|
+
} catch (e) {
|
292
372
|
log(' Repo not found'.red.bold, ':end');
|
293
373
|
}
|
294
374
|
},
|
295
|
-
findRepo(repo){
|
375
|
+
findRepo(repo) {
|
296
376
|
const repos = conf({}).create('').optionCenter('repos');
|
297
377
|
return repos.get(repo);
|
298
378
|
},
|
299
|
-
async installAppFrom(path){
|
300
|
-
if (path.startsWith('github:')) this.installApp(await this.cloneGit(path), true, true);
|
301
|
-
else if(path.startsWith('@')) this.fromRepo(path);
|
302
|
-
else this.installApp(path);
|
379
|
+
async installAppFrom(path, opts) {
|
380
|
+
if (path.startsWith('github:')) this.installApp(await this.cloneGit(path), opts, true, true);
|
381
|
+
else if (path.startsWith('@')) this.fromRepo(path, opts);
|
382
|
+
else this.installApp(path, opts, null, null);
|
303
383
|
},
|
304
|
-
uninstall(packageName, all){
|
384
|
+
uninstall(packageName, all) {
|
305
385
|
const confPath = path.join(CONFIG_PATH, packageName);
|
306
386
|
const apppath = path.resolve(confPath, 'app');
|
307
387
|
const appConfpath = path.join(apppath, 'app.yaml');
|
308
|
-
if(!fs.existsSync(appConfpath) && fs.existsSync(confPath) && !all){
|
388
|
+
if (!fs.existsSync(appConfpath) && fs.existsSync(confPath) && !all) {
|
309
389
|
log(` App ${packageName.green}`.red.bold, `not found`.red.bold, `but configs are found.`.green.bold);
|
310
390
|
return log(`Use the`.cyan, '--all'.green, 'flag to remove them.'.cyan, ':end');
|
311
|
-
} else if(!fs.existsSync(appConfpath) && !all){
|
391
|
+
} else if (!fs.existsSync(appConfpath) && !all) {
|
312
392
|
return log(` App ${packageName.green}`.red.bold, `not found.`.red.bold, ':end');
|
313
393
|
}
|
314
394
|
log('Uninstalling'.cyan, packageName.green);
|
315
|
-
execSync('rm -rf '+(all ? confPath : apppath));
|
395
|
+
execSync('rm -rf ' + (all ? confPath : apppath));
|
396
|
+
fs.readdirSync(binpath)
|
397
|
+
.forEach(filename => {
|
398
|
+
const filepath = path.join(binpath, filename);
|
399
|
+
const lfilepath = path.join(localBinPath, filename);
|
400
|
+
const content = fs.readFileSync(filepath, { encoding: 'utf-8' });
|
401
|
+
if (content.split('\n')[1].startsWith('#@app.' + packageName)) {
|
402
|
+
fs.unlinkSync(lfilepath);
|
403
|
+
fs.unlinkSync(filepath);
|
404
|
+
}
|
405
|
+
});
|
316
406
|
log('Uninstalled'.cyan, ':end');
|
317
407
|
},
|
318
|
-
async getRepoJson(repoUrl){
|
319
|
-
try{
|
320
|
-
const text = (await req(repoUrl.startsWith('//.') ? 'http://'+repoUrl.slice(3) : repoUrl.startsWith('//') ? 'https://'+repoUrl : repoUrl)).data;
|
408
|
+
async getRepoJson(repoUrl) {
|
409
|
+
try {
|
410
|
+
const text = (await req(repoUrl.startsWith('//.') ? 'http://' + repoUrl.slice(3) : repoUrl.startsWith('//') ? 'https://' + repoUrl : repoUrl)).data;
|
321
411
|
const json = text.startsWith('---') || text.startsWith('%YAML') ? jsYaml.loadAll(text)[0] : JSON.parse(text);
|
322
|
-
if(Array.isArray(json.include)){
|
323
|
-
for(let i of json.include){
|
412
|
+
if (Array.isArray(json.include)) {
|
413
|
+
for (let i of json.include) {
|
324
414
|
json.packages = {
|
325
415
|
...json.packages,
|
326
416
|
...((await this.getRepoJson(i.startsWith('.') ? path.join(path.dirname(repoUrl), i) : i)).packages || {})
|
@@ -328,47 +418,50 @@ module.exports = {
|
|
328
418
|
}
|
329
419
|
}
|
330
420
|
return json;
|
331
|
-
} catch(e){
|
421
|
+
} catch (e) {
|
332
422
|
log(` Fetch Error. Check your connection.`.red.bold);
|
333
423
|
return {};
|
334
424
|
}
|
335
425
|
},
|
336
|
-
|
337
|
-
|
426
|
+
async fromRepo(repoAndPkg, opts) {
|
427
|
+
const [repo, pkg] = repoAndPkg.slice(1).split('/');
|
338
428
|
const repoUrl = this.findRepo(repo);
|
339
|
-
if(!repoUrl){
|
340
|
-
|
429
|
+
if (!repoUrl) {
|
430
|
+
log(` Repository "${repo.green}"`.red.bold, `not found.`.red.bold);
|
341
431
|
return log(`Add with:`.yellow, '\n\t$'.green, `rew repo add ${repo} URL`.cyan.bold, ':end');
|
342
432
|
} else {
|
343
433
|
const repoJson = await this.getRepoJson(repoUrl);
|
344
|
-
if(repoJson?.packages?.[pkg]){
|
345
|
-
await this.installAppFrom(repoJson.packages[pkg]);
|
434
|
+
if (repoJson?.packages?.[pkg]) {
|
435
|
+
await this.installAppFrom(repoJson.packages[pkg], opts);
|
346
436
|
} else {
|
347
|
-
log(` Package "${pkg}" is not in repo "${repo.green}"`.red.bold, ":end");
|
437
|
+
log(` Package "${pkg.cyan}" is not in repo "${repo.green}"`.red.bold, ":end");
|
348
438
|
}
|
349
439
|
}
|
350
|
-
|
351
|
-
async repo(command, key, value) {
|
440
|
+
},
|
441
|
+
async repo(command, key, value, options) {
|
352
442
|
const confInstance = conf({}).create('').optionCenter('repos') || {};
|
353
|
-
|
443
|
+
|
354
444
|
if (command === 'add' || command === 'set') {
|
355
445
|
confInstance.set(key, value.replace('https://', '//').replace('http://', '//.'));
|
356
446
|
} else if (command === 'get') {
|
357
447
|
if (key) {
|
358
448
|
console.log(confInstance.get(key) || 'Not found');
|
359
449
|
} else {
|
450
|
+
if(options.json) return console.log(JSON.stringify(confInstance.getAll()));
|
360
451
|
console.log(Object.keys(confInstance.getAll()).join('\n'));
|
361
452
|
}
|
362
453
|
} else if (command === 'view') {
|
363
454
|
if (key) {
|
364
455
|
const url = confInstance.get(key);
|
365
|
-
if(!url) return log(' Repo not found'.red.bold, ':end');
|
456
|
+
if (!url) return log(' Repo not found'.red.bold, ':end');
|
366
457
|
const json = await this.getRepoJson(url);
|
367
|
-
if(json
|
458
|
+
if(options.json) return console.log(JSON.stringify(json));
|
459
|
+
if (json.name) log(json.name);
|
368
460
|
log('Packages:'.yellow)
|
369
|
-
if(json.packages) Object.keys(json.packages).forEach(name => log(name)) || log(`${Object.keys(json.packages).length} Packages in ${key}`, ':end');
|
461
|
+
if (json.packages) Object.keys(json.packages).forEach(name => log(name)) || log(`${Object.keys(json.packages).length} Packages in ${key}`, ':end');
|
370
462
|
else log('None'.blue, ':end')
|
371
463
|
} else {
|
464
|
+
if(options.json) return JSON.stringify(confInstance.getAll());
|
372
465
|
console.log(Object.keys(confInstance.getAll()).join('\n'));
|
373
466
|
}
|
374
467
|
} else if (command === 'delete') {
|
@@ -376,8 +469,11 @@ module.exports = {
|
|
376
469
|
} else {
|
377
470
|
log(' Invalid command'.red.bold, ':end');
|
378
471
|
}
|
379
|
-
},
|
380
|
-
initFirst(){
|
472
|
+
},
|
473
|
+
initFirst() {
|
474
|
+
log('First time init')
|
381
475
|
conf({}).create('').optionCenter('repos').set('rewpkgs', '//raw.githubusercontent.com/kevinJ045/rewpkgs/main/main.yaml');
|
476
|
+
fs.mkdirSync(binpath, { recursive: true });
|
477
|
+
fs.mkdirSync(logspath, { recursive: true });
|
382
478
|
}
|
383
479
|
};
|
package/lib/rew/const/default.js
CHANGED
@@ -7,8 +7,11 @@ const { match } = require('../functions/match');
|
|
7
7
|
const { map } = require('../functions/map');
|
8
8
|
const { typex, typeis, typedef, typei, int, float, num, str, bool } = require('../functions/types');
|
9
9
|
const { isEmpty, clone, deepClone, merge, uniqueId, compose, curry } = require('../functions/core');
|
10
|
-
const { print, input } = require('../functions/stdout');
|
10
|
+
const { print, input, clear } = require('../functions/stdout');
|
11
11
|
const { curl } = require('../functions/curl');
|
12
|
+
const { wait } = require('../functions/wait');
|
13
|
+
const { scheduleFrame } = require('../functions/misc');
|
14
|
+
const { jsons, yaml, json, yamls } = require('../functions/json');
|
12
15
|
|
13
16
|
module.exports = {
|
14
17
|
cenum,
|
@@ -16,8 +19,11 @@ module.exports = {
|
|
16
19
|
future,
|
17
20
|
emitter,
|
18
21
|
sleep,
|
22
|
+
wait,
|
23
|
+
scheduleFrame,
|
19
24
|
match,
|
20
25
|
map,
|
26
|
+
clear,
|
21
27
|
|
22
28
|
typex,
|
23
29
|
typei,
|
@@ -38,6 +44,11 @@ module.exports = {
|
|
38
44
|
compose,
|
39
45
|
curry,
|
40
46
|
|
47
|
+
json,
|
48
|
+
jsons,
|
49
|
+
yaml,
|
50
|
+
yamls,
|
51
|
+
|
41
52
|
curl,
|
42
53
|
|
43
54
|
print,
|
package/lib/rew/const/files.js
CHANGED
@@ -1,15 +1,9 @@
|
|
1
1
|
const fs = require('fs');
|
2
2
|
const path = require('path');
|
3
|
-
|
4
|
-
const HOME_PATH = path.resolve(process.env.HOME, '.config/rew/default');
|
5
|
-
const THEME_PATH = (module.exports.THEME_PATH = path.resolve(HOME_PATH, 'theme.css'));
|
3
|
+
const { CONFIG_PATH } = require('./config_path');
|
6
4
|
|
7
5
|
module.exports.FILES = [
|
8
6
|
{
|
9
|
-
path:
|
10
|
-
}
|
11
|
-
{
|
12
|
-
path: THEME_PATH,
|
13
|
-
content: fs.readFileSync(path.resolve(__dirname, '../css/theme.css')),
|
14
|
-
},
|
7
|
+
path: CONFIG_PATH,
|
8
|
+
}
|
15
9
|
];
|
@@ -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
|
}
|
@@ -14,14 +14,15 @@ const lookUpInOtherApps = (fullPath) => {
|
|
14
14
|
const name = fullPath.indexOf('/') ? fullPath.split('/')[0] : fullPath;
|
15
15
|
let dpath = fullPath.indexOf('/') ? fullPath.split('/')[1] : '';
|
16
16
|
let ppath = path.join(con.CONFIG_PATH, name, 'app');
|
17
|
-
const config = jsYaml.load(readFileSync(path.join(ppath, 'app.yaml'), 'utf-8'));
|
18
17
|
if (!existsSync(ppath)) return null;
|
18
|
+
const config = jsYaml.load(readFileSync(path.join(ppath, 'app.yaml'), 'utf-8'));
|
19
19
|
if (!dpath) {
|
20
|
-
dpath = config.entry;
|
20
|
+
dpath = config.exec.entry;
|
21
21
|
}
|
22
22
|
if(config.private == true) return null;
|
23
|
+
if(dpath in config.exec) dpath = config.exec[dpath];
|
23
24
|
const pepath = path.join(ppath, dpath);
|
24
|
-
if(Array.isArray(config.private)){
|
25
|
+
if(Array.isArray(config.manifest.private)){
|
25
26
|
if(config.private.find(f => pepath == path.join(ppath, f))) return null;
|
26
27
|
}
|
27
28
|
if (existsSync(pepath)) return pepath;
|
@@ -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
|
+
}
|
@@ -1,8 +1,7 @@
|
|
1
|
-
const {
|
2
|
-
const fs = require('fs');
|
1
|
+
const { spawnSync } = require('child_process');
|
3
2
|
|
4
|
-
const print = (module.exports.print = function print(...
|
5
|
-
return console.log(...
|
3
|
+
const print = (module.exports.print = function print(...args) {
|
4
|
+
return console.log(...args);
|
6
5
|
});
|
7
6
|
|
8
7
|
print.stdout = process.stdout;
|
@@ -28,3 +27,7 @@ module.exports.input = function input(prompt) {
|
|
28
27
|
|
29
28
|
return spawnSync(cmd, args, opts).stdout.toString().trim();
|
30
29
|
};
|
30
|
+
|
31
|
+
module.exports.clear = () => {
|
32
|
+
console.clear();
|
33
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
const deasync = require("deasync");
|
2
|
+
|
3
|
+
|
4
|
+
module.exports.wait = (...args) => {
|
5
|
+
const fn = args.shift();
|
6
|
+
if(typeof fn !== "function") throw new TypeError("The first argument must be a function to use wait.");
|
7
|
+
const df = deasync(async (cb) => {
|
8
|
+
cb(null, await fn(...args));
|
9
|
+
});
|
10
|
+
return df();
|
11
|
+
}
|