Appendix A. Setting Up a Development Environment

At some point you’re going to need to set up a local or server copy of Enyo, if only to package up the applications you’ve developed. We’ll cover a few methods of setting up Enyo and discuss the prerequisites for each.

Prerequisites

There are a couple of tools that Enyo makes use of that, depending on your needs, will be required. These tools include Node.js and Git. We’ll cover why you’ll need those and where to get them.

Node.js

Node.js is a platform for running JavaScript outside of a browser. It can be used as a general purpose scripting language. Node is available for Windows, Linux, and Mac OS X. Visit the Node.js download page to download the appropriate version of Node for your system.

Git

Git is a distributed source-code management tool. It allows for software developers to keep revisioned copies of their source code. It is also the tool the Enyo team uses for Enyo development and the tool required to work with GitHub, an online source code repository that hosts the Enyo source.

Git is not required to use the basic parts of Enyo. You’ll want to install Git if you wish to be able to keep up with the latest developments with Enyo, wish to contribute to Enyo, or you want to use a system that makes it easy to keep past revisions of your source code.

GitHub has instructions for setting up Git. The basic installation installs a command-line client. There are also GUI clients available for all the major platforms.

Installing Enyo

There are several methods for installing Enyo. One of the easiest ways to make Enyo apps is to start with Bootplate. Bootplate includes all the scaffolding you’ll need to debug and deploy an app. We’ll cover Bootplate and other methods for installing Enyo.

Bootplate

Bootplate is a scaffold upon which to build an Enyo app. It includes tools that allow you easily debug your app in a browser and then deploy a minified version of Enyo with your app. There are two ways to install Bootplate: by downloading a zipped archive from the Enyo site and by cloning the archive from GitHub.

The simplest method is to download the zip archive from the Get Enyo page. As of this writing, the latest version is 2.1.1. After downloading, simply unzip the archive.

To download Bootplate from GitHub, perform the following steps:

git clone https://github.com/enyojs/bootplate.git
cd bootplate
git submodule update --init

Full Source

You can download the full source-code tree for Enyo from GitHub. To set up Enyo you will need to clone the Enyo repository and then create a lib directory in the same directory. Inside the lib directory, clone the Enyo libraries you need for your application. The following diagram shows the directory structure and the Git repos:

enyo          [email protected]:enyojs/enyo.git
lib           (mkdir the lib folder)
   onyx       [email protected]:enyojs/onyx.git
   layout     [email protected]:enyojs/layout.git
   ...

Enyo npm Module

Another method to quickly create Enyo apps is to use the Enyo npm module. npm is a package manager for Node.js. npm is installed with the latest versions of Node. To install the Enyo package, issue the following command:

npm install -g enyo

Once the Enyo npm module is installed you will have a new command-line tool that will create new Enyo apps for you. It also includes a debug server built with Node. To initialize a Bootplate project, use the following command within an empty directory:

enyo init:bootplate

You will be prompted to answer several questions about your new app. Once complete, you will have a project ready to test. To start the test server, use:

enyo debug

This creates a server on port 8000. You can test your app by navigating your browser to http://127.0.0.1:8000/debug.html.

Using Bootplate

Bootplate gives you a head start in creating your app by providing a ready-to-use structure for your app. It provides a source directory that contains App.js and App.css, which you can edit with your own source. You can modify the included package.js to add additional source files and directories.

Bootplate provides scripts to create a ready-to-deploy version of your app, including a minified version of Enyo. For general testing, you will load debug.html into your browser. When you have created a production version, you can load it by opening index.html. To produce a deployable version of your app, issue the following command:

tools/deploy.sh (toolsdeploy.bat on Windows)

When all the source has been combined and minified it will be placed into the deploy/bootplate directory. The contents of that directory can be copied up to a web server or packaged with one of the various packaging tools (see Chapter 6).

Warning

When testing Enyo apps by loading a file directly into the browser (as opposed to serving it from a web server), you can run into security restrictions in the browser, particularly when attempting to perform requests to load resources. Some browsers allow you to override those security restrictions. For best results, test your app by serving it with a web browser (such as Apache) or using the debug server built into the npm module.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.60.249