A simple command-line tool to create the folders and helper files
create a website to promote your project.
the tests, the distribution files? Do you have support scripts to
Generators to create new unit test HTML files?
newjs has finished helping you write your source libraries,
write test HTML files, providing autotesting scripts to make TDD a piece of cake,
What a nice helpful tool it is!
The command-line application
newjs is installed as below,
for any operating system (except the ‘sudo’ part – use as necessary):
sudo gem install newjs
To kick-off your new project/library, run the command-line app
Look at all that!
Unit testing uses the
developed within prototypejs. It should
Your raw, unconcatenated library/source files go in
Your unit test HTML files, go in
test/unit/ (see test generator below).
Your functional test HTML files, go in
test/functional/ (see test generator below).
When you’ve got a new version to release, edit
Rakefile and modify the
APP_VERSION string (see Distribution section below).
To merge your
src/ files into a distribution file, see below.
If you are going to have a
src/some_lib.js file, then you’ll want a unit
test file(s). By default you’d call it
Generating test HTML files
on Rails, which allows you to generate a
test HTML stub. So I’ve included a version of it
test HTML files, ready to rock and roll.
$ script/generate unit_test some_lib create test/unit create test/unit/some_lib_test.html
test/unit/some_lib_test.html and follow the comments
that tell you what to do to write your unit tests.
Want to name your test file something different? Specify the target
library as an additional parameter.
$ script/generate unit_test my_library_tests some_lib exists test/unit create test/unit/my_library_tests_test.html
Running unit tests
Each test HTML file should be self-executable: just open it in a target
browser. That is, to run the
in Firefox, open the file in Firefox.
It will print out a beautiful log success/error messages for each test.
End-to-end functional tests will test the final distribution file(s), rather than
As shown below, your
src/ files will be merged into (commonly) one
distribution file – a merging of your source files.
Generating test HTML files
To create functional tests, there is another generator:
$ script/generate functional_test basic_usage create test/functional create test/functional/basic_usage_test.html
Running functional tests
The generated HTML file uses the
dist/mylib.js file. So, if
you are running these tests it is best to use the
as it pre-builds the distribution files first.
Distribution of library
Your project comes with the ability to concatenate all your
files into a single file for distribution, as
src/HEADER with information that will be included
at the top of the generated distribution file.
src/project_name.js to include the names of
src/ files that will be concatenated together
in your required order.
Finally, run the command:
Two files are added into the
$ ls dist/ drnic_js_test_helpers-0.5.0.js drnic_js_test_helpers.js
One with a version number, and one without.
Upload library to rubyforge
Assuming you don’t really care where your package/library is uploaded
and made available for downloading,
newjs projects comes
pre-built ready to upload them to
First, you’ll need a rubyforge account.
Second, create a rubyforge project. It can take 12-48hrs for confirmation
to come back.
Third, use the
rubyforge command-line app to
store your rubyforge project information locally.
$ rubyforge setup # first time only $ rubyforge login $ rubyforge config $ rubyforge create_package project_name project_name
rubyforge project, then the two
- The rubyforge project name (e.g. drnicutilities)
Finally, each time you want to release a new version of your library you do
- Update Rakefile’s
APP_VERSIONvalue to the new version number
rake release VERSION=X.Y.Z
Your files are now available for download via rubyforge.org.
If you use the generated website (below), it comes with a link to these
files when you click the large version number (e.g. “Get Version X.Y.Z”).
Create a website for your project
You can quickly create a clean, readable website for your project
that prominently displays the current version number (which is a
clickable link through to the download page), just like this page.
Now edit the generated
website/index.txt file (Textile format).
To convert it to HTML, run:
website/index.html in your browser to preview.
The project’s version number is automatically inserted into the page
(change version numbers via
Configuration of website upload
It is assumed you will upload your website files to rubyforge.org server.
To push files to an alternate server, modify the
To configure which rubyforge project to upload to, create
There is an example in
An example might be:
host: email@example.com remote_dir: /var/www/gforge-projects/drnicutilities/drnic_js_test_helpers
Here, the files will be uploaded into the
project, under a sub-directory
drnic_js_test_helpers. This site
would be visible at http://drnicutilities.rubyforge.org/drnic_js_test_helpers
If your website lives in its own rubyforge project, then just specify the project
name, and the website will be uploaded into the root folder.
For example, the website would be available at http://drnicutilities.rubyforge.org/ if your
host: firstname.lastname@example.org remote_dir: /var/www/gforge-projects/drnicutilities
Uploading website to server
To upload the website (and its CSS etc) run:
More commonly, to generate and upload the website:
Screencast coming soon
soon be published by PeepCode. It will cost $9
and you’ll love every minute of it.
Subscribe to PeepCode’s blog for announcement details.
Checkout this project to see examples of unit tests, configuration etc.
How to submit patches
This code is free to use under the terms of the MIT license.