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
38469208
Commit
38469208
authored
Apr 29, 2019
by
rockyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cli wrapper
parent
735bba59
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
61 additions
and
43 deletions
+61
-43
cli-wrapper.js
bin/cli-wrapper.js
+49
-0
cli.js
bin/cli.js
+6
-42
package.json
package.json
+1
-1
index.js
src/index.js
+5
-0
No files found.
bin/cli-wrapper.js
0 → 100644
View file @
38469208
/**
* Created by rockyl on 2019-04-29.
*/
const
os
=
require
(
'os'
);
const
path
=
require
(
'path'
);
const
fs
=
require
(
'fs-extra'
);
const
{
generateDeclareMap
}
=
require
(
'../src/index'
);
export
async
function
execute
(
program
){
if
(
!
program
.
input
||
!
program
.
output
){
console
.
warn
(
'parameter is incorrect'
);
process
.
exit
(
1
);
}
const
componentsPath
=
program
.
projectPath
||
path
.
join
(
os
.
homedir
(),
'.scilla'
,
'components'
);
const
componentsSrcPath
=
path
.
join
(
componentsPath
,
'src'
);
const
tsconfig
=
fs
.
readJsonSync
(
path
.
join
(
componentsPath
,
'tsconfig.json'
));
const
inputFile
=
program
.
input
;
const
inputFileFolder
=
path
.
dirname
(
inputFile
);
const
projectPath
=
process
.
cwd
();
function
declareFilter
(
source
)
{
return
source
.
fileName
.
indexOf
(
inputFileFolder
)
>=
0
;
}
const
result
=
generateDeclareMap
(
tsconfig
,
program
.
input
,
componentsSrcPath
,
projectPath
,
null
,
declareFilter
);
if
(
program
.
verbose
){
console
.
log
(
result
);
}
if
(
Object
.
keys
(
result
.
missingDependencies
).
length
>
0
){
console
.
warn
(
JSON
.
stringify
(
result
.
missingDependencies
,
null
,
'
\
t'
));
process
.
exit
(
2
);
}
fs
.
ensureDirSync
(
path
.
dirname
(
program
.
output
));
fs
.
writeJsonSync
(
program
.
output
,
result
.
declareMap
);
}
bin/cli.js
View file @
38469208
...
@@ -4,56 +4,20 @@
...
@@ -4,56 +4,20 @@
* Created by rockyl on 2019-04-26.
* Created by rockyl on 2019-04-26.
*/
*/
const
os
=
require
(
'os'
);
import
{
execute
}
from
"./cli-wrapper"
;
const
path
=
require
(
'path'
);
const
fs
=
require
(
'fs-extra'
);
const
program
=
require
(
'commander'
);
const
program
=
require
(
'commander'
);
const
{
generateDeclareMap
}
=
require
(
'../src/index'
);
program
program
.
version
(
'1.0.3'
)
.
version
(
'1.0.3'
)
.
description
(
'scilla declare generator'
)
.
description
(
'scilla declare generator'
)
.
option
(
'-i, --input [string]'
,
'input file'
)
.
option
(
'-i, --input [string]'
,
'input file'
)
.
option
(
'-o, --output [string]'
,
'output file'
)
.
option
(
'-o, --output [string]'
,
'output file'
)
.
option
(
'-p, --p
athofcomponents
[string]'
,
'path of components'
)
.
option
(
'-p, --p
rojectPath
[string]'
,
'path of components'
)
.
option
(
'-v, --verbose [boolean]'
,
'verbose mode'
,
false
)
.
option
(
'-v, --verbose [boolean]'
,
'verbose mode'
,
false
)
.
parse
(
process
.
argv
);
.
parse
(
process
.
argv
);
if
(
!
program
.
input
||
!
program
.
output
){
execute
(
program
).
catch
(
e
=>
{
console
.
warn
(
'parameter is incorrect'
);
console
.
error
(
e
);
process
.
exit
(
1
);
}
const
componentsPath
=
program
.
pathofcomponents
||
path
.
join
(
os
.
homedir
(),
'.scilla'
,
'components'
);
const
componentsSrcPath
=
path
.
join
(
componentsPath
,
'src'
);
const
tsconfig
=
fs
.
readJsonSync
(
path
.
join
(
componentsPath
,
'tsconfig.json'
));
const
inputFile
=
program
.
input
;
const
inputFileFolder
=
path
.
dirname
(
inputFile
);
const
projectPath
=
process
.
cwd
();
function
declareFilter
(
source
)
{
return
source
.
fileName
.
indexOf
(
inputFileFolder
)
>=
0
;
}
const
result
=
generateDeclareMap
(
tsconfig
,
program
.
input
,
componentsSrcPath
,
projectPath
,
null
,
declareFilter
);
if
(
program
.
verbose
){
console
.
log
(
result
);
}
if
(
Object
.
keys
(
result
.
missingDependencies
).
length
>
0
){
console
.
warn
(
JSON
.
stringify
(
result
.
missingDependencies
,
null
,
'
\
t'
));
process
.
exit
(
2
);
process
.
exit
(
2
);
}
});
fs
.
ensureDirSync
(
path
.
dirname
(
program
.
output
));
fs
.
writeJsonSync
(
program
.
output
,
result
.
declareMap
);
package.json
View file @
38469208
{
{
"name"
:
"scilla-declare-generator"
,
"name"
:
"scilla-declare-generator"
,
"version"
:
"1.0.
2
"
,
"version"
:
"1.0.
3
"
,
"main"
:
"src/index.js"
,
"main"
:
"src/index.js"
,
"bin"
:
"bin/cli.js"
,
"bin"
:
"bin/cli.js"
,
"license"
:
"
MIT
"
,
"license"
:
"
MIT
"
,
...
...
src/index.js
View file @
38469208
...
@@ -35,6 +35,7 @@ exports.generateDeclareMap = function(tsconfig, file, componentsPath, projectPat
...
@@ -35,6 +35,7 @@ exports.generateDeclareMap = function(tsconfig, file, componentsPath, projectPat
if
(
showLog
)
console
.
timeEnd
(
'getTypeChecker'
);
if
(
showLog
)
console
.
timeEnd
(
'getTypeChecker'
);
if
(
showLog
)
console
.
time
(
'delint'
);
if
(
showLog
)
console
.
time
(
'delint'
);
const
dependencies
=
[];
const
missingDependencies
=
{};
const
missingDependencies
=
{};
for
(
let
sourceFile
of
sourceFiles
){
for
(
let
sourceFile
of
sourceFiles
){
if
(
sourceFile
.
fileName
.
indexOf
(
'.d.ts'
)
<
0
)
{
if
(
sourceFile
.
fileName
.
indexOf
(
'.d.ts'
)
<
0
)
{
...
@@ -42,6 +43,9 @@ exports.generateDeclareMap = function(tsconfig, file, componentsPath, projectPat
...
@@ -42,6 +43,9 @@ exports.generateDeclareMap = function(tsconfig, file, componentsPath, projectPat
const
fileName
=
sourceFile
.
fileName
;
const
fileName
=
sourceFile
.
fileName
;
if
(
sourceFile
.
resolvedModules
){
if
(
sourceFile
.
resolvedModules
){
sourceFile
.
resolvedModules
.
forEach
((
item
,
key
)
=>
{
sourceFile
.
resolvedModules
.
forEach
((
item
,
key
)
=>
{
if
(
!
dependencies
.
includes
(
key
)){
dependencies
.
push
(
key
);
}
if
(
!
item
){
if
(
!
item
){
let
t
=
missingDependencies
[
fileName
];
let
t
=
missingDependencies
[
fileName
];
if
(
!
t
){
if
(
!
t
){
...
@@ -61,6 +65,7 @@ exports.generateDeclareMap = function(tsconfig, file, componentsPath, projectPat
...
@@ -61,6 +65,7 @@ exports.generateDeclareMap = function(tsconfig, file, componentsPath, projectPat
return
{
return
{
declareMap
,
declareMap
,
dependencies
,
missingDependencies
,
missingDependencies
,
};
};
};
};
...
...
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