package org.codingmatters.value.objects.php;

import org.codingmatters.value.objects.php.generator.SpecPhpGenerator;
import org.codingmatters.value.objects.php.generator.SpecReaderPhp;
import org.codingmatters.value.objects.spec.Spec;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class MainClass {

    static private Spec loadSpec( String resource ) {
        try {
            return new SpecReaderPhp().read( new FileInputStream( resource ) );
        } catch( Exception e ) {
            throw new RuntimeException( "error loading spec", e );
        }
    }

    public static void main( String[] args ) throws IOException {

        String rootPath = System.getProperty( "generationTargetDir", "" );
        if( rootPath.equals( "" ) ) {
            System.out.println( "Generation target dir property not found" );
            System.exit( 1 );
        }
        System.out.println( "Generating in " + rootPath );

//        Spec spec = loadSpec( "books.yaml" );
//        new SpecCodeGenerator( spec, "org.generated", new File( rootPath ) ).generate();


        for( File file : new File( rootPath ).listFiles() ) {
            if( file.getName().endsWith( "yaml" ) ) {
                Spec spec = loadSpec( rootPath + "/" + file.getName() );
                new SpecPhpGenerator( spec, "org.generated", new File( rootPath ) ).generate();
            }
        }

//        Spec spec = loadSpec( "books.yaml" );

    }

}

@@ -668,17 +668,16 @@
 ption %7B%0A
-%0A
         
@@ -963,149 +963,8 @@
 );%0A%0A
-//        Spec spec = loadSpec( %22books.yaml%22 );%0A//        new SpecCodeGenerator( spec, %22org.generated%22, new File( rootPath ) ).generate();%0A%0A%0A
     
@@ -1250,32 +1250,32 @@
 ;%0A            %7D%0A
+
         %7D%0A%0A//   
@@ -1272,58 +1272,8 @@
   %7D%0A
-%0A//        Spec spec = loadSpec( %22books.yaml%22 );%0A%0A
     

remove dead code