Posted by & filed under Tips.

This tip is based off of v0.6.1.

The source code for enchant.js exists within the enchant.js, but this file is created from dev/src/*.js (github). The dev/src folder contains files which separate out the different parts of enchant.js by class. For instance the code which makes up the Sprite class is located in dev/src/sprite.js. To search for code which makes up a specific class, this is the best way to find it.

Files in dev/src/ must undergo a syntax check, be combined, and then optimized in order to create enchant.js and enchant.min.js. This is called the build process. If files in dev/src/ are edited, they must undergo the build process again in order to be usable in working script.

The following tools are required for the build process:

  • node.js
  • npm (node package manager)
  • grunt
  • ruby
  • rake
  • (phantomjs)

Ruby and rake are included by default on most installations of OSX and Linux. Node.js and npm can be downloaded from http://node.io. After installing Node.js and npm, navigate to the enchant.js directory in command line, and type npm install to install the required package.

Executing the grunt command is what begins the build process (More info on grunt). Several different options are available when building, but by default, grunt runs lint:core concat min qunit exec:lang. These commands do the following:

  • lint: js – Checks code syntax
  • concat: – Creates dev/enchant.js from dev/src/*.js
  • min: – Creates enchant.min.js from dev/enchant.js
  • qunit: – Carries out unit testing on dev/enchant.js with qunit, via phantomjs
  • exec:lang: – Creates enchant.js ,ja/enchant.js, etc. based off of language of comments in the code from dev/enchant.js

Specific build tasks can be performed, such as grunt lint, etc., but keep in mind that if any files within dev/src are changed, concat min will be run automatically due to grunt watch. (grunt watch monitors files in a directory for changes.)

This post is also available in: Japanese

Comments are closed.