diff --git a/package.json b/package.json index c2204e1..8acd4cd 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,7 @@ "scripts": { "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", - "copy-fonts": "cp -R node_modules/font-awesome/fonts theme/static/build/", - "build-js": "./scripts/build-js.sh", - "build-scss": "./scripts/build-scss.sh" + "copy-fonts": "cp -R node_modules/font-awesome/fonts theme/static/build/" }, "repository": { "type": "git", diff --git a/plugins/static_build.py b/plugins/static_build.py index 2908bab..ace1520 100644 --- a/plugins/static_build.py +++ b/plugins/static_build.py @@ -1,11 +1,28 @@ from pelican import signals import os +import sh +NODE_PRODUCTION = os.environ.get('NODE_ENV') == 'production' def static_build(*args, **kwargs): - os.system('npm run build-js') - os.system('npm run build-scss') + if NODE_PRODUCTION: + 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(): signals.static_generator_init.connect(static_build) diff --git a/scripts/build-js.sh b/scripts/build-js.sh deleted file mode 100755 index 2071800..0000000 --- a/scripts/build-js.sh +++ /dev/null @@ -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!" diff --git a/scripts/build-scss.sh b/scripts/build-scss.sh deleted file mode 100755 index 164454a..0000000 --- a/scripts/build-scss.sh +++ /dev/null @@ -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 diff --git a/scripts/test b/scripts/test old mode 100644 new mode 100755