Add pubspec.yaml

This commit is contained in:
Fabian Stamm 2022-07-21 09:09:10 +02:00
parent 68af1ff442
commit 276fd12894
6 changed files with 87 additions and 34 deletions

3
.gitignore vendored
View File

@ -12,3 +12,6 @@ examples/Dart/out
templates/CSharp/bin
templates/CSharp/obj
lib/
templates/Dart/.dart_tool
templates/Dart/.packages
templates/Dart/pubspec.lock

View File

@ -1,10 +1,8 @@
import "./out/Test.dart";
import "./out/TestAtom.dart";
import "./out/TestEnum.dart";
import "./out/lib/example.dart";
import "dart:convert";
int main() {
var t = new TestAtom(10, false, "hello");
var t = TestAtom(val_boolean: false, val_number: 1, val_string: "hi");
print(jsonEncode(t));
var t2 = TestEnum.VAL2;

View File

@ -2,6 +2,7 @@ import "./import";
define csharp_namespace Example;
define rust_crate example;
define dart_library_name example;
enum TestEnum {
VAL1,

View File

@ -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,7 +59,7 @@ 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) {
@ -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));
}
}

View File

@ -0,0 +1,30 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.
include: package:lints/recommended.yaml
# Uncomment the following section to specify additional rules.
# linter:
# rules:
# - camel_case_types
# analyzer:
# exclude:
# - path/to/excluded/files/**
# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints
# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options

View File

@ -0,0 +1,10 @@
name: __NAME__
description: JRPC
version: 1.0.0
environment:
sdk: '>=2.17.6 <3.0.0'
dependencies:
dev_dependencies:
lints: ^2.0.0