Skip to content

Commit 10d6714

Browse files
committed
Split StarterTemplates to AvailableTemplates
1 parent a44e1a6 commit 10d6714

File tree

9 files changed

+166
-163
lines changed

9 files changed

+166
-163
lines changed

waspc/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ Do the non-bold steps when necessary (decide for each step depending on the chan
433433
- Update Open Saas:
434434
- Check and merge all Open Saas PRs with the label `merge-before-release`.
435435
- Create and merge new PRs if necessary (i.e., if there are breaking changes or new features it should make use of but aren't in one of the `merge-before-release` PRs).
436-
- Update [the template tag in StarterTemplates.hs](https://github.com/wasp-lang/wasp/blob/a963125327c3ef5270207e685d0c3a426c9e3553/waspc/cli/src/Wasp/Cli/Command/CreateNewProject/StarterTemplates.hs#L189). It will point to a non-existing version of OpenSaas for now. That's ok, we'll handle that later.
436+
- Update [the template tag in `AvailableTemplates.hs`](https://github.com/wasp-lang/wasp/blob/main/waspc/cli/src/Wasp/Cli/Command/CreateNewProject/AvailableTemplates.hs). It will point to a non-existing version of OpenSaas for now. That's ok, we'll handle that later.
437437
- 👉 The version in `waspc.cabal` should already be correct, but double check and update it if needed.
438438
- If you modify `waspc.cabal`: create a PR, wait for approval and all the checks (CI) to pass. Then squash and merge the PR into main.
439439
- 👉 Ensure that you have merged any changes from the `release` branch into `main`. You can see the latest PR at https://github.com/wasp-lang/wasp/pull/release.

waspc/cli/exe/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import Wasp.Cli.Command.Clean (clean)
1919
import Wasp.Cli.Command.Compile (compile)
2020
import Wasp.Cli.Command.CreateNewProject (createNewProject)
2121
import qualified Wasp.Cli.Command.CreateNewProject.AI as Command.CreateNewProject.AI
22-
import Wasp.Cli.Command.CreateNewProject.StarterTemplates (availableStarterTemplates)
22+
import Wasp.Cli.Command.CreateNewProject.AvailableTemplates (availableStarterTemplates)
2323
import Wasp.Cli.Command.Db (runCommandThatRequiresDbRunning)
2424
import qualified Wasp.Cli.Command.Db.Migrate as Command.Db.Migrate
2525
import qualified Wasp.Cli.Command.Db.Reset as Command.Db.Reset

waspc/cli/src/Wasp/Cli/Command/CreateNewProject.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Wasp.Cli.Command (Command)
1010
import Wasp.Cli.Command.Call (Arguments)
1111
import qualified Wasp.Cli.Command.CreateNewProject.AI as AI
1212
import Wasp.Cli.Command.CreateNewProject.ArgumentsParser (newProjectArgsParser)
13+
import Wasp.Cli.Command.CreateNewProject.AvailableTemplates (availableStarterTemplates)
1314
import qualified Wasp.Cli.Command.CreateNewProject.Common as Common
1415
import Wasp.Cli.Command.CreateNewProject.ProjectDescription
1516
( NewProjectDescription (..),
@@ -18,7 +19,6 @@ import Wasp.Cli.Command.CreateNewProject.ProjectDescription
1819
import Wasp.Cli.Command.CreateNewProject.StarterTemplates
1920
( DirBasedTemplateMetadata (_path),
2021
StarterTemplate (..),
21-
availableStarterTemplates,
2222
getTemplateStartingInstructions,
2323
)
2424
import Wasp.Cli.Command.CreateNewProject.StarterTemplates.Bundled (createProjectOnDiskFromBundledTemplate)
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
{-# LANGUAGE TupleSections #-}
2+
3+
module Wasp.Cli.Command.CreateNewProject.AvailableTemplates
4+
( availableStarterTemplates,
5+
defaultStarterTemplate,
6+
)
7+
where
8+
9+
import StrongPath (reldir)
10+
import qualified System.FilePath as FP
11+
import Wasp.Cli.Command.CreateNewProject.StarterTemplates (DirBasedTemplateMetadata (..), StarterTemplate (..))
12+
import qualified Wasp.Cli.GithubRepo as GhRepo
13+
import Wasp.Util.Terminal (styleCode, styleText)
14+
15+
availableStarterTemplates :: [StarterTemplate]
16+
availableStarterTemplates =
17+
[ basicStarterTemplate,
18+
minimalStarterTemplate,
19+
openSaasStarterTemplate,
20+
AiGeneratedStarterTemplate
21+
]
22+
23+
defaultStarterTemplate :: StarterTemplate
24+
defaultStarterTemplate = basicStarterTemplate
25+
26+
{- HLINT ignore minimalStarterTemplate "Redundant $" -}
27+
28+
minimalStarterTemplate :: StarterTemplate
29+
minimalStarterTemplate =
30+
BundledStarterTemplate $
31+
DirBasedTemplateMetadata
32+
{ _path = [reldir|minimal|],
33+
_name = "minimal",
34+
_description = "A minimal starter template that features just a single page.",
35+
_buildStartingInstructions = \projectDirName ->
36+
unlines
37+
[ styleText $ "To run your new app, do:",
38+
styleCode $ " cd " <> projectDirName,
39+
styleCode $ " wasp start"
40+
]
41+
}
42+
43+
{- HLINT ignore basicStarterTemplate "Redundant $" -}
44+
45+
basicStarterTemplate :: StarterTemplate
46+
basicStarterTemplate =
47+
BundledStarterTemplate $
48+
DirBasedTemplateMetadata
49+
{ _path = [reldir|basic|],
50+
_name = "basic",
51+
_description = "A basic starter template designed to help you get up and running quickly. It features examples covering the most common use cases.",
52+
_buildStartingInstructions = \projectDirName ->
53+
unlines
54+
[ styleText $ "To run your new app, do:",
55+
styleCode $ " cd " <> projectDirName,
56+
styleCode $ " wasp db migrate-dev",
57+
styleCode $ " wasp start",
58+
styleText $ "",
59+
styleText $ "Check the " <> styleCode "README.md" <> " for additional guidance!"
60+
]
61+
}
62+
63+
{- HLINT ignore openSaasStarterTemplate "Redundant $" -}
64+
65+
openSaasStarterTemplate :: StarterTemplate
66+
openSaasStarterTemplate =
67+
GhRepoReleaseArchiveTemplate
68+
( GhRepo.GithubRepoRef
69+
{ GhRepo._repoOwner = "wasp-lang",
70+
GhRepo._repoName = "open-saas",
71+
GhRepo._repoReferenceName = waspVersionTemplateGitTag
72+
}
73+
)
74+
"template.tar.gz"
75+
( DirBasedTemplateMetadata
76+
{ _name = "saas",
77+
_description =
78+
"Everything a SaaS needs! Comes with Auth, ChatGPT API, Tailwind, Stripe payments and more."
79+
<> " Check out https://opensaas.sh/ for more details.",
80+
-- We assume that the archive contains files at its root.
81+
_path = [reldir|.|],
82+
_buildStartingInstructions = \projectDirName ->
83+
unlines
84+
[ styleText $ "To run your new app, follow the instructions below:",
85+
styleText $ "",
86+
styleText $ " 1. Position into app's root directory:",
87+
styleCode $ " cd " <> projectDirName FP.</> "app",
88+
styleText $ "",
89+
styleText $ " 2. Run the development database (and leave it running):",
90+
styleCode $ " wasp db start",
91+
styleText $ "",
92+
styleText $ " 3. Open new terminal window (or tab) in that same dir and continue in it.",
93+
styleText $ "",
94+
styleText $ " 4. Apply initial database migrations:",
95+
styleCode $ " wasp db migrate-dev",
96+
styleText $ "",
97+
styleText $ " 5. Create initial dot env file from the template:",
98+
styleCode $ " cp .env.server.example .env.server",
99+
styleText $ "",
100+
styleText $ " 6. Last step: run the app!",
101+
styleCode $ " wasp start",
102+
styleText $ "",
103+
styleText $ "Check the README for additional guidance and the link to docs!"
104+
]
105+
}
106+
)
107+
108+
-- NOTE: As version of Wasp CLI changes, so we should update this tag name here,
109+
-- and also create it on gh repos of templates.
110+
-- By tagging templates for each version of Wasp CLI, we ensure that each release of
111+
-- Wasp CLI uses correct version of templates, that work with it.
112+
waspVersionTemplateGitTag :: String
113+
waspVersionTemplateGitTag = "wasp-v0.19-template"

waspc/cli/src/Wasp/Cli/Command/CreateNewProject/ProjectDescription.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import Wasp.Cli.Command (Command)
2020
import Wasp.Cli.Command.CreateNewProject.ArgumentsParser
2121
( NewProjectArgs (..),
2222
)
23+
import Wasp.Cli.Command.CreateNewProject.AvailableTemplates (defaultStarterTemplate)
2324
import Wasp.Cli.Command.CreateNewProject.Common (throwProjectCreationError)
2425
import Wasp.Cli.Command.CreateNewProject.StarterTemplates
2526
( StarterTemplate,
26-
defaultStarterTemplate,
2727
findTemplateByString,
2828
)
2929
import Wasp.Cli.FileSystem (getAbsPathToDirInCwd)

waspc/cli/src/Wasp/Cli/Command/CreateNewProject/StarterTemplates.hs

Lines changed: 2 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
{-# LANGUAGE TupleSections #-}
22

33
module Wasp.Cli.Command.CreateNewProject.StarterTemplates
4-
( availableStarterTemplates,
5-
StarterTemplate (..),
4+
( StarterTemplate (..),
65
DirBasedTemplateMetadata (..),
76
findTemplateByString,
8-
defaultStarterTemplate,
97
readWaspProjectSkeletonFiles,
108
getTemplateStartingInstructions,
119
)
@@ -15,13 +13,12 @@ import Data.Foldable (find)
1513
import Data.Text (Text)
1614
import StrongPath (Dir', File', Path, Path', Rel, Rel', System, reldir, (</>))
1715
import qualified StrongPath as SP
18-
import qualified System.FilePath as FP
1916
import qualified Wasp.Cli.GithubRepo as GhRepo
2017
import qualified Wasp.Cli.Interactive as Interactive
2118
import qualified Wasp.Data as Data
2219
import Wasp.Project.Common (WaspProjectDir)
2320
import Wasp.Util.IO (listDirectoryDeep, readFileStrict)
24-
import Wasp.Util.Terminal (styleCode)
21+
import Wasp.Util.Terminal (styleCode, styleText)
2522

2623
-- More on how starter templates work in Wasp, including the development process,
2724
-- can be found in the `waspc/data/Cli/starters/README.md` file.
@@ -73,121 +70,6 @@ getTemplateStartingInstructions projectDirName = \case
7370
styleCode $ " wasp start"
7471
]
7572

76-
availableStarterTemplates :: [StarterTemplate]
77-
availableStarterTemplates =
78-
[ basicStarterTemplate,
79-
minimalStarterTemplate,
80-
openSaasStarterTemplate,
81-
AiGeneratedStarterTemplate
82-
]
83-
84-
defaultStarterTemplate :: StarterTemplate
85-
defaultStarterTemplate = basicStarterTemplate
86-
87-
{- HLINT ignore minimalStarterTemplate "Redundant $" -}
88-
89-
minimalStarterTemplate :: StarterTemplate
90-
minimalStarterTemplate =
91-
BundledStarterTemplate $
92-
DirBasedTemplateMetadata
93-
{ _path = [reldir|minimal|],
94-
_name = "minimal",
95-
_description = "A minimal starter template that features just a single page.",
96-
_buildStartingInstructions = \projectDirName ->
97-
unlines
98-
[ styleText $ "To run your new app, do:",
99-
styleCode $ " cd " <> projectDirName,
100-
styleCode $ " wasp start"
101-
]
102-
}
103-
104-
{- HLINT ignore basicStarterTemplate "Redundant $" -}
105-
106-
basicStarterTemplate :: StarterTemplate
107-
basicStarterTemplate =
108-
BundledStarterTemplate $
109-
DirBasedTemplateMetadata
110-
{ _path = [reldir|basic|],
111-
_name = "basic",
112-
_description = "A basic starter template designed to help you get up and running quickly. It features examples covering the most common use cases.",
113-
_buildStartingInstructions = \projectDirName ->
114-
unlines
115-
[ styleText $ "To run your new app, do:",
116-
styleCode $ " cd " <> projectDirName,
117-
styleCode $ " wasp db migrate-dev",
118-
styleCode $ " wasp start",
119-
styleText $ "",
120-
styleText $ "Check the " <> styleCode "README.md" <> " for additional guidance!"
121-
]
122-
}
123-
124-
{- HLINT ignore openSaasStarterTemplate "Redundant $" -}
125-
126-
openSaasStarterTemplate :: StarterTemplate
127-
openSaasStarterTemplate =
128-
simpleGhReleaseArchiveTemplate
129-
("open-saas", "template.tar.gz")
130-
( "saas",
131-
"Everything a SaaS needs! Comes with Auth, ChatGPT API, Tailwind, Stripe payments and more."
132-
<> " Check out https://opensaas.sh/ for more details."
133-
)
134-
( \projectDirName ->
135-
unlines
136-
[ styleText $ "To run your new app, follow the instructions below:",
137-
styleText $ "",
138-
styleText $ " 1. Position into app's root directory:",
139-
styleCode $ " cd " <> projectDirName FP.</> "app",
140-
styleText $ "",
141-
styleText $ " 2. Run the development database (and leave it running):",
142-
styleCode $ " wasp db start",
143-
styleText $ "",
144-
styleText $ " 3. Open new terminal window (or tab) in that same dir and continue in it.",
145-
styleText $ "",
146-
styleText $ " 4. Apply initial database migrations:",
147-
styleCode $ " wasp db migrate-dev",
148-
styleText $ "",
149-
styleText $ " 5. Create initial dot env file from the template:",
150-
styleCode $ " cp .env.server.example .env.server",
151-
styleText $ "",
152-
styleText $ " 6. Last step: run the app!",
153-
styleCode $ " wasp start",
154-
styleText $ "",
155-
styleText $ "Check the README for additional guidance and the link to docs!"
156-
]
157-
)
158-
159-
styleText :: String -> String
160-
styleText = id
161-
162-
simpleGhReleaseArchiveTemplate :: (String, GhRepo.GithubReleaseArchiveName) -> (String, String) -> StartingInstructionsBuilder -> StarterTemplate
163-
simpleGhReleaseArchiveTemplate (repoName, assetName) (tmplDisplayName, tmplDescription) buildStartingInstructions =
164-
GhRepoReleaseArchiveTemplate
165-
( GhRepo.GithubRepoRef
166-
{ GhRepo._repoOwner = waspGhOrgName,
167-
GhRepo._repoName = repoName,
168-
GhRepo._repoReferenceName = waspVersionTemplateGitTag
169-
}
170-
)
171-
assetName
172-
( DirBasedTemplateMetadata
173-
{ _name = tmplDisplayName,
174-
_description = tmplDescription,
175-
-- We assume that the archive contains files at its root.
176-
_path = [reldir|.|],
177-
_buildStartingInstructions = buildStartingInstructions
178-
}
179-
)
180-
181-
waspGhOrgName :: String
182-
waspGhOrgName = "wasp-lang"
183-
184-
-- NOTE: As version of Wasp CLI changes, so we should update this tag name here,
185-
-- and also create it on gh repos of templates.
186-
-- By tagging templates for each version of Wasp CLI, we ensure that each release of
187-
-- Wasp CLI uses correct version of templates, that work with it.
188-
waspVersionTemplateGitTag :: String
189-
waspVersionTemplateGitTag = "wasp-v0.19-template"
190-
19173
findTemplateByString :: [StarterTemplate] -> String -> Maybe StarterTemplate
19274
findTemplateByString templates query = find ((== query) . show) templates
19375

waspc/src/Wasp/Util/Terminal.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module Wasp.Util.Terminal
55
getAnsiCodeFor,
66
ansiEscapeCode,
77
ansiResetCode,
8+
styleText,
89
)
910
where
1011

@@ -14,6 +15,12 @@ import Data.List (foldl')
1415
styleCode :: String -> String
1516
styleCode = applyStyles [Bold]
1617

18+
-- | Applies the Wasp CLI standardized text styling to a string. Currently, this
19+
-- is a no-op, but it exists for future-proofing. And to make consecutive calls
20+
-- to styleCode and styleText look similar.
21+
styleText :: String -> String
22+
styleText = id
23+
1724
data Style
1825
= Black
1926
| Red

0 commit comments

Comments
 (0)