Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script to help with building as packages and fix devkit and package info #4529

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,6 @@ go-vendor-*.tgz
website/build
website/site-dist
website/.docusaurus

# Npm package builds
/npm_pkg
274 changes: 274 additions & 0 deletions build/ngbuild.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
#!/usr/bin/env bash

# Build the front-end packages ready

# This should be moved into devkit at some point as a library builder

# Script folder
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
STRATOS="`cd "${DIR}/..";pwd`"

# Colours
CYAN="\033[96m"
YELLOW="\033[93m"
RED="\033[91m"
RESET="\033[0m"
BOLD="\033[1m"

BUILD="false"
PUBLISH="false"
UNPUBLISH="false"
LINK="false"
INSTALL_LINKS="false"

function show_help() {

echo
echo -e "${CYAN}${BOLD}ngbuild - tool to help build Stratos as packages${RESET}"
echo
echo -e "Run with: ${BOLD}build/ngbuild.sh <Flags> <Packages>${RESET}"
echo
echo "Flags can be:"
echo
echo " -b Build packages"
echo " -p Publish packages to npm"
echo " -u Unpublish packages from npm"
echo " -l Link packages using npm link"
echo " -i Install linked packages into node_modules"
echo
echo "With no packages specified, all are used, otherwise you can specify one or more of:"
echo " core"
echo " store"
echo " devkit"
echo " theme"
echo " shared"
echo
}

while getopts "hbpuli" opt; do
case $opt in
h)
show_help
exit 0
;;
b)
BUILD="true"
;;
p)
PUBLISH="true"
;;
u)
UNPUBLISH="true"
;;
l)
LINK="true"
;;
i)
INSTALL_LINKS="true"
;;
esac
done

shift $(expr $OPTIND - 1 )

PKGS="$@"
if [ -z "$PKGS" ]; then
PKGS="shared store devkit theme core"
fi

echo -e "${CYAN}${BOLD}=============================${RESET}"
echo -e "${CYAN}${BOLD}= Building Stratos packages =${RESET}"
echo -e "${CYAN}${BOLD}=============================${RESET}"

# ===================================================================================================
# Store
# ===================================================================================================

function build_store() {
echo
echo -e "${YELLOW}${BOLD}= Package: @stratosui/store${RESET}"
echo

ng build store

rm -rf ${STRATOS}/npm_pkg/store
cp -r ${STRATOS}/dist/store ${STRATOS}/npm_pkg

# Patch version number
jq '.version = "'${VERSION}'"' ${STRATOS}/npm_pkg/store/package.json > ${STRATOS}/npm_pkg/store/package.json.up
# Remove script
jq '.scripts = {}' ${STRATOS}/npm_pkg/store/package.json.up > ${STRATOS}/npm_pkg/store/package.json
}

# ===================================================================================================
# Shared
# ===================================================================================================

function build_shared() {
echo
echo -e "${YELLOW}${BOLD}= Package: @stratosui/shared${RESET}"
echo

ng build shared

rm -rf ${STRATOS}/npm_pkg/shared
cp -r ${STRATOS}/dist/shared ${STRATOS}/npm_pkg

# Patch version number
jq '.version = "'${VERSION}'"' ${STRATOS}/npm_pkg/shared/package.json > ${STRATOS}/npm_pkg/shared/package.json.up
# Remove script
jq '.scripts = {}' ${STRATOS}/npm_pkg/shared/package.json.up > ${STRATOS}/npm_pkg/shared/package.json
rm ${STRATOS}/npm_pkg/shared/package.json.up

# Need to copy other files - sass files for shared
cp -r ${STRATOS}/src/frontend/packages/shared/sass ${STRATOS}/npm_pkg/shared/sass
}

# ===================================================================================================
# Theme
# ===================================================================================================

function build_theme() {
echo
echo -e "${YELLOW}${BOLD}= Package: @stratosui/theme${RESET}"
echo

pushd ${STRATOS} > /dev/null
ng build theme
popd > /dev/null

rm -rf ${STRATOS}/npm_pkg/theme
cp -r ${STRATOS}/dist/theme ${STRATOS}/npm_pkg

# Patch version number
jq '.version = "'${VERSION}'"' ${STRATOS}/npm_pkg/theme/package.json > ${STRATOS}/npm_pkg/theme/package.json.up
mv ${STRATOS}/npm_pkg/theme/package.json.up ${STRATOS}/npm_pkg/theme/package.json
}

# ===================================================================================================
# Devkit
# ===================================================================================================

function build_devkit() {
echo
echo -e "${YELLOW}${BOLD}= Package: @stratosui/devkit${RESET}"
echo

npm run build-devkit

rm -rf ${STRATOS}/npm_pkg/devkit
cp -r ${STRATOS}/dist-devkit ${STRATOS}/npm_pkg/devkit

# Patch version number
jq '.version = "'${VERSION}'"' ${STRATOS}/npm_pkg/devkit/package.json > ${STRATOS}/npm_pkg/devkit/package.json.up
jq '.scripts = {}' ${STRATOS}/npm_pkg/devkit/package.json.up > ${STRATOS}/npm_pkg/devkit/package.json
rm ${STRATOS}/npm_pkg/devkit/package.json.up
}

# ===================================================================================================
# Core
# ===================================================================================================

function build_core {
echo
echo -e "${YELLOW}${BOLD}= Package: @stratosui/core${RESET}"
echo

rm -rf ${STRATOS}/npm_pkg/core
mkdir -p ${STRATOS}/npm_pkg/core
cp -r ${STRATOS}/src/frontend/packages/core/ ${STRATOS}/npm_pkg

# Some files/folder we don't need
rm -rf ${STRATOS}/npm_pkg/core/test-framework
rm -rf ${STRATOS}/npm_pkg/core/tsconfig.spec.json
rm -rf ${STRATOS}/npm_pkg/core/tsconfig.lib.json

# Patch version
jq '.version = "'${VERSION}'"' ${STRATOS}/npm_pkg/core/package.json > ${STRATOS}/npm_pkg/core/package.json.up
mv ${STRATOS}/npm_pkg/core/package.json.up ${STRATOS}/npm_pkg/core/package.json

# Delete node_modules
rm -rf ${STRATOS}/npm_pkg/core/node_modules

# Delete test files
rm -f ${STRATOS}/npm_pkg/core/src/test.ts
find ${STRATOS}/npm_pkg/core/src -type f -name "*.spec.ts" -delete

# Dev files
mkdir ${STRATOS}/npm_pkg/core/dev
cp ${STRATOS}/dev-ssl/server.* ${STRATOS}/npm_pkg/core/dev/
cp ${STRATOS}/proxy.conf.js ${STRATOS}/npm_pkg/core/dev/
}

echo -e "${CYAN}${BOLD}Packages: $PKGS${RESET}"
VERSION=$(cat "${STRATOS}/package.json" | jq -r .version)
echo -e "${CYAN}Current version: ${BOLD}${VERSION}${RESET}"

if [ ${BUILD} == "true" ]; then
echo
echo -e "${CYAN}${BOLD}Building packages to ${STRATOS}/npm_pkg${RESET}"
mkdir -p ${STRATOS}/npm_pkg
for pkg in $PKGS
do
BUILD_TARGET="build_$pkg"
$BUILD_TARGET
done
fi

if [ "${UNPUBLISH}" == "true" ]; then
for PKG in "$PKGS"
do
echo
echo -e "${YELLOW}${BOLD}= Unpublishing package: @stratosui/${PKG}${RESET}"
echo
npm unpublish "@stratosui/${PKG}@${VERSION}"
done
fi

if [ ${PUBLISH} == "true" ]; then
echo
echo -e "${CYAN}${BOLD}Publishing packages to npm${RESET}"
echo

for PKG in $PKGS
do # Delete test files
rm -f ${STRATOS}/npm_pkg/core/src/test.ts
find ${STRATOS}/npm_pkg/core/src -type f -name "*.spec.ts" -delete
echo
echo -e "${YELLOW}${BOLD}= Publishing package: @stratosui/${PKG}${RESET}"
echo
pushd ${STRATOS}/npm_pkg/$PKG > /dev/null
npm publish --access public
popd > /dev/null
done
fi

# Run npm link
if [ ${LINK} == "true" ]; then
echo
echo -e "${CYAN}${BOLD}Linking packages${RESET}"
echo

for PKG in $PKGS
do
echo -e "${YELLOW}${BOLD}= Linking package: @stratosui/${PKG}${RESET}"
pushd ${STRATOS}/npm_pkg/$PKG > /dev/null
npm link
popd > /dev/null
done
fi

# Run npm link for each of the packages to install them in the node_modules folder
if [ ${INSTALL_LINKS} == "true" ]; then
echo
echo -e "${CYAN}${BOLD}NPM Linking packages${RESET}"
echo

for PKG in $PKGS
do
echo -e "${YELLOW}${BOLD}= NPM Linking package: @stratosui/${PKG}${RESET}"
npm link @stratosui/${PKG}
done
fi


48 changes: 48 additions & 0 deletions src/frontend/packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,54 @@
{
"name": "@stratosui/core",
"version": "0.0.1",
"description": "Stratos Core",
"license": "Apache-2.0",
"repository": "https://github.com/cloudfoundry/stratos",
"dependencies": {
"@angular/animations": "^9.1.6",
"@angular/cdk": "^9.2.3",
"@angular/common": "^9.1.6",
"@angular/compiler": "^9.1.6",
"@angular/core": "^9.1.6",
"@angular/flex-layout": "^9.0.0-beta.29",
"@angular/forms": "^9.1.6",
"@angular/material": "^9.2.3",
"@angular/material-moment-adapter": "^9.2.3",
"@angular/platform-browser": "^9.1.6",
"@angular/platform-browser-dynamic": "^9.1.6",
"@angular/platform-server": "^9.1.6",
"@angular/router": "^9.1.6",
"@ngrx/effects": "^9.1.2",
"@ngrx/router-store": "^9.1.2",
"@ngrx/store": "^9.1.2",
"@ngrx/store-devtools": "^9.1.2",
"@swimlane/ngx-charts": "^13.0.3",
"@types/moment-timezone": "^0.5.13",
"@types/marked": "^0.7.4",
"angular2-virtual-scroll": "^0.4.16",
"core-js": "^3.6.5",
"immer": "^6.0.3",
"lodash-es": "^4.17.14",
"mappy-breakpoints": "^0.2.3",
"marked": "^0.8.2",
"intersect": "^1.0.1",
"moment": "^2.24.0",
"moment-timezone": "^0.5.28",
"ngrx-store-localstorage": "9.0.0",
"ngx-moment": "^3.5.0",
"normalizr": "^3.6.0",
"reselect": "^4.0.0",
"rxjs": "^6.5.5",
"rxjs-spy": "^7.0.2",
"rxjs-websockets": "~8.0.1",
"@cfstratos/ajsf-material": "^0.1.5",
"ts-md5": "^1.2.7",
"tslib": "^1.10.0",
"web-animations-js": "^2.3.2",
"xterm": "^4.5.0",
"xterm-addon-fit": "^0.3.0",
"zone.js": "~0.10.2"
},
"stratos": {
"assets": {
"assets": "core/assets"
Expand Down
5 changes: 4 additions & 1 deletion src/frontend/packages/devkit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"name": "@stratosui/devkit",
"version": "0.0.1",
"description": "Stratos Development Kit for apps and extensions",
"license": "Apache-2.0",
"repository": "https://github.com/cloudfoundry/stratos",
"scripts": {
"build": "tsc && node build.js",
"tsc": "tsc"
Expand All @@ -11,7 +14,7 @@
"typescript": "~3.8.2"
},
"devDependencies": {
"@angular-devkit/architect": "^1.0.0"
"@angular-devkit/architect": "^0.901.7"
},
"builders": "builders/builders.json",
"schematics": "./schematics/collection.json"
Expand Down
4 changes: 3 additions & 1 deletion src/frontend/packages/devkit/src/build/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ class StratosBuilder {
constructor(public webpackConfig, public options) { }

public run() {
const dir = this.webpackConfig.context || __dirname;

// Read in the Stratos config file if present (and do so config initialization)
const sConfig = new StratosConfig(__dirname, this.options);
const sConfig = new StratosConfig(dir, this.options);

// Sass handler for themes and themable packages
const sass = new SassHandler();
Expand Down
10 changes: 8 additions & 2 deletions src/frontend/packages/devkit/src/lib/packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,14 @@ const isDirectory = source => {
const stats = fs.lstatSync(realPath);
return stats.isDirectory();
}
const getDirectories = source =>
fs.readdirSync(source).map(name => path.join(source, name)).filter(isDirectory);

const getDirectories = source => {
if (!fs.existsSync(source)) {
return [];
}

return fs.readdirSync(source).map(name => path.join(source, name)).filter(isDirectory);
}

// Default theme to use
export const DEFAULT_THEME = '@stratosui/theme';
Expand Down
3 changes: 3 additions & 0 deletions src/frontend/packages/shared/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"name": "@stratosui/shared",
"version": "0.0.1",
"description": "Stratos Shared Components",
"license": "Apache-2.0",
"repository": "https://github.com/cloudfoundry/stratos",
"peerDependencies": {
"@angular/common": "^8.2.9",
"@angular/core": "^8.2.9"
Expand Down
Loading