Skip to content

Commit 1dfd7ab

Browse files
authored
Merge pull request #473 from hypery2k/issue-120
Fixed ngPackagr and Angular 8 support
2 parents 360ab71 + 21c9ec4 commit 1dfd7ab

File tree

5 files changed

+41
-22
lines changed

5 files changed

+41
-22
lines changed

src/main/java/io/swagger/codegen/v3/generators/typescript/TypeScriptAngularClientCodegen.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
3939
public static final String SNAPSHOT = "snapshot";
4040
public static final String WITH_INTERFACES = "withInterfaces";
4141
public static final String NG_VERSION = "ngVersion";
42+
public static final String NG_PACKAGR = "useNgPackagr";
4243

4344
protected String npmName = null;
4445
protected String npmVersion = "1.0.0";
@@ -102,19 +103,9 @@ public void processOpts() {
102103
supportingFiles.add(new SupportingFile("variables.mustache", getIndexDirectory(), "variables.ts"));
103104
supportingFiles.add(new SupportingFile("encoder.mustache", getIndexDirectory(), "encoder.ts"));
104105
supportingFiles.add(new SupportingFile("gitignore", "", ".gitignore"));
106+
supportingFiles.add(new SupportingFile("npmignore", "", ".npmignore"));
105107
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
106108

107-
if (additionalProperties.containsKey(NPM_NAME)) {
108-
addNpmPackageGeneration();
109-
}
110-
111-
if (additionalProperties.containsKey(WITH_INTERFACES)) {
112-
boolean withInterfaces = Boolean.parseBoolean(additionalProperties.get(WITH_INTERFACES).toString());
113-
if (withInterfaces) {
114-
apiTemplateFiles.put("apiInterface.mustache", "Interface.ts");
115-
}
116-
}
117-
118109
// determine NG version
119110
SemVer ngVersion;
120111
if (additionalProperties.containsKey(NG_VERSION)) {
@@ -125,13 +116,27 @@ public void processOpts() {
125116
LOGGER.info(" (you can select the angular version by setting the additionalProperty ngVersion)");
126117
}
127118
additionalProperties.put(NG_VERSION, ngVersion);
119+
additionalProperties.put(NG_PACKAGR, ngVersion.atLeast("8.0.0"));
128120
additionalProperties.put("useRxJS6", ngVersion.atLeast("6.0.0"));
129121
additionalProperties.put("injectionToken", ngVersion.atLeast("4.0.0") ? "InjectionToken" : "OpaqueToken");
130122
additionalProperties.put("injectionTokenTyped", ngVersion.atLeast("4.0.0"));
131123
additionalProperties.put("useHttpClient", ngVersion.atLeast("4.3.0"));
124+
additionalProperties.put("useHttpClientPackage", ngVersion.atLeast("4.3.0") && !ngVersion.atLeast("8.0.0"));
132125
if (!ngVersion.atLeast("4.3.0")) {
133126
supportingFiles.add(new SupportingFile("rxjs-operators.mustache", getIndexDirectory(), "rxjs-operators.ts"));
134127
}
128+
129+
if (additionalProperties.containsKey(NPM_NAME)) {
130+
addNpmPackageGeneration();
131+
}
132+
133+
if (additionalProperties.containsKey(WITH_INTERFACES)) {
134+
boolean withInterfaces = Boolean.parseBoolean(additionalProperties.get(WITH_INTERFACES).toString());
135+
if (withInterfaces) {
136+
apiTemplateFiles.put("apiInterface.mustache", "Interface.ts");
137+
}
138+
}
139+
135140
}
136141

137142
private void addNpmPackageGeneration() {
@@ -158,6 +163,10 @@ private void addNpmPackageGeneration() {
158163
supportingFiles.add(new SupportingFile("package.mustache", getIndexDirectory(), "package.json"));
159164
supportingFiles.add(new SupportingFile("typings.mustache", getIndexDirectory(), "typings.json"));
160165
supportingFiles.add(new SupportingFile("tsconfig.mustache", getIndexDirectory(), "tsconfig.json"));
166+
if (additionalProperties.containsKey(NG_PACKAGR)
167+
&& Boolean.valueOf(additionalProperties.get(NG_PACKAGR).toString())) {
168+
supportingFiles.add(new SupportingFile("ng-package.mustache", getIndexDirectory(), "ng-package.json"));
169+
}
161170
}
162171

163172
private String getIndexDirectory() {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
wwwroot/*.js
2+
node
3+
node_modules
4+
typings
5+
dist

src/main/resources/handlebars/typescript-angular/package.mustache

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
},
2323
{{/useNgPackagr}}
2424
"peerDependencies": {
25-
"@angular/core": "^{{ngVersion}}",
26-
"@angular/http": "^{{ngVersion}}",
25+
"@angular/core": "^{{ngVersion}}",{{#useHttpClientPackage}}
26+
"@angular/http": "^{{ngVersion}}",{{/useHttpClientPackage}}
2727
"@angular/common": "^{{ngVersion}}",
2828
"@angular/compiler": "^{{ngVersion}}",
2929
"core-js": "^2.4.0",
@@ -34,16 +34,16 @@
3434
},
3535
"devDependencies": {
3636
"@angular/compiler-cli": "^{{ngVersion}}",
37-
"@angular/core": "^{{ngVersion}}",
38-
"@angular/http": "^{{ngVersion}}",
37+
"@angular/core": "^{{ngVersion}}",{{#useHttpClientPackage}}
38+
"@angular/http": "^{{ngVersion}}",{{/useHttpClientPackage}}
3939
"@angular/common": "^{{ngVersion}}",
4040
"@angular/compiler": "^{{ngVersion}}",
4141
"@angular/platform-browser": "^{{ngVersion}}",{{#useNgPackagr}}
42-
"ng-packagr": {{#useOldNgPackagr}}"^1.6.0"{{/useOldNgPackagr}}{{^useOldNgPackagr}}{{#useRxJS6}}"5.3.0"{{/useRxJS6}}{{^useRxJS6}}"^2.4.1"{{/useRxJS6}}{{/useOldNgPackagr}},{{/useNgPackagr}}
42+
"ng-packagr": {{#useOldNgPackagr}}"^1.6.0"{{/useOldNgPackagr}}{{^useOldNgPackagr}}{{#useRxJS6}}"5.5.1"{{/useRxJS6}}{{^useRxJS6}}"^2.4.1"{{/useRxJS6}}{{/useOldNgPackagr}},{{/useNgPackagr}}
4343
"reflect-metadata": "^0.1.3",
4444
"rxjs": "{{#useRxJS6}}~6.3.3{{/useRxJS6}}{{^useRxJS6}}^5.4.0{{/useRxJS6}}",
4545
"zone.js": "^0.7.6",
46-
"typescript": "^2.1.5"
46+
"typescript": "{{#useNgPackagr}}~3.4.5{{/useNgPackagr}}{{^useNgPackagr}}^2.1.5{{/useNgPackagr}}"
4747
}{{#npmRepository}},{{/npmRepository}}
4848
{{#npmRepository}}
4949
"publishConfig": {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
wwwroot/*.js
2+
node
3+
node_modules
4+
typings
5+
dist

src/main/resources/mustache/typescript-angular/package.mustache

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
},
2323
{{/useNgPackagr}}
2424
"peerDependencies": {
25-
"@angular/core": "^{{ngVersion}}",
26-
"@angular/http": "^{{ngVersion}}",
25+
"@angular/core": "^{{ngVersion}}",{{^useHttpClientPackage}}
26+
"@angular/http": "^{{ngVersion}}",{{/useHttpClientPackage}}
2727
"@angular/common": "^{{ngVersion}}",
2828
"@angular/compiler": "^{{ngVersion}}",
2929
"core-js": "^2.4.0",
@@ -33,16 +33,16 @@
3333
},
3434
"devDependencies": {
3535
"@angular/compiler-cli": "^{{ngVersion}}",
36-
"@angular/core": "^{{ngVersion}}",
37-
"@angular/http": "^{{ngVersion}}",
36+
"@angular/core": "^{{ngVersion}}",{{^useHttpClientPackage}}
37+
"@angular/http": "^{{ngVersion}}",{{/useHttpClientPackage}}
3838
"@angular/common": "^{{ngVersion}}",
3939
"@angular/compiler": "^{{ngVersion}}",
4040
"@angular/platform-browser": "^{{ngVersion}}",{{#useNgPackagr}}
4141
"ng-packagr": {{#useOldNgPackagr}}"^1.6.0"{{/useOldNgPackagr}}{{^useOldNgPackagr}}{{#useRxJS6}}"5.3.0"{{/useRxJS6}}{{^useRxJS6}}"^2.4.1"{{/useRxJS6}}{{/useOldNgPackagr}},{{/useNgPackagr}}
4242
"reflect-metadata": "^0.1.3",
4343
"rxjs": "{{#useRxJS6}}~6.3.3{{/useRxJS6}}{{^useRxJS6}}^5.4.0{{/useRxJS6}}",
4444
"zone.js": "^0.7.6",
45-
"typescript": ">=2.1.5 <2.8"
45+
"typescript": "{{#useNgPackagr}}~3.4.5{{/useNgPackagr}}{{^useNgPackagr}}^>=2.1.5 <2.8{{/useNgPackagr}}"
4646
}{{#npmRepository}},{{/npmRepository}}
4747
{{#npmRepository}}
4848
"publishConfig": {

0 commit comments

Comments
 (0)