-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.xml
190 lines (167 loc) · 6.14 KB
/
build.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?xml version="1.0" encoding="UTF-8"?>
<project name="hCaptcha Extension Builder" description="Builds an extension.zip from a git repository" default="all">
<property name="env" value="production" />
<property name="vendor-name" value="alfredoramos" />
<property name="extension-name" value="hcaptcha" />
<!--
Only set this to "true" if you have dependencies in the composer.json,
otherwise use "false".
-->
<property name="has-dependencies" value="false" />
<!--
Remove some unnecessary files/directories
${dir}/ is the folder of your extension
example: ext/${vendor-name}/${extension-name}/
-->
<target name="clean-package">
<echo msg="Cleaning files and directories" />
<delete dir="${dir}/scss" />
<delete dir="${dir}/tests" />
<delete dir="${dir}/node_modules" />
<delete dir="${dir}/.github"/>
<delete dir="${dir}/.vscode"/>
<delete file="${dir}/.gitignore" />
<delete file="${dir}/.gitattributes" />
<delete file="${dir}/.editorconfig" />
<delete file="${dir}/.stylelintrc.json" />
<delete file="${dir}/.tool-versions" />
<delete file="${dir}/build.xml" />
<delete file="${dir}/crowdin.yml" />
<delete file="${dir}/phpunit.xml.dist" />
<delete file="${dir}/README.md" />
<delete file="${dir}/package.json" />
<delete file="${dir}/package-lock.json" />
<delete file="${dir}/postcss.config.js" />
<if>
<and>
<equals arg1="${env}" arg2="production" />
<isset property="exclude-langs" />
</and>
<then>
<phingcall target="clean-langs" />
</then>
</if>
</target>
<!-- DO NOT EDIT BELOW THIS LINE -->
<property name="version" value="HEAD" override="true" />
<property name="build-directory" value="build" override="true" />
<property name="package-directory" value="${build-directory}/package/${vendor-name}/${extension-name}" />
<!-- Remove incomplete translations. -->
<property name="exclude-langs" value="nl" override="true" />
<!-- These are the main targets which you will probably want to use -->
<target name="all" depends="prepare-structure,package" />
<!-- Remove incomplete language pack -->
<target name="remove-lang">
<if>
<and>
<not>
<isfalse value="${lang}" />
</not>
<not>
<equals arg1="${lang}" arg2="en" />
</not>
</and>
<then>
<delete dir="${package-directory}/language/${lang}" />
</then>
</if>
</target>
<!-- Replace invalid characters in language files -->
<target name="clean-lang">
<echo msg="Replacing invalid characters: ${filename}" />
<exec dir="${package-directory}/language" command="sed -ri 's|'\\\\\''|’|g' ${filename}" checkreturn="true" />
</target>
<!-- Clean up the language directory -->
<target name="clean-langs">
<if>
<not>
<isfalse value="${exclude-langs}" />
</not>
<then>
<echo msg="Deleting incomplete languages" />
<foreach list="${exclude-langs}" param="lang" target="remove-lang" />
</then>
</if>
<foreach param="filename" target="clean-lang">
<fileset dir="${package-directory}/language">
<patternset>
<include name="**/*.php" />
</patternset>
</fileset>
</foreach>
</target>
<!-- Clean up the build directory -->
<target name="clean">
<delete dir="${build-directory}" />
</target>
<!-- Minify CSS and JS assets -->
<target name="minify-assets">
<echo msg="Minifying assets" />
<exec command="npm run build" checkreturn="true" />
</target>
<!-- Recreate the necessary folders -->
<target name="prepare-structure" depends="clean">
<mkdir dir="${build-directory}" />
<mkdir dir="${build-directory}/checkout" />
<mkdir dir="${build-directory}/package" />
<mkdir dir="${build-directory}/package/${vendor-name}" />
<mkdir dir="${build-directory}/package/${vendor-name}/${extension-name}" />
<mkdir dir="${build-directory}/upload" />
</target>
<!-- The real packaging -->
<target name="package">
<echo msg="Extracting ${version}" />
<phingcall target="git-checkout">
<property name="archive-version" value="${version}" />
</phingcall>
<if>
<equals arg1="${has-dependencies}" arg2="1" />
<then>
<echo msg="Installing dependencies" />
<exec dir="${package-directory}" command="composer install --prefer-dist --no-dev" checkreturn="true" />
</then>
</if>
<phingcall target="clean-package">
<property name="dir" value="${package-directory}" />
</phingcall>
<!-- Try setting the package version property from composer.json -->
<exec dir="${package-directory}"
command='php -r "\$j = json_decode(file_get_contents(\"composer.json\")); echo (isset(\$j->version) ? \$j->version : \"${version}\");"'
checkreturn="true"
outputProperty='package-version' />
<!-- Build and ninify assets -->
<if>
<equals arg1="${env}" arg2="production" />
<then>
<phingcall target="minify-assets">
<property name="dir" value="${package-directory}" />
</phingcall>
</then>
</if>
<phingcall target="wrap-package">
<property name="destination-filename" value="${build-directory}/upload/${vendor-name}_${extension-name}_${package-version}" />
</phingcall>
</target>
<!-- Checkout a given version and install/clean the dependencies -->
<target name="git-checkout">
<echo msg="Getting archive for ${archive-version}" />
<exec command="git archive ${archive-version} --format zip --output ${build-directory}/checkout/${archive-version}.zip"
checkreturn="true" />
<unzip file="${build-directory}/checkout/${archive-version}.zip" todir="${package-directory}" />
</target>
<!-- Create the zip and tar ball -->
<target name="wrap-package">
<echo msg="Creating archives (${vendor-name}/${extension-name} ${version})" />
<zip basedir="${build-directory}/package/" destfile="${destination-filename}.zip" />
<tar basedir="${build-directory}/package/" destfile="${destination-filename}.tar.gz" compression="gzip" />
<tar basedir="${build-directory}/package/" destfile="${destination-filename}.tar.bz2" compression="bzip2" />
<echo msg="Generating checksums" />
<manifest checksum="sha512" file="${build-directory}/upload/checksums.sha512">
<fileset dir="${build-directory}/upload/">
<include name="*.zip" />
<include name="*.tar.gz" />
<include name="*.tar.bz2" />
</fileset>
</manifest>
</target>
</project>