forked from postcss/postcss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCakefile
114 lines (92 loc) · 3.16 KB
/
Cakefile
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
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 'integration', 'Test parser/stringifier on real CSS', ->
invoke('clean')
print = (text) ->
process.stdout.write(text)
error = (text) ->
process.stderr.write("\n\n" + text + "\n")
process.exit(1)
https = require('https')
http = require('http')
get = (url, callback) ->
protocol = if url.match(/^https/) then https else http
protocol.get url, (res) ->
data = ''
res.on 'data', (chunk) -> data += chunk
res.on 'end', -> callback(data)
postcss = require(__dirname + '/lib/postcss')
test = (css) ->
try
processed = postcss.parse(css).toString()
catch e
fs.writeFileSync(__dirname + '/fail.css', css)
error("Parsing error: #{ e.message }\nBad file was saved to fail.css")
if processed != css
fs.writeFileSync(__dirname + '/origin.css', css)
fs.writeFileSync(__dirname + '/fail.css', processed)
error("Wrong stringifing\n" +
"Check difference between origin.css and fail.css")
links = []
nextLink = ->
if links.length == 0
print("\n")
nextSite()
return
get links.shift(), (css) ->
test(css)
print('.')
nextLink()
sites = [{ name: 'GitHub', url: 'https://github.com/' }
{ name: 'Twitter', url: 'https://twitter.com/' }
{ name: 'Habrahabr', url: 'http://habrahabr.ru/' }
{ name: 'Bootstrap', url: 'http://getbootstrap.com/' }]
nextSite = ->
return if sites.length == 0
site = sites.shift()
print('Test ' + site.name + ' styles')
get site.url, (html) ->
links = html.match(/[^"]+\.css/g).map (i) -> i.replace(/^\.?\//, site.url)
nextLink()
nextSite()
task 'clean', 'Remove all temporary files', ->
fs.removeSync(__dirname + '/build')
fs.removeSync(__dirname + '/fail.css')
fs.removeSync(__dirname + '/origin.css')
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
fs.copy(sourcePath, buildPath)
compile()
task 'publish', 'Publish new version to npm', ->
invoke('compile')
build = __dirname + '/build/'
sh "npm publish #{build}", ->
fs.removeSync(build)