-
Notifications
You must be signed in to change notification settings - Fork 1
/
mk-full-package.py
executable file
Β·147 lines (123 loc) Β· 3.8 KB
/
mk-full-package.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
#!/usr/bin/env python3
# coding: utf8
import shutil
import argparse
import os
import codecs
import platform
from contextlib import closing
from zipfile import ZipFile, ZIP_DEFLATED
import time
def zipdir(basedir, archivename):
assert os.path.isdir(basedir)
with closing(
ZipFile(archivename, mode='w', compression=ZIP_DEFLATED, compresslevel=9)
) as z:
for root, dirs, files in os.walk(basedir):
# NOTE: ignore empty directories
for fn in files:
absfn = os.path.join(root, fn)
zfn = absfn[len(basedir) + len(os.sep) :] # XXX: relative path
z.write(absfn, zfn)
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-z', '--zip', help='Compress with zip', action='store_true')
parser.add_argument(
'-d', '--delete', help='empty folder if exists', action='store_true'
)
parser.add_argument(
'-t',
'--target',
action='store',
dest='target',
required=True,
help='Target directory',
)
args = parser.parse_args()
target = os.path.expanduser(args.target)
target = os.path.abspath(args.target)
source_dir = os.path.dirname(__file__)
ignore = [
'.gitignore',
'*.py',
'.env',
'.env.foobar',
'.env.test',
'.git',
'.gitignore',
'.php-cs-fixer.cache',
'.php-cs-fixer.php',
'.php_cs.cache',
'.php_cs.dist',
'.phpunit.cache',
'.phpunit.result.cache',
'.project',
'.settings',
'audio',
'avatars',
'cache',
'doc-src',
'generated',
'log',
'phpunit_init.php',
'report',
'run-tests.sh',
'tests',
'update.php',
'video',
'phpunit.xml'
]
# Prepare build
os.chdir('dist')
os.system('vendor/bin/robo build:prepare')
os.chdir('..')
IGNORE_PATTERNS = shutil.ignore_patterns(*ignore)
if args.delete and os.path.exists(target):
print('Folder exists. Truncating.')
shutil.rmtree(target)
print('copying files')
shutil.copytree(source_dir, target, ignore=IGNORE_PATTERNS)
installer_aus_folder = os.path.join(target, 'dist', 'installer.aus')
installer_folder = os.path.join(target, 'dist', 'installer')
if os.path.exists(installer_aus_folder):
os.rename(installer_aus_folder, installer_folder)
main_dir = os.path.join(target, 'dist')
version_file = os.path.join(target, 'dist', 'App', 'UliCMS', 'UliCMSVersion.php')
print('set build date...')
with codecs.open(version_file, 'r+', 'utf-8') as f:
lines = f.readlines()
f.seek(0)
f.truncate()
for line in lines:
if '{InsertBuildDate}' in line:
timestamp = str(int(time.time()))
line = (
' public const BUILD_DATE = '
+ timestamp
+ '; // {InsertBuildDate}\r\n'
)
print(line)
f.write(line)
old_cwd = os.getcwd()
os.chdir(main_dir)
old_cwd = os.getcwd()
# change dir to output dist dir
os.chdir(main_dir)
# Remove all non dev composer packages
os.system('composer install --no-dev --prefer-dist --optimize-autoloader')
# Remove all non dev npm packages
os.system('npm install --omit=dev')
# Clean up vendor dir
os.system('vendor/bin/robo build:optimize-resources')
# Change dir back
os.chdir(old_cwd)
archive_name = os.path.join(target, '..', os.path.basename(target) + '.zip')
if args.zip:
print('zipping folder...')
zipdir(target, archive_name)
print('removing target folder...')
shutil.rmtree(target)
try:
main()
except KeyboardInterrupt:
pass