@makano/rew 1.2.21 → 1.2.32

Sign up to get free protection for your applications and to get access to all the features.
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
- const path = require('path');
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");
@@ -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 { fork, exec, execSync } = require('child_process');
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
- const watching = [];
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.positional('command', {
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 getHost = () => `${process.env.USER}@${os.platform()}.${os.hostname()}`;
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 == getHost()) return true;
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 = "${getHost()}" # end\n \nexports { ...secrets }`, appPath.config.package))
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,23 @@ 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',
217
+ }).option('update', {
218
+ alias: 'u',
219
+ describe: 'Update the app',
220
+ type: 'boolean',
221
+ }).option('yes', {
222
+ alias: 'y',
223
+ describe: 'Auto yes',
224
+ type: 'boolean',
232
225
  });
233
226
  },
234
227
  async (argv) => {
235
- utils.installAppFrom(argv.path);
228
+ if(argv.requirements) utils.installReq(argv.path, argv);
229
+ else utils.installAppFrom(argv.path, argv);
236
230
  },
237
231
  )
238
232
  .command(
@@ -261,14 +255,20 @@ yargs(hideBin(process.argv))
261
255
  const pkg = JSON.parse(readFileSync(path.resolve(__dirname, '../../../package.json'), { encoding: 'utf-8' }));
262
256
  const getLatest = async () => {
263
257
  try{
264
- return (await (await fetch(`https://registry.npmjs.org/${pkg.name}`)).json()).dist_tags.latest.yellow.bold
258
+ return (await req(`https://registry.npmjs.org/${pkg.name}`)).data['dist-tags'].latest
265
259
  } catch(e) {
266
260
  return `(${'!err'.blue.bgRed}, see ${`https://npmjs.com/package/${pkg.name}`.blue.underline})`;
267
261
  }
268
262
  }
269
263
  log(`${'Rew'.red.bold} ${'RUNTIME'.yellow}`);
270
- log(`Version: ${pkg.name.green}@${pkg.version.yellow.bold}`);
271
- log(`Latest: ${pkg.name}@${await getLatest()}`, ':end');
264
+ log(`Version: ${pkg.name.green.bold}@${pkg.version.yellow.bold}`.magenta.bold);
265
+ const latest = await getLatest();
266
+ const isLatest = latest === pkg.version;
267
+ log(`Latest: ${pkg.name.cyan.bold}@${latest.yellow.bold}`.green.bold, isLatest ? ':end' : '');
268
+ if(!isLatest){
269
+ log(`There is an update available`.cyan.bold);
270
+ log('Update With:'.yellow, `npm i -g ${npm_package_name}`.green.bold, ':end');
271
+ }
272
272
  },
273
273
  )
274
274
  .command(
@@ -1,15 +1,8 @@
1
+ // run.js
1
2
  const { run } = require('../main');
2
3
 
3
- function exec(filePath) {
4
- return run(filePath).context.module.imports;
4
+ function exec(filePath, argv) {
5
+ return run(filePath, { argv })?.context?.module?.imports || [];
5
6
  }
6
7
 
7
- const onmsg = ({ filePath, watch }) => {
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 };
@@ -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 npm_package_name = '@makano/rew';
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 (c.entry) {
115
- if(byPath && options.dev) c.entry = c.entry.endsWith('.qrew') ? c.entry.replace(/\.qrew$/, '.coffee') : c.entry;
116
- let r = path.resolve(root, c.entry);
117
- if(options.build) {
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
- const mod_path = path.resolve(root, 'snode_moduless/@makano/rew');
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.description) {
198
+ if (p.descriptiondescription) {
163
199
  log(' Description'.blue + ': ' + p.description);
164
200
  }
165
- rl.question(logget('Install '.blue + pname.green.bold + '? (y/N) '), (f) => {
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
- execSync(command.replace(/\$installPath/g, installPath));
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
- run(path.join(installPath, c.install.file));
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
- build(argv){
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,29 +418,29 @@ 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
- async fromRepo(repoAndPkg){
337
- const [repo, pkg] = repoAndPkg.slice(1).split('/');
426
+ async fromRepo(repoAndPkg, opts) {
427
+ const [repo, pkg] = repoAndPkg.slice(1).split('/');
338
428
  const repoUrl = this.findRepo(repo);
339
- if(!repoUrl){
340
- log(` Repository "${repo.green}"`.red.bold, `not found.`.red.bold);
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
- },
440
+ },
351
441
  async repo(command, key, value) {
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') {
@@ -362,11 +452,11 @@ module.exports = {
362
452
  } else if (command === 'view') {
363
453
  if (key) {
364
454
  const url = confInstance.get(key);
365
- if(!url) return log(' Repo not found'.red.bold, ':end');
455
+ if (!url) return log(' Repo not found'.red.bold, ':end');
366
456
  const json = await this.getRepoJson(url);
367
- if(json.name) log(json.name);
457
+ if (json.name) log(json.name);
368
458
  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');
459
+ if (json.packages) Object.keys(json.packages).forEach(name => log(name)) || log(`${Object.keys(json.packages).length} Packages in ${key}`, ':end');
370
460
  else log('None'.blue, ':end')
371
461
  } else {
372
462
  console.log(Object.keys(confInstance.getAll()).join('\n'));
@@ -376,8 +466,11 @@ module.exports = {
376
466
  } else {
377
467
  log(' Invalid command'.red.bold, ':end');
378
468
  }
379
- },
380
- initFirst(){
469
+ },
470
+ initFirst() {
471
+ log('First time init')
381
472
  conf({}).create('').optionCenter('repos').set('rewpkgs', '//raw.githubusercontent.com/kevinJ045/rewpkgs/main/main.yaml');
473
+ fs.mkdirSync(binpath, { recursive: true });
474
+ fs.mkdirSync(logspath, { recursive: true });
382
475
  }
383
476
  };
@@ -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,
@@ -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: HOME_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
  ];
@@ -0,0 +1,3 @@
1
+ Function.prototype.wait = function(...args) {
2
+ return wait(this, ...args);
3
+ };