Skip to content

Commit

Permalink
setup tailwind: Be explicit about cwd
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe committed Jan 18, 2021
1 parent 817e425 commit dab69e8
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions packages/cli/src/commands/setup/tailwind/tailwind.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,30 +143,28 @@ export const handler = async ({ force }) => {
'Tailwindcss config already exists.\nUse --force to override existing config.'
)
} else {
// A gotcha here is that `yarn tailwindcss init` can generate
// tailwind.config.js in either BASE_DIR or BASE_DIR/web, depending
// on what cwd is
await execa('yarn', ['tailwindcss', 'init'])

// When the `yarn tailwindcss init` command is issued a
// tailwind.config.js file will be generated in cwd(). (cwd() will
// be either BASE_DIR or BASE_DIR/web depending on where the user
// runns the command from.) By only passing the filename (and not a
// fully qualified path) to the fs.* commands below node will look
// in cwd() for the file.
const tailwindConfigPathCwd = path.join(process.cwd(), 'tailwind.config.js')

// opt-in to upcoming changes
const config = fs.readFileSync('tailwind.config.js', 'utf-8')
const config = fs.readFileSync(tailwindConfigPathCwd, '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(tailwindConfigPathCwd, 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', tailwindConfigPathWeb)
fs.renameSync(tailwindConfigPathCwd, tailwindConfigPathWeb)
}
},
},
Expand Down

0 comments on commit dab69e8

Please sign in to comment.