init.js 898 B

12345678910111213141516171819202122232425
  1. "use strict";
  2. const npmPackagesExists = require("../utils/npm-packages-exists");
  3. const defaultGenerator = require("../generators/init-generator");
  4. const modifyHelper = require("../utils/modify-config-helper");
  5. /**
  6. *
  7. * First function to be called after running the init flag. This is a check,
  8. * if we are running the init command with no arguments or if we got dependencies
  9. *
  10. * @param {Array} args - array of arguments such as
  11. * packages included when running the init command
  12. * @returns {Function} creator/npmPackagesExists - returns an installation of the package,
  13. * followed up with a yeoman instance of that if there's packages. If not, it creates a defaultGenerator
  14. */
  15. module.exports = function initializeInquirer(...args) {
  16. const packages = args.slice(3);
  17. if (packages.length === 0) {
  18. return modifyHelper("init", defaultGenerator);
  19. }
  20. return npmPackagesExists(packages);
  21. };