1 | exports.createDirective = function(fs,directive){
|
2 | if(!fs.existsSync('./js/directive')){
|
3 | fs.mkdirSync('./js/directive');
|
4 | }
|
5 | if(!fs.existsSync('./js/directive/'+directive.name)){
|
6 | fs.mkdirSync('./js/directive/'+directive.name);
|
7 | }else{
|
8 | console.log("[ FAIL ] The factory with the name "+directive.name+" exists!\nThe creation is aborted");
|
9 | process.exit();
|
10 | }
|
11 | if(!fs.existsSync("./js/directive/"+directive.name+"/"+directive.name+".js")){
|
12 |
|
13 | fs.open("./js/directive/"+directive.name+"/"+directive.name+".js","w+",function(err,fd){
|
14 | fs.write(fd,genDirectiveCode(directive));
|
15 | })
|
16 |
|
17 | fs.open("./js/directive/"+directive.name+"/"+directive.nameCtrl+".js","w+",function(err,fd){
|
18 | fs.write(fd,"app\n.controller('"+directive.nameCtrl+"',function($scope)\n\t{\n\t})");
|
19 | })
|
20 | fs.open("./js/directive/"+directive.name+"/"+directive.name+".html","w+",function(err,fd){
|
21 | fs.write(fd,"<!-- THIS HTML FILE IS THE CONTENT OF DIRECTIVE "+directive.name+" -->\n");
|
22 | })
|
23 | }
|
24 |
|
25 |
|
26 | }
|
27 |
|
28 | exports.addDirectiveToIndex = function(fs,directive){
|
29 | var index = fs.readFileSync("./index.html",'utf8');
|
30 | var newIndex = index.replace("</body>","<script type=\"text/javascript\" src=\"js/directive/"+directive.name+"/"+directive.nameCtrl+".js\"> </script>\n\t<script type=\"text/javascript\" src=\"js/directive/"+directive.name+"/"+directive.name+".js\"> </script>\n\t</body>");
|
31 | fs.open("./index.html","w+",function(err,fd){
|
32 | fs.write(fd,newIndex);
|
33 | })
|
34 | }
|
35 |
|
36 |
|
37 |
|
38 | function genDirectiveCode(directive){
|
39 |
|
40 | var directiveJS = "'use strict';\n";
|
41 | directiveJS += "app\n";
|
42 | directiveJS += "\t.directive('"+directive.name+"', function() {\n";
|
43 | directiveJS += "\t\treturn {\n";
|
44 | directiveJS += "\t\t\trestrict: 'E',\n";
|
45 | directiveJS += "\t\t\ttransclude: true,\n";
|
46 | directiveJS += "\t\t\tscope:{\n";
|
47 | directiveJS += "\t\t\t\t//EXAMPLE: variableName:'=attrTagName'\n\n";
|
48 | directiveJS += "\t\t\t},\n";
|
49 | directiveJS += "\t\t\tcontroller:'"+directive.nameCtrl+"',\n";
|
50 | directiveJS += "\t\t\ttemplateUrl:'js/directive/"+directive.name+"/"+directive.name+".html'\n";
|
51 | directiveJS += "\t\t}\n";
|
52 | directiveJS += "\t});\n";
|
53 |
|
54 | return directiveJS;
|
55 |
|
56 | }
|