UNPKG

5.47 kBJavaScriptView Raw
1"use strict";
2var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4 return new (P || (P = Promise))(function (resolve, reject) {
5 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8 step((generator = generator.apply(thisArg, _arguments || [])).next());
9 });
10};
11Object.defineProperty(exports, "__esModule", { value: true });
12const cli_helper_1 = require("./cli-helper");
13const cli_1 = require("./cli");
14const prompts = require("prompts");
15function init() {
16 return __awaiter(this, void 0, void 0, function* () {
17 cli_helper_1.printHeader();
18 cli_helper_1.printSubheader("Initialize Flagpole Project");
19 const initialResponses = yield prompts([
20 {
21 type: "text",
22 name: "project",
23 message: "What is the name of your project?",
24 initial: process
25 .cwd()
26 .split("/")
27 .pop(),
28 format: cli_helper_1.trimInput
29 },
30 {
31 type: "multiselect",
32 name: "env",
33 message: "What environments do you want to support?",
34 hint: "You can easily add more later",
35 initial: "dev",
36 min: 1,
37 max: 8,
38 choices: [
39 { value: "dev", title: "dev" },
40 { value: "stag", title: "stag" },
41 { value: "prod", title: "prod" },
42 { value: "preprod", title: "preprod" },
43 { value: "qa", title: "qa" },
44 { value: "local", title: "local" },
45 { value: "alpha", title: "alpha" },
46 { value: "beta", title: "beta" }
47 ],
48 validate: function (input) {
49 return input.length > 0;
50 }
51 }
52 ]);
53 const domainPrompts = [];
54 initialResponses.env.forEach((env) => {
55 domainPrompts.push({
56 type: "text",
57 name: `domain_${env}`,
58 message: `Default Domain for ${env}`,
59 format: cli_helper_1.trimInput,
60 validate: domain => {
61 return /^https?:\/\/[a-z][a-z0-9_.-]+[a-z](:[0-9]+)?(\/.*)?$/i.test(domain) ?
62 true : 'Must be a valid URL, starting with http:// or https://';
63 }
64 });
65 });
66 const domains = yield prompts(domainPrompts);
67 const tsResponse = yield prompts({
68 type: "toggle",
69 name: "useTypeScript",
70 message: "Do you want Flagpole to use TypeScript?",
71 initial: true,
72 active: "Yes",
73 inactive: "No"
74 });
75 const rootFolder = yield prompts({
76 type: "text",
77 name: "path",
78 message: tsResponse.useTypeScript
79 ? "What is the root subfolder you want to put your tests in? (tsconfig.json will go here)"
80 : "What subfolder do you want to put your tests in?",
81 initial: "tests",
82 format: cli_helper_1.trimInput
83 });
84 let tsFolders = undefined;
85 if (tsResponse.useTypeScript) {
86 tsFolders = yield prompts([
87 {
88 type: "text",
89 name: "sourceFolder",
90 message: `Source Folder ${rootFolder.path}/`,
91 initial: `src`
92 },
93 {
94 type: "text",
95 name: "outputFolder",
96 message: `Output Folder ${rootFolder.path}/`,
97 initial: `out`
98 }
99 ]);
100 }
101 const configOptions = {
102 configPath: `${process.cwd()}/flagpole.json`,
103 project: {
104 name: initialResponses.project,
105 path: rootFolder.path,
106 source: tsFolders == undefined ? undefined : tsFolders.sourceFolder,
107 output: tsFolders == undefined ? undefined : tsFolders.outputFolder
108 },
109 environments: (() => {
110 const out = [];
111 initialResponses.env.forEach((env) => {
112 out.push({
113 name: env,
114 defaultDomain: domains[`domain_${env}`]
115 });
116 });
117 return out;
118 })(),
119 suites: []
120 };
121 cli_1.Cli.hideBanner = true;
122 cli_1.Cli.log("Creating your Flagpole project...");
123 cli_1.Cli.init(configOptions)
124 .then((tasks) => {
125 cli_1.Cli.log("");
126 cli_1.Cli.list(tasks);
127 cli_1.Cli.log("");
128 cli_1.Cli.log("Your Flagpole project was created.");
129 cli_1.Cli.exit(0);
130 })
131 .catch((err) => {
132 cli_1.Cli.log(err);
133 cli_1.Cli.exit(1);
134 });
135 });
136}
137exports.init = init;
138//# sourceMappingURL=init.js.map
\No newline at end of file