@makano/rew 1.2.1 → 1.2.3

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 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
21
  if (!existsSync(CONFIG_PATH)) {
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,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.installAppFrom(argv.path);
220
+ if(argv.requirements) utils.installReq(argv.path);
221
+ else utils.installAppFrom(argv.path);
236
222
  },
237
223
  )
238
224
  .command(
@@ -243,6 +229,7 @@ yargs(hideBin(process.argv))
243
229
  describe: 'Package of the app to uninstall',
244
230
  type: 'string',
245
231
  }).option('all', {
232
+ alias: 'a',
246
233
  describe: 'Remove the configs as well',
247
234
  type: 'boolean',
248
235
  });
@@ -260,14 +247,20 @@ yargs(hideBin(process.argv))
260
247
  const pkg = JSON.parse(readFileSync(path.resolve(__dirname, '../../../package.json'), { encoding: 'utf-8' }));
261
248
  const getLatest = async () => {
262
249
  try{
263
- return (await (await fetch(`https://registry.npmjs.org/${pkg.name}`)).json()).dist_tags.latest.yellow.bold
250
+ return (await req(`https://registry.npmjs.org/${pkg.name}`)).data['dist-tags'].latest
264
251
  } catch(e) {
265
252
  return `(${'!err'.blue.bgRed}, see ${`https://npmjs.com/package/${pkg.name}`.blue.underline})`;
266
253
  }
267
254
  }
268
255
  log(`${'Rew'.red.bold} ${'RUNTIME'.yellow}`);
269
- log(`Version: ${pkg.name.green}@${pkg.version.yellow.bold}`);
270
- log(`Latest: ${pkg.name}@${await getLatest()}`, ':end');
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
+ }
271
264
  },
272
265
  )
273
266
  .command(
@@ -310,6 +303,11 @@ yargs(hideBin(process.argv))
310
303
  describe: 'Translate to js',
311
304
  type: 'boolean',
312
305
  })
306
+ .option('single', {
307
+ alias: 's',
308
+ describe: 'Build single file(don\'t build imports)',
309
+ type: 'boolean',
310
+ })
313
311
  .option('remove', {
314
312
  alias: 'r',
315
313
  describe: 'Remove all coffee',
@@ -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,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 npm_package_name = '@makano/rew';
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 (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) {
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
- 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);
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.description) {
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,14 +208,39 @@ 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
  }
219
+ if (c.install.commands) {
220
+ for (let command of c.install.commands) {
221
+ execSync(command.replace(/\$installPath/g, installPath));
222
+ }
223
+ }
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
+ }
243
+ }
184
244
  }
185
245
  rl.close();
186
246
  } else {
@@ -195,7 +255,21 @@ module.exports = {
195
255
  log(' Path is not a rew app'.red.bold, ':end');
196
256
  }
197
257
  },
198
- build(argv){
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) {
199
273
  function readFile(filePath) {
200
274
  return fs.readFileSync(filePath, { encoding: 'utf-8' });
201
275
  }
@@ -228,7 +302,7 @@ module.exports = {
228
302
  const newFilePath = path.join(dirName, `${baseName}.${argv.translate ? 'js' : 'qrew'}`);
229
303
  fs.writeFileSync(newFilePath, compiledCode);
230
304
  log(`${'Compiled'.green.bold}: ${newFilePath.yellow}`);
231
- if(argv.remove){
305
+ if (argv.remove) {
232
306
  fs.unlinkSync(filePath);
233
307
  log(`${'Removed'.red.bold}: ${filePath.yellow}`);
234
308
  }
@@ -236,7 +310,7 @@ module.exports = {
236
310
 
237
311
  function processFile(filePath, importsArray) {
238
312
  const content = readFile(filePath);
239
- const imports = extractImports(content);
313
+ const imports = argv.single ? [] : extractImports(content);
240
314
 
241
315
  imports.forEach((importStatement) => {
242
316
  const importedFilePath = path.resolve(path.dirname(filePath), importStatement.url);
@@ -256,7 +330,7 @@ module.exports = {
256
330
 
257
331
  const appPath = findAppInfo(filePath);
258
332
 
259
- 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('.'));
260
334
  writeCompiledFile(filePath, compiled);
261
335
  }
262
336
 
@@ -271,7 +345,7 @@ module.exports = {
271
345
  const p = gitpath.split('github:')[1];
272
346
  const url = `https://github.com/${p}`;
273
347
  const apiurl = `https://api.github.com/repos/${p}`;
274
- try{
348
+ try {
275
349
  const response = await req(apiurl);
276
350
  if (response.status !== 200) return log(' Repo not found'.red.bold, ':end');
277
351
  log(''.blue, 'Cloning from github'.yellow);
@@ -280,39 +354,49 @@ module.exports = {
280
354
  log(''.blue, 'Installing deps...'.yellow);
281
355
  execSync(`cd ${tempPath} && npm i`);
282
356
  return tempPath;
283
- } catch(e){
357
+ } catch (e) {
284
358
  log(' Repo not found'.red.bold, ':end');
285
359
  }
286
360
  },
287
- findRepo(repo){
361
+ findRepo(repo) {
288
362
  const repos = conf({}).create('').optionCenter('repos');
289
363
  return repos.get(repo);
290
364
  },
291
- async installAppFrom(path){
365
+ async installAppFrom(path) {
292
366
  if (path.startsWith('github:')) this.installApp(await this.cloneGit(path), true, true);
293
- else if(path.startsWith('@')) this.fromRepo(path);
367
+ else if (path.startsWith('@')) this.fromRepo(path);
294
368
  else this.installApp(path);
295
369
  },
296
- uninstall(packageName, all){
370
+ uninstall(packageName, all) {
297
371
  const confPath = path.join(CONFIG_PATH, packageName);
298
372
  const apppath = path.resolve(confPath, 'app');
299
373
  const appConfpath = path.join(apppath, 'app.yaml');
300
- if(!fs.existsSync(appConfpath) && fs.existsSync(confPath) && !all){
374
+ if (!fs.existsSync(appConfpath) && fs.existsSync(confPath) && !all) {
301
375
  log(` App ${packageName.green}`.red.bold, `not found`.red.bold, `but configs are found.`.green.bold);
302
376
  return log(`Use the`.cyan, '--all'.green, 'flag to remove them.'.cyan, ':end');
303
- } else if(!fs.existsSync(appConfpath) && !all){
377
+ } else if (!fs.existsSync(appConfpath) && !all) {
304
378
  return log(` App ${packageName.green}`.red.bold, `not found.`.red.bold, ':end');
305
379
  }
306
380
  log('Uninstalling'.cyan, packageName.green);
307
- 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
+ });
308
392
  log('Uninstalled'.cyan, ':end');
309
393
  },
310
- async getRepoJson(repoUrl){
311
- try{
312
- 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;
313
397
  const json = text.startsWith('---') || text.startsWith('%YAML') ? jsYaml.loadAll(text)[0] : JSON.parse(text);
314
- if(Array.isArray(json.include)){
315
- for(let i of json.include){
398
+ if (Array.isArray(json.include)) {
399
+ for (let i of json.include) {
316
400
  json.packages = {
317
401
  ...json.packages,
318
402
  ...((await this.getRepoJson(i.startsWith('.') ? path.join(path.dirname(repoUrl), i) : i)).packages || {})
@@ -320,29 +404,29 @@ module.exports = {
320
404
  }
321
405
  }
322
406
  return json;
323
- } catch(e){
407
+ } catch (e) {
324
408
  log(` Fetch Error. Check your connection.`.red.bold);
325
409
  return {};
326
410
  }
327
411
  },
328
- async fromRepo(repoAndPkg){
329
- const [repo, pkg] = repoAndPkg.slice(1).split('/');
412
+ async fromRepo(repoAndPkg) {
413
+ const [repo, pkg] = repoAndPkg.slice(1).split('/');
330
414
  const repoUrl = this.findRepo(repo);
331
- if(!repoUrl){
332
- log(` Repository "${repo.green}"`.red.bold, `not found.`.red.bold);
415
+ if (!repoUrl) {
416
+ log(` Repository "${repo.green}"`.red.bold, `not found.`.red.bold);
333
417
  return log(`Add with:`.yellow, '\n\t$'.green, `rew repo add ${repo} URL`.cyan.bold, ':end');
334
418
  } else {
335
419
  const repoJson = await this.getRepoJson(repoUrl);
336
- if(repoJson?.packages?.[pkg]){
420
+ if (repoJson?.packages?.[pkg]) {
337
421
  await this.installAppFrom(repoJson.packages[pkg]);
338
422
  } else {
339
- 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");
340
424
  }
341
425
  }
342
- },
426
+ },
343
427
  async repo(command, key, value) {
344
428
  const confInstance = conf({}).create('').optionCenter('repos') || {};
345
-
429
+
346
430
  if (command === 'add' || command === 'set') {
347
431
  confInstance.set(key, value.replace('https://', '//').replace('http://', '//.'));
348
432
  } else if (command === 'get') {
@@ -354,22 +438,23 @@ module.exports = {
354
438
  } else if (command === 'view') {
355
439
  if (key) {
356
440
  const url = confInstance.get(key);
357
- if(!url) return log(' Repo not found'.red.bold, ':end');
441
+ if (!url) return log(' Repo not found'.red.bold, ':end');
358
442
  const json = await this.getRepoJson(url);
359
- if(json.name) log(json.name);
443
+ if (json.name) log(json.name);
360
444
  log('Packages:'.yellow)
361
- 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');
362
446
  else log('None'.blue, ':end')
363
447
  } else {
364
- console.log(Object.keys(repos).join('\n'));
448
+ console.log(Object.keys(confInstance.getAll()).join('\n'));
365
449
  }
366
450
  } else if (command === 'delete') {
367
451
  confInstance.remove('repos');
368
452
  } else {
369
453
  log(' Invalid command'.red.bold, ':end');
370
454
  }
371
- },
372
- initFirst(){
455
+ },
456
+ initFirst() {
373
457
  conf({}).create('').optionCenter('repos').set('rewpkgs', '//raw.githubusercontent.com/kevinJ045/rewpkgs/main/main.yaml');
458
+ fs.mkdirSync(binpath, { recursive: true });
374
459
  }
375
460
  };
@@ -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
+ };
@@ -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,5 @@
1
+
2
+ module.exports.scheduleFrame = function scheduleFrame(cb, immediate = false){
3
+ return immediate ? setImmediate(cb) : setTimeout(cb, 1);
4
+ }
5
+