@makano/rew 1.2.64 → 1.2.65

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
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@makano/rew",
3
- "version": "1.2.64",
3
+ "version": "1.2.65",
4
4
  "description": "A simple coffescript runtime and app manager",
5
5
  "main": "main.js",
6
6
  "directories": {