@@ -8,7 +8,7 @@ import {getGitUrl, getRepository, getBuildCommands, getWorkspace, getCommitMessa
8
8
export const deploy = async ( branch : string , context : Context ) => {
9
9
const workDir = path . resolve ( getWorkspace ( ) , '.work' ) ;
10
10
const buildDir = path . resolve ( workDir , 'build' ) ;
11
- const pushDir = path . resolve ( workDir , 'build ' ) ;
11
+ const pushDir = path . resolve ( workDir , 'push ' ) ;
12
12
signale . info ( `Deploying branch %s to %s` , branch , getRepository ( context ) ) ;
13
13
14
14
fs . mkdirSync ( pushDir , { recursive : true } ) ;
@@ -33,6 +33,23 @@ const cloneForBranch = async (pushDir: string, branch: string, context: Context)
33
33
34
34
const url = getGitUrl ( context ) ;
35
35
await execAsync ( `git -C ${ pushDir } clone --quiet --branch=${ branch } --depth=1 ${ url } .` , true , 'git clone' , true ) ;
36
+ if ( ! fs . existsSync ( path . resolve ( pushDir , '.git' ) ) ) {
37
+ await gitInit ( pushDir ) ;
38
+ await gitCheckout ( pushDir , branch ) ;
39
+ }
40
+ } ;
41
+
42
+ const gitInit = async ( pushDir : string ) => {
43
+ signale . info ( 'Initializing local git repo' ) ;
44
+
45
+ await execAsync ( `git -C ${ pushDir } init .` ) ;
46
+
47
+ } ;
48
+
49
+ const gitCheckout = async ( pushDir : string , branch : string ) => {
50
+ signale . info ( 'Checking out orphan branch %s' , branch ) ;
51
+
52
+ await execAsync ( `git -C ${ pushDir } checkout --orphan "${ branch } "` ) ;
36
53
} ;
37
54
38
55
const config = async ( pushDir : string ) => {
@@ -69,22 +86,9 @@ const cloneForBuild = async (buildDir: string, context: Context) => {
69
86
70
87
const runBuild = async ( buildDir : string ) => {
71
88
signale . info ( '=== Running build for release ===' ) ;
72
- let commands = getBuildCommands ( ) ;
73
- const buildCommand = detectBuildCommand ( buildDir ) ;
74
- const hasInstallCommand = commands . filter ( command => command . includes ( 'npm run install' ) || command . includes ( 'yarn install' ) ) . length > 0 ;
75
- if ( ! hasInstallCommand ) {
76
- commands . push ( 'yarn install' ) ;
77
- }
78
- if ( typeof buildCommand === 'string' ) {
79
- commands = commands . filter ( command => ! buildCommand . startsWith ( `npm run ${ command } ` ) && ! buildCommand . startsWith ( `yarn ${ command } ` ) ) ;
80
- commands . push ( `yarn ${ buildCommand } ` ) ;
81
- }
82
- if ( ! hasInstallCommand ) {
83
- commands . push ( 'yarn install --production' ) ;
84
- }
85
89
86
90
const current = process . cwd ( ) ;
87
- for ( const command of commands ) {
91
+ for ( const command of getBuildCommands ( buildDir ) ) {
88
92
await execAsync ( `cd ${ buildDir } && ${ command } ` ) ;
89
93
}
90
94
await execAsync ( `cd ${ current } ` ) ;
@@ -97,14 +101,13 @@ const copyFiles = async (buildDir: string, pushDir: string) => {
97
101
} ;
98
102
99
103
const execAsync = ( command : string , quiet : boolean = false , altCommand : string | null = null , suppressError : boolean = false ) => new Promise < string > ( ( resolve , reject ) => {
100
- if ( quiet && 'string' === typeof altCommand ) signale . info ( `Run command: ${ altCommand } ` ) ;
101
- if ( ! quiet ) signale . info ( `Run command: ${ command } ` ) ;
104
+ if ( 'string' === typeof altCommand ) signale . info ( `Run command: ${ altCommand } ` ) ;
105
+ else if ( ! quiet ) signale . info ( `Run command: ${ command } ` ) ;
102
106
exec ( command + ( quiet ? ' > /dev/null 2>&1' : '' ) + ( suppressError ? ' || :' : '' ) , ( error , stdout ) => {
103
107
if ( error ) {
104
- if ( quiet ) {
105
- if ( 'string' === typeof altCommand ) reject ( new Error ( `command [${ altCommand } ] exited with code ${ error . code } .` ) ) ;
106
- else reject ( new Error ( `command exited with code ${ error . code } .` ) ) ;
107
- } else reject ( new Error ( `command [${ command } ] exited with code ${ error . code } .` ) ) ;
108
+ if ( 'string' === typeof altCommand ) reject ( new Error ( `command [${ altCommand } ] exited with code ${ error . code } .` ) ) ;
109
+ else if ( ! quiet ) reject ( new Error ( `command [${ command } ] exited with code ${ error . code } .` ) ) ;
110
+ else reject ( new Error ( `command exited with code ${ error . code } .` ) ) ;
108
111
} else {
109
112
if ( ! quiet ) console . log ( stdout ) ;
110
113
resolve ( stdout ) ;
0 commit comments