1
+ <?php
2
+
3
+ define (TWEAK , true );
4
+ define (CLEAN , true );
5
+ define (INPUT_FILE , 'src/plugins.json ' );
6
+ define (OUTPUT_DIR , 'build ' );
7
+
8
+ array_shift ($ argv ); //pom.php
9
+ if (!($ input_file = array_shift ($ argv ))) {
10
+ $ input_file = INPUT_FILE ;
11
+ }
12
+ if (!($ output_dir = array_shift ($ argv )) || !is_dir ($ output_dir )) {
13
+ $ output_dir = OUTPUT_DIR ;
14
+ }
15
+
16
+ print "\nCompiling POM from $ input_file to $ output_dir \n\n" ;
17
+
18
+ try {
19
+ $ input = json_decode (file_get_contents ($ input_file ), true );
20
+ $ plugins = $ input ['plugins ' ];
21
+ } catch (Exception $ e ) {
22
+ print "Could not read or parse $ input_file as a JSON list of plugins " ;
23
+ exit ();
24
+ }
25
+
26
+ if (TWEAK ) {
27
+ tweak ($ plugins );
28
+ }
29
+
30
+ if (CLEAN ) {
31
+ @rmdir ($ output_dir );
32
+ }
33
+ @mkdir ($ output_dir );
34
+
35
+ foreach (compilePhp ($ plugins ) as $ filename =>$ php ) {
36
+ $ filename = $ output_dir . DIRECTORY_SEPARATOR . $ filename ;
37
+ file_put_contents ($ filename , $ php );
38
+ include_once ($ filename );
39
+ print "Wrote & tested $ filename \n" ;
40
+ }
41
+
42
+ exit ();
43
+
44
+ // -----------
45
+
46
+ function tweak ($ plugins ) {
47
+ foreach ($ plugins as $ index =>$ plugin ) {
48
+ $ params = $ plugin ['params ' ];
49
+ foreach ($ params as $ param =>$ config ) {
50
+ foreach ($ config as $ field =>$ value ) {
51
+ switch ($ field ) {
52
+ case 'description ' :
53
+ if (substr ($ value , -1 ) != '. ' ) {
54
+ $ plugins [$ index ] .= ". " ;
55
+ }
56
+ break ;
57
+ default :
58
+ break ;
59
+ }
60
+ $ config [$ field ] = $ value ;
61
+ }
62
+ $ params [$ param ] = $ config ;
63
+ }
64
+ $ plugins [$ index ] = $ plugin ;
65
+ }
66
+ }
67
+
68
+ function compilePhp ($ plugins ) {
69
+ $ compiled = array (
70
+ 'base.php ' =>
71
+ array (
72
+ 'class FBP_Base { ' ,
73
+ '} '
74
+ )
75
+ );
76
+ foreach ($ plugins as $ index =>$ plugin ) {
77
+ $ filename = str_replace (' ' , '' , strtolower ($ plugin ['name ' ])) . '.php ' ;
78
+ $ php = array ("// Autogenerated at " . gmdate ('Y-m-d H:i:s ' ) . " GMT " );
79
+
80
+ $ class = str_replace (' ' , '_ ' , ucwords ($ plugin ['name ' ]));
81
+ $ php [] = "include_once('base.php'); " ;
82
+ $ php [] = "class FBP_ $ class extends FBP_Base { " ;
83
+ $ php [] = "} " ;
84
+ $ compiled [$ filename ] = $ php ;
85
+ }
86
+ foreach ($ compiled as $ filename =>$ php ) {
87
+ array_unshift ($ php , '<?php ' );
88
+ array_push ($ php , '?> ' );
89
+ $ compiled [$ filename ] = implode ("\n" , $ php );
90
+ }
91
+ return $ compiled ;
92
+ }
93
+
94
+ ?>
0 commit comments