@rivinia/env 0.2.0 → 0.3.0
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 +6 -6
- package/package.json +1 -1
- package/schematics/collection.json +1 -1
- package/schematics/ng-add/index.cjs +22 -17
- package/schematics/ng-add/schema.json +19 -7
package/README.md
CHANGED
|
@@ -8,14 +8,14 @@ Typed application environments for Angular: dev/staging/prod file layout, a
|
|
|
8
8
|
files and wires the build configurations. Zero runtime code — environments are
|
|
9
9
|
build-time constants; this package ships types plus setup tooling only.
|
|
10
10
|
|
|
11
|
-
- Version: **0.
|
|
11
|
+
- Version: **0.3.0**
|
|
12
12
|
- Requires: nothing at runtime (types only). Schematic runs under Angular CLI 22+.
|
|
13
13
|
|
|
14
14
|
## Install
|
|
15
15
|
|
|
16
16
|
```bash
|
|
17
17
|
npm install @rivinia/env
|
|
18
|
-
ng add @rivinia/env # multi-select:
|
|
18
|
+
ng add @rivinia/env # multi-select: dev / stage / prod
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
Interactive runs ask which environments to scaffold (checkbox, all checked by
|
|
@@ -23,7 +23,7 @@ default); non-interactive runs take all. From flags, comma-separate (short
|
|
|
23
23
|
aliases work: `dev`, `prod`, `stag`):
|
|
24
24
|
|
|
25
25
|
```bash
|
|
26
|
-
ng add @rivinia/env --environments
|
|
26
|
+
ng add @rivinia/env --environments stage,prod
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
Only the selection is scaffolded and wired (model + base file always — the
|
|
@@ -36,9 +36,9 @@ overwrite files or duplicate configuration.
|
|
|
36
36
|
|
|
37
37
|
```
|
|
38
38
|
environment.model.ts # AppEnvironment extends BaseEnvironment — extend it
|
|
39
|
-
environment.ts #
|
|
40
|
-
environment.staging.ts #
|
|
41
|
-
environment.prod.ts #
|
|
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
42
|
```
|
|
43
43
|
|
|
44
44
|
and wires `angular.json`: `production` gains its replacement if missing, and a
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"$schema": "../../../node_modules/@angular-devkit/schematics/collection-schema.json",
|
|
3
3
|
"schematics": {
|
|
4
4
|
"ng-add": {
|
|
5
|
-
"description": "Scaffold typed environment files and wire dev/
|
|
5
|
+
"description": "Scaffold typed environment files and wire dev/stage/prod configurations.",
|
|
6
6
|
"factory": "./ng-add/index.cjs#ngAdd",
|
|
7
7
|
"schema": "./ng-add/schema.json"
|
|
8
8
|
}
|
|
@@ -14,19 +14,25 @@ export interface AppEnvironment extends BaseEnvironment {
|
|
|
14
14
|
readonly apiUrl: string;
|
|
15
15
|
}
|
|
16
16
|
`;
|
|
17
|
-
const ALL_ENVIRONMENTS = ['
|
|
17
|
+
const ALL_ENVIRONMENTS = ['dev', 'stage', 'prod'];
|
|
18
18
|
/** Short aliases users actually type (`prod`, `dev`, `stag`). */
|
|
19
19
|
const ENVIRONMENT_ALIASES = {
|
|
20
|
-
dev: '
|
|
21
|
-
prod: '
|
|
22
|
-
stag: '
|
|
23
|
-
stage: '
|
|
20
|
+
dev: 'dev',
|
|
21
|
+
prod: 'prod',
|
|
22
|
+
stag: 'stage',
|
|
23
|
+
stage: 'stage',
|
|
24
24
|
};
|
|
25
25
|
/** Output directory short names: builds/dev, builds/prod, builds/stag. */
|
|
26
26
|
const OUTPUT_DIR = {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
dev: 'builds/dev',
|
|
28
|
+
stage: 'builds/stag',
|
|
29
|
+
prod: 'builds/prod',
|
|
30
|
+
};
|
|
31
|
+
/** Maps an environment name to its Angular CLI configuration name. */
|
|
32
|
+
const CONFIG_NAME = {
|
|
33
|
+
dev: 'development',
|
|
34
|
+
stage: 'staging',
|
|
35
|
+
prod: 'production',
|
|
30
36
|
};
|
|
31
37
|
const fileDefs = (sourceRoot, selected) => {
|
|
32
38
|
const files = [
|
|
@@ -44,7 +50,7 @@ const fileDefs = (sourceRoot, selected) => {
|
|
|
44
50
|
`};\n`,
|
|
45
51
|
},
|
|
46
52
|
];
|
|
47
|
-
if (selected.includes('
|
|
53
|
+
if (selected.includes('stage')) {
|
|
48
54
|
files.push({
|
|
49
55
|
name: `${sourceRoot}/environments/environment.staging.ts`,
|
|
50
56
|
content: (version) => `import type { AppEnvironment } from './environment.model';\n\n` +
|
|
@@ -56,7 +62,7 @@ const fileDefs = (sourceRoot, selected) => {
|
|
|
56
62
|
`};\n`,
|
|
57
63
|
});
|
|
58
64
|
}
|
|
59
|
-
if (selected.includes('
|
|
65
|
+
if (selected.includes('prod')) {
|
|
60
66
|
files.push({
|
|
61
67
|
name: `${sourceRoot}/environments/environment.prod.ts`,
|
|
62
68
|
content: (version) => `import type { AppEnvironment } from './environment.model';\n\n` +
|
|
@@ -105,11 +111,9 @@ function ngAdd(options) {
|
|
|
105
111
|
const unknown = [...new Set(cleaned)].filter((e) => !ALL_ENVIRONMENTS.includes(e));
|
|
106
112
|
if (unknown.length > 0) {
|
|
107
113
|
throw new schematics_1.SchematicsException(`[rivinia/env] unknown environment(s): ${unknown.join(', ')}. ` +
|
|
108
|
-
`Choose from
|
|
114
|
+
`Choose from dev, stage (stag), prod.`);
|
|
109
115
|
}
|
|
110
|
-
const selected = cleaned.length > 0
|
|
111
|
-
? [...new Set(cleaned)]
|
|
112
|
-
: [...ALL_ENVIRONMENTS];
|
|
116
|
+
const selected = cleaned.length > 0 ? [...new Set(cleaned)] : [...ALL_ENVIRONMENTS];
|
|
113
117
|
const configsSnapshot = () => JSON.stringify(project.architect?.build?.configurations ?? null);
|
|
114
118
|
const configsBefore = configsSnapshot();
|
|
115
119
|
let created = 0;
|
|
@@ -122,13 +126,13 @@ function ngAdd(options) {
|
|
|
122
126
|
tree.create(path, file.content(version));
|
|
123
127
|
created++;
|
|
124
128
|
}
|
|
125
|
-
if (selected.includes('
|
|
129
|
+
if (selected.includes('prod')) {
|
|
126
130
|
ensureReplacement(tree, angular, name, 'production', {
|
|
127
131
|
replace: `${sourceRoot}/environments/environment.ts`,
|
|
128
132
|
with: `${sourceRoot}/environments/environment.prod.ts`,
|
|
129
133
|
});
|
|
130
134
|
}
|
|
131
|
-
if (selected.includes('
|
|
135
|
+
if (selected.includes('stage')) {
|
|
132
136
|
ensureStaging(tree, angular, name, sourceRoot, context);
|
|
133
137
|
}
|
|
134
138
|
ensureOutputPaths(tree, angular, name, selected, context);
|
|
@@ -224,7 +228,8 @@ function ensureOutputPaths(tree, angular, name, selected, context) {
|
|
|
224
228
|
const configurations = getConfigurations(angular, name);
|
|
225
229
|
let touched = false;
|
|
226
230
|
for (const env of selected) {
|
|
227
|
-
const
|
|
231
|
+
const configName = CONFIG_NAME[env];
|
|
232
|
+
const target = configurations[configName];
|
|
228
233
|
if (!target || 'outputPath' in target)
|
|
229
234
|
continue;
|
|
230
235
|
target['outputPath'] = OUTPUT_DIR[env];
|
|
@@ -6,23 +6,35 @@
|
|
|
6
6
|
"properties": {
|
|
7
7
|
"environments": {
|
|
8
8
|
"type": ["array", "string"],
|
|
9
|
-
"description": "Which environments to scaffold and wire: array, or comma-separated string on the CLI (--environments
|
|
10
|
-
"default": ["
|
|
11
|
-
"items": {
|
|
9
|
+
"description": "Which environments to scaffold and wire: array, or comma-separated string on the CLI (--environments stage,prod). Model + base file always. Omit for all three.",
|
|
10
|
+
"default": ["dev", "stage", "prod"],
|
|
11
|
+
"items": {
|
|
12
|
+
"type": "string",
|
|
13
|
+
"enum": ["dev", "stage", "prod", "stag"]
|
|
14
|
+
},
|
|
12
15
|
"x-prompt": {
|
|
13
16
|
"message": "Which environments should ng-add scaffold and wire?",
|
|
14
17
|
"type": "list",
|
|
15
18
|
"multiselect": true,
|
|
16
19
|
"items": [
|
|
17
|
-
{
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
{
|
|
21
|
+
"value": "dev",
|
|
22
|
+
"label": "dev \u2014 base file, no replacement"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"value": "stage",
|
|
26
|
+
"label": "stage \u2014 staging file + configuration"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"value": "prod",
|
|
30
|
+
"label": "prod \u2014 prod file + replacement"
|
|
31
|
+
}
|
|
20
32
|
]
|
|
21
33
|
}
|
|
22
34
|
},
|
|
23
35
|
"project": {
|
|
24
36
|
"type": "string",
|
|
25
|
-
"description": "Angular CLI project name
|
|
37
|
+
"description": "Angular CLI project name \u2014 only for multi-app workspaces. Defaults to the workspace default project.",
|
|
26
38
|
"default": ""
|
|
27
39
|
}
|
|
28
40
|
},
|