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
a59dc6c9
Commit
a59dc6c9
authored
May 05, 2019
by
rockyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
依赖列表抽离到dep.json中
parent
923167cf
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
39 deletions
+44
-39
cli-wrapper.js
bin/cli-wrapper.js
+11
-4
package.json
package.json
+1
-0
index.js
src/index.js
+27
-14
test.js
test.js
+0
-21
yarn.lock
yarn.lock
+5
-0
No files found.
bin/cli-wrapper.js
View file @
a59dc6c9
...
@@ -15,11 +15,19 @@ exports.execute = async function (program) {
...
@@ -15,11 +15,19 @@ exports.execute = async function (program) {
const
componentsPath
=
program
.
projectPath
||
path
.
join
(
os
.
homedir
(),
'.scilla'
,
'components'
);
const
componentsPath
=
program
.
projectPath
||
path
.
join
(
os
.
homedir
(),
'.scilla'
,
'components'
);
const
componentsSrcPath
=
path
.
join
(
componentsPath
,
'src'
);
const
componentsSrcPath
=
path
.
join
(
componentsPath
,
'src'
);
const
tsconfig
=
fs
.
readJsonSync
(
path
.
join
(
componentsPath
,
'tsconfig.json'
));
const
tsconfig
=
fs
.
readJsonSync
(
path
.
join
(
componentsPath
,
'tsconfig.json'
));
const
inputFile
=
program
.
input
;
const
inputFile
=
program
.
input
;
const
inputFileFolder
=
path
.
dirname
(
inputFile
);
const
inputFileFolder
=
path
.
dirname
(
inputFile
);
const
outputFile
=
path
.
join
(
inputFileFolder
,
'declare.json'
);
const
outputFile
=
path
.
join
(
inputFileFolder
,
'dec.json'
);
let
dependencies
;
try
{
dependencies
=
fs
.
readJsonSync
(
path
.
join
(
inputFileFolder
,
'dep.json'
));
}
catch
(
e
)
{
}
const
projectPath
=
process
.
cwd
();
const
projectPath
=
process
.
cwd
();
...
@@ -27,8 +35,9 @@ exports.execute = async function (program) {
...
@@ -27,8 +35,9 @@ exports.execute = async function (program) {
return
source
.
fileName
.
indexOf
(
inputFileFolder
)
>=
0
;
return
source
.
fileName
.
indexOf
(
inputFileFolder
)
>=
0
;
}
}
const
{
declareMap
,
dependencies
,
missingDependencies
}
=
generateDeclareMap
(
const
{
declareMap
,
missingDependencies
}
=
generateDeclareMap
(
tsconfig
,
tsconfig
,
dependencies
,
inputFile
,
inputFile
,
componentsSrcPath
,
componentsSrcPath
,
projectPath
,
projectPath
,
...
@@ -40,8 +49,6 @@ exports.execute = async function (program) {
...
@@ -40,8 +49,6 @@ exports.execute = async function (program) {
console
.
log
(
result
);
console
.
log
(
result
);
}
}
declareMap
.
dependencies
=
dependencies
;
if
(
Object
.
keys
(
missingDependencies
).
length
>
0
)
{
if
(
Object
.
keys
(
missingDependencies
).
length
>
0
)
{
console
.
warn
(
JSON
.
stringify
(
missingDependencies
,
null
,
'
\
t'
));
console
.
warn
(
JSON
.
stringify
(
missingDependencies
,
null
,
'
\
t'
));
return
2
;
return
2
;
...
...
package.json
View file @
a59dc6c9
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
"dependencies"
:
{
"dependencies"
:
{
"
commander
"
:
"
^2.20.0
"
,
"
commander
"
:
"
^2.20.0
"
,
"
fs-extra
"
:
"
^7.0.1
"
,
"
fs-extra
"
:
"
^7.0.1
"
,
"
semver
"
:
"
^6.0.0
"
,
"
typescript
"
:
"
^3.2.2
"
"
typescript
"
:
"
^3.2.2
"
}
}
}
}
src/index.js
View file @
a59dc6c9
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
*/
*/
const
ts
=
require
(
'typescript'
);
const
ts
=
require
(
'typescript'
);
const
fs
=
require
(
'fs-extra'
);
const
semver
=
require
(
'semver'
);
let
declareMap
;
let
declareMap
;
let
_componentsPath
;
let
_componentsPath
;
...
@@ -16,7 +18,7 @@ const componentBaseClassName = '"scilla/core/Component".Component';
...
@@ -16,7 +18,7 @@ const componentBaseClassName = '"scilla/core/Component".Component';
const
showLog
=
false
;
const
showLog
=
false
;
const
showVerboseLog
=
false
;
const
showVerboseLog
=
false
;
exports
.
generateDeclareMap
=
function
(
tsconfig
,
file
,
componentsPath
,
projectPath
,
assetsPath
,
filter
)
{
exports
.
generateDeclareMap
=
function
(
tsconfig
,
dependencies
,
file
,
componentsPath
,
projectPath
,
assetsPath
,
filter
)
{
_componentsPath
=
componentsPath
;
_componentsPath
=
componentsPath
;
_projectPath
=
projectPath
;
_projectPath
=
projectPath
;
_assetsPath
=
assetsPath
;
_assetsPath
=
assetsPath
;
...
@@ -24,6 +26,26 @@ exports.generateDeclareMap = function(tsconfig, file, componentsPath, projectPat
...
@@ -24,6 +26,26 @@ exports.generateDeclareMap = function(tsconfig, file, componentsPath, projectPat
const
config
=
ts
.
parseJsonConfigFileContent
(
tsconfig
,
ts
.
sys
,
projectPath
);
const
config
=
ts
.
parseJsonConfigFileContent
(
tsconfig
,
ts
.
sys
,
projectPath
);
const
missingDependencies
=
[];
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
);
}
}
if
(
missingDependencies
.
length
>
0
){
return
{
missingDependencies
};
}
const
files
=
file
?
[
file
]
:
config
.
fileNames
;
const
files
=
file
?
[
file
]
:
config
.
fileNames
;
const
program
=
ts
.
createProgram
(
files
,
config
.
options
);
const
program
=
ts
.
createProgram
(
files
,
config
.
options
);
const
sourceFiles
=
program
.
getSourceFiles
();
const
sourceFiles
=
program
.
getSourceFiles
();
...
@@ -35,29 +57,20 @@ exports.generateDeclareMap = function(tsconfig, file, componentsPath, projectPat
...
@@ -35,29 +57,20 @@ 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
=
{};
for
(
let
sourceFile
of
sourceFiles
){
for
(
let
sourceFile
of
sourceFiles
){
if
(
sourceFile
.
fileName
.
indexOf
(
'.d.ts'
)
<
0
)
{
if
(
sourceFile
.
fileName
.
indexOf
(
'.d.ts'
)
<
0
)
{
if
(
!
_filter
||
_filter
(
sourceFile
)){
if
(
!
_filter
||
_filter
(
sourceFile
)){
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
];
missingDependencies
.
push
(
key
);
if
(
!
t
){
t
=
missingDependencies
[
fileName
]
=
[];
}
t
.
push
(
key
);
}
}
});
});
}
}
if
(
showLog
&&
showVerboseLog
)
console
.
time
(
sourceFile
.
fileName
);
if
(
showLog
&&
showVerboseLog
)
console
.
time
(
fileName
);
delint
(
checker
,
sourceFile
);
delint
(
checker
,
sourceFile
);
if
(
showLog
&&
showVerboseLog
)
console
.
timeEnd
(
sourceFile
.
fileName
);
if
(
showLog
&&
showVerboseLog
)
console
.
timeEnd
(
fileName
);
}
}
}
}
}
}
...
@@ -65,7 +78,6 @@ exports.generateDeclareMap = function(tsconfig, file, componentsPath, projectPat
...
@@ -65,7 +78,6 @@ exports.generateDeclareMap = function(tsconfig, file, componentsPath, projectPat
return
{
return
{
declareMap
,
declareMap
,
dependencies
,
missingDependencies
,
missingDependencies
,
};
};
};
};
...
@@ -226,6 +238,7 @@ function getFullyQualifiedNameOfType(type, checker) {
...
@@ -226,6 +238,7 @@ function getFullyQualifiedNameOfType(type, checker) {
path
=
path
.
replace
(
'src'
,
'components'
)
path
=
path
.
replace
(
'src'
,
'components'
)
}
else
{
}
else
{
path
=
path
.
replace
(
_componentsPath
,
'components'
)
path
=
path
.
replace
(
_componentsPath
,
'components'
)
.
replace
(
/
\/\d
+
\.\d
+
\.\d
+
\/
index/
,
''
)
}
}
fullClassName
=
`"
${
path
}
".
${
className
}
`
;
fullClassName
=
`"
${
path
}
".
${
className
}
`
;
}
}
...
...
test.js
deleted
100644 → 0
View file @
923167cf
/**
* Created by rockyl on 2018-12-19.
*/
const
{
generateDeclareMap
,
}
=
require
(
'./src/index'
);
async
function
exec
(){
let
classDeclareMap
=
await
generateDeclareMap
(
'/Users/rockyl/.scilla/components'
,
'/Users/rockyl/WorkSpaces/scilla/jigsaw-puzzle'
,
'/Users/rockyl/WorkSpaces/scilla/jigsaw-puzzle/assets'
,
'/Users/rockyl/WorkSpaces/scilla/jigsaw-puzzle/assets/scripts/game/Puzzle.ts'
);
console
.
log
(
JSON
.
stringify
(
classDeclareMap
,
null
,
'
\
t'
));
//const keys = Object.keys(classDeclareMap);
//console.log(keys);
//console.log(JSON.stringify(classDeclareMap[keys[keys.length - 1]], null, '\t'));
}
exec
();
yarn.lock
View file @
a59dc6c9
...
@@ -28,6 +28,11 @@ jsonfile@^4.0.0:
...
@@ -28,6 +28,11 @@ jsonfile@^4.0.0:
optionalDependencies:
optionalDependencies:
graceful-fs "^4.1.6"
graceful-fs "^4.1.6"
semver@^6.0.0:
version "6.0.0"
resolved "https://registry.npm.taobao.org/semver/download/semver-6.0.0.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fsemver%2Fdownload%2Fsemver-6.0.0.tgz#05e359ee571e5ad7ed641a6eec1e547ba52dea65"
integrity sha1-BeNZ7lceWtftZBpu7B5Ue6Ut6mU=
typescript@^3.2.2:
typescript@^3.2.2:
version "3.2.2"
version "3.2.2"
resolved "https://registry.npmjs.org/typescript/-/typescript-3.2.2.tgz#fe8101c46aa123f8353523ebdcf5730c2ae493e5"
resolved "https://registry.npmjs.org/typescript/-/typescript-3.2.2.tgz#fe8101c46aa123f8353523ebdcf5730c2ae493e5"
...
...
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