Add pubspec.yaml
This commit is contained in:
@ -17,13 +17,17 @@ function toDartType(type: string): string {
|
||||
return (conversion as any)[type] || type;
|
||||
}
|
||||
|
||||
export class DartTarget extends CompileTarget<{}> {
|
||||
export class DartTarget extends CompileTarget<{ dart_library_name: string }> {
|
||||
name: string = "dart";
|
||||
|
||||
start(): void {
|
||||
if (this.options.allow_bytes == true) {
|
||||
throw new Error("Dart has no support for 'bytes' yet!");
|
||||
}
|
||||
|
||||
if (!this.options.dart_library_name) {
|
||||
throw new Error("Setting dart_library_name is required for DART target!");
|
||||
}
|
||||
}
|
||||
|
||||
getImport(name: string) {
|
||||
@ -55,13 +59,13 @@ export class DartTarget extends CompileTarget<{}> {
|
||||
}
|
||||
|
||||
a(0, ``);
|
||||
a(1, `${definition.name}(${definition.fields.map(e => `this.${e.name}`).join(",")});`);
|
||||
a(1, `${definition.name}({${definition.fields.map(e => `this.${e.name}`).join(",")}});`);
|
||||
a(0, ``);
|
||||
a(1, `${definition.name}.fromJson(Map<String, dynamic> json) {`);
|
||||
for (const field of definition.fields) {
|
||||
a(2, `if(json.containsKey("${field.name}")) {`);
|
||||
|
||||
const parseField = (value: string)=>{
|
||||
|
||||
const parseField = (value: string) => {
|
||||
if (conversion[field.type]) {
|
||||
return value;
|
||||
} else {
|
||||
@ -69,12 +73,12 @@ export class DartTarget extends CompileTarget<{}> {
|
||||
}
|
||||
}
|
||||
|
||||
if(field.array) {
|
||||
if (field.array) {
|
||||
a(3, `this.${field.name} = [];`);
|
||||
a(3, `(json["${field.name}"] as List<dynamic>).forEach((e) => {`)
|
||||
a(4, `this.${field.name}!.add(${parseField("e")})`);
|
||||
a(3, `});`)
|
||||
} else if(field.map) {
|
||||
} else if (field.map) {
|
||||
a(3, `this.${field.name} = {};`);
|
||||
a(3, `(json["${field.name}"] as Map<${toDartType(field.map)},dynamic>).forEach((key, value) => {`)
|
||||
a(4, `this.${field.name}![key] = ${parseField("value")}`);
|
||||
@ -91,7 +95,7 @@ export class DartTarget extends CompileTarget<{}> {
|
||||
a(1, `}`);
|
||||
a(0, `}`);
|
||||
|
||||
this.writeFile(`${definition.name}.dart`, getResult());
|
||||
this.writeFile(`lib/src/${definition.name}.dart`, getResult());
|
||||
}
|
||||
|
||||
generateEnum(definition: EnumDefinition): void {
|
||||
@ -114,6 +118,7 @@ export class DartTarget extends CompileTarget<{}> {
|
||||
}
|
||||
a(3, `default:`);
|
||||
a(4, `return null;`);
|
||||
a(2, `}`);
|
||||
a(1, `}`);
|
||||
a(0, `}`);
|
||||
|
||||
@ -132,7 +137,7 @@ export class DartTarget extends CompileTarget<{}> {
|
||||
// a(1, `}`);
|
||||
// a(0, `}`);
|
||||
|
||||
this.writeFile(`${definition.name}.dart`, getResult());
|
||||
this.writeFile(`lib/src/${definition.name}.dart`, getResult());
|
||||
}
|
||||
|
||||
generateService(definition: ServiceDefinition): void {
|
||||
@ -145,24 +150,30 @@ export class DartTarget extends CompileTarget<{}> {
|
||||
finalize(steps: Step[]): void {
|
||||
const { a, getResult } = LineAppender();
|
||||
|
||||
// steps.forEach(([type, def]) => {
|
||||
// switch (type) {
|
||||
// case "type":
|
||||
// a(0, `pub ${this.getImport(def.name)}`);
|
||||
// break;
|
||||
// case "enum":
|
||||
// a(0, `pub ${this.getImport(def.name)}`);
|
||||
// break;
|
||||
// default:
|
||||
// console.warn(
|
||||
// chalk.yellow("[DART] WARNING:"),
|
||||
// "unimplemented step found:",
|
||||
// type
|
||||
// );
|
||||
// // case "service":
|
||||
// }
|
||||
// });
|
||||
a(0, `library ${this.options.dart_library_name};`)
|
||||
a(0, ``);
|
||||
|
||||
// this.writeFile(`mod.dart`, getResult());
|
||||
|
||||
steps.forEach(([type, def]) => {
|
||||
switch (type) {
|
||||
case "type":
|
||||
a(0, `export 'src/${def.name}.dart';`);
|
||||
break;
|
||||
case "enum":
|
||||
a(0, `export 'src/${def.name}.dart';`);
|
||||
break;
|
||||
default:
|
||||
console.warn(
|
||||
chalk.yellow("[DART] WARNING:"),
|
||||
"unimplemented step found:",
|
||||
type
|
||||
);
|
||||
// case "service":
|
||||
}
|
||||
});
|
||||
|
||||
this.writeFile(`lib/${this.options.dart_library_name}.dart`, getResult());
|
||||
|
||||
this.writeFile(`pubspec.yaml`, this.getTemplate("Dart/pubspec.yaml").replace("__NAME__", this.options.dart_library_name));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user