1
Fork 0

Fix post build commands and refactor

This commit is contained in:
Jake Howard 2017-01-12 09:00:01 +00:00
parent e416ae704d
commit c78f77b9f0
3 changed files with 39 additions and 28 deletions

View file

@ -1,14 +1,21 @@
from pelican import signals
import os
from plugins.utils import run_command
OUTPUT_PATH = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'output')
def post_build(*args, **kwargs):
os.system("mv {0}/assets/robots.txt {0}".format(OUTPUT_PATH))
os.system("cp -R {0}/assets/* {0}/static".format(OUTPUT_PATH))
os.system("rm -rf {0}/assets".format(OUTPUT_PATH))
run_command('Copying Robots.txt', [
'mv', os.path.join(OUTPUT_PATH, 'assets', 'robots.txt'), 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():

View file

@ -1,6 +1,6 @@
from pelican import signals
import os
import subprocess
from plugins.utils import node_bin, run_command
import logging
logger = logging.getLogger(__file__)
@ -8,30 +8,6 @@ logger = logging.getLogger(__file__)
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):
if NODE_PRODUCTION:
logger.info('Building Production...')

28
plugins/utils.py Normal file
View 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)