-
-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathindex.ts
More file actions
78 lines (73 loc) · 2.17 KB
/
Copy pathindex.ts
File metadata and controls
78 lines (73 loc) · 2.17 KB
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
76
77
78
import {
EK_GENERATED_CODE_PLAIN,
EK_IMAGE_ASSET_REPOSITORY_MAP,
} from "@core/constant/ek.constant";
import {
onService,
_Code_Event,
_APP_EVENT_CODE_GEN_RESULT_EK,
CodeGenRequest,
} from "./events";
import { designToFlutter, designToReact } from "./design-to-code";
import { FigmaNodeCache } from "figma-core/node-cache";
import { Framework } from "../framework-option";
import { repo_assets } from "@design-sdk/core";
onService(main_cb);
// main callback
function main_cb(evt: _Code_Event) {
// to logic
switch (evt.type) {
case "code-gen-request":
_handle_code_gen_request(evt);
break;
}
}
async function _handle_code_gen_request(req: CodeGenRequest) {
//#region run code gen
const rnode = FigmaNodeCache.getLastConverted();
if (rnode) {
const codePlatform = (() => {
switch (req.option.framework) {
case Framework.react:
return "react";
case Framework.flutter:
return "flutter";
default:
return "flutter"; // currently default mode is flutter due to flutter is default legacy.
}
throw `unrecognized user_interest givven "${req.option.framework}"`;
})();
const hostingjob = async () => {
// host images
const transportableImageAssetRepository =
await repo_assets.MainImageRepository.instance.current.makeTransportable();
figma.ui.postMessage({
type: EK_IMAGE_ASSET_REPOSITORY_MAP,
data: transportableImageAssetRepository,
});
};
//@ts-ignore
if (codePlatform == "flutter") {
const flutterBuild = await designToFlutter(rnode, hostingjob);
figma.ui.postMessage({
type: EK_GENERATED_CODE_PLAIN,
data: {
code: flutterBuild.widget.build().finalize(),
app: flutterBuild.app.build().finalize(),
},
});
} else if (codePlatform == "react") {
const reactBuild = designToReact(rnode);
figma.ui.postMessage({
type: EK_GENERATED_CODE_PLAIN,
data: {
code: reactBuild.app,
app: reactBuild.app,
},
});
}
} else {
console.warn("user requested linting, but non selected to run lint on.");
}
//#endregion
}