1 | ### Build App
|
2 |
|
3 | **Build App** is a full-stack JS App build system. Inspired by Facebook's create-react-app and other client build systems it is going one step futher providing similar facilities for full-stack JS development.
|
4 |
|
5 | The aim of the project is to simplify development of modern full-stack JS applications, providing most of basic dev operations out of the box (build, run dev mode, lint, etc).
|
6 |
|
7 | It is provided with starter templates for Client/Server which you can combine to seed you project with technologies of your choice.
|
8 |
|
9 | See deployed template here:
|
10 |
|
11 | [React / PostgreSQL on Heroku](https://napp-full-tmp.herokuapp.com)
|
12 |
|
13 | Use user_a@test.com / pas123 for login.
|
14 |
|
15 | _Build App_ works is OS-agnostic.
|
16 |
|
17 | ## Getting started
|
18 |
|
19 | ```sh
|
20 | # install build-app globally
|
21 | npm install -g build-app
|
22 |
|
23 | # see list of available commands
|
24 | app-scripts --help
|
25 |
|
26 | # init new project
|
27 | app-scripts init
|
28 |
|
29 | # change directory to new project folder
|
30 | cd my-app
|
31 |
|
32 | # seed project
|
33 | app-scripts seed
|
34 | ```
|
35 |
|
36 | To run server: open project in IDE (preferably VS Code) and use available configuration alternatively you can run it with `app-script serve -s`
|
37 |
|
38 | To run client run in terminal: `app-scripts serve -c`
|
39 |
|
40 | ## Project structure
|
41 |
|
42 | _Build App_ assumes some predefined project structure.
|
43 |
|
44 | Project consists of server and client parts.
|
45 |
|
46 | By default server part is located in {root}/server folder and client in {root}/client.
|
47 |
|
48 | Those values can be overridden in build-app.config.
|
49 |
|
50 | ### Client:
|
51 |
|
52 | Client is SPA written in one modern JS front-end frameworks (React/Angular/vue). They are using existing client side build systems (like create-react-app for React).
|
53 |
|
54 | Build system expects to be able to create client build by running 'npm run build' command in client folder. Output is expected in {client}/build folder and index.html starts client SPA application.
|
55 |
|
56 | More details how to setup client-side build you can find in docs for particular build system:
|
57 |
|
58 | React: [create-react-app](https://github.com/facebookincubator/create-react-app)
|
59 |
|
60 | ### Server:
|
61 |
|
62 | Both JS/TS js flavors are supported. For JS you can use latest language features like ES6, async/await and others. Code is compiled to ES5 during the build.
|
63 |
|
64 | Server entry file should be located at ./src/index (.ts or .js).
|
65 |
|
66 | There are some special folders
|
67 |
|
68 | **data**: folder with data assets like data json files, email templates, etc.
|
69 |
|
70 | **local**: folder where server writes data to, here you can have logs output, local overridden values for config file, file uploads, etc.
|
71 |
|
72 | ## app-script commands
|
73 |
|
74 | After build-app is installed globally app-scripts command is available globally. It has different commands (scripts). Note instead of 'app-scripts' command you can use 'napp' alias.
|
75 |
|
76 | ### Init
|
77 |
|
78 | _init_ command seeds empty project. There are separate templates for server and client parts.
|
79 |
|
80 | For interactive init run init command with no parameters:
|
81 |
|
82 | ```sh
|
83 | app-scripts init
|
84 | ```
|
85 |
|
86 | To see all available templates run:
|
87 |
|
88 | ```sh
|
89 | app-scripts init --list
|
90 | ```
|
91 |
|
92 | To seed project with particular templates use --project --server --client options:
|
93 |
|
94 | ```sh
|
95 | app-scripts init my-app --project simple --server ts --client react
|
96 | ```
|
97 |
|
98 | To init basic IDE settings use option --ide (currently supported vs code only)
|
99 |
|
100 | ```
|
101 | app-scripts init my-app --default --ide code
|
102 | ```
|
103 |
|
104 | ### Seed
|
105 |
|
106 | _seed_ command do initial project setup. That includes installing dependencies, building server/client code, and running seed task if available in template. Note you can run install and build commands separately later.
|
107 |
|
108 | ```
|
109 | app-scripts seed
|
110 | ```
|
111 |
|
112 | ### Install
|
113 |
|
114 | _install_ command installs dependencies for both client and server project parts. It can use one of following package managers under the hood: npm, yarn, pnpm. If pnpm is installed globally it is used, then yarn used if available, then npm.
|
115 |
|
116 | The same can be done manually with
|
117 |
|
118 | ```sh
|
119 | cd {server_dir}
|
120 | npm install
|
121 |
|
122 | cd ../{client_dir}
|
123 | npm install
|
124 | ```
|
125 |
|
126 | ### Build
|
127 |
|
128 | _build_ command creates production ready build in build folder (./build by default).
|
129 |
|
130 | To start server run index.js file. You may need to install dependencies first.
|
131 |
|
132 | Build command builds server and client separately and then combines them together into deployable build package.
|
133 |
|
134 | ### Deploy
|
135 |
|
136 | Deploys application to different sources (by using target parameter):
|
137 |
|
138 | #### _local_ deployments:
|
139 |
|
140 | ```bash
|
141 | app-scripts deploy
|
142 | ```
|
143 |
|
144 | Build package copied to deployment folder (./deploy/local by default) and starts the application with one of supported process managers (forever or pm2). Following deployments will stop application first and clear all deploy folder content except local folder.
|
145 |
|
146 | #### _heroku_ deployments:
|
147 |
|
148 | Create new heroku app
|
149 |
|
150 | Install heroku and login locally
|
151 |
|
152 | ```bash
|
153 | npm i -g heroku
|
154 | heroku login
|
155 | ```
|
156 |
|
157 | For deployment run
|
158 |
|
159 | ```bash
|
160 | # specify heroku app id for initial deployment
|
161 | app-scripts deploy -t heroku -i dev --heroku-app my-heroku-id-for-dev
|
162 | # for following deployment you can skip that
|
163 | app-scripts deploy -t heroku -i dev
|
164 | ```
|
165 |
|
166 | Note that that you can deploy to multiple instances corresponding to different environments (dev/staging), you have to create separate heroku apps for each
|
167 | ## Npm Scripts
|
168 |
|
169 | Some operations are expected to be configured as particular npm scripts:
|
170 |
|
171 | Build client - 'build' script (in client folder)
|
172 |
|
173 | Serve client - 'start' script
|
174 |
|
175 | Serve server - 'start' script (in server folder)
|
176 |
|
177 | Also if pre-build/post-build scripts are defined in server/client package.json files corresponding scripts will be executed before/after server/client builds.
|
178 |
|
179 | ## Local development
|
180 |
|
181 | For local development run
|
182 |
|
183 | ```bash
|
184 | sudo npm link #(in package dir)
|
185 | ```
|