forked from erdem/django-map-widgets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
147 lines (109 loc) · 4.44 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
import os
from fabric.api import local
JS_FILE_MAPPING = {
"GooglePointFieldWidget": {
"input_files": [
"mapwidgets/static/mapwidgets/js/jquery_init.js",
"mapwidgets/static/mapwidgets/js/jquery_class.js",
"mapwidgets/static/mapwidgets/js/django_mw_base.js",
"mapwidgets/static/mapwidgets/js/mw_google_point_field.js",
],
"output_file": "mapwidgets/static/mapwidgets/js/mw_google_point_field.min.js"
},
"MapboxPointFieldWidget": {
"input_files": [
"mapwidgets/static/mapwidgets/js/jquery_init.js",
"mapwidgets/static/mapwidgets/js/jquery_class.js",
"mapwidgets/static/mapwidgets/js/django_mw_base.js",
"mapwidgets/static/mapwidgets/js/mw_mapbox_point_field.js",
],
"output_file": "mapwidgets/static/mapwidgets/js/mw_mapbox_point_field.min.js"
},
"GooglePointFieldInlineWidget": {
"input_files": [
"mapwidgets/static/mapwidgets/js/jquery_init.js",
"mapwidgets/static/mapwidgets/js/jquery_class.js",
"mapwidgets/static/mapwidgets/js/django_mw_base.js",
"mapwidgets/static/mapwidgets/js/mw_google_point_field.js",
"mapwidgets/static/mapwidgets/js/mw_google_point_field_generater.js",
],
"output_file": "mapwidgets/static/mapwidgets/js/mw_google_point_inline_field.min.js"
},
"GoogleStaticOverlayMapWidget": {
"input_files": [
"mapwidgets/static/mapwidgets/js/jquery_init.js",
"mapwidgets/static/mapwidgets/js/jquery.custom.magnific-popup.js",
],
"output_file": "mapwidgets/static/mapwidgets/js/jquery.custom.magnific-popup.min.js"
}
}
CSS_FILE_MAPPING = {
"GooglePointFieldWidget": {
"input_files": [
"mapwidgets/static/mapwidgets/css/map_widgets.css",
],
"output_file": "mapwidgets/static/mapwidgets/css/map_widgets.min.css"
},
"GoogleStaticOverlayMapWidget": {
"input_files": [
"mapwidgets/static/mapwidgets/css/magnific-popup.css",
],
"output_file": "mapwidgets/static/mapwidgets/css/magnific-popup.min.css",
}
}
DJANGO_MAPWIDGETS_CONTAINER_NAME = os.environ.get('DJANGO_MAPWIDGETS_CONTAINER_NAME', 'django_mapwidgets')
POSTGRES_CONTAINER_NAME = os.environ.get('DJANGO_MAPWIDGETS_CONTAINER_NAME', 'mapwidget_postgres')
def install_npm_packages():
"""
Install uglifycss and uglifyjs CLI to minify the static files.
"""
local("npm install uglify-js -g")
local("npm install uglifycss -g")
def minify_js_files():
"""
This command minified js files with UglifyJS
"""
for k, v in JS_FILE_MAPPING.items():
input_files = " ".join(v["input_files"])
output_file = v["output_file"]
uglifyjs_command = "uglifyjs {input_files} -o {output_file}".format(
input_files=input_files,
output_file=output_file
)
local(uglifyjs_command)
def minify_css_files():
"""
This command minified js files with UglifyCSS
"""
for k, v in CSS_FILE_MAPPING.items():
input_files = " ".join(v["input_files"])
output_file = v["output_file"]
uglifyjs_command = "uglifycss {input_files} > {output_file}".format(
input_files=input_files,
output_file=output_file
)
local(uglifyjs_command)
def minify_files():
minify_js_files()
minify_css_files()
def docker_build():
local('docker-compose up --build --force-recreate')
def docker_up():
local('docker-compose up')
def docker_shell():
local('docker exec -it {} /bin/bash'.format(DJANGO_MAPWIDGETS_CONTAINER_NAME))
def run_on_docker(command):
local('docker exec -it {} /bin/bash -c "{}"'.format(DJANGO_MAPWIDGETS_CONTAINER_NAME, command))
def docker_runserver():
run_on_docker("cd tests/testapp/; python manage.py runserver 0:8000")
def docker_run_unit_tests():
run_on_docker("cd tests/testapp/; python manage.py test")
def docker_postgres_shell():
local('docker exec -it {} /bin/bash'.format(POSTGRES_CONTAINER_NAME))
def docker_covarage_tests():
run_on_docker('cd tests/testapp;coverage run --source="../../mapwidgets" manage.py test;coverage report')
def create_pypi_package():
local('python setup.py sdist bdist_wheel')
local('twine check dist/*')
def upload_pypi_package_to_test_repo():
local('twine upload --repository-url https://test.pypi.org/legacy/ dist/*')