From 6cf9434f6d59dceee05b5d5bd8484b6c9d5b1011 Mon Sep 17 00:00:00 2001 From: Jason Park Date: Fri, 18 Jan 2019 11:51:33 -0500 Subject: [PATCH] Quiet tracers --- src/backend/common/util.js | 4 ++-- src/backend/controllers/algorithms.js | 4 ++-- src/backend/controllers/tracers.js | 2 +- src/backend/models/Hierarchy.js | 25 +++++++++++++------------ src/backend/tracers/ImageBuilder.js | 2 +- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/backend/common/util.js b/src/backend/common/util.js index 1fe1503..49b36d3 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 b735bbc..6bac374 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 fad3f6a..b15ffc4 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 2abcd86..589910e 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 62ebad2..e25d7c1 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 }); } } -- GitLab