Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qg-cli
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
ui
qg-cli
Commits
a448b51a
Commit
a448b51a
authored
Nov 20, 2020
by
郝聪敏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feature: 新增block下载功能
parent
ae804575
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
205 additions
and
9 deletions
+205
-9
block.js
dist/block.js
+87
-0
main.js
dist/main.js
+8
-2
constants.js
dist/utils/constants.js
+6
-5
get.js
dist/utils/get.js
+23
-1
block.js
src/block.js
+53
-0
main.js
src/main.js
+10
-0
constants.js
src/utils/constants.js
+2
-1
get.js
src/utils/get.js
+16
-0
No files found.
dist/block.js
0 → 100644
View file @
a448b51a
'
use strict
'
;
var
_get
=
require
(
'
./utils/get
'
);
var
_rc
=
require
(
'
./utils/rc
'
);
var
_ora
=
require
(
'
ora
'
);
var
_ora2
=
_interopRequireDefault
(
_ora
);
var
_inquirer
=
require
(
'
inquirer
'
);
var
_inquirer2
=
_interopRequireDefault
(
_inquirer
);
var
_fs
=
require
(
'
fs
'
);
var
_fs2
=
_interopRequireDefault
(
_fs
);
var
_chalk
=
require
(
'
chalk
'
);
var
_chalk2
=
_interopRequireDefault
(
_chalk
);
var
_logSymbols
=
require
(
'
log-symbols
'
);
var
_logSymbols2
=
_interopRequireDefault
(
_logSymbols
);
function
_interopRequireDefault
(
obj
)
{
return
obj
&&
obj
.
__esModule
?
obj
:
{
default
:
obj
};
}
function
_asyncToGenerator
(
fn
)
{
return
function
()
{
var
gen
=
fn
.
apply
(
this
,
arguments
);
return
new
Promise
(
function
(
resolve
,
reject
)
{
function
step
(
key
,
arg
)
{
try
{
var
info
=
gen
[
key
](
arg
);
var
value
=
info
.
value
;
}
catch
(
error
)
{
reject
(
error
);
return
;
}
if
(
info
.
done
)
{
resolve
(
value
);
}
else
{
return
Promise
.
resolve
(
value
).
then
(
function
(
value
)
{
step
(
"
next
"
,
value
);
},
function
(
err
)
{
step
(
"
throw
"
,
err
);
});
}
}
return
step
(
"
next
"
);
});
};
}
const
util
=
require
(
'
util
'
);
const
exec
=
util
.
promisify
(
require
(
'
child_process
'
).
exec
);
let
block
=
(()
=>
{
var
_ref
=
_asyncToGenerator
(
function
*
(
action
,
blockName
)
{
let
result
=
yield
(
0
,
_rc
.
get
)(
'
block
'
);
switch
(
action
)
{
case
'
add
'
:
if
(
_fs2
.
default
.
existsSync
(
'
block
'
))
{
yield
exec
(
'
rm -rf block
'
);
}
if
(
!
result
.
includes
(
blockName
))
{
console
.
log
(
_logSymbols2
.
default
.
error
,
_chalk2
.
default
.
red
(
`The blockName
${
blockName
}
not exists`
));
return
;
}
//命令行交互
_inquirer2
.
default
.
prompt
([{
name
:
'
destination
'
,
message
:
'
Please enter the destination:(default src/view/)
'
}]).
then
((()
=>
{
var
_ref2
=
_asyncToGenerator
(
function
*
(
answer
)
{
if
(
answer
.
destination
&&
!
_fs2
.
default
.
existsSync
(
answer
.
destination
))
{
console
.
log
(
_logSymbols2
.
default
.
error
,
_chalk2
.
default
.
red
(
'
The destination not exists
'
));
return
;
}
let
loading
=
(
0
,
_ora2
.
default
)(
'
downloading block ...
'
);
loading
.
start
();
(
0
,
_get
.
downloadBlock
)().
then
(
function
()
{
loading
.
succeed
();
const
destination
=
answer
.
destination
?
`
${
answer
.
destination
}
`
:
'
src/view/
'
;
exec
(
`cp -r block/
${
blockName
}
${
destination
}
&& rm -rf block`
);
},
function
(
e
)
{
loading
.
fail
(
e
.
message
);
});
});
return
function
(
_x3
)
{
return
_ref2
.
apply
(
this
,
arguments
);
};
})());
break
;
case
'
list
'
:
result
.
forEach
(
function
(
block
)
{
return
console
.
log
(
block
+
'
\r
'
);
});
break
;
default
:
break
;
}
});
return
function
block
(
_x
,
_x2
)
{
return
_ref
.
apply
(
this
,
arguments
);
};
})();
module
.
exports
=
block
;
\ No newline at end of file
dist/main.js
View file @
a448b51a
...
@@ -32,9 +32,12 @@ let actionMap = {
...
@@ -32,9 +32,12 @@ let actionMap = {
description
:
'
config .qgrc
'
,
description
:
'
config .qgrc
'
,
usages
:
[
'
qg config set <k> <v>
'
,
'
qg config get <k>
'
,
'
qg config remove <k>
'
]
usages
:
[
'
qg config set <k> <v>
'
,
'
qg config get <k>
'
,
'
qg config remove <k>
'
]
},
block
:
{
description
:
'
add a block to destination
'
,
usages
:
[
'
qg block list
'
,
'
qg block add <blockName>
'
]
//other commands
}
}
//other commands
// 添加 init / config 命令
// 添加 init / config 命令
};
Object
.
keys
(
actionMap
).
forEach
(
action
=>
{
};
Object
.
keys
(
actionMap
).
forEach
(
action
=>
{
...
@@ -48,6 +51,9 @@ let actionMap = {
...
@@ -48,6 +51,9 @@ let actionMap = {
case
'
init
'
:
case
'
init
'
:
(
0
,
_index2
.
default
)(
action
,
...
process
.
argv
.
slice
(
3
));
(
0
,
_index2
.
default
)(
action
,
...
process
.
argv
.
slice
(
3
));
break
;
break
;
case
'
block
'
:
(
0
,
_index2
.
default
)(
action
,
...
process
.
argv
.
slice
(
3
));
break
;
default
:
default
:
break
;
break
;
}
}
...
...
dist/utils/constants.js
View file @
a448b51a
'
use strict
'
;
'
use strict
'
;
Object
.
defineProperty
(
exports
,
"
__esModule
"
,
{
Object
.
defineProperty
(
exports
,
"
__esModule
"
,
{
value
:
true
value
:
true
});
});
exports
.
DEFAULTS
=
exports
.
RC
=
exports
.
VERSION
=
undefined
;
exports
.
DEFAULTS
=
exports
.
RC
=
exports
.
VERSION
=
undefined
;
...
@@ -21,8 +21,9 @@ const RC = exports.RC = `${HOME}/.qgrc`;
...
@@ -21,8 +21,9 @@ const RC = exports.RC = `${HOME}/.qgrc`;
// https://api.github.com/${type}/${registry}/repos
// https://api.github.com/${type}/${registry}/repos
// 模板下载地址可配置
// 模板下载地址可配置
const
DEFAULTS
=
exports
.
DEFAULTS
=
{
const
DEFAULTS
=
exports
.
DEFAULTS
=
{
type
:
'
ui
'
,
type
:
'
ui
'
,
address
:
'
http://git.quantgroup.cn
'
,
address
:
'
http://git.quantgroup.cn
'
,
antd
:
'
react-based-ant-pro.git
'
,
antd
:
'
react-based-ant-pro.git
'
,
vue
:
'
my-vue.git
'
vue
:
'
my-vue.git
'
,
block
:
[
'
activityList
'
,
'
makeActiyity
'
]
};
};
\ No newline at end of file
dist/utils/get.js
View file @
a448b51a
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
Object
.
defineProperty
(
exports
,
"
__esModule
"
,
{
Object
.
defineProperty
(
exports
,
"
__esModule
"
,
{
value
:
true
value
:
true
});
});
exports
.
downloadLocal
=
undefined
;
exports
.
download
Block
=
exports
.
download
Local
=
undefined
;
var
_rc
=
require
(
'
./rc
'
);
var
_rc
=
require
(
'
./rc
'
);
...
@@ -35,4 +35,26 @@ const downloadLocal = exports.downloadLocal = (() => {
...
@@ -35,4 +35,26 @@ const downloadLocal = exports.downloadLocal = (() => {
return
function
downloadLocal
(
_x
,
_x2
)
{
return
function
downloadLocal
(
_x
,
_x2
)
{
return
_ref
.
apply
(
this
,
arguments
);
return
_ref
.
apply
(
this
,
arguments
);
};
};
})();
const
downloadBlock
=
exports
.
downloadBlock
=
(()
=>
{
var
_ref2
=
_asyncToGenerator
(
function
*
()
{
let
config
=
yield
(
0
,
_rc
.
getAll
)();
let
api
=
`direct:
${
config
.
address
}
/
${
config
.
type
}
/block.git`
;
console
.
log
(
`\ndownload from
${
api
}
`
);
return
new
Promise
(
function
(
resolve
,
reject
)
{
//projectName 为下载到的本地目录
(
0
,
_downloadGitRepo2
.
default
)(
api
,
'
block
'
,
{
clone
:
true
},
function
(
err
)
{
if
(
err
)
{
reject
(
err
);
}
resolve
();
});
});
});
return
function
downloadBlock
()
{
return
_ref2
.
apply
(
this
,
arguments
);
};
})();
})();
\ No newline at end of file
src/block.js
0 → 100644
View file @
a448b51a
import
{
downloadLocal
,
downloadBlock
}
from
'
./utils/get
'
;
import
{
get
}
from
'
./utils/rc
'
;
import
ora
from
'
ora
'
;
import
inquirer
from
'
inquirer
'
;
import
fs
from
'
fs
'
;
import
chalk
from
'
chalk
'
;
import
symbol
from
'
log-symbols
'
;
const
util
=
require
(
'
util
'
);
const
exec
=
util
.
promisify
(
require
(
'
child_process
'
).
exec
);
let
block
=
async
(
action
,
blockName
)
=>
{
let
result
=
await
get
(
'
block
'
);
switch
(
action
)
{
case
'
add
'
:
if
(
fs
.
existsSync
(
'
block
'
))
{
await
exec
(
'
rm -rf block
'
);
}
if
(
!
result
.
includes
(
blockName
))
{
console
.
log
(
symbol
.
error
,
chalk
.
red
(
`The blockName
${
blockName
}
not exists`
));
return
;
}
//命令行交互
inquirer
.
prompt
([
{
name
:
'
destination
'
,
message
:
'
Please enter the destination:(default src/view/)
'
}
]).
then
(
async
(
answer
)
=>
{
if
(
answer
.
destination
&&
!
fs
.
existsSync
(
answer
.
destination
))
{
console
.
log
(
symbol
.
error
,
chalk
.
red
(
'
The destination not exists
'
));
return
;
}
let
loading
=
ora
(
'
downloading block ...
'
);
loading
.
start
();
downloadBlock
().
then
(()
=>
{
loading
.
succeed
();
const
destination
=
answer
.
destination
?
`
${
answer
.
destination
}
`
:
'
src/view/
'
;
exec
(
`cp -r block/
${
blockName
}
${
destination
}
&& rm -rf block`
);
},
(
e
)
=>
{
loading
.
fail
(
e
.
message
);
});
});
break
;
case
'
list
'
:
result
.
forEach
(
block
=>
console
.
log
(
block
+
'
\r
'
));
break
;
default
:
break
;
}
}
module
.
exports
=
block
;
\ No newline at end of file
src/main.js
View file @
a448b51a
...
@@ -26,6 +26,13 @@ let actionMap = {
...
@@ -26,6 +26,13 @@ let actionMap = {
]
]
},
},
block
:
{
description
:
'
add a block to destination
'
,
usages
:
[
'
qg block list
'
,
'
qg block add <blockName>
'
]
}
//other commands
//other commands
}
}
...
@@ -43,6 +50,9 @@ Object.keys(actionMap).forEach((action) => {
...
@@ -43,6 +50,9 @@ Object.keys(actionMap).forEach((action) => {
case
'
init
'
:
case
'
init
'
:
apply
(
action
,
...
process
.
argv
.
slice
(
3
));
apply
(
action
,
...
process
.
argv
.
slice
(
3
));
break
;
break
;
case
'
block
'
:
apply
(
action
,
...
process
.
argv
.
slice
(
3
));
break
;
default
:
default
:
break
;
break
;
}
}
...
...
src/utils/constants.js
View file @
a448b51a
...
@@ -17,5 +17,6 @@ export const DEFAULTS = {
...
@@ -17,5 +17,6 @@ export const DEFAULTS = {
type
:
'
ui
'
,
type
:
'
ui
'
,
address
:
'
http://git.quantgroup.cn
'
,
address
:
'
http://git.quantgroup.cn
'
,
antd
:
'
react-based-ant-pro.git
'
,
antd
:
'
react-based-ant-pro.git
'
,
vue
:
'
my-vue.git
'
vue
:
'
my-vue.git
'
,
block
:
[
'
activityList
'
,
'
makeActiyity
'
]
}
}
\ No newline at end of file
src/utils/get.js
View file @
a448b51a
...
@@ -15,4 +15,20 @@ export const downloadLocal = async (templateName, projectName) => {
...
@@ -15,4 +15,20 @@ export const downloadLocal = async (templateName, projectName) => {
resolve
();
resolve
();
});
});
});
});
}
export
const
downloadBlock
=
async
()
=>
{
let
config
=
await
getAll
();
let
api
=
`direct:
${
config
.
address
}
/
${
config
.
type
}
/block.git`
;
console
.
log
(
`\ndownload from
${
api
}
`
);
return
new
Promise
((
resolve
,
reject
)
=>
{
//projectName 为下载到的本地目录
downloadGit
(
api
,
'
block
'
,
{
clone
:
true
},
(
err
)
=>
{
if
(
err
)
{
reject
(
err
);
}
resolve
();
});
});
}
}
\ 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