Skip to content

Commit

Permalink
♻️ Move exec function to helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
BetaHuhn committed Mar 7, 2021
1 parent 5e590a1 commit 1e8745f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 36 deletions.
38 changes: 20 additions & 18 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30369,7 +30369,6 @@ module.exports = {
/***/ 109:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {

const { exec } = __nccwpck_require__(3129)
const { parse } = __nccwpck_require__(1150)
const core = __nccwpck_require__(2186)
const path = __nccwpck_require__(5622)
Expand All @@ -30384,7 +30383,7 @@ const {
OVERWRITE_EXISTING_PR
} = __nccwpck_require__(4570)

const { dedent } = __nccwpck_require__(8505)
const { dedent, execCmd } = __nccwpck_require__(8505)

const init = (repo) => {
let github
Expand Down Expand Up @@ -30576,21 +30575,6 @@ const init = (repo) => {
}
}

const execCmd = (command, workingDir) => {
core.debug(`EXEC: "${ command }" IN ${ workingDir }`)
return new Promise((resolve, reject) => {
exec(
command,
{
cwd: workingDir
},
function(error, stdout) {
error ? reject(error) : resolve(stdout.trim())
}
)
})
}

module.exports = {
init
}
Expand All @@ -30601,6 +30585,8 @@ module.exports = {
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {

const fs = __nccwpck_require__(5747)
const { exec } = __nccwpck_require__(3129)
const core = __nccwpck_require__(2186)

// From https://github.com/toniov/p-iteration/blob/master/lib/static-methods.js - MIT © Antonio V
const forEach = async (array, callback) => {
Expand Down Expand Up @@ -30637,6 +30623,21 @@ const dedent = function(templateStrings, ...values) {
return string
}

const execCmd = (command, workingDir) => {
core.debug(`EXEC: "${ command }" IN ${ workingDir }`)
return new Promise((resolve, reject) => {
exec(
command,
{
cwd: workingDir
},
function(error, stdout) {
error ? reject(error) : resolve(stdout.trim())
}
)
})
}

const addTrailingSlash = (str) => str.endsWith('/') ? str : str + '/'

const pathIsDirectory = async (path) => {
Expand All @@ -30648,7 +30649,8 @@ module.exports = {
forEach,
dedent,
addTrailingSlash,
pathIsDirectory
pathIsDirectory,
execCmd
}

/***/ }),
Expand Down
18 changes: 1 addition & 17 deletions src/git.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const { exec } = require('child_process')
const { parse } = require('@putout/git-status-porcelain')
const core = require('@actions/core')
const path = require('path')
Expand All @@ -13,7 +12,7 @@ const {
OVERWRITE_EXISTING_PR
} = require('./config')

const { dedent } = require('./helpers')
const { dedent, execCmd } = require('./helpers')

const init = (repo) => {
let github
Expand Down Expand Up @@ -205,21 +204,6 @@ const init = (repo) => {
}
}

const execCmd = (command, workingDir) => {
core.debug(`EXEC: "${ command }" IN ${ workingDir }`)
return new Promise((resolve, reject) => {
exec(
command,
{
cwd: workingDir
},
function(error, stdout) {
error ? reject(error) : resolve(stdout.trim())
}
)
})
}

module.exports = {
init
}
20 changes: 19 additions & 1 deletion src/helpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const fs = require('fs')
const { exec } = require('child_process')
const core = require('@actions/core')

// From https://github.com/toniov/p-iteration/blob/master/lib/static-methods.js - MIT © Antonio V
const forEach = async (array, callback) => {
Expand Down Expand Up @@ -35,6 +37,21 @@ const dedent = function(templateStrings, ...values) {
return string
}

const execCmd = (command, workingDir) => {
core.debug(`EXEC: "${ command }" IN ${ workingDir }`)
return new Promise((resolve, reject) => {
exec(
command,
{
cwd: workingDir
},
function(error, stdout) {
error ? reject(error) : resolve(stdout.trim())
}
)
})
}

const addTrailingSlash = (str) => str.endsWith('/') ? str : str + '/'

const pathIsDirectory = async (path) => {
Expand All @@ -46,5 +63,6 @@ module.exports = {
forEach,
dedent,
addTrailingSlash,
pathIsDirectory
pathIsDirectory,
execCmd
}

0 comments on commit 1e8745f

Please sign in to comment.