Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
node-devlop-rest-api
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhouzihao
node-devlop-rest-api
Commits
bb85e2b8
Commit
bb85e2b8
authored
Mar 27, 2020
by
zhouzihao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dev-添加构建部分代码OC
parent
58e43f53
Changes
8
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
544 additions
and
3 deletions
+544
-3
.gitignore
.gitignore
+3
-1
api/buidApi.js
api/buidApi.js
+21
-0
package-lock.json
package-lock.json
+422
-0
package.json
package.json
+3
-1
route.js
route.js
+2
-0
shell/build.js
shell/build.js
+49
-0
shell/java.js
shell/java.js
+23
-0
tools/databaseHelper.js
tools/databaseHelper.js
+21
-1
No files found.
.gitignore
View file @
bb85e2b8
node_modules/
node_modules/
.vscode
.vscode
tmp/
!tmp/*.gitkeep
\ No newline at end of file
api/buidApi.js
0 → 100644
View file @
bb85e2b8
const
buildshell
=
require
(
"
../shell/build
"
);
var
_
=
require
(
'
lodash
'
);
module
.
exports
=
{
build
:
(
req
,
res
)
=>
{
// post请求
(
async
()
=>
{
try
{
var
body
=
req
.
body
;
var
p_id
=
_
.
toInteger
(
body
.
p_id
);
var
env_id
=
_
.
toInteger
(
body
.
env_id
);
var
branch
=
body
.
branch
;
var
version
=
body
.
version
;
var
result
=
await
buildshell
.
build
(
p_id
,
env_id
,
branch
,
version
);
res
.
end
(
result
);
}
catch
(
error
)
{
res
.
end
(
error
);
}
})();
}
}
\ No newline at end of file
package-lock.json
View file @
bb85e2b8
This diff is collapsed.
Click to expand it.
package.json
View file @
bb85e2b8
...
@@ -13,6 +13,8 @@
...
@@ -13,6 +13,8 @@
"
express
"
:
"
^4.14.1
"
,
"
express
"
:
"
^4.14.1
"
,
"
json-sql-builder2
"
:
"
^1.0.24
"
,
"
json-sql-builder2
"
:
"
^1.0.24
"
,
"
lodash
"
:
"
^4.17.15
"
,
"
lodash
"
:
"
^4.17.15
"
,
"
mysql
"
:
"
^2.13.0
"
"
mysql
"
:
"
^2.13.0
"
,
"
execa
"
:
"
^4.0.0
"
,
"
replace-in-file
"
:
"
^5.0.2
"
}
}
}
}
route.js
View file @
bb85e2b8
...
@@ -7,6 +7,7 @@ var projectApi = require("./api/projectApi");
...
@@ -7,6 +7,7 @@ var projectApi = require("./api/projectApi");
var
metaDataApi
=
require
(
"
./api/metaDataApi
"
);
var
metaDataApi
=
require
(
"
./api/metaDataApi
"
);
var
buildLogApi
=
require
(
"
./api/buildLogApi
"
);
var
buildLogApi
=
require
(
"
./api/buildLogApi
"
);
var
configApi
=
require
(
"
./api/configApi
"
);
var
configApi
=
require
(
"
./api/configApi
"
);
var
buildApi
=
require
(
"
./api/buidApi
"
);
app
.
use
(
bodyParser
.
json
());
// to support JSON-encoded bodies
app
.
use
(
bodyParser
.
json
());
// to support JSON-encoded bodies
app
.
use
(
bodyParser
.
urlencoded
({
// to support URL-encoded bodies
app
.
use
(
bodyParser
.
urlencoded
({
// to support URL-encoded bodies
...
@@ -55,5 +56,6 @@ app.post("/config/", configApi.saveConfig);
...
@@ -55,5 +56,6 @@ app.post("/config/", configApi.saveConfig);
// todo build command !!!
// todo build command !!!
app
.
post
(
"
/project/build
"
,
buildApi
.
build
);
module
.
exports
=
app
;
module
.
exports
=
app
;
\ No newline at end of file
shell/build.js
0 → 100644
View file @
bb85e2b8
// 构建
var
_
=
require
(
'
lodash
'
);
var
databaseHelper
=
require
(
"
../tools/databaseHelper
"
)
var
javaBuilder
=
require
(
'
./java
'
);
const
build
=
async
(
p_id
,
env_id
,
branch
,
version
)
=>
{
//获取项目基本信息
var
projectObj
=
await
databaseHelper
.
findOne
(
'
project
'
,
p_id
,
'
p_id
'
);
console
.
log
(
JSON
.
stringify
(
projectObj
));
// 获取构建类型源数据
var
type_id
=
projectObj
.
type
;
var
typeObj
=
await
databaseHelper
.
findOne
(
'
meta_data
'
,
type_id
,
'
type_id
'
);
console
.
log
(
JSON
.
stringify
(
typeObj
));
// 获取环境源数据
var
envObj
=
await
databaseHelper
.
findOne
(
'
env
'
,
env_id
,
'
env_id
'
);
console
.
log
(
JSON
.
stringify
(
envObj
));
// 获取配置数据
var
configList
=
await
databaseHelper
.
listDbByJson
({
p_id
,
env_id
,
},
'
project_config
'
,
"
*
"
);
console
.
log
(
JSON
.
stringify
(
configList
));
// check 检查同一个项目 同一个环境下 构建日志不能存在构建中的数据
var
logs
=
await
databaseHelper
.
listDbByJson
({
p_id
,
env_id
,
success
:
3
},
'
build_log
'
,
"
*
"
);
console
.
log
(
JSON
.
stringify
(
logs
));
if
(
!
_
.
isEmpty
(
logs
))
{
throw
new
Error
(
"
存在正在构建的项目!
"
);
}
switch
(
_
.
lowerCase
(
typeObj
.
name
))
{
case
"
java
"
:
await
javaBuilder
.
buildJava
(
projectObj
,
envObj
,
typeObj
,
configList
);
break
;
default
:
throw
new
Error
(
"
never used type!
"
);
}
}
module
.
exports
=
{
build
,
}
\ No newline at end of file
shell/java.js
0 → 100644
View file @
bb85e2b8
// 处理Java 类型的项目构建
const
execa
=
require
(
'
execa
'
);
const
replace
=
require
(
'
replace-in-file
'
);
/**
* 构建Java项目
* @param {*} projectObj 项目信息
* @param {*} envObj 环境信息
* @param {*} typeObj 构建源数据
* @param {*} configList 配置信息
*/
const
buildJava
=
async
(
projectObj
,
envObj
,
typeObj
,
configList
)
=>
{
//start to buid
// 获取项目源数据
var
projectMetaData
=
JSON
.
parse
(
projectObj
.
meta_data
);
console
.
log
(
JSON
.
stringify
(
projectMetaData
));
// 下载到的地址
}
module
.
exports
=
{
buildJava
,
}
\ No newline at end of file
tools/databaseHelper.js
View file @
bb85e2b8
...
@@ -11,7 +11,7 @@ var saveJsonToDb = (json, table, key) => {
...
@@ -11,7 +11,7 @@ var saveJsonToDb = (json, table, key) => {
return
new
Promise
((
resovle
,
reject
)
=>
{
return
new
Promise
((
resovle
,
reject
)
=>
{
var
sql
=
""
;
var
sql
=
""
;
if
(
_
.
has
(
json
,
key
)
&&
_
.
get
(
json
,
key
,
0
)
>
0
)
{
if
(
_
.
has
(
json
,
key
)
&&
_
.
get
(
json
,
key
,
0
)
>
0
)
{
var
jsonClone
=
Object
.
assign
({},
json
);
var
jsonClone
=
Object
.
assign
({},
json
);
_
.
unset
(
jsonClone
,
key
);
_
.
unset
(
jsonClone
,
key
);
var
where
=
{};
var
where
=
{};
where
[
key
]
=
_
.
get
(
json
,
key
);;
where
[
key
]
=
_
.
get
(
json
,
key
);;
...
@@ -156,9 +156,29 @@ var pagedDbByJson = (json, table, items, key, page = 1, pageSize = 10, orderby =
...
@@ -156,9 +156,29 @@ var pagedDbByJson = (json, table, items, key, page = 1, pageSize = 10, orderby =
});
});
}
}
/**
* 根据主键查询单条数据
*/
var
findOne
=
(
table
,
id
,
key
)
=>
{
return
new
Promise
((
resovle
,
reject
)
=>
{
let
sql
=
`select * from \`
${
table
}
\` where
${
key
}
=
${
id
}
`
;
db
.
query
(
sql
)
.
then
((
row
)
=>
{
if
(
_
.
isEmpty
(
row
))
{
reject
(
"
no data exception!
"
);
}
else
{
resovle
(
row
[
0
]);
}
}).
catch
((
err
)
=>
{
reject
(
JSON
.
stringify
(
err
));
});
});
}
module
.
exports
=
{
module
.
exports
=
{
saveJsonToDb
,
saveJsonToDb
,
listDbByJson
,
listDbByJson
,
countByJson
,
countByJson
,
pagedDbByJson
,
pagedDbByJson
,
findOne
,
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment