Skip to content

Commit 31b11f5

Browse files
committed
Update documentation for stack new and stack templates
1 parent d8ae925 commit 31b11f5

File tree

2 files changed

+91
-68
lines changed

2 files changed

+91
-68
lines changed

doc/new_command.md

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ stack new PACKAGE_NAME [--bare] [TEMPLATE_NAME] [-p|--param KEY:VALUE] [DIR(S)]
77
[--omit-packages] [--force] [--ignore-subdirs]
88
~~~
99

10-
`stack new` creates a new Stack project for a package using a template.
10+
`stack new` creates a new Stack project for a package using a project template.
1111

1212
The project is created in a new directory named after the package, unless the
1313
`--bare` flag is passed, in which case the project is created in the current
@@ -21,3 +21,67 @@ in a template. The option can be specified multiple times.
2121

2222
The arguments specifying directories and the `--ignore-subdirs`, `--force` and
2323
`--omit-packages` flags are as for the [`stack init` command](init_command.md).
24+
25+
## Project templates
26+
27+
Project template files can be located in a repository named `stack-templates` on
28+
GitHub, GitLab or Bitbucket; at a URL; or on the local file system.
29+
30+
Project template file names have the extension `.hsfiles`. The extension does
31+
not need to be specified.
32+
33+
A project template file `my-template.hsfiles` in a repository
34+
`username/stack-templates` on GitHub, GitLab or Bitbucket can be specified as:
35+
36+
~~~test
37+
<service>:username/my-template
38+
~~~
39+
40+
where `<service>` is one of `github` for [GitHub](https://github.com/),
41+
`gitlab:` for [GitLab](https://gitlab.com), or `bitbucket:` for
42+
[Bitbucket](https://bitbucket.com).
43+
44+
The default service is GitHub, the default username is `commercialhaskell` and
45+
the default project template name is `new-template`.
46+
47+
## Examples
48+
49+
Create a project with the default project template:
50+
51+
~~~text
52+
stack new my-project
53+
~~~
54+
55+
Create a project with the `rio` project template at the default repository:
56+
57+
~~~text
58+
stack new my-project rio
59+
~~~
60+
61+
Create a project with the `mysql` project template provided by the
62+
`yesodweb/stack-templates` repository on GitHub:
63+
64+
~~~text
65+
stack new my-project yesodweb/mysql
66+
~~~
67+
68+
Create a project with the `my-template` project template provided by the
69+
`username/stack-templates` repository on Bitbucket:
70+
71+
~~~text
72+
stack new my-project bitbucket:username/my-template
73+
~~~
74+
75+
Create a project with the `my-template.hsfiles` project template file at
76+
`https://example.com`:
77+
78+
~~~text
79+
stack new my-project https://example.com/my-template
80+
~~~
81+
82+
Create a project with the local project template file
83+
`<path_to_template>/my-template.hsfiles`:
84+
85+
~~~text
86+
stack new my-project <path_to_template_file>/my-template
87+
~~~

doc/templates_command.md

Lines changed: 26 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -6,70 +6,29 @@
66
stack templates
77
~~~
88

9-
`stack templates` provides information about how to find templates available for
10-
`stack new`.
11-
12-
Stack provides multiple templates to start a new project from. You can specify
13-
one of these templates following your project name in the `stack new` command:
14-
15-
~~~text
16-
stack new my-rio-project rio
17-
Downloading template "rio" to create project "my-rio-project" in my-rio-project/ ...
18-
Looking for .cabal or package.yaml files to use to init the project.
19-
Using cabal packages:
20-
- my-rio-project/
21-
22-
Selecting the best among 18 snapshots...
23-
24-
* Matches ...
25-
26-
Selected resolver: ...
27-
Initialising configuration using resolver: ...
28-
Total number of user packages considered: 1
29-
Writing configuration to file: my-rio-project/stack.yaml
30-
All done.
31-
<Stack root>\templates\rio.hsfiles: 10.10 KiB downloaded...
32-
~~~
33-
34-
The default templates repository is
35-
https://github.com/commercialhaskell/stack-templates. You can download templates
36-
from a different GitHub user by prefixing the username and a slash. Command:
37-
38-
~~~text
39-
stack new my-yesod-project yesodweb/simple
40-
~~~
41-
42-
Then template file `simple.hsfiles` would be downloaded from GitHub repository
43-
`yesodweb/stack-templates`.
44-
45-
You can even download templates from a service other that GitHub, such as
46-
[GitLab](https://gitlab.com) or [Bitbucket](https://bitbucket.com). For example,
47-
command:
48-
49-
~~~text
50-
stack new my-project gitlab:user29/foo
51-
~~~
52-
53-
Template file `foo.hsfiles` would be downloaded from GitLab, user account
54-
`user29`, repository `stack-templates`.
55-
56-
If you need more flexibility, you can specify the full URL of the template.
57-
Command:
58-
59-
~~~text
60-
stack new my-project https://my-site.com/content/template9.hsfiles
61-
~~~
62-
63-
(The `.hsfiles` extension is optional; it will be added if it's not specified.)
64-
65-
Alternatively you can use a local template by specifying the path. Command:
66-
67-
~~~text
68-
stack new project <path_to_template>/template.hsfiles
69-
~~~
70-
71-
As a starting point for creating your own templates, you can use the
72-
["simple" template](https://github.com/commercialhaskell/stack-templates/blob/master/simple.hsfiles).
73-
The
74-
[stack-templates repository](https://github.com/commercialhaskell/stack-templates#readme)
75-
provides an introduction into creating templates.
9+
`stack templates` provides information about project templates used with the
10+
[`stack new` command](new_command.md).
11+
12+
Project templates are specified in `.hsfiles` files. The format of those files
13+
is documented at the
14+
[`commercialhaskell/stack-templates`](https://github.com/commercialhaskell/stack-templates#project-template-format)
15+
repository on GitHub.
16+
17+
Any GitHub, GitLab or Bitbucket repository named `stack-templates` can provide
18+
project template files. For example, a template file
19+
`username/stack-templates/my-template.hsfiles` on GitHub can be identified as
20+
`username/my-template` when using `stack new`. The relevant service can be
21+
specified by a prefix: `github:` for [GitHub](https://github.com/) (the default
22+
service), `gitlab:` for [GitLab](https://gitlab.com), or `bitbucket:` for
23+
[Bitbucket](https://bitbucket.com).
24+
25+
[`commercialhaskell/stack-templates`](https://github.com/commercialhaskell/stack-templates#project-template-format)
26+
on GitHub is the default repository for project templates. Its username
27+
(`commercialhaskell`) does not need to be specified when using `stack new`.
28+
29+
The project template that `stack new` uses by default is named `new-template`
30+
and provided at the default repository.
31+
32+
The default repository provides 24 other project templates. Its Wiki provides
33+
a description of some of those templates and information about the location of
34+
other templates.

0 commit comments

Comments
 (0)