FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
frontend/project/SbtGruntPlugin.scala at events · devhttps/frontend · GitHub
devhttps
/
frontend
Public
forked from
guardian/frontend
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
frontend
/
project
/
SbtGruntPlugin.scala
Copy path
More file actions
More file actions
Latest commit
History
History
History
84 lines (66 loc) · 2.14 KB
Breadcrumbs
frontend
/
project
/
SbtGruntPlugin.scala
Copy path
File metadata and controls
84 lines (66 loc) · 2.14 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
io
.
Source
import
java
.
io
.
FileWriter
import
sbt
.
_
import
Keys
.
_
object
SbtGruntPlugin
extends
Plugin
{
val
dateStampCache
:
File
=
{
val
t
=
IO
.createTemporaryDirectory
t.mkdirs()
t.mkdir()
t
}
private
def
runGrunt
(
task
:
String
)
=
{
val
cmd
=
"
grunt
"
+
task
cmd
!
}
//
Grunt command
def
gruntCommand
=
{
Command
.single(
"
grunt
"
) { (
state
:
State
,
task
:
String
)
=>
runGrunt(task)
state
}
}
//
Grunt task
def
gruntTask
(
taskName
:
String
)
=
streams map { (
s
:
TaskStreams
)
=>
val
retval
=
runGrunt(taskName)
if
(retval
!=
0
) {
throw
new
Exception
(
"
Grunt task %s failed
"
.format(taskName))
}
}
def
gruntTask
(
taskName
:
String
,
filesToCheck
:
SettingKey
[
PathFinder
])
=
(streams, filesToCheck) map { (
s
:
TaskStreams
,
finder
:
PathFinder
)
=>
val
lastUpdated
=
dateStampCache
/
taskName
if
(
!
lastUpdated.exists()) {
lastUpdated.createNewFile()
writeCacheFile(lastUpdated,
0
,
0
)
}
val
(lastSize, lastUpdateTime)
=
readLastCache(lastUpdated)
val
files
=
finder.get
val
newestSource
=
if
(files.isEmpty)
Long
.
MaxValue
else
files.map(_.lastModified).max
val
newestSize
=
files.size
if
(lastSize
!=
newestSize
||
lastUpdateTime
<
newestSource) {
val
retval
=
runGrunt(taskName)
if
(retval
!=
0
) {
throw
new
Exception
(
"
Grunt task %s failed
"
.format(taskName))
}
writeCacheFile(lastUpdated, newestSize, newestSource)
}
else
{
s.log.debug(
"
No need to run grunt task:
"
+
taskName)
}
}
//
Expose plugin
override
lazy
val
settings
=
Seq
(
commands
+=
gruntCommand,
clean
~=
{ unit
=>
dateStampCache.listFiles.foreach(_.delete()) }
)
private
def
readLastCache
(
lastUpdated
:
File
)
:
(
Long
,
Long
)
=
{
val
fileLines
=
Source
.fromFile(lastUpdated).getLines.toSeq.take(
2
)
val
lastSize
=
fileLines(
0
).toLong
val
lastUpdateTime
=
fileLines(
1
).toLong
(lastSize, lastUpdateTime)
}
private
def
writeCacheFile
(
lastUpdated
:
File
,
newestSize
:
Int
,
newestSource
:
Long
) {
val
writer
=
new
FileWriter
(lastUpdated)
writer.write(newestSize
+
"
\n
"
+
newestSource)
writer.close()
}
}
Back
|
FazBrowse Home
|
New Git URL