@makano/rew 1.2.21 → 1.2.31
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 +1 -8
- package/lib/rew/cli/cli.js +43 -51
- package/lib/rew/cli/run.js +4 -11
- package/lib/rew/cli/utils.js +131 -53
- package/lib/rew/const/default.js +6 -1
- package/lib/rew/const/files.js +3 -9
- package/lib/rew/const/pre-exec.js +3 -0
- package/lib/rew/functions/import.js +4 -3
- package/lib/rew/functions/misc.js +5 -0
- package/lib/rew/functions/require.js +0 -2
- 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 +16 -14
- package/lib/rew/modules/runtime.js +21 -2
- package/lib/rew/pkgs/rune.js +10 -4
- 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/README.md
CHANGED
|
@@ -31,6 +31,9 @@ in the process.
|
|
|
31
31
|
```
|
|
32
32
|
Optionally, you can run single files with `rew [filename]`
|
|
33
33
|
|
|
34
|
+
## Docs
|
|
35
|
+
You can pay a visit to the [docs](https://kevinj045.github.io/rew-docs/) to learn more about rew and how it works.
|
|
36
|
+
|
|
34
37
|
## Author's Notes
|
|
35
38
|
|
|
36
39
|
Any suggestions, bug fixes or ideas are accepted, feel free to ask anything.
|
package/bin/rew
CHANGED
|
@@ -1,9 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const rew_mod = path.resolve(process.cwd(), 'snode_moduless/@makano/rew');
|
|
5
|
-
if(fs.existsSync(rew_mod)){
|
|
6
|
-
require(path.join(rew_mod, 'lib/rew/cli/cli.js'));
|
|
7
|
-
} else {
|
|
8
|
-
require('../lib/rew/cli/cli.js');
|
|
9
|
-
}
|
|
2
|
+
require("../lib/rew/cli/cli.js");
|
package/lib/rew/cli/cli.js
CHANGED
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
const yargs = require('yargs/yargs');
|
|
4
4
|
const path = require('path');
|
|
5
5
|
const { hideBin } = require('yargs/helpers');
|
|
6
|
-
const {
|
|
7
|
-
const { watch } = require('chokidar');
|
|
6
|
+
const { execSync } = require('child_process');
|
|
8
7
|
const utils = require('./utils');
|
|
9
8
|
const { existsSync, readFileSync, writeFileSync, mkdirSync } = require('fs');
|
|
10
9
|
const { log } = require('./log');
|
|
@@ -16,12 +15,16 @@ const { to_qrew, from_qrew } = require('../qrew/compile');
|
|
|
16
15
|
const { findAppInfo } = require('../misc/findAppInfo');
|
|
17
16
|
const { print, input } = require('../functions/stdout');
|
|
18
17
|
const colors = require('colors');
|
|
18
|
+
const { req } = require('../misc/req');
|
|
19
|
+
const { gen_key } = require('../misc/bin');
|
|
19
20
|
|
|
20
|
-
if (!existsSync(CONFIG_PATH)) {
|
|
21
|
+
if (!existsSync(CONFIG_PATH) || !existsSync(CONFIG_PATH+'/repos.yaml')) {
|
|
21
22
|
mkdirSync(CONFIG_PATH, { recursive: true });
|
|
22
23
|
utils.initFirst();
|
|
23
24
|
}
|
|
24
25
|
|
|
26
|
+
const npm_package_name = '@makano/rew';
|
|
27
|
+
|
|
25
28
|
yargs(hideBin(process.argv))
|
|
26
29
|
.command(
|
|
27
30
|
'$0 <file>',
|
|
@@ -41,31 +44,10 @@ yargs(hideBin(process.argv))
|
|
|
41
44
|
(argv) => {
|
|
42
45
|
const filePath = path.resolve(process.cwd(), argv.file);
|
|
43
46
|
if (!existsSync(filePath)) {
|
|
44
|
-
log('File not found:', argv.file, ':end');
|
|
47
|
+
log('File not found:'.red.bold, argv.file, ':end');
|
|
45
48
|
return;
|
|
46
49
|
}
|
|
47
|
-
|
|
48
|
-
const watchIt = (file) => {
|
|
49
|
-
if (watching.includes(file)) return;
|
|
50
|
-
watch(file).on('change', () => runIt());
|
|
51
|
-
watching.push(file);
|
|
52
|
-
};
|
|
53
|
-
let prevFork;
|
|
54
|
-
const runIt = () => {
|
|
55
|
-
if (argv.watch) console.clear();
|
|
56
|
-
if (prevFork && !prevFork.killed) prevFork.kill?.();
|
|
57
|
-
prevFork = fork(path.resolve(__dirname, './run.js'))
|
|
58
|
-
.on('message', (data) => {
|
|
59
|
-
if (argv.watch) {
|
|
60
|
-
data.forEach((file) => {
|
|
61
|
-
watchIt(file);
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
})
|
|
65
|
-
.send({ filePath, watch: argv.watch });
|
|
66
|
-
if (argv.watch) watchIt(filePath);
|
|
67
|
-
};
|
|
68
|
-
runIt();
|
|
50
|
+
utils.runFileWithArgv(filePath, { watch: argv.watch });
|
|
69
51
|
},
|
|
70
52
|
)
|
|
71
53
|
.command(
|
|
@@ -122,19 +104,6 @@ yargs(hideBin(process.argv))
|
|
|
122
104
|
console.log('Encryption Key:', rune({}).genKey(input('Secret Value: ') || null));
|
|
123
105
|
},
|
|
124
106
|
)
|
|
125
|
-
.command(
|
|
126
|
-
'ui-bin <path>',
|
|
127
|
-
'Build the UI bin for your own app',
|
|
128
|
-
(yargs) => {
|
|
129
|
-
yargs.positional('path', {
|
|
130
|
-
describe: 'Path of the output bin',
|
|
131
|
-
type: 'string',
|
|
132
|
-
});
|
|
133
|
-
},
|
|
134
|
-
(argv) => {
|
|
135
|
-
execSync('sh ' + path.resolve(__dirname, '../../../build.sh') + ' ' + argv.path);
|
|
136
|
-
},
|
|
137
|
-
)
|
|
138
107
|
.command(
|
|
139
108
|
'run <path | package>',
|
|
140
109
|
'Run an app',
|
|
@@ -147,6 +116,11 @@ yargs(hideBin(process.argv))
|
|
|
147
116
|
describe: 'If your entry file is a .qrew, then just use the .coffee instead',
|
|
148
117
|
type: 'boolean',
|
|
149
118
|
})
|
|
119
|
+
.option('entry', {
|
|
120
|
+
alias: 'e',
|
|
121
|
+
describe: 'Choose entry file from app.config.exec',
|
|
122
|
+
type: 'string',
|
|
123
|
+
})
|
|
150
124
|
.option('build', {
|
|
151
125
|
alias: 'b',
|
|
152
126
|
describe: 'Builds to a .qrew before running',
|
|
@@ -166,30 +140,37 @@ yargs(hideBin(process.argv))
|
|
|
166
140
|
'secret <command> [key]',
|
|
167
141
|
'Add secrets to the current path',
|
|
168
142
|
(yargs) => {
|
|
169
|
-
yargs
|
|
143
|
+
yargs
|
|
144
|
+
.positional('command', {
|
|
170
145
|
describe: 'Path of the app to run',
|
|
171
146
|
type: 'string',
|
|
172
|
-
})
|
|
147
|
+
})
|
|
148
|
+
.option('file', {
|
|
149
|
+
alias: 'f',
|
|
150
|
+
describe: 'Set file name',
|
|
151
|
+
type: 'string',
|
|
152
|
+
default: 'secrets.qrew'
|
|
153
|
+
})
|
|
173
154
|
},
|
|
174
155
|
(argv) => {
|
|
175
156
|
const appPath = findAppInfo(path.join(process.cwd(), 'app.yaml'));
|
|
176
157
|
|
|
177
158
|
if (!appPath) return log(''.red.bold, 'Secrets only available in apps'.red.bold, ':end');
|
|
178
159
|
|
|
179
|
-
const qrewPath = path.join(appPath.path, 'secrets.qrew');
|
|
160
|
+
const qrewPath = path.join(appPath.path, argv.file || 'secrets.qrew');
|
|
180
161
|
|
|
181
|
-
const
|
|
162
|
+
const getPass = () => gen_key(input('Secret Encryptor: '));//`${process.env.USER}@${os.platform()}.${os.hostname()}`;
|
|
182
163
|
|
|
183
164
|
const verifyUser = (content) => {
|
|
184
165
|
const owner = content.match(/^owner = "(.*)" # end$/m)?.[1];
|
|
185
|
-
if (owner ==
|
|
166
|
+
if (owner == getPass()) return true;
|
|
186
167
|
return false;
|
|
187
168
|
};
|
|
188
169
|
|
|
189
170
|
if (argv.command == 'init') {
|
|
190
|
-
writeFileSync(qrewPath, to_qrew(`secrets = {} # end\n\nowner = "${
|
|
171
|
+
writeFileSync(qrewPath, to_qrew(`secrets = {} # end\n\nowner = "${getPass()}" # end\n \nexports { ...secrets }`, appPath.config.manifest.package))
|
|
191
172
|
} else {
|
|
192
|
-
const currentFileContent = from_qrew(readFileSync(qrewPath), appPath.config.package).toString();
|
|
173
|
+
const currentFileContent = from_qrew(readFileSync(qrewPath), appPath.config.manifest.package).toString();
|
|
193
174
|
if (!verifyUser(currentFileContent)) return log(''.red.bold, 'You are not allowed to change this data'.red.bold, ':end');
|
|
194
175
|
|
|
195
176
|
const secrets = currentFileContent.match(/^secrets = (.*) # end$/m)?.[1];
|
|
@@ -208,7 +189,7 @@ yargs(hideBin(process.argv))
|
|
|
208
189
|
const newSecrets = `secrets = ${JSON.stringify(secretsJson)} # end`;
|
|
209
190
|
const newFileContent = currentFileContent.replace(/^secrets = .* # end$/m, newSecrets);
|
|
210
191
|
|
|
211
|
-
writeFileSync(qrewPath, to_qrew(newFileContent, appPath.config.package))
|
|
192
|
+
writeFileSync(qrewPath, to_qrew(newFileContent, appPath.config.manifest.package))
|
|
212
193
|
} else if (argv.command == 'get') {
|
|
213
194
|
if (argv.key) {
|
|
214
195
|
console.log(argv.key.yellow, '=', secretsJson[argv.key].green);
|
|
@@ -229,10 +210,15 @@ yargs(hideBin(process.argv))
|
|
|
229
210
|
yargs.positional('path', {
|
|
230
211
|
describe: 'Path or github or repo id of the app to install',
|
|
231
212
|
type: 'string',
|
|
213
|
+
}).option('requirements', {
|
|
214
|
+
alias: 'r',
|
|
215
|
+
describe: 'Install requirements of the app',
|
|
216
|
+
type: 'boolean',
|
|
232
217
|
});
|
|
233
218
|
},
|
|
234
219
|
async (argv) => {
|
|
235
|
-
utils.
|
|
220
|
+
if(argv.requirements) utils.installReq(argv.path);
|
|
221
|
+
else utils.installAppFrom(argv.path);
|
|
236
222
|
},
|
|
237
223
|
)
|
|
238
224
|
.command(
|
|
@@ -261,14 +247,20 @@ yargs(hideBin(process.argv))
|
|
|
261
247
|
const pkg = JSON.parse(readFileSync(path.resolve(__dirname, '../../../package.json'), { encoding: 'utf-8' }));
|
|
262
248
|
const getLatest = async () => {
|
|
263
249
|
try{
|
|
264
|
-
return (await (
|
|
250
|
+
return (await req(`https://registry.npmjs.org/${pkg.name}`)).data['dist-tags'].latest
|
|
265
251
|
} catch(e) {
|
|
266
252
|
return `(${'!err'.blue.bgRed}, see ${`https://npmjs.com/package/${pkg.name}`.blue.underline})`;
|
|
267
253
|
}
|
|
268
254
|
}
|
|
269
255
|
log(`${'Rew'.red.bold} ${'RUNTIME'.yellow}`);
|
|
270
|
-
log(`Version: ${pkg.name.green}@${pkg.version.yellow.bold}
|
|
271
|
-
|
|
256
|
+
log(`Version: ${pkg.name.green.bold}@${pkg.version.yellow.bold}`.magenta.bold);
|
|
257
|
+
const latest = await getLatest();
|
|
258
|
+
const isLatest = latest === pkg.version;
|
|
259
|
+
log(`Latest: ${pkg.name.cyan.bold}@${latest.yellow.bold}`.green.bold, isLatest ? ':end' : '');
|
|
260
|
+
if(!isLatest){
|
|
261
|
+
log(`There is an update available`.cyan.bold);
|
|
262
|
+
log('Update With:'.yellow, `npm i -g ${npm_package_name}`.green.bold, ':end');
|
|
263
|
+
}
|
|
272
264
|
},
|
|
273
265
|
)
|
|
274
266
|
.command(
|
package/lib/rew/cli/run.js
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
|
+
// run.js
|
|
1
2
|
const { run } = require('../main');
|
|
2
3
|
|
|
3
|
-
function exec(filePath) {
|
|
4
|
-
return run(filePath)
|
|
4
|
+
function exec(filePath, argv) {
|
|
5
|
+
return run(filePath, { argv })?.context?.module?.imports || [];
|
|
5
6
|
}
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
const imports = exec(filePath);
|
|
9
|
-
if (watch) {
|
|
10
|
-
process.send(imports);
|
|
11
|
-
}
|
|
12
|
-
process.off('message', onmsg);
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
process.on('message', onmsg);
|
|
8
|
+
module.exports = { execRewFile: exec };
|
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,46 @@ 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 localBinPath = path.join(binpath, '../../../', 'bin');
|
|
17
20
|
|
|
18
21
|
module.exports = {
|
|
22
|
+
runFile(filePath, options = {}, argv) {
|
|
23
|
+
const watching = [];
|
|
24
|
+
const watchIt = (file) => {
|
|
25
|
+
if (watching.includes(file)) return;
|
|
26
|
+
watch(file).on('change', () => runIt());
|
|
27
|
+
watching.push(file);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const runIt = () => {
|
|
31
|
+
if (options.watch) console.clear();
|
|
32
|
+
const imports = execRewFile(filePath, [filePath, ...(argv || [])]);
|
|
33
|
+
if (options.watch) {
|
|
34
|
+
imports.forEach((file) => {
|
|
35
|
+
watchIt(file);
|
|
36
|
+
});
|
|
37
|
+
watchIt(filePath);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
runIt();
|
|
42
|
+
},
|
|
43
|
+
runFileWithArgv(filePath, options = {}, cargv) {
|
|
44
|
+
const argv = cargv || process.argv;
|
|
45
|
+
argv.shift();
|
|
46
|
+
if (argv[0].endsWith('rew')) {
|
|
47
|
+
if (argv[1] == 'run') {
|
|
48
|
+
argv.splice(0, 3);
|
|
49
|
+
} else if(argv[1] == '-w' || argv[1] == '--watch'){
|
|
50
|
+
argv.splice(0, 3);
|
|
51
|
+
} else argv.splice(0, 2);
|
|
52
|
+
}
|
|
53
|
+
this.runFile(filePath, options, argv)
|
|
54
|
+
},
|
|
19
55
|
conf(command, fullPath, key, value) {
|
|
20
56
|
const con = conf({});
|
|
21
57
|
if (command == 'get') {
|
|
@@ -69,8 +105,9 @@ module.exports = {
|
|
|
69
105
|
fs.mkdirSync(projectPath, { recursive: true });
|
|
70
106
|
const confPath = path.join(projectPath, 'app.yaml');
|
|
71
107
|
const entryFile = path.join(projectPath, 'main.coffee');
|
|
72
|
-
fs.writeFileSync(confPath, jsYaml.dump({ package: project.package, entry: 'main.coffee' }));
|
|
108
|
+
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
109
|
fs.writeFileSync(entryFile, `print("Hello World!")`);
|
|
110
|
+
fs.mkdirSync(path.join(projectPath, 'assets'), { recursive: true });
|
|
74
111
|
if (project.git) {
|
|
75
112
|
fs.writeFileSync(path.join(projectPath, '.gitignore'), `node_modules/\npackage-lock.json`);
|
|
76
113
|
execSync('cd ' + projectPath + ' && git init . && git branch -m main', { stdio: 'ignore' });
|
|
@@ -111,22 +148,20 @@ module.exports = {
|
|
|
111
148
|
|
|
112
149
|
const runAppRoot = (root, confPath, byPath) => {
|
|
113
150
|
const c = jsYaml.load(fs.readFileSync(confPath, { encoding: 'utf-8' }));
|
|
114
|
-
if (
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
151
|
+
if (options.entry) {
|
|
152
|
+
c.exec.entry = c.exec[options.entry] || c.exec.entry;
|
|
153
|
+
}
|
|
154
|
+
if (c.exec.entry) {
|
|
155
|
+
if (byPath && options.dev) c.exec.entry = c.entry.endsWith('.qrew') ? c.exec.entry.replace(/\.qrew$/, '.coffee') : c.exec.entry;
|
|
156
|
+
let r = path.resolve(root, c.exec.entry);
|
|
157
|
+
if (options.build) {
|
|
118
158
|
this.build({
|
|
119
159
|
file: r,
|
|
120
160
|
translate: options.translate || false
|
|
121
161
|
});
|
|
122
|
-
r = path.resolve(root, c.entry.replace(new RegExp(path.extname(c.entry).replace('.', '\\.') + '$'), options.translate ? '.js' : '.qrew'));
|
|
162
|
+
r = path.resolve(root, c.exec.entry.replace(new RegExp(path.extname(c.exec.entry).replace('.', '\\.') + '$'), options.translate ? '.js' : '.qrew'));
|
|
123
163
|
}
|
|
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);
|
|
164
|
+
this.runFileWithArgv(r);
|
|
130
165
|
}
|
|
131
166
|
};
|
|
132
167
|
|
|
@@ -151,7 +186,7 @@ module.exports = {
|
|
|
151
186
|
if (fs.existsSync(apppath) && fs.existsSync(appConfpath)) {
|
|
152
187
|
const c = jsYaml.load(fs.readFileSync(appConfpath, { encoding: 'utf-8' }));
|
|
153
188
|
const p = JSON.parse(fs.readFileSync(appPackagepath, { encoding: 'utf-8' }));
|
|
154
|
-
const pname = c.package;
|
|
189
|
+
const pname = c.manifest.package;
|
|
155
190
|
const installPath = path.join(conf({}).create(pname).root, 'app');
|
|
156
191
|
const rl = readline.createInterface({
|
|
157
192
|
input: process.stdin,
|
|
@@ -159,7 +194,7 @@ module.exports = {
|
|
|
159
194
|
});
|
|
160
195
|
log(' Installing '.blue + pname.green.bold);
|
|
161
196
|
log(' Package'.blue + ': ' + p.name.green + '@' + p.version.yellow);
|
|
162
|
-
if (p.
|
|
197
|
+
if (p.descriptiondescription) {
|
|
163
198
|
log(' Description'.blue + ': ' + p.description);
|
|
164
199
|
}
|
|
165
200
|
rl.question(logget('Install '.blue + pname.green.bold + '? (y/N) '), (f) => {
|
|
@@ -173,21 +208,38 @@ module.exports = {
|
|
|
173
208
|
execSync(`rm -r ${apppath}`);
|
|
174
209
|
}
|
|
175
210
|
log(' Installed '.green + pname.cyan.bold, c.install ? '' : ':end');
|
|
176
|
-
if(c.install){
|
|
177
|
-
if(c.install.build){
|
|
211
|
+
if (c.install) {
|
|
212
|
+
if (c.install.build) {
|
|
178
213
|
log(' Building'.blue);
|
|
179
214
|
this.build({
|
|
180
215
|
...c.install.build,
|
|
181
216
|
file: path.join(installPath, c.install.build.file)
|
|
182
217
|
});
|
|
183
218
|
}
|
|
184
|
-
if(c.install.commands){
|
|
185
|
-
for(let command of c.install.commands){
|
|
219
|
+
if (c.install.commands) {
|
|
220
|
+
for (let command of c.install.commands) {
|
|
186
221
|
execSync(command.replace(/\$installPath/g, installPath));
|
|
187
222
|
}
|
|
188
223
|
}
|
|
189
|
-
if(c.install.file){
|
|
190
|
-
|
|
224
|
+
if (c.install.file) {
|
|
225
|
+
this.runFileWithArgv(path.join(installPath, c.exec[c.install.file] || c.install.file), {}, []);
|
|
226
|
+
}
|
|
227
|
+
if (c.install.requirements) {
|
|
228
|
+
this.installReq(c);
|
|
229
|
+
}
|
|
230
|
+
if (c.install.exec) {
|
|
231
|
+
// this.installReq(c);
|
|
232
|
+
for (let i in c.install.exec) {
|
|
233
|
+
let iff = c.install.exec[i];
|
|
234
|
+
if (iff in c.exec) iff = c.exec[iff];
|
|
235
|
+
const file = path.join(installPath, iff);
|
|
236
|
+
const filepath = path.join(binpath, i);
|
|
237
|
+
const binfp = path.join(localBinPath, i);
|
|
238
|
+
if (!fs.existsSync(localBinPath)) fs.mkdirSync(localBinPath, { recursive: true });
|
|
239
|
+
fs.writeFileSync(filepath, `#!/usr/bin/env bash\n#@app.${pname}\nrew ${file} $*`);
|
|
240
|
+
fs.chmodSync(filepath, '755');
|
|
241
|
+
fs.linkSync(filepath, binfp);
|
|
242
|
+
}
|
|
191
243
|
}
|
|
192
244
|
}
|
|
193
245
|
rl.close();
|
|
@@ -203,7 +255,21 @@ module.exports = {
|
|
|
203
255
|
log(' Path is not a rew app'.red.bold, ':end');
|
|
204
256
|
}
|
|
205
257
|
},
|
|
206
|
-
|
|
258
|
+
installReq(config) {
|
|
259
|
+
if (typeof config !== "object") {
|
|
260
|
+
const confPath = path.join(config, './app.yaml');
|
|
261
|
+
if (!fs.existsSync(confPath)) return log(' Path is not a rew app'.red.bold, ':end');
|
|
262
|
+
config = jsYaml.load(fs.readFileSync(confPath, { encoding: 'utf-8' }));
|
|
263
|
+
}
|
|
264
|
+
if (config.install?.requirements) {
|
|
265
|
+
if (!Array.isArray(config.install.requirements)) return log(' Requirements must be an array'.red.bold, ':end');
|
|
266
|
+
config.install.requirements.forEach(req => {
|
|
267
|
+
log('Finding '.cyan + req.green);
|
|
268
|
+
this.installAppFrom(req);
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
build(argv) {
|
|
207
273
|
function readFile(filePath) {
|
|
208
274
|
return fs.readFileSync(filePath, { encoding: 'utf-8' });
|
|
209
275
|
}
|
|
@@ -236,7 +302,7 @@ module.exports = {
|
|
|
236
302
|
const newFilePath = path.join(dirName, `${baseName}.${argv.translate ? 'js' : 'qrew'}`);
|
|
237
303
|
fs.writeFileSync(newFilePath, compiledCode);
|
|
238
304
|
log(`${'Compiled'.green.bold}: ${newFilePath.yellow}`);
|
|
239
|
-
if(argv.remove){
|
|
305
|
+
if (argv.remove) {
|
|
240
306
|
fs.unlinkSync(filePath);
|
|
241
307
|
log(`${'Removed'.red.bold}: ${filePath.yellow}`);
|
|
242
308
|
}
|
|
@@ -264,7 +330,7 @@ module.exports = {
|
|
|
264
330
|
|
|
265
331
|
const appPath = findAppInfo(filePath);
|
|
266
332
|
|
|
267
|
-
const compiled = argv.translate ? compile({ content }, {}) : to_qrew(content, appPath?.config?.package || path.basename(filePath).split('.').slice(0, -1).join('.'));
|
|
333
|
+
const compiled = argv.translate ? compile({ content }, {}) : to_qrew(content, appPath?.config?.manifest?.package || path.basename(filePath).split('.').slice(0, -1).join('.'));
|
|
268
334
|
writeCompiledFile(filePath, compiled);
|
|
269
335
|
}
|
|
270
336
|
|
|
@@ -279,7 +345,7 @@ module.exports = {
|
|
|
279
345
|
const p = gitpath.split('github:')[1];
|
|
280
346
|
const url = `https://github.com/${p}`;
|
|
281
347
|
const apiurl = `https://api.github.com/repos/${p}`;
|
|
282
|
-
try{
|
|
348
|
+
try {
|
|
283
349
|
const response = await req(apiurl);
|
|
284
350
|
if (response.status !== 200) return log(' Repo not found'.red.bold, ':end');
|
|
285
351
|
log(''.blue, 'Cloning from github'.yellow);
|
|
@@ -288,39 +354,49 @@ module.exports = {
|
|
|
288
354
|
log(''.blue, 'Installing deps...'.yellow);
|
|
289
355
|
execSync(`cd ${tempPath} && npm i`);
|
|
290
356
|
return tempPath;
|
|
291
|
-
} catch(e){
|
|
357
|
+
} catch (e) {
|
|
292
358
|
log(' Repo not found'.red.bold, ':end');
|
|
293
359
|
}
|
|
294
360
|
},
|
|
295
|
-
findRepo(repo){
|
|
361
|
+
findRepo(repo) {
|
|
296
362
|
const repos = conf({}).create('').optionCenter('repos');
|
|
297
363
|
return repos.get(repo);
|
|
298
364
|
},
|
|
299
|
-
async installAppFrom(path){
|
|
365
|
+
async installAppFrom(path) {
|
|
300
366
|
if (path.startsWith('github:')) this.installApp(await this.cloneGit(path), true, true);
|
|
301
|
-
else if(path.startsWith('@')) this.fromRepo(path);
|
|
367
|
+
else if (path.startsWith('@')) this.fromRepo(path);
|
|
302
368
|
else this.installApp(path);
|
|
303
369
|
},
|
|
304
|
-
uninstall(packageName, all){
|
|
370
|
+
uninstall(packageName, all) {
|
|
305
371
|
const confPath = path.join(CONFIG_PATH, packageName);
|
|
306
372
|
const apppath = path.resolve(confPath, 'app');
|
|
307
373
|
const appConfpath = path.join(apppath, 'app.yaml');
|
|
308
|
-
if(!fs.existsSync(appConfpath) && fs.existsSync(confPath) && !all){
|
|
374
|
+
if (!fs.existsSync(appConfpath) && fs.existsSync(confPath) && !all) {
|
|
309
375
|
log(` App ${packageName.green}`.red.bold, `not found`.red.bold, `but configs are found.`.green.bold);
|
|
310
376
|
return log(`Use the`.cyan, '--all'.green, 'flag to remove them.'.cyan, ':end');
|
|
311
|
-
} else if(!fs.existsSync(appConfpath) && !all){
|
|
377
|
+
} else if (!fs.existsSync(appConfpath) && !all) {
|
|
312
378
|
return log(` App ${packageName.green}`.red.bold, `not found.`.red.bold, ':end');
|
|
313
379
|
}
|
|
314
380
|
log('Uninstalling'.cyan, packageName.green);
|
|
315
|
-
execSync('rm -rf '+(all ? confPath : apppath));
|
|
381
|
+
execSync('rm -rf ' + (all ? confPath : apppath));
|
|
382
|
+
fs.readdirSync(binpath)
|
|
383
|
+
.forEach(filename => {
|
|
384
|
+
const filepath = path.join(binpath, filename);
|
|
385
|
+
const lfilepath = path.join(localBinPath, filename);
|
|
386
|
+
const content = fs.readFileSync(filepath, { encoding: 'utf-8' });
|
|
387
|
+
if (content.split('\n')[1].startsWith('#@app.' + packageName)) {
|
|
388
|
+
fs.unlinkSync(lfilepath);
|
|
389
|
+
fs.unlinkSync(filepath);
|
|
390
|
+
}
|
|
391
|
+
});
|
|
316
392
|
log('Uninstalled'.cyan, ':end');
|
|
317
393
|
},
|
|
318
|
-
async getRepoJson(repoUrl){
|
|
319
|
-
try{
|
|
320
|
-
const text = (await req(repoUrl.startsWith('//.') ? 'http://'+repoUrl.slice(3) : repoUrl.startsWith('//') ? 'https://'+repoUrl : repoUrl)).data;
|
|
394
|
+
async getRepoJson(repoUrl) {
|
|
395
|
+
try {
|
|
396
|
+
const text = (await req(repoUrl.startsWith('//.') ? 'http://' + repoUrl.slice(3) : repoUrl.startsWith('//') ? 'https://' + repoUrl : repoUrl)).data;
|
|
321
397
|
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){
|
|
398
|
+
if (Array.isArray(json.include)) {
|
|
399
|
+
for (let i of json.include) {
|
|
324
400
|
json.packages = {
|
|
325
401
|
...json.packages,
|
|
326
402
|
...((await this.getRepoJson(i.startsWith('.') ? path.join(path.dirname(repoUrl), i) : i)).packages || {})
|
|
@@ -328,29 +404,29 @@ module.exports = {
|
|
|
328
404
|
}
|
|
329
405
|
}
|
|
330
406
|
return json;
|
|
331
|
-
} catch(e){
|
|
407
|
+
} catch (e) {
|
|
332
408
|
log(` Fetch Error. Check your connection.`.red.bold);
|
|
333
409
|
return {};
|
|
334
410
|
}
|
|
335
411
|
},
|
|
336
|
-
|
|
337
|
-
|
|
412
|
+
async fromRepo(repoAndPkg) {
|
|
413
|
+
const [repo, pkg] = repoAndPkg.slice(1).split('/');
|
|
338
414
|
const repoUrl = this.findRepo(repo);
|
|
339
|
-
if(!repoUrl){
|
|
340
|
-
|
|
415
|
+
if (!repoUrl) {
|
|
416
|
+
log(` Repository "${repo.green}"`.red.bold, `not found.`.red.bold);
|
|
341
417
|
return log(`Add with:`.yellow, '\n\t$'.green, `rew repo add ${repo} URL`.cyan.bold, ':end');
|
|
342
418
|
} else {
|
|
343
419
|
const repoJson = await this.getRepoJson(repoUrl);
|
|
344
|
-
if(repoJson?.packages?.[pkg]){
|
|
420
|
+
if (repoJson?.packages?.[pkg]) {
|
|
345
421
|
await this.installAppFrom(repoJson.packages[pkg]);
|
|
346
422
|
} else {
|
|
347
|
-
log(` Package "${pkg}" is not in repo "${repo.green}"`.red.bold, ":end");
|
|
423
|
+
log(` Package "${pkg.cyan}" is not in repo "${repo.green}"`.red.bold, ":end");
|
|
348
424
|
}
|
|
349
425
|
}
|
|
350
|
-
|
|
426
|
+
},
|
|
351
427
|
async repo(command, key, value) {
|
|
352
428
|
const confInstance = conf({}).create('').optionCenter('repos') || {};
|
|
353
|
-
|
|
429
|
+
|
|
354
430
|
if (command === 'add' || command === 'set') {
|
|
355
431
|
confInstance.set(key, value.replace('https://', '//').replace('http://', '//.'));
|
|
356
432
|
} else if (command === 'get') {
|
|
@@ -362,11 +438,11 @@ module.exports = {
|
|
|
362
438
|
} else if (command === 'view') {
|
|
363
439
|
if (key) {
|
|
364
440
|
const url = confInstance.get(key);
|
|
365
|
-
if(!url) return log(' Repo not found'.red.bold, ':end');
|
|
441
|
+
if (!url) return log(' Repo not found'.red.bold, ':end');
|
|
366
442
|
const json = await this.getRepoJson(url);
|
|
367
|
-
if(json.name) log(json.name);
|
|
443
|
+
if (json.name) log(json.name);
|
|
368
444
|
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');
|
|
445
|
+
if (json.packages) Object.keys(json.packages).forEach(name => log(name)) || log(`${Object.keys(json.packages).length} Packages in ${key}`, ':end');
|
|
370
446
|
else log('None'.blue, ':end')
|
|
371
447
|
} else {
|
|
372
448
|
console.log(Object.keys(confInstance.getAll()).join('\n'));
|
|
@@ -376,8 +452,10 @@ module.exports = {
|
|
|
376
452
|
} else {
|
|
377
453
|
log(' Invalid command'.red.bold, ':end');
|
|
378
454
|
}
|
|
379
|
-
},
|
|
380
|
-
initFirst(){
|
|
455
|
+
},
|
|
456
|
+
initFirst() {
|
|
457
|
+
log('First time init')
|
|
381
458
|
conf({}).create('').optionCenter('repos').set('rewpkgs', '//raw.githubusercontent.com/kevinJ045/rewpkgs/main/main.yaml');
|
|
459
|
+
fs.mkdirSync(binpath, { recursive: true });
|
|
382
460
|
}
|
|
383
461
|
};
|
package/lib/rew/const/default.js
CHANGED
|
@@ -7,8 +7,10 @@ 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');
|
|
12
14
|
|
|
13
15
|
module.exports = {
|
|
14
16
|
cenum,
|
|
@@ -16,8 +18,11 @@ module.exports = {
|
|
|
16
18
|
future,
|
|
17
19
|
emitter,
|
|
18
20
|
sleep,
|
|
21
|
+
wait,
|
|
22
|
+
scheduleFrame,
|
|
19
23
|
match,
|
|
20
24
|
map,
|
|
25
|
+
clear,
|
|
21
26
|
|
|
22
27
|
typex,
|
|
23
28
|
typei,
|
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
|
];
|
|
@@ -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;
|