AppSuite:GettingStarted 7.6.0: Difference between revisions

From Open-Xchange
Line 108: Line 108:
  $ grunt dist:rpm
  $ grunt dist:rpm


You can then use tools like rpmbuild to build the rpm file.
You can then use tools like rpmbuild to build the rpm file. One example would be:
 
$ mkdir -p ~/rpmbuild/{SOURCES,SPECS,BUILD,RPMS}
  cp dist/*.orig.tar.gz ~/rpmbuild/SOURCES/
  cp dist/*.spec ~/rpmbuild/SPECS/
  rpmbuild -bb ~/rpmbuild/SPECS/*.spec


=== DEB packages ===
=== DEB packages ===

Revision as of 15:10, 20 May 2014

Getting Started
OX AppSuite UI Development Workflow.png

Hello and welcome to the world of OX App Suite development. This document is designed to get you started with developing your first app for OX App Suite as quickly and simply as possible. However, along the way we will also tempt you to learn more by linking to some more in-depth documentation about the various topics we cover.

Installing the Development Tools

First, you need to install some tools which are necessary for UI development.

$ npm install -g grunt-cli bower yo Open-Xchange-Frontend/generator-ox-ui-module

Create a Workspace

All your app development can take place inside one working directory. The examples will assume you have created a directory named myapp inside your home directory:

$ mkdir ~/myapp
$ cd ~/myapp

It doesn't need to be in your home directory, and the actual name should reflect the name of your app. The main point is that all commands will be executed in this directory and all paths will be relative to this directory from now on.

Now, you can generate a grunt configuration using:

$ yo ox-ui-module

The source code of your app will reside in the subfolder named apps. To avoid name collisions please pick a unique subfolder inside that. The easiest and recommended way is to use a domain name that you own. Typically, the domain elements are reversed, like in Java. example.com becomes com.example:

$ mkdir -p apps/com.example

Writing an App

As an example, let's create the smallest possible app and test it. It requires only two files: apps/com.example/register.js for the source code of the app:

define('com.example/register', function () {
    'use strict';
    alert('Hello, World!');
});

and apps/com.example/manifest.json for the manifest which tells the UI that your app exists and what to do with it:

{ "namespace": "core" }

Building an App

The source code of your app can't be used by OX App Suite as it. It first has to be processed by the build system. This step will check the source code for syntax errors, compress it, and depending on the structure of your code, many other things. The processed code is then written to a directory named build by default. Start the build with this command:

$ grunt

If your editor supports it, you can configure it to call the build system after every file save. Take care to call it from the top directory of your app's workspace, not from the directory of the saved file.

Testing an App

The freshly built code can now be tested. Instead of uploading your code to an OX App Suite server, you can use the appserver proxy to inject your code into the UI code of any existing OX App Suite installation. For example, to start appserver using ox.io as the server, you will need a local configuration pointing to that server. You can generate it with this command:

$ grunt show-config:local --output grunt/local.conf.json

Open up the file grunt/local.conf.json in your editor and add "http://ox.io/ ox.io" to the server setting of the appserver section. Then start the development server:

$ grunt dev

This command will serve your app from the local directory build, and get everything else from the URL specified in the server setting.

Once appserver is running, you can access OX App Suite by opening your browser using this address:

http://localhost:8337/appsuite

After logging in, the app should be loaded and display the alert message.

Development cycle

Once you are sure that your setup works, you can extend the example and write the actual code for your app. The dev task will detect any changes and rebuild your app and even reload all browsers connected to http://localhost:8337/appsuite.

While developing always keep in mind, that there is an article about debugging the user interface which helps you avoid and fix typical errors.

Packaging

The following sections are for testing the "API" before the actual release, they will only work with recent developer versions of the tools mentioned above. Please be patient until this message disappears or you think you know, what you are doing

Together with our ox-ui-module generator, we provide you with generators for packaging information.

Generating a source tarball

There is a grunt tasks to create source packages. You can use it to create a tar.gz file containing all sources needed to build the project. This source package should contain all dependencies that are installed during bower install and npm install (basically containing your bower_components and node_modules directories). To generate this file, run:

$ grunt dist:source --include-dependencies

This file (can be found in the dist/ directory) together with the distribution specific packaging information will be needed to build the package.

RPM packages

In order to generate a spec file for your project, run:

$ yo ox-ui-module:rpm-pkg

Will generate a spec file, with some default values read from your package.json file. So you might want to make this file as complete as possible. However, yeoman will ask you about the information missing.

Please remember, that the generated spec file is only a scaffold for a real one. It will work for very simple cases, but as soon as your package gets more complicated, you will have to adjust it to your needs.

Once you have the spec file in your project, you can use

$ grunt dist:rpm

You can then use tools like rpmbuild to build the rpm file. One example would be:

$ mkdir -p ~/rpmbuild/{SOURCES,SPECS,BUILD,RPMS}
  cp dist/*.orig.tar.gz ~/rpmbuild/SOURCES/
  cp dist/*.spec ~/rpmbuild/SPECS/
  rpmbuild -bb ~/rpmbuild/SPECS/*.spec

DEB packages

Creating packages for the Debian distribution works similar to rpm packages. Just run:

$ yo ox-ui-module:deb-pkg

This will generate a debian directory containing all needed files. Some default values will be read from your package.json file. So you might want to make this file as complete as possible. However, yeoman will ask you about the information missing.

Please remember, that the generated spec file is only a scaffold for a real one. It will work for very simple cases, but as soon as your package gets more complicated, you will have to adjust it to your needs.

Once you have a debian/ directory for your project, you can go on. To enable some grunt tasks to help you, you need to install (with npm install) grunt-contrib-compress and grunt-exec. Now you can run:

$ dist:dpkg-source

You can now use the files in the dist/ directory to build your packages. A simple example would look like:

$ cd dist/unicorn-0.0.1/
  dpkg-buildpackage -b

Further Reading