Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
scilla-declare-generator
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
劳工
scilla-declare-generator
Commits
23c636b8
Commit
23c636b8
authored
May 06, 2019
by
rockyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复组件依赖关系
增加文件夹遍历执行
parent
a59dc6c9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
17 deletions
+48
-17
cli-wrapper.js
bin/cli-wrapper.js
+47
-8
index.js
src/index.js
+1
-9
No files found.
bin/cli-wrapper.js
View file @
23c636b8
...
...
@@ -5,8 +5,36 @@
const
os
=
require
(
'os'
);
const
path
=
require
(
'path'
);
const
fs
=
require
(
'fs-extra'
);
const
semver
=
require
(
'semver'
);
const
{
generateDeclareMap
}
=
require
(
'../src/index'
);
function
getAllDependencies
(
dependencies
,
missingDependencies
,
componentName
,
version
,
componentsSrcPath
){
let
temp
;
try
{
temp
=
fs
.
readJsonSync
(
path
.
join
(
componentsSrcPath
,
componentName
,
version
,
'dep.json'
));
}
catch
(
e
)
{}
if
(
temp
){
for
(
let
key
in
temp
){
if
(
!
dependencies
[
key
]){
let
componentName
=
key
.
replace
(
'components/'
,
''
);
let
componentPath
=
path
.
join
(
componentsSrcPath
,
componentName
);
let
versions
=
fs
.
readdirSync
(
componentPath
);
versions
=
versions
.
filter
(
item
=>
item
.
match
(
/^
\d
+
\.\d
+
\.\d
+$/
));
let
maxVersion
=
semver
.
maxSatisfying
(
versions
,
temp
[
key
]);
if
(
maxVersion
){
dependencies
[
key
]
=
maxVersion
;
getAllDependencies
(
dependencies
,
missingDependencies
,
componentName
,
maxVersion
,
componentsSrcPath
);
}
else
{
missingDependencies
[
key
]
=
temp
[
key
];
}
}
}
}
}
exports
.
execute
=
async
function
(
program
)
{
if
(
!
program
.
input
)
{
console
.
warn
(
'parameter is incorrect'
);
...
...
@@ -22,11 +50,15 @@ exports.execute = async function (program) {
const
inputFileFolder
=
path
.
dirname
(
inputFile
);
const
outputFile
=
path
.
join
(
inputFileFolder
,
'dec.json'
);
let
dependencies
;
try
{
dependencies
=
fs
.
readJsonSync
(
path
.
join
(
inputFileFolder
,
'dep.json'
));
}
catch
(
e
)
{
let
componentPath
=
path
.
relative
(
componentsSrcPath
,
inputFileFolder
);
let
componentName
=
componentPath
.
substring
(
0
,
componentPath
.
lastIndexOf
(
'/'
));
let
componentVersion
=
componentPath
.
substr
(
componentPath
.
lastIndexOf
(
'/'
)
+
1
);
let
dependencies
=
{},
missingDependenciesPre
=
{};
getAllDependencies
(
dependencies
,
missingDependenciesPre
,
componentName
,
componentVersion
,
componentsSrcPath
);
let
result
=
dealMissingDependencies
(
missingDependenciesPre
);
if
(
result
>
0
){
return
result
;
}
const
projectPath
=
process
.
cwd
();
...
...
@@ -46,13 +78,20 @@ exports.execute = async function (program) {
);
if
(
program
.
verbose
)
{
console
.
log
(
result
);
console
.
log
(
declareMap
,
missingDependencies
);
}
if
(
Object
.
keys
(
missingDependencies
).
length
>
0
)
{
console
.
warn
(
JSON
.
stringify
(
missingDependencies
,
null
,
'
\
t'
));
return
2
;
result
=
dealMissingDependencies
(
missingDependencies
);
if
(
result
>
0
){
return
result
;
}
fs
.
writeJsonSync
(
outputFile
,
declareMap
);
};
function
dealMissingDependencies
(
missingDependencies
){
if
(
Object
.
keys
(
missingDependencies
).
length
>
0
)
{
console
.
warn
(
JSON
.
stringify
(
missingDependencies
,
null
,
'
\
t'
));
return
2
;
}
}
src/index.js
View file @
23c636b8
...
...
@@ -4,7 +4,6 @@
const
ts
=
require
(
'typescript'
);
const
fs
=
require
(
'fs-extra'
);
const
semver
=
require
(
'semver'
);
let
declareMap
;
let
_componentsPath
;
...
...
@@ -30,14 +29,7 @@ exports.generateDeclareMap = function(tsconfig, dependencies, file, componentsPa
for
(
let
key
in
dependencies
){
let
componentSrcPath
=
key
.
replace
(
'components'
,
'src'
);
let
versions
=
fs
.
readdirSync
(
componentSrcPath
);
versions
=
versions
.
filter
(
item
=>
item
.
match
(
/^
\d
+
\.\d
+
\.\d
+$/
));
let
maxVersion
=
semver
.
maxSatisfying
(
versions
,
dependencies
[
key
]);
if
(
maxVersion
){
config
.
options
.
paths
[
key
]
=
[
componentSrcPath
+
'/'
+
maxVersion
+
'/index'
];
}
else
{
missingDependencies
.
push
(
key
);
}
config
.
options
.
paths
[
key
]
=
[
componentSrcPath
+
'/'
+
dependencies
[
key
]
+
'/index'
];
}
if
(
missingDependencies
.
length
>
0
){
...
...
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