Skip to content

Commit

Permalink
Merge pull request #123 from MentorMate/106-vue-query
Browse files Browse the repository at this point in the history
Add support for TanStack Query
  • Loading branch information
Yordan-Ramchev authored Nov 15, 2023
2 parents 2fbb033 + 4f458fa commit a6785c5
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ npx @mentormate/create-vue
* StoryBook - Frontend workshop for building UI components and pages in isolation (<https://storybook.js.org/>)
* SonarQube - The code quality tool for better code (<https://www.sonarsource.com/products/sonarqube/>)
* Husky - Modern native git hooks made easy (<https://typicode.github.io/husky/>)
* TanStack Query - Powerful asynchronous state management (<https://tanstack.com/query/latest>)
* Please submit an <a href="https://github.com/MentorMate/create-vue/issues">issue</a> if you would like to see other features to be supported

## Contribution
Expand Down
28 changes: 24 additions & 4 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ async function init() {
// --cypress
// --nightwatch
// --playwright
// --tanStackQuery
// --force (for force overwriting)
const argv = minimist(process.argv.slice(2), {
alias: {
Expand Down Expand Up @@ -109,7 +110,8 @@ async function init() {
argv.vueUse ??
argv.i18n ??
argv.storybook ??
argv.sonarQube
argv.sonarQube ??
argv.tanStackQuery
) === 'boolean'

let targetDir = argv._[0]
Expand All @@ -131,6 +133,7 @@ async function init() {
needsI18n?: boolean
needsStorybook?: boolean
needsSonarQube?: boolean
needsTanStackQuery?: boolean
} = {}

try {
Expand All @@ -149,6 +152,7 @@ async function init() {
// - Add i18n - internationalization plugin?
// - Add Storybook?
// - Add SonarQube for code coverage?
// - Add TanStack Query - Hooks for fetching, caching and updating asynchronous data?
result = await prompts(
[
{
Expand Down Expand Up @@ -287,6 +291,15 @@ async function init() {
initial: false,
active: 'Yes',
inactive: 'No'
},
{
name: 'needsTanStackQuery',
type: () => (isFeatureFlagsUsed ? null : 'toggle'),
message:
'Add TanStack Query - Hooks for fetching, caching and updating asynchronous data?',
initial: false,
active: 'Yes',
inactive: 'No'
}
],
{
Expand Down Expand Up @@ -314,7 +327,8 @@ async function init() {
needsVueUse = argv.vueUse,
needsI18n = argv.i18n,
needsStorybook = argv.storybook,
needsSonarQube = argv.SneedsSonarQube
needsSonarQube = argv.needsSonarQube,
needsTanStackQuery = argv.needsTanStackQuery
} = result

const { needsE2eTesting } = result
Expand Down Expand Up @@ -414,6 +428,10 @@ async function init() {
render('config/sonarQube')
}

if (needsTanStackQuery) {
render('config/tanStackQuery')
}

// Render ESLint config
// By default ESLint, Prettier and Husky will be added
renderEslint(root, { needsTypeScript, needsCypress, needsCypressCT })
Expand All @@ -432,7 +450,8 @@ async function init() {
generateIndex({
needsPinia,
needsRouter,
needsI18n
needsI18n,
needsTanStackQuery
})
)

Expand Down Expand Up @@ -528,7 +547,8 @@ async function init() {
needsCypressCT,
needsVueUse,
needsI18n,
needsSonarQube
needsSonarQube,
needsTanStackQuery
})
)

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mentormate/create-vue",
"version": "0.2.0",
"version": "0.3.0",
"description": "🛠️ Extended way to start a Vite-powered Vue project",
"type": "module",
"bin": {
Expand Down
5 changes: 5 additions & 0 deletions template/config/tanStackQuery/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"@tanstack/vue-query": "^5.8.3"
}
}
12 changes: 11 additions & 1 deletion utils/generateIndex.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default function generateIndex({ needsPinia, needsRouter, needsI18n }) {
export default function generateIndex({ needsPinia, needsRouter, needsI18n, needsTanStackQuery }) {
let indexFile = `
import './assets/main.css'
import { createApp } from 'vue'`
Expand All @@ -18,6 +18,11 @@ import router from './router'`
import { createI18n } from 'vue-i18n'`
}

if (needsTanStackQuery) {
indexFile += `
import { VueQueryPlugin } from '@tanstack/vue-query'`
}

indexFile += `
import App from './App.vue'
`
Expand Down Expand Up @@ -71,6 +76,11 @@ const i18n = createI18n({
`
}

if (needsTanStackQuery) {
indexFile += `app.use(VueQueryPlugin)
`
}

const mount = `app.mount('#app')`

return (indexFile += mount)
Expand Down
9 changes: 8 additions & 1 deletion utils/generateReadme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export default function generateReadme({
needsVitest,
needsVueUse,
needsI18n,
needsSonarQube
needsSonarQube,
needsTanStackQuery
}) {
const commandFor = (scriptName: string, args?: string) =>
getCommand(packageManager, scriptName, args)
Expand Down Expand Up @@ -189,6 +190,12 @@ ${commandFor('lint')}
### Modern native git hooks made easy [Husky](https://typicode.github.io/husky/)
`

if (needsTanStackQuery) {
npmScriptsDescriptions += `
### Powerful asynchronous state management [TanStack Query](https://tanstack.com/query/latest)
`
}

https: readme += npmScriptsDescriptions

return readme
Expand Down

0 comments on commit a6785c5

Please sign in to comment.