generator-jhipster-yellowbricks-angular-contextpath 0.1.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 +58 -0
- package/cli/cli-customizations.cjs +2 -0
- package/cli/cli.cjs +38 -0
- package/generators/angular/command.js +13 -0
- package/generators/angular/generator.js +169 -0
- package/generators/angular/index.js +2 -0
- package/generators/angular/templates/template-file-angular.ejs +0 -0
- package/package.json +60 -0
package/README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# generator-jhipster-yellowbricks-angular-contextpath
|
|
2
|
+
|
|
3
|
+
A [JHipster](https://www.jhipster.tech/) blueprint that sets the Angular `baseHref` in `angular.json` to a configurable context path.
|
|
4
|
+
|
|
5
|
+
[![NPM version][npm-image]][npm-url]
|
|
6
|
+
[![Generator][github-generator-image]][github-generator-url]
|
|
7
|
+
|
|
8
|
+
## What it does
|
|
9
|
+
|
|
10
|
+
Patches `angular.json` during generation to insert `baseHref` as the first key in `build.options`:
|
|
11
|
+
|
|
12
|
+
```diff
|
|
13
|
+
"architect": {
|
|
14
|
+
"build": {
|
|
15
|
+
"builder": "@angular-builders/custom-esbuild:application",
|
|
16
|
+
"options": {
|
|
17
|
+
+ "baseHref": "/jh/",
|
|
18
|
+
...
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The value is configurable — any context path can be used.
|
|
22
|
+
|
|
23
|
+
## Prerequisites
|
|
24
|
+
|
|
25
|
+
- Node.js `^22.18.0 || >=24.11.0`
|
|
26
|
+
- JHipster 9
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm install -g generator-jhipster-yellowbricks-angular-contextpath
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
Run JHipster with this blueprint and pass your desired context path:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
jhipster --blueprints yellowbricks-angular-contextpath \
|
|
40
|
+
--yellowbricks-angular-contextpath-config='{"contextPath":"/jh/"}'
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Replace `/jh/` with your actual context path. The trailing slash is required.
|
|
44
|
+
|
|
45
|
+
## Pre-release
|
|
46
|
+
|
|
47
|
+
To use the latest unreleased version directly from GitHub:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
npm install -g idNoRD/generator-jhipster-yellowbricks-angular-contextpath#main
|
|
51
|
+
jhipster --blueprints yellowbricks-angular-contextpath \
|
|
52
|
+
--yellowbricks-angular-contextpath-config='{"contextPath":"/jh/"}'
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
[npm-image]: https://img.shields.io/npm/v/generator-jhipster-yellowbricks-angular-contextpath.svg
|
|
56
|
+
[npm-url]: https://npmjs.org/package/generator-jhipster-yellowbricks-angular-contextpath
|
|
57
|
+
[github-generator-image]: https://github.com/idNoRD/generator-jhipster-yellowbricks-angular-contextpath/actions/workflows/generator.yml/badge.svg
|
|
58
|
+
[github-generator-url]: https://github.com/idNoRD/generator-jhipster-yellowbricks-angular-contextpath/actions/workflows/generator.yml
|
package/cli/cli.cjs
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { basename, dirname, join } = require('path');
|
|
4
|
+
|
|
5
|
+
const { bin, version } = require('../package.json');
|
|
6
|
+
|
|
7
|
+
// Get package name to use as namespace.
|
|
8
|
+
// Allows blueprints to be aliased.
|
|
9
|
+
const packagePath = dirname(__dirname);
|
|
10
|
+
const packageFolderName = basename(packagePath);
|
|
11
|
+
const devBlueprintPath = join(packagePath, '.blueprint');
|
|
12
|
+
const blueprint = packageFolderName.startsWith('jhipster-') ? `generator-${packageFolderName}` : packageFolderName;
|
|
13
|
+
|
|
14
|
+
(async () => {
|
|
15
|
+
const { runJHipster, done, logger } = await import('generator-jhipster/cli');
|
|
16
|
+
const executableName = Object.keys(bin)[0];
|
|
17
|
+
|
|
18
|
+
runJHipster({
|
|
19
|
+
executableName,
|
|
20
|
+
executableVersion: version,
|
|
21
|
+
defaultCommand: 'app',
|
|
22
|
+
devBlueprintPath,
|
|
23
|
+
blueprints: {
|
|
24
|
+
[blueprint]: version,
|
|
25
|
+
},
|
|
26
|
+
printBlueprintLogo: () => {
|
|
27
|
+
console.log('===================== JHipster Yellowbricks Angular Contextpath =====================');
|
|
28
|
+
console.log('');
|
|
29
|
+
},
|
|
30
|
+
lookups: [{ packagePaths: [packagePath] }],
|
|
31
|
+
...require('./cli-customizations.cjs'),
|
|
32
|
+
}).catch(done);
|
|
33
|
+
|
|
34
|
+
process.on('unhandledRejection', up => {
|
|
35
|
+
logger.error('Unhandled promise rejection at:');
|
|
36
|
+
logger.fatal(up);
|
|
37
|
+
});
|
|
38
|
+
})();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { asCommand } from 'generator-jhipster';
|
|
2
|
+
|
|
3
|
+
export default asCommand({
|
|
4
|
+
configs: {
|
|
5
|
+
contextPath: {
|
|
6
|
+
description: 'Context path to set as baseHref in angular.json (e.g. /jh/)',
|
|
7
|
+
cli: {
|
|
8
|
+
type: String,
|
|
9
|
+
},
|
|
10
|
+
scope: 'blueprint',
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
});
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import BaseApplicationGenerator from 'generator-jhipster/generators/base-application';
|
|
2
|
+
|
|
3
|
+
export default class extends BaseApplicationGenerator {
|
|
4
|
+
constructor(args, opts, features) {
|
|
5
|
+
super(args, opts, {
|
|
6
|
+
...features,
|
|
7
|
+
|
|
8
|
+
sbsBlueprint: true,
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
get [BaseApplicationGenerator.INITIALIZING]() {
|
|
13
|
+
return this.asInitializingTaskGroup({
|
|
14
|
+
async initializingTemplateTask() {},
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
get [BaseApplicationGenerator.PROMPTING]() {
|
|
19
|
+
return this.asPromptingTaskGroup({
|
|
20
|
+
async promptingTemplateTask() {},
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get [BaseApplicationGenerator.CONFIGURING]() {
|
|
25
|
+
return this.asConfiguringTaskGroup({
|
|
26
|
+
async configuringTemplateTask() {},
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get [BaseApplicationGenerator.COMPOSING]() {
|
|
31
|
+
return this.asComposingTaskGroup({
|
|
32
|
+
async composingTemplateTask() {},
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
get [BaseApplicationGenerator.COMPOSING_COMPONENT]() {
|
|
37
|
+
return this.asComposingComponentTaskGroup({
|
|
38
|
+
async composingComponentTemplateTask() {},
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get [BaseApplicationGenerator.LOADING]() {
|
|
43
|
+
return this.asLoadingTaskGroup({
|
|
44
|
+
async loadingTemplateTask() {},
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
get [BaseApplicationGenerator.PREPARING]() {
|
|
49
|
+
return this.asPreparingTaskGroup({
|
|
50
|
+
async preparingTemplateTask() {},
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
get [BaseApplicationGenerator.POST_PREPARING]() {
|
|
55
|
+
return this.asPostPreparingTaskGroup({
|
|
56
|
+
async postPreparingTemplateTask() {},
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
get [BaseApplicationGenerator.DEFAULT]() {
|
|
61
|
+
return this.asDefaultTaskGroup({
|
|
62
|
+
async defaultTemplateTask() {},
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
get [BaseApplicationGenerator.WRITING]() {
|
|
67
|
+
return this.asWritingTaskGroup({
|
|
68
|
+
async writingTemplateTask({ application }) {
|
|
69
|
+
await this.writeFiles({
|
|
70
|
+
sections: {
|
|
71
|
+
files: [{ templates: ['template-file-angular'] }],
|
|
72
|
+
},
|
|
73
|
+
context: application,
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
get [BaseApplicationGenerator.MULTISTEP_TRANSFORM]() {
|
|
80
|
+
return this.asMultistepTransformTaskGroup({
|
|
81
|
+
async multistepTransformTemplateTask() {},
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
get [BaseApplicationGenerator.POST_WRITING]() {
|
|
86
|
+
return this.asPostWritingTaskGroup({
|
|
87
|
+
async addBaseHref() {
|
|
88
|
+
const contextPath = this.blueprintConfig.contextPath;
|
|
89
|
+
if (!contextPath) {
|
|
90
|
+
this.log.warn(
|
|
91
|
+
'[base-href blueprint] contextPath not configured — pass --yellowbricks-angular-contextpath-config=\'{"contextPath":"/jh/"}\' when running jhipster',
|
|
92
|
+
);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
this.editFile('angular.json', { ignoreNonExisting: true }, content => {
|
|
97
|
+
const json = JSON.parse(content);
|
|
98
|
+
const projectName = Object.keys(json.projects ?? {})[0];
|
|
99
|
+
const build = json.projects?.[projectName]?.architect?.build;
|
|
100
|
+
|
|
101
|
+
// --- drift detection: verify expected surrounding structure ---
|
|
102
|
+
const expectedBuilder = '@angular-builders/custom-esbuild:application';
|
|
103
|
+
|
|
104
|
+
if (!build) {
|
|
105
|
+
this.log.warn('[base-href blueprint] angular.json: architect.build section not found — manual intervention needed');
|
|
106
|
+
return content;
|
|
107
|
+
}
|
|
108
|
+
if (build.builder !== expectedBuilder) {
|
|
109
|
+
this.log.warn(
|
|
110
|
+
`[base-href blueprint] angular.json: expected builder "${expectedBuilder}" but found "${build.builder ?? 'undefined'}" — manual intervention needed`,
|
|
111
|
+
);
|
|
112
|
+
return content;
|
|
113
|
+
}
|
|
114
|
+
if (!build.options) {
|
|
115
|
+
this.log.warn('[base-href blueprint] angular.json: architect.build.options not found — manual intervention needed');
|
|
116
|
+
return content;
|
|
117
|
+
}
|
|
118
|
+
if (!Array.isArray(build.options.plugins)) {
|
|
119
|
+
this.log.warn('[base-href blueprint] angular.json: build.options.plugins array not found — manual intervention needed');
|
|
120
|
+
return content;
|
|
121
|
+
}
|
|
122
|
+
if (!build.options.outputPath) {
|
|
123
|
+
this.log.warn('[base-href blueprint] angular.json: build.options.outputPath not found — manual intervention needed');
|
|
124
|
+
return content;
|
|
125
|
+
}
|
|
126
|
+
// --- end drift detection ---
|
|
127
|
+
|
|
128
|
+
const previousBaseHref = build.options.baseHref;
|
|
129
|
+
|
|
130
|
+
// Remove existing baseHref (if any) then insert as the first key in options
|
|
131
|
+
const { baseHref: _removed, ...remainingOptions } = build.options;
|
|
132
|
+
build.options = { baseHref: contextPath, ...remainingOptions };
|
|
133
|
+
|
|
134
|
+
if (previousBaseHref && previousBaseHref !== contextPath) {
|
|
135
|
+
this.log.info(`[base-href blueprint] angular.json: baseHref renamed from "${previousBaseHref}" to "${contextPath}"`);
|
|
136
|
+
} else {
|
|
137
|
+
this.log.info(`[base-href blueprint] angular.json: baseHref "${contextPath}" added successfully`);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return `${JSON.stringify(json, null, 2)}\n`;
|
|
141
|
+
});
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
get [BaseApplicationGenerator.TRANSFORM]() {
|
|
147
|
+
return this.asTransformTaskGroup({
|
|
148
|
+
async transformTemplateTask() {},
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
get [BaseApplicationGenerator.INSTALL]() {
|
|
153
|
+
return this.asInstallTaskGroup({
|
|
154
|
+
async installTemplateTask() {},
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
get [BaseApplicationGenerator.POST_INSTALL]() {
|
|
159
|
+
return this.asPostInstallTaskGroup({
|
|
160
|
+
async postInstallTemplateTask() {},
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
get [BaseApplicationGenerator.END]() {
|
|
165
|
+
return this.asEndTaskGroup({
|
|
166
|
+
async endTemplateTask() {},
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
File without changes
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "generator-jhipster-yellowbricks-angular-contextpath",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "JHipster blueprint to configure Angular application baseHref via a custom context path",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"yeoman-generator",
|
|
7
|
+
"jhipster-blueprint",
|
|
8
|
+
"jhipster-9",
|
|
9
|
+
"generator-jhipster-yellowbricks"
|
|
10
|
+
],
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/idNoRD/generator-jhipster-yellowbricks-angular-contextpath.git"
|
|
14
|
+
},
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"author": "idNoRD",
|
|
17
|
+
"bin": {
|
|
18
|
+
"jhipster-yellowbricks-angular-contextpath": "cli/cli.cjs"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"cli",
|
|
22
|
+
"generators",
|
|
23
|
+
"!**/__*",
|
|
24
|
+
"!**/*.snap",
|
|
25
|
+
"!**/*.spec.?(c|m)js"
|
|
26
|
+
],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"ejslint": "ejslint generators/**/*.ejs",
|
|
29
|
+
"lint": "eslint .",
|
|
30
|
+
"lint-fix": "npm run ejslint && npm run lint -- --fix",
|
|
31
|
+
"prepare": "husky",
|
|
32
|
+
"prettier-check": "prettier --check \"{,**/}*.{md,json,yml,html,cjs,mjs,js,cts,mts,ts,tsx,css,scss,vue,java}\"",
|
|
33
|
+
"prettier-format": "prettier --write \"{,**/}*.{md,json,yml,html,cjs,mjs,js,cts,mts,ts,tsx,css,scss,vue,java}\"",
|
|
34
|
+
"pretest": "npm run prettier-check && npm run lint",
|
|
35
|
+
"test": "vitest run",
|
|
36
|
+
"update-snapshot": "vitest run --update",
|
|
37
|
+
"vitest": "vitest"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"generator-jhipster": "9.0.0-beta.3"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"ejs-lint": "2.0.1",
|
|
44
|
+
"eslint": "9.39.2",
|
|
45
|
+
"eslint-config-prettier": "10.1.8",
|
|
46
|
+
"eslint-plugin-prettier": "5.5.5",
|
|
47
|
+
"globals": "17.3.0",
|
|
48
|
+
"husky": "9.1.7",
|
|
49
|
+
"jiti": "2.6.1",
|
|
50
|
+
"lint-staged": "16.2.7",
|
|
51
|
+
"prettier": "3.8.1",
|
|
52
|
+
"prettier-plugin-packagejson": "3.0.0",
|
|
53
|
+
"vitest": "4.0.18",
|
|
54
|
+
"yeoman-test": ">=10"
|
|
55
|
+
},
|
|
56
|
+
"engines": {
|
|
57
|
+
"generator-jhipster": "9.0.0-beta.3",
|
|
58
|
+
"node": "^22.18.0 || >=24.11.0"
|
|
59
|
+
}
|
|
60
|
+
}
|