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 |
|
5 | If 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 |
|
7 | Run 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 |
|
15 | If 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 |
|
19 | If 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 |
|
27 | For authentication, you'll need your **Partner Portal** account credentials.
|
28 | See 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 |
|
30 | To add your environment to a config file, run the `env add` command, and authenticate with your **Partner Portal** credentials:
|
31 |
|
32 | ```
|
33 | pos-cli env add [environment] --email [your email] --url [your application url]
|
34 | ```
|
35 |
|
36 | Example: `pos-cli env add staging --email myemail@example.com --url https://example.com`
|
37 |
|
38 | Configuration for environments is in the `.pos` file.
|
39 |
|
40 | ### Syncing changes
|
41 |
|
42 | ```
|
43 | pos-cli sync [environment]
|
44 | ```
|
45 |
|
46 | Example: `pos-cli sync staging`
|
47 |
|
48 | Enables 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 |
|
52 | Add `--livereload` (`-l`) to your sync command to run the [LiveReload](http://livereload.com) server in the background.
|
53 | You need to install the LiveReload browser extension for it to refresh your browser on file changes.
|
54 |
|
55 | ```
|
56 | pos-cli sync [environment] -l
|
57 | ```
|
58 |
|
59 | #### Automatically opening the browser
|
60 |
|
61 | If you add `--open` (`-o`) to the sync command, it will open your Instance in the default browser.
|
62 |
|
63 | ```
|
64 | pos-cli sync [environment] -o
|
65 | ```
|
66 |
|
67 | #### Concurrency
|
68 |
|
69 | By 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 | ```
|
72 | pos-cli sync [environment] -c 10
|
73 | ```
|
74 |
|
75 | ### Deploying changes
|
76 |
|
77 | ```
|
78 | pos-cli deploy [environment]
|
79 | ```
|
80 |
|
81 | Example: `pos-cli deploy staging`
|
82 |
|
83 | Deploys 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 |
|
85 | To skip the audit during deploy, set the environmental variable `CI` to `true`.
|
86 |
|
87 | ### Code audit
|
88 |
|
89 | ```
|
90 | pos-cli audit
|
91 | ```
|
92 |
|
93 | Example: `pos-cli audit`
|
94 |
|
95 | Runs statical analysis on files in your current application directory.
|
96 |
|
97 | ### Reading logs
|
98 |
|
99 | Access 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 | ```
|
102 | pos-cli logs [environment]
|
103 | ```
|
104 |
|
105 | From 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 |
|
107 | You can filter logs by type using the `--filter` argument.
|
108 |
|
109 | ```
|
110 | pos-cli logs [environment] --filter type
|
111 | ```
|
112 |
|
113 | Example:
|
114 |
|
115 | ```
|
116 | pos-cli logs staging --filter debug
|
117 | ```
|
118 |
|
119 | ### Listing environments
|
120 |
|
121 | If you forgot what your environments are called or the URL that corresponds to any name, use:
|
122 |
|
123 | ```
|
124 | pos-cli env list
|
125 | ```
|
126 |
|
127 | ### Initializing the directory structure
|
128 |
|
129 | If you need to create a new project from scratch you can initialize the directory structure using:
|
130 |
|
131 | ```
|
132 | pos-cli init --url mdyd-dev/directory-structure --branch master
|
133 | ```
|
134 |
|
135 | Default URL: `mdyd-dev/directory-structure`
|
136 | Default branch: `master`
|
137 |
|
138 | The `init` command supports all formats supported by [degit](https://github.com/Rich-Harris/degit), as it is used as an engine underneath.
|
139 |
|
140 | It downloads the directory structure from a given git repository and extracts it in your current directory.
|
141 |
|
142 | ### Modules
|
143 |
|
144 | #### List
|
145 |
|
146 | Lists all modules installed through the Partners Portal on a given environment.
|
147 | This command will not list modules that you deployed via the `modules/` directory.
|
148 |
|
149 | ```
|
150 | pos-cli modules list [environment]
|
151 | ```
|
152 |
|
153 | #### Remove
|
154 |
|
155 | Removes a module from your application.
|
156 |
|
157 | ```
|
158 | pos-cli modules remove [environment] <module name>
|
159 | ```
|
160 |
|
161 | ##### module templates
|
162 |
|
163 | Templates 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 |
|
165 | Markup 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 |
|
167 | Values 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 |
|
169 | For 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 |
|
171 | Directory structure with `template-values.json`:
|
172 |
|
173 | ```shell
|
174 | modules
|
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 |
|
189 | A page with this code
|
190 |
|
191 | ```yaml
|
192 | ---
|
193 | slug: <%= &desired_location =%>
|
194 | ---
|
195 |
|
196 | This is using templates <%= what =%> !
|
197 | ```
|
198 |
|
199 | and a `template-values.json`
|
200 |
|
201 | ```json
|
202 | {
|
203 | "desired_location": "index",
|
204 | "what": "magic"
|
205 | }
|
206 | ```
|
207 |
|
208 | will turn into this during deploy/sync:
|
209 |
|
210 | ```yaml
|
211 | ---
|
212 | slug: index
|
213 | ---
|
214 |
|
215 | This is using templates magic!
|
216 | ```
|
217 |
|
218 | ### Migrations
|
219 |
|
220 | Migrations are files that contain Liquid code (including GraphQL) that you want to run and have a trace of what exactly has been run.
|
221 |
|
222 | This 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 |
|
224 | Read 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 |
|
231 | Lists migrations deployed to the server and their current status.
|
232 |
|
233 | ```
|
234 | pos-cli migrations list [environment] [name]
|
235 | ```
|
236 |
|
237 | #### Generate
|
238 |
|
239 | Generates 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 |
|
241 | Migrations run automatically on deploy.
|
242 |
|
243 | ```
|
244 | pos-cli migrations generate [environment] [name]
|
245 | ```
|
246 |
|
247 | #### Run
|
248 |
|
249 | You can run a migration manually using the `run` command. You must first sync the migration file to the environment.
|
250 |
|
251 | The name of the migration is the filename without the extension, or just the timestamp.
|
252 |
|
253 | ```
|
254 | pos-cli migrations run [environment] [name]
|
255 | ```
|
256 |
|
257 | Example:
|
258 |
|
259 | ```
|
260 | pos-cli migrations run staging 20190715132951_update_admin_password
|
261 | ```
|
262 |
|
263 | ### Data
|
264 |
|
265 | #### Export
|
266 |
|
267 | Exports data from the environment to a given file in JSON format.
|
268 |
|
269 | Read 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 | ```
|
272 | pos-cli data export staging --path=data.json
|
273 | ```
|
274 |
|
275 | #### Import
|
276 |
|
277 | Imports data from a given JSON file with proper data structure.
|
278 |
|
279 | Read 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 | ```
|
282 | pos-cli data import staging --path=data.json
|
283 | ```
|
284 |
|
285 | #### Clean (only staging)
|
286 |
|
287 | Cleans data on an Instance. Keep in mind that this only removes rows of data, not the structure definition.
|
288 |
|
289 | For 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 |
|
291 | This 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 | ```
|
296 | pos-cli data clean staging
|
297 | ```
|
298 |
|
299 | ### Admin - Graphical interface
|
300 |
|
301 | To start the http server locally that will serve the GUI use:
|
302 |
|
303 | ```
|
304 | pos-cli gui serve [environment]
|
305 | ```
|
306 |
|
307 | Example: `pos-cli gui serve staging`
|
308 |
|
309 | To open platformOS Admin go to [http://localhost:3333](http://localhost:3333)
|
310 |
|
311 | #### Opening Admin automatically
|
312 |
|
313 | If you want to open platformOS Admin as soon as `gui serve` is running, add `--open` (`-o`) as your argument.
|
314 |
|
315 | ```
|
316 | pos-cli gui serve [environment] -o
|
317 | ```
|
318 |
|
319 | #### GraphiQL Browser
|
320 |
|
321 | To explore your Instance database using GraphQL open [http://localhost:3333/gui/graphql](http://localhost:3333/gui/graphql) in your web browser.
|
322 |
|
323 | In the right sidebar there is a schema documentation should you need it.
|
324 |
|
325 | #### Liquid evaluator
|
326 |
|
327 | To 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 |
|
334 | Develop install dependencies (`npm ci`) and start development mode (`npm start`).
|
335 |
|
336 | After your work is done, build production assets (`npm run build`) and commit changes to the repository.
|