UNPKG

2.96 kBMarkdownView Raw
1# KASH Core
2
3Set of tools to bundle, transpile and compress apps.
4
5## Creating a project
6
7This guide will explain how to create a minimal project that can be used to output an application on all the platforms supported by kit-app-shell
8
9### index.js
10
11Create an `index.js` file and input the following:
12
13```js
14// This is your app main class, the bridge between the shell and your web content
15class App {
16 // When your app is created, it is given a bus to communicate with the backend and
17 // a config object containing your project's config
18 constructor(bus, config) {
19 // kit-app-shell will be looking for this property to be set as the root of your DOM tree
20 this.root = document.createElement('div');
21 // Show something
22 this.root.innerText = 'Hello World'
23 }
24}
25
26// By calling this method, you provide the shell your App class and it will be used to start the app
27Shell.define(App);
28```
29
30With this simple configuration, you can already run `kash run web ./` in your project's directory (Make sure you have `@kano/kit-app-shell-web` installed) and open a browser to the given URL.
31You should now see your `Hello World` message.
32
33### Environment and config
34
35Each app is ran or built for a target environment. This environment can be defined using the `--env` flag with the CLI, its default value will be `development`
36Config managment for your project is done through a set of JSON files under your project's `config` directory.
37
38Create a `config` directory and a `default.json` inside. The `default.json` file will always be loaded, but its values can be overriden by a config file matching an environment.
39If you add a `development.json` file both default and development config will be loaded and values in the development config will override the default values.
40Common environments are `staging`, `production`, `rc`, `test`.
41
42You can retrieve the app's environment at runtime through the `ENV` property in the config object.
43
44In your newly created `default.json`, add the following:
45
46```json
47{
48 "APP_ID": "com.acme.app",
49 "APP_NAME": "My App"
50}
51```
52
53Then update your `index.js`:
54
55```js
56class App {
57 constructor(bus, config) {
58 this.root = document.createElement('div');
59 this.root.innerText = `${config.APP_NAME} - ${config.ENV}`;
60 }
61}
62
63Shell.define(App);
64```
65
66Refreshing your browser page should now display the message `My App - development`, you can try running `kash run web ./ --env=<env>` with different environment to see the changes
67
68### Versioning
69
70The version of the app will be loaded from your project's `package.json` and will be added to the config object under the `VERSION` key.
71
72Add a `package.json` file in your project if it doesn;t already have one. Set the `version` field to a custom version.
73
74Update your `index.js` again to use the `VERSION` key from the config:
75
76```js
77this.root.innerText = `${config.APP_NAME} - ${config.ENV} running version ${config.VERSION}`;
78```