1 | # KASH Core
|
2 |
|
3 | Set of tools to bundle, transpile and compress apps.
|
4 |
|
5 | ## Creating a project
|
6 |
|
7 | This 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 |
|
11 | Create 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
|
15 | class 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
|
27 | Shell.define(App);
|
28 | ```
|
29 |
|
30 | With 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.
|
31 | You should now see your `Hello World` message.
|
32 |
|
33 | ### Environment and config
|
34 |
|
35 | Each 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`
|
36 | Config managment for your project is done through a set of JSON files under your project's `config` directory.
|
37 |
|
38 | Create 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.
|
39 | If 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.
|
40 | Common environments are `staging`, `production`, `rc`, `test`.
|
41 |
|
42 | You can retrieve the app's environment at runtime through the `ENV` property in the config object.
|
43 |
|
44 | In 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 |
|
53 | Then update your `index.js`:
|
54 |
|
55 | ```js
|
56 | class App {
|
57 | constructor(bus, config) {
|
58 | this.root = document.createElement('div');
|
59 | this.root.innerText = `${config.APP_NAME} - ${config.ENV}`;
|
60 | }
|
61 | }
|
62 |
|
63 | Shell.define(App);
|
64 | ```
|
65 |
|
66 | Refreshing 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 |
|
70 | The 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 |
|
72 | Add a `package.json` file in your project if it doesn;t already have one. Set the `version` field to a custom version.
|
73 |
|
74 | Update your `index.js` again to use the `VERSION` key from the config:
|
75 |
|
76 | ```js
|
77 | this.root.innerText = `${config.APP_NAME} - ${config.ENV} running version ${config.VERSION}`;
|
78 | ```
|