@makano/rew 1.2.64 → 1.2.66

Sign up to get free protection for your applications and to get access to all the features.
@@ -405,20 +405,37 @@ module.exports = {
405
405
  }
406
406
  },
407
407
  async cloneGit(gitpath, opts) {
408
- const p = gitpath.split('github:')[1];
408
+ let p = gitpath.split('github:')[1];
409
409
  const clonePath = path.join(cachepath, 'rew-git-clone-'+gen_key(gitpath).substring(0, 12));
410
+ const load = loading("Finding Repo...".yellow).start();
411
+
412
+ let branch = null; // Default branch
413
+ let commit = null;
414
+
415
+ // Extracting branch or commit if specified
416
+ if (p.includes('@')) {
417
+ [p, branch] = p.split('@');
418
+ }
419
+ if (branch?.includes('#')) {
420
+ [branch, commit] = branch.split('#');
421
+ }
422
+ if (p.includes('#')) {
423
+ [p, commit] = p.split('#');
424
+ }
425
+
410
426
  const url = `https://github.com/${p}`;
411
427
  const apiurl = `https://api.github.com/repos/${p}/commits`;
412
- const load = loading("Finding Repo...".yellow).start();
428
+
413
429
  try {
414
430
  const response = await req(apiurl);
431
+ if(!commit) commit = response.data[0].sha;
415
432
  if (response.status !== 200) {
416
433
  load.stop();
417
434
  return log(' Package not found in github'.red.bold, ':end');
418
435
  }
419
436
  let pull = false;
420
437
  if(fs.existsSync(clonePath)){
421
- if(fs.existsSync(path.join(clonePath, response.data[0].sha))){
438
+ if(fs.existsSync(path.join(clonePath, commit))){
422
439
  load.stop();
423
440
  log('Found Cache'.yellow);
424
441
  return clonePath+'/clone';
@@ -427,20 +444,23 @@ module.exports = {
427
444
  }
428
445
  }
429
446
  fs.mkdirSync(clonePath, { recursive: true });
430
- fs.writeFileSync(path.join(clonePath, response.data[0].sha), '');
431
- load.text = 'Cloning from github'.blue.bold;
447
+ fs.writeFileSync(path.join(clonePath, commit), '');
448
+ load.text = pull ? 'Updating repository'.blue.bold : 'Cloning from github'.blue.bold;
432
449
  await sleep(100)
433
- if(pull) execSync(`cd ${clonePath}/clone && git pull`, { stdio: opts.verbose ? 'inherit' : 'ignore' });
434
- else execSync(`git clone ${url} ${clonePath}/clone`, { stdio: opts.verbose ? 'pipe' : 'ignore' });
435
- load.text = 'Installing npm packages'.green.bold;
436
- await sleep(100)
437
- execSync(`cd ${clonePath}/clone && npm i`, { stdio: opts.verbose ? 'inherit' : 'ignore' });
450
+ if(pull) execSync(`cd ${clonePath}/clone && git fetch --all${response.data[0].sha !== commit ? ` && git reset --hard ${commit}` : ''}`, { stdio: opts.verbose ? 'inherit' : 'ignore' });
451
+ else execSync(`git clone ${url} ${clonePath}/clone && cd ${clonePath}/clone${response.data[0].sha !== commit ? ` && git reset --hard ${commit}` : ''}${branch ? ' && git checkout '+branch : ''}`, { stdio: opts.verbose ? 'pipe' : 'ignore' });
452
+ if (fs.existsSync(path.join(clonePath, 'clone', 'package.json'))) {
453
+ load.text = 'Installing npm packages'.green.bold;
454
+ await sleep(100);
455
+ execSync(`cd ${clonePath}/clone && npm install`, { stdio: opts.verbose ? 'inherit' : 'ignore' });
456
+ }
438
457
  load.stop();
439
458
  return clonePath+'/clone';
440
459
  } catch (e) {
441
460
  const logFile = path.join(logspath, 'logs-'+Date.now()+'.log');
442
461
  fs.writeFileSync(logFile, e.toString() +'\n'+ e.stack);
443
462
  load.stop();
463
+ if(opts.verbose) console.error(e);
444
464
  log(' Something went wrong, check logs at'.red.bold, logFile.green, ':end');
445
465
  }
446
466
  },
@@ -1,4 +1,4 @@
1
1
  const path = require('path');
2
2
 
3
- const CONFIG_PATH = path.resolve(process.env.HOME, '.local/share/rew');
3
+ const CONFIG_PATH = path.resolve(process.env.HOME || process.env.USERPROFILE, '.local/share/rew');
4
4
  module.exports.CONFIG_PATH = CONFIG_PATH;
@@ -12,4 +12,18 @@ module.exports.USING_DEFAULT = {
12
12
  DECORATORS: {
13
13
  use: (options) => options.decorators = true
14
14
  }
15
+ }
16
+
17
+ module.exports.Usage = class Usage {
18
+ name = "null";
19
+ trigger = () => {}
20
+
21
+ constructor(name, trigger){
22
+ this.name = name;
23
+ this.trigger = trigger;
24
+ }
25
+
26
+ create(name, trigger){
27
+ return new Usage(name, trigger);
28
+ }
15
29
  }
@@ -7,7 +7,7 @@ const fsLib = require("../functions/fs");
7
7
  const pathLib = require("../functions/path");
8
8
  const execLib = require("../functions/exec");
9
9
  const { findAppInfo } = require("../misc/findAppInfo");
10
- const { USING_DEFAULT } = require("../const/usage");
10
+ const { USING_DEFAULT, Usage } = require("../const/usage");
11
11
 
12
12
  let mainFile = "";
13
13
  const isMainFile = (filepath) => filepath == mainFile;
@@ -45,6 +45,7 @@ module.exports.prepareContext = function (
45
45
  ...pathLib(filepath),
46
46
  ...execLib(filepath),
47
47
  ...custom_context,
48
+ Usage
48
49
  };
49
50
  }
50
51
  if (!context.process)
@@ -98,6 +99,8 @@ module.exports.prepareContext = function (
98
99
  if(USING_DEFAULT[name].param) {
99
100
  context.__using__[name] = USING_DEFAULT[name].param(...params);
100
101
  }
102
+ } else if(name instanceof Usage) {
103
+ context.__using__[name.name] = name.trigger(...params) || true;
101
104
  } else {
102
105
  context.__using__[name] = params.length ? params.length > 1 ? [...params] : params : true;
103
106
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@makano/rew",
3
- "version": "1.2.64",
3
+ "version": "1.2.66",
4
4
  "description": "A simple coffescript runtime and app manager",
5
5
  "main": "main.js",
6
6
  "directories": {