forked from narfdotpl/jquery-typing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
169 lines (122 loc) · 3.76 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
166
167
168
169
#!/usr/bin/env python
# encoding: utf-8
"""
This file is used to make certain development tasks less annoying.
To take full advantage of it, you'll need Python, Fabric, Java, Ruby
and Haml.
"""
from os.path import dirname, join, realpath
from fabric.api import cd, env, local, put, run
__author__ = 'Maciej Konieczny <[email protected]>'
VERSION = '0.2.0'
REPO_DIR = dirname(realpath(__file__))
DEMO_DIR = join(REPO_DIR, 'demo')
DEMO_SOURCE_DIR = join(REPO_DIR, 'demo-source')
PLUGIN_DIR = join(REPO_DIR, 'plugin')
TOOLS_DIR = join(REPO_DIR, 'tools')
COMPILER_PATH = join(TOOLS_DIR, 'closure-compiler/compiler.jar')
YUICOMPRESSOR_PATH = join(TOOLS_DIR,
'yuicompressor/build/yuicompressor-2.4.2.jar')
PLUGIN_PATH = join(PLUGIN_DIR, 'jquery.typing-{0}.js'.format(VERSION))
COMPRESSED_PLUGIN_PATH = join(PLUGIN_DIR,
'jquery.typing-{0}.min.js'.format(VERSION))
env.hosts = ['narf.megiteam.pl']
def build():
"""
Create compressed version of the plugin and build demo.
"""
compress()
demo()
def compress():
"""
Create compressed version of the plugin.
"""
# remove old compressed version
_rm_min(PLUGIN_DIR)
# compress
local('java -jar {0} --js={1} --js_output_file={2}'.format(
COMPILER_PATH, PLUGIN_PATH, COMPRESSED_PLUGIN_PATH))
# copy info comment from development version
info = ''
with open(PLUGIN_PATH) as f:
for line in f:
if line.startswith('//'):
info += line
else:
break
# add info comment to compressed version
if info:
with open(COMPRESSED_PLUGIN_PATH) as f:
compressed = f.read()
with open(COMPRESSED_PLUGIN_PATH, 'w') as f:
f.write(info + compressed)
def demo():
"""
Build demo.
"""
# remove old compressed version
_rm_min(DEMO_DIR)
# copy compressed plugin
local('cp {0} {1}'.format(COMPRESSED_PLUGIN_PATH, DEMO_DIR))
# generate styles
demo_css()
# render haml
haml = join(DEMO_SOURCE_DIR, 'index.haml')
html = join(DEMO_DIR, 'index.html')
local('haml {0} > {1}'.format(haml, html))
def demo_css():
"""
Generate styles for demo.
"""
# set paths
reset = join(DEMO_SOURCE_DIR, 'reset.css')
style = join(DEMO_SOURCE_DIR, 'style.sass')
output = join(DEMO_DIR, 'style.css')
# copy reset
local('cp {0} {1}'.format(reset, output))
# render sass
local('sass {0} >> {1}'.format(style, output))
# compress css
local('java -jar {0} -o {1} {1}'.format(YUICOMPRESSOR_PATH, output))
def deploy():
"""
Update MegiTeam and push to GitHub.
"""
# update MegiTeam
megi()
# push to GitHub
local('git push')
local('git push --tags')
def megi():
"""
Update MegiTeam.
"""
# archive demo
archive_name = 'typing.tar.bz2'
archive_path = '/tmp/' + archive_name
with cd(DEMO_DIR):
local('tar -cj --exclude *.haml -f {0} *'.format(archive_path))
# set remote directory names
main_dir = 'narf.pl/main/on-the-stage'
typing_dir_name = 'jquery-typing'
typing_dir = join(main_dir, typing_dir_name)
# create jQuery-typing directory
with cd(main_dir):
run("""if [ -d {0} ]; then
rm -rf {0}/*
else
mkdir {0}
fi""".format(typing_dir_name))
# upload
put(archive_path, typing_dir)
# extract and remove remote archive
with cd(typing_dir):
run('tar xf ' + archive_name)
run('rm ' + archive_name)
# remove local archive
local('rm ' + archive_path)
def _rm_min(directory):
"""
Remove compressed version in given directory.
"""
local('rm {0}/jquery.typing*.min.js'.format(directory))