Skip to content

Commit dda8807

Browse files
committed
File linking
1 parent dfab871 commit dda8807

File tree

5 files changed

+27
-66
lines changed

5 files changed

+27
-66
lines changed

src/cli.ts

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -89,75 +89,19 @@ const config = {
8989
await mkdir(join(targetDir, 'public'), {recursive: true});
9090
},
9191

92-
getFiles: (context: Record<string, unknown>) => {
93-
const {typescript, react, ext, prettier, eslint} = context;
94-
95-
const files = [
92+
getFiles: () => {
93+
return [
9694
{
9795
template: 'base/package.json.hbs',
9896
output: 'package.json',
9997
prettier: true,
10098
},
101-
{
102-
template: 'base/index.html.hbs',
103-
output: 'index.html',
104-
prettier: true,
105-
},
106-
{
107-
template: 'public/favicon.svg',
108-
output: 'public/favicon.svg',
109-
},
11099
{
111100
template: 'base/README.md.hbs',
112101
output: 'README.md',
113102
prettier: true,
114103
},
115-
{
116-
template: 'src/index.css.hbs',
117-
output: 'src/index.css',
118-
prettier: true,
119-
},
120-
{
121-
template: 'src/index.tsx.hbs',
122-
output: `src/index.${ext}`,
123-
prettier: true,
124-
transpile: !typescript,
125-
},
126104
];
127-
128-
if (prettier) {
129-
files.push({
130-
template: 'base/.prettierrc.hbs',
131-
output: '.prettierrc',
132-
prettier: true,
133-
});
134-
}
135-
136-
if (eslint) {
137-
files.push({
138-
template: 'base/eslint.config.js.hbs',
139-
output: 'eslint.config.js',
140-
prettier: true,
141-
});
142-
}
143-
144-
if (react) {
145-
files.push({
146-
template: 'base/vite.config.js.hbs',
147-
output: 'vite.config.js',
148-
prettier: true,
149-
});
150-
}
151-
152-
if (typescript) {
153-
files.push({
154-
template: 'base/tsconfig.json.hbs',
155-
output: 'tsconfig.json',
156-
prettier: true,
157-
});
158-
}
159-
160-
return files;
161105
},
162106

163107
processIncludedFile: (file: FileConfig, context: TemplateContext) => {

templates/base/index.html.hbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<link rel="preconnect" href="https://fonts.googleapis.com" />
88
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
99
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@400;800&display=swap" />
10+
{{includeFile template="public/favicon.svg" output="public/favicon.svg"}}
1011
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
1112
<title>
1213
TinyBase / {{#if typescript}}TypeScript{{else}}JavaScript{{/if}}{{#if react}} + React{{/if}}
@@ -47,6 +48,7 @@
4748
</details>
4849
</div>
4950
{{/if}}
51+
{{includeFile template="src/index.tsx.hbs" output="src/index.{{ext}}"}}
5052
<script type="module" src="/src/index.{{ext}}"></script>
5153
</body>
5254

templates/base/package.json.hbs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "1.0.0",
44
"scripts": {
55
{{#list}}
6+
{{includeFile template="base/index.html.hbs" output="index.html"}}
67
"dev": "vite"
78
{{#if typescript}}
89
"build": "tsc && vite build"
@@ -57,4 +58,16 @@
5758
{{/if}}
5859
{{/list}}
5960
}
60-
}
61+
}
62+
{{#if prettier}}
63+
{{includeFile template="base/.prettierrc.hbs" output=".prettierrc"}}
64+
{{/if}}
65+
{{#if eslint}}
66+
{{includeFile template="base/eslint.config.js.hbs" output="eslint.config.js"}}
67+
{{/if}}
68+
{{#if react}}
69+
{{includeFile template="base/vite.config.js.hbs" output="vite.config.js"}}
70+
{{/if}}
71+
{{#if typescript}}
72+
{{includeFile template="base/tsconfig.json.hbs" output="tsconfig.json"}}
73+
{{/if}}

templates/src/index.tsx.hbs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
{{includeFile template="src/index.css.hbs" output="src/index.css"}}
12
import './index.css';
2-
33
{{#if react}}
4-
54
import ReactDOM from 'react-dom/client';
65
import {App} from './App';
76
{{includeFile template="src/App.tsx.hbs" output="src/App.{{ext}}"}}
@@ -11,12 +10,9 @@ import './index.css';
1110
ReactDOM.createRoot(document.getElementById('app')!).render(
1211
<App />),
1312
);
14-
1513
{{else}}
16-
1714
import {app} from './app';
1815
{{includeFile template="src/app.ts.hbs" output="src/app.{{ext}}"}}
1916

2017
addEventListener('load', app);
21-
2218
{{/if}}

test/__snapshots__/cli.test.js.snap

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ npm run dev
2929
rel="stylesheet"
3030
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;800&display=swap"
3131
/>
32+
3233
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
3334
<title>TinyBase / JavaScript + React</title>
3435
</head>
3536
3637
<body>
3738
<div id="app"></div>
39+
3840
<script type="module" src="/src/index.jsx"></script>
3941
</body>
4042
</html>
@@ -335,6 +337,7 @@ npm run dev
335337
rel="stylesheet"
336338
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;800&display=swap"
337339
/>
340+
338341
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
339342
<title>TinyBase / JavaScript</title>
340343
</head>
@@ -369,6 +372,7 @@ npm run dev
369372
<pre id="tablesJson"></pre>
370373
</details>
371374
</div>
375+
372376
<script type="module" src="/src/index.js"></script>
373377
</body>
374378
</html>
@@ -603,12 +607,14 @@ npm run dev
603607
rel="stylesheet"
604608
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;800&display=swap"
605609
/>
610+
606611
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
607612
<title>TinyBase / TypeScript + React</title>
608613
</head>
609614
610615
<body>
611616
<div id="app"></div>
617+
612618
<script type="module" src="/src/index.tsx"></script>
613619
</body>
614620
</html>
@@ -871,7 +877,6 @@ table.sortedTable thead th {
871877
}
872878
",
873879
"src/index.tsx": "import './index.css';
874-
875880
import ReactDOM from 'react-dom/client';
876881
import {App} from './App';
877882
@@ -944,6 +949,7 @@ npm run dev
944949
rel="stylesheet"
945950
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;800&display=swap"
946951
/>
952+
947953
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
948954
<title>TinyBase / TypeScript</title>
949955
</head>
@@ -978,6 +984,7 @@ npm run dev
978984
<pre id="tablesJson"></pre>
979985
</details>
980986
</div>
987+
981988
<script type="module" src="/src/index.ts"></script>
982989
</body>
983990
</html>
@@ -1185,7 +1192,6 @@ table.sortedTable thead th {
11851192
}
11861193
",
11871194
"src/index.ts": "import './index.css';
1188-
11891195
import {app} from './app';
11901196
11911197
addEventListener('load', app);

0 commit comments

Comments
 (0)