From d6683bac30d52c44cd79b025ea2be3afa60ae11a Mon Sep 17 00:00:00 2001 From: Alexis Georges Date: Mon, 12 Mar 2018 15:17:07 +0100 Subject: [PATCH] feat(stark-build) Remove config-stark files + Refactor tsconfig + Fix ts issues (#244) * feat(stark-build) tsconfig moved in stark-build * feat(stark-build) Remove config-stark files + Refactor tsconfig + Fix ts issues * Add Karma-Typescript Reformat ignore files Fix ts issues Change templateUrl by template * Move karma typescript config in stark-build --- .dockerignore | 39 +++ .gitignore | 24 +- packages/stark-build/config-stark/helpers.js | 122 ------- .../stark-build/config-stark/postpublish.js | 8 - .../stark-build/config-stark/prepublish.js | 0 .../config-stark/stark.dev-demo.js | 108 ------ packages/stark-build/config-stark/tagger.js | 64 ---- .../config-stark/webpack.common-data.js | 113 ------- .../config-stark/webpack.common.js | 295 ----------------- .../stark-build/config-stark/webpack.dev.js | 313 ------------------ .../stark-build/config-stark/webpack.prod.js | 193 ----------- packages/stark-build/config/build-utils.js | 4 +- packages/stark-build/config/helpers.js | 24 +- .../json-server.common.js | 0 packages/stark-build/config/karma.conf.js | 63 +++- .../config/karma.conf.typescript.js | 76 +++++ .../{config-stark => config}/nightly-build.js | 0 packages/stark-build/config/webpack.common.js | 74 +++-- packages/stark-build/config/webpack.dev.js | 26 +- packages/stark-build/config/webpack.prod.js | 3 +- packages/stark-build/config/webpack.test.js | 6 +- starter/.gitattributes | 1 - starter/.gitignore | 76 ++--- starter/.nvmrc | 1 - starter/LICENSE | 21 -- starter/base.spec.ts | 18 + starter/docker-compose.yml | 14 - starter/karma.conf.js | 4 - starter/karma.conf.typescript.js | 4 + starter/package.json | 14 +- .../+child-barrel/child-barrel.module.ts | 4 +- starter/src/app/+barrel/barrel.module.ts | 4 +- .../+child-detail/child-detail.module.ts | 4 +- starter/src/app/+detail/detail.module.ts | 4 +- .../src/app/+dev-module/dev-module.module.ts | 4 +- starter/src/app/about/about.component.spec.ts | 1 - starter/src/app/about/about.component.ts | 16 +- starter/src/app/app.component.spec.ts | 2 +- starter/src/app/app.component.ts | 2 +- starter/src/app/app.e2e.ts | 16 +- starter/src/app/app.module.ts | 5 +- starter/src/app/app.routes.ts | 4 +- starter/src/app/app.service.ts | 4 +- starter/src/app/home/home.component.spec.ts | 11 +- starter/src/app/home/home.component.ts | 2 +- starter/src/app/home/home.e2e.ts | 8 +- .../src/app/home/title/title.service.spec.ts | 5 +- .../home/x-large/x-large.directive.spec.ts | 3 +- starter/src/custom-typings.d.ts | 8 +- starter/src/main.browser.ts | 2 +- starter/tsconfig.app.json | 15 + starter/tsconfig.json | 20 +- starter/tsconfig.spec.json | 19 ++ starter/tsconfig.webpack.json | 8 - 54 files changed, 417 insertions(+), 1462 deletions(-) create mode 100644 .dockerignore delete mode 100644 packages/stark-build/config-stark/helpers.js delete mode 100644 packages/stark-build/config-stark/postpublish.js delete mode 100644 packages/stark-build/config-stark/prepublish.js delete mode 100644 packages/stark-build/config-stark/stark.dev-demo.js delete mode 100644 packages/stark-build/config-stark/tagger.js delete mode 100644 packages/stark-build/config-stark/webpack.common-data.js delete mode 100644 packages/stark-build/config-stark/webpack.common.js delete mode 100644 packages/stark-build/config-stark/webpack.dev.js delete mode 100644 packages/stark-build/config-stark/webpack.prod.js rename packages/stark-build/{config-stark => config}/json-server.common.js (100%) create mode 100644 packages/stark-build/config/karma.conf.typescript.js rename packages/stark-build/{config-stark => config}/nightly-build.js (100%) delete mode 100644 starter/.gitattributes delete mode 100644 starter/.nvmrc delete mode 100644 starter/LICENSE create mode 100644 starter/base.spec.ts delete mode 100644 starter/docker-compose.yml create mode 100644 starter/karma.conf.typescript.js create mode 100644 starter/tsconfig.app.json create mode 100644 starter/tsconfig.spec.json delete mode 100644 starter/tsconfig.webpack.json diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000..24f1eaae6f --- /dev/null +++ b/.dockerignore @@ -0,0 +1,39 @@ +.git +.github +.vscode +coverage + +# OS generated files # +.DS_Store +ehthumbs.db +Icon? +Thumbs.db + +# Node Files # +node_modules +npm-debug.log +npm-debug.log.* + +# Typing # +src/typings/tsd +typings +tsd_typings + +# Dist # +dist +.awcache +.webpack.json +compiled +dll + +# IDE # +.idea +*.swp + + +# Angular # +*.ngfactory.ts +*.css.shim.ts +*.ngsummary.json +*.shim.ngstyle.ts + diff --git a/.gitignore b/.gitignore index 89df5d5532..58f40d2a3b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,9 @@ # Build -/dist/ +dist/ +.awcache/ +dist/ +.tmp/ +/.tmp/ # Reports directory reports/ @@ -8,14 +12,24 @@ reports/ package-lock.json # Logs -./logs/ +logs/ *.log +# Runtime data +pids +*.pid +*.seed + +# Coverage directory used by tools like istanbul +coverage + # Bak *.bak # Node node_modules/ +npm-debug.log +/npm-debug.log.* # OS generated files # Desktop.ini @@ -40,3 +54,9 @@ pids # Patch files *.patch + +# Angular # +*.ngfactory.ts +*.css.shim.ts +*.ngsummary.json +*.shim.ngstyle.ts diff --git a/packages/stark-build/config-stark/helpers.js b/packages/stark-build/config-stark/helpers.js deleted file mode 100644 index 6af1dc9c6a..0000000000 --- a/packages/stark-build/config-stark/helpers.js +++ /dev/null @@ -1,122 +0,0 @@ -"use strict"; - -const path = require("path"); - -// Helper functions -// dirname is equals to the location of the script that is running -// cwd is the process current working directory -const _root = path.resolve(process.cwd(), "."); // project root folder -const _rootStark = path.resolve(process.cwd(), "node_modules/@nationalbankbelgium/stark"); // stark root folder - -function hasProcessFlag(flag) { - return process.argv.join("").indexOf(flag) > -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)); -} - -function root(args) { - args = Array.prototype.slice.call(arguments, 0); - //console.log("dirname "+ __dirname); - //console.log("process.cwd " + process.cwd()); - //console.log("app path: ",path.join.apply(path, [_root].concat(args))); - return path.join.apply(path, [_root].concat(args)); -} - -function rootNode(args) { - args = Array.prototype.slice.call(arguments, 0); - return root.apply(path, ["node_modules"].concat(args)); -} - -function prependExt(extensions, args) { - args = args || []; - if (!Array.isArray(args)) { - args = [args]; - } - return extensions.reduce( - (memo, val) => { - return memo.concat( - val, - args.map(prefix => { - return prefix + val; - }) - ); - }, - [""] - ); -} - -function packageSort(packages) { - const len = packages.length - 1; - const first = packages[0]; - const last = packages[len]; - return function sort(a, b) { - // polyfills always first - if (a.names[0] === first) { - return -1; - } - // main always last - if (a.names[0] === last) { - return 1; - } - // vendor before app - if (a.names[0] !== first && b.names[0] === last) { - return -1; - } else { - return 1; - } - // a must be equal to b - return 0; - }; -} - -function reverse(arr) { - return arr.reverse(); -} - -/** - * Method for removing object properties - */ -const removeObjectProperties = (obj, props) => { - for (let i = 0; i < props.length; i++) { - if (obj.hasOwnProperty(props[i])) { - delete obj[props[i]]; - } - } -}; - -/** - * Retrieve the relative path from the config directory to the path argument value (if provided). That path argument can be passed to only execute a subset of the unit tests (see spec-bundle.ts) - * @param args the arguments to look into - * @returns {*} The relative path from this directory (config) to the location pointed at by the path argument value (if provided), an empty string otherwise - */ -function getTestPath(args) { - for (let i = 0; i < args.length; ++i) { - if (args[i] === "--path--") { - let providedPath = args[i + 1] || ""; - if (!providedPath.toLocaleLowerCase().startsWith("src/")) { - throw new Error("If you want to execute a subset of the unit tests, then the path you provide MUST start with 'src/'"); - } - //return path.relative(__dirname, providedPath); - // posix style to get the expected path separator - return path.posix.relative(__dirname, providedPath); - } - } - return ""; -} - -exports.reverse = reverse; -exports.hasProcessFlag = hasProcessFlag; -exports.root = root; -exports.rootStark = rootStark; -exports.rootNode = rootNode; -exports.prependExt = prependExt; -exports.prepend = prependExt; -exports.packageSort = packageSort; -exports.getTestPath = getTestPath; -exports.removeObjectProperties = removeObjectProperties; diff --git a/packages/stark-build/config-stark/postpublish.js b/packages/stark-build/config-stark/postpublish.js deleted file mode 100644 index f3171a445b..0000000000 --- a/packages/stark-build/config-stark/postpublish.js +++ /dev/null @@ -1,8 +0,0 @@ -"use strict"; -const spawnSync = require("child_process").spawnSync; - -console.log("Logout from publishConfig registry after publishing..."); - -spawnSync("npm", ["logout", "--registry=http://nexus.prd.nbb:81/repository/nbb-npm-internal/"], { stdio: "inherit", shell: true }); - -console.log("Logout done..."); diff --git a/packages/stark-build/config-stark/prepublish.js b/packages/stark-build/config-stark/prepublish.js deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/packages/stark-build/config-stark/stark.dev-demo.js b/packages/stark-build/config-stark/stark.dev-demo.js deleted file mode 100644 index 9309a389b9..0000000000 --- a/packages/stark-build/config-stark/stark.dev-demo.js +++ /dev/null @@ -1,108 +0,0 @@ -"use strict"; - -const spawn = require("child_process").spawn; -const helpers = require("./helpers"); -const fs = require("fs"); - -var starkAppConfig = require(helpers.root("/src/stark-app-config.json")); -var starkWebpackCustomConfig = require(helpers.root("/config/webpack-custom-config.dev.json")); -var jsonServerBackends = []; - -if (process.argv.length > 2) { - starkAppConfig = getAppConfigCLI(process.argv.slice(2), starkAppConfig); - fs.writeFileSync(helpers.root("/src/stark-app-config.json"), JSON.stringify(starkAppConfig)); - starkWebpackCustomConfig = getWebpackCustomConfigCLI(starkWebpackCustomConfig, jsonServerBackends); - fs.writeFileSync(helpers.root("/config/webpack-custom-config.dev.json"), JSON.stringify(starkWebpackCustomConfig)); -} - -function getAppConfigCLI(args, defaultConfig) { - let backends = []; - let ports = []; - let host = "localhost"; - - args.forEach(arg => { - let param = arg.split("="); - switch (param[0]) { - case "--port": - case "-p": - if (ports.indexOf(param[1]) < 0) { - ports.push(param[1]); - } - break; - case "--host": - case "-h": - host = param[1]; - break; - } - }); - - Object.keys(defaultConfig.backends).forEach(function(property) { - if (defaultConfig.backends[property].mock && defaultConfig.backends[property].mock === "json-server") { - if (ports.length > 0) { - defaultConfig.backends[property].url = "http://" + host + ":" + ports[0]; - backends.push("http://" + host + ":" + ports[0]); - } - if (ports.length > 1) { - ports = ports.slice(1); - } - } - }); - - jsonServerBackends = backends; - return defaultConfig; -} - -function getWebpackCustomConfigCLI(defaultConfig, backends) { - backends.forEach(backend => { - if (defaultConfig["cspConnectSrc"].indexOf(backend) < 0) { - defaultConfig["cspConnectSrc"] += " " + backend; - } - if (defaultConfig["cspFormAction"].indexOf(backend) < 0) { - defaultConfig["cspFormAction"] += " " + backend; - } - }); - - return defaultConfig; -} - -const jsonServer = spawn("npm", ["run", "json-server"], { stdio: "inherit", shell: true }); -jsonServer.on("close", () => { - console.log("caught child's jsonServer close"); - process.kill(); - process.exit(); -}); - -jsonServer.on("exit", () => { - console.log("caught child's jsonServer exit"); - jsonServer.kill(); -}); - -const demoStark = spawn("npm", ["start"], { stdio: "inherit", shell: true }); -demoStark.on("close", () => { - console.log("caught child's " + starkAppConfig.logApplicationId + " close"); - process.kill(); - process.exit(); -}); - -demoStark.on("exit", () => { - console.log("caught child's " + starkAppConfig.logApplicationId + " exit"); - demoStark.kill(); -}); - -process.on("exit", () => { - console.log("caught process exit"); - process.kill(-jsonServer.pid); - process.kill(-demoStark.pid); - jsonServer.kill(); - demoStark.kill(); -}); - -process.on("SIGINT", () => { - jsonServer.kill(); - demoStark.kill(); -}); - -process.on("uncaughtException", () => { - jsonServer.kill(); - demoStark.kill(); -}); diff --git a/packages/stark-build/config-stark/tagger.js b/packages/stark-build/config-stark/tagger.js deleted file mode 100644 index a20a1e8108..0000000000 --- a/packages/stark-build/config-stark/tagger.js +++ /dev/null @@ -1,64 +0,0 @@ -"use strict"; - -// This script will be executed as an npm "preversion" script. -// -// The goal of this script will be to : -// 1) if no local changes -// 2) then create a tag based on the current working copy remote url -const helpers = require("./helpers"); -const packageConfig = require(helpers.root("package.json")); -var Client = require("svn-spawn"); - -const packageName = packageConfig.name.replace("@nationalbankbelgium/", ""); -const packageVersion = packageConfig.version; -var scmRepoUrl = ""; -var tagUrl = ""; - -console.log("package name : %s", packageName); -console.log("package version : %s", packageVersion); - -Client.prototype.svnCopy = function(source, target, callback) { - var self = this; - self.session("silent", true).cmd(["copy", source, target, "-m", "Tagging"], callback); -}; - -var client = new Client({ - cwd: helpers.root("") -}); - -client.status(function(err, data) { - console.log("Checking for local changes..."); - if (data.length != 0) { - console.log("You have local changes, please commit your code before creating a tag..."); - process.exit(1); - } else { - client.getInfo(function(err, data) { - if (!err === null) { - console.log("an error occured in the svn client : %s", err); - } else { - console.log(JSON.stringify(data)); - - scmRepoUrl = data.url; - console.log("Repository url is %s", scmRepoUrl); - if (!!~scmRepoUrl.indexOf("trunk")) { - tagUrl = scmRepoUrl.replace("trunk", "tags"); - tagUrl = tagUrl.concat("/", packageName, "-", packageVersion); - } else { - if (!!~scmRepoUrl.indexOf("branches")) { - tagUrl = scmRepoUrl.replace("branches", "tags"); - tagUrl = tagUrl.substr(0, tagUrl.lastIndexOf("/")); - tagUrl = tagUrl.concat("/", packageName, "-", packageVersion); - } else { - console.log("cannot detect if working copy is a branch or a tag."); - process.exit(1); - } - } - console.log("tag url will be : %s", tagUrl); - client.svnCopy(scmRepoUrl, tagUrl, function(err, data) { - console.log("error is %s", err); - console.log("data is %s", data); - }); - } - }); - } -}); diff --git a/packages/stark-build/config-stark/webpack.common-data.js b/packages/stark-build/config-stark/webpack.common-data.js deleted file mode 100644 index c3162096f2..0000000000 --- a/packages/stark-build/config-stark/webpack.common-data.js +++ /dev/null @@ -1,113 +0,0 @@ -"use strict"; - -// The goal of this module is only to export common configuration data that the different Webpack configuration files use - -// Helpers -const helpers = require("./helpers"); -const path = require("path"); - -//const webpack = require("webpack"); - -// Metadata -const starkAppMetadata = require(helpers.root("src/stark-app-metadata.json")); -const starkAppConfig = require(helpers.root("src/stark-app-config.json")); - -// FIXME: extract other configurations and centralize them here: -// distinguish between dev/test/prod (e.g., ts: { dev: ..., prod: ...} - -module.exports = { - // static data for index.html - starkAppMetadata: starkAppMetadata, - starkAppConfig: starkAppConfig, - - ts: { - // Allows overriding TypeScript options. Should be specified in the same format as you would do for the compilerOptions property in tsconfig.json. - compilerOptions: { - silent: false, // default value: false - compiler: "typescript", // default value: "typescript" - useTranspileModule: false, // default value: false - instance: "at-loader", // default value: "at-loader" - configFileName: "tsconfig.json", // default value: "tsconfig.json" - transpileOnly: false, // default value: false - errorsAsWarnings: false, // default value: false - forceIsolatedModules: false, // default value: false - ignoreDiagnostics: [], // default value: [] - useBabel: false, // default value: false - useCache: false, // default value: false - usePrecompiledFiles: false, // default value: false - cacheDirectory: ".awcache", // default value: ".awcache" - reportFiles: [] // default value: [] - } - }, - - // TSLint configuration - // Static analysis linter for TypeScript advanced options configuration - // Description: An extensible linter for the TypeScript language. - // reference: https://github.com/wbuchwalter/tslint-loader - tslint: { - dev: { - // TSLint errors are displayed by default as warnings - // set emitErrors to true to display them as errors - emitErrors: false, - - // TSLint does not interrupt the compilation by default - // if you want any file with tslint errors to fail - // set failOnHint to true - failOnHint: false, - - resourcePath: helpers.root("src") - - // can be used to customize the path to the directory containing formatter (optional) - //formattersDirectory: helpers.rootStark("node_modules/tslint-loader/formatters/"), - }, - - prod: { - // TSLint errors are displayed by default as warnings - // set emitErrors to true to display them as errors - emitErrors: true, - - // TSLint does not interrupt the compilation by default - // if you want any file with tslint errors to fail - // set failOnHint to true - failOnHint: true, - - resourcePath: helpers.root("src") - - // can be used to customize the path to the directory containing formatter (optional) - //formattersDirectory: helpers.rootStark("node_modules/tslint-loader/formatters/"), - } - }, - - // Html loader for HTML minification (advanced options) - // reference: https://github.com/webpack/html-loader#advanced-options - htmlLoader: { - dev: { - removeAttributeQuotes: false, - caseSensitive: true, - customAttrSurround: [[/#/, /(?:)/], [/\*/, /(?:)/], [/\[?\(?/, /(?:)/]], - customAttrAssign: [/\)?\]?=/] - }, - - prod: { - minimize: true, - removeAttributeQuotes: false, - caseSensitive: true, - customAttrSurround: [[/#/, /(?:)/], [/\*/, /(?:)/], [/\[?\(?/, /(?:)/]], - customAttrAssign: [/\)?\]?=/] - } - }, - - babel: { - presets: [ - [ - "env", - { - targets: { - browsers: ["last 2 versions", "ie >= 11", "Chrome >= 56", "Firefox >= 48", "Safari >= 7"] - }, - modules: false - } - ] - ] - } -}; diff --git a/packages/stark-build/config-stark/webpack.common.js b/packages/stark-build/config-stark/webpack.common.js deleted file mode 100644 index c59b614276..0000000000 --- a/packages/stark-build/config-stark/webpack.common.js +++ /dev/null @@ -1,295 +0,0 @@ -"use strict"; - -const webpack = require("webpack"); - -// Helpers -const helpers = require("./helpers"); - -// Stark App Config -const starkAppConfig = require(helpers.root("src/stark-app-config.json")); - -// Webpack Plugins -const CopyWebpackPlugin = require("copy-webpack-plugin"); -const ExtractTextWebpackPlugin = require("extract-text-webpack-plugin"); -const WebpackSHAHash = require("webpack-sha-hash"); -const LoaderOptionsPlugin = require("webpack/lib/LoaderOptionsPlugin"); -const NoEmitOnErrorsPlugin = require("webpack/lib/NoEmitOnErrorsPlugin"); -const ContextReplacementPlugin = require("webpack/lib/ContextReplacementPlugin"); -// const ModuleConcatenationPlugin = require("webpack/lib/optimize/ModuleConcatenationPlugin"); - -// awesome-typescript-loader specific: -const CheckerPlugin = require("awesome-typescript-loader").CheckerPlugin; -const TsConfigPathsPlugin = require("awesome-typescript-loader").TsConfigPathsPlugin; - -/* - * Config - * reference: https://webpack.js.org/configuration - */ -module.exports = { - stats: { - colors: true, - reasons: true, - errorDetails: true // display error details. Same as the --show-error-details flag - // maxModules: Infinity, // examine all modules (ModuleConcatenationPlugin debugging) - // optimizationBailout: true // display bailout reasons (ModuleConcatenationPlugin debugging) - }, - - // Tell webpack which environment the application is targeting. - // reference: https://webpack.js.org/configuration/target/ - // reference: https://webpack.js.org/concepts/targets/ - target: "web", // <== can be omitted as default is "web" - - // Options affecting the output of the compilation - // reference: https://webpack.js.org/configuration/output - output: { - // Mandatory but not actually useful since everything remains in memory with webpack-dev-server - // reference: https://webpack.js.org/configuration/output/#output-path - path: helpers.root("dist"), - // We need to tell Webpack to serve our bundled application - // from the build path. When proxying: - // http://localhost:3000/ -> http://localhost:8080/ - publicPath: starkAppConfig.baseUrl, - // Adding hashes to files for cache busting - // IMPORTANT: You must not specify an absolute path here! - // reference: https://webpack.js.org/configuration/output/#output-filename - filename: "[name].[hash].bundle.js", - // The filename of the SourceMaps for the JavaScript files. - // They are inside the output.path directory. - // reference: https://webpack.js.org/configuration/output/#output-sourcemapfilename - sourceMapFilename: "[name].[hash].map", - // The filename of non-entry chunks as relative path - // inside the output.path directory. - // reference: https://webpack.js.org/configuration/output/#output-chunkfilename - chunkFilename: "[id].[hash].chunk.js" - }, - - // Options affecting the resolving of modules. - // reference: https://webpack.js.org/configuration/resolve - resolve: { - // an array of extensions that should be used to resolve modules. - // reference: https://webpack.js.org/configuration/resolve/#resolve-extensions - extensions: [".ts", ".js", ".json", ".css", ".pcss", ".html"], - - plugins: [ - // Awesome Typescript Loader - new TsConfigPathsPlugin({ - configFileName: helpers.root("tsconfig.json"), - compiler: "typescript" - }) - ] - }, - - // Options affecting the normal modules. - // reference: https://webpack.js.org/configuration/module - module: { - // An array of applied loaders. - // IMPORTANT: The loaders here are resolved relative to the resource which they are applied to. - // This means they are not resolved relative to the configuration file. - // reference: https://webpack.js.org/configuration/module/#module-rules - rules: [ - // TsLint loader support for *.ts files - // reference: https://github.com/wbuchwalter/tslint-loader - { - enforce: "pre", - test: /\.ts$/, - use: ["tslint-loader"], - exclude: [helpers.root("node_modules"), helpers.rootStark("node_modules")] - }, - - // Source map loader support for *.js files - // Extracts SourceMaps for source files that as added as sourceMappingURL comment. - // reference: https://github.com/webpack/source-map-loader - { - enforce: "pre", - test: /\.js$/, - use: ["source-map-loader"], - exclude: [helpers.rootStark("node_modules/rxjs"), helpers.root("node_modules/rxjs")] - }, - - // Support for CSS as raw text - // reference: https://github.com/webpack/raw-loader - { - test: /\.css$/, - use: ExtractTextWebpackPlugin.extract({ - use: "raw-loader" - }) - }, - - // Support for PostCSS - { - test: /\.pcss$/, - use: ExtractTextWebpackPlugin.extract({ - fallback: "style-loader", - // "use" entries have an "options" property - // but could also have a "query" property which is an alias for the "options" property - // https://webpack.js.org/configuration/module/#useentry - use: [ - { - loader: "css-loader", - options: { - //modules: true, // to check if needed - //minimize: true, - // even if disabled, sourceMaps gets generated - sourceMap: false, // true - autoprefixer: false, - // see https://github.com/webpack-contrib/css-loader#importloaders) - importLoaders: 1 // 1 => postcss-loader - } - }, - { - loader: "postcss-loader", - options: { - sourceMap: true, - plugins: [ - // reference: https://github.com/postcss/postcss-import - // https://github.com/postcss/postcss-import/issues/244 - require("postcss-import")(), - - // plugin to rebase, inline or copy on url(). - // https://github.com/postcss/postcss-url - require("postcss-url")(), - - require("postcss-nesting")(), - require("postcss-simple-extend")(), - require("postcss-cssnext")({ - // see https://github.com/MoOx/postcss-cssnext/issues/268 for example - browsers: ["last 3 versions", "Chrome >= 45"] - }) - ] - } - } - ] - }) - }, - - // Support for .html - { - test: /\.html$/, - use: ["html-loader"], - exclude: [helpers.root("src/index.html")] - } - ] - }, - - // Add additional plugins to the compiler. - // reference: https://webpack.js.org/plugins - plugins: [ - // Plugin: NoEmitOnErrorsPlugin - // Description: Only emit files when there are no errors. - // reference: https://webpack.js.org/plugins/no-emit-on-errors-plugin - new NoEmitOnErrorsPlugin(), - - // Plugin: ForkCheckerPlugin - // Description: Do type checking in a separate process, so webpack don't need to wait. - // reference: https://github.com/s-panferov/awesome-typescript-loader#forkchecker-boolean-defaultfalse - // TODO: remove this in the future depending on the output of https://github.com/webpack/webpack/issues/3460 - new CheckerPlugin(), - - // Plugin: CopyWebpackPlugin - // Description: Copy files and directories in webpack. - // Copies project static assets. - // reference: https://www.npmjs.com/package/copy-webpack-plugin - new CopyWebpackPlugin( - [ - // Stark assets - { - from: helpers.rootStark("assets"), - to: "assets" - }, - // those assets are copied to the root of the target folder - { - from: helpers.rootStark("assets-base"), - to: "" - }, - - // Mdi svg file - { - from: "node_modules/@nationalbankbelgium/angular-mdi-svg/mdi.svg", - to: "assets/icons/mdi.svg" - }, - - // Application assets - { - from: helpers.root("assets"), - to: "assets", - force: "true" // overwrite files already copied from Stark - }, - // those assets are copied to the root of the target folder - { - from: helpers.root("assets-base"), - to: "", - force: "true" // overwrite files already copied from Stark - } - ], - { - ignore: [ - "translations/*", // skip translation since they will be copied in the next round (see block below) - "*.md", - //See https://github.com/kevlened/copy-webpack-plugin/issues/54#issuecomment-223205388 - { - dot: true, - glob: ".svn/**/*" - } - ] - - // By default the plugin only copies modified files during - // a watch or webpack-dev-server build - // Setting this to true copies all files - // copyUnmodified: true - } - ), - - // Plugin: CopyWebpackPlugin - // Description: Copy files and directories in webpack. - // Copies project static assets. - // reference: https://www.npmjs.com/package/copy-webpack-plugin - new CopyWebpackPlugin( - [ - // Stark assets - { - from: helpers.rootStark("assets/translations"), - to: "assets/translations/stark" - }, - - // Application assets - { - from: helpers.root("assets/translations"), - to: "assets/translations/app" - } - ], - {} - ), - - // Plugin: WebpackSHAHash - // Description: Generate SHA content hashes - new WebpackSHAHash(), - - // Plugin: ContextReplacementPlugin - // Description: allows to override the inferred information in a 'require' context - // Including only a certain set of Moment locales - // reference: https://webpack.js.org/plugins/context-replacement-plugin/ - new ContextReplacementPlugin(/moment[\/\\]locale$/, /(de|fr|en-gb|nl|nl-be)\.js/) - - // Webpack 3 feature: scope hoisting - // Description: Hoist or concatenate the scope of all your modules into one closure and allow for your code - // to have a faster execution time in the browser. - // This plugin this allows to concatenate all modules and rename variables in a smart way to fulfill - // the EcmaScript Modules (ESM) spec semantics. - // reference: https://webpack.js.org/plugins/module-concatenation-plugin/ - // reference: https://medium.com/webpack/webpack-3-official-release-15fd2dd8f07b - // reference: https://medium.com/webpack/webpack-freelancing-log-book-week-5-7-4764be3266f5 - // new ModuleConcatenationPlugin() - ], - - // Include polyfills or mocks for various node stuff - // Description: Node configuration - // reference: https://webpack.js.org/configuration/node - node: { - global: true, - process: false, - crypto: "empty", - module: false, - clearImmediate: false, - setImmediate: false - } -}; diff --git a/packages/stark-build/config-stark/webpack.dev.js b/packages/stark-build/config-stark/webpack.dev.js deleted file mode 100644 index c3e1c6b467..0000000000 --- a/packages/stark-build/config-stark/webpack.dev.js +++ /dev/null @@ -1,313 +0,0 @@ -"use strict"; - -const webpack = require("webpack"); - -const webpackMerge = require("webpack-merge"); // Used to merge webpack configs -const commonConfig = require("./webpack.common.js"); // common configuration between environments -const commonData = require("./webpack.common-data.js"); // common configuration between environments - -// Helpers -const helpers = require("./helpers"); - -// Dev custom config -const webpackCustomConfig = require(helpers.root("config/webpack-custom-config.dev.json")); - -// Webpack Plugins -const ExtractTextWebpackPlugin = require("extract-text-webpack-plugin"); -const DefinePlugin = require("webpack/lib/DefinePlugin"); -const CommonsChunkPlugin = require("webpack/lib/optimize/CommonsChunkPlugin"); -const WriteFilePlugin = require("write-file-webpack-plugin"); -const HtmlWebpackPlugin = require("html-webpack-plugin"); -const LoaderOptionsPlugin = require("webpack/lib/LoaderOptionsPlugin"); -const StylelintPlugin = require("stylelint-webpack-plugin"); -const CircularDependencyPlugin = require("circular-dependency-plugin"); -// const UglifyJsPlugin = require("webpack/lib/optimize/UglifyJsPlugin"); - -// Metadata -const METADATA = { - HOST: process.env.HOST || "localhost", - PORT: parseInt(process.env.PORT, 10) || 3000, - ENV: (process.env.ENV = process.env.NODE_ENV = "development"), - HMR: helpers.hasProcessFlag("hot"), - PRODUCTION: false, - DEVELOPMENT: true -}; - -// Directives to be used in CSP header -const cspDirectives = [ - "base-uri 'self'", - "default-src 'self'", - "child-src 'self'", - "connect-src 'self' ws://" + METADATA.HOST + ":" + METADATA.PORT + " " + webpackCustomConfig["cspConnectSrc"], // ws://HOST:PORT" is due to Webpack - "font-src 'self'", - "form-action 'self' " + webpackCustomConfig["cspFormAction"], - "frame-src 'self'", // deprecated. Use child-src instead. Used here because child-src is not yet supported by Firefox. Remove as soon as it is fully supported - "frame-ancestors 'none'", // the app will not be allowed to be embedded in an iframe (roughly equivalent to X-Frame-Options: DENY) - "img-src 'self' data: image/png", // data: image/png" is due to Angular Material loading PNG images in base64 encoding - "media-src 'self'", - "object-src 'self'", - "plugin-types application/pdf", // valid mime-types for plugins invoked via and - "script-src 'self' 'nonce-cefb24121ec5443c8819cc7c5e33c4a2'", - "style-src 'self' 'nonce-cef324d21ec5483c8819cc7a5e33c4a2'" // We define the same nonce value via the $mdThemingProvider (https://material.angularjs.org/HEAD/api/service/$mdThemingProvider) -]; - -/* - * Config - * IMPORTANT: notice that the configuration below is MERGED with the common configuration (commonConfig) - * reference: https://webpack.js.org/configuration - */ -module.exports = webpackMerge(commonConfig, { - // Developer tool to enhance debugging - // reference: https://webpack.js.org/configuration/devtool - // reference: https://github.com/webpack/docs/wiki/build-performance#sourcemaps - devtool: "cheap-module-source-map", - - // the entry point for the bundles - // reference: https://webpack.js.org/configuration/entry-context/#entry - entry: { - // main entries - polyfills: helpers.root("src/polyfills.ts"), - "vendor-styles": helpers.root("src/vendor-styles.ts"), - "main-styles": helpers.root("src/main-styles.ts"), // our angular app's styles. Useful only changing the styles bundle while working on styling - vendor: helpers.root("src/vendor.ts"), - main: helpers.root("src/main.ts") // our angular app - }, - - // Options affecting the normal modules. - // reference: https://webpack.js.org/configuration/module - module: { - // An array of applied loaders. - // IMPORTANT: The loaders here are resolved relative to the resource which they are applied to. - // This means they are not resolved relative to the configuration file. - // reference: https://webpack.js.org/configuration/module/#module-rules - rules: [ - // Support for .ts files. - // reference: https://github.com/s-panferov/awesome-typescript-loader - { - test: /\.ts$/, - use: [ - { - loader: "babel-loader", - options: commonData.babel - }, - { - loader: "awesome-typescript-loader", - options: commonData.ts - } - ], - exclude: [ - /\.e2e-spec\.ts$/, // exclude end-to-end tests - /\.spec\.ts$/ // exclude unit tests - ] - } - ] - }, - - // Add additional plugins to the compiler. - // reference: https://webpack.js.org/plugins - plugins: [ - // Environment helpers (when adding more properties make sure you include them in environment.d.ts) - // Plugin: DefinePlugin - // Description: Define free variables. - // Useful for having development builds with debug logging or adding global constants. - // reference: https://webpack.js.org/plugins/define-plugin - // NOTE: when adding more properties make sure you include them in custom-typings.d.ts - new DefinePlugin({ - ENV: JSON.stringify(METADATA.ENV), - NODE_ENV: JSON.stringify(METADATA.ENV), - HMR: METADATA.HMR, - PRODUCTION: METADATA.PRODUCTION, - DEVELOPMENT: METADATA.DEVELOPMENT, - "process.env": { - ENV: JSON.stringify(METADATA.ENV), - NODE_ENV: JSON.stringify(METADATA.ENV), - HMR: METADATA.HMR, - PRODUCTION: METADATA.PRODUCTION, - DEVELOPMENT: METADATA.DEVELOPMENT - } - }), - - // Plugin: CommonsChunkPlugin - // Description: Shares common code between the pages. - // It identifies common modules and put them into a commons chunk. - // reference: https://webpack.js.org/plugins/commons-chunk-plugin - // reference: https://github.com/webpack/docs/wiki/optimization#multi-page-app - new CommonsChunkPlugin({ - name: helpers.reverse(["polyfills", "vendor", "main", "vendor-styles", "main-styles"]), - // the filename configured in the output section is reused - //filename: "[name].[hash].bundle.js", - chunks: Infinity - }), - - // // Plugin: Uglify - // // Description: minify code, compress, ... - // // reference: https://webpack.js.org/plugins/uglifyjs-webpack-plugin - // new UglifyJsPlugin({ - // beautify: false, // set to true for debugging - // //dead_code: false, // uncomment for debugging - // //unused: false, // uncomment for debugging - // mangle: { // reference: https://github.com/mishoo/UglifyJS2#mangle-options - // screw_ie8: true, - // keep_fnames: true, - // except: [ - // // list strings that should not be mangled here - // ] - // }, - // compress: { // reference: https://github.com/mishoo/UglifyJS2#compress-options - // screw_ie8: true, - // warnings: false - // // uncomment for debugging - // //, - // //keep_fnames: true, - // //drop_debugger: false, - // //dead_code: false, - // //unused: false - // }, - // comments: false, // set to true for debugging - // sourceMap: false - // }), - - // Plugin: ExtractTextWebpackPlugin - // Description: Extract css file contents - // reference: https://github.com/webpack/extract-text-webpack-plugin - // notice that in DEV we do not add hashes to the stylesheet file names - new ExtractTextWebpackPlugin({ - filename: "[name].css", - disable: false, - allChunks: true - }), - - // Plugin: HtmlWebpackPlugin - // Description: Simplifies creation of HTML files to serve your webpack bundles. - // This is especially useful for webpack bundles that include a hash in the filename - // which changes every compilation. - // reference: https://github.com/jantimon/html-webpack-plugin - new HtmlWebpackPlugin({ - template: helpers.root("src/index.html"), - chunksSortMode: helpers.packageSort(["polyfills", "vendor", "main", "vendor-styles", "main-styles"]), - metadata: METADATA, - inject: "body", // true (default) or "body" are the same - starkAppMetadata: commonData.starkAppMetadata, - starkAppConfig: commonData.starkAppConfig - }), - - // this plugin makes sure that bundles and assets are written to disk - // this is necessary so that assets are available in dev mode - // reference: https://www.npmjs.com/package/write-file-webpack-plugin - new WriteFilePlugin(), - - // reference: https://webpack.js.org/plugins/loader-options-plugin - new LoaderOptionsPlugin({ - // Switch loaders to debug mode - debug: true, - options: { - context: __dirname, - - // Html loader for HTML minification (advanced options) - // reference: https://github.com/webpack/html-loader#advanced-options - htmlLoader: commonData.htmlLoader.dev, - - // TSLint configuration - // Static analysis linter for TypeScript advanced options configuration - // Description: An extensible linter for the TypeScript language. - // reference: https://github.com/wbuchwalter/tslint-loader - tslint: commonData.tslint.dev - } - }), - - // Plugin: Stylelint - // Description: Lints the stylesheets loaded in the app (pcss, scss, css, sass) - // reference https://github.com/JaKXz/stylelint-webpack-plugin - new StylelintPlugin({ - configFile: "stylelint.config.js", - emitErrors: false, - files: ["src/**/*.?(pc|sc|c|sa)ss"] // pcss|scss|css|sass - }), - - new CircularDependencyPlugin({ - // exclude detection of files based on a RegExp - exclude: /node_modules/, - // log warnings to webpack - failOnError: false - }) - - // new webpack.HotModuleReplacementPlugin() - ], - - // Webpack Development Server configuration - // Description: The webpack-dev-server is a little node.js Express server. - // The server emits information about the compilation state to the client, - // which reacts to those events. - // reference: https://webpack.js.org/configuration/dev-server/ - devServer: { - port: METADATA.PORT, - host: METADATA.HOST, - inline: true, - compress: true, - overlay: { - errors: false, - warnings: false - }, - // hot: true, - - // HTML5 History API support: no need for # in URLs - // automatically redirect 404 errors to the index.html page - // uses connect-history-api-fallback behind the scenes: https://github.com/bripkens/connect-history-api-fallback - // reference: http://jaketrent.com/post/pushstate-webpack-dev-server/ - historyApiFallback: true, - - // Due to a security fix of Webpack Server, we enable this option to permit the access to the application when running on 0.0.0.0 - // reference: https://github.com/webpack/webpack-dev-server/releases/tag/v2.4.3 - disableHostCheck: true, - - // file watch configuration - // reference: https://webpack.js.org/configuration/watch/ - watchOptions: { - aggregateTimeout: 300, - poll: 1000 - }, - contentBase: helpers.root("dist"), // necessary so that all the content is available (e.g., app assets, stark assets, ...) - - // Can be used to add specific headers - headers: { - // enable CORS - "Access-Control-Allow-Origin": "*", - - // CSP header (and its variants per browser) - "Content-Security-Policy": cspDirectives.join(" ; "), - "X-Content-Security-Policy": cspDirectives.join(" ; "), - "X-WebKit-CSP": cspDirectives.join(" ; "), - - // Other security headers - - // protect against clickjacking: https://en.wikipedia.org/wiki/Clickjacking - // reference: https://developer.mozilla.org/en-US/docs/Web/HTTP/X-Frame-Options - "X-Frame-Options": "deny", - - // enable some protection against XSS - // reference: https://www.owasp.org/index.php/List_of_useful_HTTP_headers - "X-Xss-Protection": "1; mode=block", - - // protect against drive-by download attacks and user uploaded content that could be treated by Internet Explorer as executable or dynamic HTML files - // reference: https://www.owasp.org/index.php/List_of_useful_HTTP_headers - "X-Content-Type-Options": "nosniff" - } - } -}); - -//FIXME review for Webpack 2: might not be needed. We might have to switch back to HMR by default.. -// Configure live reloading -// By default, if Hot Module Replacement (HMR) is enabled and the --inline flag is passed to Webpack -// then id adds the following bundle as entry: https://github.com/webpack/webpack/blob/master/hot/dev-server.js -// that script takes care of HMR but reloads the whole page when HMR does not work (e.g., when a stylesheet changes) - -// With the following, if HMR is enabled but --inline was not specified, we disable the page reloads for cases when HMR does not work -// reference: https://github.com/webpack/webpack/issues/418 - -if (helpers.hasProcessFlag("hot")) { - if (!helpers.hasProcessFlag("inline")) { - // adds the following script: https://github.com/webpack/webpack/blob/master/hot/only-dev-server.js - // that script handles HMR but does NOT force a page reload - module.exports.entry["webpack-dev-server"] = helpers.root("node_modules/webpack/hot/only-dev-server"); - } -} diff --git a/packages/stark-build/config-stark/webpack.prod.js b/packages/stark-build/config-stark/webpack.prod.js deleted file mode 100644 index dd7c1810bb..0000000000 --- a/packages/stark-build/config-stark/webpack.prod.js +++ /dev/null @@ -1,193 +0,0 @@ -"use strict"; - -const webpack = require("webpack"); - -const webpackMerge = require("webpack-merge"); // Used to merge webpack configs -const commonConfig = require("./webpack.common.js"); // common configuration between environments -const commonData = require("./webpack.common-data.js"); // common configuration between environments - -// Helpers -const helpers = require("./helpers"); - -// Webpack Plugins -const CompressionPlugin = require("compression-webpack-plugin"); -const DefinePlugin = require("webpack/lib/DefinePlugin"); -const CommonsChunkPlugin = require("webpack/lib/optimize/CommonsChunkPlugin"); -const ExtractTextWebpackPlugin = require("extract-text-webpack-plugin"); -const HtmlWebpackPlugin = require("html-webpack-plugin"); -const LoaderOptionsPlugin = require("webpack/lib/LoaderOptionsPlugin"); -const UglifyJsPlugin = require("webpack/lib/optimize/UglifyJsPlugin"); - -// Metadata -const METADATA = { - host: process.env.HOST || "localhost", - port: parseInt(process.env.PORT, 10) || 8080, - ENV: (process.env.NODE_ENV = process.env.ENV = "production"), - PRODUCTION: true, - DEVELOPMENT: false -}; - -/* - * Config - * IMPORTANT: notice that the configuration below is MERGED with the common configuration (commonConfig) - * reference: https://webpack.js.org/configuration/ - */ -module.exports = webpackMerge(commonConfig, { - // Developer tool to enhance debugging - // reference: https://webpack.js.org/configuration/devtool - // reference: https://github.com/webpack/docs/wiki/build-performance#sourcemaps - devtool: "source-map", - - // the entry point for the bundles - // reference: https://webpack.js.org/configuration/entry-context/#entry - entry: { - polyfills: helpers.root("src/polyfills.ts"), - vendor: helpers.root("src/vendor.ts"), - main: helpers.root("src/main.ts") // our angular app - }, - - // Options affecting the normal modules. - // reference: https://webpack.js.org/configuration/module - module: { - // An array of applied loaders. - // IMPORTANT: The loaders here are resolved relative to the resource which they are applied to. - // This means they are not resolved relative to the configuration file. - // reference: https://webpack.js.org/configuration/module/#module-rules - rules: [ - // Support for .ts files. - // reference: https://github.com/s-panferov/awesome-typescript-loader - { - test: /\.ts$/, - use: [ - { - loader: "babel-loader", - options: commonData.babel - }, - { - loader: "awesome-typescript-loader", - options: commonData.ts - } - ], - exclude: [ - /\.e2e-spec\.ts$/, // exclude end-to-end tests - /\.spec\.ts$/ // exclude unit tests - ] - } - ] - }, - - // Add additional plugins to the compiler. - // reference: https://webpack.js.org/plugins - plugins: [ - // Environment helpers (when adding more properties make sure you include them in environment.d.ts) - // Plugin: DefinePlugin - // Description: Define free variables. - // Useful for having development builds with debug logging or adding global constants. - // reference: https://webpack.js.org/plugins/define-plugin - // NOTE: when adding more properties make sure you include them in custom-typings.d.ts - new DefinePlugin({ - ENV: JSON.stringify(METADATA.ENV), - NODE_ENV: JSON.stringify(METADATA.ENV), - HMR: false, - PRODUCTION: METADATA.PRODUCTION, - DEVELOPMENT: METADATA.DEVELOPMENT, - "process.env": { - ENV: JSON.stringify(METADATA.ENV), - NODE_ENV: JSON.stringify(METADATA.ENV), - HMR: false, - PRODUCTION: METADATA.PRODUCTION, - DEVELOPMENT: METADATA.DEVELOPMENT - } - }), - - // Plugin: CommonsChunkPlugin - // Description: Shares common code between the pages. - // It identifies common modules and put them into a commons chunk. - // reference: https://webpack.js.org/plugins/commons-chunk-plugin - // reference: https://github.com/webpack/docs/wiki/optimization#multi-page-app - new CommonsChunkPlugin({ - name: helpers.reverse(["polyfills", "vendor", "main"]), - // the filename configured in the output section is reused - //filename: "[name].[hash].bundle.js", - chunks: Infinity - }), - - // Plugin: Uglify - // Description: minify code, compress, ... - // reference: https://webpack.js.org/plugins/uglifyjs-webpack-plugin - new UglifyJsPlugin({ - beautify: false, // set to true for debugging - //dead_code: false, // uncomment for debugging - //unused: false, // uncomment for debugging - mangle: { - // reference: https://github.com/mishoo/UglifyJS2#mangle-options - screw_ie8: true, - keep_fnames: true, - except: [ - // list strings that should not be mangled here - ] - }, - compress: { - // reference: https://github.com/mishoo/UglifyJS2#compress-options - screw_ie8: true, - warnings: false - // uncomment for debugging - //, - //keep_fnames: true, - //drop_debugger: false, - //dead_code: false, - //unused: false - }, - comments: false, // set to true for debugging - sourceMap: false - }), - - // Plugin: CompressionPlugin - // Description: Prepares compressed versions of assets to serve - // them with Content-Encoding - // reference: https://github.com/webpack/compression-webpack-plugin - new CompressionPlugin({ - regExp: /\.css$|\.html$|\.js$|\.map$/, - threshold: 2 * 1024 - }), - - // Plugin: ExtractTextWebpackPlugin - // Description: Extract css file contents - // reference: https://github.com/webpack/extract-text-webpack-plugin - new ExtractTextWebpackPlugin({ - filename: "[name].[hash].css", - disable: false - }), - - // Plugin: HtmlWebpackPlugin - // Description: Simplifies creation of HTML files to serve your webpack bundles. - // This is especially useful for webpack bundles that include a hash in the filename - // which changes every compilation. - // reference: https://github.com/jantimon/html-webpack-plugin - new HtmlWebpackPlugin({ - template: helpers.root("src/index.html"), - chunksSortMode: helpers.packageSort(["polyfills", "vendor", "main"]), - metadata: METADATA, - inject: "body", // true (default) or "body" are the same - starkAppMetadata: commonData.starkAppMetadata, - starkAppConfig: commonData.starkAppConfig - }), - - // reference: https://webpack.js.org/plugins/loader-options-plugin - new LoaderOptionsPlugin({ - // Switch loaders to debug mode - debug: false, - options: { - // Html loader for HTML minification (advanced options) - // reference: https://github.com/webpack/html-loader#advanced-options - htmlLoader: commonData.htmlLoader.prod, - - // TSLint configuration - // Static analysis linter for TypeScript advanced options configuration - // Description: An extensible linter for the TypeScript language. - // reference: https://github.com/wbuchwalter/tslint-loader - tslint: commonData.tslint.prod - } - }) - ] -}); diff --git a/packages/stark-build/config/build-utils.js b/packages/stark-build/config/build-utils.js index f4cc85ba38..ee893705aa 100644 --- a/packages/stark-build/config/build-utils.js +++ b/packages/stark-build/config/build-utils.js @@ -4,14 +4,14 @@ const fs = require("fs"); const helpers = require("./helpers"); const DEFAULT_METADATA = { - title: "Angular Starter by @gdi2290 from @TipeIO", + title: "Stark Application by @NationalBankBelgium", baseUrl: "/", isDevServer: helpers.isWebpackDevServer(), HMR: helpers.hasProcessFlag("hot"), AOT: process.env.BUILD_AOT || helpers.hasNpmFlag("aot"), E2E: !!process.env.BUILD_E2E, WATCH: helpers.hasProcessFlag("watch"), - tsConfigPath: "tsconfig.webpack.json", + tsConfigPath: "tsconfig.app.json", /** * This suffix is added to the environment.ts file, if not set the default environment file is loaded (development) diff --git a/packages/stark-build/config/helpers.js b/packages/stark-build/config/helpers.js index 73fa6fb498..41d9000ef4 100644 --- a/packages/stark-build/config/helpers.js +++ b/packages/stark-build/config/helpers.js @@ -1,6 +1,3 @@ -/** - * @author: tipe.io - */ const path = require("path"); const EVENT = process.env.npm_lifecycle_event || ""; @@ -24,11 +21,32 @@ function isWebpackDevServer() { return process.argv[1] && !!/webpack-dev-server/.exec(process.argv[1]); } +/** + * Retrieve the relative path from the config directory to the path argument value (if provided). That path argument can be passed to only execute a subset of the unit tests (see spec-bundle.ts) + * @param args the arguments to look into + * @returns {*} The relative path from this directory (config) to the location pointed at by the path argument value (if provided), an empty string otherwise + */ +function getTestPath(args) { + for (let i = 0; i < args.length; ++i) { + if (args[i] === "--path--") { + let providedPath = args[i + 1] || ""; + if (!providedPath.toLocaleLowerCase().startsWith("src/")) { + throw new Error("If you want to execute a subset of the unit tests, then the path you provide MUST start with 'src/'"); + } + //return path.relative(__dirname, providedPath); + // posix style to get the expected path separator + return path.posix.relative(__dirname, providedPath); + } + } + return ""; +} + const root = path.join.bind(path, _root); const rootStark = path.join.bind(path, _rootStark); exports.hasProcessFlag = hasProcessFlag; exports.hasNpmFlag = hasNpmFlag; exports.isWebpackDevServer = isWebpackDevServer; +exports.getTestPath = getTestPath; exports.root = root; exports.rootStark = rootStark; diff --git a/packages/stark-build/config-stark/json-server.common.js b/packages/stark-build/config/json-server.common.js similarity index 100% rename from packages/stark-build/config-stark/json-server.common.js rename to packages/stark-build/config/json-server.common.js diff --git a/packages/stark-build/config/karma.conf.js b/packages/stark-build/config/karma.conf.js index e11c47b7fb..67237624ce 100644 --- a/packages/stark-build/config/karma.conf.js +++ b/packages/stark-build/config/karma.conf.js @@ -1,13 +1,10 @@ -/** - * @author: @AngularClass - */ - +// Helpers const helpers = require("./helpers"); module.exports = function(config) { - var testWebpackConfig = require("./webpack.test.js")(); + const testWebpackConfig = require("./webpack.test.js")(); - var configuration = { + const configuration = { /** * Base path that will be used to resolve all patterns (e.g. files, exclude). */ @@ -25,8 +22,18 @@ module.exports = function(config) { */ exclude: [], + // client configuration client: { - captureConsole: false + // can be used to pass arguments to tests (see spec-bundle.ts) + args: [ + { + // path to the subset of the tests to consider (used to filter the unit tests to execute (see spec-bundle.ts) + testPath: helpers.getTestPath(process.argv) + } + ], + + // other client-side config + captureConsole: true }, /** @@ -35,12 +42,24 @@ module.exports = function(config) { * we are building the test environment in ./spec-bundle.js */ files: [ - { pattern: helpers.rootStark("./config/spec-bundle.js"), watched: false }, - { pattern: "./src/assets/**/*", watched: false, included: false, served: true, nocache: false } + { + pattern: helpers.rootStark("./config/spec-bundle.js"), + watched: false + }, + // paths to support debugging with source maps in dev tools + { + pattern: "./src/assets/**/*", + watched: false, + included: false, + served: true, + nocache: false + } ], /** * By default all assets are served at http://localhost:[PORT]/base/ + * can be used to map paths served by the Karma web server to /base/ content + * knowing that /base corresponds to the project root folder (i.e., where this config file is located) */ proxies: { "/assets/": "/base/src/assets/" @@ -51,7 +70,9 @@ module.exports = function(config) { * available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor */ // TODO Change this absolute path to a relative one (with helpers ?) - preprocessors: { "./node_modules/@nationalbankbelgium/stark-build/config/spec-bundle.js": ["coverage", "webpack", "sourcemap"] }, + preprocessors: { + "./node_modules/@nationalbankbelgium/stark-build/config/spec-bundle.js": ["coverage", "webpack", "sourcemap"] + }, /** * Webpack Config at ./webpack.test.js @@ -94,7 +115,12 @@ module.exports = function(config) { * possible values: 'dots', 'progress' * available reporters: https://npmjs.org/browse/keyword/karma-reporter */ - reporters: ["mocha", "coverage", "remap-coverage"], + reporters: ["mocha", "coverage", "progress", "remap-coverage"], + + // Give a type to files, otherwise it will not work with Chrome > 55 + mime: { + "text/x-typescript": ["ts", "tsx"] + }, /** * Web server port. @@ -115,13 +141,17 @@ module.exports = function(config) { /** * enable / disable watching file and executing tests whenever any file changes */ - autoWatch: false, + autoWatch: true, /** * start these browsers * available browser launchers: https://npmjs.org/browse/keyword/karma-launcher */ - browsers: ["Chrome"], + browsers: [ + "Chrome" + //"Firefox", + //"IE", + ], customLaunchers: { ChromeTravisCi: { @@ -134,7 +164,12 @@ module.exports = function(config) { * Continuous Integration mode * if true, Karma captures browsers, runs the tests and exits */ - singleRun: true + singleRun: false, + + // Timeout settings + browserNoActivityTimeout: 30000, + browserDisconnectTolerance: 1, + browserDisconnectTimeout: 30000 }; if (process.env.TRAVIS) { diff --git a/packages/stark-build/config/karma.conf.typescript.js b/packages/stark-build/config/karma.conf.typescript.js new file mode 100644 index 0000000000..e6685f9812 --- /dev/null +++ b/packages/stark-build/config/karma.conf.typescript.js @@ -0,0 +1,76 @@ +// Helpers +const helpers = require("./helpers"); + +// Karma configuration +// reference: http://karma-runner.github.io/2.0/config/configuration-file.html +module.exports = function(config) { + config.set({ + // base path that will be used to resolve all patterns (e.g. files, exclude) + basePath: "", + + // frameworks to use + // available frameworks: https://npmjs.org/browse/keyword/karma-adapter + frameworks: ["jasmine", "karma-typescript"], + + // list of files / patterns to load in the browser + files: [{ pattern: helpers.root("base.spec.ts") }, { pattern: helpers.root("src/**/*.ts") }], + + // list of files to exclude + exclude: [], + + // preprocess matching files before serving them to the browser + // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor + preprocessors: { + "**/*.ts": ["karma-typescript", "sourcemap"] + }, + + karmaTypescriptConfig: { + bundlerOptions: { + entrypoints: /\.spec\.ts$/, + exclude: [ + "coffee-script", // FIXME: https://github.com/monounity/karma-typescript/issues/209 + "saucelabs", // gives an error + "protractor", // not needed for unit testing + "selenium-webdriver" // not needed for unit testing + ], + transforms: [ + require("karma-typescript-angular2-transform") // see https://github.com/monounity/karma-typescript-angular2-transform + ] + }, + tsconfig: "tsconfig.spec.json" + }, + + // test results reporter to use + // possible values: "dots", "progress", "spec", "junit", "mocha", "coverage" (others if you import reporters) + // available reporters: https://npmjs.org/browse/keyword/karma-reporter + // https://www.npmjs.com/package/karma-junit-reporter + // https://www.npmjs.com/package/karma-spec-reporter + reporters: ["mocha", "progress", "karma-typescript"], + + // web server port + port: 9876, + + // enable / disable colors in the output (reporters and logs) + colors: true, + + // level of logging + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG + logLevel: config.LOG_WARN, + + // enable / disable watching file and executing tests whenever any file changes + autoWatch: true, + + // start these browsers + // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher + browsers: ["Chrome"], + + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: false, + + // Timeout settings + browserNoActivityTimeout: 30000, + browserDisconnectTolerance: 1, + browserDisconnectTimeout: 30000 + }); +}; diff --git a/packages/stark-build/config-stark/nightly-build.js b/packages/stark-build/config/nightly-build.js similarity index 100% rename from packages/stark-build/config-stark/nightly-build.js rename to packages/stark-build/config/nightly-build.js diff --git a/packages/stark-build/config/webpack.common.js b/packages/stark-build/config/webpack.common.js index 9e2acc8add..e68e5ea87d 100644 --- a/packages/stark-build/config/webpack.common.js +++ b/packages/stark-build/config/webpack.common.js @@ -10,13 +10,12 @@ const commonData = require("./webpack.common-data.js"); // common configuration * * problem with copy-webpack-plugin */ -const DefinePlugin = require("webpack/lib/DefinePlugin"); +// const DefinePlugin = require("webpack/lib/DefinePlugin"); const CommonsChunkPlugin = require("webpack/lib/optimize/CommonsChunkPlugin"); const CopyWebpackPlugin = require("copy-webpack-plugin"); const HtmlWebpackPlugin = require("html-webpack-plugin"); -const InlineManifestWebpackPlugin = require("inline-manifest-webpack-plugin"); -const LoaderOptionsPlugin = require("webpack/lib/LoaderOptionsPlugin"); -const ScriptExtHtmlWebpackPlugin = require("script-ext-html-webpack-plugin"); +// const InlineManifestWebpackPlugin = require("inline-manifest-webpack-plugin"); +// const ScriptExtHtmlWebpackPlugin = require("script-ext-html-webpack-plugin"); const { AngularCompilerPlugin } = require("@ngtools/webpack"); const { NamedLazyChunksWebpackPlugin } = require("@angular/cli/plugins/webpack"); const NoEmitOnErrorsPlugin = require("webpack/lib/NoEmitOnErrorsPlugin"); @@ -51,6 +50,21 @@ module.exports = function(options) { }; return { + stats: { + colors: true, + reasons: true, + errorDetails: true // display error details. Same as the --show-error-details flag + // maxModules: Infinity, // examine all modules (ModuleConcatenationPlugin debugging) + // optimizationBailout: true // display bailout reasons (ModuleConcatenationPlugin debugging) + }, + + /** + * Tell webpack which environment the application is targeting. + * reference: https://webpack.js.org/configuration/target/ + * reference: https://webpack.js.org/concepts/targets/ + */ + target: "web", // <== can be omitted as default is "web" + /** * The entry point for the bundle * Our Angular.js app @@ -72,7 +86,7 @@ module.exports = function(options) { * * See: http://webpack.github.io/docs/configuration.html#resolve-extensions */ - extensions: [".ts", ".js", ".json"], + extensions: [".ts", ".js", ".json", ".css", ".pcss", ".html"], /** * An array of directory names to be resolved to the current directory @@ -131,10 +145,7 @@ module.exports = function(options) { enforce: "pre", test: /\.ts$/, use: ["tslint-loader"], - exclude: [ - helpers.root("node_modules") - // helpers.rootStark("node_modules") - ] + exclude: [helpers.root("node_modules")] }, // Source map loader support for *.js files @@ -144,11 +155,7 @@ module.exports = function(options) { enforce: "pre", test: /\.js$/, use: ["source-map-loader"], - exclude: [ - // helpers.rootStark("node_modules/rxjs"), - helpers.root("node_modules/rxjs"), - helpers.root("node_modules/@angular") - ] + exclude: [helpers.root("node_modules/rxjs"), helpers.root("node_modules/@angular")] }, /** @@ -230,7 +237,7 @@ module.exports = function(options) { * File loader for supporting fonts, for example, in CSS files. */ { - test: /\.(eot|woff2?|svg|ttf)([\?]?.*)$/, + test: /\.(eot|woff2?|svg|ttf)([?]?.*)$/, use: "file-loader" } ] @@ -376,12 +383,12 @@ module.exports = function(options) { // from: helpers.rootStark("assets/translations"), // to: "assets/translations/stark" // }, - - // Application assets - { - from: helpers.root("assets/translations"), - to: "assets/translations/app" - } + // + // // Application assets + // { + // from: helpers.root("assets/translations"), + // to: "assets/translations/app" + // } ], {} ), @@ -448,18 +455,31 @@ module.exports = function(options) { // }), new AngularCompilerPlugin({ + // Optional params + sourceMap: true, // TODO: apply based on tsConfig value? mainPath: entry.main, - platform: 0, // 0 = browser, 1 = server - // entryModule: 'path/to/app.module#AppModule', // TODO not used, probably already defined in the main.browser.ts? + skipCodeGeneration: !METADATA.AOT, hostReplacementPaths: { [helpers.root("src/environments/environment.ts")]: environment }, - sourceMap: true, // TODO: apply based on tsConfig value? - tsConfigPath: METADATA.tsConfigPath, - skipCodeGeneration: !METADATA.AOT, + platform: 0, // 0 = browser, 1 = server compilerOptions: { module: !isProd && METADATA.WATCH ? "commonjs" : "es2015" // TODO is it needed in our case? => Force commonjs module format for TS on dev watch builds. - } + }, + // forkTypeChecker?: boolean; + // basePath: METADATA.tsConfigPath + // entryModule: 'path/to/app.module#AppModule', // TODO not used, probably already defined in the main.browser.ts? + // i18nInFile?: string; + // i18nInFormat?: string; + // i18nOutFile?: string; + // i18nOutFormat?: string; + // locale?: string; + // missingTranslation?: string; + // nameLazyFiles?: boolean; + // additionalLazyModules?: { [module: string]: string }; + + // Required params + tsConfigPath: METADATA.tsConfigPath }) /** diff --git a/packages/stark-build/config/webpack.dev.js b/packages/stark-build/config/webpack.dev.js index d3998cd8c2..95f5e09229 100644 --- a/packages/stark-build/config/webpack.dev.js +++ b/packages/stark-build/config/webpack.dev.js @@ -17,6 +17,7 @@ const SourceMapDevToolPlugin = require("webpack/lib/SourceMapDevToolPlugin"); const WriteFilePlugin = require("write-file-webpack-plugin"); const StylelintPlugin = require("stylelint-webpack-plugin"); +const CircularDependencyPlugin = require("circular-dependency-plugin"); // Dev custom config const webpackCustomConfig = require(helpers.root("config/webpack-custom-config.dev.json")); @@ -59,14 +60,6 @@ module.exports = function() { ]; return webpackMerge(commonConfig({ ENV: ENV, metadata: METADATA }), { - stats: { - colors: true, - reasons: true, - errorDetails: true // display error details. Same as the --show-error-details flag - // maxModules: Infinity, // examine all modules (ModuleConcatenationPlugin debugging) - // optimizationBailout: true // display bailout reasons (ModuleConcatenationPlugin debugging) - }, - /** * Tell webpack which environment the application is targeting. * reference: https://webpack.js.org/configuration/target/ @@ -205,16 +198,6 @@ module.exports = function() { */ new NamedModulesPlugin(), - /** - * Plugin LoaderOptionsPlugin (experimental) - * - * See: https://gist.github.com/sokra/27b24881210b56bbaff7 - */ - new LoaderOptionsPlugin({ - debug: true, - options: {} - }), - /** * Plugin: WriteFilePlugin * Description: This plugin makes sure that bundles and assets are written to disk @@ -232,6 +215,13 @@ module.exports = function() { configFile: "stylelint.config.js", emitErrors: false, files: ["src/**/*.?(pc|sc|c|sa)ss"] // pcss|scss|css|sass + }), + + new CircularDependencyPlugin({ + // exclude detection of files based on a RegExp + exclude: /node_modules/, + // log warnings to webpack + failOnError: false }) ], diff --git a/packages/stark-build/config/webpack.prod.js b/packages/stark-build/config/webpack.prod.js index 4d8e8a14b9..aec9c97a2b 100644 --- a/packages/stark-build/config/webpack.prod.js +++ b/packages/stark-build/config/webpack.prod.js @@ -41,7 +41,8 @@ function getUglifyOptions(supportES2015) { output: { ascii_only: true, comments: false - } + }, + beautify: false // set to true for debugging }; } diff --git a/packages/stark-build/config/webpack.test.js b/packages/stark-build/config/webpack.test.js index d3407c8a04..11227ac7da 100644 --- a/packages/stark-build/config/webpack.test.js +++ b/packages/stark-build/config/webpack.test.js @@ -7,7 +7,6 @@ const helpers = require("./helpers"); /** * Webpack Plugins */ -const ProvidePlugin = require("webpack/lib/ProvidePlugin"); const DefinePlugin = require("webpack/lib/DefinePlugin"); const LoaderOptionsPlugin = require("webpack/lib/LoaderOptionsPlugin"); const SourceMapDevToolPlugin = require("webpack/lib/SourceMapDevToolPlugin"); @@ -95,7 +94,8 @@ module.exports = function() { * below by DefinePlugin */ removeComments: true - } + }, + configFileName: "tsconfig.spec.json" } }, "angular2-template-loader" @@ -262,7 +262,7 @@ module.exports = function() { /** * The (\\|\/) piece accounts for path separators in *nix and Windows */ - /angular(\\|\/)core(\\|\/)@angular/, + /angular[\\\/]core([\\\/])@angular/, helpers.root("src"), // location of your src { /** diff --git a/starter/.gitattributes b/starter/.gitattributes deleted file mode 100644 index 70e53eefec..0000000000 --- a/starter/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -yarn.lock -diff diff --git a/starter/.gitignore b/starter/.gitignore index bffc999b05..120a9bc8e8 100644 --- a/starter/.gitignore +++ b/starter/.gitignore @@ -1,7 +1,15 @@ -# tipe.io +# Build +dist/ +.awcache/ + +# Reports directory +reports/ + +# NPM +package-lock.json # Logs -logs +logs/ *.log # Runtime data @@ -9,62 +17,40 @@ pids *.pid *.seed -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - # Coverage directory used by tools like istanbul coverage -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) -.grunt +# Bak +*.bak -# Compiled binary addons (http://nodejs.org/api/addons.html) -build/Release - -# Users Environment Variables -.lock-wscript +# Node +node_modules/ +npm-debug.log +/npm-debug.log.* # OS generated files # +Desktop.ini +Thumbs.db .DS_Store ehthumbs.db Icon? -Thumbs.db - -# Node Files # -/node_modules/ -/bower_components/ -npm-debug.log -/npm-debug.log.* -# Coverage # -/coverage/ - -# Typing # -/src/typings/tsd/ -/typings/ -/tsd_typings/ - -# Dist # -/dist -/public/__build__/ -/src/*/__build__/ -/__build__/** -/public/dist/ -/src/*/dist/ -/dist/** -/.awcache -.webpack.json -/compiled/ -dll/ - -# Doc # -/doc/ -/documentation/ - -# IDE # +# JetBrains IDEs +*.iml .idea/ +.webstorm/ *.swp +# Sublime text +.sublime-gulp.cache + +# Runtime data +pids +*.pid +*.seed + +# Patch files +*.patch # Angular # *.ngfactory.ts diff --git a/starter/.nvmrc b/starter/.nvmrc deleted file mode 100644 index b009dfb9d9..0000000000 --- a/starter/.nvmrc +++ /dev/null @@ -1 +0,0 @@ -lts/* diff --git a/starter/LICENSE b/starter/LICENSE deleted file mode 100644 index 5d160fcc91..0000000000 --- a/starter/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2015-2017 PatrickJS, Tipe Inc - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/starter/base.spec.ts b/starter/base.spec.ts new file mode 100644 index 0000000000..704a2fe02e --- /dev/null +++ b/starter/base.spec.ts @@ -0,0 +1,18 @@ +"use strict"; + +import "core-js/es6"; +import "core-js/es7/reflect"; +import "core-js/stage/4"; + +import "zone.js/dist/zone"; +import "zone.js/dist/long-stack-trace-zone"; +import "zone.js/dist/proxy"; // since zone.js 0.6.15 +import "zone.js/dist/sync-test"; +import "zone.js/dist/jasmine-patch"; // put here since zone.js 0.6.14 +import "zone.js/dist/async-test"; +import "zone.js/dist/fake-async-test"; + +import { TestBed } from "@angular/core/testing"; +import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from "@angular/platform-browser-dynamic/testing"; + +TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting()); diff --git a/starter/docker-compose.yml b/starter/docker-compose.yml deleted file mode 100644 index 7b01be37e3..0000000000 --- a/starter/docker-compose.yml +++ /dev/null @@ -1,14 +0,0 @@ -version: '3' -services: - angular-starter: - build: - context: . - dockerfile: Dockerfile - container_name: angular-starter - networks: - - angular-starter - ports: - - '8080:80' -networks: - angular-starter: - driver: bridge diff --git a/starter/karma.conf.js b/starter/karma.conf.js index 731f2b3a2d..6dac432318 100644 --- a/starter/karma.conf.js +++ b/starter/karma.conf.js @@ -1,7 +1,3 @@ -/** - * @author: @AngularClass - */ - /** * Look in ./config for karma.conf.js */ diff --git a/starter/karma.conf.typescript.js b/starter/karma.conf.typescript.js new file mode 100644 index 0000000000..b0379cc990 --- /dev/null +++ b/starter/karma.conf.typescript.js @@ -0,0 +1,4 @@ +/** + * Look in ./config for karma.conf.js + */ +module.exports = require("./node_modules/@nationalbankbelgium/stark-build/config/karma.conf.typescript.js"); diff --git a/starter/package.json b/starter/package.json index 7006c3c978..ea7050b298 100644 --- a/starter/package.json +++ b/starter/package.json @@ -64,6 +64,7 @@ "start": "npm run server:dev", "start:aot": "npm run server:aot:dev", "test": "npm run lint && karma start", + "test-fast": "karma start karma.conf.typescript.js", "tsc": "tsc", "tslint": "tslint", "typedoc": "typedoc", @@ -98,8 +99,8 @@ "@angular/platform-server": "5.2.6", "@angular/router": "5.2.6", "@nationalbankbelgium/angular-mdi-svg": "1.6.0", - "@nationalbankbelgium/stark-build": "10.0.0-alpha.1", - "@nationalbankbelgium/stark-core": "10.0.0-alpha.1", + "@nationalbankbelgium/stark-build": "file:../dist/packages-dist/stark-build/nationalbankbelgium-stark-build-10.0.0-alpha.0-dacb040.tgz", + "@nationalbankbelgium/stark-core": "file:../dist/packages-dist/stark-core/nationalbankbelgium-stark-core-10.0.0-alpha.0-dacb040.tgz", "@uirouter/angular": "1.0.1", "@uirouter/visualizer": "6.0.0", "core-js": "2.5.3", @@ -113,6 +114,7 @@ }, "devDependencies": { "@compodoc/compodoc": "1.0.7", + "@types/core-js": "0.9.46", "@types/hammerjs": "2.0.35", "@types/jasmine": "2.8.6", "@types/node": "6.0.101", @@ -122,6 +124,14 @@ "find-root": "^1.0.0", "gh-pages": "^1.0.0", "jasmine-core": "2.99.1", + "karma": "2.0.0", + "karma-chrome-launcher": "2.2.0", + "karma-jasmine": "1.1.1", + "karma-mocha-reporter": "2.2.5", + "karma-sourcemap-loader": "0.3.7", + "karma-spec-reporter": "0.0.32", + "karma-typescript": "3.0.12", + "karma-typescript-angular2-transform": "1.0.2", "npm-run-all": "^4.0.2", "optimize-js-plugin": "0.0.4", "parse5": "^3.0.2", diff --git a/starter/src/app/+barrel/+child-barrel/child-barrel.module.ts b/starter/src/app/+barrel/+child-barrel/child-barrel.module.ts index d3ef648728..a416af0629 100644 --- a/starter/src/app/+barrel/+child-barrel/child-barrel.module.ts +++ b/starter/src/app/+barrel/+child-barrel/child-barrel.module.ts @@ -1,7 +1,7 @@ import { CommonModule } from "@angular/common"; import { FormsModule } from "@angular/forms"; import { NgModule } from "@angular/core"; -import {Ng2StateDeclaration, UIRouterModule} from "@uirouter/angular"; +import { Ng2StateDeclaration, UIRouterModule } from "@uirouter/angular"; import { CHILD_BARREL_STATES } from "./child-barrel.routes"; import { ChildBarrelComponent } from "./child-barrel.component"; @@ -26,5 +26,5 @@ console.log("`ChildBarrel` bundle loaded asynchronously"); ] }) export class ChildBarrelModule { - public static routes: Ng2StateDeclaration = CHILD_BARREL_STATES; + public static routes: Ng2StateDeclaration[] = CHILD_BARREL_STATES; } diff --git a/starter/src/app/+barrel/barrel.module.ts b/starter/src/app/+barrel/barrel.module.ts index e6cf6c2a5e..8a97ae5f4a 100644 --- a/starter/src/app/+barrel/barrel.module.ts +++ b/starter/src/app/+barrel/barrel.module.ts @@ -1,7 +1,7 @@ import { CommonModule } from "@angular/common"; import { FormsModule } from "@angular/forms"; import { NgModule } from "@angular/core"; -import {Ng2StateDeclaration, UIRouterModule} from "@uirouter/angular"; +import { Ng2StateDeclaration, UIRouterModule } from "@uirouter/angular"; import { BARREL_STATES } from "./barrel.routes"; import { BarrelComponent } from "./barrel.component"; @@ -26,5 +26,5 @@ console.log("`Barrel` bundle loaded asynchronously"); ] }) export class BarrelModule { - public static routes: Ng2StateDeclaration = BARREL_STATES; + public static routes: Ng2StateDeclaration[] = BARREL_STATES; } diff --git a/starter/src/app/+detail/+child-detail/child-detail.module.ts b/starter/src/app/+detail/+child-detail/child-detail.module.ts index 2a5c6d592e..acec59d04b 100644 --- a/starter/src/app/+detail/+child-detail/child-detail.module.ts +++ b/starter/src/app/+detail/+child-detail/child-detail.module.ts @@ -1,7 +1,7 @@ import { CommonModule } from "@angular/common"; import { FormsModule } from "@angular/forms"; import { NgModule } from "@angular/core"; -import {Ng2StateDeclaration, UIRouterModule} from "@uirouter/angular"; +import { Ng2StateDeclaration, UIRouterModule } from "@uirouter/angular"; import { CHILD_DETAIL_STATES } from "./child-detail.routes"; import { ChildDetailComponent } from "./child-detail.component"; @@ -26,5 +26,5 @@ console.log("`ChildDetail` bundle loaded asynchronously"); ] }) export class ChildDetailModule { - public static routes: Ng2StateDeclaration = CHILD_DETAIL_STATES; + public static routes: Ng2StateDeclaration[] = CHILD_DETAIL_STATES; } diff --git a/starter/src/app/+detail/detail.module.ts b/starter/src/app/+detail/detail.module.ts index 8abdccc890..b6572782aa 100644 --- a/starter/src/app/+detail/detail.module.ts +++ b/starter/src/app/+detail/detail.module.ts @@ -1,7 +1,7 @@ import { CommonModule } from "@angular/common"; import { FormsModule } from "@angular/forms"; import { NgModule } from "@angular/core"; -import {Ng2StateDeclaration, UIRouterModule} from "@uirouter/angular"; +import { Ng2StateDeclaration, UIRouterModule } from "@uirouter/angular"; import { DETAIL_STATES } from "./detail.routes"; import { DetailComponent } from "./detail.component"; @@ -26,5 +26,5 @@ console.log("`Detail` bundle loaded asynchronously"); ] }) export class DetailModule { - public static routes: Ng2StateDeclaration = DETAIL_STATES; + public static routes: Ng2StateDeclaration[] = DETAIL_STATES; } diff --git a/starter/src/app/+dev-module/dev-module.module.ts b/starter/src/app/+dev-module/dev-module.module.ts index 3a229dcddc..251b57ab36 100644 --- a/starter/src/app/+dev-module/dev-module.module.ts +++ b/starter/src/app/+dev-module/dev-module.module.ts @@ -1,6 +1,6 @@ import { NgModule } from "@angular/core"; import { CommonModule } from "@angular/common"; -import {Ng2StateDeclaration, UIRouterModule} from "@uirouter/angular"; +import { Ng2StateDeclaration, UIRouterModule } from "@uirouter/angular"; import { DEV_MODULE_STATES } from "./dev-module.routes"; import { DevModuleComponent } from "./dev-module.component"; @@ -21,7 +21,7 @@ import { routerChildConfigFn } from "../router.config"; ] }) export class DevModuleModule { - public static routes: Ng2StateDeclaration = DEV_MODULE_STATES; + public static routes: Ng2StateDeclaration[] = DEV_MODULE_STATES; constructor() { console.log("`DevModuleModule` module initialized"); } diff --git a/starter/src/app/about/about.component.spec.ts b/starter/src/app/about/about.component.spec.ts index e34dbe2f7a..c88b1101c9 100644 --- a/starter/src/app/about/about.component.spec.ts +++ b/starter/src/app/about/about.component.spec.ts @@ -1,5 +1,4 @@ import { ActivatedRoute, Data } from "@angular/router"; -import { Component } from "@angular/core"; import { inject, TestBed } from "@angular/core/testing"; /** diff --git a/starter/src/app/about/about.component.ts b/starter/src/app/about/about.component.ts index 9d95bb7cc6..c2bed91afd 100644 --- a/starter/src/app/about/about.component.ts +++ b/starter/src/app/about/about.component.ts @@ -44,10 +44,12 @@ export class AboutComponent implements OnInit { * Getting the resolves values */ // if the resolve is an observable, we need to subscribe to it to get the value - this.resolvedData.subscribe((data: any) => { - console.warn("data resolved"); - this.localState = { ...this.localState, ...data }; - }); + if (this.resolvedData) { + this.resolvedData.subscribe((data: any) => { + console.warn("data resolved"); + this.localState = { ...this.localState, ...data }; + }); + } // if the resolve is a promise and the resolve policy is WAIT // the value is already available @@ -76,11 +78,5 @@ export class AboutComponent implements OnInit { * you would do this if you don't want the mock-data bundled * remember that 'es6-promise-loader' is a promise */ - setTimeout(() => { - System.import("../../assets/mock-data/mock-data.json").then(json => { - console.log("async mockData", json); - this.localState = { ...this.localState, asyncData: json }; - }); - }); } } diff --git a/starter/src/app/app.component.spec.ts b/starter/src/app/app.component.spec.ts index 3d9fa10bc7..ce2a6f68f2 100644 --- a/starter/src/app/app.component.spec.ts +++ b/starter/src/app/app.component.spec.ts @@ -1,5 +1,5 @@ import { NO_ERRORS_SCHEMA } from "@angular/core"; -import { inject, async, TestBed, ComponentFixture } from "@angular/core/testing"; +import { async, TestBed, ComponentFixture } from "@angular/core/testing"; /** * Load the implementations that should be tested diff --git a/starter/src/app/app.component.ts b/starter/src/app/app.component.ts index fb7df49441..582939084e 100644 --- a/starter/src/app/app.component.ts +++ b/starter/src/app/app.component.ts @@ -2,7 +2,7 @@ * Angular 2 decorators and services */ import { Component, OnInit, ViewEncapsulation } from "@angular/core"; -import { environment } from "environments/environment"; +import { environment } from "../environments/environment"; import { AppState } from "./app.service"; /** diff --git a/starter/src/app/app.e2e.ts b/starter/src/app/app.e2e.ts index cdfb5a6fe8..7f8ea433ac 100644 --- a/starter/src/app/app.e2e.ts +++ b/starter/src/app/app.e2e.ts @@ -7,26 +7,26 @@ describe("App", () => { }); it("should have a title", async () => { - let subject = await browser.getTitle(); - let result = "Angular Starter by @gdi2290 from @TipeIO"; + const subject = await browser.getTitle(); + const result = "Angular Starter by @gdi2290 from @TipeIO"; expect(subject).toEqual(result); }); it("should have header", async () => { - let subject = await element(by.css("h1")).isPresent(); - let result = true; + const subject = await element(by.css("h1")).isPresent(); + const result = true; expect(subject).toEqual(result); }); it("should have ", async () => { - let subject = await element(by.css("app home")).isPresent(); - let result = true; + const subject = await element(by.css("app home")).isPresent(); + const result = true; expect(subject).toEqual(result); }); it("should have buttons", async () => { - let subject = await element(by.css("button")).getText(); - let result = "Submit Value"; + const subject = await element(by.css("button")).getText(); + const result = "Submit Value"; expect(subject).toEqual(result); }); }); diff --git a/starter/src/app/app.module.ts b/starter/src/app/app.module.ts index eae168a0f3..b4cad41a51 100644 --- a/starter/src/app/app.module.ts +++ b/starter/src/app/app.module.ts @@ -9,7 +9,7 @@ import { routerConfigFn } from "./router.config"; /* * Platform and Environment providers/directives/pipes */ -import { environment } from "environments/environment"; +import { environment } from "../environments/environment"; import { APP_STATES } from "./app.routes"; // App is our top level component import { AppComponent } from "./app.component"; @@ -22,7 +22,6 @@ import { DevModuleModule } from "./+dev-module"; import "../styles/styles.scss"; import "../styles/headings.css"; -import { MyAwesomeComponentComponent } from './src/app/about/my-awesome-component/my-awesome-component.component'; // Application wide providers const APP_PROVIDERS = [AppState]; @@ -32,7 +31,7 @@ const APP_PROVIDERS = [AppState]; */ @NgModule({ bootstrap: [AppComponent], - declarations: [AppComponent, AboutComponent, HomeComponent, NoContentComponent, XLargeDirective, MyAwesomeComponentComponent], + declarations: [AppComponent, AboutComponent, HomeComponent, NoContentComponent, XLargeDirective], /** * Import Angular's modules. */ diff --git a/starter/src/app/app.routes.ts b/starter/src/app/app.routes.ts index 875ae6f262..2d92a3c95d 100644 --- a/starter/src/app/app.routes.ts +++ b/starter/src/app/app.routes.ts @@ -4,9 +4,9 @@ import { NoContentComponent } from "./no-content"; import { Ng2StateDeclaration, Transition } from "@uirouter/angular"; import { of } from "rxjs/observable/of"; import "rxjs/add/operator/delay"; -import {Observable} from "rxjs/Observable"; +import { Observable } from "rxjs/Observable"; -export function getResolvedData(): Observable { +export function getResolvedData(): Observable { console.warn("resolve data being fetched... please wait..."); // could return an observable but then the component should subscribe to it // if resolve policy = 'WAIT' or 'NOWAIT' the component WILL BE LOADED WITHOUT diff --git a/starter/src/app/app.service.ts b/starter/src/app/app.service.ts index 6b394459f7..c9e27c5318 100644 --- a/starter/src/app/app.service.ts +++ b/starter/src/app/app.service.ts @@ -1,8 +1,8 @@ import { Injectable } from "@angular/core"; -export type InternalStateType = { +export interface InternalStateType { [key: string]: any; -}; +} @Injectable() export class AppState { diff --git a/starter/src/app/home/home.component.spec.ts b/starter/src/app/home/home.component.spec.ts index 3d765e2fd4..e227006896 100644 --- a/starter/src/app/home/home.component.spec.ts +++ b/starter/src/app/home/home.component.spec.ts @@ -1,7 +1,6 @@ import { NO_ERRORS_SCHEMA } from "@angular/core"; -import { inject, async, TestBed, ComponentFixture, getTestBed } from "@angular/core/testing"; -import { Component } from "@angular/core"; -import { HttpClientTestingModule, HttpTestingController } from "@angular/common/http/testing"; +import { async, TestBed, ComponentFixture } from "@angular/core/testing"; +import { HttpClientTestingModule } from "@angular/common/http/testing"; /** * Load the implementations that should be tested. @@ -13,9 +12,6 @@ import { Title } from "./title"; describe(`Home`, () => { let comp: HomeComponent; let fixture: ComponentFixture; - let injector: TestBed; - let service: AppState; - let httpMock: HttpTestingController; /** * async beforeEach. @@ -33,9 +29,6 @@ describe(`Home`, () => { * Compile template and css. */ .compileComponents(); - injector = getTestBed(); - service = injector.get(AppState); - httpMock = injector.get(HttpTestingController); }) ); diff --git a/starter/src/app/home/home.component.ts b/starter/src/app/home/home.component.ts index 6af7bff948..374934deb6 100644 --- a/starter/src/app/home/home.component.ts +++ b/starter/src/app/home/home.component.ts @@ -21,7 +21,7 @@ import { Title } from "./title"; /** * Every Angular template is first compiled by the browser before Angular runs it's compiler. */ - templateUrl: "./home.component.html" + template: require("./home.component.html") }) export class HomeComponent implements OnInit { /** diff --git a/starter/src/app/home/home.e2e.ts b/starter/src/app/home/home.e2e.ts index 4f2a8e85cd..f2f5b721de 100644 --- a/starter/src/app/home/home.e2e.ts +++ b/starter/src/app/home/home.e2e.ts @@ -10,14 +10,14 @@ describe("Home", () => { }); it("should have a title", async () => { - let subject = await browser.getTitle(); - let result = "Angular Starter by @gdi2290 from @TipeIO"; + const subject = await browser.getTitle(); + const result = "Angular Starter by @gdi2290 from @TipeIO"; expect(subject).toEqual(result); }); it("should have `your content here` x-large", async () => { - let subject = await element(by.css("[x-large]")).getText(); - let result = "Your Content Here"; + const subject = await element(by.css("[x-large]")).getText(); + const result = "Your Content Here"; expect(subject).toEqual(result); }); }); diff --git a/starter/src/app/home/title/title.service.spec.ts b/starter/src/app/home/title/title.service.spec.ts index d5359fc89e..4f7428736c 100644 --- a/starter/src/app/home/title/title.service.spec.ts +++ b/starter/src/app/home/title/title.service.spec.ts @@ -1,6 +1,5 @@ -import { inject, async, TestBed, ComponentFixture, getTestBed } from "@angular/core/testing"; -import { Component } from "@angular/core"; -import { HttpClientTestingModule, HttpTestingController } from "@angular/common/http/testing"; +import { inject, TestBed } from "@angular/core/testing"; +import { HttpClientTestingModule } from "@angular/common/http/testing"; import { Title } from "./title.service"; describe("Title", () => { diff --git a/starter/src/app/home/x-large/x-large.directive.spec.ts b/starter/src/app/home/x-large/x-large.directive.spec.ts index 498ac5d557..88354b991e 100644 --- a/starter/src/app/home/x-large/x-large.directive.spec.ts +++ b/starter/src/app/home/x-large/x-large.directive.spec.ts @@ -1,7 +1,6 @@ import { By } from "@angular/platform-browser"; -import { inject, fakeAsync, tick, async, TestBed, ComponentFixture, getTestBed } from "@angular/core/testing"; +import { fakeAsync, tick, TestBed } from "@angular/core/testing"; import { Component } from "@angular/core"; -import { HttpClientTestingModule, HttpTestingController } from "@angular/common/http/testing"; /** * Load the implementations that should be tested. diff --git a/starter/src/custom-typings.d.ts b/starter/src/custom-typings.d.ts index 5a136cce56..a0fb47a290 100644 --- a/starter/src/custom-typings.d.ts +++ b/starter/src/custom-typings.d.ts @@ -72,16 +72,14 @@ interface GlobalEnvironment { System: SystemJS; } -interface Es6PromiseLoader { - (id: string): (exportName?: string) => Promise; -} +type Es6PromiseLoader = (id: string) => (exportName?: string) => Promise; type FactoryEs6PromiseLoader = () => Es6PromiseLoader; type FactoryPromise = () => Promise; -type AsyncRoutes = { +interface AsyncRoutes { [component: string]: Es6PromiseLoader | Function | FactoryEs6PromiseLoader | FactoryPromise; -}; +} type IdleCallbacks = Es6PromiseLoader | Function | FactoryEs6PromiseLoader | FactoryPromise; diff --git a/starter/src/main.browser.ts b/starter/src/main.browser.ts index a3510d1417..8025078044 100644 --- a/starter/src/main.browser.ts +++ b/starter/src/main.browser.ts @@ -2,7 +2,7 @@ * Angular bootstrapping */ import { platformBrowserDynamic } from "@angular/platform-browser-dynamic"; -import { environment } from "environments/environment"; +import { environment } from "./environments/environment"; /** * App Module diff --git a/starter/tsconfig.app.json b/starter/tsconfig.app.json new file mode 100644 index 0000000000..da4b03e03d --- /dev/null +++ b/starter/tsconfig.app.json @@ -0,0 +1,15 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "es2015", + "lib": ["es2015", "dom"], + "types": ["hammerjs", "jasmine", "node", "source-map", "uglify-js", "webpack"], + "paths": { + "@angular/*": ["node_modules/@angular/*"], + "@nationalbankbelgium/stark-build/*": ["node_modules/@nationalbankbelgium/stark-build/*"], + "@nationalbankbelgium/stark-core/*": ["node_modules/@nationalbankbelgium/stark-core/*"] + }, + "typeRoots": ["./node_modules/@types"] + }, + "exclude": ["node_modules", "dist", "src/**/*.spec.ts", "src/**/*.e2e.ts"] +} diff --git a/starter/tsconfig.json b/starter/tsconfig.json index 0c815db833..2bc4ed6bee 100644 --- a/starter/tsconfig.json +++ b/starter/tsconfig.json @@ -1,22 +1,8 @@ { "extends": "./node_modules/@nationalbankbelgium/stark-build/tsconfig.json", "compilerOptions": { - "module": "commonjs", - "allowSyntheticDefaultImports": true, - "lib": ["dom", "es6"], - "paths": { - "@angular/*": ["node_modules/@angular/*"], - "@nationalbankbelgium/stark-build/*": ["node_modules/@nationalbankbelgium/stark-build/*"] - }, - "types": ["hammerjs", "jasmine", "node", "source-map", "uglify-js", "webpack"] + "types": ["hammerjs", "jasmine", "node", "source-map", "uglify-js", "webpack"], + "typeRoots": ["./node_modules/@types"] }, - "exclude": ["node_modules", "dist"], - "angularCompilerOptions": { - "skipMetadataEmit": true - }, - "compileOnSave": false, - "buildOnSave": false, - "atom": { - "rewriteTsconfig": false - } + "exclude": ["node_modules", "dist"] } diff --git a/starter/tsconfig.spec.json b/starter/tsconfig.spec.json new file mode 100644 index 0000000000..3b3a1e0a82 --- /dev/null +++ b/starter/tsconfig.spec.json @@ -0,0 +1,19 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "commonjs", + "typeRoots": ["./node_modules/@types"], + "lib": ["dom", "dom.iterable", "es2017"], + "paths": { + "@angular/*": ["node_modules/@angular/*"], + "@nationalbankbelgium/stark-build/*": ["node_modules/@nationalbankbelgium/stark-build/*"], + "@nationalbankbelgium/stark-core/*": ["node_modules/@nationalbankbelgium/stark-core/*"] + } + }, + + "angularCompilerOptions": { + "annotateForClosureCompiler": true, + "strictMetadataEmit": false, + "skipTemplateCodegen": true + } +} diff --git a/starter/tsconfig.webpack.json b/starter/tsconfig.webpack.json deleted file mode 100644 index c0095474ab..0000000000 --- a/starter/tsconfig.webpack.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "module": "es2015", - "lib": ["es2015", "dom"] - }, - "exclude": ["node_modules", "dist", "src/**/*.spec.ts", "src/**/*.e2e.ts"] -}