Fix post build commands and refactor
This commit is contained in:
parent
e416ae704d
commit
c78f77b9f0
3 changed files with 39 additions and 28 deletions
|
@ -1,14 +1,21 @@
|
||||||
from pelican import signals
|
from pelican import signals
|
||||||
import os
|
import os
|
||||||
|
from plugins.utils import run_command
|
||||||
|
|
||||||
|
|
||||||
OUTPUT_PATH = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'output')
|
OUTPUT_PATH = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'output')
|
||||||
|
|
||||||
|
|
||||||
def post_build(*args, **kwargs):
|
def post_build(*args, **kwargs):
|
||||||
os.system("mv {0}/assets/robots.txt {0}".format(OUTPUT_PATH))
|
run_command('Copying Robots.txt', [
|
||||||
os.system("cp -R {0}/assets/* {0}/static".format(OUTPUT_PATH))
|
'mv', os.path.join(OUTPUT_PATH, 'assets', 'robots.txt'), OUTPUT_PATH
|
||||||
os.system("rm -rf {0}/assets".format(OUTPUT_PATH))
|
])
|
||||||
|
run_command('Copying Assets', [
|
||||||
|
'cp', '-R', os.path.join(OUTPUT_PATH, 'assets', '*'), os.path.join(OUTPUT_PATH, 'static')
|
||||||
|
], True)
|
||||||
|
run_command('Remove Old Assets', [
|
||||||
|
'rm', '-rf', os.path.join(OUTPUT_PATH, 'assets')
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
def register():
|
def register():
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from pelican import signals
|
from pelican import signals
|
||||||
import os
|
import os
|
||||||
import subprocess
|
from plugins.utils import node_bin, run_command
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
logger = logging.getLogger(__file__)
|
logger = logging.getLogger(__file__)
|
||||||
|
@ -8,30 +8,6 @@ logger = logging.getLogger(__file__)
|
||||||
NODE_PRODUCTION = os.environ.get('NODE_ENV') == 'production'
|
NODE_PRODUCTION = os.environ.get('NODE_ENV') == 'production'
|
||||||
|
|
||||||
|
|
||||||
def flatten_list(array):
|
|
||||||
res = []
|
|
||||||
for el in array:
|
|
||||||
if isinstance(el, (list, tuple)):
|
|
||||||
res.extend(flatten_list(el))
|
|
||||||
continue
|
|
||||||
res.append(el)
|
|
||||||
return res
|
|
||||||
|
|
||||||
|
|
||||||
def run_command(detail, args, use_system=False):
|
|
||||||
logger.info(detail + '...')
|
|
||||||
if use_system:
|
|
||||||
exit_code = os.system(' '.join(flatten_list(args)))
|
|
||||||
if exit_code:
|
|
||||||
exit(exit_code)
|
|
||||||
else:
|
|
||||||
subprocess.run(flatten_list(args), check=True)
|
|
||||||
|
|
||||||
|
|
||||||
def node_bin(exec):
|
|
||||||
return os.path.join('node_modules', '.bin', exec)
|
|
||||||
|
|
||||||
|
|
||||||
def static_build(*args, **kwargs):
|
def static_build(*args, **kwargs):
|
||||||
if NODE_PRODUCTION:
|
if NODE_PRODUCTION:
|
||||||
logger.info('Building Production...')
|
logger.info('Building Production...')
|
||||||
|
|
28
plugins/utils.py
Normal file
28
plugins/utils.py
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
import subprocess
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__file__)
|
||||||
|
|
||||||
|
|
||||||
|
def flatten_list(array):
|
||||||
|
res = []
|
||||||
|
for el in array:
|
||||||
|
if isinstance(el, (list, tuple)):
|
||||||
|
res.extend(flatten_list(el))
|
||||||
|
continue
|
||||||
|
res.append(el)
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
def run_command(detail, args, wrap=False):
|
||||||
|
if wrap:
|
||||||
|
run_command('', ['bash', '-c', ' '.join(flatten_list(args))])
|
||||||
|
else:
|
||||||
|
logger.info(detail + '...')
|
||||||
|
subprocess.run(flatten_list(args), check=True)
|
||||||
|
|
||||||
|
|
||||||
|
def node_bin(exec):
|
||||||
|
return os.path.join('node_modules', '.bin', exec)
|
Reference in a new issue