@@ -14,20 +14,28 @@ const ASSETS = ['README.md', 'LICENSE', 'package.json', '.npmignore'];
14
14
const ENTRY_POINTS = [ 'main' , 'module' , 'types' ] ;
15
15
16
16
// check if build dir exists
17
- if ( ! fs . existsSync ( path . resolve ( BUILD_DIR ) ) ) {
18
- console . error ( `Directory ${ BUILD_DIR } DOES NOT exist` ) ;
19
- console . error ( "This script should only be executed after you've run `yarn build`." ) ;
20
- process . exit ( 1 ) ;
17
+ try {
18
+ if ( ! fs . existsSync ( path . resolve ( BUILD_DIR ) ) ) {
19
+ console . error ( `Directory ${ BUILD_DIR } DOES NOT exist` ) ;
20
+ console . error ( "This script should only be executed after you've run `yarn build`." ) ;
21
+ process . exit ( 1 ) ;
22
+ }
23
+ } catch ( error ) {
24
+ console . error ( `Error while looking up directory ${ BUILD_DIR } ` ) ;
21
25
}
22
26
23
27
// copy non-code assets to build dir
24
28
ASSETS . forEach ( asset => {
25
29
const assetPath = path . resolve ( asset ) ;
26
- if ( ! fs . existsSync ( assetPath ) ) {
27
- console . error ( `Asset ${ asset } does not exist.` ) ;
28
- process . exit ( 1 ) ;
30
+ try {
31
+ if ( ! fs . existsSync ( assetPath ) ) {
32
+ console . error ( `Asset ${ asset } does not exist.` ) ;
33
+ process . exit ( 1 ) ;
34
+ }
35
+ fs . copyFileSync ( assetPath , path . resolve ( BUILD_DIR , asset ) ) ;
36
+ } catch ( error ) {
37
+ console . error ( `Error while copying ${ asset } to ${ BUILD_DIR } ` ) ;
29
38
}
30
- fs . copyFileSync ( assetPath , path . resolve ( BUILD_DIR , asset ) ) ;
31
39
} ) ;
32
40
33
41
// package.json modifications
@@ -44,6 +52,10 @@ delete pkgJson.scripts;
44
52
delete pkgJson . volta ;
45
53
46
54
// write modified package.json to file (pretty-printed with 2 spaces)
47
- fs . writeFileSync ( packageJsonPath , JSON . stringify ( pkgJson , null , 2 ) ) ;
55
+ try {
56
+ fs . writeFileSync ( packageJsonPath , JSON . stringify ( pkgJson , null , 2 ) ) ;
57
+ } catch ( error ) {
58
+ console . error ( `Error while writing package.json to disk` ) ;
59
+ }
48
60
49
61
console . log ( `\nSuccessfully finished postbuild commands for ${ pkgJson . name } ` ) ;
0 commit comments