forked from seaweedchan/OneeChan
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Cakefile
33 lines (28 loc) · 1.26 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
{log} = console
{exec} = require 'child_process'
fs = require 'fs'
STYLE = 'style.css'
SCRIPT = 'OneeChan.user.js'
CHANGELOG = 'CHANGELOG'
option '-o', '--output [DIR]', 'Specify output location.'
task 'build', (options) ->
OUTPUT = options.output || SCRIPT
css = fs.readFileSync STYLE, 'utf8'
css = css.replace /(\/\*[^\*]+\*\/|\t|\r|\n|\s{4})/g, ''
css = css.replace /;}/g, '}'
css = css.replace /\s(\+|\?|:|(?:!|=)==)(?:\s|\n)/g, '$1'
ujs = fs.readFileSync SCRIPT, 'utf8'
fs.writeFileSync OUTPUT, ujs.replace /css\s=.+;/, "css = \"#{css}\";", 'utf8', (err) ->
throw err if err
log 'Build Successful!'
option '-v', '--version [VERSION]', 'Release a new version.'
task 'release', (options) ->
{version} = options
return log 'ERROR! No version provided.' unless version
data = fs.readFileSync SCRIPT, 'utf8'
fs.writeFileSync SCRIPT, data.replace /(\/\s@version\s+|VERSION\s+=\s\")[\d\.]+/g, "$1#{version}", 'utf8', (err) ->
throw err if err
data = fs.readFileSync CHANGELOG, 'utf8'
fs.writeFileSync CHANGELOG, data.replace 'master', "master\n\n#{version}", 'utf8', (err) ->
throw err if err
exec "cake build && git commit -am 'Release #{version}' && git tag -a #{version} -m '#{version}' && git tag -af stable -m '#{version}'"