Skip to content

Commit

Permalink
Tailwind Setup: Use fully specified paths
Browse files Browse the repository at this point in the history
Fixes #1643
  • Loading branch information
Tobbe committed Jan 17, 2021
1 parent d427179 commit 1f12f1d
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions packages/cli/src/commands/setup/tailwind/tailwind.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,36 +128,56 @@ export const handler = async ({ force }) => {
{
title: 'Initializing Tailwind CSS...',
task: async () => {
console.log('cwd', process.cwd());
console.log('__dirname', __dirname);
// Depending on where the users stands when setting up tailwind the
// config file can end up in two different places: BASE_DIR or
// BASE_DIR/web.
const tailwindConfigPathWeb = path.join(
getPaths().web.base,
'tailwind.config.js'
)
const tailwindConfigPathBase = path.join(
getPaths().base,
'tailwind.config.js'
)
const configExists = fs.existsSync(tailwindConfigPathWeb)

/**
* If it doesn't already exist,
* initialize tailwind and move tailwind.config.js to web/
*/
const configExists = fs.existsSync(
path.join(getPaths().web.base, 'tailwind.config.js')
)

if (!force && configExists) {
throw new Error(
'Tailwindcss config already exists.\nUse --force to override existing config.'
)
} else {
await execa('yarn', ['tailwindcss', 'init'])

const generatedTailwindConfigPath = fs.existsSync(
tailwindConfigPathBase
)
? tailwindConfigPathBase
: tailwindConfigPathWeb

// opt-in to upcoming changes
const config = fs.readFileSync('tailwind.config.js', 'utf-8')
const config = fs.readFileSync(generatedTailwindConfigPath, 'utf-8')

const uncommentFlags = (str) =>
str.replace(/\/{2} ([\w-]+: true)/g, '$1')

const newConfig = config.replace(/future.*purge/s, uncommentFlags)

fs.writeFileSync('tailwind.config.js', newConfig)
fs.writeFileSync(generatedTailwindConfigPath, newConfig)

/**
* Later, when we can tell the vscode extension where to look for the config,
* we can put it in web/config/
*/
fs.renameSync('tailwind.config.js', 'web/tailwind.config.js')
fs.renameSync(
generatedTailwindConfigPath,
tailwindConfigPathWeb
)
}
},
},
Expand Down

0 comments on commit 1f12f1d

Please sign in to comment.