2018-12-12 18:39:14 -05:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -eux -o pipefail
|
2019-02-20 12:58:42 -05:00
|
|
|
|
2020-02-04 14:45:40 -05:00
|
|
|
# sedi makes `sed -i` work on both OSX & Linux
|
|
|
|
# See https://stackoverflow.com/questions/2320564/i-need-my-sed-i-command-for-in-place-editing-to-work-with-both-gnu-sed-and-bsd
|
|
|
|
function sedi () {
|
|
|
|
case $(uname) in
|
|
|
|
Darwin*) sedi=('-i' '') ;;
|
|
|
|
*) sedi='-i' ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
sed "${sedi[@]}" "$@"
|
|
|
|
}
|
|
|
|
|
2019-02-20 12:58:42 -05:00
|
|
|
function installLocalPackages() {
|
|
|
|
# Install Angular packages that are built locally from HEAD.
|
|
|
|
# This also gets around the bug whereby yarn caches local `file://` urls.
|
|
|
|
# See https://github.com/yarnpkg/yarn/issues/2165
|
|
|
|
readonly pwd=$(pwd)
|
|
|
|
readonly packages=(
|
|
|
|
animations common compiler core forms platform-browser
|
2019-04-25 19:38:45 -04:00
|
|
|
platform-browser-dynamic router bazel compiler-cli language-service
|
2019-02-20 12:58:42 -05:00
|
|
|
)
|
|
|
|
local local_packages=()
|
|
|
|
for package in "${packages[@]}"; do
|
2020-02-04 14:45:40 -05:00
|
|
|
local_packages+=("@angular/${package}@file:${pwd}/../node_modules/@angular/${package}")
|
2019-02-20 12:58:42 -05:00
|
|
|
done
|
2019-10-01 19:44:50 -04:00
|
|
|
|
2020-02-14 20:23:05 -05:00
|
|
|
# keep protractor, typescript, tslib, and @types/node versions in sync with the ones used in this repo
|
|
|
|
local_packages+=("protractor@file:${pwd}/../node_modules/protractor")
|
2020-02-04 14:45:40 -05:00
|
|
|
local_packages+=("typescript@file:${pwd}/../node_modules/typescript")
|
|
|
|
local_packages+=("tslib@file:${pwd}/../node_modules/tslib")
|
|
|
|
local_packages+=("@types/node@file:${pwd}/../node_modules/@types/node")
|
2019-10-01 19:44:50 -04:00
|
|
|
|
2020-02-14 20:23:05 -05:00
|
|
|
# add protractor, puppeteer & webdriver-manager so we get the chrome & chromedriver binaries
|
|
|
|
# that have already been downloaded at the root
|
|
|
|
local_packages+=("puppeteer@file:${pwd}/../node_modules/puppeteer")
|
|
|
|
local_packages+=("webdriver-manager@file:${pwd}/../node_modules/webdriver-manager")
|
|
|
|
|
2020-03-05 14:01:20 -05:00
|
|
|
yarn add --ignore-scripts --silent "${local_packages[@]}" --cache-folder ./.yarn_local_cache
|
2019-02-20 12:58:42 -05:00
|
|
|
}
|
2018-12-12 18:39:14 -05:00
|
|
|
|
2020-02-14 20:23:05 -05:00
|
|
|
function patchKarmaConf() {
|
|
|
|
sedi "s#module.exports#process.env.CHROME_BIN = require\('puppeteer'\).executablePath\(\); module.exports#" ./karma.conf.js
|
2020-02-04 14:45:40 -05:00
|
|
|
sedi "s#browsers\: \['Chrome'\],#customLaunchers\: \{ ChromeHeadlessNoSandbox\: \{ base\: 'ChromeHeadless', flags\: \['--no-sandbox', '--headless', '--disable-gpu', '--disable-dev-shm-usage', '--hide-scrollbars', '--mute-audio'\] \} \}, browsers\: \['ChromeHeadlessNoSandbox'\],#" ./karma.conf.js
|
|
|
|
}
|
|
|
|
|
2020-02-14 20:23:05 -05:00
|
|
|
function patchProtractorConf() {
|
|
|
|
sedi "s#browserName\: 'chrome'#browserName\: 'chrome', chromeOptions\: \{ binary: require\('puppeteer'\).executablePath\(\), args: \['--no-sandbox', '--headless', '--disable-gpu', '--disable-dev-shm-usage', '--hide-scrollbars', '--mute-audio'\] \},#" ./e2e/protractor.conf.js
|
2020-02-04 14:45:40 -05:00
|
|
|
}
|
2019-08-20 13:52:31 -04:00
|
|
|
|
2018-12-18 18:44:13 -05:00
|
|
|
function testBazel() {
|
2018-12-12 18:39:14 -05:00
|
|
|
# Set up
|
|
|
|
bazel version
|
2019-01-28 14:03:04 -05:00
|
|
|
ng version
|
2018-12-12 18:39:14 -05:00
|
|
|
rm -rf demo
|
|
|
|
# Create project
|
2019-03-27 12:58:59 -04:00
|
|
|
ng new demo --collection=@angular/bazel --routing --skip-git --skip-install --style=scss
|
2018-12-12 18:39:14 -05:00
|
|
|
cd demo
|
2020-03-05 14:01:20 -05:00
|
|
|
# Use a local yarn cache folder so we don't access the global yarn cache
|
|
|
|
mkdir .yarn_local_cache
|
2020-02-14 20:23:05 -05:00
|
|
|
patchKarmaConf
|
|
|
|
patchProtractorConf
|
2019-02-20 12:58:42 -05:00
|
|
|
installLocalPackages
|
2019-01-17 16:21:31 -05:00
|
|
|
ng generate component widget --style=css
|
2019-01-24 14:51:20 -05:00
|
|
|
ng build
|
2018-12-17 16:17:13 -05:00
|
|
|
ng test
|
|
|
|
ng e2e
|
2019-03-18 19:44:03 -04:00
|
|
|
ng e2e --prod
|
2019-03-06 20:50:57 -05:00
|
|
|
if [ -e 'WORKSPACE' ] || [ -e 'BUILD.bazel' ]; then
|
|
|
|
echo 'WORKSPACE / BUILD.bazel file should not exist in project'
|
|
|
|
exit 1
|
|
|
|
fi
|
2018-12-12 18:39:14 -05:00
|
|
|
}
|
|
|
|
|
2018-12-18 18:44:13 -05:00
|
|
|
function testNonBazel() {
|
|
|
|
# Replace angular.json that uses Bazel builder with the default generated by CLI
|
2019-01-28 14:03:04 -05:00
|
|
|
mv ./angular.json.bak ./angular.json
|
2018-12-18 18:44:13 -05:00
|
|
|
rm -rf dist src/main.dev.ts src/main.prod.ts
|
2019-10-01 19:44:50 -04:00
|
|
|
# disable CLI's version check (if version is 0.0.0, then no version check happens)
|
|
|
|
yarn --cwd node_modules/@angular/cli version --new-version 0.0.0 --no-git-tag-version
|
2019-10-16 19:28:09 -04:00
|
|
|
# re-add build-angular
|
2020-03-05 14:01:20 -05:00
|
|
|
yarn add --dev file:../node_modules/@angular-devkit/build-angular --cache-folder ./.yarn_local_cache
|
2019-01-04 13:27:09 -05:00
|
|
|
ng build --progress=false
|
|
|
|
ng test --progress=false --watch=false
|
2020-02-04 14:45:40 -05:00
|
|
|
ng e2e --port 0 --configuration=production --webdriver-update=false
|
2018-12-18 18:44:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
testBazel
|
2019-10-16 19:28:09 -04:00
|
|
|
|
|
|
|
# this test verifies that users can undo bazel - the value of this is questionable
|
|
|
|
# because there are way too many manual steps and it would be easier for users to
|
|
|
|
# just revert the diff created by `ng add @angular/bazel`
|
2018-12-18 18:44:13 -05:00
|
|
|
testNonBazel
|