forked from EleotleCram/jshamcrest
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfabfile.py
165 lines (138 loc) · 4.4 KB
/
fabfile.py
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#-*- coding:utf-8 -*-
"""JsHamcrest build script.
"""
import re
import cStringIO as StringIO
from fabric.api import *
# Project
env.project = 'jshamcrest'
env.version = '0.6.7'
env.full_name = '%s-%s' % (env.project, env.version)
# Build output
env.build_dir = 'build'
env.dist_dir = 'dist'
env.rev_info_file = '%s/_rev_info.txt' % (env.build_dir,)
# Output script files
env.js = '%s/%s.js' % (env.build_dir, env.project)
env.js_version = '%s/%s.js' % (env.build_dir, env.full_name)
env.js_min = '%s/%s-min.js' % (env.build_dir, env.project)
env.js_min_version = '%s/%s-min.js' % (env.build_dir, env.full_name)
# Test
env.test_dir = 'test'
env.web_browser = 'firefox'
# Documentation
env.tmp_dir = '/tmp/%s' % env.project
env.doc_dir = 'doc'
env.doc_build = '%s/_build' % env.doc_dir
env.doc_dir_html = '%s/html' % env.doc_build
env.doc_dir_pdf = '%s/latex' % env.doc_build
env.doc_pdf = '%s/JsHamcrest.pdf' % env.doc_dir_pdf
# Source code
env.src_dir = 'src'
env.src_files = (
'jshamcrest',
'core',
'number',
'text',
'object',
'collection',
'operator',
'integration',
)
# Remote server
env.hosts = ['destaquenet.com']
# Constants
_PATTERN_COMMIT_HASH = re.compile('commit\W+([0-9a-f]+)')
_PATTERN_COMMIT_DATE = re.compile('Date:\W+(.*)')
@runs_once
def clean():
"""Resets the build output directories.
"""
local('rm -fR %s %s' % (env.build_dir, env.dist_dir))
local('mkdir -p %s %s' % (env.build_dir, env.dist_dir))
@runs_once
def build():
"""Builds the final script and writes it to the disk.
"""
_set_revision_info()
_replace_tokens()
content = env.src_content.readlines()
file(env.js, 'w').writelines(content)
local('cp %s %s' % (env.js, env.js_version))
@runs_once
def pack():
"""Creates a minified version of the final script using the Google Closure
Compiler service.
"""
build()
local('python lib/closure_compiler_cli.py -f %s > %s' % (env.js, env.js_min))
local('cp %s %s' % (env.js_min, env.js_min_version))
def test():
"""Opens the test suite on a web browser.
"""
pack()
web_browser = prompt('Please choose your web browser', \
default=env.web_browser)
local('%s %s/testSuite.html &' % (web_browser, env.test_dir))
@runs_once
def doc_clean():
"""Resets the doc output directories.
"""
local('cd %s; make clean;' % env.doc_dir)
def doc_html():
"""Builds the HTML documentation.
"""
doc_clean()
local('cd %s; make html' % env.doc_dir)
def doc_pdf():
"""Builds the PDF documentation.
"""
doc_clean()
local('cd %s; make latex' % env.doc_dir)
local('cd %s; make all-pdf' % env.doc_dir_pdf)
def make_site():
"""Builds the documentation both in HTML and PDF.
"""
doc_clean()
doc_html()
doc_pdf()
pack()
local('cp %s %s' % (env.doc_pdf, env.doc_dir_html))
local('cp %s %s' % (env.js, env.doc_dir_html))
local('cp %s %s' % (env.js_min, env.doc_dir_html))
local('cd %s ; touch .nojekyll' % env.doc_dir_html)
def deploy():
"""Deploys the documentation.
"""
make_site()
local('rm -fR %s ; mkdir -p %s' % (env.tmp_dir, env.tmp_dir))
local('cp -R %s/* %s' % (env.doc_dir_html, env.tmp_dir))
local('git checkout gh-pages')
local('cp -R %s/* .' % env.tmp_dir)
local('git add . ; git commit -m "Updated documentation."')
def _set_revision_info():
"""Reads information about the latest revision.
"""
clean()
local('git rev-list --all --max-count=1 --pretty > %s' % env.rev_info_file)
rev_info = file(env.rev_info_file, 'r').read()
env.commit_hash = _PATTERN_COMMIT_HASH.findall(rev_info)[0]
env.commit_date = _PATTERN_COMMIT_DATE.findall(rev_info)[0]
def _read_files():
"""Reads and joins the source files.
"""
env.src_content = StringIO.StringIO()
for file_name in env.src_files:
file_path = '%s/%s.js' % (env.src_dir, file_name)
env.src_content.writelines(file(file_path, 'r').readlines())
def _replace_tokens():
"""Replaces the tokens found in the source code.
"""
_read_files()
content = env.src_content.getvalue()
env.src_content = StringIO.StringIO()
content = content.replace('@VERSION', env.version)
content = content.replace('@REV', env.commit_hash)
content = content.replace('@DATE', env.commit_date)
env.src_content.write(content)
env.src_content.seek(0)