11const fs = require ( 'fs' ) ;
2- const path = require ( 'path' ) ;
32
43const filenameTailwind = 'tailwind.config.js' ;
54
@@ -10,17 +9,17 @@ function loadModule(src, filename) {
109 return m . exports ;
1110}
1211
13- function readPostcssConfig ( generator ) {
12+ function readPostcssConfig ( api ) {
1413 const filename = 'postcss.config.js' ;
15- const file = generator . files [ filename ] ;
14+ const file = api . generator . files [ filename ] ;
1615
1716 if ( file ) {
18- const filePath = path . join ( generator . context , filename ) ;
17+ const filePath = api . resolve ( filename ) ;
1918 fs . writeFileSync ( filePath , '' ) ;
2019 return loadModule ( file , filename ) ;
2120 }
2221
23- const config = generator . originalPkg . postcss ;
22+ const config = api . generator . originalPkg . postcss ;
2423 if ( config ) {
2524 const copy = { ...config } ;
2625 delete config . plugins ;
@@ -30,19 +29,22 @@ function readPostcssConfig(generator) {
3029 return { } ;
3130}
3231
33- function generateConfig ( option ) {
32+ function generateConfig ( api , option ) {
3433 const args = [ 'init' ] ;
3534 if ( option === 'full' ) {
3635 args . push ( '--full' ) ;
3736 }
3837 const { spawnSync } = require ( 'child_process' ) ;
39- const tailwind = path . resolve ( './node_modules/.bin/tailwind' ) ;
38+ const tailwind = api . resolve ( './node_modules/.bin/tailwind' ) ;
4039 if ( ! fs . existsSync ( tailwind ) ) throw new Error ( `${ tailwind } not found` ) ;
41- spawnSync ( tailwind , args , { shell : process . platform === 'win32' } ) ;
40+ spawnSync ( tailwind , args , {
41+ cwd : api . generator . context ,
42+ shell : process . platform === 'win32' ,
43+ } ) ;
4244}
4345
44- function injectPurgeConfig ( ctx ) {
45- const configPath = path . join ( ctx , filenameTailwind ) ;
46+ function injectPurgeConfig ( api ) {
47+ const configPath = api . resolve ( filenameTailwind ) ;
4648 const tailwindConfig = fs . readFileSync ( configPath , 'utf-8' ) ;
4749 fs . writeFileSync (
4850 configPath ,
@@ -54,7 +56,7 @@ function injectPurgeConfig(ctx) {
5456}
5557
5658module . exports = ( api , options ) => {
57- const postcss = readPostcssConfig ( api . generator ) ;
59+ const postcss = readPostcssConfig ( api ) ;
5860 const configs = {
5961 dependencies : {
6062 '@tailwindcss/postcss7-compat' : '^2.0.2' ,
@@ -79,7 +81,7 @@ module.exports = (api, options) => {
7981
8082 if ( options . replaceConfig ) {
8183 delete api . generator . files [ filenameTailwind ] ;
82- const configPath = path . join ( api . generator . context , filenameTailwind ) ;
84+ const configPath = api . resolve ( filenameTailwind ) ;
8385 try {
8486 fs . unlinkSync ( configPath ) ;
8587 } catch ( error ) {
@@ -89,8 +91,8 @@ module.exports = (api, options) => {
8991
9092 if ( options . initConfig && options . replaceConfig !== false ) {
9193 api . onCreateComplete ( ( ) => {
92- generateConfig ( options . initConfig ) ;
93- injectPurgeConfig ( api . generator . context ) ;
94+ generateConfig ( api , options . initConfig ) ;
95+ injectPurgeConfig ( api ) ;
9496 } ) ;
9597 }
9698} ;
0 commit comments