@makano/rew 1.2.41 → 1.2.43

Sign up to get free protection for your applications and to get access to all the features.
@@ -223,6 +223,10 @@ yargs(hideBin(process.argv))
223
223
  alias: 'r',
224
224
  describe: 'Install requirements of the app',
225
225
  type: 'boolean',
226
+ }).option('verbose', {
227
+ alias: 'v',
228
+ describe: 'Verbose',
229
+ type: 'boolean',
226
230
  }).option('update', {
227
231
  alias: 'u',
228
232
  describe: 'Update the app',
@@ -280,6 +284,20 @@ yargs(hideBin(process.argv))
280
284
  }
281
285
  },
282
286
  )
287
+
288
+ .command(
289
+ 'cache <command>',
290
+ 'Manage cache',
291
+ (yargs) => {
292
+ yargs.positional('command', {
293
+ describe: 'Command to clear/list',
294
+ type: 'string',
295
+ });
296
+ },
297
+ async (argv) => {
298
+ utils.cache(argv.command)
299
+ },
300
+ )
283
301
  .command(
284
302
  'repo <command> [name] [url]',
285
303
  'Manage install repositories',
@@ -4,6 +4,8 @@ const middlePrefix = '├';
4
4
  const separator = '│';
5
5
  const endPrefix = '╰';
6
6
 
7
+ let last = '';
8
+
7
9
  const log = (module.exports.log = function (...toPrint) {
8
10
  let prefix = start ? startPrefix : middlePrefix;
9
11
  let returns = false;
@@ -16,8 +18,10 @@ const log = (module.exports.log = function (...toPrint) {
16
18
  toPrint.pop();
17
19
  }
18
20
  if (prefix == endPrefix && start) prefix = separator;
19
- if (!start) console.log(separator);
21
+ // if(last == endPrefix && prefix == separator) prefix = startPrefix;
22
+ if (!start) console.log(last == endPrefix ? startPrefix : separator);
20
23
  if (start) start = false;
24
+ last = prefix;
21
25
  if (returns) return [prefix, ...toPrint].join(' ');
22
26
  else console.log(prefix, ...toPrint);
23
27
  });
@@ -14,9 +14,14 @@ const { req } = require('../misc/req');
14
14
  const { CONFIG_PATH } = require('../const/config_path');
15
15
  const { watch } = require('chokidar');
16
16
  const { execRewFile } = require('./run');
17
+ const { seededID } = require('../misc/seededid');
18
+ const loading = require('loading-cli');
19
+ const sleep = require('../functions/sleep');
20
+ const { gen_key } = require('../misc/bin');
17
21
 
18
22
  const binpath = path.join(conf({}).create('').root, '.bin');
19
23
  const logspath = path.join(conf({}).create('').root, '.logs');
24
+ const cachepath = path.join(conf({}).create('').root, '.cache');
20
25
  const localBinPath = path.join(binpath, '../../../', 'bin');
21
26
 
22
27
  module.exports = {
@@ -195,28 +200,30 @@ module.exports = {
195
200
  });
196
201
  log(' Installing '.blue + pname.green.bold);
197
202
  log(' Package'.blue + ': ' + p.name.green + '@' + p.version.yellow);
198
- if (p.descriptiondescription) {
199
- log(' Description'.blue + ': ' + p.description);
203
+ if (p.description) {
204
+ log(' Description'.blue + '\n' + p.description.split('\n').map((i, ind, a) => ' '+(ind == 0 && a.length > 1 ? log.startPrefix : (a.length-1 == ind ? log.endPrefix : log.middlePrefix))+' '+i).join('\n'), ':end');
205
+ }
206
+ if (p.keywords && p.keywords.length) {
207
+ log(' Tags'.blue + '\n ' + log.endPrefix + p.keywords.map(i => '#'+i).join(' '), ':end')
200
208
  }
201
209
  const done = (f) => {
202
210
  if (f.toLowerCase() == 'y' || f.toLowerCase() == 'yes') {
203
211
  if (fs.existsSync(installPath)) {
204
212
  execSync(`rm -r ${installPath}`);
205
213
  }
206
- execSync(`cp -r ${apppath} ${installPath}`);
207
- execSync(`chmod 444 ${installPath}/app.yaml`);
208
- if (rmidir) {
209
- execSync(`rm -r ${apppath}`);
210
- }
211
- log(' Installed '.green + pname.cyan.bold, c.install ? '' : ':end');
212
- if (c.install) {
213
- if (c.install.build) {
214
- log(' Building'.blue);
214
+ if (c.install?.build) {
215
+ log(' Building'.blue);
216
+ try{
215
217
  this.build({
216
218
  ...c.install.build,
217
- file: path.join(installPath, c.install.build.file)
219
+ file: path.join(apppath, c.exec[c.install.build.file] || c.install.build.file)
218
220
  });
219
- }
221
+ } catch(e){}
222
+ }
223
+ execSync(`cp -r ${apppath} ${installPath}`);
224
+ execSync(`chmod 444 ${installPath}/app.yaml`);
225
+ log(' Installed '.green + pname.cyan.bold, ':end');
226
+ if (c.install) {
220
227
  if (c.install.commands) {
221
228
  for (let command of c.install.commands) {
222
229
  try{
@@ -232,7 +239,7 @@ module.exports = {
232
239
  this.runFileWithArgv(path.join(installPath, c.exec[c.install.file] || c.install.file), {}, []);
233
240
  }
234
241
  if (c.install.requirements) {
235
- this.installReq(c);
242
+ this.installReq(c, opts);
236
243
  }
237
244
  if (c.install.exec) {
238
245
  // this.installReq(c);
@@ -251,9 +258,6 @@ module.exports = {
251
258
  }
252
259
  rl.close();
253
260
  } else {
254
- if (rmidiri) {
255
- execSync(`rm -rf ${apppath}`);
256
- }
257
261
  log(' Canceled install'.red.bold, ':end');
258
262
  rl.close();
259
263
  }
@@ -355,21 +359,51 @@ module.exports = {
355
359
  processFile(filePath, importsArray);
356
360
  log('󰈔 Compiled'.yellow, (importsArray.length + 1 + '').blue, `file${importsArray.length ? 's' : ''}.`.yellow, ':end');
357
361
  },
358
- async cloneGit(gitpath) {
362
+ cache(command){
363
+ if(command == 'list'){
364
+ console.log(fs.readdirSync(cachepath).join('\n').trim());
365
+ } else {
366
+ fs.readdirSync(cachepath).forEach(file => fs.rmSync(path.join(cachepath, file), { recursive: true }));
367
+ }
368
+ },
369
+ async cloneGit(gitpath, opts) {
359
370
  const p = gitpath.split('github:')[1];
371
+ const clonePath = path.join(cachepath, 'rew-git-clone-'+gen_key(gitpath).substring(0, 12));
360
372
  const url = `https://github.com/${p}`;
361
- const apiurl = `https://api.github.com/repos/${p}`;
373
+ const apiurl = `https://api.github.com/repos/${p}/commits`;
374
+ const load = loading("Finding Repo...".yellow).start();
362
375
  try {
363
376
  const response = await req(apiurl);
364
- if (response.status !== 200) return log(' Repo not found'.red.bold, ':end');
365
- log(''.blue, 'Cloning from github'.yellow);
366
- const tempPath = '/tmp/rew-git-clone-' + p.replace(/\//g, '_') + '-' + generateRandomID();
367
- execSync(`git clone ${url} ${tempPath}`, { stdio: 'ignore' });
368
- log(''.blue, 'Installing deps...'.yellow);
369
- execSync(`cd ${tempPath} && npm i`);
370
- return tempPath;
377
+ if (response.status !== 200) {
378
+ load.stop();
379
+ return log(' Package not found in github'.red.bold, ':end');
380
+ }
381
+ let pull = false;
382
+ if(fs.existsSync(clonePath)){
383
+ if(fs.existsSync(path.join(clonePath, response.data[0].sha))){
384
+ load.stop();
385
+ log('Found Cache'.yellow);
386
+ return clonePath+'/clone';
387
+ } else {
388
+ pull = true;
389
+ }
390
+ }
391
+ fs.mkdirSync(clonePath, { recursive: true });
392
+ fs.writeFileSync(path.join(clonePath, response.data[0].sha), '');
393
+ load.text = 'Cloning from github'.blue.bold;
394
+ await sleep(100)
395
+ if(pull) execSync(`cd ${clonePath}/clone && git pull`, { stdio: opts.verbose ? 'inherit' : 'ignore' });
396
+ else execSync(`git clone ${url} ${clonePath}/clone`, { stdio: opts.verbose ? 'pipe' : 'ignore' });
397
+ load.text = 'Installing npm packages'.green.bold;
398
+ await sleep(100)
399
+ execSync(`cd ${clonePath}/clone && npm i`, { stdio: opts.verbose ? 'inherit' : 'ignore' });
400
+ load.stop();
401
+ return clonePath+'/clone';
371
402
  } catch (e) {
372
- log(' Repo not found'.red.bold, ':end');
403
+ const logFile = path.join(logspath, 'logs-'+Date.now()+'.log');
404
+ fs.writeFileSync(logFile, e.toString() +'\n'+ e.stack);
405
+ load.stop();
406
+ log(' Something went wrong, check logs at'.red.bold, logFile.green, ':end');
373
407
  }
374
408
  },
375
409
  findRepo(repo) {
@@ -377,7 +411,7 @@ module.exports = {
377
411
  return repos.get(repo);
378
412
  },
379
413
  async installAppFrom(path, opts) {
380
- if (path.startsWith('github:')) this.installApp(await this.cloneGit(path), opts, true, true);
414
+ if (path.startsWith('github:')) this.installApp(await this.cloneGit(path, opts), opts, true);
381
415
  else if (path.startsWith('@')) this.fromRepo(path, opts);
382
416
  else this.installApp(path, opts, null, null);
383
417
  },
@@ -465,7 +499,7 @@ module.exports = {
465
499
  console.log(Object.keys(confInstance.getAll()).join('\n'));
466
500
  }
467
501
  } else if (command === 'delete') {
468
- confInstance.remove('repos');
502
+ confInstance.remove(key);
469
503
  } else {
470
504
  log(' Invalid command'.red.bold, ':end');
471
505
  }
@@ -474,6 +508,7 @@ module.exports = {
474
508
  log('First time init')
475
509
  conf({}).create('').optionCenter('repos').set('rewpkgs', '//raw.githubusercontent.com/kevinJ045/rewpkgs/main/main.yaml');
476
510
  fs.mkdirSync(binpath, { recursive: true });
511
+ fs.mkdirSync(cachepath, { recursive: true });
477
512
  fs.mkdirSync(logspath, { recursive: true });
478
513
  }
479
514
  };
@@ -23,8 +23,8 @@ module.exports = (currentFile) => {
23
23
  );
24
24
  };
25
25
 
26
- function spawn(command, options) {
27
- return shell.spawn(command, options);
26
+ function spawn(command, ...args) {
27
+ return shell.spawn(command, ...args);
28
28
  }
29
29
 
30
30
  return { exec, spawn };
@@ -1,5 +1,5 @@
1
- module.exports.generateRandomID = function generateRandomID(length = 12, characters) {
2
- const characters = characters || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
1
+ module.exports.generateRandomID = function generateRandomID(length = 12, _characters) {
2
+ const characters = _characters || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
3
3
  const charactersLength = characters.length;
4
4
  let randomID = '';
5
5
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@makano/rew",
3
- "version": "1.2.41",
3
+ "version": "1.2.43",
4
4
  "description": "A simple coffescript runtime and app manager",
5
5
  "main": "main.js",
6
6
  "directories": {
@@ -38,6 +38,7 @@
38
38
  "colors": "^1.4.0",
39
39
  "deasync": "^0.1.30",
40
40
  "js-yaml": "^4.1.0",
41
+ "loading-cli": "^1.1.2",
41
42
  "tiny-msgpack": "^2.2.0",
42
43
  "uuid": "^9.0.1",
43
44
  "vm": "^0.1.0",