Skip to content

Commit 0c1df6a

Browse files
committed
Make ngPackagr correctly configured in API module
1 parent ec46486 commit 0c1df6a

File tree

5 files changed

+32
-15
lines changed

5 files changed

+32
-15
lines changed

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

Lines changed: 19 additions & 12 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,7 +116,7 @@ public void processOpts() {
125116
LOGGER.info(" (you can select the angular version by setting the additionalProperty ngVersion)");
126117
}
127118
additionalProperties.put(NG_VERSION, ngVersion);
128-
additionalProperties.put("useNgPackagr", ngVersion.atLeast("8.0.0"));
119+
additionalProperties.put(NG_PACKAGR, ngVersion.atLeast("8.0.0"));
129120
additionalProperties.put("useRxJS6", ngVersion.atLeast("6.0.0"));
130121
additionalProperties.put("injectionToken", ngVersion.atLeast("4.0.0") ? "InjectionToken" : "OpaqueToken");
131122
additionalProperties.put("injectionTokenTyped", ngVersion.atLeast("4.0.0"));
@@ -134,6 +125,18 @@ public void processOpts() {
134125
if (!ngVersion.atLeast("4.3.0")) {
135126
supportingFiles.add(new SupportingFile("rxjs-operators.mustache", getIndexDirectory(), "rxjs-operators.ts"));
136127
}
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+
137140
}
138141

139142
private void addNpmPackageGeneration() {
@@ -160,6 +163,10 @@ private void addNpmPackageGeneration() {
160163
supportingFiles.add(new SupportingFile("package.mustache", getIndexDirectory(), "package.json"));
161164
supportingFiles.add(new SupportingFile("typings.mustache", getIndexDirectory(), "typings.json"));
162165
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+
}
163170
}
164171

165172
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
},
3535
"devDependencies": {
3636
"@angular/compiler-cli": "^{{ngVersion}}",
37-
"@angular/core": "^{{ngVersion}}",,{{#useHttpClientPackage}}
37+
"@angular/core": "^{{ngVersion}}",{{#useHttpClientPackage}}
3838
"@angular/http": "^{{ngVersion}}",{{/useHttpClientPackage}}
3939
"@angular/common": "^{{ngVersion}}",
4040
"@angular/compiler": "^{{ngVersion}}",
@@ -43,7 +43,7 @@
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
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)