1 | "use strict";
|
2 | var __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 | };
|
11 | Object.defineProperty(exports, "__esModule", { value: true });
|
12 | const cli_1 = require("./cli");
|
13 | const child_process_1 = require("child_process");
|
14 | const prompts = require("prompts");
|
15 | const cli_helper_1 = require("./cli-helper");
|
16 | function build() {
|
17 | return __awaiter(this, void 0, void 0, function* () {
|
18 | cli_1.Cli.hideBanner = true;
|
19 | cli_helper_1.printSubheader("Build TypeScript Tests");
|
20 | if (!(yield isTscInstalled(3, 7, 0))) {
|
21 | cli_helper_1.printLine(`Must have TypeScript installed globally, with at least version 3.7.0`, "", "Use this command:", "npm i -g typescript", "");
|
22 | cli_1.Cli.exit(1);
|
23 | return;
|
24 | }
|
25 | if (cli_1.Cli.config.project.isSourceAndOutput) {
|
26 | cli_helper_1.printLine("Transpiling TypeScript to JavaScript...");
|
27 | try {
|
28 | yield cli_1.Cli.config.tsc();
|
29 | cli_helper_1.printLine("Done!");
|
30 | cli_1.Cli.exit(0);
|
31 | }
|
32 | catch (err) {
|
33 | cli_1.Cli.log(String(err));
|
34 | cli_1.Cli.exit(1);
|
35 | }
|
36 | return;
|
37 | }
|
38 | cli_helper_1.printLine("This project is not currently configured to use TypeScript with Flagpole.", "");
|
39 | const useTypeScript = yield doYouWantToConfigureTypeScript();
|
40 | if (!useTypeScript) {
|
41 | cli_1.Cli.exit(1);
|
42 | return;
|
43 | }
|
44 | const rootFolder = yield setRootFolder();
|
45 | const sourceFolder = yield setSourceFolder(rootFolder);
|
46 | const outputFolder = yield setOutputFolder(rootFolder);
|
47 | cli_1.Cli.config.project.setTypeScriptFolders(rootFolder, sourceFolder, outputFolder);
|
48 | yield cli_1.Cli.config.save();
|
49 | const tsconfigPath = yield cli_1.Cli.config.writeTsConfig();
|
50 | cli_helper_1.printLine("");
|
51 | });
|
52 | }
|
53 | exports.build = build;
|
54 | const isTscInstalled = (major, minor, build) => __awaiter(void 0, void 0, void 0, function* () {
|
55 | const result = child_process_1.execSync("tsc -v");
|
56 | const match = result.toString().match(/ ([1-9]+\.[0-9]+\.[0-9]+)/);
|
57 | if (match === null) {
|
58 | return false;
|
59 | }
|
60 | const version = match[1].split(".").map(n => parseInt(n));
|
61 | return (version[0] > major ||
|
62 | (version[0] == major && version[1] > minor) ||
|
63 | (version[0] == major && version[1] == minor && version[2] >= build));
|
64 | });
|
65 | const doYouWantToConfigureTypeScript = () => {
|
66 | return new Promise((resolve) => __awaiter(void 0, void 0, void 0, function* () {
|
67 | const response = yield prompts({
|
68 | type: "toggle",
|
69 | name: "useTypeScript",
|
70 | message: "Configure this project to use TypeScript?",
|
71 | initial: true,
|
72 | active: "Yes",
|
73 | inactive: "No"
|
74 | });
|
75 | resolve(response.useTypeScript);
|
76 | }));
|
77 | };
|
78 | const setRootFolder = () => {
|
79 | return new Promise((resolve) => __awaiter(void 0, void 0, void 0, function* () {
|
80 | const response = yield prompts({
|
81 | type: "text",
|
82 | name: "rootFolder",
|
83 | message: "Flagpole Root Folder",
|
84 | initial: `${cli_1.Cli.config.project.path}`
|
85 | });
|
86 | resolve(response.rootFolder);
|
87 | }));
|
88 | };
|
89 | const setSourceFolder = (rootFolder) => {
|
90 | return new Promise((resolve) => __awaiter(void 0, void 0, void 0, function* () {
|
91 | const response = yield prompts({
|
92 | type: "text",
|
93 | name: "sourceFolder",
|
94 | message: `Source Folder ${rootFolder}/`,
|
95 | initial: `src`
|
96 | });
|
97 | resolve(response.sourceFolder);
|
98 | }));
|
99 | };
|
100 | const setOutputFolder = (rootFolder) => {
|
101 | return new Promise((resolve) => __awaiter(void 0, void 0, void 0, function* () {
|
102 | const response = yield prompts({
|
103 | type: "text",
|
104 | name: "outputFolder",
|
105 | message: `Output Folder ${rootFolder}/`,
|
106 | initial: `out`
|
107 | });
|
108 | resolve(response.outputFolder);
|
109 | }));
|
110 | };
|
111 |
|
\ | No newline at end of file |