Permalink
Browse files

first commit

  • Loading branch information...
mparaiso
mparaiso committed May 21, 2012
0 parents commit a551861a96f3926d59fa05069f2e21d3ccc75096
Showing with 167 additions and 0 deletions.
  1. +162 −0 backbone-shell.js
  2. +5 −0 readme.md
@@ -0,0 +1,162 @@
+/**
+ * crée un dossier au nom du projet
+ * crée les sous dossiers js , css , images et datas
+ * crée un fichier index.html ,README.md , favicon
+ * récupère les libraires tel que jquery,underscore,backbone
+ * crée le html nécessaire
+ */
+
+var args,fs,options,base_path,request,help,js_scripts,getScript,
+getScriptCallback,writeToIndex,log,path,_;
+
+// @NOTE @NODE creer un repertoire : fs.mkdir("repertoire")
+// @NOTE @NODE changer de dossier : process.chdir("dossier")
+// @NOTE @NODE afficher le dossier actuel : process.cwd()
+
+// VARIABLES
+options =
+{
+ "base_path":"backbone-project",
+ "index_file_name":"index.html",
+ "readme":"backbone application generated by backbnoe-shell",
+ "index_header":"<!DOCTYPE hmtl><html><head>",
+ "index_footer":"</head></body><h1>Backbone project</h1></body></html>",
+ "files":{
+ "css":[
+ {
+ "reset.css" : "https://raw.github.com/theandym/reset_css/master/reset.css"
+ }
+ ],
+ "js":[
+ {
+ "jquery.min.js":"http://code.jquery.com/jquery-1.7.2.min.js"
+ },
+
+ {
+ "underscore.min.js":"https://raw.github.com/documentcloud/underscore/master/underscore-min.js"
+ },
+
+ {
+ "backbone.min.js":"https://raw.github.com/documentcloud/backbone/master/backbone-min.js"
+ }]
+ }
+
+}
+_ = require("underscore");
+fs = require("fs");
+request = require("request");
+path = require("path");
+console.log("BACKBONE SHELL\nby M.PARAISO");
+//@NODE @NOTE obternir le premier argument passé à la commande
+base_path = process.argv[2] || options.base_path;
+verbose = true
+help = process.argv.indexOf("-h")>0?true:false;
+if(help){
+ console.log("create boiler-plate code for a backbone application");
+ console.log("USAGE : backbone-shell [options] [projectname]");
+ console.log("OPTIONS : ");
+ console.log("-h : help");
+ process.exit();
+}
+js_scripts = options.files.js ;
+
+
+log = log || function(message){
+ this.verbose = verbose ;
+ if(this.verbose){
+ console.log(message);
+ }
+}
+
+getScript = function(scripts,directory,callback,result){
+ var i ,current_script,current_script_key;
+ if(scripts.length<=0){
+ return callback(result,directory);
+ }else{
+ result = result || {};
+ current_script = scripts.shift();
+ //@NOTE @NODE obtenir la clef d'une paire clef valeur;
+ for(i in current_script){
+ current_script_key = i
+ }
+ request(current_script[current_script_key],function(error,response,body){
+ if(!error){
+ result[current_script_key] = body ;
+ log("getting "+current_script_key+" from "+current_script[current_script_key]+" ...");
+ return getScript(scripts,directory,callback,result);
+ }else{
+ return console.log(error);
+ }
+ });
+ return void 0;
+ }
+};
+
+getScriptCallback = function(scripts,directory){
+ result = [];
+ for(var i in scripts){
+ var file_path = path.join(directory,i);
+ log("creating "+path.join(file_path)+" ...");
+ fs.writeFileSync(file_path,scripts[i]);
+ result.push(file_path);
+ }
+}
+
+writeToIndex=function(index,files){
+ var extension,i,key;
+ for(file in files){
+ for(i in files[file]){
+
+ }
+ extension = files[file][i].match(/(?:\.)([\w]+)$/i) || [];
+
+ switch(extension[0]){
+ case".js":
+ index+="<script type='text/javascript' src='js/"+i+"'></script>";
+ break;
+ case".css":
+ index+="<link rel='stylesheet' media='all' href='css/"+i+"'/>";
+ break;
+ }
+ }
+
+ return index;
+};
+
+main = function(){
+ try{
+ var i,_options,index='';
+ _options = JSON.parse(JSON.stringify(options));
+ _options2 = JSON.parse(JSON.stringify(options));
+ log("creating "+path.join(base_path)+" ...");
+ fs.mkdir(base_path);
+ for( i in _options.files){
+
+ log("creating "+path.join(base_path,i)+" ...");
+ fs.mkdir(path.join(base_path,i));
+ getScript(_options.files[i],path.join(base_path,i),getScriptCallback);
+ }
+ for(i in _options2.files){
+ index+=writeToIndex(index,_options2.files[i]);
+ }
+ index = options.index_header+index+options.index_footer;
+ log("creating "+path.join(base_path,options.index_file_name+" ..."));
+ fs.writeFileSync(path.join(base_path,options.index_file_name),index);
+ fs.writeFileSync(path.join(base_path,"README.md"),options["readme"]);
+
+ }catch(e){
+ throw e;
+ }finally{
+
+ }
+}
+//@NOTE @NODE detecter la fin du programme;
+process.once('exit', function(code) {
+ code = code || 0;
+ console.log('!DONE');
+ process.exit(code);
+});
+
+
+
+main();
@@ -0,0 +1,5 @@
+#BACKBONE SHELL
+## by M.PARAISO
+###creates boiler-plate code for a backbone application !
+### include jquery , underscore and backbone.
+###USAGE : backbone-shell [options] [projectname]

0 comments on commit a551861

Please sign in to comment.