-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathindex.ts
75 lines (69 loc) · 1.89 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { Widget } from "@reflect-ui/core";
import { compose } from "./tokens-to-flutter-widget";
import { flutter as config } from "@grida/builder-config";
import * as flutter from "@flutter-builder/flutter";
import { composeAppWithHome } from "@flutter-builder/flutter";
import { makeApp } from "./app";
import { nameit, NameCase } from "@coli.codes/naming";
import { WidgetKey } from "@reflect-ui/core";
const import_material = "import 'package:flutter/material.dart';";
const ignore_lint =
"// ignore_for_file: sort_child_properties_last, prefer_const_constructors, prefer_const_literals_to_create_immutables";
export function buildFlutterApp(
key: WidgetKey,
widget: flutter.Widget,
p: { id: string }
): config.FlutterComponentOutput {
const app =
widget &&
makeApp({
widget: widget,
scrollable: false,
});
const widgetCode = widget?.build()?.finalize();
const rootAppCode = ignore_lint + "\n" + composeAppWithHome(app);
return {
id: p.id,
name: nameit(key.name, {
// @ts-ignore
case: "snake",
}).name,
code: {
raw: composeWidgetClassFile({
imports: [ignore_lint, import_material],
className: nameit(key.name, {
// @ts-ignore
case: "pascal",
}).name,
widgetTree: widgetCode,
}),
},
scaffold: { raw: rootAppCode },
main: { raw: rootAppCode },
};
}
export function buildFlutterWidget(widget: Widget) {
if (!widget) {
throw "A valid reflect widget manifest should be passed as an input. none was passed.";
}
return compose(widget);
}
export function composeWidgetClassFile({
imports,
className,
widgetTree,
}: {
imports: string[];
className: string;
widgetTree: string;
}) {
return `
${imports?.join("\n") ?? ""}
class ${className} extends StatelessWidget {
@override
Widget build(BuildContext context) { return
${widgetTree}
}}
`;
// return compose(src);
}