@rivinia/env 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +94 -32
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,50 +3,49 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/@rivinia/env)
|
|
4
4
|
[](https://www.npmjs.com/package/@rivinia/env)
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
`@rivinia/env` provides the `BaseEnvironment` TypeScript contract and an
|
|
7
|
+
Angular CLI `ng add` schematic. It does not read environment values at
|
|
8
|
+
runtime: Angular's build file replacements select a statically imported
|
|
9
|
+
environment file.
|
|
10
10
|
|
|
11
|
-
-
|
|
12
|
-
-
|
|
11
|
+
- Prepared patch: **0.3.1** (latest published: **0.3.0**)
|
|
12
|
+
- No runtime providers or services; the package supplies a type and CLI tooling.
|
|
13
|
+
- The generated model imports `BaseEnvironment` from this package.
|
|
13
14
|
|
|
14
|
-
## Install
|
|
15
|
+
## Install and scaffold
|
|
16
|
+
|
|
17
|
+
From an Angular CLI workspace:
|
|
15
18
|
|
|
16
19
|
```bash
|
|
17
20
|
npm install @rivinia/env
|
|
18
|
-
ng add @rivinia/env
|
|
21
|
+
ng add @rivinia/env
|
|
19
22
|
```
|
|
20
23
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
The schematic prompts for environments when interactive; the default and
|
|
25
|
+
non-interactive selection is all three (`dev`, `stage`, `prod`). Select only
|
|
26
|
+
what you need with a comma-separated option:
|
|
24
27
|
|
|
25
28
|
```bash
|
|
26
29
|
ng add @rivinia/env --environments stage,prod
|
|
27
30
|
```
|
|
28
31
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
overwrite files or duplicate configuration.
|
|
32
|
+
Accepted names are `dev`, `stage` (or `stag`), and `prod`. `--project <name>`
|
|
33
|
+
selects a project in a multi-project workspace; otherwise it uses
|
|
34
|
+
`defaultProject` from `angular.json`, falling back to the first project.
|
|
35
|
+
The schematic uses that project's `sourceRoot` (or `<root>/src`, then `src`).
|
|
34
36
|
|
|
35
|
-
|
|
37
|
+
The model and development base file are always scaffolded. The selected
|
|
38
|
+
environment files are created only if they do not already exist:
|
|
36
39
|
|
|
40
|
+
```text
|
|
41
|
+
src/environments/
|
|
42
|
+
environment.model.ts # AppEnvironment extends BaseEnvironment
|
|
43
|
+
environment.ts # development defaults; not replaced by the CLI
|
|
44
|
+
environment.staging.ts # only when stage is selected
|
|
45
|
+
environment.prod.ts # only when prod is selected
|
|
37
46
|
```
|
|
38
|
-
environment.model.ts # AppEnvironment extends BaseEnvironment — extend it
|
|
39
|
-
environment.ts # dev defaults (used as-is by `dev`)
|
|
40
|
-
environment.staging.ts # stage values (production: true)
|
|
41
|
-
environment.prod.ts # prod values
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
and wires `angular.json`: `production` gains its replacement if missing, and a
|
|
45
|
-
`staging` configuration (copied from `production`) is created if absent.
|
|
46
|
-
`development` intentionally gets no replacement (CLI standard). The app version
|
|
47
|
-
is snapshotted from your `package.json` into each file (`0.0.0` fallback).
|
|
48
47
|
|
|
49
|
-
|
|
48
|
+
The generated contract and values have this shape:
|
|
50
49
|
|
|
51
50
|
```ts
|
|
52
51
|
// environment.model.ts
|
|
@@ -55,14 +54,77 @@ import type { BaseEnvironment } from '@rivinia/env';
|
|
|
55
54
|
export interface AppEnvironment extends BaseEnvironment {
|
|
56
55
|
readonly apiUrl: string;
|
|
57
56
|
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
// environment.ts (generated development defaults)
|
|
61
|
+
import type { AppEnvironment } from './environment.model';
|
|
62
|
+
|
|
63
|
+
export const environment: AppEnvironment = {
|
|
64
|
+
production: false,
|
|
65
|
+
version: '1.2.3',
|
|
66
|
+
apiUrl: 'http://localhost:3000/api',
|
|
67
|
+
};
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Staging and production files have the same fields, with `production: true`;
|
|
71
|
+
their generated API URLs are `https://staging.example.com/api` and
|
|
72
|
+
`https://api.example.com/api`. Replace these example URLs and any other
|
|
73
|
+
generated values with the app's real configuration.
|
|
74
|
+
|
|
75
|
+
The schematic adds a file replacement to an existing `production`
|
|
76
|
+
configuration when `prod` is selected. When `stage` is selected, it creates a
|
|
77
|
+
`staging` configuration if needed (copying `production` settings except its
|
|
78
|
+
`fileReplacements` and `outputPath`) and adds the staging replacement.
|
|
79
|
+
`development` intentionally uses `environment.ts` directly. The schematic
|
|
80
|
+
does not create a missing `production` or `development` configuration.
|
|
81
|
+
|
|
82
|
+
For selected configurations that exist, it sets `outputPath` to
|
|
83
|
+
`builds/dev`, `builds/stag`, or `builds/prod` only if no output path is
|
|
84
|
+
already configured. If that adds an output path and a root `.gitignore`
|
|
85
|
+
exists, `/builds` is appended once. Existing output paths and files are never
|
|
86
|
+
overwritten; repeated runs do not duplicate replacements.
|
|
87
|
+
|
|
88
|
+
The version in generated files is copied from the workspace-root
|
|
89
|
+
`package.json` when each file is first created (`0.0.0` if unavailable).
|
|
90
|
+
Since the schematic never overwrites existing files, update `version` in
|
|
91
|
+
those environment files manually when releasing a new app version; rerunning
|
|
92
|
+
`ng add` will not refresh it.
|
|
58
93
|
|
|
59
|
-
|
|
94
|
+
## Use the selected environment
|
|
95
|
+
|
|
96
|
+
Always import the base path from the app, not a stage/prod-specific file:
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
// src/app/trip.service.ts
|
|
100
|
+
import { Injectable } from '@angular/core';
|
|
60
101
|
import { environment } from '../environments/environment';
|
|
61
|
-
|
|
62
|
-
|
|
102
|
+
|
|
103
|
+
@Injectable({ providedIn: 'root' })
|
|
104
|
+
export class TripService {
|
|
105
|
+
readonly apiUrl = environment.apiUrl;
|
|
106
|
+
}
|
|
63
107
|
```
|
|
64
108
|
|
|
65
|
-
|
|
109
|
+
The Angular CLI replaces `environment.ts` for the selected build
|
|
110
|
+
configuration. For example:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
ng build --configuration development
|
|
114
|
+
ng build --configuration staging
|
|
115
|
+
ng build --configuration production
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
The generated files are compile-time configuration, not secrets: values
|
|
119
|
+
included in a browser build are visible to its users. `BaseEnvironment`
|
|
120
|
+
requires only readonly `production: boolean` and `version: string`; extend
|
|
121
|
+
AppEnvironment with the fields your app needs.
|
|
122
|
+
|
|
123
|
+
## Public API
|
|
124
|
+
|
|
125
|
+
| Export | Kind | Purpose |
|
|
126
|
+
| ----------------- | ---- | ---------------------------------------------------------------------- |
|
|
127
|
+
| `BaseEnvironment` | type | Required `production` and `version` fields for app environment models. |
|
|
66
128
|
|
|
67
129
|
## License
|
|
68
130
|
|