Conditions | 8 |
Paths | 14 |
Total Lines | 83 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | var program = require('commander'); |
||
14 | .action(function(enviroment) { |
||
15 | |||
16 | shell.mkdir('-p',['applications/assets/icons']); |
||
17 | |||
18 | shell.echo('Build Server Vagrant ('+enviroment+')'); |
||
19 | |||
20 | if ( enviroment === 'dev' ){ |
||
21 | |||
22 | var vagrantId = shell.exec("vagrant global-status | grep d1b0server | awk '{ print $1}'", {silent:true}); |
||
23 | |||
24 | var vagrantCode; |
||
25 | if ( vagrantId.code !== 0 ){ |
||
26 | //ERRORE |
||
27 | process.stderr.write(chalk.red("Errore: "+vagrantId.stderr+ " - "+vagrantId.output)); |
||
28 | process.exit(1); |
||
|
|||
29 | } else { |
||
30 | vagrantCode = vagrantId.output.trim(); |
||
31 | } |
||
32 | |||
33 | if ( !vagrantCode ) { |
||
34 | process.stdout.write(chalk.bold.cyan("Vagrant server not found")+"\n"); |
||
35 | |||
36 | shell.exec('./scripts/generatekey.sh'); |
||
37 | shell.exec('./scripts/generateSSL.sh'); |
||
38 | shell.exec('./scripts/roles_update.sh'); |
||
39 | |||
40 | shell.cd('server/'); |
||
41 | |||
42 | var upVagrant = shell.exec("vagrant up", {silent:true}); |
||
43 | if ( upVagrant.code !== 0 ){ |
||
44 | //ERRORE |
||
45 | process.stderr.write(chalk.red("Errore: "+upVagrant.stderr+ " - "+upVagrant.output)); |
||
46 | process.exit(1); |
||
47 | } |
||
48 | |||
49 | process.stdout.write("Vagrant server UP.\n"); |
||
50 | |||
51 | shell.echo('Install Server Required Package and Config'); |
||
52 | var ansibleProc = shell.exec('ansible-playbook -i '+enviroment+'.hosts site.yml'); |
||
53 | if ( ansibleProc.code !== 0 ){ |
||
54 | //ERRORE |
||
55 | process.stderr.write(chalk.red("Errore ... ")); |
||
56 | process.exit(1); |
||
57 | } |
||
58 | |||
59 | process.stdout.write("Vagrant server installation packages completed.\n"); |
||
60 | |||
61 | shell.cd('..'); |
||
62 | |||
63 | } else { |
||
64 | process.stdout.write("Find vagrant server: "+vagrantCode+". Skip creation.\n"); |
||
65 | // non funziona vagrant up by name or uuid |
||
66 | // var upVagrant = shell.exec("vagrant up "+vagrantCode); |
||
67 | |||
68 | shell.cd('server/'); |
||
69 | |||
70 | var upVagrant = shell.exec("vagrant up", {silent:true}); |
||
71 | if ( upVagrant.code !== 0 ){ |
||
72 | //ERRORE |
||
73 | process.stderr.write(chalk.red("Errore: "+upVagrant.stderr+ " - "+upVagrant.output)); |
||
74 | process.exit(1); |
||
75 | } |
||
76 | |||
77 | process.stdout.write("Vagrant server UP.\n"); |
||
78 | |||
79 | shell.cd('..'); |
||
80 | } |
||
81 | |||
82 | } else { |
||
83 | |||
84 | shell.echo('Install Server Required Package and Config'); |
||
85 | var ansibleProc = shell.exec('ansible-playbook -i '+enviroment+'.hosts site.yml', {silent:true}); |
||
86 | if ( ansibleProc.code !== 0 ){ |
||
87 | //ERRORE |
||
88 | process.stderr.write(chalk.red("Errore ... ")); |
||
89 | process.exit(1); |
||
90 | } |
||
91 | |||
92 | shell.echo('Completed'); |
||
93 | |||
94 | } |
||
95 | |||
96 | }) |
||
97 | .parse(process.argv); |
||
109 |