Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
tianyazhichiC
algorithm-visualizer
提交
c5aa4f8b
A
algorithm-visualizer
项目概览
tianyazhichiC
/
algorithm-visualizer
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
algorithm-visualizer
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c5aa4f8b
编写于
8月 06, 2018
作者:
J
Jason Park
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move all the compiling/running parts to tracers repository
上级
75308980
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
14 addition
and
57 deletion
+14
-57
bin/temporary_action.js
bin/temporary_action.js
+0
-16
bin/www
bin/www
+0
-0
package.json
package.json
+3
-5
src/backend/controllers/tracers.js
src/backend/controllers/tracers.js
+11
-36
未找到文件。
bin/temporary_action.js
已删除
100644 → 0
浏览文件 @
75308980
const
path
=
require
(
'
path
'
);
const
fs
=
require
(
'
fs
'
);
const
categories
=
fs
.
readdirSync
(
path
.
resolve
(
__dirname
,
'
..
'
,
'
src
'
,
'
backend
'
,
'
public
'
,
'
algorithms
'
));
for
(
const
category
of
categories
)
{
if
(
category
.
startsWith
(
'
.
'
))
continue
;
const
algorithms
=
fs
.
readdirSync
(
path
.
resolve
(
__dirname
,
'
..
'
,
'
src
'
,
'
backend
'
,
'
public
'
,
'
algorithms
'
,
category
));
for
(
const
algorithm
of
algorithms
)
{
if
(
algorithm
.
startsWith
(
'
.
'
))
continue
;
const
dir
=
path
.
resolve
(
__dirname
,
'
..
'
,
'
src
'
,
'
backend
'
,
'
public
'
,
'
algorithms
'
,
category
,
algorithm
);
try
{
fs
.
renameSync
(
path
.
resolve
(
dir
,
'
desc.md
'
),
path
.
resolve
(
dir
,
'
README.md
'
));
}
catch
(
e
)
{
}
}
}
\ No newline at end of file
bin/www
100644 → 100755
浏览文件 @
c5aa4f8b
文件模式从 100644 更改为 100755
package.json
浏览文件 @
c5aa4f8b
...
...
@@ -3,14 +3,12 @@
"version"
:
"2.0.0"
,
"description"
:
"Algorithm Visualizer"
,
"scripts"
:
{
"postinstall"
:
"docker pull openjdk:8 && docker pull gcc:8.1"
,
"dev"
:
"NODE_ENV=development node bin/www"
,
"start"
:
"NODE_ENV=production node bin/www"
,
"dev"
:
"NODE_ENV=development ./bin/www"
,
"start"
:
"NODE_ENV=production ./bin/www"
,
"build"
:
"npm run build:frontend && npm run build:backend"
,
"build:frontend"
:
"NODE_ENV=production node ./node_modules/webpack/bin/webpack --bail --progress --config webpack.frontend.config.js"
,
"build:backend"
:
"NODE_ENV=production node ./node_modules/webpack/bin/webpack --bail --progress --config webpack.backend.config.js"
,
"lint"
:
"./node_modules/.bin/eslint --fix src"
,
"publish"
:
"npm run lint && npm run build && git add . && git commit && git push"
"lint"
:
"./node_modules/.bin/eslint --fix src"
},
"repository"
:
{
"type"
:
"git"
,
...
...
src/backend/controllers/tracers.js
浏览文件 @
c5aa4f8b
...
...
@@ -9,51 +9,36 @@ import { CompileError, RuntimeError } from '/common/error';
const
router
=
express
.
Router
();
const
repoPath
=
path
.
resolve
(
__dirname
,
'
..
'
,
'
public
'
,
'
tracers
'
);
const
getLibsPath
=
(...
args
)
=>
path
.
resolve
(
repoPath
,
'
libs
'
,
...
args
);
const
getCodesPath
=
(...
args
)
=>
path
.
resolve
(
__dirname
,
'
..
'
,
'
public
'
,
'
codes
'
,
...
args
);
const
buildRelease
=
release
=>
(
fs
.
pathExistsSync
(
repoPath
)
?
execute
(
`git fetch && ! git diff-index --quiet
${
release
.
target_commitish
}
`
,
repoPath
)
:
execute
(
`git clone git@github.com:algorithm-visualizer/tracers
${
repoPath
}
`
,
__dirname
)
).
then
(()
=>
execute
(
`git reset --hard
${
release
.
target_commitish
}
&& npm install && npm run build`
,
repoPath
));
).
then
(()
=>
execute
(
`git reset --hard
${
release
.
target_commitish
}
&& npm install && npm run build
&& ./bin/build
`
,
repoPath
));
GitHubApi
.
getLatestRelease
(
'
algorithm-visualizer
'
,
'
tracers
'
).
then
(
buildRelease
);
// TODO: build release when webhooked
const
getJsWorker
=
(
req
,
res
,
next
)
=>
{
res
.
sendFile
(
getLibsPath
(
'
js
'
,
'
tracers.js
'
));
res
.
sendFile
(
path
.
resolve
(
repoPath
,
'
src
'
,
'
languages
'
,
'
js
'
,
'
tracers
'
,
'
build
'
,
'
tracers.js
'
));
};
const
executeInDocker
=
(
imageId
,
ext
,
srcPath
,
command
)
=>
{
// TODO: memory limit + time limit + space limit?
const
libsPath
=
getLibsPath
(
ext
);
const
dockerCommand
=
[
`docker run --rm`
,
'
-w=/usr/judge
'
,
`-v=
${
libsPath
}
:/usr/bin/tracers:ro`
,
`-v=
${
srcPath
}
:/usr/judge:rw`
,
`-e MAX_TRACES=
${
1
e6
}
-e MAX_TRACERS=
${
1
e2
}
`
,
imageId
,
].
join
(
'
'
);
return
execute
(
`
${
dockerCommand
}
${
command
}
`
,
repoPath
,
{
stdout
:
null
,
stderr
:
null
});
};
const
trace
=
({
ext
,
imageId
,
compileCommand
,
runCommand
})
=>
(
req
,
res
,
next
)
=>
{
const
trace
=
lang
=>
(
req
,
res
,
next
)
=>
{
const
{
code
}
=
req
.
body
;
const
src
Path
=
getCodesPath
(
uuid
.
v4
());
fs
.
outputFile
(
path
.
resolve
(
srcPath
,
`Main.
${
ext
}
`
),
code
)
.
then
(()
=>
execute
InDocker
(
imageId
,
ext
,
srcPath
,
compileCommand
)
const
temp
Path
=
getCodesPath
(
uuid
.
v4
());
fs
.
outputFile
(
path
.
resolve
(
tempPath
,
`Main.
${
lang
}
`
),
code
)
.
then
(()
=>
execute
(
`LANG=
${
lang
}
TEMP_PATH=
${
tempPath
}
./bin/compile`
,
repoPath
,
{
stdout
:
null
,
stderr
:
null
}
)
.
catch
(
error
=>
{
throw
new
CompileError
(
error
);
}))
.
then
(()
=>
execute
InDocker
(
imageId
,
ext
,
srcPath
,
runCommand
)
.
then
(()
=>
execute
(
`LANG=
${
lang
}
TEMP_PATH=
${
tempPath
}
./bin/run`
,
repoPath
,
{
stdout
:
null
,
stderr
:
null
}
)
.
catch
(
error
=>
{
throw
new
RuntimeError
(
error
);
}))
.
then
(()
=>
res
.
sendFile
(
path
.
resolve
(
src
Path
,
'
traces.json
'
)))
.
then
(()
=>
res
.
sendFile
(
path
.
resolve
(
temp
Path
,
'
traces.json
'
)))
.
catch
(
next
)
.
finally
(()
=>
fs
.
remove
(
src
Path
));
.
finally
(()
=>
fs
.
remove
(
temp
Path
));
};
...
...
@@ -61,19 +46,9 @@ router.route('/js')
.
get
(
getJsWorker
);
router
.
route
(
'
/java
'
)
.
post
(
trace
({
ext
:
'
java
'
,
imageId
:
'
openjdk:8
'
,
compileCommand
:
'
javac -cp /usr/bin/tracers/tracers.jar Main.java
'
,
runCommand
:
'
java -cp /usr/bin/tracers/tracers.jar:. Main
'
,
}));
.
post
(
trace
(
'
java
'
));
router
.
route
(
'
/cpp
'
)
.
post
(
trace
({
ext
:
'
cpp
'
,
imageId
:
'
gcc:8.1
'
,
compileCommand
:
'
g++ Main.cpp -o Main -O2 -std=c++11 -L/usr/bin/tracers/lib -l:tracers.a -I/usr/bin/tracers/include
'
,
runCommand
:
'
./Main
'
,
}));
.
post
(
trace
(
'
cpp
'
));
export
default
router
;
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录