No Description
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.

javascript.js 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.setup = void 0;
  4. const fs = require("fs");
  5. const path = require("path");
  6. const npm_dependencies_1 = require("./npm-dependencies");
  7. const prompt_1 = require("../../../prompt");
  8. const projectConfig_1 = require("../../../functions/projectConfig");
  9. const TEMPLATE_ROOT = path.resolve(__dirname, "../../../../templates/init/functions/javascript/");
  10. const INDEX_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, "index.js"), "utf8");
  11. const PACKAGE_LINTING_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, "package.lint.json"), "utf8");
  12. const PACKAGE_NO_LINTING_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, "package.nolint.json"), "utf8");
  13. const ESLINT_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, "_eslintrc"), "utf8");
  14. const GITIGNORE_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, "_gitignore"), "utf8");
  15. function setup(setup, config) {
  16. return (0, prompt_1.prompt)(setup.functions, [
  17. {
  18. name: "lint",
  19. type: "confirm",
  20. message: "Do you want to use ESLint to catch probable bugs and enforce style?",
  21. default: false,
  22. },
  23. ])
  24. .then(() => {
  25. if (setup.functions.lint) {
  26. const cbconfig = (0, projectConfig_1.configForCodebase)(setup.config.functions, setup.functions.codebase);
  27. cbconfig.predeploy = ['npm --prefix "$RESOURCE_DIR" run lint'];
  28. return config
  29. .askWriteProjectFile(`${setup.functions.source}/package.json`, PACKAGE_LINTING_TEMPLATE)
  30. .then(() => {
  31. config.askWriteProjectFile(`${setup.functions.source}/.eslintrc.js`, ESLINT_TEMPLATE);
  32. });
  33. }
  34. return config.askWriteProjectFile(`${setup.functions.source}/package.json`, PACKAGE_NO_LINTING_TEMPLATE);
  35. })
  36. .then(() => {
  37. return config.askWriteProjectFile(`${setup.functions.source}/index.js`, INDEX_TEMPLATE);
  38. })
  39. .then(() => {
  40. return config.askWriteProjectFile(`${setup.functions.source}/.gitignore`, GITIGNORE_TEMPLATE);
  41. })
  42. .then(() => {
  43. return (0, npm_dependencies_1.askInstallDependencies)(setup.functions, config);
  44. });
  45. }
  46. exports.setup = setup;