-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·142 lines (124 loc) · 3.49 KB
/
build.sh
File metadata and controls
executable file
·142 lines (124 loc) · 3.49 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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/bash
# Build the Rust WASM package with wasm-pack
wasm-pack build --target web
# Install npm dependencies if needed
npm install
# Build the package with Vite
npm run build
# Create package directory
rm -rf package
mkdir -p package/dist/{js,css,wasm}
# Copy build artifacts
cp -r dist/* package/dist/
cp -r public/wasm/* package/dist/wasm/
cp -r public/js/config.js package/dist/js/
cp -r public/css/terraphim-editor.css package/dist/css/
cp README.md LICENSE package/
# Extract version from Cargo.toml
VERSION=$(grep '^version' Cargo.toml | head -1 | cut -d '"' -f 2)
# Create package.json for npm distribution
cat > package/package.json << EOL
{
"name": "terraphim-editor",
"version": "${VERSION}",
"description": "WebAssembly-based Markdown editor component built with Rust",
"main": "./dist/js/terraphim-editor.umd.js",
"module": "./dist/js/terraphim-editor.mjs",
"unpkg": "./dist/js/terraphim-editor.iife.js",
"types": "./dist/js/terraphim-editor.d.ts",
"files": ["dist", "README.md", "LICENSE"],
"exports": {
".": {
"types": "./dist/js/terraphim-editor.d.ts",
"import": "./dist/js/terraphim-editor.mjs",
"require": "./dist/js/terraphim-editor.umd.js",
"default": "./dist/js/terraphim-editor.iife.js"
},
"./style.css": "./dist/css/terraphim-editor.css"
},
"peerDependencies": {
"@shoelace-style/shoelace": "^2.12.0"
}
}
EOL
# Create example files for each module format
cat > package/example-esm.html << EOL
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Terraphim Editor - ESM Example</title>
<link rel="stylesheet" href="dist/css/terraphim-editor.css">
<script type="importmap">
{
"imports": {
"terraphim-editor": "./dist/js/terraphim-editor.mjs"
}
}
</script>
</head>
<body>
<div id="editor"></div>
<script type="module">
import { TeraphimEditor } from 'terraphim-editor';
async function initEditor() {
const editor = new TeraphimEditor({
container: document.getElementById('editor'),
wasmUrl: './dist/wasm/terraphim_editor_bg.wasm'
});
await editor.initialize();
}
initEditor().catch(console.error);
</script>
</body>
</html>
EOL
cat > package/example-umd.html << EOL
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Terraphim Editor - UMD Example</title>
<link rel="stylesheet" href="dist/css/terraphim-editor.css">
<script src="dist/js/terraphim-editor.umd.js"></script>
</head>
<body>
<div id="editor"></div>
<script>
async function initEditor() {
const editor = new TeraphimEditor({
container: document.getElementById('editor'),
wasmUrl: './dist/wasm/terraphim_editor_bg.wasm'
});
await editor.initialize();
}
initEditor().catch(console.error);
</script>
</body>
</html>
EOL
cat > package/example-iife.html << EOL
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Terraphim Editor - IIFE Example</title>
<link rel="stylesheet" href="dist/css/terraphim-editor.css">
<script src="dist/js/terraphim-editor.iife.js"></script>
</head>
<body>
<div id="editor"></div>
<script>
async function initEditor() {
const editor = new TeraphimEditor({
container: document.getElementById('editor'),
wasmUrl: './dist/wasm/terraphim_editor_bg.wasm'
});
await editor.initialize();
}
initEditor().catch(console.error);
</script>
</body>
</html>
EOL
echo "Package built successfully in the 'package' directory"