1 | # Create JS App
|
2 |
|
3 | **This project is under development, API can change in different ways. Any help is appreciated :) Feel free to open PR.**
|
4 |
|
5 | Create full stack javascript apps with no build configuration and one dependency.
|
6 |
|
7 | ## Installation
|
8 |
|
9 | ```sh
|
10 | npm install -g create-js-app
|
11 |
|
12 | create-js-app my-app
|
13 | cd my-app/
|
14 | npm start
|
15 | ```
|
16 |
|
17 | Then open [http://localhost:3000](http://localhost:3000) to see your app.
|
18 |
|
19 | ## Development
|
20 |
|
21 | To start development run following command in project root directory.
|
22 |
|
23 | ```sh
|
24 | npm start
|
25 | ```
|
26 |
|
27 | ## Production
|
28 |
|
29 | To create a minified build run following command in project root directory.
|
30 |
|
31 | ```sh
|
32 | npm run build
|
33 | ```
|
34 |
|
35 | ## Configuration
|
36 |
|
37 | ```js
|
38 | // .app.js file in project directory
|
39 |
|
40 | module.exports = {
|
41 | // default is create-js-app-scripts/scripts/config/eslint/default.js
|
42 | eslint: 'create-js-app-scripts/scripts/config/eslint/airbnb.js',
|
43 |
|
44 | // tasks you want to run during development
|
45 | // it will terminate them when you terminate development script
|
46 | tasks: [
|
47 | (eventEmitter) => {
|
48 | // do something, maybe watch files using chokidar, anything
|
49 | eventEmitter.emit('task-log', 'some info');
|
50 | eventEmitter.emit('task-log-error', 'some info');
|
51 | eventEmitter.emit('task-log-info', 'some info');
|
52 | eventEmitter.emit('task-log-success', 'some info');
|
53 | eventEmitter.emit('task-log-warning', 'some info');
|
54 |
|
55 | return {
|
56 | /**
|
57 | * This is used to terminate task when command receives SIGTERM
|
58 | * @returns {Promise}
|
59 | */
|
60 | terminate() {
|
61 | return Promise.resolve();
|
62 | }
|
63 | }
|
64 | }
|
65 | ]
|
66 | };
|
67 | ```
|
68 |
|
69 | ## Directory structure
|
70 | **There is not an init command at the time so you need to create this manually**
|
71 |
|
72 | ```
|
73 | src
|
74 | /client
|
75 | /index.js
|
76 | /server
|
77 | /index.js
|
78 | ```
|
79 |
|
80 | ```js
|
81 | // example of server side javascript file
|
82 | // you can use any node.js http framework
|
83 | // but you have to export listener
|
84 | // so create-js-app can manage it
|
85 | //src/server/index.js
|
86 |
|
87 | import Koa from 'koa';
|
88 |
|
89 | const app = new Koa();
|
90 |
|
91 | // SERVER_PORT is provided by webpack build
|
92 | const listener = app.listen(SERVER_PORT);
|
93 |
|
94 | export default listener;
|
95 |
|
96 | ```
|