init.js 972 B

12345678910111213141516171819202122232425262728293031323334353637
  1. 'use strict';
  2. /**
  3. * Command module for "init" command
  4. *
  5. * @private
  6. * @module
  7. */
  8. const fs = require('fs');
  9. const path = require('path');
  10. const mkdirp = require('mkdirp');
  11. exports.command = 'init <path>';
  12. exports.description = 'create a client-side Mocha setup at <path>';
  13. exports.builder = yargs =>
  14. yargs.positional('path', {
  15. type: 'string',
  16. normalize: true
  17. });
  18. exports.handler = argv => {
  19. const destdir = argv.path;
  20. const srcdir = path.join(__dirname, '..', '..');
  21. mkdirp.sync(destdir);
  22. const css = fs.readFileSync(path.join(srcdir, 'mocha.css'));
  23. const js = fs.readFileSync(path.join(srcdir, 'mocha.js'));
  24. const tmpl = fs.readFileSync(
  25. path.join(srcdir, 'lib', 'browser', 'template.html')
  26. );
  27. fs.writeFileSync(path.join(destdir, 'mocha.css'), css);
  28. fs.writeFileSync(path.join(destdir, 'mocha.js'), js);
  29. fs.writeFileSync(path.join(destdir, 'tests.spec.js'), '');
  30. fs.writeFileSync(path.join(destdir, 'index.html'), tmpl);
  31. };