From 9c6dc9094ab15adce7e2af5044da829b493fb8a7 Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Fri, 15 Dec 2017 11:27:22 -0800 Subject: [PATCH 1/3] Add postinstall step to build lib and dist if they don't already exist. - Update build scripts to use pwd in paths. --- package.json | 8 ++++---- scripts/compile-clean.sh | 4 +++- scripts/compile-eui.sh | 20 +++++++++++--------- scripts/compile-init.sh | 12 ++++++++++++ scripts/compile-scss.sh | 13 +++++++++---- scripts/compile.sh | 8 +++++--- src/webpack.config.js | 4 ++-- 7 files changed, 46 insertions(+), 23 deletions(-) create mode 100755 scripts/compile-init.sh diff --git a/package.json b/package.json index 61e33753d15..921e805ecad 100644 --- a/package.json +++ b/package.json @@ -10,13 +10,15 @@ "sync-docs": "./scripts/docs-sync.sh", "build-docs": "./scripts/docs-build.sh", "build": "./scripts/compile.sh", + "build-init": "./scripts/compile-init.sh", "lint": "./scripts/lint.sh", "lint-fix": "./scripts/lint-fix.sh", "test": "./scripts/test.sh", "test-unit": "./scripts/test-unit.sh", "yo-component": "yo ./generator-eui/app/component.js", "yo-doc": "yo ./generator-eui/app/documentation.js", - "release": "./scripts/release.sh" + "release": "./scripts/release.sh", + "postinstall": "npm run build-init" }, "dependencies": { "brace": "0.10.0", @@ -32,9 +34,7 @@ "react-ace": "5.5.0", "serve": "6.3.1", "tabbable": "1.1.0", - "uuid": "3.1.0" - }, - "devDependencies": { + "uuid": "3.1.0", "@elastic/eslint-config-kibana": "0.13.0", "autoprefixer": "7.1.5", "babel-cli": "6.26.0", diff --git a/scripts/compile-clean.sh b/scripts/compile-clean.sh index 5b0f27d423b..baabf9fc261 100755 --- a/scripts/compile-clean.sh +++ b/scripts/compile-clean.sh @@ -2,4 +2,6 @@ set -e -rm -rf dist lib +eui="$(pwd)" + +rm -rf "${eui}/dist" "${eui}/lib" diff --git a/scripts/compile-eui.sh b/scripts/compile-eui.sh index ebcd05a63bb..2ce89898d12 100755 --- a/scripts/compile-eui.sh +++ b/scripts/compile-eui.sh @@ -2,11 +2,13 @@ set -e +eui="$(pwd)" + compile_lib() { local color_green="\033[0;32m" local color_reset="\033[0m" - mkdir -p lib/components lib/services lib/test + mkdir -p "${eui}/lib/components" "${eui}/lib/services" "${eui}/lib/test" # We use tput below to save the cursor position, then restore it later in # order to overwrite "processing" messages. @@ -15,30 +17,30 @@ compile_lib() { echo -n " Compiling src/ to lib/ " >&2 babel \ --quiet \ - --out-dir=lib \ + --out-dir="${eui}/lib" \ --ignore "**/webpack.config.js,**/*.test.js" \ - src + "${eui}/src" tput rc echo -e "${color_green}✔ Finished compiling src/ to lib/${color_reset}" >&2 # Also copy over SVGs. Babel has a --copy-files option but that brings over # all kinds of things we don't want into the lib folder. - mkdir -p lib/components/icon/assets - for SVG in $(cd src && find components -name \*.svg); do - cp "src/$SVG" "lib/$SVG" + mkdir -p "${eui}/lib/components/icon/assets" + for SVG in $(cd "${eui}/src" && find components -name \*.svg); do + cp "${eui}/src/$SVG" "${eui}/lib/$SVG" done echo -e "${color_green}✔ Finished copying SVGs${color_reset}" >&2 } compile_bundle() { - mkdir -p dist + mkdir -p "${eui}/dist" echo -e "\nBuilding bundle...\n" >&2 - webpack --config=src/webpack.config.js + webpack --config="${eui}/src/webpack.config.js" echo -e "\nBuilding minified bundle...\n" >&2 - NODE_ENV=production webpack --config=src/webpack.config.js + NODE_ENV=production webpack --config="${eui}/src/webpack.config.js" } compile_lib diff --git a/scripts/compile-init.sh b/scripts/compile-init.sh new file mode 100755 index 00000000000..da455bf8022 --- /dev/null +++ b/scripts/compile-init.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +set -e + +eui="$(pwd)" + +if [ ! -d "${eui}/lib" ]; then + # Only compile the distributable code if doesn't already exist. This is useful for projects + # which depend upon a GitHub branch of EUI instead of an NPM-published version. + "${eui}/scripts/compile-scss.sh" + "${eui}/scripts/compile-eui.sh" +fi diff --git a/scripts/compile-scss.sh b/scripts/compile-scss.sh index 71cb0952952..c89411676b8 100755 --- a/scripts/compile-scss.sh +++ b/scripts/compile-scss.sh @@ -2,9 +2,14 @@ set -e -mkdir -p dist +eui="$(pwd)" -for THEME in src/theme_*.scss; do - node-sass "$THEME" > "dist/eui_$(basename "$THEME" .scss).css" - postcss --replace --config src-docs/postcss.config.js "dist/eui_$(basename "$THEME" .scss).css" +mkdir -p "${eui}/dist" + +src="${eui}/src/theme_*.scss" + +for THEME in $src; do + dest="${eui}/dist/eui_$(basename "$THEME" .scss).css" + node-sass "$THEME" > "$dest" + postcss --replace --config "${eui}/src-docs/postcss.config.js" "$dest" done diff --git a/scripts/compile.sh b/scripts/compile.sh index aa4766405ae..36f52717667 100755 --- a/scripts/compile.sh +++ b/scripts/compile.sh @@ -2,6 +2,8 @@ set -e -./scripts/compile-clean.sh -./scripts/compile-scss.sh -./scripts/compile-eui.sh +eui="$(pwd)" + +"${eui}/scripts/compile-clean.sh" +"${eui}/scripts/compile-scss.sh" +"${eui}/scripts/compile-eui.sh" diff --git a/src/webpack.config.js b/src/webpack.config.js index d506d0b336d..2874f34c7de 100644 --- a/src/webpack.config.js +++ b/src/webpack.config.js @@ -43,11 +43,11 @@ module.exports = { loaders: [{ test: /\.js$/, loader: 'babel-loader', - exclude: /node_modules/ + include: path.resolve(__dirname, '../src'), }, { test: /\.scss$/, loaders: ['style-loader', 'css-loader', 'postcss-loader', 'sass-loader'], - exclude: /node_modules/ + include: path.resolve(__dirname, '../src'), }, { test: /\.(woff|woff2|ttf|eot|ico|png|gif|jpg|jpeg)(\?|$)/, loader: 'file-loader', From b43e6888b9af7636039c9d7be947967ebf48f20e Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Tue, 19 Dec 2017 15:25:06 -0800 Subject: [PATCH 2/3] Remove postinstall script. --- package.json | 4 +--- scripts/compile-init.sh | 12 ------------ 2 files changed, 1 insertion(+), 15 deletions(-) delete mode 100755 scripts/compile-init.sh diff --git a/package.json b/package.json index 921e805ecad..1111385c417 100644 --- a/package.json +++ b/package.json @@ -10,15 +10,13 @@ "sync-docs": "./scripts/docs-sync.sh", "build-docs": "./scripts/docs-build.sh", "build": "./scripts/compile.sh", - "build-init": "./scripts/compile-init.sh", "lint": "./scripts/lint.sh", "lint-fix": "./scripts/lint-fix.sh", "test": "./scripts/test.sh", "test-unit": "./scripts/test-unit.sh", "yo-component": "yo ./generator-eui/app/component.js", "yo-doc": "yo ./generator-eui/app/documentation.js", - "release": "./scripts/release.sh", - "postinstall": "npm run build-init" + "release": "./scripts/release.sh" }, "dependencies": { "brace": "0.10.0", diff --git a/scripts/compile-init.sh b/scripts/compile-init.sh deleted file mode 100755 index da455bf8022..00000000000 --- a/scripts/compile-init.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -set -e - -eui="$(pwd)" - -if [ ! -d "${eui}/lib" ]; then - # Only compile the distributable code if doesn't already exist. This is useful for projects - # which depend upon a GitHub branch of EUI instead of an NPM-published version. - "${eui}/scripts/compile-scss.sh" - "${eui}/scripts/compile-eui.sh" -fi From d344da80cc88dd4a184aeb35ae4c8c4ed2a0cc54 Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Tue, 19 Dec 2017 15:35:59 -0800 Subject: [PATCH 3/3] Scripts accept an -e flag for the path to EUI, which defaults to pwd. --- scripts/compile-clean.sh | 8 ++++++++ scripts/compile-eui.sh | 8 ++++++++ scripts/compile-scss.sh | 8 ++++++++ scripts/compile.sh | 8 ++++++++ 4 files changed, 32 insertions(+) diff --git a/scripts/compile-clean.sh b/scripts/compile-clean.sh index baabf9fc261..c7b31970d5f 100755 --- a/scripts/compile-clean.sh +++ b/scripts/compile-clean.sh @@ -4,4 +4,12 @@ set -e eui="$(pwd)" +while getopts 'e:' arg +do + case ${arg} in + e) eui=${OPTARG};; + *) return 1 # illegal option + esac +done + rm -rf "${eui}/dist" "${eui}/lib" diff --git a/scripts/compile-eui.sh b/scripts/compile-eui.sh index 2ce89898d12..f5b1fdb1cc9 100755 --- a/scripts/compile-eui.sh +++ b/scripts/compile-eui.sh @@ -4,6 +4,14 @@ set -e eui="$(pwd)" +while getopts 'e:' arg +do + case ${arg} in + e) eui=${OPTARG};; + *) return 1 # illegal option + esac +done + compile_lib() { local color_green="\033[0;32m" local color_reset="\033[0m" diff --git a/scripts/compile-scss.sh b/scripts/compile-scss.sh index c89411676b8..a59da8c6eee 100755 --- a/scripts/compile-scss.sh +++ b/scripts/compile-scss.sh @@ -4,6 +4,14 @@ set -e eui="$(pwd)" +while getopts 'e:' arg +do + case ${arg} in + e) eui=${OPTARG};; + *) return 1 # illegal option + esac +done + mkdir -p "${eui}/dist" src="${eui}/src/theme_*.scss" diff --git a/scripts/compile.sh b/scripts/compile.sh index 36f52717667..1c37d089d71 100755 --- a/scripts/compile.sh +++ b/scripts/compile.sh @@ -4,6 +4,14 @@ set -e eui="$(pwd)" +while getopts 'e:' arg +do + case ${arg} in + e) eui=${OPTARG};; + *) return 1 # illegal option + esac +done + "${eui}/scripts/compile-clean.sh" "${eui}/scripts/compile-scss.sh" "${eui}/scripts/compile-eui.sh"