@makano/rew 1.2.2 → 1.2.4
Sign up to get free protection for your applications and to get access to all the features.
- 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/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,3 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
|
-
|
3
|
-
|
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
|
+
global.fileName = __filename;
|
3
|
+
require("../lib/rew/cli/cli.js");
|
package/lib/rew/cli/cli.js
CHANGED
@@ -3,10 +3,9 @@
|
|
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
|
-
const { existsSync, readFileSync, writeFileSync, mkdirSync } = require('fs');
|
8
|
+
const { existsSync, readFileSync, writeFileSync, mkdirSync, statSync } = require('fs');
|
10
9
|
const { log } = require('./log');
|
11
10
|
const os = require('os');
|
12
11
|
const crypto = require('crypto');
|
@@ -16,12 +15,25 @@ 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
|
+
|
28
|
+
function isFileArgument(file) {
|
29
|
+
try {
|
30
|
+
return existsSync(file) && statSync(file).isFile();
|
31
|
+
} catch {
|
32
|
+
return false;
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
const isFileGiven = isFileArgument(hideBin(process.argv)[0]) || hideBin(process.argv)[0] == 'run';
|
25
37
|
yargs(hideBin(process.argv))
|
26
38
|
.command(
|
27
39
|
'$0 <file>',
|
@@ -41,31 +53,10 @@ yargs(hideBin(process.argv))
|
|
41
53
|
(argv) => {
|
42
54
|
const filePath = path.resolve(process.cwd(), argv.file);
|
43
55
|
if (!existsSync(filePath)) {
|
44
|
-
log('File not found:', argv.file, ':end');
|
56
|
+
log('File not found:'.red.bold, argv.file, ':end');
|
45
57
|
return;
|
46
58
|
}
|
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();
|
59
|
+
utils.runFileWithArgv(filePath, { watch: argv.watch });
|
69
60
|
},
|
70
61
|
)
|
71
62
|
.command(
|
@@ -122,19 +113,6 @@ yargs(hideBin(process.argv))
|
|
122
113
|
console.log('Encryption Key:', rune({}).genKey(input('Secret Value: ') || null));
|
123
114
|
},
|
124
115
|
)
|
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
116
|
.command(
|
139
117
|
'run <path | package>',
|
140
118
|
'Run an app',
|
@@ -143,20 +121,25 @@ yargs(hideBin(process.argv))
|
|
143
121
|
describe: 'Path of the app to run',
|
144
122
|
type: 'string',
|
145
123
|
})
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
124
|
+
.option('dev', {
|
125
|
+
describe: 'If your entry file is a .qrew, then just use the .coffee instead',
|
126
|
+
type: 'boolean',
|
127
|
+
})
|
128
|
+
.option('entry', {
|
129
|
+
alias: 'e',
|
130
|
+
describe: 'Choose entry file from app.config.exec',
|
131
|
+
type: 'string',
|
132
|
+
})
|
133
|
+
.option('build', {
|
134
|
+
alias: 'b',
|
135
|
+
describe: 'Builds to a .qrew before running',
|
136
|
+
type: 'boolean',
|
137
|
+
})
|
138
|
+
.option('translate', {
|
139
|
+
alias: 't',
|
140
|
+
describe: 'Builds to a .js before running, only used when --build is passed',
|
141
|
+
type: 'boolean',
|
142
|
+
});
|
160
143
|
},
|
161
144
|
(argv) => {
|
162
145
|
utils.runApp(argv.path, argv);
|
@@ -166,30 +149,37 @@ yargs(hideBin(process.argv))
|
|
166
149
|
'secret <command> [key]',
|
167
150
|
'Add secrets to the current path',
|
168
151
|
(yargs) => {
|
169
|
-
yargs
|
170
|
-
|
171
|
-
|
172
|
-
|
152
|
+
yargs
|
153
|
+
.positional('command', {
|
154
|
+
describe: 'Path of the app to run',
|
155
|
+
type: 'string',
|
156
|
+
})
|
157
|
+
.option('file', {
|
158
|
+
alias: 'f',
|
159
|
+
describe: 'Set file name',
|
160
|
+
type: 'string',
|
161
|
+
default: 'secrets.qrew'
|
162
|
+
})
|
173
163
|
},
|
174
164
|
(argv) => {
|
175
165
|
const appPath = findAppInfo(path.join(process.cwd(), 'app.yaml'));
|
176
166
|
|
177
167
|
if (!appPath) return log(''.red.bold, 'Secrets only available in apps'.red.bold, ':end');
|
178
168
|
|
179
|
-
const qrewPath = path.join(appPath.path, 'secrets.qrew');
|
169
|
+
const qrewPath = path.join(appPath.path, argv.file || 'secrets.qrew');
|
180
170
|
|
181
|
-
const
|
171
|
+
const getPass = () => gen_key(input('Secret Encryptor: '));//`${process.env.USER}@${os.platform()}.${os.hostname()}`;
|
182
172
|
|
183
173
|
const verifyUser = (content) => {
|
184
174
|
const owner = content.match(/^owner = "(.*)" # end$/m)?.[1];
|
185
|
-
if (owner ==
|
175
|
+
if (owner == getPass()) return true;
|
186
176
|
return false;
|
187
177
|
};
|
188
178
|
|
189
179
|
if (argv.command == 'init') {
|
190
|
-
writeFileSync(qrewPath, to_qrew(`secrets = {} # end\n\nowner = "${
|
180
|
+
writeFileSync(qrewPath, to_qrew(`secrets = {} # end\n\nowner = "${getPass()}" # end\n \nexports { ...secrets }`, appPath.config.manifest.package))
|
191
181
|
} else {
|
192
|
-
const currentFileContent = from_qrew(readFileSync(qrewPath), appPath.config.package).toString();
|
182
|
+
const currentFileContent = from_qrew(readFileSync(qrewPath), appPath.config.manifest.package).toString();
|
193
183
|
if (!verifyUser(currentFileContent)) return log(''.red.bold, 'You are not allowed to change this data'.red.bold, ':end');
|
194
184
|
|
195
185
|
const secrets = currentFileContent.match(/^secrets = (.*) # end$/m)?.[1];
|
@@ -208,7 +198,7 @@ yargs(hideBin(process.argv))
|
|
208
198
|
const newSecrets = `secrets = ${JSON.stringify(secretsJson)} # end`;
|
209
199
|
const newFileContent = currentFileContent.replace(/^secrets = .* # end$/m, newSecrets);
|
210
200
|
|
211
|
-
writeFileSync(qrewPath, to_qrew(newFileContent, appPath.config.package))
|
201
|
+
writeFileSync(qrewPath, to_qrew(newFileContent, appPath.config.manifest.package))
|
212
202
|
} else if (argv.command == 'get') {
|
213
203
|
if (argv.key) {
|
214
204
|
console.log(argv.key.yellow, '=', secretsJson[argv.key].green);
|
@@ -229,10 +219,23 @@ yargs(hideBin(process.argv))
|
|
229
219
|
yargs.positional('path', {
|
230
220
|
describe: 'Path or github or repo id of the app to install',
|
231
221
|
type: 'string',
|
222
|
+
}).option('requirements', {
|
223
|
+
alias: 'r',
|
224
|
+
describe: 'Install requirements of the app',
|
225
|
+
type: 'boolean',
|
226
|
+
}).option('update', {
|
227
|
+
alias: 'u',
|
228
|
+
describe: 'Update the app',
|
229
|
+
type: 'boolean',
|
230
|
+
}).option('yes', {
|
231
|
+
alias: 'y',
|
232
|
+
describe: 'Auto yes',
|
233
|
+
type: 'boolean',
|
232
234
|
});
|
233
235
|
},
|
234
236
|
async (argv) => {
|
235
|
-
utils.
|
237
|
+
if (argv.requirements) utils.installReq(argv.path, argv);
|
238
|
+
else utils.installAppFrom(argv.path, argv);
|
236
239
|
},
|
237
240
|
)
|
238
241
|
.command(
|
@@ -260,15 +263,21 @@ yargs(hideBin(process.argv))
|
|
260
263
|
async (argv) => {
|
261
264
|
const pkg = JSON.parse(readFileSync(path.resolve(__dirname, '../../../package.json'), { encoding: 'utf-8' }));
|
262
265
|
const getLatest = async () => {
|
263
|
-
try{
|
264
|
-
return (await (
|
265
|
-
} catch(e) {
|
266
|
+
try {
|
267
|
+
return (await req(`https://registry.npmjs.org/${pkg.name}`)).data['dist-tags'].latest
|
268
|
+
} catch (e) {
|
266
269
|
return `(${'!err'.blue.bgRed}, see ${`https://npmjs.com/package/${pkg.name}`.blue.underline})`;
|
267
270
|
}
|
268
271
|
}
|
269
272
|
log(`${'Rew'.red.bold} ${'RUNTIME'.yellow}`);
|
270
|
-
log(`Version: ${pkg.name.green}@${pkg.version.yellow.bold}
|
271
|
-
|
273
|
+
log(`Version: ${pkg.name.green.bold}@${pkg.version.yellow.bold}`.magenta.bold);
|
274
|
+
const latest = await getLatest();
|
275
|
+
const isLatest = latest === pkg.version;
|
276
|
+
log(`Latest: ${pkg.name.cyan.bold}@${latest.yellow.bold}`.green.bold, isLatest ? ':end' : '');
|
277
|
+
if (!isLatest) {
|
278
|
+
log(`There is an update available`.cyan.bold);
|
279
|
+
log('Update With:'.yellow, `npm i -g ${npm_package_name}`.green.bold, ':end');
|
280
|
+
}
|
272
281
|
},
|
273
282
|
)
|
274
283
|
.command(
|
@@ -287,9 +296,13 @@ yargs(hideBin(process.argv))
|
|
287
296
|
describe: 'url of the repo',
|
288
297
|
type: 'string',
|
289
298
|
});
|
299
|
+
yargs.option('json', {
|
300
|
+
describe: 'Return a json output',
|
301
|
+
type: 'boolean',
|
302
|
+
});
|
290
303
|
},
|
291
304
|
async (argv) => {
|
292
|
-
utils.repo(argv.command, argv.name, argv.url);
|
305
|
+
utils.repo(argv.command, argv.name, argv.url, argv);
|
293
306
|
},
|
294
307
|
)
|
295
308
|
.command(
|
@@ -326,4 +339,4 @@ yargs(hideBin(process.argv))
|
|
326
339
|
utils.build(argv);
|
327
340
|
},
|
328
341
|
)
|
329
|
-
.help().argv;
|
342
|
+
.help(!isFileGiven).argv;
|
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 };
|