Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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)) {
Expand All @@ -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() {
Expand All @@ -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() {
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/handlebars/typescript-angular/npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
wwwroot/*.js
node
node_modules
typings
dist
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": {
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/mustache/typescript-angular/npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
wwwroot/*.js
node
node_modules
typings
dist
10 changes: 5 additions & 5 deletions src/main/resources/mustache/typescript-angular/package.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -33,16 +33,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}}
"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": {
Expand Down