Skip to content

Commit

Permalink
Let's start our project ! :)
Browse files Browse the repository at this point in the history
  • Loading branch information
ageorges-nbb committed Feb 9, 2018
1 parent 389b9dd commit de680f4
Show file tree
Hide file tree
Showing 12 changed files with 368 additions and 49 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,12 @@ end_of_line = crlf
[{package.json,.travis.yml}]
indent_style = space
indent_size = 2

[**.{css, pcss, scss}]
indent_style = space
indent_size = 2

[*.md]
insert_final_newline = false
trim_trailing_whitespace = false

58 changes: 32 additions & 26 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
.DS_STORE

# Build
/dist/
bazel-*
e2e_test.*
node_modules
bower_components
tools/gulp-tasks/cldr/cldr-data/

# Include when developing application packages.
pubspec.lock
.c9
.idea/
.settings/
*.swo
modules/.settings
.vscode
modules/.vscode
!dist/

# Reports directory
reports/

# NPM
package-lock.json

# Don't check in secret files
*secret.js
# Logs
./logs/
*.log

# Ignore npm/yarn debug log
npm-debug.log
yarn-error.log
# Node
node_modules/

# OS generated files #
Desktop.ini
Thumbs.db
.DS_Store
ehthumbs.db
Icon?

# JetBrains IDEs
*.iml
.idea/
.webstorm/
*.swp

# build-analytics
.build-analytics
# Sublime text
.sublime-gulp.cache

# rollup-test output
/modules/rollup-test/dist/
# Runtime data
pids
*.pid
*.seed
181 changes: 181 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
readonly currentDir=$(cd $(dirname $0); pwd)

# TODO(i): wrap into subshell, so that we don't pollute CWD, but not yet to minimize diff collision with Jason
cd ${currentDir}

PACKAGES=(build)

BUILD_ALL=true
BUNDLE=true
VERSION_PREFIX=$(node -p "require('./package.json').version")
VERSION_SUFFIX="-$(git log --oneline -1 | awk '{print $1}')"
CONTRIBUTORS=$(node -p "require('./package.json').contributors")

# TODO Check build.sh script from angular for publish, compile, ...

#######################################
# Verifies a directory isn't in the ignored list
# Arguments:
# param1 - Path to check
# Returns:
# Boolean
#######################################
isIgnoredDirectory() {
name=$(basename ${1})
if [[ -f "${1}" || "${name}" == "src" || "${name}" == "test" || "${name}" == "integrationtest" || "${name}" == "locales" ]]; then
return 0
else
return 1
fi
}

#######################################
# Check if array contains an element
# Arguments:
# param1 - Element to check
# param2 - Array to look for element in
# Returns:
# None
#######################################
containsElement () {
local e
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
return 1
}

#######################################
# Recursively compile package
# Arguments:
# param1 - Source directory
# param2 - Out dir
# param3 - Package Name
# Returns:
# None
#######################################
compilePackage() {
# For TSC_PACKAGES items
if containsElement "${3}" "${TSC_PACKAGES[@]}"; then
echo "====== [${3}]: COMPILING: ${TSC} -p ${1}/tsconfig-build.json"
$TSC -p ${1}/tsconfig-build.json
else
echo "====== [${3}]: COMPILING: ${NGC} -p ${1}/tsconfig-build.json"
local package_name=$(basename "${2}")
$NGC -p ${1}/tsconfig-build.json
if [[ "${package_name}" != "locales" ]]; then
echo "====== Create ${1}/../${package_name}.d.ts re-export file for tsickle"
echo "$(cat ${LICENSE_BANNER}) ${N} export * from './${package_name}/${package_name}'" > ${2}/../${package_name}.d.ts
echo "{\"__symbolic\":\"module\",\"version\":3,\"metadata\":{},\"exports\":[{\"from\":\"./${package_name}/${package_name}\"}],\"flatModuleIndexRedirect\":true}" > ${2}/../${package_name}.metadata.json
fi
fi

# Build subpackages
for DIR in ${1}/* ; do
[ -d "${DIR}" ] || continue
BASE_DIR=$(basename "${DIR}")
# Skip over directories that are not nested entry points
[[ -e ${DIR}/tsconfig-build.json && "${BASE_DIR}" != "integrationtest" ]] || continue
compilePackage ${DIR} ${2}/${BASE_DIR} ${3}
done
}

#######################################
# Adds a package.json in directories where needed (secondary entry point typings).
# This is read by NGC to be able to find the flat module index.
# Arguments:
# param1 - Source directory of typings files
# Returns:
# None
#######################################
addNgcPackageJson() {
for DIR in ${1}/* ; do
[ -d "${DIR}" ] || continue
# Confirm there is an ${PACKAGE}.d.ts and ${PACKAGE}.metadata.json file. If so, create
# the package.json and recurse.
if [[ -f ${DIR}/${PACKAGE}.d.ts && -f ${DIR}/${PACKAGE}.metadata.json ]]; then
echo '{"typings": "${PACKAGE}.d.ts"}' > ${DIR}/package.json
addNgcPackageJson ${DIR}
fi
done
}

updateVersionReferences() {
NPM_DIR="$1"
(
echo "====== VERSION: Updating version references in ${NPM_DIR}"
cd ${NPM_DIR}
echo "====== EXECUTE: perl -p -i -e \"s/0\.0\.0\-PLACEHOLDER/${VERSION}/g\" $""(grep -ril 0\.0\.0\-PLACEHOLDER .)"
perl -p -i -e "s/0\.0\.0\-PLACEHOLDER/${VERSION}/g" $(grep -ril 0\.0\.0\-PLACEHOLDER .) < /dev/null 2> /dev/null
)
}

for PACKAGE in ${PACKAGES[@]}
do
PWD=`pwd`
ROOT_DIR=${PWD}/packages
SRC_DIR=${ROOT_DIR}/${PACKAGE}
ROOT_OUT_DIR=${PWD}/dist/packages
OUT_DIR=${ROOT_OUT_DIR}/${PACKAGE}
NPM_DIR=${PWD}/dist/packages-dist/${PACKAGE}
ESM5_DIR=${NPM_DIR}/esm5

LICENSE_BANNER=${ROOT_DIR}/license-banner.txt

if [[ ${COMPILE_SOURCE} == true ]]; then
rm -rf ${OUT_DIR}
rm -f ${ROOT_OUT_DIR}/${PACKAGE}.js
compilePackage ${SRC_DIR} ${OUT_DIR} ${PACKAGE}
fi

if [[ ${BUNDLE} == true ]]; then
echo "====== BUNDLING ${PACKAGE}: ${SRC_DIR} ====="
rm -rf ${NPM_DIR} && mkdir -p ${NPM_DIR}

if ! containsElement "${PACKAGE}" "${NODE_PACKAGES[@]}"; then

echo "====== Copy ${PACKAGE} typings"
rsync -a --exclude=*.js --exclude=*.js.map ${OUT_DIR}/ ${NPM_DIR}

(
cd ${SRC_DIR}
echo "====== Rollup ${PACKAGE}"
rollupIndex ${OUT_DIR} ${ESM2015_DIR} ${PACKAGE}

echo "====== Produce ESM5 version"
compilePackageES5 ${SRC_DIR} ${OUT_DIR_ESM5} ${PACKAGE}
rollupIndex ${OUT_DIR_ESM5} ${ESM5_DIR} ${PACKAGE}

echo "====== Run rollup conversions on ${PACKAGE}"
runRollup ${SRC_DIR}
addBanners ${BUNDLES_DIR}
minify ${BUNDLES_DIR}

if [[ -e ${SRC_DIR}/build.sh ]]; then
echo "====== Custom build for ${PACKAGE}"
cd ${SRC_DIR} && ${SRC_DIR}/build.sh
fi

) 2>&1 | grep -v "as external dependency"

if [[ ${PACKAGE} == "common" ]]; then
echo "====== Copy i18n locale data"
rsync -a ${OUT_DIR}/locales/ ${NPM_DIR}/locales
fi
else
echo "====== Copy ${PACKAGE} node tool"
rsync -a ${OUT_DIR}/ ${NPM_DIR}
fi

echo "====== Copy ${PACKAGE} package.json and .externs.js files"
rsync -am --include="package.json" --include="*/" --exclude=* ${SRC_DIR}/ ${NPM_DIR}/
rsync -am --include="*.externs.js" --include="*/" --exclude=* ${SRC_DIR}/ ${NPM_DIR}/

cp ${ROOT_DIR}/README.md ${NPM_DIR}/
fi


if [[ -d ${NPM_DIR} ]]; then
updateVersionReferences ${NPM_DIR}
fi

travisFoldEnd "build package: ${PACKAGE}"
done
51 changes: 51 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "stark-srcs",
"version": "10.0.0-alpha.0",
"private": false,
"author": {
"name": "Alexis Georges",
"email": "alexis.georges@nbb.be",
"url": "https://nbb.be"
},
"contributors": [
{
"name": "Dubois Sebastien",
"email": "sebastien.dubois@nbb.be",
"url": "https://www.nbb.be"
},
{
"name": "Cedric Namotte",
"email": "cedric.namotte@nbb.be",
"url": "https://www.nbb.be"
},
{
"name": "Alexis Georges",
"email": "alexis.georges@nbb.be",
"url": "https://www.nbb.be"
},
{
"name": "Christopher Cortes",
"email": "christopher.cortes@nbb.be",
"url": "https://www.nbb.be"
},
{
"name": "Robby De Laet",
"email": "robby.delaet@nbb.be",
"url": "https://www.nbb.be"
}
],
"license": "MIT",
"engines": {
"node": ">=6.11.0",
"npm": ">=5.3.0"
},
"bugs": "https://github.com/nationalbankbelgium/stark/issues",
"homepage": "https://github.com/nationalbankbelgium/stark",
"repository": {
"type": "git",
"url": "https://github.com/nationalbankbelgium/stark.git"
},
"dependencies": {
"typescript": "2.6.2"
}
}
10 changes: 1 addition & 9 deletions packages/build/config/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const EVENT = process.env.npm_lifecycle_event || '';
*/
// const ROOT = path.resolve(__dirname, '..');
const _root = path.resolve(process.cwd(), "."); // project root folder
const _rootStark = path.resolve(process.cwd(), "node_modules/@nationalbankbelgium/stark"); // stark root folder
const _rootStark = path.resolve(process.cwd(), "node_modules/@nationalbankbelgium/stark-build"); // stark root folder

function hasProcessFlag(flag) {
return process.argv.join('').indexOf(flag) > -1;
Expand All @@ -24,14 +24,6 @@ function isWebpackDevServer() {
return process.argv[1] && !! (/webpack-dev-server/.exec(process.argv[1]));
}

// function rootStark(args){
// args = Array.prototype.slice.call(arguments, 0);
// //console.log("dirname "+ __dirname);
// //console.log("process.cwd " + process.cwd());
// //console.log("stark path: ",path.join.apply(path, [_rootStark].concat(args)));
// return path.join.apply(path, [_rootStark].concat(args));
// }

const root = path.join.bind(path, _root);
const rootStark = path.join.bind(path, _rootStark);

Expand Down
7 changes: 5 additions & 2 deletions packages/build/config/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* @author: @AngularClass
*/

const helpers = require('./helpers');

module.exports = function (config) {
var testWebpackConfig = require('./webpack.test.js')();

Expand Down Expand Up @@ -34,7 +36,7 @@ module.exports = function (config) {
* we are building the test environment in ./spec-bundle.js
*/
files: [
{ pattern: './config/spec-bundle.js', watched: false },
{ pattern: helpers.rootStark('./config/spec-bundle.js'), watched: false },
{ pattern: './src/assets/**/*', watched: false, included: false, served: true, nocache: false }
],

Expand All @@ -49,7 +51,8 @@ module.exports = function (config) {
* Preprocess matching files before serving them to the browser
* available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
*/
preprocessors: { './config/spec-bundle.js': ['coverage', 'webpack', 'sourcemap'] },
// TODO Change this absolute path to a relative one (with helpers ?)
preprocessors: { './node_modules/@nationalbankbelgium/stark-build/config/spec-bundle.js': ['coverage', 'webpack', 'sourcemap'] },

/**
* Webpack Config at ./webpack.test.js
Expand Down
3 changes: 2 additions & 1 deletion packages/build/config/spec-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ testing.TestBed.initTestEnvironment(
* any file that ends with spec.ts and get its path. By passing in true
* we say do this recursively
*/
var testContext = require.context('../src', true, /\.spec\.ts/);
// TODO Use helpers for getting the path :)
var testContext = require.context('../../../../src', true, /\.spec\.ts/);

/**
* Get all the files, for each file, call the context function
Expand Down
2 changes: 1 addition & 1 deletion packages/build/config/webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const SourceMapDevToolPlugin = require('webpack/lib/SourceMapDevToolPlugin');
const WriteFilePlugin = require("write-file-webpack-plugin");

// Dev custom config
const webpackCustomConfig = require(helpers.root("app-config/webpack-custom-config.dev.json"));
const webpackCustomConfig = require(helpers.root("config/webpack-custom-config.dev.json"));

/**
* Webpack configuration
Expand Down
Loading

0 comments on commit de680f4

Please sign in to comment.