Skip to content

Commit 2c49f4d

Browse files
committed
Vars & indenting
1 parent 43bbc45 commit 2c49f4d

File tree

10 files changed

+175
-187
lines changed

10 files changed

+175
-187
lines changed

src/cli.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,14 @@ const config = {
6363
],
6464

6565
createContext: (answers: TinyBaseAnswers) => {
66-
const isTypescript = answers.language === 'typescript';
67-
const isReact = answers.framework === 'react';
68-
const ext = isTypescript
69-
? isReact
70-
? 'tsx'
71-
: 'ts'
72-
: isReact
73-
? 'jsx'
74-
: 'js';
66+
const typescript = answers.language === 'typescript';
67+
const react = answers.framework === 'react';
68+
const ext = typescript ? (react ? 'tsx' : 'ts') : react ? 'jsx' : 'js';
7569

7670
return {
7771
...answers,
78-
isTypescript,
79-
isReact,
72+
typescript,
73+
react,
8074
ext,
8175
};
8276
},
@@ -89,7 +83,7 @@ const config = {
8983
},
9084

9185
getFiles: (context: Record<string, unknown>) => {
92-
const {isTypescript, isReact, ext, prettier, eslint} = context;
86+
const {typescript, react, ext, prettier, eslint} = context;
9387

9488
const files = [
9589
{
@@ -135,7 +129,7 @@ const config = {
135129
});
136130
}
137131

138-
if (isReact) {
132+
if (react) {
139133
files.push(
140134
{
141135
template: 'src/App.tsx.hbs',
@@ -151,7 +145,7 @@ const config = {
151145
);
152146
}
153147

154-
if (isTypescript) {
148+
if (typescript) {
155149
files.push(
156150
{template: 'base/tsconfig.json.hbs', output: 'tsconfig.json'},
157151
{

templates/base/README.md.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# {{projectName}}
22

3-
A TinyBase app built with {{#if isTypescript}}TypeScript{{else}}JavaScript{{/if}} and {{#if isReact}}React{{else}}Vanilla JS{{/if}}.
3+
A TinyBase app built with {{#if typescript}}TypeScript{{else}}JavaScript{{/if}} and {{#if react}}React{{else}}Vanilla JS{{/if}}.
44

55
## Getting Started
66

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,38 @@
1-
{{#if isTypescript}}{{addImport "import tseslint from 'typescript-eslint';"}}{{/if}}
2-
{{#if isReact}}{{addImport "import pluginReact from 'eslint-plugin-react';"}}{{/if}}
3-
{{#if isReact}}{{addImport "import pluginReactHooks from 'eslint-plugin-react-hooks';"}}{{/if}}
1+
{{#if typescript}}
2+
{{addImport "import tseslint from 'typescript-eslint';"}}
3+
{{/if}}
4+
{{#if react}}
5+
{{addImport "import pluginReact from 'eslint-plugin-react';"}}
6+
{{addImport "import pluginReactHooks from 'eslint-plugin-react-hooks';"}}
7+
{{/if}}
48

59
export default [
6-
{{#if isTypescript}}
7-
...tseslint.configs.recommended,
8-
{{else}}
9-
{
10-
rules: {
11-
'no-unused-vars': 'warn',
12-
'no-undef': 'error',
10+
{{#if typescript}}
11+
...tseslint.configs.recommended,
12+
{{else}}
13+
{
14+
rules: {
15+
'no-unused-vars': 'warn',
16+
'no-undef': 'error',
17+
},
1318
},
14-
},
15-
{{/if}}
19+
{{/if}}
1620

17-
{{#if isReact}}
18-
pluginReact.configs.flat.recommended,
19-
{
20-
plugins: {
21-
'react-hooks': pluginReactHooks,
22-
},
23-
rules: {
24-
...pluginReactHooks.configs.recommended.rules,
25-
'react/react-in-jsx-scope': 'off',
26-
},
27-
settings: {
28-
react: {
29-
version: 'detect',
21+
{{#if react}}
22+
pluginReact.configs.flat.recommended,
23+
{
24+
plugins: {
25+
'react-hooks': pluginReactHooks,
26+
},
27+
rules: {
28+
...pluginReactHooks.configs.recommended.rules,
29+
'react/react-in-jsx-scope': 'off',
30+
},
31+
settings: {
32+
react: {
33+
version: 'detect',
34+
},
3035
},
3136
},
32-
},
33-
{{/if}}
37+
{{/if}}
3438
];

templates/base/index.html.hbs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
<title>TinyBase</title>
77
</head>
88
<body>
9-
{{#if isReact}}
10-
<div id="app"></div>
11-
{{/if}}
9+
{{#if react}}
10+
<div id="app"></div>
11+
{{/if}}
1212
<script type="module" src="/src/index.{{ext}}"></script>
1313
</body>
1414
</html>

templates/base/package.json.hbs

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,59 @@
22
"name": "{{projectName}}",
33
"version": "1.0.0",
44
"scripts": {
5-
{{#list}}
6-
"dev": "vite"
7-
{{#if isTypescript}}
8-
"build": "tsc && vite build"
9-
{{else}}
10-
"build": "vite build"
11-
{{/if}}
12-
"preview": "vite preview"
13-
{{#if prettier}}
14-
"format": "prettier --write ."
15-
"format:check": "prettier --check ."
16-
{{/if}}
17-
{{#if eslint}}
18-
"lint": "eslint ."
19-
{{/if}}
20-
{{/list}}
5+
{{#list}}
6+
"dev": "vite"
7+
{{#if typescript}}
8+
"build": "tsc && vite build"
9+
{{else}}
10+
"build": "vite build"
11+
{{/if}}
12+
"preview": "vite preview"
13+
{{#if prettier}}
14+
"format": "prettier --write ."
15+
"format:check": "prettier --check ."
16+
{{/if}}
17+
{{#if eslint}}
18+
"lint": "eslint ."
19+
{{/if}}
20+
{{/list}}
2121
},
2222
"devDependencies": {
23-
{{#list}}
24-
"vite": "^7.1.3"
25-
{{#if isTypescript}}
26-
"typescript": "^5.9.3"
27-
"@types/node": "^25.0.3"
28-
{{#if isReact}}
29-
"@types/react": "^18.3.18"
30-
"@types/react-dom": "^18.3.5"
31-
{{/if}}
32-
{{/if}}
33-
{{#if isReact}}
34-
"@vitejs/plugin-react": "^4.3.4"
35-
{{/if}}
36-
{{#if prettier}}
37-
"prettier": "^3.7.4"
38-
{{/if}}
39-
{{#if eslint}}
40-
"eslint": "^9.39.2"
41-
{{#if isTypescript}}
42-
"typescript-eslint": "^8.51.0"
43-
{{/if}}
44-
{{#if isReact}}
45-
"eslint-plugin-react": "^7.37.3"
46-
"eslint-plugin-react-hooks": "^5.1.0"
47-
{{/if}}
48-
{{/if}}
49-
{{/list}}
23+
{{#list}}
24+
"vite": "^7.1.3"
25+
{{#if typescript}}
26+
"typescript": "^5.9.3"
27+
"@types/node": "^25.0.3"
28+
{{#if react}}
29+
"@types/react": "^18.3.18"
30+
"@types/react-dom": "^18.3.5"
31+
{{/if}}
32+
{{/if}}
33+
{{#if react}}
34+
"@vitejs/plugin-react": "^4.3.4"
35+
{{/if}}
36+
{{#if prettier}}
37+
"prettier": "^3.7.4"
38+
{{/if}}
39+
{{#if eslint}}
40+
"eslint": "^9.39.2"
41+
{{#if typescript}}
42+
"typescript-eslint": "^8.51.0"
43+
{{/if}}
44+
{{#if react}}
45+
"eslint-plugin-react": "^7.37.3"
46+
"eslint-plugin-react-hooks": "^5.1.0"
47+
{{/if}}
48+
{{/if}}
49+
{{/list}}
5050
},
5151
"dependencies": {
52-
{{#list}}
53-
"tinybase": "^6.6.0"
54-
{{#if isReact}}
55-
"react": "^18.3.1"
56-
"react-dom": "^18.3.1"
57-
{{/if}}
58-
{{/list}}
52+
{{#list}}
53+
"tinybase": "^6.6.0"
54+
{{#if react}}
55+
"react": "^18.3.1"
56+
"react-dom": "^18.3.1"
57+
{{/if}}
58+
{{/list}}
5959
}
6060
}

templates/base/tsconfig.json.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"isolatedModules": true,
1111
"moduleDetection": "force",
1212
"noEmit": true,
13-
{{#if isReact}}
13+
{{#if react}}
1414
"jsx": "react-jsx",
1515
{{/if}}
1616
"strict": true,

templates/base/vite.config.js.hbs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
{{#if isReact}}{{addImport "import react from '@vitejs/plugin-react';"}}{{/if}}
21
{{addImport "import {defineConfig} from 'vite';"}}
3-
4-
export default defineConfig({
52
{{#if isReact}}
6-
plugins: [react()],
3+
{{addImport "import react from '@vitejs/plugin-react';"}}
74
{{/if}}
5+
6+
export default defineConfig({
7+
{{#if isReact}}
8+
plugins: [react()],
9+
{{/if}}
810
});

templates/src/App.tsx.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
{{#if isReact}}{{addImport "import {createStore} from 'tinybase';"}}{{/if}}
2-
{{#if isReact}}{{addImport "import {Provider, useValue} from 'tinybase/ui-react';"}}{{/if}}
1+
{{addImport "import {createStore} from 'tinybase';"}}
2+
{{addImport "import {Provider, useValue} from 'tinybase/ui-react';"}}
33

44
const store = createStore().setValue('count', 0);
55

templates/src/index.tsx.hbs

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
11
{{addImport "import './index.css';"}}
22

3-
{{#if isReact}}
4-
{{addImport "import ReactDOM from 'react-dom/client';"}}
5-
{{addImport "import {App} from './App';"}}
3+
{{#if react}}
4+
{{addImport "import ReactDOM from 'react-dom/client';"}}
5+
{{addImport "import {App} from './App';"}}
66

7-
addEventListener('load', () =>
8-
ReactDOM.createRoot(document.getElementById('app')!).render(<App />),
9-
);
10-
11-
{{else}}
12-
{{addImport "import {createStore} from 'tinybase';"}}
13-
14-
const onClick = (id: string, onClick: () => void) =>
15-
document.getElementById(id)!.addEventListener('click', onClick);
16-
17-
const updateJson = (id: string, content: unknown) =>
18-
(document.getElementById(id)!.innerText = JSON.stringify(content, null, 2));
19-
20-
const getRandom = (max = 100) => Math.floor(Math.random() * max);
21-
22-
addEventListener('load', () => {
23-
const store = createStore();
24-
25-
onClick('countButton', () => store.setValue('counter', (value) => value + 1));
26-
onClick('randomButton', () => store.setValue('random', getRandom()));
27-
onClick('addPetButton', () =>
28-
store.addRow('pets', {
29-
name: ['fido', 'felix', 'bubbles', 'lowly', 'polly'][getRandom(5)],
30-
species: store.getRowIds('species')[getRandom(5)],
31-
}),
7+
addEventListener('load', () =>
8+
ReactDOM.createRoot(document.getElementById('app')!).render(<App />),
329
);
3310

34-
store.addValuesListener(() => updateJson('valuesJson', store.getValues()));
35-
store.addTablesListener(() => updateJson('tablesJson', store.getTables()));
36-
37-
store
38-
.setValue('counter', 0)
39-
.setRow('pets', '0', {name: 'fido', species: 'dog'})
40-
.setTable('species', {
41-
dog: {price: 5},
42-
cat: {price: 4},
43-
fish: {price: 2},
44-
worm: {price: 1},
45-
parrot: {price: 3},
46-
});
47-
});
11+
{{else}}
12+
{{addImport "import {createStore} from 'tinybase';"}}
13+
14+
const onClick = (id: string, onClick: () => void) =>
15+
document.getElementById(id)!.addEventListener('click', onClick);
16+
17+
const updateJson = (id: string, content: unknown) =>
18+
(document.getElementById(id)!.innerText = JSON.stringify(content, null, 2));
19+
20+
const getRandom = (max = 100) => Math.floor(Math.random() * max);
21+
22+
addEventListener('load', () => {
23+
const store = createStore();
24+
25+
onClick('countButton', () => store.setValue('counter', (value) => value + 1));
26+
onClick('randomButton', () => store.setValue('random', getRandom()));
27+
onClick('addPetButton', () =>
28+
store.addRow('pets', {
29+
name: ['fido', 'felix', 'bubbles', 'lowly', 'polly'][getRandom(5)],
30+
species: store.getRowIds('species')[getRandom(5)],
31+
}),
32+
);
33+
34+
store.addValuesListener(() => updateJson('valuesJson', store.getValues()));
35+
store.addTablesListener(() => updateJson('tablesJson', store.getTables()));
36+
37+
store
38+
.setValue('counter', 0)
39+
.setRow('pets', '0', {name: 'fido', species: 'dog'})
40+
.setTable('species', {
41+
dog: {price: 5},
42+
cat: {price: 4},
43+
fish: {price: 2},
44+
worm: {price: 1},
45+
parrot: {price: 3},
46+
});
47+
});
4848
{{/if}}

0 commit comments

Comments
 (0)