Skip to content

feat(@schematics/angular): add environments generation schematic#24409

Merged
angular-robot[bot] merged 1 commit into
angular:mainfrom
clydin:schematics/environments
Dec 13, 2022
Merged

feat(@schematics/angular): add environments generation schematic#24409
angular-robot[bot] merged 1 commit into
angular:mainfrom
clydin:schematics/environments

Conversation

@clydin
Copy link
Copy Markdown
Member

@clydin clydin commented Dec 9, 2022

A schematic has been added that will allow the generation of environment files for all existing build configurations within a project. The fileReplacements option will also be setup to allow the replacement of the appropriate environment file. Environment files themselves do not provide any special behavior beyond that of other application TypeScript files and rely on the fileReplacements option for build-time behavior. The schematic will skip generating environment files for configurations that already have an appropriately named environment file. The fileReplacements option addition will also be skipped if an appropriate entry is already present.
Example usage: ng generate environments

Closes #24381

@clydin clydin added the target: minor This PR is targeted for the next minor release label Dec 9, 2022
@angular-robot angular-robot Bot added the detected: feature PR contains a feature commit label Dec 9, 2022
@clydin clydin marked this pull request as ready for review December 10, 2022 00:05
Copy link
Copy Markdown
Collaborator

@alan-agius4 alan-agius4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of comments. Otherwise this looks good.

Comment thread packages/schematics/angular/environments/index.ts
Comment thread packages/schematics/angular/environments/index.ts
Comment thread packages/schematics/angular/environments/schema.json Outdated
@clydin clydin force-pushed the schematics/environments branch 2 times, most recently from b5031cd to fb46369 Compare December 12, 2022 16:22
A schematic has been added that will allow the generation of environment files
for all existing configurations within a project. The `fileReplacements` option
will also be setup to allow the replacement of the appropriate environment file.
Environment files themselves do not provide any special behavior beyond
that of other application TypeScript files and rely on the `fileReplacements`
option for build-time behavior. The schematic will skip generating environment files
for configurations that already have an appropriately named environment file. The
`fileReplacements` option addition will also be skipped if an appropriate entry
is already present.
@clydin clydin force-pushed the schematics/environments branch from fb46369 to 32526d5 Compare December 12, 2022 17:14
@clydin clydin requested a review from alan-agius4 December 12, 2022 17:19
@clydin clydin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Dec 12, 2022
@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Dec 13, 2022
@angular-robot angular-robot Bot merged commit 8d000d1 into angular:main Dec 13, 2022
@clydin clydin deleted the schematics/environments branch December 13, 2022 14:28
@alexander-kastil
Copy link
Copy Markdown

@clydin Could you please share on how to use your schematics to add env files. thank you in advance

@clydin
Copy link
Copy Markdown
Member Author

clydin commented Dec 14, 2022

Description updated with an example usage.

@ek1mb4
Copy link
Copy Markdown

ek1mb4 commented Dec 31, 2022

A schematic has been added that will allow the generation of environment files for all existing build configurations within a project. The fileReplacements option will also be setup to allow the replacement of the appropriate environment file. Environment files themselves do not provide any special behavior beyond that of other application TypeScript files and rely on the fileReplacements option for build-time behavior. The schematic will skip generating environment files for configurations that already have an appropriately named environment file. The fileReplacements option addition will also be skipped if an appropriate entry is already present. Example usage: ng generate environments

Closes #24381

Your example does not work. "ng generate environments". I guess I will be using a service.

@clydin
Copy link
Copy Markdown
Member Author

clydin commented Jan 3, 2023

It will be available in 15.1.0 which is currently in prerelease (available via the next npm tag).

@alexander-kastil
Copy link
Copy Markdown

@clydin Great job … For simpler apps environment.ts and *.prod.ts was a good & simple solution to provide global vars like api url, … thanks a lot 👍

@cosmoKenney
Copy link
Copy Markdown

cosmoKenney commented Feb 2, 2023

Somewhere along the line whole environments thing stopped working. In angular 8 I used to have one for development, staging and production. And had corresponding fileReplacements in angular.json. Doing ng build --configuration=staging would copy the environment.staging.ts into the dist/environments/environment.ts file. That no longer works in Angular 14. How do I accomplish the same thing with Angular 14?
This is clearly documented here in the Angular 14 documentation here: https://v14.angular.io/guide/build
And is clearly documented in the "stable" docs here: https://angular.io/guide/build
But none of what is written about fileReplacements there works.

@angular-automatic-lock-bot
Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Mar 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker detected: feature PR contains a feature commit target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bring back environment.ts to new projects

5 participants