1
+ /* eslint-disable no-console */
2
+ const execa = require ( "execa" ) ;
3
+ const fs = require ( "fs" ) ;
4
+ ( async ( ) => {
5
+ try {
6
+ await execa ( "git" , [ "checkout" , "--orphan" , "gh-pages" ] ) ;
7
+ // eslint-disable-next-line no-console
8
+ console . log ( "Building started..." ) ;
9
+ await execa ( "npm" , [ "run" , "build" ] ) ;
10
+ // Understand if it's dist or build folder
11
+ const folderName = fs . existsSync ( "dist" ) ? "dist" : "build" ;
12
+ await execa ( "git" , [ "--work-tree" , folderName , "add" , "--all" ] ) ;
13
+ await execa ( "git" , [ "--work-tree" , folderName , "commit" , "-m" , "gh-pages" ] ) ;
14
+ console . log ( "Pushing to gh-pages..." ) ;
15
+ await execa ( "git" , [ "push" , "origin" , "HEAD:gh-pages" , "--force" ] ) ;
16
+ await execa ( "rm" , [ "-r" , folderName ] ) ;
17
+ await execa ( "git" , [ "checkout" , "-f" , "master" ] ) ;
18
+ await execa ( "git" , [ "branch" , "-D" , "gh-pages" ] ) ;
19
+ console . log ( "Successfully deployed, check your settings" ) ;
20
+ } catch ( e ) {
21
+ // eslint-disable-next-line no-console
22
+ console . log ( e . message ) ;
23
+ process . exit ( 1 ) ;
24
+ }
25
+ } ) ( ) ;
0 commit comments