11#!/usr/bin/env node
2-
32const { execSync } = require ( 'child_process' ) ;
4- const path = require ( 'path' ) ;
3+
54const variablePrefix = 'npm_package_config_deployToGit_' ;
65const fields = [ 'repository' , 'branch' , 'folder' , 'commit' , 'script' , 'user_name' , 'user_email' ] ;
76const cwd = process . cwd ( ) ;
87const config = { } ;
98
10- for ( const field of fields ) {
9+ for ( const field of fields ) {
1110 const configVar = process . env [ `${ variablePrefix } ${ field } ` ] ;
1211
13- if ( ! configVar ) {
12+ if ( ! configVar ) {
1413 throw Error ( `deployOnGit requires "${ field } " field in package config` ) ;
1514 }
1615
1716 config [ field ] = configVar . replace ( / \$ ( [ a - z A - Z 0 - 9 _ ] + ) / g, ( match , envVarName ) => {
1817 const envVar = process . env [ envVarName ] ;
1918
20- if ( ! envVar ) {
21- throw Error ( `Environment variable "${ envVarName } " presented at string "${ configVar } " is missing` )
19+ if ( ! envVar ) {
20+ throw Error ( `Environment variable "${ envVarName } " presented at string "${ configVar } " is missing` ) ;
2221 }
2322
2423 return envVar ;
@@ -32,7 +31,7 @@ execSync(`git clone -b ${config.branch} ${config.repository} ${config.folder} 2>
3231console . log ( `Starting script ${ config . script } ...` ) ;
3332console . log ( execSync ( `${ config . script } ` , { cwd } ) . toString ( 'utf-8' ) ) ;
3433
35- console . log ( ` Configuring and committing...` ) ;
34+ console . log ( ' Configuring and committing...' ) ;
3635execSync ( `
3736 cd ${ config . folder } &&
3837 git config user.email "${ config . user_email } " &&
@@ -41,7 +40,7 @@ execSync(`
4140 git commit --allow-empty -m "${ config . commit } " 2>&1
4241` , { cwd } ) ;
4342
44- console . log ( ` Pushing...` ) ;
43+ console . log ( ' Pushing...' ) ;
4544execSync ( `git push ${ config . repository } ${ config . branch } ` , { cwd } ) ;
4645
4746console . log ( 'Deploying to git is finished.' ) ;
0 commit comments