diff --git a/packages/create-vue-lib/src/index.ts b/packages/create-vue-lib/src/index.ts index 5d773bb..e0cee9b 100644 --- a/packages/create-vue-lib/src/index.ts +++ b/packages/create-vue-lib/src/index.ts @@ -86,6 +86,8 @@ type Config = { includeGithubCi: boolean includeAtAliases: boolean includeTestVariable: boolean + includeTailwind: boolean + includeVpRaw: boolean } type Args = { @@ -263,10 +265,12 @@ async function init() { process.exit(1) } + const includeTailwind = await togglePrompt('Include Tailwind CSS?') const includeEsLint = await togglePrompt('Include ESLint?', true) const includeEsLintStylistic = await togglePromptIf(includeEsLint, 'Include ESLint Stylistic for formatting?', includeEsLint) const includeVitest = await togglePromptIf(extended, 'Include Vitest for testing?', true) const includeDocs = await togglePrompt('Include VitePress for documentation?', true) + const includeVpRaw = includeDocs && await togglePromptIf(extended, 'Include support for vp-raw in VitePress?', includeTailwind) const includeGithubPages = includeDocs && await togglePrompt('Include GitHub Pages config for documentation?') const includePlayground = await togglePrompt('Include playground application for development?', true) const includeGithubCi = await togglePrompt('Include GitHub CI configuration?', !!githubPath) @@ -338,7 +342,9 @@ async function init() { includeVitest, includeGithubCi, includeAtAliases, - includeTestVariable + includeTestVariable, + includeTailwind, + includeVpRaw } copyTemplate('base', config) @@ -367,6 +373,14 @@ async function init() { copyTemplate('ci', config) } + if (config.includeTailwind) { + copyTemplate('tailwind', config) + } + + if (config.includeVpRaw) { + copyTemplate('vp-raw', config) + } + console.log() console.log(`${bgGreen(bold(black('DONE')))} Project created`) console.log() @@ -441,7 +455,10 @@ function copyFiles(templateFile: string, config: Config) { const target = targetPath.replace(/\.ejs$/, '') let content = ejs.render(template, { config }) - if (/\.(json|m?[jt]s)$/.test(target)) { + if (/\.(json|m?[jt]s|vue)$/.test(target)) { + // Ensure there are no blank lines at the start and a single blank line at the end + content = content.trim() + '\n' + // Trim spaces from the ends of lines content = content.replace(/ +\n/g, '\n') @@ -450,6 +467,9 @@ function copyFiles(templateFile: string, config: Config) { // Remove trailing commas and any blank newlines that follow them content = content.replace(/, *(?:\n+(\n\s*)|(\s*))([}\])])/g, '$1$2$3') + + // Trim blank lines after {, [ or ( + content = content.replace(/([{[(]\n)\n+/g, '$1') } fs.writeFileSync(target, content) diff --git a/packages/create-vue-lib/src/template/base/config/packages/@projectName@/package.json.ejs b/packages/create-vue-lib/src/template/base/config/packages/@projectName@/package.json.ejs index 0910f4a..56887b6 100644 --- a/packages/create-vue-lib/src/template/base/config/packages/@projectName@/package.json.ejs +++ b/packages/create-vue-lib/src/template/base/config/packages/@projectName@/package.json.ejs @@ -39,6 +39,9 @@ }, "devDependencies": { "@rollup/plugin-replace": "^6.0.2", + <%_ if (config.includeTailwind) { _%> + "@tailwindcss/vite": "^4.1.5", + <%_ } _%> "@tsconfig/node22": "^22.0.1", "@types/jsdom": "^21.1.7", "@types/node": "^22.13.14", @@ -53,6 +56,9 @@ "npm-run-all2": "^7.0.2", "publint": "^0.3.9", "rimraf": "^5.0.1", + <%_ if (config.includeTailwind) { _%> + "tailwindcss": "^4.1.5", + <%_ } _%> "typescript": "~5.8.0", "vite": "^6.2.4", "vite-plugin-dts": "^4.5.3", diff --git a/packages/create-vue-lib/src/template/base/config/packages/@projectName@/vite.config.mts.ejs b/packages/create-vue-lib/src/template/base/config/packages/@projectName@/vite.config.mts.ejs index 732db18..00df61c 100644 --- a/packages/create-vue-lib/src/template/base/config/packages/@projectName@/vite.config.mts.ejs +++ b/packages/create-vue-lib/src/template/base/config/packages/@projectName@/vite.config.mts.ejs @@ -4,6 +4,9 @@ import { defineConfig, type UserConfig } from 'vite' import replace from '@rollup/plugin-replace' import vue from '@vitejs/plugin-vue' import dts from 'vite-plugin-dts' +<%_ if (config.includeTailwind) { _%> +import tailwindcss from '@tailwindcss/vite' +<%_ } _%> export default defineConfig(({ mode }): UserConfig => { if (mode !== 'production' && mode !== 'development' && mode !== 'neutral' && mode !== 'test') { @@ -38,6 +41,9 @@ export default defineConfig(({ mode }): UserConfig => { prodDevtools: mode === 'development' } }), + <%_ if (config.includeTailwind) { _%> + tailwindcss(), + <%_ } _%> dtsPlugin ], diff --git a/packages/create-vue-lib/src/template/base/examples/packages/@projectName@/src/components/ExampleComponent.vue.ejs b/packages/create-vue-lib/src/template/base/examples/packages/@projectName@/src/components/ExampleComponent.vue.ejs index 5f25c65..d1bac35 100644 --- a/packages/create-vue-lib/src/template/base/examples/packages/@projectName@/src/components/ExampleComponent.vue.ejs +++ b/packages/create-vue-lib/src/template/base/examples/packages/@projectName@/src/components/ExampleComponent.vue.ejs @@ -9,12 +9,13 @@ const msg = ref('Hello world!') +<%_ if (!config.includeTailwind) { _%> +<%_ } _%> diff --git a/packages/create-vue-lib/src/template/base/examples/packages/@projectName@/src/components/MyPanel.vue b/packages/create-vue-lib/src/template/base/examples/packages/@projectName@/src/components/MyPanel.vue.ejs similarity index 57% rename from packages/create-vue-lib/src/template/base/examples/packages/@projectName@/src/components/MyPanel.vue rename to packages/create-vue-lib/src/template/base/examples/packages/@projectName@/src/components/MyPanel.vue.ejs index 19a47bf..29d4523 100644 --- a/packages/create-vue-lib/src/template/base/examples/packages/@projectName@/src/components/MyPanel.vue +++ b/packages/create-vue-lib/src/template/base/examples/packages/@projectName@/src/components/MyPanel.vue.ejs @@ -13,21 +13,22 @@ if (__DEV__) { +<%_ if (!config.includeTailwind) { _%> +<%_ } _%> diff --git a/packages/create-vue-lib/src/template/base/examples/packages/@projectName@/src/components/MyPanelSection.vue.ejs b/packages/create-vue-lib/src/template/base/examples/packages/@projectName@/src/components/MyPanelSection.vue.ejs index 2415c4d..d358418 100644 --- a/packages/create-vue-lib/src/template/base/examples/packages/@projectName@/src/components/MyPanelSection.vue.ejs +++ b/packages/create-vue-lib/src/template/base/examples/packages/@projectName@/src/components/MyPanelSection.vue.ejs @@ -13,13 +13,15 @@ if (__DEV__) { +<%_ if (!config.includeTailwind) { _%> +<%_ } _%> diff --git a/packages/create-vue-lib/src/template/base/examples/packages/@projectName@/src/index.ts.ejs b/packages/create-vue-lib/src/template/base/examples/packages/@projectName@/src/index.ts.ejs index 131ab87..3612f7d 100644 --- a/packages/create-vue-lib/src/template/base/examples/packages/@projectName@/src/index.ts.ejs +++ b/packages/create-vue-lib/src/template/base/examples/packages/@projectName@/src/index.ts.ejs @@ -1,3 +1,7 @@ +<%_ if (config.includeTailwind) { _%> +import './index.css' + +<%_ } _%> export { default as ExampleComponent } from './components/ExampleComponent.vue' export { default as MyPanel } from './components/MyPanel.vue' export { default as MyPanelSection } from './components/MyPanelSection.vue' diff --git a/packages/create-vue-lib/src/template/playground/config/packages/playground/package.json b/packages/create-vue-lib/src/template/playground/config/packages/playground/package.json.ejs similarity index 79% rename from packages/create-vue-lib/src/template/playground/config/packages/playground/package.json rename to packages/create-vue-lib/src/template/playground/config/packages/playground/package.json.ejs index a5c126f..65174d2 100644 --- a/packages/create-vue-lib/src/template/playground/config/packages/playground/package.json +++ b/packages/create-vue-lib/src/template/playground/config/packages/playground/package.json.ejs @@ -5,12 +5,18 @@ "vue": "^3.5.13" }, "devDependencies": { + <%_ if (config.includeTailwind) { _%> + "@tailwindcss/vite": "^4.1.5", + <%_ } _%> "@tsconfig/node22": "^22.0.1", "@types/node": "^22.13.14", "@vitejs/plugin-vue": "^5.2.3", "@vue/tsconfig": "^0.7.0", "npm-run-all2": "^7.0.2", "rimraf": "^5.0.1", + <%_ if (config.includeTailwind) { _%> + "tailwindcss": "^4.1.5", + <%_ } _%> "typescript": "~5.8.0", "vite": "^6.2.4", "vite-plugin-vue-devtools": "^7.7.2", diff --git a/packages/create-vue-lib/src/template/playground/config/packages/playground/vite.config.mts.ejs b/packages/create-vue-lib/src/template/playground/config/packages/playground/vite.config.mts.ejs index d1515d6..78ecf26 100644 --- a/packages/create-vue-lib/src/template/playground/config/packages/playground/vite.config.mts.ejs +++ b/packages/create-vue-lib/src/template/playground/config/packages/playground/vite.config.mts.ejs @@ -3,6 +3,9 @@ import { fileURLToPath, URL } from 'node:url' import { defineConfig, type UserConfig } from 'vite' import vue from '@vitejs/plugin-vue' import vueDevTools from 'vite-plugin-vue-devtools' +<%_ if (config.includeTailwind) { _%> +import tailwindcss from '@tailwindcss/vite' +<%_ } _%> <%_ if (config.includeAtAliases) { _%> const librarySrc = fileURLToPath(new URL('../<%- config.mainPackageDirName %>/src/', import.meta.url)) @@ -12,6 +15,9 @@ const playgroundSrc = fileURLToPath(new URL('./src/', import.meta.url)) export default defineConfig(({ mode }): UserConfig => ({ plugins: [ vue(), + <%_ if (config.includeTailwind) { _%> + tailwindcss(), + <%_ } _%> vueDevTools() ], diff --git a/packages/create-vue-lib/src/template/playground/examples/packages/playground/src/App.vue b/packages/create-vue-lib/src/template/playground/examples/packages/playground/src/App.vue.ejs similarity index 68% rename from packages/create-vue-lib/src/template/playground/examples/packages/playground/src/App.vue rename to packages/create-vue-lib/src/template/playground/examples/packages/playground/src/App.vue.ejs index 0c7653d..7aa9e40 100644 --- a/packages/create-vue-lib/src/template/playground/examples/packages/playground/src/App.vue +++ b/packages/create-vue-lib/src/template/playground/examples/packages/playground/src/App.vue.ejs @@ -1,9 +1,9 @@ +<%_ if (!config.includeTailwind) { _%> +<%_ } _%> diff --git a/packages/create-vue-lib/src/template/tailwind/examples/packages/@projectName@/src/index.css b/packages/create-vue-lib/src/template/tailwind/examples/packages/@projectName@/src/index.css new file mode 100644 index 0000000..a41506c --- /dev/null +++ b/packages/create-vue-lib/src/template/tailwind/examples/packages/@projectName@/src/index.css @@ -0,0 +1,3 @@ +@import "tailwindcss"; + +@source "."; diff --git a/packages/create-vue-lib/src/template/vitepress/config/packages/docs/.vitepress/config.mts.ejs b/packages/create-vue-lib/src/template/vitepress/config/packages/docs/.vitepress/config.mts.ejs index a1efdc4..96ad028 100644 --- a/packages/create-vue-lib/src/template/vitepress/config/packages/docs/.vitepress/config.mts.ejs +++ b/packages/create-vue-lib/src/template/vitepress/config/packages/docs/.vitepress/config.mts.ejs @@ -1,6 +1,9 @@ import { fileURLToPath, URL } from 'node:url' import { defineConfigWithTheme } from 'vitepress' +<%_ if (config.includeTailwind) { _%> +import tailwindcss from '@tailwindcss/vite' +<%_ } _%> <%_ if (config.includeAtAliases) { _%> const librarySrc = fileURLToPath(new URL('../../<%- config.mainPackageDirName %>/src/', import.meta.url)) @@ -34,6 +37,12 @@ export default ({ mode }: { mode: string }) => defineConfigWithTheme({ <%_ } _%> vite: { + <%_ if (config.includeTailwind) { _%> + plugins: [ + tailwindcss() + ], + <%_ } _%> + resolve: { <%_ if (config.includeAtAliases) { _%> alias: [ diff --git a/packages/create-vue-lib/src/template/vitepress/config/packages/docs/package.json b/packages/create-vue-lib/src/template/vitepress/config/packages/docs/package.json.ejs similarity index 75% rename from packages/create-vue-lib/src/template/vitepress/config/packages/docs/package.json rename to packages/create-vue-lib/src/template/vitepress/config/packages/docs/package.json.ejs index 0e669d7..ff30957 100644 --- a/packages/create-vue-lib/src/template/vitepress/config/packages/docs/package.json +++ b/packages/create-vue-lib/src/template/vitepress/config/packages/docs/package.json.ejs @@ -5,11 +5,20 @@ "vue": "^3.5.13" }, "devDependencies": { + <%_ if (config.includeTailwind) { _%> + "@tailwindcss/vite": "^4.1.5", + <%_ } _%> "@tsconfig/node22": "^22.0.1", "@types/node": "^22.13.14", "@vue/tsconfig": "^0.7.0", "npm-run-all2": "^7.0.2", + <%_ if (config.includeVpRaw) { _%> + "postcss": "^8.5.3", + <%_ } _%> "rimraf": "^5.0.1", + <%_ if (config.includeTailwind) { _%> + "tailwindcss": "^4.1.5", + <%_ } _%> "typescript": "~5.8.0", "vitepress": "^1.6.3", "vue-tsc": "^2.2.8" diff --git a/packages/create-vue-lib/src/template/vitepress/examples/packages/docs/src/introduction.md b/packages/create-vue-lib/src/template/vitepress/examples/packages/docs/src/introduction.md.ejs similarity index 67% rename from packages/create-vue-lib/src/template/vitepress/examples/packages/docs/src/introduction.md rename to packages/create-vue-lib/src/template/vitepress/examples/packages/docs/src/introduction.md.ejs index 63bbb69..78b443a 100644 --- a/packages/create-vue-lib/src/template/vitepress/examples/packages/docs/src/introduction.md +++ b/packages/create-vue-lib/src/template/vitepress/examples/packages/docs/src/introduction.md.ejs @@ -1,5 +1,5 @@