add ngVersion option

This commit is contained in:
wing328
2017-07-04 01:00:35 +08:00
parent 15382f5b77
commit 45eb5fffc0
44 changed files with 2252 additions and 137 deletions

View File

@@ -33,12 +33,14 @@ public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCod
public static final String INJECTION_TOKEN = "injectionToken";
public static final String INJECTION_TOKEN_IMPORT = "injectionTokenImport";
public static final String WITH_INTERFACES = "withInterfaces";
public static final String NG_VERSION = "ngVersion";
protected String npmName = null;
protected String npmVersion = "1.0.0";
protected String npmRepository = null;
protected String injectionToken = "InjectionToken<string>";
protected String injectionTokenImport = "InjectionToken";
protected String ngVersion = "4";
public TypeScriptAngular2ClientCodegen() {
super();
@@ -59,6 +61,7 @@ public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCod
this.cliOptions.add(new CliOption(SNAPSHOT, "When setting this property to true the version will be suffixed with -SNAPSHOT.yyyyMMddHHmm", BooleanProperty.TYPE).defaultValue(Boolean.FALSE.toString()));
this.cliOptions.add(new CliOption(USE_OPAQUE_TOKEN, "When setting this property to true, OpaqueToken is used instead of InjectionToken", BooleanProperty.TYPE).defaultValue(Boolean.FALSE.toString()));
this.cliOptions.add(new CliOption(WITH_INTERFACES, "Setting this property to true will generate interfaces next to the default class implementations.", BooleanProperty.TYPE).defaultValue(Boolean.FALSE.toString()));
this.cliOptions.add(new CliOption(NG_VERSION, "The version of Angular (2 or 4). Default is '4'"));
}
@Override
@@ -74,7 +77,7 @@ public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCod
@Override
public String getHelp() {
return "Generates a TypeScript Angular2 client library.";
return "Generates a TypeScript Angular (2.x or 4.x) client library.";
}
@Override
@@ -106,6 +109,23 @@ public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCod
apiTemplateFiles.put("apiInterface.mustache", "Interface.ts");
}
}
// determine NG version
if (additionalProperties.containsKey(NG_VERSION)) {
if ("2".equals(additionalProperties.get(NG_VERSION).toString())) {
additionalProperties.put("isNg2x", true);
setNgVersion("2");
} else if ("4".equals(additionalProperties.get(NG_VERSION).toString())) {
additionalProperties.put("isNg4x", true);
setNgVersion("4");
} else {
throw new IllegalArgumentException("Invalid ngVersion, which must be either '2' or '4'");
}
} else {
// default to 4
additionalProperties.put("isNg4x", true);
setNgVersion("4");
}
}
private void addNpmPackageGeneration() {
@@ -307,6 +327,14 @@ public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCod
return modelPackage() + "/" + toModelFilename(name);
}
public String getNgVersion() {
return ngVersion;
}
public void setNgVersion(String ngVersion) {
this.ngVersion = ngVersion;
}
public String getNpmName() {
return npmName;
}

View File

@@ -14,21 +14,21 @@
"postinstall": "npm run build"
},
"peerDependencies": {
"@angular/core": "^2.2.2",
"@angular/http": "^2.2.2",
"@angular/common": "^2.2.2",
"@angular/compiler": "^2.2.2",
"@angular/core": "{{#isNg2x}}^2.2.2{{/isNg2x}}{{#isNg4x}}^4.2.5{{/isNg4x}}",
"@angular/http": "{{#isNg2x}}^2.2.2{{/isNg2x}}{{#isNg4x}}^4.2.5{{/isNg4x}}",
"@angular/common": "{{#isNg2x}}^2.2.2{{/isNg2x}}{{#isNg4x}}^4.2.5{{/isNg4x}}",
"@angular/compiler": "{{#isNg2x}}^2.2.2{{/isNg2x}}{{#isNg4x}}^4.2.5{{/isNg4x}}",
"core-js": "^2.4.0",
"reflect-metadata": "^0.1.3",
"rxjs": "^5.1.0",
"zone.js": "^0.7.6"
},
"devDependencies": {
"@angular/core": "^2.2.2",
"@angular/http": "^2.2.2",
"@angular/common": "^2.2.2",
"@angular/compiler": "^2.2.2",
"@angular/platform-browser": "^2.2.2",
"@angular/core": "{{#isNg2x}}^2.2.2{{/isNg2x}}{{#isNg4x}}^4.2.5{{/isNg4x}}",
"@angular/http": "{{#isNg2x}}^2.2.2{{/isNg2x}}{{#isNg4x}}^4.2.5{{/isNg4x}}",
"@angular/common": "{{#isNg2x}}^2.2.2{{/isNg2x}}{{#isNg4x}}^4.2.5{{/isNg4x}}",
"@angular/compiler": "{{#isNg2x}}^2.2.2{{/isNg2x}}{{#isNg4x}}^4.2.5{{/isNg4x}}",
"@angular/platform-browser": "{{#isNg2x}}^2.2.2{{/isNg2x}}{{#isNg4x}}^4.2.5{{/isNg4x}}",
"reflect-metadata": "^0.1.3",
"rxjs": "5.1.0",
"zone.js": "^0.7.6",