forked from postcss/autoprefixer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCakefile
More file actions
151 lines (120 loc) · 4.17 KB
/
Cakefile
File metadata and controls
151 lines (120 loc) · 4.17 KB
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
fs = require('fs-extra')
sh = (cmd, callback) ->
require('child_process').exec cmd, (error, stdout, stderr) ->
process.stderr.write(stderr)
process.exit(1) if error
callback()
task 'clean', 'Remove all temporary files', ->
fs.removeSync(__dirname + '/build')
fs.removeSync(__dirname + '/autoprefixer.js')
task 'compile', 'Compile CoffeeScript to JS', ->
invoke('clean')
coffee = require('coffee-script')
build = __dirname + '/build'
fs.removeSync(build)
fs.mkdirSync(build)
ignore = fs.readFileSync(__dirname + '/.npmignore').toString().split("\n")
ignore = ignore.concat(['.git', '.npmignore'])
compileCoffee = (path) ->
source = fs.readFileSync(path).toString()
coffee.compile(source)
compile = (dir = '/') ->
path = __dirname + dir + '/'
for name in fs.readdirSync(__dirname + dir)
continue if ignore.some (i) -> i == name
path = dir + name
sourcePath = __dirname + path
buildPath = build + path
if fs.statSync(sourcePath).isDirectory()
fs.mkdirSync(buildPath)
compile(path + '/')
else if name[-7..-1] == '.coffee'
compiled = compileCoffee(sourcePath)
jsPath = buildPath.replace(/\.coffee$/, '.js')
fs.writeFileSync(jsPath, compiled)
else if path == '/bin/autoprefixer'
compiled = compileCoffee(sourcePath)
compiled = "#!/usr/bin/env node\n" + compiled
fs.writeFileSync(buildPath, compiled)
fs.chmodSync(buildPath, '775')
else
fs.copy(sourcePath, buildPath)
compile()
task 'publish', 'Publish new version to npm', ->
invoke('compile', /binary.coffee/)
build = __dirname + '/build/'
sh "npm publish #{build}", ->
fs.removeSync(build)
task 'build', 'Build standalone autoprefixer.js', ->
invoke('compile')
browserify = require('browserify')
builder = browserify(basedir: __dirname + '/build/')
builder.add('./lib/autoprefixer.js')
result = __dirname + '/autoprefixer.js'
output = fs.createWriteStream(result)
builder.bundle standalone: 'autoprefixer', (error, build) ->
if error
process.stderr.write(error.toString() + "\n")
process.exit(1)
fs.removeSync(__dirname + '/build/')
rails = __dirname + '/../autoprefixer-rails/vendor/autoprefixer.js'
fs.writeFile(result, build)
fs.writeFile(rails, build) if fs.existsSync(rails)
task 'bench', 'Benchmark on GitHub styles', ->
invoke('compile')
print = (text) -> process.stdout.write(text)
https = require('https')
get = (url, callback) ->
https.get url, (res) ->
data = ''
res.on 'data', (chunk) -> data += chunk
res.on 'end', -> callback(data)
capitalize = (text) ->
text[0].toUpperCase() + text[1..-1]
loadGithubStyles = (callback) ->
print("Load GitHub styles")
get 'https://github.com', (html) ->
link = html.match(/[^"]+\.css/g)[0]
get link, (css) ->
print("\n")
require('coffee-script/register')
autoprefixer = require(__dirname + '/lib/autoprefixer')
cleaner = autoprefixer('none')
callback(cleaner.process(css).css)
indent = (max, current) ->
diff = max.toString().length - current.toString().length
for i in [0...diff]
print(' ')
loadGithubStyles (css) ->
times = { }
tests = fs.readdirSync(__dirname + '/benchmark').filter (file) ->
file.match(/\.coffee$/)
result = (code, time) ->
print(time + " ms")
if times.autoprefixer
slower = time / times.autoprefixer
print(" (#{ slower.toFixed(1) } times slower)")
times[code] = time
print("\n")
tick = ->
if tests.length == 0
fs.removeSync(__dirname + '/build/')
return
file = tests.shift()
code = file.replace('.coffee', '')
name = capitalize code
print(name + ': ')
indent('Autoprefixer', name)
test = require('./benchmark/' + file)
test.prepare(css)
start = new Date()
test.run ->
test.run ->
test.run ->
test.run ->
test.run ->
end = new Date()
result code, Math.round((end - start) / 5)
test.clean()
tick()
tick()