UNPKG

10.4 kBMarkdownView Raw
1## Overview
2
3[pos-cli](https://github.com/mdyd-dev/pos-cli) is a command line tool developed to allow you to easily deploy your configuration files and assets to platformOS. It expects you to follow a certain file structure to correctly communicate with the platformOS API. You do not have to use it, however, it is highly recommended that you do. It is a CLI tool, hence you are expected to have basic knowledge in working with a command line interface like Terminal.
4
5If you have any feature requests, feedback, or problems, please head over to the [issues page](https://github.com/mdyd-dev/pos-cli/issues) and let us know.
6
7Run all commands in the project root directory - one level above the `app` or `modules` directory.
8
9### Requirements
10
11`pos-cli` requires nodejs >= v10 to work properly. [Read more on how to install node on your platform](https://nodejs.org/en/download/).
12
13## Installation and update
14
15If your node is installed for all users you might need to use `sudo` to install npm packages globally:
16
17 sudo npm install -g @platformos/pos-cli
18
19If you are using nvm or have node installed on your account, you can omit that:
20
21 npm install -g @platformos/pos-cli
22
23## Usage
24
25### Adding environments and authenticating
26
27For authentication, you'll need your **Partner Portal** account credentials.
28See this [guide](https://documentation.platformos.com/get-started/partner-portal/inviting-new-user-to-partner-portal) if you don't have a Partner Portal account yet.
29
30To add your environment to a config file, run the `env add` command, and authenticate with your **Partner Portal** credentials:
31
32```
33pos-cli env add [environment] --email [your email] --url [your application url]
34```
35
36Example: `pos-cli env add staging --email myemail@example.com --url https://example.com`
37
38Configuration for environments is in the `.pos` file.
39
40### Syncing changes
41
42```
43pos-cli sync [environment]
44```
45
46Example: `pos-cli sync staging`
47
48Enables sync mode - immediately pushes changes made to the file system to the proper environment. It feels like working on localhost. Because changes are immediate, it is dangerous to use sync on production, on a live application - it is recommended to use it only for staging.
49
50#### Livereloading changes
51
52Add `--livereload` (`-l`) to your sync command to run the [LiveReload](http://livereload.com) server in the background.
53You need to install the LiveReload browser extension for it to refresh your browser on file changes.
54
55```
56pos-cli sync [environment] -l
57```
58
59#### Automatically opening the browser
60
61If you add `--open` (`-o`) to the sync command, it will open your Instance in the default browser.
62
63```
64pos-cli sync [environment] -o
65```
66
67#### Concurrency
68
69By default, the `sync` command uses 3 concurrent connections to our server when syncing resources and assets. You can adjust it for your connection.
70
71```
72pos-cli sync [environment] -c 10
73```
74
75### Deploying changes
76
77```
78pos-cli deploy [environment]
79```
80
81Example: `pos-cli deploy staging`
82
83Deploys all changes. It is recommended to first deploy to `staging`, test, and only then trigger a deploy to production. Effectively, deploy creates a zip file containing all your files and sends it to the API. It is then processed in the background. We store each zip file to allow you to roll back in case something goes wrong.
84
85To skip the audit during deploy, set the environmental variable `CI` to `true`.
86
87### Code audit
88
89```
90pos-cli audit
91```
92
93Example: `pos-cli audit`
94
95Runs statical analysis on files in your current application directory.
96
97### Reading logs
98
99Access errors and logs that you or the system logs for you using the `logs` command. Read more on [how to create logs](https://documentation.platformos.com/api-reference/liquid/platformos-tags#log).
100
101```
102pos-cli logs [environment]
103```
104
105From now on, as long as your `logs` command is running, logs will appear here. Errors will trigger system notifications if your operating system supports them.
106
107You can filter logs by type using the `--filter` argument.
108
109```
110pos-cli logs [environment] --filter type
111```
112
113Example:
114
115```
116pos-cli logs staging --filter debug
117```
118
119### Listing environments
120
121If you forgot what your environments are called or the URL that corresponds to any name, use:
122
123```
124pos-cli env list
125```
126
127### Initializing the directory structure
128
129If you need to create a new project from scratch you can initialize the directory structure using:
130
131```
132pos-cli init --url mdyd-dev/directory-structure --branch master
133```
134
135Default URL: `mdyd-dev/directory-structure`
136Default branch: `master`
137
138The `init` command supports all formats supported by [degit](https://github.com/Rich-Harris/degit), as it is used as an engine underneath.
139
140It downloads the directory structure from a given git repository and extracts it in your current directory.
141
142### Modules
143
144#### List
145
146Lists all modules installed through the Partners Portal on a given environment.
147This command will not list modules that you deployed via the `modules/` directory.
148
149```
150pos-cli modules list [environment]
151```
152
153#### Remove
154
155Removes a module from your application.
156
157```
158pos-cli modules remove [environment] <module name>
159```
160
161##### module templates
162
163Templates provide automatic processing for easier module configuration. For example, upon installing a module, it is possible to specify URIs under which pages will be available after the module has been installed. This works both in sync and deploy mode.
164
165Markup is the commonly used ERB/EJS stye: `<%=` `=%>` there is no logic supported, the only available filter is `&` which will unescape the value provided by the user (by default they are all escaped).
166
167Values for variables have to be provided in the root module directory `template-values.json`, but you can set the location of the configuration file using the `TEMPLATE_VALUES_FILE_PATH` variable.
168
169For example, by executing `TEMPLATE_VALUES_FILE_PATH=templates/values.json pos-cli deploy staging` the `templates/values.json` file will be used as values for templates.
170
171Directory structure with `template-values.json`:
172
173```shell
174modules
175└──admincms
176 ├── template-values.json
177 ├── private
178 │ └── graphql
179 │ ├── get_models.graphql
180 │ └── get_pages.graphql
181 └── public
182 └── views
183 └── pages
184 └── admin.liquid
185```
186
187**Example**
188
189A page with this code
190
191```yaml
192---
193slug: <%= &desired_location =%>
194---
195
196This is using templates <%= what =%> !
197```
198
199and a `template-values.json`
200
201```json
202{
203 "desired_location": "index",
204 "what": "magic"
205}
206```
207
208will turn into this during deploy/sync:
209
210```yaml
211---
212slug: index
213---
214
215This is using templates magic!
216```
217
218### Migrations
219
220Migrations are files that contain Liquid code (including GraphQL) that you want to run and have a trace of what exactly has been run.
221
222This is very helpful if you want to execute the same code on multiple environments after the code has been deployed. For example, seeding initial data.
223
224Read more about migrations in our documentation:
225
226* https://documentation.platformos.com/developer-guide/data-import-export/migrating-data
227* https://documentation.platformos.com/use-cases/e-commerce/seeding-configuration-data
228
229#### List
230
231Lists migrations deployed to the server and their current status.
232
233```
234pos-cli migrations list [environment] [name]
235```
236
237#### Generate
238
239Generates new migration with the name you provided. It will be prepended with a timestamp so if you create more than one, they will be run in the order you intended.
240
241Migrations run automatically on deploy.
242
243```
244pos-cli migrations generate [environment] [name]
245```
246
247#### Run
248
249You can run a migration manually using the `run` command. You must first sync the migration file to the environment.
250
251The name of the migration is the filename without the extension, or just the timestamp.
252
253```
254pos-cli migrations run [environment] [name]
255```
256
257Example:
258
259```
260pos-cli migrations run staging 20190715132951_update_admin_password
261```
262
263### Data
264
265#### Export
266
267Exports data from the environment to a given file in JSON format.
268
269Read more about [exporting data with the CLI, REST API and GraphQL](https://documentation.platformos.com/developer-guide/data-import-export/export) in our documentation.
270
271```
272pos-cli data export staging --path=data.json
273```
274
275#### Import
276
277Imports data from a given JSON file with proper data structure.
278
279Read more about [importing data with the CLI, REST API and GraphQL](https://documentation.platformos.com/developer-guide/data-import-export/import) in our documentation.
280
281```
282pos-cli data import staging --path=data.json
283```
284
285#### Clean (only staging)
286
287Cleans data on an Instance. Keep in mind that this only removes rows of data, not the structure definition.
288
289For example, if you have a model schema `car` and there are 10 entries of type `car`, those will be deleted, but the model schema `car` will remain intact.
290
291This is useful for testing your imports/exports or resetting your database to a pristine state between tests.
292
293**This operation is irreversible**. `pos-cli` will ask you twice if you are sure you want to do it.
294
295```
296pos-cli data clean staging
297```
298
299### Admin - Graphical interface
300
301To start the http server locally that will serve the GUI use:
302
303```
304pos-cli gui serve [environment]
305```
306
307Example: `pos-cli gui serve staging`
308
309To open platformOS Admin go to [http://localhost:3333](http://localhost:3333)
310
311#### Opening Admin automatically
312
313If you want to open platformOS Admin as soon as `gui serve` is running, add `--open` (`-o`) as your argument.
314
315```
316pos-cli gui serve [environment] -o
317```
318
319#### GraphiQL Browser
320
321To explore your Instance database using GraphQL open [http://localhost:3333/gui/graphql](http://localhost:3333/gui/graphql) in your web browser.
322
323In the right sidebar there is a schema documentation should you need it.
324
325#### Liquid evaluator
326
327To open a page where you can experiment with Liquid and evaluate it on your Instance, open [http://localhost:3333/gui/liquid](http://localhost:3333/gui/liquid) in your browser.
328
329
330## Development
331
332`pos-cli gui serve` (graphiql) has its own build process. You will find it in `gui/editor/graphql`.
333
334Develop install dependencies (`npm ci`) and start development mode (`npm start`).
335
336After your work is done, build production assets (`npm run build`) and commit changes to the repository.