Skip to content

Commit

Permalink
refactor: parse suffix to compile command
Browse files Browse the repository at this point in the history
Signed-off-by: himself65 <himself6565@gmail.com>
  • Loading branch information
himself65 committed Apr 6, 2019
1 parent 3d58412 commit 4fa1bc7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/rrreol-core/src/compiler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { spawn } from 'child_process'
import { isString } from 'lodash'
import { parseFileSuffix } from './utils'
import { empty, isNil, curry } from 'ramda'

export function Compiler () {
Expand All @@ -11,7 +12,7 @@ Compiler.compile = curry(async (path, output) => {
return Promise.reject(new TypeError('path or output is not string'))
}
// fixme: add more command options
const childProcess = spawn('g++', ['-o', output, path])
const childProcess = spawn(parseFileSuffix(path), ['-o', output, path])
return new Promise((resolve, reject) => {
childProcess.on('exit', (code) => {
if (code !== 0) {
Expand Down
8 changes: 5 additions & 3 deletions packages/rrreol-core/src/utils/helpers.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { basename, extname } from 'path'

export const compilerConfig = {
'c': ['gcc', '-pipe'],
'c++': ['g++', '-pipe']
export const compileCommandRule = {
'.cpp': 'g++',
'.c': 'gcc'
}

export const parseFileSuffix = (file) => compileCommandRule[extname(file)] || null

export const getFileName = name => {
const _ = /[\S]+(?=\..+)/.exec(name)
return _ && basename(_[0])
Expand Down

0 comments on commit 4fa1bc7

Please sign in to comment.