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.

utils.js 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import * as childProcess from 'child_process';
  2. import * as fs from 'fs-extra';
  3. import * as os from 'os';
  4. import * as path from 'path';
  5. async function useAndRemoveDirectory(directory, fn) {
  6. let result;
  7. try {
  8. result = await fn(directory);
  9. }
  10. finally {
  11. await fs.remove(directory);
  12. }
  13. return result;
  14. }
  15. export async function withTempDirectoryIn(parentDirectory = os.tmpdir(), fn) {
  16. const tempDirectoryPrefix = 'electron-download-';
  17. const tempDirectory = await fs.mkdtemp(path.resolve(parentDirectory, tempDirectoryPrefix));
  18. return useAndRemoveDirectory(tempDirectory, fn);
  19. }
  20. export async function withTempDirectory(fn) {
  21. return withTempDirectoryIn(undefined, fn);
  22. }
  23. export function normalizeVersion(version) {
  24. if (!version.startsWith('v')) {
  25. return `v${version}`;
  26. }
  27. return version;
  28. }
  29. /**
  30. * Runs the `uname` command and returns the trimmed output.
  31. */
  32. export function uname() {
  33. return childProcess
  34. .execSync('uname -m')
  35. .toString()
  36. .trim();
  37. }
  38. /**
  39. * Generates an architecture name that would be used in an Electron or Node.js
  40. * download file name.
  41. */
  42. export function getNodeArch(arch) {
  43. if (arch === 'arm') {
  44. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  45. switch (process.config.variables.arm_version) {
  46. case '6':
  47. return uname();
  48. case '7':
  49. default:
  50. return 'armv7l';
  51. }
  52. }
  53. return arch;
  54. }
  55. /**
  56. * Generates an architecture name that would be used in an Electron or Node.js
  57. * download file name, from the `process` module information.
  58. */
  59. export function getHostArch() {
  60. return getNodeArch(process.arch);
  61. }
  62. export function ensureIsTruthyString(obj, key) {
  63. if (!obj[key] || typeof obj[key] !== 'string') {
  64. throw new Error(`Expected property "${key}" to be provided as a string but it was not`);
  65. }
  66. }
  67. export function isOfficialLinuxIA32Download(platform, arch, version, mirrorOptions) {
  68. return (platform === 'linux' &&
  69. arch === 'ia32' &&
  70. Number(version.slice(1).split('.')[0]) >= 4 &&
  71. typeof mirrorOptions === 'undefined');
  72. }
  73. //# sourceMappingURL=utils.js.map