1
Fork 0

Move static build into pelican. refactor later

This commit is contained in:
Jake Howard 2017-01-10 17:52:42 +00:00
parent 8692dbbbef
commit 2abbfb49ec
5 changed files with 20 additions and 72 deletions

View file

@ -5,9 +5,7 @@
"scripts": { "scripts": {
"postinstall": "npm run create-build-dirs && npm run copy-fonts", "postinstall": "npm run create-build-dirs && npm run copy-fonts",
"create-build-dirs": "mkdir -p theme/static/build/js/lib theme/static/build/fonts theme/static/build/css theme/static/build/img", "create-build-dirs": "mkdir -p theme/static/build/js/lib theme/static/build/fonts theme/static/build/css theme/static/build/img",
"copy-fonts": "cp -R node_modules/font-awesome/fonts theme/static/build/", "copy-fonts": "cp -R node_modules/font-awesome/fonts theme/static/build/"
"build-js": "./scripts/build-js.sh",
"build-scss": "./scripts/build-scss.sh"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

View file

@ -1,11 +1,28 @@
from pelican import signals from pelican import signals
import os import os
import sh
NODE_PRODUCTION = os.environ.get('NODE_ENV') == 'production'
def static_build(*args, **kwargs): def static_build(*args, **kwargs):
os.system('npm run build-js') if NODE_PRODUCTION:
os.system('npm run build-scss') print('Building Production...')
sh.mkdir('-p', 'theme/static/build/js/lib')
os.system('uglifyjs node_modules/bootstrap-sass/assets/javascripts/bootstrap.js --compress --screw-ie8 --define --stats --keep-fnames -o theme/static/build/js/lib/bootstrap.js')
os.system('uglifyjs theme/static/build/js/lib/* --compress --screw-ie8 --define --stats --keep-fnames -o theme/static/build/js/libs.js')
sh.rm('-rf', 'theme/static/build/js/lib')
os.system('uglifyjs node_modules/jquery/dist/jquery.js --compress --screw-ie8 --define --stats --keep-fnames -o theme/static/build/js/jquery.js')
os.system('browserify -t [ babelify --presets [ es2015 react ] ] theme/static/src/js/app.js -o theme/static/build/js/app.js')
os.system('uglifyjs theme/static/build/js/app.js --compress --screw-ie8 --define --stats --keep-fnames -o theme/static/build/js/app.js')
print('JS built!')
os.system('pygmentize -S github -f html -a .highlight > theme/static/src/scss/pygment.css')
os.system('npm run build-scss')
os.system('node-sass theme/static/src/scss/index.scss theme/static/build/css/index.css --source-map-embed')
os.system('postcss -u autoprefixer -o theme/static/build/css/index.css theme/static/build/css/index.css')
os.system('cleancss -d --s0 -o theme/static/build/css/index.css theme/static/build/css/index.css')
print('SCSS Built!')
def register(): def register():
signals.static_generator_init.connect(static_build) signals.static_generator_init.connect(static_build)

View file

@ -1,44 +0,0 @@
#!/usr/bin/env bash
set -e
if [ "$NODE_ENV" = "production" ]
then
echo ">>> WARNING: Building in Production Mode!"
fi
mkdir -p theme/static/build/js/lib
if [ "$NODE_ENV" = "production" ]
then
echo ">> Compressing Libraries..."
uglifyjs node_modules/bootstrap-sass/assets/javascripts/bootstrap.js --compress --screw-ie8 --define --stats --keep-fnames -o theme/static/build/js/lib/bootstrap.js
uglifyjs theme/static/build/js/lib/* --compress --screw-ie8 --define --stats --keep-fnames -o theme/static/build/js/libs.js
else
echo ">> Building Libraries..."
cp node_modules/bootstrap-sass/assets/javascripts/bootstrap.js theme/static/build/js/lib/bootstrap.js
uglifyjs theme/static/build/js/lib/* --screw-ie8 --stats --keep-fnames -o theme/static/build/js/libs.js
fi
rm -rf theme/static/build/js/lib
if [ "$NODE_ENV" = "production" ]
then
echo ">> Compressing jQuery..."
uglifyjs node_modules/jquery/dist/jquery.js --compress --screw-ie8 --define --stats --keep-fnames -o theme/static/build/js/jquery.js
else
echo ">> Building jQuery..."
cp node_modules/jquery/dist/jquery.js theme/static/build/js/jquery.js
fi
echo ">> Building Application JS..."
browserify -t [ babelify --presets [ es2015 react ] ] theme/static/src/js/app.js -o theme/static/build/js/app.js
if [ "$NODE_ENV" = "production" ]
then
echo ">> Compressing Application..."
uglifyjs theme/static/build/js/app.js --compress --screw-ie8 --define --stats --keep-fnames -o theme/static/build/js/app.js
fi
echo "> JS Built!"

View file

@ -1,23 +0,0 @@
#!/usr/bin/env bash
set -e
if [ "$NODE_ENV" = "production" ]
then
echo ">>> WARNING: Building in Production Mode!"
fi
echo ">> Generating Pygments styles..."
env/bin/pygmentize -S github -f html -a .highlight > theme/static/src/scss/pygment.css
echo ">> Building SCSS..."
node-sass theme/static/src/scss/index.scss theme/static/build/css/index.css --source-map-embed
echo ">> Post-Processing..."
postcss -u autoprefixer -o theme/static/build/css/index.css theme/static/build/css/index.css
if [ "$NODE_ENV" = "production" ]
then
echo ">> Compressing CSS..."
cleancss -d --s0 -o theme/static/build/css/index.css theme/static/build/css/index.css
fi

0
scripts/test Normal file → Executable file
View file