Skip to content

Commit

Permalink
Integrated Rake for the build system. Updated define.js after running…
Browse files Browse the repository at this point in the history
… through jslint. Grabbed the latest version of amdjs-tests.
  • Loading branch information
Darren Schnare committed Mar 10, 2012
1 parent 21e0656 commit 8b128f3
Show file tree
Hide file tree
Showing 241 changed files with 16,451 additions and 338 deletions.
3 changes: 3 additions & 0 deletions Gemfile
@@ -0,0 +1,3 @@
source :rubygems

gem 'sinatra', '1.3.2'
17 changes: 17 additions & 0 deletions Gemfile.lock
@@ -0,0 +1,17 @@
GEM
remote: http://rubygems.org/
specs:
rack (1.4.1)
rack-protection (1.2.0)
rack
sinatra (1.3.2)
rack (~> 1.3, >= 1.3.6)
rack-protection (~> 1.2)
tilt (~> 1.3, >= 1.3.3)
tilt (1.3.3)

PLATFORMS
x86-mingw32

DEPENDENCIES
sinatra (= 1.3.2)
7 changes: 7 additions & 0 deletions License
@@ -0,0 +1,7 @@
Copyright (c) 2012 Darren Schnare

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1 change: 1 addition & 0 deletions Procfile
@@ -0,0 +1 @@
web: bundle exec ruby -Cweb app.rb -p $PORT
118 changes: 73 additions & 45 deletions README.markdown → README.md
@@ -1,44 +1,4 @@
> Author: Darren Schnare
> Keywords: javascript,amd,browser,pure,lightweight
> License: MIT ( http://www.opensource.org/licenses/mit-license.php )
> Repo: https://github.com/dschnare/definejs

Definejs
====================


Installation
--------------------

The `src/define.js` file is the source file with inline commenting, and the `bin/define.min.js` file is the minified obsfucated source file.

To install, simply download one of the files above and include them via a `<script>` element.

The [wiki](https://github.com/dschnare/definejs/wiki) contains several pages on the usage and API.

**NOTICE:** Like [RequireJS](http://requirejs.org/docs/api.html#define), definejs modules must map 1-to-1 to a file. The only exception is when writing modules in an embedded `<script>`
on the page that includes definejs.

Browser Support
--------------------

The following browsers have been tested:

- IE 6/7/8/9 and IE10 testdrive
- Chrome 15+
- FF 3+
- Safari 5.1
- Opera 10+

This list will be frequently updated as testing ensues.


Overview
--------------------
# Overview

This implemtation of the [AMD sepcification](https://github.com/amdjs/amdjs-api/wiki/AMD) is solely targeted
at web browsers and only web browsers. The sole purpose of this project is to provide a no-frills, pure-to-spec,
Expand All @@ -57,10 +17,14 @@ plugins are focused on. Definejs manages modules well. Definejs is not a resourc
Also by not poluting the AMD loader with plugin "plumbing" code we effectively reduce the surface area of the loader in general, making
it easier to maintain, test and debug.

However, others are welcome to take definejs as a base and integrate plugin support into their own "build".
However, others are welcome to take definejs as a base and integrate plugin support into their own build.

define.amd property
--------------------
The [wiki](https://github.com/dschnare/definejs/wiki) contains several pages on the usage and API.

**NOTICE:** Like [RequireJS](http://requirejs.org/docs/api.html#define), definejs modules must map 1-to-1 to a file. The only exception is when writing modules in an embedded `<script>` on the page that includes definejs.


# define.amd property

{
plugins: false, // no plugin support
Expand All @@ -73,4 +37,68 @@ define.amd property
}

The `defaultDeps` property is defined to make developers aware that definejs does not set `["require", "exports", "module"]` as
default dependencies when no dependencies are specified.
default dependencies when no dependencies are specified.


# Organization

This project is organized into the following partitions/abstractions.

- src

This directory contains all the JavaScript source code for definejs and several AMD modules.

- min

This directory contains the minified versions of each module and definejs produced from Rake.

- vendor

This directory contains all the required third party binaries and source code.

The following third party dependencies exist:

- AjaxMin.exe (used to minify the JavaScript source -- Requires Windows)
- jslint.js (used to test the JavaScript source)
- rhino.jar (used to execute jslint.js)

- web

This directory is a web project that tests definejs using the [amdjs-tests](https://github.com/amdjs/amdjs-tests) suite.

# Building

Ruby Rake is used to build minify and move around the minified code to the appropriate directories.
Use `rake -D` to list all the rake tasks. The `Rakefile` is commented quite well so you can read
this file to understand how the build process.


# Testing

Any web server can be used to serve up the testing project, but for convenience a Sinatra web app
has been written to get testing quickly.

To get started with the built-in Sinatra app run (requires [Bundler](http://gembundler.com/) and [Foreman](https://github.com/ddollar/foreman)):

Mac/Linux/Unix:

bundle install
foreman start

Windows (does not require Foreman)

bundle install
bundle exec ruby -Cweb app.rb -p 5000

Once the web server is running then simply point your browser to the [amdjs-tests](http://localhost:5000/amdjs-tests/tests/doh/runner.html?config=definejs/config.js&impl=definejs/define.js) and hit the play button. To kill the web server press `Ctr+C`.


# Support

The following list of environments will be updated as testing ensues:

- IE 6/7/8/9 and IE10 testdrive
- Chrome 15+
- Firefox 3+
- Safari 5+
- Opera 10+
102 changes: 102 additions & 0 deletions Rakefile
@@ -0,0 +1,102 @@
#!/usr/bin/ruby
#coding: utf-8

##########
# CONFIG #
##########

ENCODING = Encoding::UTF_8

SRC_DIR = 'src'
MIN_DIR = 'min'
WEB_SCRIPTS_DIR = File.join('web', 'public', 'scripts')

SRC_GLOB = File.join(SRC_DIR, '**', '*.js')
MIN_GLOB = File.join(MIN_DIR, '**', '*.js')

RHINOJAR = File.join('vendor', 'rhino.jar')
JSLINT_PATH = File.join('vendor', 'jslint.js')

# Define our minify method. Change this if you want to minify using something of your choice.
def minify (*input, output)
Kernel.system("vendor/ajaxmin.exe -js -global:define,window -clobber:true #{input.join(' ')} -out #{output}")
end

desc "Minifies all AMD modules in '#{SRC_DIR}' and copies the minified versions of each module to 'web/public/scripts'. A copy of '#{SRC_DIR}/define.js' is also copied to 'web/public/amdjs-tests/impl/definejs'."
task :default

# Make sure we have a min directory.
directory MIN_DIR


##############
# SYNTHESIZE #
##############

=begin
Here we synthesize a file task for each source JavaScript file. This file task
will minify the source file and save the minified version to JS_OUT_DIR.
Finally this block adds each newly created file task as a dependency to the 'default' task.
=end
FileList[SRC_GLOB].each do |src|
path = File.dirname(src)
extname = File.extname(src)
filename = File.basename(src, extname)
js_minified_file = File.join(MIN_DIR, "#{filename}#{extname}")

file js_minified_file => src do |t|
minify(src, t.name)
end
end

=begin
Creates a task that copies all files from the srcGlob to a destination.
Usage:
create_copy_task 'articles/*.gif', 'articles', :articles
Reference:
http://martinfowler.com/articles/rake.html
=end
def create_copy_task srcGlob, targetDir, taskSymbol
mkdir_p(targetDir, :verbose => false)
FileList[srcGlob].each do |f|
target = File.join(targetDir, File.basename(f))
file target => [f] do |t|
cp f, target
end
task taskSymbol => target
end
end


#########
# TASKS #
#########

# Create the task to copy all our unminified source files.
create_copy_task(MIN_GLOB, 'web/public/scripts', :scripts)
# Copy the source define.js to the appropriate directory in amdjs-tests.
create_copy_task(File.join(MIN_DIR, 'define.js'), 'web/public/amdjs-tests/impl/definejs', :scripts)

# Add all file tasks to the default task.
Rake.application.tasks.each do |t|
if t.kind_of? Rake::FileTask
task :default => [t.name]
end
end

desc "Check JavaScript source in the '#{SRC_DIR}' with JSLint - exit with status 1 if a file fails."
task :jslint do |t, args|
FileList["#{SRC_DIR}/**/*.js"].exclude("**/_*.js").each do |fname|
cmd = "java -cp #{RHINOJAR} org.mozilla.javascript.tools.shell.Main #{JSLINT_PATH} #{fname}"
results = %x{#{cmd}}

unless results.length == 0
puts "#{fname}:"
puts results
exit 1
end
end
end
8 changes: 0 additions & 8 deletions bin/define.min.js

This file was deleted.

7 changes: 0 additions & 7 deletions min.bat

This file was deleted.

1 change: 1 addition & 0 deletions min/browser.js
@@ -0,0 +1 @@
define("browser",{window:window,document:document,navigator:window.navigator,console:window.console||{}})
1 change: 1 addition & 0 deletions min/config.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8b128f3

Please sign in to comment.