Convert site to a single JavaScript archive
* Convert build to use a single JavaScript file on the site (instead of downloading each library separately). This also means that all global variables (e.g., `$` for JQuery, `_` for Underscore.js) can be removed. * Remove unused scripts and/or move them to a more appropriate repo * Update the `deploy` script to work with CircleCI's automation * Update markdown display code to allow images to be located with the markdown data files instead of the pre-rendered index pages
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
ssh [email protected]
|
||||
@@ -1,50 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
read -d '' USAGE <<END
|
||||
USAGE: convert-nei-dump <source> <mod_slug> <mod_version>
|
||||
|
||||
Converts output from NEI dump files into a format which can be used by
|
||||
Crafting Guide. In particlar, this script looks for the "Item Panel" dump
|
||||
both in PNG and CSV formats and assumes they contain all the data for the
|
||||
target mod.
|
||||
|
||||
Unfortunate, NEI doesn't generate enough information to fill in all the
|
||||
recipes for each item: only their names. Once this script has converted the
|
||||
data, you will need to manually enter the missing content.
|
||||
|
||||
<source> : the "dumps" directory where NEI dropped its content
|
||||
<mod_slug> : the slug of the mod being converted
|
||||
<mod_version> : the version of the mod being converted
|
||||
END
|
||||
|
||||
|
||||
SOURCE_DIR="$1"; shift
|
||||
MOD_SLUG="$1"; shift
|
||||
MOD_VERSION="$1"; shift
|
||||
|
||||
mkdir -p "./static/data/$MOD_SLUG/$MOD_VERSION"
|
||||
DATA_FILE="./static/data/$MOD_SLUG/$MOD_VERSION/mod-version.cg"
|
||||
touch "$DATA_FILE"
|
||||
|
||||
if [[ "$SOURCE_DIR" == "" || "$MOD_SLUG" == "" || "$MOD_VERSION" == "" ]]; then
|
||||
echo "$USAGE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "./static/browse/$MOD_SLUG/images"
|
||||
ls $SOURCE_DIR/itempanel_icons | while read FILE; do
|
||||
ITEM_NAME="$(echo $FILE | sed 's/.png//')"
|
||||
ITEM_SLUG="$(echo $ITEM_NAME \
|
||||
| sed 's/[^a-zA-Z0-9]/_/g' \
|
||||
| sed 's/__*/_/g' \
|
||||
| sed 's/^_//' \
|
||||
| sed 's/_$//' \
|
||||
| tr '[A-Z]' '[a-z]' \
|
||||
)"
|
||||
mkdir -p "./static/browse/$MOD_SLUG/$ITEM_SLUG"
|
||||
cp "$SOURCE_DIR/itempanel_icons/$FILE" "./static/browse/$MOD_SLUG/$ITEM_SLUG/icon.png"
|
||||
if ! grep -q "item: $ITEM_NAME$" $DATA_FILE; then
|
||||
echo "item: $ITEM_NAME" >> $DATA_FILE
|
||||
echo "" >> $DATA_FILE
|
||||
fi
|
||||
done
|
||||
@@ -1,11 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
for FILE in $(ls $1/images); do
|
||||
ITEM=$(basename -s .png $FILE)
|
||||
MOD=$(basename $(dirname $1))
|
||||
TARGET_DIR="./static/browse/$MOD/$ITEM"
|
||||
TARGET_FILE="./static/browse/$MOD/$ITEM/icon.png"
|
||||
|
||||
mkdir -p "$TARGET_DIR"
|
||||
mv "$1/images/$FILE" "$TARGET_FILE"
|
||||
done
|
||||
+25
-17
@@ -1,32 +1,40 @@
|
||||
#!/bin/bash
|
||||
|
||||
export AWS_CONFIG_FILE="aws.config"
|
||||
if [[ -e "./aws.config" ]]; then
|
||||
export AWS_CONFIG_FILE="./aws.config"
|
||||
else
|
||||
export AWS_CONFIG_FILE="$HOME/.aws/config"
|
||||
fi
|
||||
|
||||
ROOT="./dist"
|
||||
SOURCE_DIR="./dist/"
|
||||
SITE="crafting-guide.com"
|
||||
TARGET=""
|
||||
while [[ "$1" != "" ]]; do
|
||||
case "$1" in
|
||||
"--new") TARGET="new";;
|
||||
"--promote") TARGET="promote";;
|
||||
"--staging") TARGET="staging";;
|
||||
"--production") TARGET="production";;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if [[ "$TARGET" == "" ]]; then
|
||||
echo "Please choose either --new or --promote for the target."
|
||||
exit
|
||||
echo "Please choose either --staging or --production for the target."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "$TARGET" == "new" ]]; then
|
||||
find . -name ".DS_Store" 2>/dev/null | xargs rm &>/dev/null
|
||||
if grunt dist; then
|
||||
echo "Preparing to upload to S3..."
|
||||
s3cmd sync -r --add-header="cache-control:max-age=1800" "$ROOT/" "s3://new.$SITE/"
|
||||
grunt clean:dist build
|
||||
else
|
||||
echo "Aborting deployment"
|
||||
fi
|
||||
elif [[ "$TARGET" == "promote" ]]; then
|
||||
aws s3 sync "s3://new.$SITE" "s3://$SITE" --delete
|
||||
if [[ "$TARGET" == "staging" ]]; then
|
||||
TARGET_DIR="s3://new.$SITE/"
|
||||
elif [[ "$TARGET" == "production" ]]; then
|
||||
TARGET_DIR="s3://$SITE/"
|
||||
fi
|
||||
|
||||
S3CMD_CFG="$HOME/.s3cfg"
|
||||
if [[ ! -e "$S3CMD_CFG" ]]; then
|
||||
echo "[default]" > "$S3CMD_CFG"
|
||||
cat $AWS_CONFIG_FILE | grep "aws_access_key_id" | sed "s/aws_access_key_id/access_key/" >> "$S3CMD_CFG"
|
||||
cat $AWS_CONFIG_FILE | grep "aws_secret_access_key" | sed "s/aws_secret_access_key/secret_key/" >> "$S3CMD_CFG"
|
||||
fi
|
||||
|
||||
echo "Preparing to upload to S3..."
|
||||
s3cmd sync -r --add-header="cache-control:max-age=1800" $SOURCE_DIR $TARGET_DIR
|
||||
echo "S3 Upload Complete"
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
BASE_DIR="$1"
|
||||
for FILE in $(ls $BASE_DIR/images); do
|
||||
NAME=$(basename -s.png $FILE)
|
||||
DIR="$BASE_DIR/$NAME"
|
||||
IMG_DEST="$DIR/icon.png"
|
||||
|
||||
mkdir -p $DIR
|
||||
mv "$BASE_DIR/images/$FILE" "$IMG_DEST"
|
||||
done
|
||||
@@ -1,73 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
USAGE=<<END
|
||||
USAGE: prerender <options>
|
||||
|
||||
Options:
|
||||
|
||||
--force : overwrite existing files (default skips)
|
||||
--clean : remove all files before starting
|
||||
--only <pattern> : restrict rendering to the given pattern
|
||||
--output <dir> : output directory (default: ./static)
|
||||
--sitemap <file> : sitemap file (default: ./static/sitemap.txt
|
||||
|
||||
END
|
||||
|
||||
CLEAN="no"
|
||||
FORCE="no"
|
||||
ONLY=".*"
|
||||
OUTPUT_DIR="./static"
|
||||
SITEMAP_FILE="./static/sitemap.txt"
|
||||
while [[ "$1" != "" ]]; do
|
||||
case "$1" in
|
||||
"--force") FORCE="yes";;
|
||||
"--help") echo $USAGE; exit 0;;
|
||||
"--clean") CLEAN="yes";;
|
||||
"--only") shift; ONLY="$1";;
|
||||
"--output") shift; OUTPUT_DIR="$1";;
|
||||
"--sitemap") shift; SITEMAP_FILE="$1";;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
SCRIPT='/tmp/prerender_script.coffee'
|
||||
cat > $SCRIPT <<END
|
||||
url = require('system').args[1]
|
||||
page = require('webpage').create()
|
||||
path = "#{url}".replace(/http:\/\/[^/]*/, '').replace(/^\//, '')
|
||||
localUrl = "http://local.crafting-guide.com:8000/#{path}"
|
||||
|
||||
page.open localUrl, (status)->
|
||||
if status isnt 'success'
|
||||
console.error "Could not load #{url}"
|
||||
phantom.exit(1)
|
||||
|
||||
setTimeout (->
|
||||
console.log page.content
|
||||
phantom.exit(0)
|
||||
), 5000
|
||||
END
|
||||
|
||||
if [[ "$CLEAN" == "yes" ]]; then
|
||||
find "$OUTPUT_DIR/browse" -name "*.html" | xargs rm
|
||||
fi
|
||||
|
||||
cat $SITEMAP_FILE | grep "$ONLY" | while read URL; do
|
||||
OUTPUT_FILE=$(sed 's/http:\/\/[^/]*\///' <<< $URL)
|
||||
OUTPUT_FILE="$OUTPUT_DIR/$OUTPUT_FILE/index.html"
|
||||
OUTPUT_FILE=$(sed 's/\/\//\//' <<< $OUTPUT_FILE)
|
||||
|
||||
if [[ ! -e "$OUTPUT_FILE" || "$FORCE" == "yes" ]]; then
|
||||
mkdir -p $(dirname "$OUTPUT_FILE")
|
||||
echo "prerendering $URL into $OUTPUT_FILE"
|
||||
phantomjs --web-security=false --load-images=false $SCRIPT "$URL" >"$OUTPUT_FILE" 2>/dev/null
|
||||
if [[ "$?" != "0" ]]; then
|
||||
echo "An error occured rendering $URL"
|
||||
rm "$OUTPUT_FILE" 2>/dev/null
|
||||
fi
|
||||
else
|
||||
echo "Skipping $URL..."
|
||||
fi
|
||||
done
|
||||
|
||||
rm $SCRIPT
|
||||
@@ -1,51 +0,0 @@
|
||||
#!/usr/bin/env coffee
|
||||
|
||||
global._ = require 'underscore'
|
||||
global.Backbone = require 'backbone'
|
||||
|
||||
ModVersion = require '../src/coffee/models/mod_version'
|
||||
ModVersionParser = require '../src/coffee/models/mod_version_parser'
|
||||
fs = require 'fs'
|
||||
{Logger} = require 'crafting-guide-common'
|
||||
|
||||
require '../src/coffee/underscore_mixins'
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
if process.argv.length is 3
|
||||
sourceFileName = process.argv[2]
|
||||
targetFileName = process.argv[2]
|
||||
else if process.argv.length is 4
|
||||
sourceFileName = process.argv[2]
|
||||
targetFileName = process.argv[3]
|
||||
else
|
||||
console.error """
|
||||
|
||||
USAGE: reformat <source> (<target>)
|
||||
|
||||
Reformats a given recipe book into the latest version of the recipe book
|
||||
format. This includes alphabetizing entries, simplifying item lists, and
|
||||
upgrading to the latest version.
|
||||
|
||||
If given a single argument, the named file will be replaced with the
|
||||
reformatted version. If two arguments are given, then the output will be
|
||||
written to the second file. If a "-" is given as the second file, the
|
||||
output will be written to stdout.
|
||||
|
||||
"""
|
||||
process.exit -1
|
||||
|
||||
global.logger = new Logger level:Logger.WARNING
|
||||
|
||||
try
|
||||
text = fs.readFileSync sourceFileName, 'UTF-8'
|
||||
parser = new ModVersionParser model:new ModVersion modSlug:'', version:''
|
||||
modVersion = parser.parse text
|
||||
text = parser.unparse(modVersion).trim().replace(/^\s\s*$/gm, '')
|
||||
|
||||
if targetFileName is '-'
|
||||
console.log text
|
||||
else
|
||||
fs.writeFileSync targetFileName, text, encoding:'UTF-8'
|
||||
catch e
|
||||
console.error e.stack
|
||||
@@ -1,34 +0,0 @@
|
||||
#!/usr/bin/env coffee
|
||||
|
||||
global._ = require 'underscore'
|
||||
global.Backbone = require 'backbone'
|
||||
|
||||
fs = require 'fs'
|
||||
Logger = require '../src/scripts/logger'
|
||||
ModVersionParser = require '../src/scripts/models/mod_version_parser'
|
||||
|
||||
require '../src/scripts/underscore_mixins'
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
if process.argv.length is 3
|
||||
sourceFileName = process.argv[2]
|
||||
else
|
||||
console.error """
|
||||
|
||||
USAGE: verify <source>
|
||||
|
||||
Verifies that a recipe book is in the proper format. If there is a problem,
|
||||
then a message will be displayed. Otherwise, the command has no output.
|
||||
|
||||
"""
|
||||
process.exit -1
|
||||
|
||||
global.logger = new Logger level:Logger.WARNING
|
||||
|
||||
try
|
||||
text = fs.readFileSync sourceFileName, 'UTF-8'
|
||||
parser = new ModVersionParser showAllErrors:true
|
||||
modVersion = parser.parse text
|
||||
catch e
|
||||
console.error e.message
|
||||
Reference in New Issue
Block a user