diff --git a/generators/app/index.js b/generators/app/index.js index 4866475e..d33d05f7 100755 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -302,6 +302,7 @@ module.exports = Generator.make({ 'electron-linux': props => props.desktop && props.desktop.includes('linux'), 'tools-hads': props => props.tools && props.tools.includes('hads'), 'tools-jest': props => props.tools && props.tools.includes('jest'), - 'tools-karma': props => props.tools && !props.tools.includes('jest') + 'tools-karma': props => props.tools && !props.tools.includes('jest'), + 'dtap': props => props.dtap }) }); diff --git a/generators/app/prompts.js b/generators/app/prompts.js index 9216eed1..29142553 100755 --- a/generators/app/prompts.js +++ b/generators/app/prompts.js @@ -225,6 +225,12 @@ module.exports = [ } ] }, + { + type: 'confirm', + name: 'dtap', + message: 'Do you want common architecture development, testing, acceptance and production (DTAP)?', + default: false + }, { type: 'list', name: 'deploy', diff --git a/generators/app/templates/_README.md b/generators/app/templates/_README.md index bf2f2a26..94359ebd 100644 --- a/generators/app/templates/_README.md +++ b/generators/app/templates/_README.md @@ -72,6 +72,8 @@ Task | Description `npm run build [-- --configuration=production]` | Lint code and build web app for production (with [AOT](https://angular.io/guide/aot-compiler)) in `www/` folder <% } else { -%> `npm run build [-- --configuration=production]` | Lint code and build web app for production (with [AOT](https://angular.io/guide/aot-compiler)) in `dist/` folder +`npm run build:testing` | Lint code and build web app for user testing (with [AOT](https://angular.io/guide/aot-compiler)) in `dist/` folder +`npm run build:acceptance` | Lint code and build web app for user acceptance (with [AOT](https://angular.io/guide/aot-compiler)) in `dist/` folder <% } -%> <% } -%> <% if (props.target.includes('cordova')) { -%> diff --git a/generators/app/templates/_angular.json b/generators/app/templates/_angular.json index 2087977a..2b89b7f4 100644 --- a/generators/app/templates/_angular.json +++ b/generators/app/templates/_angular.json @@ -78,6 +78,70 @@ } ] }, +<% if (props.dtap) { -%> + "testing": { + "optimization": true, + "outputHashing": "all", + "sourceMap": false, + "extractCss": true, + "namedChunks": false, + "aot": true, + "extractLicenses": true, + "vendorChunk": false, + "buildOptimizer": true, + "budgets": [ + { + "type": "initial", + "maximumWarning": "2mb", + "maximumError": "5mb" + }, + { + "type": "anyComponentStyle", + "maximumWarning": "6kb" + } + ], +<% if (props.pwa) { -%> + "serviceWorker": true, +<% } -%> + "fileReplacements": [ + { + "replace": "src/environments/environment.ts", + "with": "src/environments/environment.testing.ts" + } + ] + }, + "acceptance": { + "optimization": true, + "outputHashing": "all", + "sourceMap": false, + "extractCss": true, + "namedChunks": false, + "aot": true, + "extractLicenses": true, + "vendorChunk": false, + "buildOptimizer": true, + "budgets": [ + { + "type": "initial", + "maximumWarning": "2mb", + "maximumError": "5mb" + }, + { + "type": "anyComponentStyle", + "maximumWarning": "6kb" + } + ], +<% if (props.pwa) { -%> + "serviceWorker": true, +<% } -%> + "fileReplacements": [ + { + "replace": "src/environments/environment.ts", + "with": "src/environments/environment.acceptance.ts" + } + ] + }, +<% } -%> "ci": { "progress": false } diff --git a/generators/app/templates/_package.json b/generators/app/templates/_package.json index bd432f57..abd72012 100644 --- a/generators/app/templates/_package.json +++ b/generators/app/templates/_package.json @@ -9,6 +9,10 @@ "scripts": { "ng": "ng", "build": "<%= run('env') %> && ng build --prod", +<% if (props.dtap) { -%> + "build:testing": "<%= run('env') %> && ng build --prod --configuration=testing", + "build:acceptance": "<%= run('env') %> && ng build --prod --configuration=acceptance", +<% } -%> "start": "<%= run('env') %> && ng serve --proxy-config proxy.conf.js", <% if (props.deploy !== 'none') { -%> "deploy": "<%= run('env') %> && ng deploy", diff --git a/generators/app/templates/src/environments/__dtap._environment.acceptance.ts b/generators/app/templates/src/environments/__dtap._environment.acceptance.ts new file mode 100644 index 00000000..38c17285 --- /dev/null +++ b/generators/app/templates/src/environments/__dtap._environment.acceptance.ts @@ -0,0 +1,16 @@ +// `.env.ts` is generated by the `npm run env` command +// `npm run env` exposes environment variables as JSON for any usage you might +// want, like displaying the version or getting extra config from your CI bot, etc. +// This is useful for granularity you might need beyond just the environment. +// Note that as usual, any environment variables you expose through it will end up in your +// bundle, and you should not use it for any sensitive information like passwords or keys. +import { env } from './.env'; + +export const environment = { + production: true, + hmr: false, + version: env.npm_package_version + '-acceptance', + serverUrl: 'https://api.chucknorris.io', + defaultLanguage: '<%= props.languages.includes('en-US') ? 'en-US' : props.languages[0] %>', + supportedLanguages: [<%- (props['languages']).map(language => `'${language}'`).join(', ') %>] +}; diff --git a/generators/app/templates/src/environments/__dtap._environment.testing.ts b/generators/app/templates/src/environments/__dtap._environment.testing.ts new file mode 100644 index 00000000..461eac22 --- /dev/null +++ b/generators/app/templates/src/environments/__dtap._environment.testing.ts @@ -0,0 +1,16 @@ +// `.env.ts` is generated by the `npm run env` command +// `npm run env` exposes environment variables as JSON for any usage you might +// want, like displaying the version or getting extra config from your CI bot, etc. +// This is useful for granularity you might need beyond just the environment. +// Note that as usual, any environment variables you expose through it will end up in your +// bundle, and you should not use it for any sensitive information like passwords or keys. +import { env } from './.env'; + +export const environment = { + production: true, + hmr: false, + version: env.npm_package_version + '-testing', + serverUrl: 'https://api.chucknorris.io', + defaultLanguage: '<%= props.languages.includes('en-US') ? 'en-US' : props.languages[0] %>', + supportedLanguages: [<%- (props['languages']).map(language => `'${language}'`).join(', ') %>] +};