diff --git a/src/main/java/io/swagger/codegen/v3/generators/typescript/TypeScriptAngularClientCodegen.java b/src/main/java/io/swagger/codegen/v3/generators/typescript/TypeScriptAngularClientCodegen.java index fbbe1a5787..6d2794e5c5 100644 --- a/src/main/java/io/swagger/codegen/v3/generators/typescript/TypeScriptAngularClientCodegen.java +++ b/src/main/java/io/swagger/codegen/v3/generators/typescript/TypeScriptAngularClientCodegen.java @@ -39,6 +39,7 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode public static final String SNAPSHOT = "snapshot"; public static final String WITH_INTERFACES = "withInterfaces"; public static final String NG_VERSION = "ngVersion"; + public static final String NG_PACKAGR = "useNgPackagr"; protected String npmName = null; protected String npmVersion = "1.0.0"; @@ -102,19 +103,9 @@ public void processOpts() { supportingFiles.add(new SupportingFile("variables.mustache", getIndexDirectory(), "variables.ts")); supportingFiles.add(new SupportingFile("encoder.mustache", getIndexDirectory(), "encoder.ts")); supportingFiles.add(new SupportingFile("gitignore", "", ".gitignore")); + supportingFiles.add(new SupportingFile("npmignore", "", ".npmignore")); supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh")); - if (additionalProperties.containsKey(NPM_NAME)) { - addNpmPackageGeneration(); - } - - if (additionalProperties.containsKey(WITH_INTERFACES)) { - boolean withInterfaces = Boolean.parseBoolean(additionalProperties.get(WITH_INTERFACES).toString()); - if (withInterfaces) { - apiTemplateFiles.put("apiInterface.mustache", "Interface.ts"); - } - } - // determine NG version SemVer ngVersion; if (additionalProperties.containsKey(NG_VERSION)) { @@ -125,13 +116,27 @@ public void processOpts() { LOGGER.info(" (you can select the angular version by setting the additionalProperty ngVersion)"); } additionalProperties.put(NG_VERSION, ngVersion); + additionalProperties.put(NG_PACKAGR, ngVersion.atLeast("8.0.0")); additionalProperties.put("useRxJS6", ngVersion.atLeast("6.0.0")); additionalProperties.put("injectionToken", ngVersion.atLeast("4.0.0") ? "InjectionToken" : "OpaqueToken"); additionalProperties.put("injectionTokenTyped", ngVersion.atLeast("4.0.0")); additionalProperties.put("useHttpClient", ngVersion.atLeast("4.3.0")); + additionalProperties.put("useHttpClientPackage", ngVersion.atLeast("4.3.0") && !ngVersion.atLeast("8.0.0")); if (!ngVersion.atLeast("4.3.0")) { supportingFiles.add(new SupportingFile("rxjs-operators.mustache", getIndexDirectory(), "rxjs-operators.ts")); } + + if (additionalProperties.containsKey(NPM_NAME)) { + addNpmPackageGeneration(); + } + + if (additionalProperties.containsKey(WITH_INTERFACES)) { + boolean withInterfaces = Boolean.parseBoolean(additionalProperties.get(WITH_INTERFACES).toString()); + if (withInterfaces) { + apiTemplateFiles.put("apiInterface.mustache", "Interface.ts"); + } + } + } private void addNpmPackageGeneration() { @@ -158,6 +163,10 @@ private void addNpmPackageGeneration() { supportingFiles.add(new SupportingFile("package.mustache", getIndexDirectory(), "package.json")); supportingFiles.add(new SupportingFile("typings.mustache", getIndexDirectory(), "typings.json")); supportingFiles.add(new SupportingFile("tsconfig.mustache", getIndexDirectory(), "tsconfig.json")); + if (additionalProperties.containsKey(NG_PACKAGR) + && Boolean.valueOf(additionalProperties.get(NG_PACKAGR).toString())) { + supportingFiles.add(new SupportingFile("ng-package.mustache", getIndexDirectory(), "ng-package.json")); + } } private String getIndexDirectory() { diff --git a/src/main/resources/handlebars/typescript-angular/npmignore b/src/main/resources/handlebars/typescript-angular/npmignore new file mode 100644 index 0000000000..7e981c47c9 --- /dev/null +++ b/src/main/resources/handlebars/typescript-angular/npmignore @@ -0,0 +1,5 @@ +wwwroot/*.js +node +node_modules +typings +dist diff --git a/src/main/resources/handlebars/typescript-angular/package.mustache b/src/main/resources/handlebars/typescript-angular/package.mustache index 7536244d51..fcbfff0010 100644 --- a/src/main/resources/handlebars/typescript-angular/package.mustache +++ b/src/main/resources/handlebars/typescript-angular/package.mustache @@ -22,8 +22,8 @@ }, {{/useNgPackagr}} "peerDependencies": { - "@angular/core": "^{{ngVersion}}", - "@angular/http": "^{{ngVersion}}", + "@angular/core": "^{{ngVersion}}",{{#useHttpClientPackage}} + "@angular/http": "^{{ngVersion}}",{{/useHttpClientPackage}} "@angular/common": "^{{ngVersion}}", "@angular/compiler": "^{{ngVersion}}", "core-js": "^2.4.0", @@ -34,16 +34,16 @@ }, "devDependencies": { "@angular/compiler-cli": "^{{ngVersion}}", - "@angular/core": "^{{ngVersion}}", - "@angular/http": "^{{ngVersion}}", + "@angular/core": "^{{ngVersion}}",{{#useHttpClientPackage}} + "@angular/http": "^{{ngVersion}}",{{/useHttpClientPackage}} "@angular/common": "^{{ngVersion}}", "@angular/compiler": "^{{ngVersion}}", "@angular/platform-browser": "^{{ngVersion}}",{{#useNgPackagr}} - "ng-packagr": {{#useOldNgPackagr}}"^1.6.0"{{/useOldNgPackagr}}{{^useOldNgPackagr}}{{#useRxJS6}}"5.3.0"{{/useRxJS6}}{{^useRxJS6}}"^2.4.1"{{/useRxJS6}}{{/useOldNgPackagr}},{{/useNgPackagr}} + "ng-packagr": {{#useOldNgPackagr}}"^1.6.0"{{/useOldNgPackagr}}{{^useOldNgPackagr}}{{#useRxJS6}}"5.5.1"{{/useRxJS6}}{{^useRxJS6}}"^2.4.1"{{/useRxJS6}}{{/useOldNgPackagr}},{{/useNgPackagr}} "reflect-metadata": "^0.1.3", "rxjs": "{{#useRxJS6}}~6.3.3{{/useRxJS6}}{{^useRxJS6}}^5.4.0{{/useRxJS6}}", "zone.js": "^0.7.6", - "typescript": "^2.1.5" + "typescript": "{{#useNgPackagr}}~3.4.5{{/useNgPackagr}}{{^useNgPackagr}}^2.1.5{{/useNgPackagr}}" }{{#npmRepository}},{{/npmRepository}} {{#npmRepository}} "publishConfig": { diff --git a/src/main/resources/mustache/typescript-angular/npmignore b/src/main/resources/mustache/typescript-angular/npmignore new file mode 100644 index 0000000000..7e981c47c9 --- /dev/null +++ b/src/main/resources/mustache/typescript-angular/npmignore @@ -0,0 +1,5 @@ +wwwroot/*.js +node +node_modules +typings +dist diff --git a/src/main/resources/mustache/typescript-angular/package.mustache b/src/main/resources/mustache/typescript-angular/package.mustache index 1aabb2cf1a..2cce79bca3 100644 --- a/src/main/resources/mustache/typescript-angular/package.mustache +++ b/src/main/resources/mustache/typescript-angular/package.mustache @@ -22,8 +22,8 @@ }, {{/useNgPackagr}} "peerDependencies": { - "@angular/core": "^{{ngVersion}}", - "@angular/http": "^{{ngVersion}}", + "@angular/core": "^{{ngVersion}}",{{^useHttpClientPackage}} + "@angular/http": "^{{ngVersion}}",{{/useHttpClientPackage}} "@angular/common": "^{{ngVersion}}", "@angular/compiler": "^{{ngVersion}}", "core-js": "^2.4.0", @@ -33,8 +33,8 @@ }, "devDependencies": { "@angular/compiler-cli": "^{{ngVersion}}", - "@angular/core": "^{{ngVersion}}", - "@angular/http": "^{{ngVersion}}", + "@angular/core": "^{{ngVersion}}",{{^useHttpClientPackage}} + "@angular/http": "^{{ngVersion}}",{{/useHttpClientPackage}} "@angular/common": "^{{ngVersion}}", "@angular/compiler": "^{{ngVersion}}", "@angular/platform-browser": "^{{ngVersion}}",{{#useNgPackagr}} @@ -42,7 +42,7 @@ "reflect-metadata": "^0.1.3", "rxjs": "{{#useRxJS6}}~6.3.3{{/useRxJS6}}{{^useRxJS6}}^5.4.0{{/useRxJS6}}", "zone.js": "^0.7.6", - "typescript": ">=2.1.5 <2.8" + "typescript": "{{#useNgPackagr}}~3.4.5{{/useNgPackagr}}{{^useNgPackagr}}^>=2.1.5 <2.8{{/useNgPackagr}}" }{{#npmRepository}},{{/npmRepository}} {{#npmRepository}} "publishConfig": {