Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.uninstall = exports.add = exports.set = exports.install = void 0;
  4. const cp = require("child_process");
  5. const fs = require("fs");
  6. const p = require("path");
  7. const l = (msg) => console.log(`husky - ${msg}`);
  8. const git = (args) => cp.spawnSync('git', args, { stdio: 'inherit' });
  9. function install(dir = '.husky') {
  10. if (git(['rev-parse']).status !== 0) {
  11. return;
  12. }
  13. const url = 'https://git.io/Jc3F9';
  14. if (!p.resolve(process.cwd(), dir).startsWith(process.cwd())) {
  15. throw new Error(`.. not allowed (see ${url})`);
  16. }
  17. if (!fs.existsSync('.git')) {
  18. throw new Error(`.git can't be found (see ${url})`);
  19. }
  20. try {
  21. fs.mkdirSync(p.join(dir, '_'), { recursive: true });
  22. fs.writeFileSync(p.join(dir, '_/.gitignore'), '*');
  23. fs.copyFileSync(p.join(__dirname, '../husky.sh'), p.join(dir, '_/husky.sh'));
  24. const { error } = git(['config', 'core.hooksPath', dir]);
  25. if (error) {
  26. throw error;
  27. }
  28. }
  29. catch (e) {
  30. l('Git hooks failed to install');
  31. throw e;
  32. }
  33. l('Git hooks installed');
  34. }
  35. exports.install = install;
  36. function set(file, cmd) {
  37. const dir = p.dirname(file);
  38. if (!fs.existsSync(dir)) {
  39. throw new Error(`can't create hook, ${dir} directory doesn't exist (try running husky install)`);
  40. }
  41. fs.writeFileSync(file, `#!/bin/sh
  42. . "$(dirname "$0")/_/husky.sh"
  43. ${cmd}
  44. `, { mode: 0o0755 });
  45. l(`created ${file}`);
  46. }
  47. exports.set = set;
  48. function add(file, cmd) {
  49. if (fs.existsSync(file)) {
  50. fs.appendFileSync(file, `${cmd}\n`);
  51. l(`updated ${file}`);
  52. }
  53. else {
  54. set(file, cmd);
  55. }
  56. }
  57. exports.add = add;
  58. function uninstall() {
  59. git(['config', '--unset', 'core.hooksPath']);
  60. }
  61. exports.uninstall = uninstall;