@@ -8,7 +8,7 @@ import {getGitUrl, getRepository, getBuildCommands, getWorkspace, getCommitMessa
88export const deploy = async ( branch : string , context : Context ) => {
99 const workDir = path . resolve ( getWorkspace ( ) , '.work' ) ;
1010 const buildDir = path . resolve ( workDir , 'build' ) ;
11- const pushDir = path . resolve ( workDir , 'build ' ) ;
11+ const pushDir = path . resolve ( workDir , 'push ' ) ;
1212 signale . info ( `Deploying branch %s to %s` , branch , getRepository ( context ) ) ;
1313
1414 fs . mkdirSync ( pushDir , { recursive : true } ) ;
@@ -33,6 +33,23 @@ const cloneForBranch = async (pushDir: string, branch: string, context: Context)
3333
3434 const url = getGitUrl ( context ) ;
3535 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 } "` ) ;
3653} ;
3754
3855const config = async ( pushDir : string ) => {
@@ -69,22 +86,9 @@ const cloneForBuild = async (buildDir: string, context: Context) => {
6986
7087const runBuild = async ( buildDir : string ) => {
7188 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- }
8589
8690 const current = process . cwd ( ) ;
87- for ( const command of commands ) {
91+ for ( const command of getBuildCommands ( buildDir ) ) {
8892 await execAsync ( `cd ${ buildDir } && ${ command } ` ) ;
8993 }
9094 await execAsync ( `cd ${ current } ` ) ;
@@ -97,14 +101,13 @@ const copyFiles = async (buildDir: string, pushDir: string) => {
97101} ;
98102
99103const 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 } ` ) ;
102106 exec ( command + ( quiet ? ' > /dev/null 2>&1' : '' ) + ( suppressError ? ' || :' : '' ) , ( error , stdout ) => {
103107 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 } .` ) ) ;
108111 } else {
109112 if ( ! quiet ) console . log ( stdout ) ;
110113 resolve ( stdout ) ;
0 commit comments