-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
110 lines (93 loc) · 3.09 KB
/
build.gradle
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
import com.eriwen.gradle.js.tasks.MinifyJsTask
import de.undercouch.gradle.tasks.download.Download
import org.apache.tools.ant.taskdefs.condition.Os
plugins {
id "com.eriwen.gradle.js" version "2.14.1"
id "de.undercouch.download" version "3.2.0"
}
ext.PHANTOM_JS_ARCHIVE_EXT = ".zip"
ext.PHANTOM_JS_BINARY_NAME = "phantomjs"
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
ext.PHANTOM_JS_PLATFORM = "windows"
ext.PHANTOM_JS_BINARY_NAME += ".exe"
} else if (Os.isFamily(Os.FAMILY_MAC)) {
ext.PHANTOM_JS_PLATFORM = "macosx"
} else if (Os.isFamily(Os.FAMILY_UNIX)) {
ext.PHANTOM_JS_PLATFORM = "linux"
if (System.properties["os.arch"] == "amd64") {
ext.PHANTOM_JS_PLATFORM += "-x86_64"
} else {
ext.PHANTOM_JS_PLATFORM += "-i686"
}
ext.PHANTOM_JS_ARCHIVE_EXT = ".tar.bz2"
} else {
throw new GradleException("Unsupported OS")
}
ext.PHANTOM_JS_VERSION = "2.1.1"
ext.PHANTOM_JS_FILENAME = "phantomjs-" + PHANTOM_JS_VERSION + "-" + PHANTOM_JS_PLATFORM
ext.PHANTOM_JS_BINARIES_DIR = "phantomjs-binaries"
ext.PHANTOM_JS_BINARIES_UNPACKED_DIR = PHANTOM_JS_BINARIES_DIR + "/unpacked"
javascript.source {
custom {
js {
srcDir projectDir
include "src/main/js/*.js"
}
}
}
javascript.source.custom.js.each { File file ->
tasks.create(name: "dominifyJs_${file.name}", type: MinifyJsTask) {
source = file
dest = "${buildDir}/minifiedJs/${file.name}"
closure {
compilationLevel = "SIMPLE_OPTIMIZATIONS"
warningLevel = "QUIET"
}
}
}
task cleanBuildDir {
new File("${buildDir}").deleteDir()
}
task downloadPhantomJs(type: Download) {
def phantomJsZipFileName = PHANTOM_JS_FILENAME + PHANTOM_JS_ARCHIVE_EXT
def fullPath = PHANTOM_JS_BINARIES_DIR + "/" + phantomJsZipFileName
src "https://bitbucket.org/ariya/phantomjs/downloads/" + phantomJsZipFileName
dest PHANTOM_JS_BINARIES_DIR + "/" + phantomJsZipFileName
if (new File(fullPath).exists()) {
logger.warn "PhantomJS archive already exists."
overwrite false
}
}
task unzipPhantomJs(type: Copy) {
if (downloadPhantomJs.dest) {
from zipTree(downloadPhantomJs.dest)
into PHANTOM_JS_BINARIES_UNPACKED_DIR
}
}
task copyPhantomJs(type: Copy) {
from "${PHANTOM_JS_BINARIES_UNPACKED_DIR}/${PHANTOM_JS_FILENAME}/bin"
into buildDir
include PHANTOM_JS_BINARY_NAME
}
task copyDependencies(type: Copy) {
from "${projectDir}/dep"
into "${buildDir}/dep"
include "*.js"
}
task processJs(dependsOn: tasks.matching { Task task -> task.name.startsWith("dominifyJs") })
task zip(type: Zip) {
from("${buildDir}/minifiedJs") {
include("*.js")
}
from(PHANTOM_JS_BINARIES_UNPACKED_DIR + "/" + PHANTOM_JS_FILENAME + "/bin") {
include(PHANTOM_JS_BINARY_NAME)
}
destinationDir buildDir
archiveName "bank-web-scraper.zip"
}
downloadPhantomJs.dependsOn cleanBuildDir
unzipPhantomJs.dependsOn downloadPhantomJs
processJs.dependsOn unzipPhantomJs
copyPhantomJs.dependsOn processJs
copyDependencies.dependsOn copyPhantomJs
zip.dependsOn copyDependencies