@@ -3,11 +3,15 @@ module Terminal.Init exposing
3
3
, run
4
4
)
5
5
6
+ import Basics.Extra exposing (flip )
7
+ import Builder.Deps.Registry as Registry
6
8
import Builder.Deps.Solver as Solver
7
9
import Builder.Elm.Outline as Outline
10
+ import Builder.File as File
8
11
import Builder.Reporting as Reporting
9
12
import Builder.Reporting.Exit as Exit
10
13
import Builder.Reporting.Exit.Help as Help
14
+ import Builder.Stuff as Stuff
11
15
import Compiler.Data.NonEmptyList as NE
12
16
import Compiler.Elm.Constraint as Con
13
17
import Compiler.Elm.Licenses as Licenses
@@ -111,78 +115,115 @@ init package =
111
115
IO . pure ( Err ( Exit . InitRegistryProblem problem))
112
116
113
117
Ok ( Solver . Env cache _ connection registry) ->
114
- Solver . verify cache connection registry defaults
115
- |> IO . bind
116
- ( \ result ->
117
- case result of
118
- Solver . SolverErr exit ->
119
- IO . pure ( Err ( Exit . InitSolverProblem exit))
120
-
121
- Solver . NoSolution ->
122
- IO . pure ( Err ( Exit . InitNoSolution ( Dict . keys compare defaults)))
123
-
124
- Solver . NoOfflineSolution ->
125
- IO . pure ( Err ( Exit . InitNoOfflineSolution ( Dict . keys compare defaults)))
126
-
127
- Solver . SolverOk details ->
128
- Utils . dirCreateDirectoryIfMissing True " src"
129
- |> IO . bind
130
- ( \ _ ->
131
- let
132
- outline : Outline . Outline
133
- outline =
134
- if package then
135
- let
136
- directs : Dict ( String , String ) Pkg . Name Con . Constraint
137
- directs =
138
- Dict . map
139
- ( \ pkg _ ->
140
- let
141
- ( Solver . Details vsn _) =
142
- Utils . find identity pkg details
143
- in
144
- Con . untilNextMajor vsn
145
- )
146
- packageDefaults
147
- in
148
- Outline . Pkg <|
149
- Outline . PkgOutline
150
- Pkg . dummyName
151
- Outline . defaultSummary
152
- Licenses . bsd3
153
- V . one
154
- ( Outline . ExposedList [] )
155
- directs
156
- Dict . empty
157
- Con . defaultElm
158
-
159
- else
160
- let
161
- solution : Dict ( String , String ) Pkg . Name V . Version
162
- solution =
163
- Dict . map ( \ _ ( Solver . Details vsn _) -> vsn) details
164
-
165
- directs : Dict ( String , String ) Pkg . Name V . Version
166
- directs =
167
- Dict . intersection compare solution defaults
168
-
169
- indirects : Dict ( String , String ) Pkg . Name V . Version
170
- indirects =
171
- Dict . diff solution defaults
172
- in
173
- Outline . App <|
174
- Outline . AppOutline V . elmCompiler
175
- ( NE . Nonempty ( Outline . RelativeSrcDir " src" ) [] )
176
- directs
177
- indirects
178
- Dict . empty
179
- Dict . empty
180
- in
181
- Outline . write " ." outline
182
- )
183
- |> IO . bind ( \ _ -> IO . putStrLn " Okay, I created it. Now read that link!" )
184
- |> IO . fmap ( \ _ -> Ok () )
185
- )
118
+ verify cache connection registry defaults <|
119
+ \ details ->
120
+ verify cache connection registry testDefaults <|
121
+ \ testDetails ->
122
+ Utils . dirCreateDirectoryIfMissing True " src"
123
+ |> IO . bind ( \ _ -> Utils . dirCreateDirectoryIfMissing True " tests" )
124
+ |> IO . bind ( \ _ -> File . writeUtf8 " tests/Example.elm" testExample)
125
+ |> IO . bind
126
+ ( \ _ ->
127
+ let
128
+ outline : Outline . Outline
129
+ outline =
130
+ if package then
131
+ let
132
+ directs : Dict ( String , String ) Pkg . Name Con . Constraint
133
+ directs =
134
+ Dict . map
135
+ ( \ pkg _ ->
136
+ let
137
+ ( Solver . Details vsn _) =
138
+ Utils . find identity pkg details
139
+ in
140
+ Con . untilNextMajor vsn
141
+ )
142
+ packageDefaults
143
+
144
+ testDirects : Dict ( String , String ) Pkg . Name Con . Constraint
145
+ testDirects =
146
+ Dict . map
147
+ ( \ pkg _ ->
148
+ let
149
+ ( Solver . Details vsn _) =
150
+ Utils . find identity pkg testDetails
151
+ in
152
+ Con . untilNextMajor vsn
153
+ )
154
+ packageTestDefaults
155
+ in
156
+ Outline . Pkg <|
157
+ Outline . PkgOutline
158
+ Pkg . dummyName
159
+ Outline . defaultSummary
160
+ Licenses . bsd3
161
+ V . one
162
+ ( Outline . ExposedList [] )
163
+ directs
164
+ testDirects
165
+ Con . defaultElm
166
+
167
+ else
168
+ let
169
+ solution : Dict ( String , String ) Pkg . Name V . Version
170
+ solution =
171
+ Dict . map ( \ _ ( Solver . Details vsn _) -> vsn) details
172
+
173
+ directs : Dict ( String , String ) Pkg . Name V . Version
174
+ directs =
175
+ Dict . intersection compare solution defaults
176
+
177
+ indirects : Dict ( String , String ) Pkg . Name V . Version
178
+ indirects =
179
+ Dict . diff solution defaults
180
+
181
+ testSolution : Dict ( String , String ) Pkg . Name V . Version
182
+ testSolution =
183
+ Dict . map ( \ _ ( Solver . Details vsn _) -> vsn) testDetails
184
+
185
+ testDirects : Dict ( String , String ) Pkg . Name V . Version
186
+ testDirects =
187
+ Dict . intersection compare testSolution testDefaults
188
+
189
+ testIndirects : Dict ( String , String ) Pkg . Name V . Version
190
+ testIndirects =
191
+ Dict . diff testSolution testDefaults
192
+ |> flip Dict . diff directs
193
+ |> flip Dict . diff indirects
194
+ in
195
+ Outline . App <|
196
+ Outline . AppOutline V . elmCompiler
197
+ ( NE . Nonempty ( Outline . RelativeSrcDir " src" ) [] )
198
+ directs
199
+ indirects
200
+ testDirects
201
+ testIndirects
202
+ in
203
+ Outline . write " ." outline
204
+ )
205
+ |> IO . bind ( \ _ -> IO . putStrLn " Okay, I created it. Now read that link!" )
206
+ |> IO . fmap ( \ _ -> Ok () )
207
+ )
208
+
209
+
210
+ verify : Stuff .PackageCache -> Solver .Connection -> Registry .Registry -> Dict ( String , String ) Pkg .Name Con .Constraint -> (Dict ( String , String ) Pkg .Name Solver .Details -> IO (Result Exit .Init () )) -> IO (Result Exit .Init () )
211
+ verify cache connection registry constraints callback =
212
+ Solver . verify cache connection registry constraints
213
+ |> IO . bind
214
+ ( \ result ->
215
+ case result of
216
+ Solver . SolverErr exit ->
217
+ IO . pure ( Err ( Exit . InitSolverProblem exit))
218
+
219
+ Solver . NoSolution ->
220
+ IO . pure ( Err ( Exit . InitNoSolution ( Dict . keys compare constraints)))
221
+
222
+ Solver . NoOfflineSolution ->
223
+ IO . pure ( Err ( Exit . InitNoOfflineSolution ( Dict . keys compare constraints)))
224
+
225
+ Solver . SolverOk details ->
226
+ callback details
186
227
)
187
228
188
229
@@ -195,8 +236,37 @@ defaults =
195
236
]
196
237
197
238
239
+ testDefaults : Dict ( String , String ) Pkg .Name Con .Constraint
240
+ testDefaults =
241
+ Dict . fromList identity
242
+ [ ( Pkg . test, Con . anything )
243
+ ]
244
+
245
+
198
246
packageDefaults : Dict ( String , String ) Pkg .Name Con .Constraint
199
247
packageDefaults =
200
248
Dict . fromList identity
201
249
[ ( Pkg . core, Con . anything )
202
250
]
251
+
252
+
253
+ packageTestDefaults : Dict ( String , String ) Pkg .Name Con .Constraint
254
+ packageTestDefaults =
255
+ Dict . fromList identity
256
+ [ ( Pkg . test, Con . anything )
257
+ ]
258
+
259
+
260
+ testExample : String
261
+ testExample =
262
+ """ module Example exposing (..)
263
+
264
+ import Expect exposing (Expectation)
265
+ import Fuzz exposing (Fuzzer, int, list, string)
266
+ import Test exposing (..)
267
+
268
+
269
+ suite : Test
270
+ suite =
271
+ todo "Implement our first test. See https://package.elm-lang.org/packages/elm-explorations/test/latest for how to do this!"
272
+ """
0 commit comments