Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/swift-spoons-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-rspeedy": patch
---

move Vitest integration to create-rstack extraTools and merge the Vitest templates into a single incremental overlay
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ jobs:
pnpm run build --mode development
pnpm run lint
cd `mktemp -d`
npx --registry http://localhost:4873 create-rspeedy-canary@latest --template react-vitest-rltl --dir create-rspeedy-regression-vitest-rltl --tools eslint
npx --registry http://localhost:4873 create-rspeedy-canary@latest --template react --dir create-rspeedy-regression-vitest-rltl --tools eslint,vitest-rltl
cd create-rspeedy-regression-vitest-rltl
npx --registry http://localhost:4873 upgrade-rspeedy-canary@latest
pnpm install --registry=http://localhost:4873
Expand Down
64 changes: 29 additions & 35 deletions packages/rspeedy/create-rspeedy/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import path from 'node:path'
import { fileURLToPath } from 'node:url'

import type { Argv } from 'create-rstack'
import { checkCancel, create, multiselect, select } from 'create-rstack'
import { checkCancel, copyFolder, create, select } from 'create-rstack'

type LANG = 'js' | 'ts'

Expand All @@ -24,33 +24,31 @@ const { devDependencies } = require('../package.json') as {
interface Template {
template: string
lang: LANG
tools?: Record<string, string> | undefined
}

const composeTemplateName = ({
template,
tools,
lang,
}: {
template: string
tools?: Record<string, string> | undefined
lang: LANG
}) => {
const toolsKeys = (tools ? Object.keys(tools) : []).sort()
const toolsStr = toolsKeys.length > 0 ? `-${toolsKeys.join('-')}` : ''
return `${template}${toolsStr}-${lang}`
return `${template}-${lang}`
}

const TEMPLATES: Template[] = [
{ template: 'react', tools: {}, lang: 'ts' },
{ template: 'react', tools: {}, lang: 'js' },
{ template: 'react', lang: 'ts' },
{ template: 'react', lang: 'js' },
] as const

async function getTemplateName({ template }: Argv) {
if (typeof template === 'string') {
const pair = template.split('-')
const lang = pair[pair.length - 1]
if (lang && ['js', 'ts'].includes(lang)) {
if (pair[0] === 'react') {
return `react-${lang}`
}
return template
}
// default to ts
Expand All @@ -67,46 +65,42 @@ async function getTemplateName({ template }: Argv) {
}),
)

const tools = checkCancel<string[]>(
await multiselect({
message:
'Select development tools (Use <space> to select, <enter> to continue)',
required: false,
options: [
{
value: 'vitest-rltl',
label: 'Add ReactLynx Testing Library for unit testing',
},
],
initialValues: [
'vitest-rltl',
],
}),
)

return composeTemplateName({
template: 'react',
lang: language,
tools: Object.fromEntries(
tools.map((tool) => [tool, tool]),
),
})
}

void create({
root: path.resolve(__dirname, '..'),
name: 'rspeedy',
templates: TEMPLATES.map(({ template, tools, lang }) =>
composeTemplateName({ template, lang, tools })
templates: TEMPLATES.map(({ template, lang }) =>
composeTemplateName({ template, lang })
),
version: devDependencies,
getTemplateName,
extraTools: [
{
value: 'vitest-rltl',
label: 'ReactLynx Testing Library - unit testing',
order: 'pre',
when: (templateName) =>
templateName === 'react-js' || templateName === 'react-ts',
action: ({ distFolder, addAgentsMdSearchDirs }) => {
const from = path.resolve(__dirname, '..', 'template-react-vitest-rltl')
copyFolder({
from,
to: distFolder,
isMergePackageJson: true,
})
addAgentsMdSearchDirs(from)
},
},
],
mapESLintTemplate(templateName) {
const lang = TEMPLATES.find(({ template }) =>
templateName.startsWith(template)
)?.lang
const lang = templateName.split('-').at(-1)

if (!lang) return null
if (lang !== 'js' && lang !== 'ts') return null

switch (lang) {
case 'js':
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading