UNPKG

3.01 kBMarkdownView Raw
1# The Ampersand CLI
2
3<!-- starthide -->
4Part of the [Ampersand.js toolkit](http://ampersandjs.com) for building clientside applications.
5<!-- endhide -->
6
7The idea behind the CLI is not to solve all your problems and write all your code but to help you with the tedious parts of building an app, that you know, computers are supposed to help us with.
8
9## installation
10
11```
12npm install -g ampersand
13```
14
15## Starting a new app
16
17Just, `cd` into whatever directory you normally put your projects in and just run `ampersand`.
18
19The CLI will walk you through some basic questions and kick out an app, that runs, out of the box.
20
21It's meant as a loose guide, not an edict. Just delete whatever isn't relevant.
22
23
24## Generating stuff
25
26```
27ampersand gen {{type}}
28```
29
30Type can be `form`, `view`, `model` or `collection`.
31
32
33## Generating models (from JSON)
34
35You can use the CLI to generate a model and collection for that model. If you already know what the JSON is going to look like you can pipe it into the generator to create a model with matching properties.
36
37On a mac, if you've copied some JSON to your clipboard you can do this from anywhere within your project folder:
38
39```
40pbpaste | ampersand gen model MyModel
41```
42
43And it'll kick out two files in your models folder (which is configurable, see below):
44
45```
46my-model.js
47my-model-collection.js
48```
49
50And it will create the properties in the JSON object as model propeties.
51
52Don't worry it won't overwrite anything unless you use the the `-f` option.
53
54
55## Generating forms from models
56
57You can also use a model to generate the starting point of a form-view for editing that model.
58
59```
60ampersand gen form ./path/to/your/model.js
61```
62
63It will create a form view in your `/client/forms` folder.
64
65
66Don't worry it won't overwrite anything unless you use the the `-f` option so it's safe to just experiment with.
67
68
69## Configuring the generated code
70
71The cli looks for config options from a number of sources, starting with default, applying configs from a `.ampersandrc` in your home folder, then your project root, then by parsing option flags from stdin.
72
73Those files can be JSON or ini format.
74
75The available options and defaults are as follows:
76
77```js
78{
79 framework: 'hapi',
80 indent: 4,
81 view: '', // default template
82 router: '', // default template
83 model: '', // default template
84 page: '', // default template
85 collection: '', // default template
86 clientfolder: 'client',
87 viewfolder: 'views',
88 pagefolder: 'pages',
89 modelfolder: 'models',
90 formsfolder: 'forms',
91 collectionfolder: 'models',
92 // whether to create collection when making a model
93 makecollection: true,
94 // if it was called without the 'gen' argument we're building a new one
95 // so we won't look for an application root
96 approot: '', // starts walking up folders looking for package.json
97 f: false, // overwrite
98 force: false, // overwrite flag, longform
99 quotes: 'single' // can be 'single' or 'double'
100};
101```
102
103## license
104
105MIT