Skip to content

Commit 79a14f4

Browse files
Merge pull request #1011 from ProvableHQ/command-line-templating
Create Leo App - specify template via command line
2 parents 9b097c2 + 0adec1b commit 79a14f4

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

.circleci/config.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ jobs:
9393
command: |
9494
yarn start
9595
96+
create-leo-app-cli:
97+
executor: rust-node
98+
steps:
99+
- setup
100+
- run:
101+
working_directory: create-leo-app
102+
command: |
103+
npm i -D tsx
104+
npx tsx src/index.ts test-app --template react-leo
96105
97106
template-node:
98107
executor: rust-node
@@ -172,6 +181,9 @@ workflows:
172181
- e2e-mainnet:
173182
requires:
174183
- sdk
184+
- create-leo-app-cli:
185+
requires:
186+
- sdk
175187
- template-node:
176188
requires:
177189
- sdk

create-leo-app/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ npm create leo-app@latest
1313

1414
Then follow the prompts!
1515

16-
You can also directly specify the project name you want to use via additional command line options. For example, to scaffold a Leo project, run:
16+
You can also directly specify the project name and template you want to use via additional command line options. For example, to scaffold a Leo project using the Vanilla JavaScript template, run:
1717

1818
```bash
1919
# npm 6.x
20-
npm create leo-app@latest my-leo-app
20+
npm create leo-app@latest my-leo-app --template vanilla
2121

2222
# npm 7+, extra double-dash is needed:
23-
npm create leo-app@latest my-leo-app
23+
npm create leo-app@latest my-leo-app -- --template vanilla
2424
```
2525

2626
Currently supported template presets include:

create-leo-app/src/index.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,20 @@ async function init() {
9292
const getProjectName = () =>
9393
targetDir === "." ? path.basename(path.resolve()) : targetDir;
9494

95+
let selectedFramework: Framework | undefined;
96+
let selectedVariant: string | undefined;
97+
98+
if (argTemplate && TEMPLATES.includes(argTemplate)) {
99+
for (const framework of FRAMEWORKS) {
100+
const match = framework.variants.find((v) => v.name === argTemplate);
101+
if (match) {
102+
selectedFramework = framework;
103+
selectedVariant = match.name;
104+
break;
105+
}
106+
}
107+
}
108+
95109
let result: prompts.Answers<
96110
"projectName" | "overwrite" | "packageName" | "framework" | "variant"
97111
>;
@@ -136,8 +150,7 @@ async function init() {
136150
isValidPackageName(dir) || "Invalid package.json name",
137151
},
138152
{
139-
type:
140-
argTemplate && TEMPLATES.includes(argTemplate) ? null : "select",
153+
type: selectedFramework ? null : "select",
141154
name: "framework",
142155
message:
143156
typeof argTemplate === "string" && !TEMPLATES.includes(argTemplate)
@@ -155,8 +168,7 @@ async function init() {
155168
}),
156169
},
157170
{
158-
type: (framework: Framework) =>
159-
framework && framework.variants ? "select" : null,
171+
type: selectedVariant ? null : "select",
160172
name: "variant",
161173
message: reset("Select a variant:"),
162174
choices: (framework: Framework) =>

0 commit comments

Comments
 (0)