UNPKG

13.3 kBJavaScriptView Raw
1var opener = require('opener');
2var serviceManager = require('./service.js');
3var factoryManager = require('./factoryManager.js');
4var directiveManager = require('./directiveManager.js');
5/**
6
7exports.cmd = function(fs,help,settingsMan,indexGen,genBootApp,
8moduleManager,stateManager,shelljs,server,
9colors,os,httpServer,opener,argv,
10module,moduleData,config,dataConfig,states,stateData,portfinder,commandManager,http,version,readlineSync,Parallel,liveServer){**/
11exports.cmd = function(fs,help,settingsMan,indexGen,genBootApp,
12 moduleManager,stateManager,shelljs,colors,argv,module,moduleData,
13 config,dataConfig,states,stateData,commandManager,version,readlineSync,Parallel,liveServer,http,cssGen,isWeb){
14 switch(argv[0]){
15
16 case "project":{
17 if(argv[1] && !isWeb){
18 if(!fs.existsSync('./'+argv[1]+'/')){
19 fs.mkdirSync(argv[1]);
20 }else{
21 console.log("[ FAIL ] Exists the directory name, it's a possible angular app, please insert another name for the project");
22 process.exit();
23 }
24 if(!fs.existsSync(argv[1]+"/js")){
25 fs.mkdirSync(argv[1]+"/js");
26 }
27 if(!fs.existsSync(argv[1]+"/css")){
28 fs.mkdirSync(argv[1]+"/css");
29 }
30 if(!fs.existsSync(argv[1]+"/img")){
31 fs.mkdirSync(argv[1]+"/img");
32 }
33 if(!fs.existsSync(argv[1]+"/settings")){
34 fs.mkdirSync(argv[1]+"/settings");
35 }
36 if(!fs.existsSync(argv[1]+"/template")){
37 fs.mkdirSync(argv[1]+"/template");
38 }
39 console.log("[ OK ]".white+"Created all directory for the project".green.bgBlue);
40 console.log("Download angular module".grey);
41 shelljs.exec('bower install angular');
42
43 moduleData.usageName="";
44 moduleData.name="angular";
45 moduleData.path='"bower_components/angular/angular.js"';
46 moduleManager.insertNewModule(moduleData,module);
47 console.log("[ OK ]".bgGreen.white+"Added to setting module "+moduleData.name.bgBlue.green);
48
49 console.log("Download angular-ui module".grey);
50 shelljs.exec('bower install angular-ui-router');
51 var moduleDatas = {};
52 moduleDatas.usageName="'ui.router'";
53 moduleDatas.name = "angular-ui-router";
54 moduleDatas.path='"bower_components/angular-ui/build/angular-ui.js"';
55 moduleManager.insertNewModule(moduleDatas,module);
56 console.log("[ OK ]".bgGreen.white+"Added to setting module "+moduleDatas.name.bgBlue.green);
57 console.log("[ OK ]".bgGreen.white+"Finish angular-ui".green.bgBlue);
58 console.log("Adding Module".grey);
59
60 moduleManager.saveModule(fs,module,argv[1]);
61 console.log("/----Saved module----/")
62 console.log("Configuring your components");
63 shelljs.exec('mv bower_components ./'+argv[1]+'/bower_components');
64 console.log("Create the configuration for this AngularJS App".grey);
65 dataConfig.appname = argv[1];
66 dataConfig.conf = 'app.js';
67 config[config.length] = dataConfig;
68
69 var dataConfig = {};
70 dataConfig.conf = 'config.js';
71 config[config.length] = dataConfig;
72
73 var dataConfig ={};
74 dataConfig.conf = 'config.routes.js';
75
76 config[config.length] = dataConfig;
77
78 var html = indexGen.createIndexInit(argv[1]);
79 cssGen.createCSSFile(fs,config);
80 fs.open(argv[1]+'/index.html','w+',function(err,fd){
81 fs.write(fd,html);
82 indexGen.insertDependencesConf(config,argv[1],fs,settingsMan);
83 })
84 console.log("[ OK ]".bgGreen.white+"Complete your configuration");
85 var ret = settingsMan.saveSettings(fs,config);
86 genBootApp.createFileAppJS(fs,config,module);
87 genBootApp.createFileConfJS(fs,config);
88 genBootApp.createFileConfRouteJS(fs,config);
89 console.log("[ OK ]".bgGreen.white+"All file has been initializated");
90 console.log("***********FINISHED ALL!\n\n".blue);
91 console.log("Now go with the terminal into ".green+argv[1].yellow+" with: "+"cd ".yellow+argv[1].yellow+" directory and use all command you need!".green);
92 }
93 else{
94 console.log("Error you need the name of project that you want create".bgWhite.red);
95 console.log("Usage".yellow+": ng-make project nameOfProject");
96 }
97 break;
98 }
99 case "state":{
100
101 config = settingsMan.loadSettings(fs,config);
102 var nameState = argv[1];
103 if(nameState==""||nameState=="-h"||nameState=="-help"||nameState=="--h"||nameState=="--help"){
104 help.showHelpState();
105 }else{
106 if(nameState=="-h"||nameState=="--help"||nameState=="help"){
107 console.log("Usage of state keywords.\n");
108 if(isWeb){
109 console.log("state nameOfState [abstract(optional)] [default(optional)]");
110
111 }else{
112 console.log("ng-make state nameOfState [abstract] [default]");
113 }
114 console.log("You can use abstract for the name of the state that are abstract, \nalso you can use together for create a state that you can run at first page and abastract\nIf you would make a state in first view you must use default\n\n");
115 console.log("FOR MORE INFO (http://npmjs.org/packages/ng-make)")
116 }else{
117 console.log("Creating a "+argv[1]+" state");
118 var defaultState = false;
119 var isAbstract = false;
120 argv.forEach(function(val,id){
121
122 if(val=="abstract"){
123 isAbstract = true;
124 }
125 if(val=="default"){
126 defaultState = true;
127 }
128 });
129 //console.log(isAbstract);
130 if(isAbstract){
131 stateData.name=nameState;
132 stateData.url = "'/"+nameState+"'";
133 stateData.templateUrl = "'template/"+nameState+".html'";
134 stateData.controller = "'"+nameState+"CTRL'";
135 stateData.isAbstract = "true";
136 }else{
137
138 stateData.name=nameState;
139 stateData.url = "'/"+nameState+"'";
140 stateData.templateUrl = "'template/"+nameState+".html'";
141 stateData.controller = "'"+nameState+"CTRL'";
142
143 }
144 if(fs.existsSync('./js/'+argv[1]+"CTRL.js")){
145 console.log("[ FAIL ] Exists another file with the equal name of the state that you want create, please fix it!");
146 process.exit();
147 }else{
148 stateManager.createNewState(fs,stateData,config,isAbstract,defaultState);
149 console.log("[ OK ] The state has been configured");
150 var paths = "js/"+stateData.name+"CTRL.js";
151 indexGen.addingScriptDependency(config,paths,fs);
152 console.log("[ OK ] The index dipendency has been saved");
153
154 var modules = moduleManager.loadModule(fs);
155 var functionCtrl = "function($scope)\n\t{\n\t}"
156 if(modules!=false){
157 modules.forEach(function(val,id){
158 if(val.usageCtrl!=""&&val.usageCtrl!="undefined"&&val.usageCtrl){
159 functionCtrl = functionCtrl.replace("$scope","$scope,"+val.usageCtrl);
160 }
161 })
162 }
163 fs.open(paths,'w+',function(err,fd){
164 fs.write(fd,"app\n.controller('"+stateData.name+"CTRL',"+functionCtrl+")");
165 });
166 console.log("[ OK ] the "+argv[1]+" controller has been created");
167 fs.open("template/"+stateData.name+".html",'w+',function(err,fd){
168 if(isAbstract){
169 fs.write(fd,'<div ui-view>\n</div>');
170 }
171 });
172 var states;
173 states = stateManager.loadState(fs);
174 if(states){
175 states[states.length] = stateData;
176 stateManager.saveState(fs,states);
177
178 }else{
179 var sta = [{}];
180 sta[sta.length] = stateData;
181 stateManager.saveState(fs,sta);
182
183
184 }
185 console.log("[ OK ] The view has been created in template/"+stateData.name);
186 console.log("All STEPS are finished".yellow);
187 }
188 if(isWeb){
189 console.log('$ ');
190 }
191 }
192 }
193 break;
194 }
195 case "webstart":{
196 help.showWebStart();
197 isWeb=true;
198 var params = {
199 port: 9090 || argv[2],
200 host: "0.0.0.0" || argv[1],
201 root: "./" || argv[3],
202 open: true,
203 logLevel:0,
204 ignore: '',
205 wait: 0
206 };
207
208 liveServer.start(params);
209
210 //server.start(argv,process,os,httpServer,portfinder,opener);
211 console.log("\nYOU CAN USE THE COMMAND WITHOUT ng-make call\n".yellow);
212 console.log("VISIT THE WEBSITE FOR REPOSITORY(http://angelocarraggi.altervista.org/ng-make)".red);
213
214 var p = new Parallel(),
215 log = function () {
216 if(arguments[0]=="exit"){
217 process.exit();
218 }else{
219 var ar = arguments[0].split(" ");
220 commandManager.cmd(fs,help,settingsMan,indexGen,genBootApp,
221 moduleManager,stateManager,shelljs,colors,ar,module,moduleData,
222 config,dataConfig,states,stateData,commandManager,version,readlineSync,Parallel,liveServer,http,cssGen,isWeb);
223
224
225 p.spawn(doCmd).then(log)
226
227
228 }
229 };
230
231
232 function doCmd(argv) {
233
234 var readlineSync = require('readline-sync');
235
236 var command = readlineSync.question('$ ');
237 return command;
238 };
239
240 p.spawn(doCmd).then(log)
241
242
243 break;
244 }
245 case "module":{
246
247 if(help.showHelpModule(argv)==2){
248 if(argv[1]=="list"){
249
250 var moduleRepo =[{}];
251
252 moduleManager.listModuleRepo(http,moduleRepo,commandManager);
253
254 }
255 if(argv[1]=="install"){
256 var moduleRepo =[{}];
257 var namePackage = argv[2];
258 var states = stateManager.loadState(fs);
259 moduleManager.installModule(moduleManager,http,fs,config,indexGen,moduleRepo,namePackage,shelljs,cssGen,states,stateManager);
260
261
262 }
263 if(argv[1]=="list-installed"){
264 moduleManager.listInstalled(moduleManager,fs);
265 }
266 //console.log(!(argv[1]=="list")&&!(argv[1]=="install")&&!(argv[1]=="list-installed"));
267 if(!(argv[1]=="list")&&!(argv[1]=="install")&&!(argv[1]=="list-installed")){
268 module = moduleManager.loadModule(fs,config);
269 moduleData = {};
270 moduleData.name = argv[1];
271 moduleData.usageName=""+argv[1]+"";
272 moduleData.usageCtrl = ""+argv[1]+"";
273 moduleData.path="js/"+argv[1]+".js";
274 module[module.length] = moduleData;
275 moduleManager.addModule(moduleData,config,fs,indexGen);
276 moduleManager.saveNewModule(fs,module);
277 var states = stateManager.loadState(fs);
278 if(states==false){
279
280 }else{
281 if(moduleData.usageCtrl!=""){
282 stateManager.updateControllerFile(moduleData.usageCtrl,fs,states);
283 }
284 }
285 }
286
287
288 }
289 if(isWeb){
290 console.log('$ ');
291 }
292 console.log("VISIT THE WEBSITE FOR REPOSITORY(http://angelocarraggi.altervista.org/ng-make)".red);
293
294 break;
295 }
296 case "using":{
297
298 /*if(help.showHelpUsing()==2){
299 var moduleRepo =[{}];
300
301 //moduleManager.listModuleRepo(http,moduleRepo,commandManager);
302 moduleManager.getListRepo(http,moduleRepo);
303
304 }*/
305
306 }
307 case "create":{
308 if(argv[1]=="module"||argv[1]=="state"||argv[1]=="service"||argv[1]=="factory"){
309 opener('http://www.angelocarraggi.altervista.org/ng-make');
310 console.log("Sorry, for create a new "+argv[1]+" you must go on the web site");
311 }else{
312 console.log("error");
313 }
314 }
315 case "service":{
316
317
318 config = settingsMan.loadSettings(fs,config);
319 if(argv[1]=="help"||argv[1]=="-help"||argv[1]=="--h"|| argv[1]=="-h"){
320 help.showServiceHelp(isWeb);
321 }else{
322 console.log("Creating a "+argv[1]+" service");
323 var serviceName = argv[1];
324 var err = serviceManager.createService(fs,serviceName,config);
325 if(err!=1){
326 serviceManager.addServiceToIndex(fs,serviceName);
327 serviceManager.addServiceToAppJS(fs,serviceName);
328 console.log("[ OK ] Service has been created");
329 }
330
331 }
332 break;
333 }
334 case "factory":{
335 config = settingsMan.loadSettings(fs,config);
336 if(argv[1]=="help"||argv[1]=="-help"||argv[1]=="--h"|| argv[1]=="-h"){
337 help.showFactoryHelp(isWeb);
338
339 }else{
340 console.log("Creating new "+argv[1]+" factory...");
341 var factoryName = argv[1];
342 var err = factoryManager.createFactory(fs,factoryName,config);
343 if(err!=1){
344 factoryManager.addFactoryToIndex(fs,factoryName);
345 factoryManager.addFactoryToAppJS(fs,factoryName);
346
347 console.log("[ OK ] All done! Factory has been created");
348 }
349
350 }
351 break;
352 }
353 case "directive":{
354
355
356 //config = settingsMan.loadSettings(fs,config);
357 if(argv[1]=="help"||argv[1]=="-help"||argv[1]=="--h"|| argv[1]=="-h"){
358 help.showDirectiveHelp(isWeb);
359 }else{
360 console.log("Creating a "+argv[1]+" directive");
361 var directive = {};
362 directive.name = argv[1];
363 directive.nameCtrl = argv[1]+"CTRLDirective";
364 directiveManager.createDirective(fs,directive);
365
366 directiveManager.addDirectiveToIndex(fs,directive);
367 console.log("[ OK ] Directive has been created");
368
369
370 }
371 break;
372 }
373 default :{
374 help.showGeneralHelp(argv,version);
375 if(isWeb){
376 console.log('$ ');
377 }
378 console.log("VISIT THE WEBSITE FOR REPOSITORY(http://angelocarraggi.altervista.org/ng-make)".red);
379
380 }
381
382 }
383
384 }
385
386exports.printModulesRepository = function(moduleRepo){
387 console.log("The list of repository available are:".grey);
388 moduleRepo.forEach(function(val,id){
389
390 console.log(val.name+"-> "+val.description);
391
392
393 })
394 }
\No newline at end of file