@@ -6,53 +6,80 @@ function fromRootPath(...paths) {
6
6
return path . resolve ( process . cwd ( ) , ...paths )
7
7
}
8
8
9
- function backupPath ( ...paths ) {
10
- return path . resolve ( process . cwd ( ) , 'node_modules' , '__tw_cache__' , ...paths )
11
- }
12
-
13
9
function copy ( fromPath , toPath ) {
14
- fs . mkdirSync ( path . dirname ( toPath ) , { recursive : true } )
15
10
fs . copyFileSync ( fromPath , toPath )
16
11
}
17
12
18
13
if ( process . argv . includes ( '--prepare' ) ) {
14
+ if (
15
+ fs . existsSync ( fromRootPath ( 'package.postcss8.json' ) ) ||
16
+ fs . existsSync ( fromRootPath ( 'src' , 'index.postcss8.js' ) )
17
+ ) {
18
+ console . error ( '\n\n[ABORT] Already in PostCSS 7 compatibility mode!\n\n' )
19
+ process . exit ( 1 )
20
+ }
21
+
19
22
const mainPackageJson = require ( '../package.json' )
20
23
const compatPackageJson = require ( '../package.postcss7.json' )
21
24
22
25
// 1. Backup original package.json file
23
- copy ( fromRootPath ( 'package.json' ) , backupPath ( 'package.json' ) )
26
+ copy ( fromRootPath ( 'package.json' ) , fromRootPath ( 'package.postcss8 .json' ) )
24
27
25
- // 2. Backup lib /index.js file
26
- copy ( fromRootPath ( 'lib ' , 'index.js' ) , backupPath ( 'lib ', 'index.js' ) )
28
+ // 2. Backup src /index.js file
29
+ copy ( fromRootPath ( 'src ' , 'index.js' ) , fromRootPath ( 'src ', 'index.postcss8 .js' ) )
27
30
28
- // 3. Use the postcss7 compat file
29
- copy ( fromRootPath ( 'lib ' , 'index.postcss7.js' ) , fromRootPath ( 'lib ' , 'index.js' ) )
31
+ // 3. Use the PostCSS 7 compat file
32
+ copy ( fromRootPath ( 'src ' , 'index.postcss7.js' ) , fromRootPath ( 'src ' , 'index.js' ) )
30
33
31
34
// 4. Deep merge package.json contents
32
35
const packageJson = merge ( { } , mainPackageJson , compatPackageJson )
33
36
34
- // 5. Write package.json with the new contents
37
+ // 5. Remove peerDependencies
38
+ delete packageJson . peerDependencies
39
+
40
+ // 6. Write package.json with the new contents
35
41
fs . writeFileSync ( fromRootPath ( 'package.json' ) , JSON . stringify ( packageJson , null , 2 ) , 'utf8' )
36
42
37
- // 6 . Print some useful information to make publishing easy
43
+ // 7 . Print some useful information to make publishing easy
38
44
console . log ( )
39
45
console . log ( 'You can safely publish `tailwindcss` in PostCSS 7 compatibility mode:\n' )
40
46
console . log (
41
- [ 'npm version' , 'npm publish --tag compat' , 'npm run compat:restore' ]
47
+ [
48
+ // Not necessary, but a quick 'hash', basically the current date/time
49
+ `git checkout -b compat-${ new Date ( )
50
+ . toJSON ( )
51
+ . replace ( / [ - : . T Z ] / g, '' ) // Remove weird characters
52
+ . slice ( 0 , - 3 ) } `, // Remove milliseconds precision
53
+ 'git add .' ,
54
+ 'git commit -m "compat"' ,
55
+ 'npm version' ,
56
+ 'npm publish --tag compat' ,
57
+ 'npm run compat:restore' ,
58
+ ]
42
59
. map ( ( v ) => ` ${ v } ` )
43
60
. join ( '\n' )
44
61
)
45
62
console . log ( )
46
63
} else if ( process . argv . includes ( '--restore' ) ) {
64
+ if (
65
+ ! fs . existsSync ( fromRootPath ( 'package.postcss8.json' ) ) ||
66
+ ! fs . existsSync ( fromRootPath ( 'src' , 'index.postcss8.js' ) )
67
+ ) {
68
+ console . error ( '\n\n[ABORT] Already in latest PostCSS mode!\n\n' )
69
+ process . exit ( 1 )
70
+ }
71
+
47
72
// 1. Restore original package.json file
48
- copy ( backupPath ( 'package.json' ) , fromRootPath ( 'package.json' ) )
49
- fs . unlinkSync ( backupPath ( 'package.json' ) )
73
+ copy ( fromRootPath ( 'package.postcss8.json' ) , fromRootPath ( 'package.json' ) )
74
+
75
+ // 2. Restore src/index.js file
76
+ copy ( fromRootPath ( 'src' , 'index.postcss8.js' ) , fromRootPath ( 'src' , 'index.js' ) )
50
77
51
- // 2. Restore lib/index.js file
52
- copy ( backupPath ( 'lib' , 'index.js' ) , fromRootPath ( 'lib' , 'index.js ') )
53
- fs . unlinkSync ( backupPath ( 'lib ', 'index.js' ) )
78
+ // 3. Cleanup PostCSS 8 related files
79
+ fs . unlinkSync ( fromRootPath ( 'package.postcss8.json ' ) )
80
+ fs . unlinkSync ( fromRootPath ( 'src ', 'index.postcss8 .js' ) )
54
81
55
- // 3 . Done
82
+ // 4 . Done
56
83
console . log ( )
57
84
console . log ( 'Restored from PostCSS 7 mode to latest PostCSS mode!' )
58
85
console . log ( )
0 commit comments