Skip to content

Commit

Permalink
new install is possible for specific files/folders
Browse files Browse the repository at this point in the history
  • Loading branch information
Pinhook committed Mar 29, 2011
1 parent 5df5805 commit e075f14
Show file tree
Hide file tree
Showing 6 changed files with 253 additions and 18 deletions.
13 changes: 13 additions & 0 deletions generate/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,19 @@ steal("//steal/generate/ejs", '//steal/generate/inflector', '//steal/rhino/promp
.replace(regs.dash, '_').toLowerCase();
},
//converts a name to a bunch of useful things

/**
* @hide
* FooBar.ZedTed ->
* {
* appName : "foobar",
* className : "ZedTed",
* fullName : "FooBar.ZedTed",
* name : "FooBar.ZedTed",
* path : foo_bar,
* underscore : "zed_ted"
* }
*/
convert: function( name ) {
var className = name.match(/[^\.]*$/)[0]; //Customer
var appName = name.split(".")[0]; //Customer
Expand Down
54 changes: 54 additions & 0 deletions get/dummysteal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// a dummy version of steal that can run on a file and extract data from it ...
steal(function(s){
var makeFunc = function(name){
return function(){
for(var i =0; i < arguments.length; i++){
this["_"+name].push(arguments[i])
}

return this;
}
}

s.dummy = function(code){
var args = [];
var dummy = function(){
args.push(arguments);
}

for(var prop in s){
if(typeof s[prop] == 'function'){
dummy["_"+prop] = []
dummy[prop] = makeFunc(prop);
}else {
dummy[prop] = {};
}
}
//additional funcs (for 3.0)
var funcs = ['plugins','views','models','controllers','css','less'];
for(var i =0; i < funcs.length; i++){
var prop = funcs[i];

dummy["_"+prop] = []
dummy[prop] = makeFunc(prop);
}

//save current steal
var curSteal = steal;
//replace ...

steal = dummy;

eval(code)

steal = curSteal;
for(var prop in dummy){
if(prop.substr(0,1) === "_"){
dummy[prop.substr(1)] = dummy[prop];
}
}
return dummy;
}


})()
126 changes: 118 additions & 8 deletions get/get.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
steal("//steal/get/json", "//steal/rhino/prompt", function( steal ) {
steal("//steal/get/json",
"//steal/rhino/prompt",
"//steal/get/dummysteal",function( steal ) {

// a map of plugins that you just installed (prevents cycles)
var installed = {};

/**
* @parent stealjs
* Downloads and installs a plugin from a url. Normally this is run from the steal/getjs script.
Expand Down Expand Up @@ -65,13 +71,24 @@ steal("//steal/get/json", "//steal/rhino/prompt", function( steal ) {
if (!name ) {
name = guessName(url);
}
//print("getting name "+name+" "+url);

//make the folder for this plugin
new steal.File(name).mkdirs();

// do old dependency thing ...

steal.print(" Checking dependencies ... ");
dependenciesUrl = getter.dependenciesUrl(url);

installDependencies(dependenciesUrl, name);

// do new dependency thing ...
var stealDependsUrl = getter.pluginDependenciesUrl(url);
if(stealDependsUrl){
get.installDependencies( get.pluginDependencies(stealDependsUrl) )
}
steal.print(" ");

//get contents
var fetcher = new getter(url, name, options);
fetcher.quiet = options.quiet || true;
Expand All @@ -81,14 +98,14 @@ steal("//steal/get/json", "//steal/rhino/prompt", function( steal ) {
steal.print("\n " + name + " plugin downloaded.");
runInstallScript(name);

}),
}),
/**
* @hide
* looks for a url elsewhere
* @param {Object} name
*/
pluginList = function( name ) {
steal.print(" Looking for plugin ...");
//steal.print(" Looking for plugin ...");

var plugin_list_source =
readUrl("https://github.com/jupiterjs/steal/raw/master/get/gets.json");
Expand All @@ -97,6 +114,23 @@ steal("//steal/get/json", "//steal/rhino/prompt", function( steal ) {
if ( plugin_list[name] ) {
return plugin_list[name];
}
// check if the first part matches ....
var parts = name.split("/")
firstPart = parts.shift();
if(plugin_list[firstPart]){
var first = plugin_list[firstPart];
if(/github\.com/.test(first) && !/tree\/\w+/.test(first)){
// http://github.com/jupiterjs/mxui ->
// http://github.com/jupiterjs/mxui/tree/master/util/selectable/
return first+"/tree/master/"+parts.join("/")+"/"
//first = first.replace(/[^\/]+$/g, function(end){
//
//})
}
return first;
}


steal.print(" Looking in gets.json for your own plugin list")

plugin_list_source = readFile("gets.json");
Expand All @@ -117,15 +151,15 @@ steal("//steal/get/json", "//steal/rhino/prompt", function( steal ) {
// works for
// https://github.com/jupiterjs/funcunit/raw/master/dependencies.json
installDependencies = function( depend_url, name ) {
steal.print(" Checking dependencies ...");

var depend_text, dependencies;

try {
depend_text = readUrl(depend_url);
} catch (e) {}

if (!depend_text ) {
steal.print(" No dependancies");
//steal.print(" No dependancies");
return;
}

Expand All @@ -145,7 +179,7 @@ steal("//steal/get/json", "//steal/rhino/prompt", function( steal ) {
}
}

steal.print(" Installed all dependencies for " + name);
//steal.print(" Installed all dependencies for " + name);
},
runInstallScript = function( name ) {
if ( readFile(name + "/install.js") ) {
Expand All @@ -158,5 +192,81 @@ steal("//steal/get/json", "//steal/rhino/prompt", function( steal ) {
}
};


steal.extend(get,{
pluginList: pluginList,
pluginDependencies : function(url){
//steal.print(" Checking plugin file ..."+url);
var script, dependencies;

try {
script = readUrl(url);
} catch (e) {
steal.print("No plugin file");
return;
}
if(/steal/.test(script)){
try{
var stealCalls = steal.dummy(script)
} catch(e){
//steal.print("Unable to figure out plugins. Are you using steal in an unusual way?");
//return;
}
}
// get non-jquery plugins and see if they want to install ...
var plugins = []
for(var i = 0; i < stealCalls.plugins.length; i++){
var plugin = stealCalls.plugins[i];
if(!/^jquery\/|steal/.test(plugin) ){
plugins.push(stealCalls.plugins[i])
}
}
//create a temp steal to run this app ...




if (!plugins.length ) {
//steal.print(" No dependancies");
return;
}
//print("length", plugins.length)
return plugins;
},
installDependencies : function(dependencies){
if(dependencies){
//first we need to make sure the folder doesn't exist locally ...
for(var i =0; i < dependencies.length; i++){
get.installDependency(dependencies[i]);
}
}

},
installDependency : function(depend){
if(installed[depend]){
return;
}
if(steal.File(depend).exists()){
installed[depend] = true;
if ( steal.prompt.yesno("Update dependency " + depend + "? (yN):") ) {
steal.print("Updating " + depend + "...");
steal.get(depend, {
name: depend
});
}

return false;
}else{

if ( steal.prompt.yesno("Install dependency " + depend + "? (yN):") ) {
installed[depend] = true;
steal.print("Installing " + depend + "...");
steal.get(depend, {
name: depend
});
}

return true;
}
}
})
}, "//steal/get/getter", "//steal/get/github");
29 changes: 20 additions & 9 deletions get/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,34 @@
*/

steal(function( steal ) {

// helpers ...
var addHttps = function(url){
return !/^https/.test(url) ? url.replace(/http/i, 'https') : url;
},
lastPart = function(url){
return (url.substr(url.length-1) === "/" ? url.substr(0, url.length-1) : url).match(/[^\/]+$/)[0]
};

steal.get.github = function( url, where, options, level ) {
if ( url ) {
this.init.apply(this, arguments);
}
};

steal.get.github.dependenciesUrl = function( url ) {
if(!/https/.test(url)) { // github requires https
url = url.replace(/http/, 'https');
}
var depUrl = url +
(url.lastIndexOf("/") === url.length - 1 ? "" : "/") +
"raw/master/dependencies.json";
return depUrl;
url = addHttps(url);
return steal.File(url).join("raw/master/dependencies.json");
};

//
steal.get.github.pluginDependenciesUrl = function(url){
//http://github.com/jupiterjs/mxui/tree/master/util/selectable/ ->
//https://github.com/jupiterjs/mxui/raw/master/util/selectable/selectable.js
var pluginName = lastPart( url );
if(url.indexOf('tree') == -1){
return null;
}
return steal.File(addHttps(url)).join(pluginName + ".js").replace("/tree/","/raw/");
}
steal.get.github.prototype = new steal.get.getter();
steal.extend(steal.get.github.prototype, {
init: function( url, where, options, level ) {
Expand Down
39 changes: 38 additions & 1 deletion get/test/get_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,45 @@ steal('//steal/get/get',function(rhinoSteal){


_S.module("steal/get")
STEALPRINT = false;
// STEALPRINT = false;

_S.test("pluginList", function(t){
var url = rhinoSteal.get.pluginList("mxui/util/selectable");

t.equals(url, "http://github.com/jupiterjs/mxui/tree/master/util/selectable/", "Right url")
});

_S.test("pluginUrl", function(t){
var url = rhinoSteal.get.github.pluginDependenciesUrl("http://github.com/jupiterjs/mxui/tree/master/util/selectable/");
t.equals(url, "https://github.com/jupiterjs/mxui/raw/master/util/selectable/selectable.js", "Right url");

var url = rhinoSteal.get.github.pluginDependenciesUrl("http://github.com/jupiterjs/mxui/");
t.equals(url, null, "Nothing if repo form");

})

_S.test("dummySteal", function(t){
var code = readFile('steal/get/test/stealCode1.js');
var results = rhinoSteal.dummy(code);
t.equals(results.plugins[0], "foo/bar", "first is right");
t.equals(results.plugins.length, 4, "has other plugins")
});

_S.test("pluginDependencies", function(t){
var depends = rhinoSteal.get.pluginDependencies("https://github.com/jupiterjs/mxui/raw/master/data/grid/grid.js");

t.equals(depends[0], "mxui/layout/fill", "first is right");
t.equals(depends.length, 2, "has other plugins")
});

_S.test("installDependency", function(t){
rhinoSteal.File("jqueryui").removeDir();
//t.equals( rhinoSteal.get.installDependency("jquery/controller") , false, "exists" );
t.equals( rhinoSteal.get.installDependency("jqueryui/draggable") , true, "doesn't exist" );


})
return;
_S.test("root repo" , function(t){

rhinoSteal.get('ss/router',{});
Expand Down
10 changes: 10 additions & 0 deletions get/test/stealCode1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
steal.plugins("foo/bar",
/**
* Comment
* @param {Object} "something/else"
*/
"abc/def").then(function(){

}).plugins("something/else");

steal.plugins("one/two");

0 comments on commit e075f14

Please sign in to comment.