Skip to content

Commit 1903929

Browse files
committed
feat: vueform astro vueform ts
1 parent 1b5bbc3 commit 1903929

File tree

8 files changed

+138
-15
lines changed

8 files changed

+138
-15
lines changed

src/files/vueform/astro/vueform/js/tsconfig.json

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { defineConfig } from 'astro/config'
2+
import vue from '@astrojs/vue'
3+
4+
// https://astro.build/config
5+
export default defineConfig({
6+
integrations: [vue({ appEntrypoint: '/src/pages/_app' })],
7+
})
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<template>
2+
<Vueform>
3+
<TextElement name="hello_world" label="Hello" placeholder="World" />
4+
</Vueform>
5+
</template>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { App } from 'vue';
2+
import Vueform from '@vueform/vueform'
3+
4+
export default async (app: App) => {
5+
const vueformConfig = (await import('../../vueform.config')).default
6+
app.use(Vueform, vueformConfig)
7+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
import Layout from '../layouts/Layout.astro';
3+
import TestForm from './../components/TestForm.vue';
4+
---
5+
<style is:global lang="scss">
6+
@import './../styles/style.scss';
7+
</style>
8+
9+
<Layout title="Welcome to Astro.">
10+
<TestForm client:only="vue" />
11+
</Layout>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
@import '@vueform/vueform/themes/vueform/scss/index.scss';
2+
3+
@media (prefers-color-scheme: dark) {
4+
:root, :before, :after, * {
5+
@include vf-dark-vars;
6+
}
7+
}
8+
9+
:root {
10+
color: white;
11+
12+
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
13+
font-synthesis: none;
14+
text-rendering: optimizeLegibility;
15+
-webkit-font-smoothing: antialiased;
16+
-moz-osx-font-smoothing: grayscale;
17+
}
18+
19+
body {
20+
margin: 0;
21+
display: flex;
22+
place-items: center;
23+
min-width: 320px;
24+
min-height: 100vh;
25+
}
26+
27+
form {
28+
max-width: 1280px;
29+
margin: 0 auto;
30+
padding: 2rem;
31+
text-align: center;
32+
}
33+
34+
@media (prefers-color-scheme: light) {
35+
:root {
36+
color: black;
37+
}
38+
39+
html {
40+
background: white;
41+
}
42+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import en from '@vueform/vueform/locales/en'
2+
import theme from '@vueform/vueform/dist/vueform'
3+
import { defineConfig } from '@vueform/vueform'
4+
5+
export default defineConfig({
6+
theme,
7+
locales: { en },
8+
locale: 'en',
9+
})

src/test.js

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* - test different package managers
44
* - think about npm < 6
55
* - get notified if any framework files change
6+
* - exit properly anytime
67
*/
78

89
import { spawn } from 'child_process'
@@ -137,12 +138,6 @@ async function main() {
137138
return
138139
}
139140

140-
const isTs = ['nuxt'].indexOf(framework) !== -1 || ts
141-
const isBuilder = builder === 'builder'
142-
const isTailwind = ['tailwind', 'tailwind-material'].indexOf(theme) !== -1
143-
const isBootstrap = ['bootstrap'].indexOf(theme) !== -1
144-
const isAstro = framework === 'astro'
145-
146141
/**
147142
* Enter project folder
148143
*/
@@ -155,6 +150,17 @@ async function main() {
155150
console.log('Running npm install...')
156151
await runCommand('npm', ['install'])
157152

153+
/**
154+
* Variables
155+
*/
156+
const isAstro = framework === 'astro'
157+
const isTs = await isTypescript(process.cwd(), framework, ts)
158+
const isBuilder = builder === 'builder'
159+
const isTailwind = ['tailwind', 'tailwind-material'].indexOf(theme) !== -1
160+
const isBootstrap = ['bootstrap'].indexOf(theme) !== -1
161+
const sourcePath = path.join(__dirname, 'files', builder, framework, theme, isTs ? 'ts' : 'js')
162+
const targetPath = process.cwd()
163+
158164
/**
159165
* Install Tailwind
160166
*/
@@ -175,11 +181,15 @@ async function main() {
175181
}
176182

177183
/**
178-
* Install Vue in Astro
184+
* Astro updates
179185
*/
180186
if (isAstro) {
187+
// Install Vue in Astro
181188
console.log('Installing Vue...')
182189
await runCommand('npm', ['install', 'vue', '@astrojs/vue'])
190+
191+
// Extend tsconfig.json
192+
await updateAstroTsConfig(process.cwd())
183193
}
184194

185195
/**
@@ -196,8 +206,6 @@ async function main() {
196206
* Copy Vueform files to project directory
197207
*/
198208
console.log(`Copying additional files to ${projectName}...`)
199-
const sourcePath = path.join(__dirname, 'files', builder, framework, theme, isTs ? 'ts' : 'js')
200-
const targetPath = process.cwd()
201209
await copyFilesToProject(sourcePath, targetPath)
202210

203211
console.log('')
@@ -256,6 +264,46 @@ async function directoryExists(path) {
256264
}
257265
}
258266

267+
async function isTypescript(dir, framework, ts) {
268+
switch (framework) {
269+
case 'nuxt':
270+
return true
271+
break
272+
273+
case 'astro':
274+
const tsConfigPath = path.join(dir, 'tsconfig.json')
275+
276+
try {
277+
const tsConfig = await fsExtra.readJson(tsConfigPath)
278+
279+
return tsConfig.extends !== 'astro/tsconfigs/base'
280+
} catch (err) {
281+
console.error('Error reading tsconfig.json:', err)
282+
}
283+
break
284+
285+
default:
286+
return ts
287+
}
288+
}
289+
290+
async function updateAstroTsConfig(dir) {
291+
const tsConfigPath = path.join(dir, 'tsconfig.json')
292+
293+
try {
294+
const tsConfig = await fsExtra.readJson(tsConfigPath)
295+
296+
tsConfig.compilerOptions = {
297+
'jsx': 'preserve'
298+
}
299+
300+
await fsExtra.writeJson(tsConfigPath, tsConfig, { spaces: 2 })
301+
console.log('tsconfig.json has been updated')
302+
} catch (err) {
303+
console.error('Error updating tsconfig.json:', err)
304+
}
305+
}
306+
259307
async function copyFilesToProject(sourceDir, targetDir) {
260308
try {
261309
await fsExtra.copy(sourceDir, targetDir, { overwrite: true })

0 commit comments

Comments
 (0)