diff --git a/src/backend/common/util.js b/src/backend/common/util.js index 1fe15032d37b59dcf1891b562766662a5f0cee74..49b36d32763b0df75f6ece06236e4909ffa6b889 100644 --- a/src/backend/common/util.js +++ b/src/backend/common/util.js @@ -4,8 +4,8 @@ import path from 'path'; import fs from 'fs-extra'; import removeMarkdown from 'remove-markdown'; -const execute = (command, cwd, { stdout = process.stdout, stderr = process.stderr } = {}) => new Promise((resolve, reject) => { - const child = child_process.exec(command, { cwd }, (error, stdout, stderr) => { +const execute = (command, { stdout = process.stdout, stderr = process.stderr, ...options } = {}) => new Promise((resolve, reject) => { + const child = child_process.exec(command, options, (error, stdout, stderr) => { if (error) return reject(error.code ? new Error(stderr) : error); resolve(stdout); }); diff --git a/src/backend/controllers/algorithms.js b/src/backend/controllers/algorithms.js index b735bbc9806e67a7d3ac06f33a445560488ddea8..6bac37467aecba8e07a0edc0b907f0e9e6ff6346 100644 --- a/src/backend/controllers/algorithms.js +++ b/src/backend/controllers/algorithms.js @@ -9,8 +9,8 @@ const router = express.Router(); const downloadCategories = () => ( fs.pathExistsSync(hierarchy.path) ? - execute(`git fetch && git reset --hard origin/master`, hierarchy.path) : - execute(`git clone https://github.com/algorithm-visualizer/algorithms.git ${hierarchy.path}`, __dirname) + execute(`git fetch && git reset --hard origin/master`, { cwd: hierarchy.path }) : + execute(`git clone https://github.com/algorithm-visualizer/algorithms.git ${hierarchy.path}`) ).then(() => hierarchy.refresh()); downloadCategories().catch(console.error); diff --git a/src/backend/controllers/tracers.js b/src/backend/controllers/tracers.js index fad3f6a78e9c5b1c949d35abcef847c55725737b..b15ffc4bd169ff7e2945cdbef1e1ffbd4eb80455 100644 --- a/src/backend/controllers/tracers.js +++ b/src/backend/controllers/tracers.js @@ -32,7 +32,7 @@ const trace = lang => (req, res, next) => { `-m=${memoryLimit}m`, '-e ALGORITHM_VISUALIZER=1', builder.imageName, - ].join(' ')).catch(error => { + ].join(' '), { stdout: null, stderr: null }).catch(error => { if (killed) throw new Error('Time Limit Exceeded'); throw error; }).finally(() => clearTimeout(timer)); diff --git a/src/backend/models/Hierarchy.js b/src/backend/models/Hierarchy.js index 2abcd86844ff1f256dfd7766113bc85dc12d89c8..589910e0c9adc9604e6e84c15f7047eb81a4f8b5 100644 --- a/src/backend/models/Hierarchy.js +++ b/src/backend/models/Hierarchy.js @@ -40,19 +40,20 @@ class Hierarchy { cacheContributors(files, commitAuthors) { return Promise.each(files, file => { - return execute(`git --no-pager log --follow --no-merges --format="%H" "${file.path}"`, this.path, { stdout: null }) - .then(stdout => { - const output = stdout.toString().replace(/\n$/, ''); - const shas = output.split('\n').reverse(); - const contributors = []; - for (const sha of shas) { - const author = commitAuthors[sha]; - if (author && !contributors.find(contributor => contributor.login === author.login)) { - contributors.push(author); - } + return execute(`git --no-pager log --follow --no-merges --format="%H" "${file.path}"`, { + cwd: this.path, stdout: null, + }).then(stdout => { + const output = stdout.toString().replace(/\n$/, ''); + const shas = output.split('\n').reverse(); + const contributors = []; + for (const sha of shas) { + const author = commitAuthors[sha]; + if (author && !contributors.find(contributor => contributor.login === author.login)) { + contributors.push(author); } - file.contributors = contributors; - }); + } + file.contributors = contributors; + }); }); } diff --git a/src/backend/tracers/ImageBuilder.js b/src/backend/tracers/ImageBuilder.js index 62ebad28ef2ce4594a9e394d287268fa2ee9332e..e25d7c193e28df6286361ab4cc779819436e5908 100644 --- a/src/backend/tracers/ImageBuilder.js +++ b/src/backend/tracers/ImageBuilder.js @@ -12,7 +12,7 @@ class ImageBuilder { build(release) { const { tag_name } = release; - return execute(`docker build -t ${this.imageName} . --build-arg tag_name=${tag_name}`, this.directory); + return execute(`docker build -t ${this.imageName} . --build-arg tag_name=${tag_name}`, { cwd: this.directory }); } }