@@ -12,6 +12,7 @@ class GenerateCommand extends DependencyLicenseCommand
12
12
* @var bool
13
13
*/
14
14
private $ hideVersion = false ;
15
+ private $ toCsv = false ;
15
16
16
17
/**
17
18
* Configure the command options.
@@ -23,7 +24,8 @@ protected function configure()
23
24
$ this
24
25
->setName ('generate ' )
25
26
->setDescription ('Generate Licenses file from project dependencies. ' )
26
- ->addOption ('hide-version ' , 'hv ' , InputOption::VALUE_NONE , 'Hide dependency version ' );
27
+ ->addOption ('hide-version ' , 'hv ' , InputOption::VALUE_NONE , 'Hide dependency version ' )
28
+ ->addOption ('csv ' , null , InputOption::VALUE_NONE , 'Output csv format ' );
27
29
}
28
30
29
31
/**
@@ -37,11 +39,17 @@ protected function configure()
37
39
protected function execute (InputInterface $ input , OutputInterface $ output )
38
40
{
39
41
$ this ->hideVersion = $ input ->getOption ('hide-version ' );
42
+ $ this ->toCsv = $ input ->getOption ('csv ' );
40
43
$ dependencies = $ this ->getDependencyList ();
41
44
42
45
$ output ->writeln ('<info>Generating Licenses file...</info> ' );
43
- $ this ->generateLicensesText ( $ dependencies );
46
+ if ( $ this ->toCsv ) {
44
47
48
+ $ this ->generateLicensesCSV ($ dependencies );
49
+ } else {
50
+
51
+ $ this ->generateLicensesText ($ dependencies );
52
+ }
45
53
$ output ->writeln ('<info>Done!</info> ' );
46
54
47
55
return 0 ;
@@ -65,6 +73,24 @@ protected function generateLicensesText($dependencies)
65
73
file_put_contents ('licenses.md ' , $ text );
66
74
}
67
75
76
+ protected function generateLicensesCSV ($ dependencies )
77
+ {
78
+ $ fp = fopen ('licenses.csv ' , 'w ' );
79
+ $ title = ['name ' , 'version ' , 'source ' , 'license description ' ];
80
+
81
+ fputcsv ($ fp , $ title );
82
+ foreach ($ dependencies as $ dependency ) {
83
+ $ dependencyLists = [
84
+ $ dependency ['name ' ],
85
+ $ this ->hideVersion ? '' : $ dependency ['version ' ],
86
+ $ dependency ['source ' ]['url ' ],
87
+ $ this ->getTextForDependency ($ dependency )
88
+ ];
89
+ fputcsv ($ fp , $ dependencyLists );
90
+ }
91
+ fclose ($ fp );
92
+ }
93
+
68
94
/**
69
95
* Returns Boilerplate text for the Licences File.
70
96
*
@@ -108,11 +134,11 @@ protected function getTextForDependency($dependency)
108
134
*/
109
135
protected function getFullLicenseText ($ name )
110
136
{
111
- $ path = getcwd (). "/vendor/ $ name/ " ;
137
+ $ path = getcwd () . "/vendor/ $ name/ " ;
112
138
$ filenames = ['LICENSE.txt ' , 'LICENSE.md ' , 'LICENSE ' , 'license.txt ' , 'license.md ' , 'license ' , 'LICENSE-2.0.txt ' ];
113
139
114
140
foreach ($ filenames as $ filename ) {
115
- $ text = @file_get_contents ($ path. $ filename );
141
+ $ text = @file_get_contents ($ path . $ filename );
116
142
if ($ text ) {
117
143
return $ text ;
118
144
}
@@ -136,7 +162,7 @@ protected function getFullLicenseText($name)
136
162
*/
137
163
protected function generateDependencyText ($ name , $ description , $ version , $ homepage , $ sha , $ licenseNames , $ license )
138
164
{
139
- return "### $ name " . ($ this ->hideVersion ? '' : "(Version $ version | $ sha) " ). "
165
+ return "### $ name " . ($ this ->hideVersion ? '' : "(Version $ version | $ sha) " ) . "
140
166
$ description
141
167
Homepage: $ homepage
142
168
Licenses Used: $ licenseNames
0 commit comments