Skip to content

Commit

Permalink
Initial commit v0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl committed May 27, 2014
0 parents commit b7cd349
Show file tree
Hide file tree
Showing 61 changed files with 5,756 additions and 0 deletions.
76 changes: 76 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
'use strict';
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
meta: {
banner: '/*\n * <%= pkg.name %> v<%= pkg.version %>\n' +
'<%= pkg.homepage ? " * " + pkg.homepage + "\\n" : "" %>' +
' * \n' +
' * Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %>\n */'
},
concat: {
dist: {
src: [
'bower_components/es6-module-loader/dist/es6-module-loader.js',
'bower_components/systemjs/dist/system.js',
'src/start.js',
'src/normalize.js',
'src/core.js',
'src/normalize.js',
'src/config.js',
'src/startup.js',
'src/system-format-steal.js',
'src/end.js'
],
dest: '<%= pkg.name %>.js'
},
systemFormat: {
src: [
'src/system-format-start.js',
'src/normalize.js',
'src/system-format-steal.js',
'src/system-format-end.js'
],
dest: 'system-format-steal.js'
}
},
uglify: {
options: {
banner: '<%= meta.banner %>\n',
compress: {
drop_console: true
}
},
dist: {
options: {
banner: '<%= meta.banner %>\n'
+ '/*\n * ES6 Promises shim from when.js, Copyright (c) 2010-2014 Brian Cavalier, John Hann, MIT License\n */\n'
},
src: '<%= pkg.name %>.js',
dest: '<%= pkg.name %>.production.js'
}
},
copy: {
toTest: {
files: [{expand: true, src: ['<%= pkg.name %>.js','<%= pkg.name %>.production.js'], dest: 'test/', filter: 'isFile'},
{expand: true, src: ['<%= pkg.name %>.js','<%= pkg.name %>.production.js'], dest: 'test/steal/', filter: 'isFile'},
{expand: true, src: ['<%= pkg.name %>.js','<%= pkg.name %>.production.js'], dest: 'test/bower_components/steal/', filter: 'isFile'},
{expand: true, cwd: 'bower_components/traceur/', src: ['*'], dest: 'test/bower_components/traceur/', filter: 'isFile'},
{expand: true, cwd: 'dev/', src: ['**'], dest: 'test/bower_components/steal/dev/', filter: 'isFile'}]
}
},
watch: {
files: [ "src/*.js","bower_components/systemjs/dist/**"],
tasks: "default"
}
});

grunt.loadNpmTasks( "grunt-contrib-watch" );
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.registerTask('lint', ['jshint']);
grunt.registerTask('default', [/*'jshint', */'concat', 'uglify','copy:toTest']);
};
139 changes: 139 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
StealJS is an ES6, AMD, CommonJS, and steal client-side loader. Combined with
[steal-tools](https://github.com/bitovi/steal-tools/tree/systemjs), its designed
to simplify dependency management while being extremely powerful and flexible.

Steal builds from [SystemJS](https://github.com/systemjs/systemjs) and
[ES6ModuleLoader](https://github.com/ModuleLoader/es6-module-loader) and adds:

- global configuration
- css and less support
- plugin extension mapping _(upcoming)_
- production builds with [steal-tools](https://github.com/bitovi/steal-tools/tree/systemjs)

But its __killer__ feature - progressively loaded apps that balance caching and the
number of script requests.

StealJS supports IE8+ with AMD, CommonJS, and Steal syntax and IE9+ for ES6 syntax.

## Use

### Hello World Example

Lets see how to get a basic app up and running.

1. Install StealJS:

With [Bower](http://bower.io/)

> bower install steal#0.1.1 -S
2. Create `stealconfig.js`:

Add a `stealconfig.js` file directly within your "root" folder. Your
"root" folder should contain all your static scripts and resources.

By default, steal will assume `stealconfig.js` is a sibling of `bower_components`:

ROOT/
bower.json
bower_components
stealconfig.js

`stealconfig.js` will be loaded by every page in your project. It is used to configure
the location to modules and other behavior.

3. Add `main` module:

Add a `main.js` to your project. This will load your apps other modules.

ROOT/
bower.json
bower_components
stealconfig.js
main.js
Within `main.js` add:

```js
console.log("hello world");
```

4. Create an HTML page:

Create an `index.html` page that specifies the location of `stealconfig.js` and
the `main` module name:

ROOT/
bower.json
bower_components
stealconfig.js
index.html

Within `index.html` add:

```html
<!DOCTYPE html>
<html>
<body>
<script src='./bower_components/steal/steal.js'
data-config='stealconfig.js'
data-main='main'></script>
</body>
</html>
```

To build this app, read [StealTools](https://github.com/bitovi/steal-tools/tree/systemjs) docs.


### Adding jQuery

1. Install jQuery:

With [Bower](http://bower.io/)

> bower install jquery -S
2. Configure jQuery's path and export:

Add a `System.paths` config to `stealconfig.js` to tell steal where to find
jQuery. Add a `System.meta` config to tell SystemJS that jQuery exports the "jQuery"
variable.

```js
System.paths = {jquery: 'bower_components/jquery/dist/jquery.js'};
System.meta = {jquery: { exports: "jQuery" } };
```

3. Load jQuery.

Import "jquery" with ES6 module syntax in `main.js`:

```js
import $ from "jquery";
$(document.body).append("<h1>Hello World!</h1>");
```


## Developing

After cloning ...

1. Install npm modules

> npm install
2. Install bower modules

> bower install
3. Setup grunt watch

> grunt watch
This will automatically build when anything in `src` change.

To test, open:

test/test.html
And make sure everything passes.
15 changes: 15 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "stealjs",
"main": "steal.js",
"ignore": ["test","src","core"],
"version": "0.1.1",
"devDependencies": {
"qunit": "~1.12.0",
"systemjs" : "git://github.com/bitovi/systemjs.git#4eb43a4bf0e2df9bb6e161415bdbb9e22ca12387",
"es6-module-loader": "git://github.com/ModuleLoader/es6-module-loader.git#7a4c870b4b7ee21338fd249e836b151676f79194",
"less": "1.7.0"
},
"dependencies": {
"traceur": "0.0.32"
}
}
48 changes: 48 additions & 0 deletions css.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
if( steal.config('env') === 'production' ) {
exports.fetch = function(load) {
// return a thenable for fetching (as per specification)
// alternatively return new Promise(function(resolve, reject) { ... })
var cssFile = load.address;

var link = document.createElement('link');
link.rel = 'stylesheet';
link.href = cssFile;

document.head.appendChild(link);
return "";
};
} else {
exports.instantiate = function(load) {

return {
deps: [],
execute: function(){
if(load.source) {
var head = document.head || document.getElementsByTagName('head')[0],
style = document.createElement('style'),
source = load.source+"/*# sourceURL="+load.address+" */";

// make source load relative to the current page
source = source.replace(/url\(['"]?([^'"\)]*)['"]?\)/g, function( whole, part ) {
return "url(" + steal.joinURIs( load.address, part) + ")";
});
style.type = 'text/css';

if (style.styleSheet){
style.styleSheet.cssText = source;
} else {
style.appendChild(document.createTextNode(source));
}
head.appendChild(style);
}

return new System.global.Module({});
}
};
};
}



exports.buildType = "css";
exports.includeInBuild = true;
113 changes: 113 additions & 0 deletions dev/dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*global window: false, console: true, opera: true */
//
/**
* @property steal.dev
* @parent stealjs
*
* Provides helper functions for development that get removed when put in production mode.
* This means you can leave <code>steal.dev.log("hello world")</code> in your code and it
* will get removed in prodution.
*
* ## Examples
*
* steal.dev.log("Something is happening");
* steal.dev.warn("Something bad is happening");
*
*/
(function(){
var dev = {
regexps: {
colons: /::/,
words: /([A-Z]+)([A-Z][a-z])/g,
lowerUpper: /([a-z\d])([A-Z])/g,
dash: /([a-z\d])([A-Z])/g
},
underscore: function( s ) {
var regs = this.regexps;
return s.replace(regs.colons, '/').
replace(regs.words, '$1_$2').
replace(regs.lowerUpper, '$1_$2').
replace(regs.dash, '_').toLowerCase();
},
isHappyName: function( name ) {
//make sure names are close to the current path
var path = steal.cur().path.replace(/\.[^$]+$/, "").split('/'),
//make sure parts in name match
parts = name.split('.');

for ( var i = 0; i < parts.length && path.length; i++ ) {
if (path[i] && parts[i].toLowerCase() != path[i] && this.underscore(parts[i]) != path[i] && this.underscore(parts[i]) != path[i].replace(/_controller/, "") ) {
this.warn("Are you sure " + name + " belongs in " + steal.cur().path);
}
}


},

logLevel : 0,
/**
* @function steal.dev.warn
* @parent steal.dev
*
* @signature `steal.dev.warn(out)`
* @param {String} out the message
*
* @body
* Adds a warning message to the console.
*
* steal.dev.warn("something evil");
*
*/
warn: function( out ) {
var ll = steal.config().logLevel;
if(ll < 2){
Array.prototype.unshift.call(arguments, 'steal.js WARN:');
if ( window.console && console.warn ) {
this._logger( "warn", Array.prototype.slice.call(arguments) );
} else if ( window.console && console.log ) {
this._logger( "log", Array.prototype.slice.call(arguments) );
} else if ( window.opera && window.opera.postError ) {
opera.postError("steal.js WARNING: " + out);
}
}

},
/**
* @function steal.dev.log
* @parent steal.dev
*
* @signature `steal.dev.log(out)`
* @param {String} out the message
*
* @body
* Adds a message to the console.
*
* steal.dev.log("hi");
*
*/
log: function( out ) {
var ll = steal.config().logLevel;
if (ll < 1) {
if (window.console && console.log) {
Array.prototype.unshift.call(arguments, 'steal.js INFO:');
this._logger( "log", Array.prototype.slice.call(arguments) );
}
else if (window.opera && window.opera.postError) {
opera.postError("steal.js INFO: " + out);
}
}
},
_logger:function(type, arr){
if(console.log.apply){
console[type].apply(console, arr)
} else {
console[type](arr)
}
}
};
if(typeof steal !== "undefined") {
steal.dev= dev;
} else {
module.exports = dev;
}
})();
Loading

0 comments on commit b7cd349

Please sign in to comment.