Skip to content

Commit

Permalink
feat: add html template
Browse files Browse the repository at this point in the history
  • Loading branch information
laclys committed May 17, 2023
1 parent 9d97947 commit 3cf24cb
Show file tree
Hide file tree
Showing 18 changed files with 667 additions and 0 deletions.
6 changes: 6 additions & 0 deletions dist/node/constants/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DEFAULT_TEMPLATE_PATH = exports.PACKAGE_ROOT = void 0;
const path = require("path");
exports.PACKAGE_ROOT = path.join(__dirname, '..', '..', '..');
exports.DEFAULT_TEMPLATE_PATH = path.join(exports.PACKAGE_ROOT, 'template.html');
3 changes: 3 additions & 0 deletions dist/node/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
Object.defineProperty(exports, "__esModule", { value: true });
exports.createDevServer = void 0;
const vite_1 = require("vite");
const plugin_react_1 = require("@vitejs/plugin-react");
const indexHtml_1 = require("./plugin/indexHtml");
async function createDevServer(root = process.cwd()) {
return (0, vite_1.createServer)({
root,
plugins: [(0, indexHtml_1.pluginIndexHtml)(), (0, plugin_react_1.default)()]
});
}
exports.createDevServer = createDevServer;
30 changes: 30 additions & 0 deletions dist/node/plugin/indexHtml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.pluginIndexHtml = void 0;
const promises_1 = require("fs/promises");
const constants_1 = require("../constants");
function pluginIndexHtml() {
return {
name: 'shaco:index-html',
apply: 'serve',
configureServer(server) {
return () => {
server.middlewares.use(async (req, res, next) => {
// read template.html
let content = await (0, promises_1.readFile)(constants_1.DEFAULT_TEMPLATE_PATH, 'utf-8');
try {
content = await server.transformIndexHtml(req.url, content, req.originalUrl);
// response html borwer
res.statusCode = 200;
res.setHeader('Content-Type', 'text/html');
res.end(content);
}
catch (e) {
return next(e);
}
});
};
},
};
}
exports.pluginIndexHtml = pluginIndexHtml;
9 changes: 9 additions & 0 deletions dist/runtime/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.App = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const theme_default_1 = require("../theme-default");
function App() {
return (0, jsx_runtime_1.jsx)(theme_default_1.Layout, {});
}
exports.App = App;
13 changes: 13 additions & 0 deletions dist/runtime/client-entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const jsx_runtime_1 = require("react/jsx-runtime");
const client_1 = require("react-dom/client");
const App_1 = require("./App");
function renderInBrowser() {
const containerEl = document.getElementById("root");
if (!containerEl) {
throw new Error("#root element not found");
}
(0, client_1.createRoot)(containerEl).render((0, jsx_runtime_1.jsx)(App_1.App, {}));
}
renderInBrowser();
10 changes: 10 additions & 0 deletions dist/theme-default/Layout/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Layout = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
function Layout() {
const [count, setCount] = (0, react_1.useState)(0);
return ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("h1", { children: "This is Layout Component" }), (0, jsx_runtime_1.jsxs)("div", { children: [count, (0, jsx_runtime_1.jsx)("button", { onClick: () => setCount(count + 1), children: "Add Count" })] })] }));
}
exports.Layout = Layout;
5 changes: 5 additions & 0 deletions dist/theme-default/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Layout = void 0;
var Layout_1 = require("./Layout");
Object.defineProperty(exports, "Layout", { enumerable: true, get: function () { return Layout_1.Layout; } });
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@
"license": "ISC",
"devDependencies": {
"@types/node": "^20.1.7",
"@types/react": "^18.2.6",
"@types/react-dom": "^18.2.4",
"typescript": "^5.0.4"
},
"dependencies": {
"@vitejs/plugin-react": "^4.0.0",
"cac": "^6.7.14",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"vite": "^4.3.7"
}
}
Loading

0 comments on commit 3cf24cb

Please sign in to comment.