"hello, world" pure JavaScript xjs Module Tutorial

Suppose you want to write your own pure-JavaScript xjs package that creates greetings like "hello, world". xjs packages are really just xpkg packages. The following is an example of creating the xpkg package manually.

Developing the Package

Create the following package structure

~/
  hello_0.0.1_all/
    data/
      lib/
        hello.js
    xpkg/
      meta

~/hello_0.0.1_all/data/lib/hello.js

This file contains the payload code of the package.

var hello = function(name) {
  return 'hello, ' + name;
};

~/hello_0.0.1_all/xpkg/meta

The xpkg directory contains files related to package management. The meta file describes the package.

Package      : hello
Version      : 0.0.1
Architecture : all
Maintainer   : Peter Michaux 
Description  : A welcoming xjs module.

Packaging the Package

Packages are simply tarballs.

cd ~
tar cvzf hello_0.0.1_all.xpkg hello_0.0.1_all

Sharing the Package

If other developers might benefit from your hello package then you can submit it for distribution on the central xjs site. You can email your .xpkg file to petermichaux@gmail.com to be added to the central xjs site. (Eventually a PAUSE-like site will be built.)

Comments

Have something to write? Comment on this article.