<project name="com.ibm.wala.cast.js.nodejs" default="download-core-libs" basedir=".">
	<description>
		WALA Nodejs Front-end
	</description>
	<property name="nodejs-release" location="nodejs.zip" />
	<property name="core-modules" location="dat/core-modules" />

        <target name="core-libs-present">
        <available file="${core-modules}/_debugger.js" property="corelibs.present"/>
     </target>

	<target name="download-core-libs" depends="core-libs-present" unless="corelibs.present">
		<!-- 0a604e92e258c5ee2752d763e50721e35053f135 is v0.12.4-release -->
		<get src="https://api.github.com/repos/nodejs/node/zipball/0a604e92e258c5ee2752d763e50721e35053f135"
				dest="${nodejs-release}" />
		
		<tempfile property="unzip-dest" />
		
		<unzip src="${nodejs-release}"
				dest="${unzip-dest}">
			
			<patternset>
				<include name="*/lib/**" />
			</patternset>
		</unzip>
		
		<mkdir dir="${core-modules}" />
		
		<move todir="${core-modules}"
				flatten="true">
			
			<fileset dir="${unzip-dest}">
				<include name="*/lib/*.js" />
			</fileset>
		</move>
		
		<!-- Cleanup -->
		<delete includeemptydirs="true">
			<fileset dir="${unzip-dest}" includes="**" />
			<fileset file="${nodejs-release}" />
		</delete>
	</target>
</project>
