import getGitConfig from "parse-git-config"; import { capitalize } from "lodash"; import templates from "./templates"; import { ExtendedPromptObject } from "./extended-prompts"; // Use email from git config | OS username or empty string as an initial value. // Format `value` to `value@wix.com` or use original value if it's already contains @wix.com. // Check if string is not in an email format. const withoutEmail = (value: string) => value.length && !/@+/.test(value); export default (): Array> => { const gitConfig = getGitConfig.sync({ include: true, type: "global" }); const gitUser = gitConfig.user || {}; const gitName = gitUser.name || ""; const gitEmail = gitUser.email || ""; return [ { type: "text", name: "authorName", message: "Author name", initial: gitName, }, { type: "text", name: "authorEmail", message: "Author email", }, { type: "autocomplete", name: "templateDefinition", message: "Choose project type", choices: templates.map((project) => ({ title: project.title || project.name, value: project, })), next(answers) { const questions: Array> = []; if (answers.templateDefinition.name === "server") { questions.push({ type: "select", name: "serverless", message: "If you are creating a platformized server we endorse you to check out wix-serverless", choices: [ { title: "Take me to serverless docs!", value: true }, { title: "Generate a node platform based server", value: false, }, ], }); } const templateLangs = answers.templateDefinition.availableLanguages; if (templateLangs.length === 1) { answers.language = templateLangs[0]; } else { questions.push({ type: "select", name: "language", message: "Choose JavaScript Transpiler", async getDynamicChoices(answers: any) { return answers.templateDefinition.availableLanguages.map( (lang: string) => ({ title: capitalize(lang), value: lang, }) ); }, }); } return questions; }, }, ]; };