Skip to content

Commit 773733d

Browse files
committed
replace django collectsatic
1 parent 4c901ae commit 773733d

2 files changed

Lines changed: 41 additions & 3 deletions

File tree

collectstatic.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import shutil
2+
import os
3+
from pathlib import Path
4+
import sys
5+
6+
_here = Path(os.path.abspath(os.path.dirname(__file__)))
7+
build_dir = _here / 'frontend/dist'
8+
9+
10+
def validate_static(static_dir):
11+
if os.path.isdir(static_dir):
12+
print(f'This will remove the contents of "{dest}". Continue? [y/n]')
13+
response = input()
14+
if response != 'y':
15+
print('Aborting.')
16+
exit()
17+
if os.path.isfile(static_dir):
18+
raise NotADirectoryError(f'{static_dir} is a file, not a directory')
19+
20+
21+
def clean_static(static_dir):
22+
if os.path.exists(static_dir):
23+
shutil.rmtree(static_dir)
24+
25+
26+
def collect_static(static_dir):
27+
if os.path.isdir(build_dir):
28+
shutil.copytree(build_dir, static_dir)
29+
30+
if __name__ == '__main__':
31+
if len(sys.argv) > 1:
32+
dest = Path(sys.argv[1])
33+
validate_static(dest)
34+
else:
35+
dest = _here / 'static'
36+
37+
clean_static(dest)
38+
collect_static(dest)
39+

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@
2020
"start": "yarn start-front",
2121
"build": "yarn front yarn build",
2222
"build-p": "yarn front yarn build --prod",
23-
"collectstatic-p": "cd backend && python manage.py collectstatic --noinput -v 0 --settings collect --pythonpath ..",
24-
"clean-static": "rm -rf static || rd /S /Q static",
25-
"static-p": "yarn build-p && yarn clean-static && yarn collectstatic-p",
23+
"collectstatic-p": "python collectstatic.py",
24+
"static-p": "yarn build-p && yarn collectstatic-p",
2625
"watch-front-p": "yarn front yarn watch",
2726
"start-p": "yarn static-p && yarn watch-front-p"
2827
},

0 commit comments

Comments
 (0)