Skip to content

Commit

Permalink
Generate a NPM module in dist folder when running build.
Browse files Browse the repository at this point in the history
  • Loading branch information
gcornut committed Dec 13, 2018
1 parent 9506084 commit b8cebd9
Show file tree
Hide file tree
Showing 13 changed files with 20,404 additions and 64 deletions.
63 changes: 44 additions & 19 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
set -e

SOURCE_FOLDER="./src"
JS_SOURCE=${SOURCE_FOLDER}"/js/main.js"
LESS_SOURCE="${SOURCE_FOLDER}/less/cropOntologyWidget.less"

BUILD_FOLDER="./dist"
MODULES="./node_modules"

Expand All @@ -10,46 +13,68 @@ MODULES="./node_modules"
exit 1;
}

build() {
[ -d "${BUILD_FOLDER}" ] && rm -rf "${BUILD_FOLDER}"/*
mkdir -p "${BUILD_FOLDER}"
build_module() {
# Prepare NPM module to be imported in GPDS
MODULE_FOLDER="${BUILD_FOLDER}/module"
mkdir -p "${MODULE_FOLDER}"
DEST_MODULE="${MODULE_FOLDER}/cropOntologyWidget.module"

echo "NPM module:"

# JS (export widget for ES6 import)
echo -e "[JS]\t ${JS_SOURCE} => ${DEST_MODULE}.js "
"${MODULES}/browserify/bin/cmd.js" "${JS_SOURCE}" -t babelify --debug -o "${DEST_MODULE}.js" -s CropOntologyWidget

JS_FILES=${SOURCE_FOLDER}"/js/main.js"
LESS_FILES="${SOURCE_FOLDER}/less/main.less"
# CSS
echo -e "[CSS]\t ${LESS_SOURCE} => ${DEST_MODULE}.css "
cp "${DEST_FILE}.css" "${DEST_MODULE}.css"

# Style images
cp ${MODULES}/jstree/dist/themes/default/*.{png,gif} "${MODULE_FOLDER}"

echo ""
}

build_bundle() {
# Run browserify => Bundle widget and its dependencies into one file
echo "Bundling:"
DEST_FILE="${BUILD_FOLDER}/cropOntologyWidget"

echo -ne "[JS]\t"
echo " ${JS_FILES} => ${DEST_FILE}.js "
"${MODULES}/browserify/bin/cmd.js" "${JS_FILES}" -t babelify --debug -o "${DEST_FILE}.js" &
"${MODULES}/browserify/bin/cmd.js" "${JS_FILES}" -t babelify --debug -o "${DEST_FILE}.bundle.js" -s CropOntologyWidget &
echo -e "[JS]\t ${JS_SOURCE} => ${DEST_FILE}.js "
"${MODULES}/browserify/bin/cmd.js" "${JS_SOURCE}" -t babelify --debug -o "${DEST_FILE}.js" &
# the '--debug' option adds source mapping for easier debugging in web inspector

echo -ne "[CSS]\t"
echo " ${LESS_FILES} => ${DEST_FILE}.css "
#"${MODULES}/npm-css/bin/npm-css" "${LESS_FILES}" -o "${DEST_FILE}.css"
"${MODULES}/less/bin/lessc" "${LESS_FILES}" "${DEST_FILE}.css" &
"${MODULES}/less/bin/lessc" "${SOURCE_FOLDER}/less/widget.less" "${BUILD_FOLDER}/widget.css" &
wait
echo -e "[CSS]\t ${LESS_SOURCE} => ${DEST_FILE}.css "
"${MODULES}/less/bin/lessc" "${LESS_SOURCE}" "${DEST_FILE}.css" &

echo ""
wait
}

build_minify() {
# Run uglify => Reduce file size
echo "Minifying:"
DEST_MIN_FILE="${BUILD_FOLDER}/cropOntologyWidget.min"

echo -ne "[JS]\t"
echo " ${DEST_FILE}.js => ${DEST_MIN_FILE}.js "
echo -e "[JS]\t ${DEST_FILE}.js => ${DEST_MIN_FILE}.js "
"${MODULES}/.bin/uglifyjs" "${DEST_FILE}.js" -o "${DEST_MIN_FILE}.js" &

echo -ne "[CSS]\t"
echo " ${DEST_FILE}.css => ${DEST_MIN_FILE}.css "
echo -e "[CSS]\t ${DEST_FILE}.css => ${DEST_MIN_FILE}.css "
"${MODULES}/.bin/cleancss" "${DEST_FILE}.css" -o "${DEST_MIN_FILE}.css" &
wait

echo ""
}

build() {
[ -d "${BUILD_FOLDER}" ] && rm -rf "${BUILD_FOLDER}"/*
mkdir -p "${BUILD_FOLDER}"

build_bundle

build_minify

build_module

cp -R ./demo/* "${BUILD_FOLDER}"
}
Expand Down
3 changes: 0 additions & 3 deletions dist/cropOntologyWidget.bundle.js

This file was deleted.

4 changes: 2 additions & 2 deletions dist/cropOntologyWidget.css
Git LFS file not shown
4 changes: 2 additions & 2 deletions dist/cropOntologyWidget.js
Git LFS file not shown
4 changes: 2 additions & 2 deletions dist/cropOntologyWidget.min.css
Git LFS file not shown
Binary file added dist/module/32px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dist/module/40px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit b8cebd9

Please sign in to comment.