build: add stylesheet, JS minification

This commit is contained in:
Ben Goldsworthy 2021-04-24 10:58:25 +01:00
parent 2d23541f06
commit e029c121b8
5 changed files with 606 additions and 57 deletions

View file

@ -17,57 +17,26 @@ if [[ $1 == "-c" ]]; then
echo "Concatenating files and placing in \`tmp/css/\`..."
mkdir -p ./tmp/css
cat ./src/css/dev-common.css > ./tmp/css/tmp/footnotes-nottbrpl0.css
cat ./src/css/dev-{common,layout-reference-container}.css > ./tmp/css/tmp/footnotes-nottbrpl1.css
cat ./src/css/dev-{common,layout-entry-content}.css > ./tmp/css/tmp/footnotes-nottbrpl2.css
cat ./src/css/dev-{common,layout-main-content}.css > ./tmp/css/tmp/footnotes-nottbrpl3.css
cat ./src/css/dev-{common,tooltips}.css > ./tmp/css/tmp/footnotes-jqttbrpl0.css
cat ./src/css/dev-{common,tooltips,layout-reference-container}.css > ./tmp/css/tmp/footnotes-jqttbrpl1.css
cat ./src/css/dev-{common,tooltips,layout-entry-content}.css > ./tmp/css/tmp/footnotes-jqttbrpl2.css
cat ./src/css/dev-{common,tooltips,layout-main-content}.css > ./tmp/css/tmp/footnotes-jqttbrpl3.css
cat ./src/css/dev-{common,tooltips,tooltips-alternative}.css > ./tmp/css/tmp/footnotes-alttbrpl0.css
cat ./src/css/dev-{common,tooltips,tooltips-alternative,layout-reference-container}.css > ./tmp/css/tmp/footnotes-alttbrpl1.css
cat ./src/css/dev-{common,tooltips,tooltips-alternative,layout-entry-content}.css > ./tmp/css/tmp/footnotes-alttbrpl2.css
cat ./src/css/dev-{common,tooltips,tooltips-alternative,layout-main-content}.css > ./tmp/css/tmp/footnotes-alttbrpl3.css
cat ./src/css/settings.css > ./tmp/css/tmp/settings.css
cat ./src/css/dev-common.css > ./tmp/css/footnotes-nottbrpl0.css
cat ./src/css/dev-{common,layout-reference-container}.css > ./tmp/css/footnotes-nottbrpl1.css
cat ./src/css/dev-{common,layout-entry-content}.css > ./tmp/css/footnotes-nottbrpl2.css
cat ./src/css/dev-{common,layout-main-content}.css > ./tmp/css/footnotes-nottbrpl3.css
cat ./src/css/dev-{common,tooltips}.css > ./tmp/css/footnotes-jqttbrpl0.css
cat ./src/css/dev-{common,tooltips,layout-reference-container}.css > ./tmp/css/footnotes-jqttbrpl1.css
cat ./src/css/dev-{common,tooltips,layout-entry-content}.css > ./tmp/css/footnotes-jqttbrpl2.css
cat ./src/css/dev-{common,tooltips,layout-main-content}.css > ./tmp/css/footnotes-jqttbrpl3.css
cat ./src/css/dev-{common,tooltips,tooltips-alternative}.css > ./tmp/css/footnotes-alttbrpl0.css
cat ./src/css/dev-{common,tooltips,tooltips-alternative,layout-reference-container}.css > ./tmp/css/footnotes-alttbrpl1.css
cat ./src/css/dev-{common,tooltips,tooltips-alternative,layout-entry-content}.css > ./tmp/css/footnotes-alttbrpl2.css
cat ./src/css/dev-{common,tooltips,tooltips-alternative,layout-main-content}.css > ./tmp/css/footnotes-alttbrpl3.css
cat ./src/css/settings.css > ./tmp/css/settings.css
echo "Stylesheet concatenation complete."
exit 0
elif [[ $1 == "-m" ]]; then
# TODO: this should automatically minifiy all files, outputting into `.min.css`
# files and deleting the original concatenated `.css` files in `css/tmp/`.
# Once that's done, we can change the `rm -r` command in the deploy step to
# `rmdir`, which will throw us an error if we have any minified files that
# haven't been moved over to `dist/css/` for whatever reason. As it currently
# stands, we have no error checking in place.
echo "Please minify the stylesheets in \`tmp/css/\`, saving them in the same location with the \`.min.css\` file extension."
read -p "Are you ready to continue? (Y/N): " CONFIRM && [[ $CONFIRM == [yY] || $CONFIRM == [yY][eE][sS] ]] || exit 1
exit 0
elif [[ $1 == "-d" ]]; then
# NOTE: I've temporarily replaced the `mv` command
# with `cp` and disabled the `rm` command, so the minified
# files won't be removed from the source directory.
echo "Deploying minified stylesheets to \`dist/css/\`..."
mkdir -p ./dist/css
for f in ./tmp/css/*.min.css; do
filename=$(basename $f .css)
cp $f ./dist/css
#mv $f ./dist/css
echo -e '\t' $filename".css moved."
done
#echo "Deleting temporary files..."
#rm -r ./tmp/css/tmp
echo "All stylesheets added to build."
exit 0
else
echo -e "Concatenates, minifies (TODO) and deploys stylesheets for distribution.\n"
echo -e "Concatenates stylesheets ready for distribution.\n"
echo -e "12 unified style sheets are concatenated out of these files:\n"
echo "\`dev-common.css\`"
echo "\`dev-tooltips.css\`"
@ -76,8 +45,6 @@ else
echo "\`dev-layout-entry-content.css\`"
echo -e "\`dev-layout-main-content.css\`\n"
echo "Command: \`-c\`: Concatenate \`dev-*\` CSS files into temporary directory."
echo "Command: \`-m\`: Minify files (TODO)."
echo "Command: \`-d\`: Deploy minified files to \`dist/css/\` and remove temporary files."
echo "No command, \"--help\", or anything else: Output this help section."
fi

View file

@ -6,13 +6,13 @@ echo "Building Plugin..."
echo "Copying directories..."
rm -r dist/
mkdir dist
cp -r -t dist src/{class,js,languages,templates}/
cp -r -t dist src/{class,languages,templates}/
# Among the images, only 2 out of 3 are distributed.
echo "Copying the needed images..."
mkdir -p dist/img
cp -t dist/img src/img/fn-wysiwyg.png
echo "Copying files..."
cp -t dist src/{license.txt,readme.txt,includes.php,wpml-config.xml,SECURITY.md,CHANGELOG.md}
cp -t dist ./{SECURITY.md,CHANGELOG.md,wpml-config.xml} src/{license.txt,readme.txt,includes.php}
echo "Setting production flag..."
sed "s/'PRODUCTION_ENV', false/'PRODUCTION_ENV', true/g" src/footnotes.php > dist/footnotes.php
echo "Production flag set."
@ -23,13 +23,13 @@ echo "Production flag set."
echo "Building stylesheets..."
./_tools/build-stylesheets.sh -c
if [ $? != 0 ]; then echo "Concatenation failed!"; exit 1; fi
if [[ $1 != "-y" ]]; then
./_tools/build-stylesheets.sh -m
if [ $? != 0 ]; then echo "Minification failed!"; exit 1; fi
fi
./_tools/build-stylesheets.sh -d
if [ $? != 0 ]; then echo "Deployment failed!"; exit 1; fi
echo "Stylesheet build complete."
echo "Minifying CSS and JS..."
mkdir -p dist/{css,js}
npm run minify
if [ $? != 0 ]; then echo "Minification failed!"; exit 1; fi
echo "Minification complete."
echo "Build complete."
exit 0