create-vitebook
Advanced tools
Comparing version 0.22.0 to 0.23.0
@@ -81,4 +81,2 @@ #!/usr/bin/env node | ||
console.log(targetDir); | ||
const builder = new ProjectBuilder({ | ||
@@ -223,2 +221,45 @@ targetDir, | ||
if (builder.hasFeature('markdown')) { | ||
let ext = '.js'; | ||
let viteFileContent = builder.dirs.dest.root.readFile('vite.config.js'); | ||
if (viteFileContent.length === 0) { | ||
ext = '.ts'; | ||
viteFileContent = builder.dirs.dest.root.readFile('vite.config.ts'); | ||
} | ||
let frameworkPluginName = '@sveltejs/vite-plugin-svelte'; | ||
let includeStatement = `\n{\n ${kleur.bold( | ||
"extensions: ['.svelte', '.md']", | ||
)}\n}`; | ||
switch (builder.framework) { | ||
case 'vue': | ||
frameworkPluginName = '@vitejs/plugin-vue'; | ||
includeStatement = `\n{\n ${kleur.bold('include: /\\.(md|vue)$/')}\n}`; | ||
break; | ||
case 'preact': | ||
frameworkPluginName = '@preact/preset-vite'; | ||
includeStatement = `\n{\n ${kleur.bold( | ||
'include: /\\.([j|t]sx?|md)$/', | ||
)}\n}`; | ||
break; | ||
} | ||
const hasOwnFrameworkPlugin = viteFileContent.includes(frameworkPluginName); | ||
if (hasOwnFrameworkPlugin) { | ||
console.warn( | ||
kleur.yellow( | ||
`\nDetected ${kleur.bold(frameworkPluginName)} in ${kleur.bold( | ||
`vite.config${ext}`, | ||
)}`, | ||
), | ||
'\n\nTo complete adding markdown support, add the following line to the plugin options:\n', | ||
includeStatement, | ||
'\n\n', | ||
); | ||
} | ||
} | ||
// ------------------------------------------------------------------------------------------- | ||
@@ -225,0 +266,0 @@ // Configuration File |
{ | ||
"name": "create-vitebook", | ||
"version": "0.22.0", | ||
"version": "0.23.0", | ||
"keywords": [ | ||
@@ -5,0 +5,0 @@ "alternative", |
@@ -46,2 +46,10 @@ // @ts-check | ||
* @param {string} filePath | ||
*/ | ||
readFile(filePath) { | ||
const path = this.resolve(filePath); | ||
return fs.existsSync(path) ? fs.readFileSync(path).toString() : ''; | ||
} | ||
/** | ||
* @param {string} filePath | ||
* @param {string} content | ||
@@ -48,0 +56,0 @@ * @param {{ overwrite?: boolean }} [options] |
105045
1884