Skip to content

Commit

Permalink
fix:Skip the configuration file if it exists
Browse files Browse the repository at this point in the history
  • Loading branch information
iamwangqing committed Nov 14, 2024
1 parent 695e471 commit af5df90
Showing 1 changed file with 6 additions and 22 deletions.
28 changes: 6 additions & 22 deletions src/generate/generate_tailwindcss.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { confirm } from '@clack/prompts';
import fs from 'fs-extra';
import path from 'pathe';
import type { Context } from '../types';
Expand Down Expand Up @@ -32,16 +31,8 @@ export default {
const tailwindCSSPath = path.join(cwd, 'src/tailwind.css');

const results = await Promise.all([
writeFileWithConfirmation(
tailwindConfigPath,
tailwindConfig,
'Tailwind config file already exists, do you want to overwrite?',
),
writeFileWithConfirmation(
tailwindCSSPath,
tailwindCSS,
'Tailwind CSS file already exists, do you want to overwrite?',
),
writeFileWithConfirmation(tailwindConfigPath, tailwindConfig),
writeFileWithConfirmation(tailwindCSSPath, tailwindCSS),
]);

results
Expand All @@ -52,19 +43,12 @@ export default {
async function writeFileWithConfirmation(
filePath: string,
content: string,
confirmMessage: string,
): Promise<FileOperationResult> {
if (fs.existsSync(filePath)) {
const shouldOverwrite = await confirm({
message: confirmMessage,
});

if (!shouldOverwrite) {
return {
success: false,
message: `Skipped writing to ${filePath}`,
};
}
return {
success: false,
message: `Skipped writing to ${filePath}`,
};
}

try {
Expand Down

0 comments on commit af5df90

Please sign in to comment.