This page describes the guidelines that front-end engineers develop and test the components using the UI framework of Portal and quickly familiar with our basic ideas behind the scene.
Installing the following tools before you continue.
Download and install Node.js and Ruby. Following installation, you should be able to invoke node, npm, gem on your command line. If desired, you may optionally use a tool such as nvm, nave or rvm to manage your Node.js installation.
Download and install a git client, if you don’t already have one. Following installation, you should be able to invoke git on your command line.
If you are working on Mac platform, recommending install them using brew.
Setup Dev Env
Step 1: Clone the Repo
Step 2: Install Dependencies
If you have encountered ERR! like the one below, please run the commands with sudo.
Please try running this command again as root/Administrator
Step 3: Run it
Tips
If you install the environment first time you need run the grunt serve:dist before run grunt serve to download related libraries;
if you had encountered the error like follows, you need run the command launchctl limit maxfiles 4096 4096 && ulimit -n 4096 before you do the grunt serve, or you can append this cmd in your ~/.bashrc or ~/.zshrc at your choice.
Running “watch” task
Waiting…Warning: EMFILE, too many open files ‘tmp’
The development mode is used for local dev environment, it won’t compile source files in order to let you debugging or testing your codes freely.
When it’s booted up in development environment:
First off, compiling LESS and Jade into CSS and JavaScript AMD module respectively;
Then, setting up a local web server which will be in charge of hosting static files, such as JavaScript/HTML/CSS, etc…;
Then, open the default browser and navigate to home page of portal;
Then, setting up local JSON server that mocks web backend server, at the same time this process will be kept alive;
Finally, setting up the watch task, then whatever any JavaScript or LESS source files changed, the browser will be live reloaded.
The production mode is used for production environment before deploying on staging or production environments, so you could take a glance for that quickly locally.
When it’s booted up in production environment:
Build the whole project, including compile/minify/concat/rev/uglify/… tasks;
Then, open the default browser and navigate to home page of portal;
Then, setting up local JSON server that mocks web backend server, at the same time this process will be kept alive;
Finally, setting up a local web server which will be in charge of hosting static files, such as JavaScript/HTML/CSS, etc…;
By the way, as for the JSON server task, you could find the JSON data file from test/mock/db.json. We wrote one Grunt task which is focus on read data from this file and set up RESTFul API for you automatically.
Example of db.json:
And then, the JSON server will set up the API interface below for your CRUD operation, so the development of front-end could be separated from web backend and we don’t care about the changed of schema or whatever other things you could image.
Define A Simple UI Layout
Let’s say that you wanna create one About page in order to give one brief introduction for our product.
Step 1: Create Layout Descriptor
We use the descriptor to define the layout.
As for how Descriptor works, please refer to here. The type is the path of your component relative to directory of src/app.
Here we use the layout of components/layout/simple, it only contains one body named components/about that is what we need to create.
Step 2: Create Component
First off, we need to create the Angular controller named about.controller.js which is located at directory of src/app/components/about.
Then, we will create one template named about.html.jade or about.html(we support JADE and HTML)which is located at directory of src/app/components/about.
or
Here we support pure HTML and Jade to write your template.
However, we strongly recommend to use Jade, as it’s a clean, whitespace sensitive syntax for writing HTML.
Step 3: Run it
After local dev environments starts, then navigate to About.
Define A Complex Component
From simple component Step 1 to 3 got an basic static page by component, but as for the production environment, we always need to get the data from backend in order to generate the dynamic page.
In the agile development, the backend and front developer always need coding at same time, so if there is an mock server to emulate the data, it will be more efficiently.
Currently we use the /test/mock/db.json as the mock data, the /tasks/data_server_task.js used to define the web server.
Define the Model with factory located at app/factories/addressModle.js:
Step 4: Mock Data
Pre insert mock data into /test/mock/db.json.
Step 5: Run it
Step 6: Write Unit Test
Here is the unit test for AboutController located in src/app/about/about.controller.js using Jasmine and Karma.
Build & Release & Deploy
After you finish your coding, next step is to build, release and deploy it on production environments.
I’d like to build the whole project and optimize it through Build task, the build files will be put into dist directory by default. It include:
Lint JavaScript/CSS files;
Clean dist directory;
Convert Jade template into AMD module;
Concat CSS files;
…
Combines related scripts together into build layers and minifies them via UglifyJS (the default) or Closure Compiler (an option when using Java).
Optimising CSS by inlining CSS files referenced by @import and removing comments.
If you want to release it, you could generate tar and zip file in the tmp directory through distribute task.
Finally, you could deploy it using the compressed package on your web server, such as nginx, apache or third-party CDN(such as CloudFront).