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.

instrument.js 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. 'use strict'
  2. const NYC = require('../../index.js')
  3. const path = require('path')
  4. const { promisify } = require('util')
  5. const resolveFrom = require('resolve-from')
  6. const rimraf = promisify(require('rimraf'))
  7. const { cliWrapper, setupOptions } = require('./helpers.js')
  8. exports.command = 'instrument <input> [output]'
  9. exports.describe = 'instruments a file or a directory tree and writes the instrumented code to the desired output location'
  10. exports.builder = function (yargs) {
  11. yargs
  12. .demandCommand(0, 0)
  13. .example('$0 instrument ./lib ./output', 'instrument all .js files in ./lib with coverage and output in ./output')
  14. setupOptions(yargs, 'instrument')
  15. }
  16. exports.handler = cliWrapper(async argv => {
  17. if (argv.output && !argv.inPlace && (path.resolve(argv.cwd, argv.input) === path.resolve(argv.cwd, argv.output))) {
  18. throw new Error('cannot instrument files in place, <input> must differ from <output>. Set \'--in-place\' to force')
  19. }
  20. if (path.relative(argv.cwd, path.resolve(argv.cwd, argv.input)).startsWith('..')) {
  21. throw new Error('cannot instrument files outside project root directory')
  22. }
  23. if (argv.delete && argv.inPlace) {
  24. throw new Error('cannot use \'--delete\' when instrumenting files in place')
  25. }
  26. if (argv.delete && argv.output && argv.output.length !== 0) {
  27. const relPath = path.relative(process.cwd(), path.resolve(argv.output))
  28. if (relPath !== '' && !relPath.startsWith('..')) {
  29. await rimraf(argv.output)
  30. } else {
  31. throw new Error(`attempt to delete '${process.cwd()}' or containing directory.`)
  32. }
  33. }
  34. // If instrument is set to false enable a noop instrumenter.
  35. argv.instrumenter = (argv.instrument)
  36. ? './lib/instrumenters/istanbul'
  37. : './lib/instrumenters/noop'
  38. if (argv.inPlace) {
  39. argv.output = argv.input
  40. argv.completeCopy = false
  41. }
  42. const nyc = new NYC(argv)
  43. if (!argv.useSpawnWrap) {
  44. nyc.require.forEach(requireModule => {
  45. const mod = resolveFrom.silent(nyc.cwd, requireModule) || requireModule
  46. require(mod)
  47. })
  48. }
  49. await nyc.instrumentAllFiles(argv.input, argv.output)
  50. })