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.

typescript-if-required.js 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * Copyright 2020 Google Inc. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. const child_process = require('child_process');
  17. const path = require('path');
  18. const fs = require('fs');
  19. const { promisify } = require('util');
  20. const exec = promisify(child_process.exec);
  21. const fsAccess = promisify(fs.access);
  22. const fileExists = async (filePath) =>
  23. fsAccess(filePath)
  24. .then(() => true)
  25. .catch(() => false);
  26. /*
  27. * Now Puppeteer is built with TypeScript, we need to ensure that
  28. * locally we have the generated output before trying to install.
  29. *
  30. * For users installing puppeteer this is fine, they will have the
  31. * generated lib/ directory as we ship it when we publish to npm.
  32. *
  33. * However, if you're cloning the repo to contribute, you won't have the
  34. * generated lib/ directory so this script checks if we need to run
  35. * TypeScript first to ensure the output exists and is in the right
  36. * place.
  37. */
  38. async function compileTypeScript() {
  39. return exec('npm run tsc').catch((error) => {
  40. console.error('Error running TypeScript', error);
  41. process.exit(1);
  42. });
  43. }
  44. async function compileTypeScriptIfRequired() {
  45. const libPath = path.join(__dirname, 'lib');
  46. const libExists = await fileExists(libPath);
  47. if (libExists) return;
  48. console.log('Puppeteer:', 'Compiling TypeScript...');
  49. await compileTypeScript();
  50. }
  51. // It's being run as node typescript-if-required.js, not require('..')
  52. if (require.main === module) compileTypeScriptIfRequired();
  53. module.exports = compileTypeScriptIfRequired;