-
Notifications
You must be signed in to change notification settings - Fork 8
/
webtemplates.go
128 lines (116 loc) · 2.73 KB
/
webtemplates.go
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Copyright 2022 Namespace Labs Inc; All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
package scaffold
import "text/template"
type webServiceTmplOptions struct {
}
type webTemplateFile struct {
filename string
tmpl *template.Template
}
var webTemplates = []webTemplateFile{
{
filename: "src/index.tsx",
tmpl: template.Must(template.New("index.tsx").Parse(`
import React, { useEffect, useState } from "react";
import ReactDOM from "react-dom";
import { Backends } from "../config/backends.fn.js";
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById("app")
);
function App() {
const [text, setText] = useState("");
useEffect(() => {
const fetchData = async () => {
const result = await postAPI({ text: "Hello World" });
const json = await result.json();
setText(json["text"]);
};
fetchData();
}, []);
return <>Response from the backend: {text}</>;
}
function postAPI(request: any) {
return fetch(` + "`" + `${Backends.apiBackend.managed}/api.echoservice.EchoService/Echo` + "`" + `, {
method: "POST",
mode: "cors",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(request),
});
}
`)),
},
{
filename: "package.json",
tmpl: template.Must(template.New("package.json").Parse(`{
"private": true,
"browserslist": "> 0.5%, last 2 versions, not dead",
"scripts": {
"dev": "vite",
"build": "vite build"
},
"devDependencies": {
"@types/react": "^17.0.35",
"@types/react-dom": "^17.0.11",
"@vitejs/plugin-react": "^1.1.0",
"vite-plugin-rewrite-all": "^1.0.0",
"typescript": "4.5.4",
"vite": "2.7.13"
},
"dependencies": {
"react": "^17.0.2",
"react-dom": "^17.0.2"
}
}`)),
},
{
filename: "index.html",
tmpl: template.Must(template.New("index.html").Parse(`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Welcome to Namespace</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="./src/index.tsx"></script>
</body>
</html>`)),
},
{
filename: "tsconfig.json",
tmpl: template.Must(template.New("tsconfig").Parse(`{
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"lib": [
"DOM",
"DOM.Iterable",
"ESNext"
],
"allowJs": false,
"skipLibCheck": false,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"noImplicitAny": false,
},
"include": [
"./src"
]
}`)),
},
}