Add pubspec.yaml
This commit is contained in:
parent
68af1ff442
commit
276fd12894
3
.gitignore
vendored
3
.gitignore
vendored
@ -12,3 +12,6 @@ examples/Dart/out
|
|||||||
templates/CSharp/bin
|
templates/CSharp/bin
|
||||||
templates/CSharp/obj
|
templates/CSharp/obj
|
||||||
lib/
|
lib/
|
||||||
|
templates/Dart/.dart_tool
|
||||||
|
templates/Dart/.packages
|
||||||
|
templates/Dart/pubspec.lock
|
@ -1,10 +1,8 @@
|
|||||||
import "./out/Test.dart";
|
import "./out/lib/example.dart";
|
||||||
import "./out/TestAtom.dart";
|
|
||||||
import "./out/TestEnum.dart";
|
|
||||||
import "dart:convert";
|
import "dart:convert";
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
var t = new TestAtom(10, false, "hello");
|
var t = TestAtom(val_boolean: false, val_number: 1, val_string: "hi");
|
||||||
print(jsonEncode(t));
|
print(jsonEncode(t));
|
||||||
|
|
||||||
var t2 = TestEnum.VAL2;
|
var t2 = TestEnum.VAL2;
|
||||||
|
@ -2,6 +2,7 @@ import "./import";
|
|||||||
|
|
||||||
define csharp_namespace Example;
|
define csharp_namespace Example;
|
||||||
define rust_crate example;
|
define rust_crate example;
|
||||||
|
define dart_library_name example;
|
||||||
|
|
||||||
enum TestEnum {
|
enum TestEnum {
|
||||||
VAL1,
|
VAL1,
|
||||||
|
@ -17,13 +17,17 @@ function toDartType(type: string): string {
|
|||||||
return (conversion as any)[type] || type;
|
return (conversion as any)[type] || type;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DartTarget extends CompileTarget<{}> {
|
export class DartTarget extends CompileTarget<{ dart_library_name: string }> {
|
||||||
name: string = "dart";
|
name: string = "dart";
|
||||||
|
|
||||||
start(): void {
|
start(): void {
|
||||||
if (this.options.allow_bytes == true) {
|
if (this.options.allow_bytes == true) {
|
||||||
throw new Error("Dart has no support for 'bytes' yet!");
|
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) {
|
getImport(name: string) {
|
||||||
@ -55,7 +59,7 @@ export class DartTarget extends CompileTarget<{}> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
a(0, ``);
|
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(0, ``);
|
||||||
a(1, `${definition.name}.fromJson(Map<String, dynamic> json) {`);
|
a(1, `${definition.name}.fromJson(Map<String, dynamic> json) {`);
|
||||||
for (const field of definition.fields) {
|
for (const field of definition.fields) {
|
||||||
@ -91,7 +95,7 @@ export class DartTarget extends CompileTarget<{}> {
|
|||||||
a(1, `}`);
|
a(1, `}`);
|
||||||
a(0, `}`);
|
a(0, `}`);
|
||||||
|
|
||||||
this.writeFile(`${definition.name}.dart`, getResult());
|
this.writeFile(`lib/src/${definition.name}.dart`, getResult());
|
||||||
}
|
}
|
||||||
|
|
||||||
generateEnum(definition: EnumDefinition): void {
|
generateEnum(definition: EnumDefinition): void {
|
||||||
@ -114,6 +118,7 @@ export class DartTarget extends CompileTarget<{}> {
|
|||||||
}
|
}
|
||||||
a(3, `default:`);
|
a(3, `default:`);
|
||||||
a(4, `return null;`);
|
a(4, `return null;`);
|
||||||
|
a(2, `}`);
|
||||||
a(1, `}`);
|
a(1, `}`);
|
||||||
a(0, `}`);
|
a(0, `}`);
|
||||||
|
|
||||||
@ -132,7 +137,7 @@ export class DartTarget extends CompileTarget<{}> {
|
|||||||
// a(1, `}`);
|
// a(1, `}`);
|
||||||
// a(0, `}`);
|
// a(0, `}`);
|
||||||
|
|
||||||
this.writeFile(`${definition.name}.dart`, getResult());
|
this.writeFile(`lib/src/${definition.name}.dart`, getResult());
|
||||||
}
|
}
|
||||||
|
|
||||||
generateService(definition: ServiceDefinition): void {
|
generateService(definition: ServiceDefinition): void {
|
||||||
@ -145,24 +150,30 @@ export class DartTarget extends CompileTarget<{}> {
|
|||||||
finalize(steps: Step[]): void {
|
finalize(steps: Step[]): void {
|
||||||
const { a, getResult } = LineAppender();
|
const { a, getResult } = LineAppender();
|
||||||
|
|
||||||
// steps.forEach(([type, def]) => {
|
a(0, `library ${this.options.dart_library_name};`)
|
||||||
// switch (type) {
|
a(0, ``);
|
||||||
// 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":
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
// 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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
30
templates/Dart/analysis_options.yaml
Normal file
30
templates/Dart/analysis_options.yaml
Normal 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
|
10
templates/Dart/pubspec.yaml
Normal file
10
templates/Dart/pubspec.yaml
Normal 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
|
Loading…
Reference in New Issue
Block a user