diff --git a/docs/guides/development.md b/docs/guides/development.md index bbd5164097..c3c4e56899 100644 --- a/docs/guides/development.md +++ b/docs/guides/development.md @@ -56,6 +56,9 @@ This environment file references two more files: - `environment.model.ts` where "ENVIRONMENT_DEFAULTS" are taken from - `environment.development.ts` where you can add your own configuration only for the local development environment, see overrides explanation above. +To provide a common `environment.development.ts` base configuration for projects one can add the file `src/environments/environment.development.ts.template` to the project sources and pre-configure it for the projects context. +This template will then be used by the initial `npm install` instead of our standard development configuration. + ## Development Server Run `ng serve` or `ng s` for a development server. diff --git a/scripts/init-development-environment.js b/scripts/init-development-environment.js index 8ca335c176..c5817d3fcd 100644 --- a/scripts/init-development-environment.js +++ b/scripts/init-development-environment.js @@ -1,32 +1,17 @@ -const force = process.argv.length > 2 && process.argv.slice(2).find(arg => arg === '-f' || arg === '--force'); -const empty = process.argv.length > 2 && process.argv.slice(2).find(arg => arg === '--empty'); - -const envDevFile = 'src/environments/environment.development.ts'; - const fs = require('fs'); -if (empty) { - console.log('writing empty ' + envDevFile); - - fs.writeFileSync( - envDevFile, - `import { Environment } from "./environment.model"; - -export const overrides: Partial = {}; -` - ); -} else if (!fs.existsSync(envDevFile) || force) { - if (fs.existsSync(envDevFile)) { - const environmentLocalBackupPath = envDevFile + '.bak'; - console.log('creating backup ' + environmentLocalBackupPath); - fs.renameSync(envDevFile, environmentLocalBackupPath); - } +const force = process.argv.length > 2 && process.argv.slice(2).find(arg => arg === '-f' || arg === '--force'); +const empty = process.argv.length > 2 && process.argv.slice(2).find(arg => arg === '--empty'); - console.log('writing ' + envDevFile); +const envDevPath = 'src/environments/environment.development.ts'; +const envDevTemplatePath = 'src/environments/environment.development.ts.template'; - fs.writeFileSync( - envDevFile, - `import { Environment } from "./environment.model"; +/** @type string */ +let envDevTemplate; +if (fs.existsSync(envDevTemplatePath)) { + envDevTemplate = fs.readFileSync('src/environments/environment.development.ts.template', 'utf8'); +} else { + envDevTemplate = `import { Environment } from "./environment.model"; /* eslint-disable */ @@ -40,8 +25,29 @@ export const overrides: Partial = { // features: ['compare'], }; +`; +} + +if (empty) { + console.log('writing empty ' + envDevPath); + + fs.writeFileSync( + envDevPath, + `import { Environment } from "./environment.model"; + +export const overrides: Partial = {}; ` ); +} else if (!fs.existsSync(envDevPath) || force) { + if (fs.existsSync(envDevPath)) { + const environmentLocalBackupPath = envDevPath + '.bak'; + console.log('creating backup ' + environmentLocalBackupPath); + fs.renameSync(envDevPath, environmentLocalBackupPath); + } + + console.log('writing ' + envDevPath); + + fs.writeFileSync(envDevPath, envDevTemplate); } else { - console.log('not overwriting existing ' + envDevFile); + console.log('not overwriting existing ' + envDevPath); }