Skip to content

Workflow

lptr edited this page Sep 12, 2014 · 11 revisions

Spaghetti is all about modules, and the type-safe interfaces between them. Working with Spaghetti involves creating modules, using modules from other modules, and packaging them into executable applications.

Creating a Module

Before creating a module, you need to decide on its implementation language. This will be the language you write the actual code of the module in. Spaghetti supports Haxe and TypeScript out of the box, and adding support for other languages is fairly simple.

Header Generation

The first step in creating a module is to define its API in the [Spaghetti Interface Definition Language](Spaghetti Syntax). Spaghetti then translates the module definition into the implementation language's concepts: classes, interfaces etc. We'll refer to these generated sources as "headers," from C/C++ parlance.

Module Bundles

Once you have the language-specific headers generated, you can write the actual code of the module in the chosen language. Through the generated headers the compiler will ensure that the resulting JavaScript code satisfies the API contract specified in the module's Spaghetti definition. Once the compiled JavaScript is ready, it needs to be packaged into a distributable format called the "module bundle."

Bundling

The bundle is a ZIP file that contains the compiled JavaScript code, the module's Spaghetti definition, some metadata, and optionally some resources like images or CSS files.

Handling Dependencies

A module by itself is no true module at all: it needs to access other modules to get its job done. When generating headers, you can supply additional module bundles to Spaghetti. Additional source files will be generated for these dependent modules in your module's implementation language, so your module's code can access them in a type-safe way.

Dependencies

It doesn't matter what language the dependent modules were written in: by using the definition from their bundles, Spaghetti can generate headers (i.e. proxies) in the implementation language of your module. This way your Haxe module can happily talk to another module written in TypeScript. The calls between them will be type-checked by the compiler.

Packaging Applications

Spaghetti modules are like libraries: they are not very useful without an executable application to use them. Spaghetti can generate AMD (RequireJS) and CommonJS (NodeJS) applications using your modules. Each module is first wrapped in a packaging-specific wrapper, copied to a shared directory, and then a separate executable JavaScript file (the application) is generated.

Packaging

For more info about how the module's JavaScript gets wrapped into multiple layers of functions to become an AMD or CommonJS module, see the wrapping page.