2
0
mirror of https://github.com/frappe/books.git synced 2024-09-20 19:29:02 +00:00
books/docs/app.md

131 lines
2.4 KiB
Markdown
Raw Normal View History

2018-01-16 06:09:17 +00:00
# Creating a new App
2018-01-16 06:35:07 +00:00
2018-01-16 07:29:49 +00:00
## Install Frappe.js
2018-01-16 06:49:38 +00:00
2018-01-16 06:35:07 +00:00
```
yarn add frappejs
```
2018-01-16 06:49:38 +00:00
2018-01-30 12:03:04 +00:00
FrappeJS comes with built in rollup config for your files
2018-01-16 06:49:38 +00:00
2018-01-30 12:03:04 +00:00
## Build
2018-01-16 06:49:38 +00:00
2018-01-30 12:03:04 +00:00
There are 2 files that get built for the Desk single page application
2018-01-16 06:49:38 +00:00
2018-01-30 12:03:04 +00:00
- `/dist/js/bundle.js`
- `/dist/css/style.css`
Your `rollup.config.js` should look like:
2018-01-16 06:49:38 +00:00
```js
2018-01-30 12:03:04 +00:00
module.exports = [
require('frappejs/config/rollup.config.style.js'),
require('frappejs/config/rollup.config.app.js')
]
2018-01-16 06:49:38 +00:00
```
## Create a basic app
### index.html
The UI for the single page app (desk) will be built inside the `body` element, so you just need to have an empty body element, and link your JS bundle in `index.html`
Sample index.html
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
2018-01-30 12:03:04 +00:00
<title>Document</title>
<link href="/dist/css/style.css" rel="stylesheet">
2018-01-16 06:49:38 +00:00
</head>
<body>
2018-03-21 09:48:01 +00:00
<script src="/dist/js/socket.io.js"></script>
2018-01-16 06:49:38 +00:00
<script src="js/bundle.js"></script>
</body>
</html>
```
2018-03-21 09:48:01 +00:00
## For development setup
Clone frappejs in the same folder as your app, since you will be developing frappejs on the side.
### Link frappejs
```sh
# make frappejs linkable
cd frappejs
yarn link
yarn link frappejs
# link frappejs in all
cd ../myapp
yarn link frappejs
# install libs
yarn
```
2018-01-16 06:49:38 +00:00
### server.js
Create your server file `server.js`
```js
const server = require('frappejs/server');
server.start({
backend: 'sqlite',
connection_params: {db_path: 'test.db'},
static: './'
});
```
### index.js
In your client file you will have to import all your controllers and init them.
`frappejs/client` lib will initialize your server and user interface with the Desk.
Example starting point for a to-do app:
```js
const client = require('frappejs/client');
const todo = require('frappejs/models/doctype/todo/todo.js');
// start server
client.start({
server: 'localhost:8000',
}).then(() => {
frappe.init_controller('todo', todo);
frappe.desk.add_sidebar_item('Home', '#');
frappe.desk.add_sidebar_item('New ToDo', '#new/todo');
frappe.router.default = '/list/todo';
frappe.router.show(window.location.hash);
});
2018-01-16 07:29:49 +00:00
```
## Start
To start the app and build webpack simultaneously you can use a `Procfile`
```yml
server: nodemon server.js
2018-02-13 10:05:41 +00:00
watch: node_modules/.bin/rollup -c --watch
2018-01-16 07:29:49 +00:00
```
You can use any procfile handler like `node-foreman` to start the processes.
```
2018-05-05 12:11:15 +00:00
yarn global add foreman
2018-01-16 07:29:49 +00:00
```
Then
```
nf start
2018-02-13 10:05:41 +00:00
```