Skip to content

Commit 3692a20

Browse files
authored
Add custom output directory option and git clone command (#5)
1 parent 85cb1f2 commit 3692a20

File tree

3 files changed

+84
-5
lines changed

3 files changed

+84
-5
lines changed

cli/index.ts

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import boxen from "boxen";
22
import chalk from "chalk";
33
import figlet from "figlet";
44
import inquirer from "inquirer";
5+
import shell from "shelljs";
56
import yargs from "yargs/yargs";
67

78
type CommandLineArgs = Array<string>;
@@ -12,6 +13,7 @@ type Options = {
1213
api?: string;
1314
database?: string;
1415
auth?: boolean;
16+
output?: string;
1517
_?: (string | number)[];
1618
$0?: string;
1719
};
@@ -49,6 +51,12 @@ const OPTIONS = {
4951
description: "Include built-in auth features",
5052
message: "Would you like built-in auth features?",
5153
},
54+
output: {
55+
id: "o",
56+
description: "Output directory",
57+
message:
58+
"Which directory would you like the starter code folder to be in (default is current directory)?",
59+
},
5260
};
5361

5462
const parseArguments = (args: CommandLineArgs) => {
@@ -76,6 +84,11 @@ const parseArguments = (args: CommandLineArgs) => {
7684
type: "boolean",
7785
description: OPTIONS.auth.description,
7886
},
87+
output: {
88+
alias: OPTIONS.output.id,
89+
type: "string",
90+
description: OPTIONS.output.description,
91+
},
7992
});
8093

8194
return argv;
@@ -119,13 +132,23 @@ const promptOptions = async (options: Options) => {
119132
});
120133
}
121134

135+
if (!options.output) {
136+
prompts.push({
137+
type: "output",
138+
name: "output",
139+
message: OPTIONS.output.message,
140+
default: ".",
141+
});
142+
}
143+
122144
const answers = await inquirer.prompt(prompts);
123145

124146
return {
125147
backend: options.backend || answers.backend,
126148
api: options.api || answers.api,
127149
database: options.database || answers.database,
128150
auth: options.auth || answers.auth,
151+
output: options.output || answers.output,
129152
};
130153
};
131154

@@ -173,10 +196,22 @@ const cli = async (args: CommandLineArgs) => {
173196
let options: Options = parseArguments(args);
174197
options = await promptOptions(options);
175198
const confirm = await confirmPrompt(options);
176-
if (confirm) {
177-
console.log(chalk.green.bold("Confirmed. Creating blueprint app..."));
178-
} else {
199+
if (!confirm) {
179200
console.log(chalk.red.bold("Blueprint app creation has been cancelled."));
201+
return;
202+
}
203+
console.log(chalk.green.bold("Confirmed. Creating blueprint app..."));
204+
const path = options.output;
205+
const changeDirectory = shell.cd(path);
206+
if (changeDirectory.code !== 0) {
207+
console.log("No directory exists. Exiting...");
208+
return;
209+
}
210+
const clone = shell.exec(
211+
"git clone https://github.com/uwblueprint/starter-code-v2.git",
212+
);
213+
if (clone.code !== 0) {
214+
console.log("Git clone failed. Exiting...");
180215
}
181216
};
182217

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@types/figlet": "^1.2.1",
1818
"@types/inquirer": "^7.3.1",
1919
"@types/node": "^14.14.31",
20+
"@types/shelljs": "^0.8.8",
2021
"@types/yargs": "^16.0.0",
2122
"@typescript-eslint/eslint-plugin": "^4.15.2",
2223
"@typescript-eslint/parser": "^4.15.2",
@@ -34,6 +35,7 @@
3435
"chalk": "^4.1.0",
3536
"figlet": "^1.5.0",
3637
"inquirer": "^8.0.0",
38+
"shelljs": "^0.8.4",
3739
"yargs": "^16.2.0"
3840
},
3941
"files": ["bin/"]

yarn.lock

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@
6565
resolved "https://registry.yarnpkg.com/@types/figlet/-/figlet-1.2.1.tgz#ae3ba62ae70fc2aa10ac76b42541a99680b080a1"
6666
integrity sha512-uw+Xmam7sMFHYyVGq5CGH/6Lu0T792bf4T6+jPFtPkWnJ9YVjLKqOLzF7DHuSo/LEHtLWleUO7Zi7EKkg6rSIg==
6767

68+
"@types/glob@*":
69+
version "7.1.3"
70+
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.3.tgz#e6ba80f36b7daad2c685acd9266382e68985c183"
71+
integrity sha512-SEYeGAIQIQX8NN6LDKprLjbrd5dARM5EXsd8GI/A5l0apYI1fGMWgPHSe4ZKL4eozlAyI+doUE9XbYS4xCkQ1w==
72+
dependencies:
73+
"@types/minimatch" "*"
74+
"@types/node" "*"
75+
6876
"@types/inquirer@^7.3.1":
6977
version "7.3.1"
7078
resolved "https://registry.yarnpkg.com/@types/inquirer/-/inquirer-7.3.1.tgz#1f231224e7df11ccfaf4cf9acbcc3b935fea292d"
@@ -83,11 +91,24 @@
8391
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"
8492
integrity sha1-7ihweulOEdK4J7y+UnC86n8+ce4=
8593

94+
"@types/minimatch@*":
95+
version "3.0.3"
96+
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"
97+
integrity sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==
98+
8699
"@types/node@*", "@types/node@^14.14.31":
87100
version "14.14.31"
88101
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.31.tgz#72286bd33d137aa0d152d47ec7c1762563d34055"
89102
integrity sha512-vFHy/ezP5qI0rFgJ7aQnjDXwAMrG0KqqIH7tQG5PPv3BWBayOPIQNBjVc/P6hhdZfMx51REc6tfDNXHUio893g==
90103

104+
"@types/shelljs@^0.8.8":
105+
version "0.8.8"
106+
resolved "https://registry.yarnpkg.com/@types/shelljs/-/shelljs-0.8.8.tgz#e439c69929b88a2c8123c1a55e09eb708315addf"
107+
integrity sha512-lD3LWdg6j8r0VRBFahJVaxoW0SIcswxKaFUrmKl33RJVeeoNYQAz4uqCJ5Z6v4oIBOsC5GozX+I5SorIKiTcQA==
108+
dependencies:
109+
"@types/glob" "*"
110+
"@types/node" "*"
111+
91112
"@types/through@*":
92113
version "0.0.30"
93114
resolved "https://registry.yarnpkg.com/@types/through/-/through-0.0.30.tgz#e0e42ce77e897bd6aead6f6ea62aeb135b8a3895"
@@ -881,7 +902,7 @@ glob-parent@^5.0.0, glob-parent@^5.1.0:
881902
dependencies:
882903
is-glob "^4.0.1"
883904

884-
glob@^7.1.3:
905+
glob@^7.0.0, glob@^7.1.3:
885906
version "7.1.6"
886907
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6"
887908
integrity sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==
@@ -1006,6 +1027,11 @@ inquirer@^8.0.0:
10061027
strip-ansi "^6.0.0"
10071028
through "^2.3.6"
10081029

1030+
interpret@^1.0.0:
1031+
version "1.4.0"
1032+
resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.4.0.tgz#665ab8bc4da27a774a40584e812e3e0fa45b1a1e"
1033+
integrity sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==
1034+
10091035
is-arrayish@^0.2.1:
10101036
version "0.2.1"
10111037
resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d"
@@ -1430,6 +1456,13 @@ read-pkg@^2.0.0:
14301456
normalize-package-data "^2.3.2"
14311457
path-type "^2.0.0"
14321458

1459+
rechoir@^0.6.2:
1460+
version "0.6.2"
1461+
resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.6.2.tgz#85204b54dba82d5742e28c96756ef43af50e3384"
1462+
integrity sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q=
1463+
dependencies:
1464+
resolve "^1.1.6"
1465+
14331466
regexpp@^3.0.0, regexpp@^3.1.0:
14341467
version "3.1.0"
14351468
resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-3.1.0.tgz#206d0ad0a5648cffbdb8ae46438f3dc51c9f78e2"
@@ -1450,7 +1483,7 @@ resolve-from@^4.0.0:
14501483
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-4.0.0.tgz#4abcd852ad32dd7baabfe9b40e00a36db5f392e6"
14511484
integrity sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==
14521485

1453-
resolve@^1.10.0, resolve@^1.13.1, resolve@^1.17.0:
1486+
resolve@^1.1.6, resolve@^1.10.0, resolve@^1.13.1, resolve@^1.17.0:
14541487
version "1.20.0"
14551488
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.20.0.tgz#629a013fb3f70755d6f0b7935cc1c2c5378b1975"
14561489
integrity sha512-wENBPt4ySzg4ybFQW2TT1zMQucPK95HSh/nq2CFTZVOGut2+pQvSsgtda4d26YrYcr067wjbmzOG8byDPBX63A==
@@ -1526,6 +1559,15 @@ shebang-regex@^3.0.0:
15261559
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172"
15271560
integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==
15281561

1562+
shelljs@^0.8.4:
1563+
version "0.8.4"
1564+
resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.8.4.tgz#de7684feeb767f8716b326078a8a00875890e3c2"
1565+
integrity sha512-7gk3UZ9kOfPLIAbslLzyWeGiEqx9e3rxwZM0KE6EL8GlGwjym9Mrlx5/p33bWTu9YG6vcS4MBxYZDHYr5lr8BQ==
1566+
dependencies:
1567+
glob "^7.0.0"
1568+
interpret "^1.0.0"
1569+
rechoir "^0.6.2"
1570+
15291571
signal-exit@^3.0.2:
15301572
version "3.0.3"
15311573
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.3.tgz#a1410c2edd8f077b08b4e253c8eacfcaf057461c"

0 commit comments

Comments
 (0)