Skip to content

Commit e00b66e

Browse files
Initial editor commit
1 parent 3594929 commit e00b66e

21 files changed

+2636
-0
lines changed

.gitignore

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Dependencies
2+
node_modules/
3+
.yarn-integrity
4+
5+
# Production build
6+
dist/
7+
public/bundle.js
8+
public/bundle.js.map
9+
10+
# IDE and Editor files
11+
.vscode/
12+
.idea/
13+
*.swp
14+
*.swo
15+
.DS_Store
16+
17+
# Environment files
18+
.env
19+
.env.local
20+
.env.development.local
21+
.env.test.local
22+
.env.production.local
23+
24+
# Debug logs
25+
npm-debug.log*
26+
yarn-debug.log*
27+
yarn-error.log*
28+
29+
# TypeScript cache
30+
*.tsbuildinfo
31+
32+
# Optional npm cache directory
33+
.npm
34+
35+
# Optional eslint cache
36+
.eslintcache
37+

esbuild.config.js

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
const esbuild = require("esbuild");
2+
const http = require("http");
3+
const fs = require("fs");
4+
const path = require("path");
5+
const args = process.argv.slice(2);
6+
const isServe = args.includes("--serve");
7+
8+
const PORT = 3000;
9+
10+
const buildOptions = {
11+
entryPoints: ["src/index.tsx"],
12+
bundle: true,
13+
outfile: "public/bundle.js",
14+
minify: !isServe,
15+
sourcemap: isServe,
16+
target: ["es2020", "chrome80", "firefox80", "safari13"],
17+
loader: {
18+
".png": "dataurl",
19+
".jpg": "dataurl",
20+
".svg": "text",
21+
".tsx": "tsx",
22+
".ts": "tsx",
23+
},
24+
jsx: "automatic",
25+
};
26+
27+
// Function to start the development server
28+
function startDevServer() {
29+
// Start a simple HTTP server
30+
const server = http.createServer((req, res) => {
31+
const url = req.url === "/" ? "/index.html" : req.url;
32+
const filePath = path.join(__dirname, "public", url.replace(/^\//, ""));
33+
const contentType = getContentType(filePath);
34+
35+
fs.readFile(filePath, (err, content) => {
36+
if (err) {
37+
if (err.code === "ENOENT") {
38+
res.writeHead(404);
39+
res.end("File not found");
40+
} else {
41+
res.writeHead(500);
42+
res.end(`Server Error: ${err.code}`);
43+
}
44+
} else {
45+
res.writeHead(200, { "Content-Type": contentType });
46+
res.end(content, "utf-8");
47+
}
48+
});
49+
});
50+
51+
server.listen(PORT, () => {
52+
console.log(`Server started on http://localhost:${PORT}`);
53+
console.log("Press Ctrl+C to stop");
54+
});
55+
}
56+
57+
// Build and serve based on arguments
58+
if (isServe) {
59+
// Use watch mode when serving
60+
esbuild
61+
.context(buildOptions)
62+
.then((context) => {
63+
// Start watch mode
64+
context.watch();
65+
console.log("Watch mode enabled - rebuilding on file changes");
66+
67+
// Start the dev server
68+
startDevServer();
69+
})
70+
.catch((err) => {
71+
console.error(err);
72+
process.exit(1);
73+
});
74+
} else {
75+
// Just build once for production
76+
esbuild
77+
.build(buildOptions)
78+
.then(() => {
79+
console.log("Build complete");
80+
})
81+
.catch((err) => {
82+
console.error(err);
83+
process.exit(1);
84+
});
85+
}
86+
87+
function getContentType(filePath) {
88+
const extname = path.extname(filePath);
89+
switch (extname) {
90+
case ".html":
91+
return "text/html";
92+
case ".js":
93+
return "text/javascript";
94+
case ".css":
95+
return "text/css";
96+
case ".json":
97+
return "application/json";
98+
case ".png":
99+
return "image/png";
100+
case ".jpg":
101+
case ".jpeg":
102+
return "image/jpeg";
103+
default:
104+
return "text/plain";
105+
}
106+
}

package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "arduino-tilemap-editor",
3+
"version": "0.1.0",
4+
"description": "Create, edit, and export tilemaps directly to C++ header files for Arduino.",
5+
"scripts": {
6+
"start": "node esbuild.config.js --serve",
7+
"build": "node esbuild.config.js"
8+
},
9+
"keywords": [
10+
"tilemap",
11+
"editor",
12+
"arduino",
13+
"epd",
14+
"rpg"
15+
],
16+
"author": "Aymeric Chauvin",
17+
"license": "MIT",
18+
"devDependencies": {
19+
"@types/react": "^19.1.0",
20+
"@types/react-dom": "^19.1.1",
21+
"esbuild": "^0.19.5",
22+
"typescript": "^5.2.2"
23+
},
24+
"dependencies": {
25+
"react": "^19.1.0",
26+
"react-dom": "^19.1.0"
27+
}
28+
}

public/index.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Arduino Tilemap Editor</title>
7+
<meta
8+
name="description"
9+
content="Create, edit, and export tilemaps directly to C++ header files for Arduino."
10+
/>
11+
<link rel="stylesheet" href="styles.css" />
12+
</head>
13+
<body>
14+
<div id="root"></div>
15+
16+
<script src="bundle.js"></script>
17+
</body>
18+
</html>

0 commit comments

Comments
 (0)