Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DiDi
Chameleon
提交
f340c454
C
Chameleon
项目概览
DiDi
/
Chameleon
通知
13
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
Chameleon
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
f340c454
编写于
5月 15, 2019
作者:
B
beatles-chameleon
提交者:
GitHub
5月 15, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #177 from didi/0.4.x-dev
0.4.x dev
上级
0d40eae9
8c75a773
变更
28
展开全部
隐藏空白更改
内联
并排
Showing
28 changed file
with
549 addition
and
1757 deletion
+549
-1757
packages/chameleon-tool-utils/package.json
packages/chameleon-tool-utils/package.json
+1
-1
packages/chameleon-tool-utils/src/index.js
packages/chameleon-tool-utils/src/index.js
+13
-31
packages/chameleon-tool-utils/test/index.test.js
packages/chameleon-tool-utils/test/index.test.js
+0
-16
packages/chameleon-tool-utils/test/testlib/demo-project/chameleon.config.js
...-tool-utils/test/testlib/demo-project/chameleon.config.js
+1
-2
packages/chameleon-tool/configs/component_export/getMiniAppExportConfig.js
...n-tool/configs/component_export/getMiniAppExportConfig.js
+5
-1
packages/chameleon-tool/configs/component_export/getWeexExportConfig_new.js
...-tool/configs/component_export/getWeexExportConfig_new.js
+5
-1
packages/chameleon-tool/configs/mvvm/getExtendConfig.js
packages/chameleon-tool/configs/mvvm/getExtendConfig.js
+1
-1
packages/chameleon-tool/configs/utils.js
packages/chameleon-tool/configs/utils.js
+2
-1
packages/chameleon-tool/lib/index.js
packages/chameleon-tool/lib/index.js
+1
-2
packages/easy-chameleon/npm-shrinkwrap.json
packages/easy-chameleon/npm-shrinkwrap.json
+126
-1616
packages/mvvm-interface-parser/index.js
packages/mvvm-interface-parser/index.js
+4
-18
packages/mvvm-interface-parser/lib/getInterfaceCode.js
packages/mvvm-interface-parser/lib/getInterfaceCode.js
+51
-46
packages/mvvm-interface-parser/lib/getInterfaceCode_old.js
packages/mvvm-interface-parser/lib/getInterfaceCode_old.js
+82
-0
packages/mvvm-interface-parser/lib/getMethodCode.js
packages/mvvm-interface-parser/lib/getMethodCode.js
+14
-17
packages/mvvm-interface-parser/lib/getMethodCode_old.js
packages/mvvm-interface-parser/lib/getMethodCode_old.js
+94
-0
packages/mvvm-interface-parser/runtime/copyProto.js
packages/mvvm-interface-parser/runtime/copyProto.js
+16
-0
packages/mvvm-interface-parser/test/copyProto.test.js
packages/mvvm-interface-parser/test/copyProto.test.js
+19
-0
packages/mvvm-interface-parser/test/getInterfaceCode.test.js
packages/mvvm-interface-parser/test/getInterfaceCode.test.js
+60
-1
packages/mvvm-interface-parser/test/getMethodCode.test.js
packages/mvvm-interface-parser/test/getMethodCode.test.js
+42
-3
packages/mvvm-interface-parser/test/lib/components/methodinclude.interface
...erface-parser/test/lib/components/methodinclude.interface
+1
-0
packages/mvvm-interface-parser/test/lib/components/methodsrcerror.interface
...rface-parser/test/lib/components/methodsrcerror.interface
+1
-0
packages/mvvm-interface-parser/test/lib/components/partsrcerror.interface
...terface-parser/test/lib/components/partsrcerror.interface
+1
-0
packages/mvvm-interface-parser/test/lib/components/third/double.interface
...terface-parser/test/lib/components/third/double.interface
+2
-0
packages/mvvm-interface-parser/test/lib/components/third/include1.interface
...rface-parser/test/lib/components/third/include1.interface
+2
-0
packages/mvvm-interface-parser/test/lib/components/third/include2.interface
...rface-parser/test/lib/components/third/include2.interface
+2
-0
packages/mvvm-interface-parser/test/lib/components/third/multi.interface
...nterface-parser/test/lib/components/third/multi.interface
+2
-0
packages/mvvm-interface-parser/test/lib/components/third/not.interface
...-interface-parser/test/lib/components/third/not.interface
+1
-0
packages/mvvm-interface-parser/test/lib/components/third/third.interface
...nterface-parser/test/lib/components/third/third.interface
+0
-0
未找到文件。
packages/chameleon-tool-utils/package.json
浏览文件 @
f340c454
...
...
@@ -31,7 +31,7 @@
"main"
:
"src/index.js"
,
"name"
:
"chameleon-tool-utils"
,
"scripts"
:
{
"cover"
:
"istanbul cover --report lcov node_modules/mocha/bin/_mocha --
-R spec --recursive
"
,
"cover"
:
"istanbul cover --report lcov node_modules/mocha/bin/_mocha --
test/*.test.js test/**/*.test.js
"
,
"eslint"
:
"eslint ./src"
,
"test"
:
"mocha --recursive --reporter spec"
,
"break-test"
:
"./node_modules/.bin/mocha --inspect-brk --recursive --reporter spec"
...
...
packages/chameleon-tool-utils/src/index.js
浏览文件 @
f340c454
...
...
@@ -530,8 +530,12 @@ _.getBuildinComponents = function (cmlType, context) {
if
(
cacheBuildIn
[
cmlType
])
{
return
cacheBuildIn
[
cmlType
];
}
let
packageFilePath
=
path
.
join
(
context
,
'
node_modules
'
,
builtinNpmName
,
'
package.json
'
);
let
result
=
_
.
getOnePackageComponents
(
builtinNpmName
,
packageFilePath
,
cmlType
,
context
);
let
newNpmName
=
builtinNpmName
;
if
(
_
.
isCli
()
&&
cml
.
extPlatformPlugin
&&
cml
.
extPlatformPlugin
[
cmlType
])
{
newNpmName
=
cml
.
extPlatformPlugin
[
cmlType
].
builtinUINpmName
||
newNpmName
;
}
let
packageFilePath
=
path
.
join
(
context
,
'
node_modules
'
,
newNpmName
,
'
package.json
'
);
let
result
=
_
.
getOnePackageComponents
(
newNpmName
,
packageFilePath
,
cmlType
,
context
);
let
compileTagMap
=
{};
// 内置组件的componet name需要特殊处理,并且挂在cml上给模板编译做处理
result
.
forEach
(
item
=>
{
...
...
@@ -858,13 +862,10 @@ _.findPolymorphicComponent = function(interfacePath, content, cmlType) {
function
find
(
interfacePath
,
content
,
cmlType
)
{
let
parts
=
_
.
splitParts
({
content
});
let
include
=
null
;
let
include
=
[]
;
for
(
let
i
=
0
;
i
<
parts
.
customBlocks
.
length
;
i
++
)
{
if
(
parts
.
customBlocks
[
i
].
type
===
'
include
'
)
{
if
(
include
)
{
throw
new
Error
(
`file just allow has only one <include></include>:
${
interfacePath
}
`
)
}
include
=
parts
.
customBlocks
[
i
];
include
.
push
(
parts
.
customBlocks
[
i
]);
}
}
let
targetScript
=
null
;
...
...
@@ -890,13 +891,14 @@ _.findPolymorphicComponent = function(interfacePath, content, cmlType) {
return
sameNamePath
;
}
// include中查找
if
(
include
&&
include
.
attrs
&&
include
.
attrs
.
src
)
{
let
includeFilePath
=
_
.
resolveSync
(
interfacePath
,
include
.
attrs
.
src
);
if
(
!
_
.
isFile
)
{
for
(
let
i
=
include
.
length
-
1
;
i
>=
0
;
i
--
)
{
let
item
=
include
[
i
];
let
includeFilePath
=
_
.
resolveSync
(
interfacePath
,
item
.
attrs
.
src
);
if
(
!
_
.
isFile
(
includeFilePath
))
{
throw
new
Error
(
`
${
includeFilePath
}
is not a file in :
${
interfacePath
}
`
);
}
let
newContent
=
fs
.
readFileSync
(
includeFilePath
,
{
encoding
:
'
utf-8
'
});
return
find
(
includeFilePath
,
newContent
,
cmlType
);
return
find
(
includeFilePath
,
newContent
,
cmlType
);
}
}
...
...
@@ -974,26 +976,6 @@ _.npmComponentRefPath = function (componentAbsolutePath, context) {
}
// 已经弃用了 因为在handleComponentUrl 已经返回正确的相对路径
// 将json文件中usingComponents中的组件引用路径从绝对路径改为相对路径,export导出模式要求相对路径
// 如果是绝对路径 导出的组件只能放到项目根目录下,最后生成json文件的时候修改
_
.
convertToRelativeRef
=
function
(
jsonFilePath
,
jsonObject
)
{
// if (jsonFilePath[0] !== '/') {
// jsonFilePath = '/' + jsonFilePath;
// }
let
components
=
jsonObject
.
usingComponents
;
if
(
components
)
{
Object
.
keys
(
components
).
forEach
(
key
=>
{
let
absoluteRef
=
components
[
key
];
// plugin:// 开头不处理
if
(
absoluteRef
.
indexOf
(
'
plugin://
'
)
!==
0
)
{
let
relativePath
=
_
.
handleRelativePath
(
jsonFilePath
,
absoluteRef
);
components
[
key
]
=
relativePath
;
}
})
}
}
/**
* @param {String} sourcePath 源文件地址 绝对路径
* @param {String} targetPath 目标文件地址 绝对路径
...
...
packages/chameleon-tool-utils/test/index.test.js
浏览文件 @
f340c454
...
...
@@ -433,22 +433,6 @@ describe('index.js', function () {
})
it
(
`convertToRelativeRef`
,
function
()
{
global
.
cml
=
{};
_
.
setCli
(
true
);
cml
.
event
=
new
EventEmitter
();
cml
.
config
=
require
(
'
./testlib/cli/config.js
'
);
cml
.
utils
=
require
(
'
../src/index.js
'
);
cml
.
projectRoot
=
path
.
join
(
__dirname
,
'
testlib/demo-project
'
);
cml
.
config
.
merge
({
cmlComponents
:
[
'
cml-ui
'
]
})
let
result
=
_
.
findComponent
(
__dirname
,
'
wx
'
);
expect
(
result
).
to
.
equal
(
false
);
})
it
(
'
getDevServerPath
'
,
function
()
{
process
.
env
.
HOME
=
__dirname
;
let
devpath
=
cml
.
utils
.
getDevServerPath
();
...
...
packages/chameleon-tool-utils/test/testlib/demo-project/chameleon.config.js
浏览文件 @
f340c454
...
...
@@ -2,8 +2,7 @@
// 设置静态资源的线上路径
const
publicPath
=
'
//www.static.chameleon.com/cml
'
;
// 设置api请求前缀
const
apiPrefix
=
'
https://api.chameleon.com
'
;
const
apiPrefix
=
'
https://api.chameleon.com
'
;
cml
.
config
.
merge
({
templateLang
:
'
cml
'
,
templateType
:
'
html
'
,
...
...
packages/chameleon-tool/configs/component_export/getMiniAppExportConfig.js
浏览文件 @
f340c454
...
...
@@ -5,12 +5,16 @@ const CleanWebpackPlugin = require('clean-webpack-plugin')
var
path
=
require
(
'
path
'
);
module
.
exports
=
function
(
config
,
options
)
{
let
{
type
,
root
}
=
options
;
let
{
type
,
root
,
externals
}
=
options
;
let
outputPath
=
options
.
outputPath
||
path
.
resolve
(
root
,
`dist/export/
${
type
}
`
);
Object
.
keys
(
externals
).
forEach
(
key
=>
{
externals
[
key
]
=
`require('
${
externals
[
key
]}
')`
;
})
return
merge
(
config
,
{
output
:
{
path
:
outputPath
},
externals
,
plugins
:
[
new
CleanWebpackPlugin
([
'
./*
'
],
{
root
:
outputPath
,
verbose
:
false
})
]
...
...
packages/chameleon-tool/configs/component_export/getWeexExportConfig_new.js
浏览文件 @
f340c454
...
...
@@ -11,7 +11,8 @@ module.exports = function(options) {
let
{
media
,
root
,
mode
=
'
production
'
mode
=
'
production
'
,
externals
}
=
options
;
...
...
@@ -153,6 +154,9 @@ module.exports = function(options) {
]
}
if
(
externals
)
{
exportConfig
.
externals
=
externals
;
}
return
merge
.
smart
(
getWeexCommonConfig
(
options
),
exportConfig
)
}
packages/chameleon-tool/configs/mvvm/getExtendConfig.js
浏览文件 @
f340c454
...
...
@@ -8,13 +8,13 @@ const resolve = require('resolve');
module
.
exports
=
function
(
options
)
{
let
{
type
,
media
}
=
options
;
let
npmName
=
cml
.
config
.
get
().
extPlatform
[
type
];
// let PlatformPlugin = require(path.join(cml.projectRoot, 'node_modules', npmName)); // eslint-disable-line
let
PlatformPlugin
=
require
(
resolve
.
sync
(
npmName
,
{
basedir
:
cml
.
projectRoot
}));
// 用户端扩展插件
let
platformPlugin
=
new
PlatformPlugin
({
cmlType
:
type
,
media
});
cml
.
extPlatformPlugin
[
type
]
=
platformPlugin
;
let
extendConfig
=
{
entry
:
{
app
:
path
.
join
(
cml
.
projectRoot
,
'
src/app/app.cml
'
)
...
...
packages/chameleon-tool/configs/utils.js
浏览文件 @
f340c454
...
...
@@ -521,7 +521,8 @@ let babelNpm = [
'
webpack-check-plugin
'
,
'
webpack-liveload-middleware
'
,
'
chameleon-weex-vue-loader
'
,
'
babel-plugin-chameleon-import
'
'
babel-plugin-chameleon-import
'
,
'
mvvm-interface-parser
'
];
exports
.
getBabelPath
=
function
()
{
...
...
packages/chameleon-tool/lib/index.js
浏览文件 @
f340c454
...
...
@@ -18,7 +18,6 @@ cml.cli = cli;
cml
.
log
=
log
;
cml
.
event
=
new
EventEmitter
();
cml
.
utils
.
setCli
(
true
);
// 标识当前在chameleon-cli环境中
// cml.platform = ['wx', 'weex', 'web']; // cml 当前支持的所有平台 决定打包的执行顺序web端放到最后
cml
.
logLevel
=
argv
.
log
||
'
none
'
;
// 日志输入等级 none debug
cml
.
log
.
setLogLevel
(
cml
.
logLevel
);
...
...
@@ -35,5 +34,5 @@ if (cml.utils.isFile(configPath)) {
}
// 设置内置组件库名称
cml
.
utils
.
setBuiltinNpmName
(
cml
.
config
.
get
().
builtinNpmName
);
cml
.
extPlatformPlugin
=
{};
// 扩展端的插件对象
cml
.
cli
.
run
();
packages/easy-chameleon/npm-shrinkwrap.json
浏览文件 @
f340c454
此差异已折叠。
点击以展开。
packages/mvvm-interface-parser/index.js
浏览文件 @
f340c454
...
...
@@ -3,6 +3,7 @@ const cmlUtils = require('chameleon-tool-utils');
const
{
getCode
}
=
require
(
'
./lib/check.js
'
);
const
getInterfaceCode
=
require
(
'
./lib/getInterfaceCode.js
'
);
const
getMethodCode
=
require
(
'
./lib/getMethodCode.js
'
);
const
path
=
require
(
'
path
'
);
// resolve 用于处理interface中include文件中的引用
module
.
exports
=
function
({
cmlType
,
media
,
source
,
filePath
,
check
})
{
...
...
@@ -37,25 +38,10 @@ module.exports = function({cmlType, media, source, filePath, check }) {
}
// 将对象原型上的方法属性拷贝到对象上 解决...扩展运算符取不到值的问题
const
copyProtoPath
=
path
.
join
(
__dirname
,
'
./runtime/copyProto.js
'
);
const
copyProtoProperty
=
`
function copyProtoProperty(obj = {}) {
let EXPORT_OBJ = obj;
let EXPORT_PROTO = EXPORT_OBJ.__proto__;
if (EXPORT_PROTO.constructor !== Object) {
Object.getOwnPropertyNames(EXPORT_PROTO).forEach(key => {
if (!/constructor|prototype|length/ig.test(key)) {
// 原型上有自身没有的属性 放到自身上
if (!EXPORT_OBJ.hasOwnProperty(key)) {
EXPORT_OBJ[key] = EXPORT_PROTO[key]
}
}
})
}
return EXPORT_OBJ;
}
copyProtoProperty(exports.default)
var copyProtoProperty = require('
${
cmlUtils
.
handleRelativePath
(
filePath
,
copyProtoPath
)}
');
copyProtoProperty(exports.default);
`
result
=
`
${
result
}
...
...
packages/mvvm-interface-parser/lib/getInterfaceCode.js
浏览文件 @
f340c454
const
cmlUtils
=
require
(
'
chameleon-tool-utils
'
);
const
fs
=
require
(
'
fs
'
);
/**
* 1 先找到所有interface的定义部分
* 2 校验是否一致 如果多个路径指向同一interface 则合并依赖
*/
module
.
exports
=
function
({
interfacePath
,
content
})
{
let
devDeps
=
[];
let
result
;
let
devDeps
=
[];
// 所有interface上的路径都可能影响获取
function
getInterface
(
filePath
,
content
)
{
if
(
filePath
!==
interfacePath
)
{
...
...
@@ -12,70 +16,71 @@ module.exports = function({interfacePath, content}) {
if
(
!
content
)
{
content
=
fs
.
readFileSync
(
filePath
,
{
encoding
:
'
utf-8
'
});
}
let
parts
=
cmlUtils
.
splitParts
({
content
});
let
include
=
null
;
let
include
=
[]
;
for
(
let
i
=
0
;
i
<
parts
.
customBlocks
.
length
;
i
++
)
{
if
(
parts
.
customBlocks
[
i
].
type
===
'
include
'
)
{
if
(
include
)
{
throw
new
Error
(
`file just allow has only one <include></include>:
${
filePath
}
`
)
}
include
=
parts
.
customBlocks
[
i
];
include
.
push
(
parts
.
customBlocks
[
i
]);
}
}
let
interfaceScript
=
null
;
for
(
let
i
=
0
;
i
<
parts
.
script
.
length
;
i
++
)
{
if
(
parts
.
script
[
i
].
cmlType
===
'
interface
'
)
{
interfaceScript
=
parts
.
script
[
i
];
if
(
interfaceScript
)
{
throw
new
Error
(
`multi <script cml-type='interface'></script> has define in :
${
filePath
}
`
)
}
else
{
interfaceScript
=
parts
.
script
[
i
];
}
}
}
if
(
include
&&
interfaceScript
)
{
throw
new
Error
(
`file has <include></include> not allow has <script cml-type='interface'></script>:
${
filePath
}
`
)
}
else
if
(
include
===
null
&&
interfaceScript
)
{
return
{
filePath
:
filePath
,
part
:
interfaceScript
if
(
interfaceScript
)
{
if
(
!
result
)
{
if
(
interfaceScript
.
attrs
&&
interfaceScript
.
attrs
.
src
)
{
let
newFilePath
=
cmlUtils
.
resolveSync
(
filePath
,
interfaceScript
.
attrs
.
src
);
if
(
!
cmlUtils
.
isFile
(
newFilePath
))
{
throw
new
Error
(
`not find file:
${
newFilePath
}
`
)
}
devDeps
.
push
(
newFilePath
);
let
newContent
=
fs
.
readFileSync
(
newFilePath
,
{
encoding
:
'
utf-8
'
});
result
=
{
content
:
newContent
,
contentFilePath
:
newFilePath
};
}
else
{
result
=
{
content
:
interfaceScript
.
content
,
contentFilePath
:
filePath
};
}
}
else
{
if
(
result
.
contentFilePath
!==
filePath
)
{
throw
new
Error
(
`multi <script cml-type='interface'></script> has define in :
${
filePath
}
and
${
result
.
filePath
}
`
)
}
}
}
else
if
(
include
&&
interfaceScript
===
null
)
{
if
(
!
include
.
attrs
.
src
)
{
throw
new
Error
(
`not define src attribute:
${
filePath
}
`
)
}
include
.
forEach
(
item
=>
{
if
(
!
item
.
attrs
.
src
)
{
throw
new
Error
(
`not define include src attribute in :
${
filePath
}
`
)
}
let
newFilePath
=
cmlUtils
.
resolveSync
(
filePath
,
i
nclude
.
attrs
.
src
);
let
newFilePath
=
cmlUtils
.
resolveSync
(
filePath
,
i
tem
.
attrs
.
src
);
if
(
!
cmlUtils
.
isFile
(
newFilePath
))
{
throw
new
Error
(
`not find file:
${
newFilePath
}
`
)
}
// 递归include的文件
return
getInterface
(
newFilePath
);
}
return
null
;
getInterface
(
newFilePath
);
})
}
let
result
=
getInterface
(
interfacePath
,
content
);
getInterface
(
interfacePath
,
content
);
if
(
result
)
{
let
{
part
,
filePath
}
=
result
;
// script 有src属性的
if
(
part
.
attrs
&&
part
.
attrs
.
src
)
{
let
newFilePath
=
cmlUtils
.
resolveSync
(
filePath
,
part
.
attrs
.
src
);
if
(
!
cmlUtils
.
isFile
(
newFilePath
))
{
throw
new
Error
(
`not find file:
${
newFilePath
}
`
)
}
devDeps
.
push
(
newFilePath
);
let
newContent
=
fs
.
readFileSync
(
newFilePath
,
{
encoding
:
'
utf-8
'
});
return
{
content
:
newContent
,
devDeps
,
contentFilePath
:
newFilePath
};
}
else
{
return
{
content
:
result
.
part
.
content
,
devDeps
,
contentFilePath
:
result
.
filePath
};
}
return
{
content
:
result
.
content
,
devDeps
,
contentFilePath
:
result
.
contentFilePath
};
}
else
{
throw
new
Error
(
`not find <script cml-type='interface'></script> in
${
interfacePath
}
`
)
}
...
...
packages/mvvm-interface-parser/lib/getInterfaceCode_old.js
0 → 100644
浏览文件 @
f340c454
const
cmlUtils
=
require
(
'
chameleon-tool-utils
'
);
const
fs
=
require
(
'
fs
'
);
module
.
exports
=
function
({
interfacePath
,
content
})
{
let
devDeps
=
[];
function
getInterface
(
filePath
,
content
)
{
if
(
filePath
!==
interfacePath
)
{
devDeps
.
push
(
filePath
);
}
if
(
!
content
)
{
content
=
fs
.
readFileSync
(
filePath
,
{
encoding
:
'
utf-8
'
});
}
let
parts
=
cmlUtils
.
splitParts
({
content
});
let
include
=
null
;
for
(
let
i
=
0
;
i
<
parts
.
customBlocks
.
length
;
i
++
)
{
if
(
parts
.
customBlocks
[
i
].
type
===
'
include
'
)
{
if
(
include
)
{
throw
new
Error
(
`file just allow has only one <include></include>:
${
filePath
}
`
)
}
include
=
parts
.
customBlocks
[
i
];
}
}
let
interfaceScript
=
null
;
for
(
let
i
=
0
;
i
<
parts
.
script
.
length
;
i
++
)
{
if
(
parts
.
script
[
i
].
cmlType
===
'
interface
'
)
{
interfaceScript
=
parts
.
script
[
i
];
}
}
if
(
include
&&
interfaceScript
)
{
throw
new
Error
(
`file has <include></include> not allow has <script cml-type='interface'></script>:
${
filePath
}
`
)
}
else
if
(
include
===
null
&&
interfaceScript
)
{
return
{
filePath
:
filePath
,
part
:
interfaceScript
}
}
else
if
(
include
&&
interfaceScript
===
null
)
{
if
(
!
include
.
attrs
.
src
)
{
throw
new
Error
(
`not define src attribute:
${
filePath
}
`
)
}
let
newFilePath
=
cmlUtils
.
resolveSync
(
filePath
,
include
.
attrs
.
src
);
if
(
!
cmlUtils
.
isFile
(
newFilePath
))
{
throw
new
Error
(
`not find file:
${
newFilePath
}
`
)
}
// 递归include的文件
return
getInterface
(
newFilePath
);
}
return
null
;
}
let
result
=
getInterface
(
interfacePath
,
content
);
if
(
result
)
{
let
{
part
,
filePath
}
=
result
;
// script 有src属性的
if
(
part
.
attrs
&&
part
.
attrs
.
src
)
{
let
newFilePath
=
cmlUtils
.
resolveSync
(
filePath
,
part
.
attrs
.
src
);
if
(
!
cmlUtils
.
isFile
(
newFilePath
))
{
throw
new
Error
(
`not find file:
${
newFilePath
}
`
)
}
devDeps
.
push
(
newFilePath
);
let
newContent
=
fs
.
readFileSync
(
newFilePath
,
{
encoding
:
'
utf-8
'
});
return
{
content
:
newContent
,
devDeps
,
contentFilePath
:
newFilePath
};
}
else
{
return
{
content
:
result
.
part
.
content
,
devDeps
,
contentFilePath
:
result
.
filePath
};
}
}
else
{
throw
new
Error
(
`not find <script cml-type='interface'></script> in
${
interfacePath
}
`
)
}
}
packages/mvvm-interface-parser/lib/getMethodCode.js
浏览文件 @
f340c454
...
...
@@ -13,13 +13,10 @@ module.exports = function({interfacePath, content, cmlType}) {
}
let
parts
=
cmlUtils
.
splitParts
({
content
});
let
include
=
null
;
let
include
=
[]
;
for
(
let
i
=
0
;
i
<
parts
.
customBlocks
.
length
;
i
++
)
{
if
(
parts
.
customBlocks
[
i
].
type
===
'
include
'
)
{
if
(
include
)
{
throw
new
Error
(
`file just allow has only one <include></include>:
${
filePath
}
`
)
}
include
=
parts
.
customBlocks
[
i
];
include
.
push
(
parts
.
customBlocks
[
i
]);
}
}
let
methodScript
=
null
;
...
...
@@ -36,21 +33,21 @@ module.exports = function({interfacePath, content, cmlType}) {
}
}
if
(
include
)
{
if
(
!
include
.
attrs
.
src
)
{
throw
new
Error
(
`not define src attribute:
${
filePath
}
`
)
}
let
newFilePath
=
cmlUtils
.
resolveSync
(
filePath
,
include
.
attrs
.
src
);
if
(
!
cmlUtils
.
isFile
(
newFilePath
))
{
throw
new
Error
(
`not find file:
${
newFilePath
}
`
)
for
(
let
i
=
include
.
length
-
1
;
i
>=
0
;
i
--
)
{
let
item
=
include
[
i
];
if
(
item
)
{
if
(
!
item
.
attrs
.
src
)
{
throw
new
Error
(
`not define include src attribute:
${
filePath
}
`
)
}
let
newFilePath
=
cmlUtils
.
resolveSync
(
filePath
,
item
.
attrs
.
src
);
if
(
!
cmlUtils
.
isFile
(
newFilePath
))
{
throw
new
Error
(
`not find file:
${
newFilePath
}
`
)
}
let
newContent
=
fs
.
readFileSync
(
newFilePath
,
{
encoding
:
'
utf-8
'
})
return
getMethod
(
newFilePath
,
newContent
);
}
let
newContent
=
fs
.
readFileSync
(
newFilePath
,
{
encoding
:
'
utf-8
'
})
return
getMethod
(
newFilePath
,
newContent
);
}
return
null
;
}
...
...
packages/mvvm-interface-parser/lib/getMethodCode_old.js
0 → 100644
浏览文件 @
f340c454
const
cmlUtils
=
require
(
'
chameleon-tool-utils
'
);
const
fs
=
require
(
'
fs
'
);
const
{
resolveRequire
}
=
require
(
'
./resolveRequire.js
'
);
module
.
exports
=
function
({
interfacePath
,
content
,
cmlType
})
{
let
devDeps
=
[];
function
getMethod
(
filePath
,
content
)
{
if
(
filePath
!==
interfacePath
)
{
devDeps
.
push
(
filePath
);
}
let
parts
=
cmlUtils
.
splitParts
({
content
});
let
include
=
null
;
for
(
let
i
=
0
;
i
<
parts
.
customBlocks
.
length
;
i
++
)
{
if
(
parts
.
customBlocks
[
i
].
type
===
'
include
'
)
{
if
(
include
)
{
throw
new
Error
(
`file just allow has only one <include></include>:
${
filePath
}
`
)
}
include
=
parts
.
customBlocks
[
i
];
}
}
let
methodScript
=
null
;
for
(
let
i
=
0
;
i
<
parts
.
script
.
length
;
i
++
)
{
if
(
~
parts
.
script
[
i
].
cmlType
.
split
(
'
,
'
).
indexOf
(
cmlType
))
{
methodScript
=
parts
.
script
[
i
];
}
}
if
(
methodScript
)
{
return
{
filePath
,
part
:
methodScript
}
}
if
(
include
)
{
if
(
!
include
.
attrs
.
src
)
{
throw
new
Error
(
`not define src attribute:
${
filePath
}
`
)
}
let
newFilePath
=
cmlUtils
.
resolveSync
(
filePath
,
include
.
attrs
.
src
);
if
(
!
cmlUtils
.
isFile
(
newFilePath
))
{
throw
new
Error
(
`not find file:
${
newFilePath
}
`
)
}
let
newContent
=
fs
.
readFileSync
(
newFilePath
,
{
encoding
:
'
utf-8
'
})
return
getMethod
(
newFilePath
,
newContent
);
}
return
null
;
}
function
getRawContent
()
{
let
result
=
getMethod
(
interfacePath
,
content
);
if
(
result
)
{
let
{
part
,
filePath
}
=
result
;
// script 有src属性的
if
(
part
.
attrs
&&
part
.
attrs
.
src
)
{
let
newFilePath
=
cmlUtils
.
resolveSync
(
filePath
,
part
.
attrs
.
src
);
if
(
!
cmlUtils
.
isFile
(
newFilePath
))
{
throw
new
Error
(
`not find file:
${
newFilePath
}
`
)
}
devDeps
.
push
(
newFilePath
);
let
newContent
=
fs
.
readFileSync
(
newFilePath
,
{
encoding
:
'
utf-8
'
});
return
{
content
:
newContent
,
devDeps
,
contentFilePath
:
newFilePath
};
}
else
{
return
{
content
:
result
.
part
.
content
,
devDeps
,
contentFilePath
:
result
.
filePath
};
}
}
else
{
throw
new
Error
(
`not find <script cml-type='
${
cmlType
}
'></script> in
${
interfacePath
}
`
)
}
}
let
{
content
:
newContent
,
contentFilePath
}
=
getRawContent
();
// 需要对原有content中的所有引用路径做解析 解析为绝对路径。
return
{
content
:
resolveRequire
({
content
:
newContent
,
oldFilePath
:
contentFilePath
,
newFilePath
:
interfacePath
}),
devDeps
,
contentFilePath
}
}
packages/mvvm-interface-parser/runtime/copyProto.js
0 → 100644
浏览文件 @
f340c454
module
.
exports
=
function
copyProtoProperty
(
obj
)
{
var
EXPORT_OBJ
=
obj
||
{};
var
EXPORT_PROTO
=
Object
.
getPrototypeOf
(
EXPORT_OBJ
);
if
(
EXPORT_PROTO
.
constructor
!==
Object
)
{
Object
.
getOwnPropertyNames
(
EXPORT_PROTO
).
forEach
(
function
(
key
)
{
if
(
!
/constructor|prototype|length/ig
.
test
(
key
))
{
// 原型上有自身没有的属性 放到自身上
if
(
!
EXPORT_OBJ
.
hasOwnProperty
(
key
))
{
EXPORT_OBJ
[
key
]
=
EXPORT_PROTO
[
key
]
}
}
})
}
return
EXPORT_OBJ
;
}
packages/mvvm-interface-parser/test/copyProto.test.js
0 → 100644
浏览文件 @
f340c454
const
_
=
require
(
'
../runtime/copyProto.js
'
);
const
expect
=
require
(
'
chai
'
).
expect
;
class
A
{
fun1
()
{
console
.
log
(
'
fun1
'
)
}
}
describe
(
'
mvvm-interface-parser/getMethodCode
'
,
function
()
{
it
(
'
copyProto.js
'
,
function
()
{
var
obj
=
new
A
();
_
(
obj
);
expect
(
obj
.
hasOwnProperty
(
'
fun1
'
))
})
})
packages/mvvm-interface-parser/test/getInterfaceCode.test.js
浏览文件 @
f340c454
...
...
@@ -23,6 +23,65 @@ describe('mvvm-interface-parser/getInterfaceCode', function() {
let
contentPath
=
path
.
join
(
__dirname
,
'
./lib/components/thirdinterface.js
'
)
expect
(
result1
.
contentFilePath
).
to
.
be
.
equal
(
contentPath
)
expect
(
!!~
result1
.
devDeps
.
indexOf
(
contentPath
)).
to
.
be
.
equal
(
true
)
console
.
log
(
result1
)
})
it
(
'
getInterfaceCode not has interface
'
,
function
()
{
const
interfacePath
=
path
.
join
(
__dirname
,
'
./lib/components/third/third.interface
'
);
const
content
=
fs
.
readFileSync
(
interfacePath
,
{
encoding
:
'
utf-8
'
});
try
{
getInterfaceCode
({
interfacePath
,
content
});
}
catch
(
e
)
{
expect
(
!!~
e
.
message
.
indexOf
(
`not find <script cml-type='interface'></script>`
)).
to
.
be
.
equal
(
true
)
}
})
it
(
'
multi interface
'
,
function
()
{
const
interfacePath
=
path
.
join
(
__dirname
,
'
./lib/components/third/multi.interface
'
);
const
content
=
fs
.
readFileSync
(
interfacePath
,
{
encoding
:
'
utf-8
'
});
try
{
getInterfaceCode
({
interfacePath
,
content
});
}
catch
(
e
)
{
expect
(
!!~
e
.
message
.
indexOf
(
`multi <script cml-type='interface'></script>`
)).
to
.
be
.
equal
(
true
)
}
})
it
(
'
not has src interface
'
,
function
()
{
const
interfacePath
=
path
.
join
(
__dirname
,
'
./lib/components/third/not.interface
'
);
const
content
=
fs
.
readFileSync
(
interfacePath
,
{
encoding
:
'
utf-8
'
});
try
{
getInterfaceCode
({
interfacePath
,
content
});
}
catch
(
e
)
{
expect
(
!!~
e
.
message
.
indexOf
(
`not find file: `
)).
to
.
be
.
equal
(
true
)
}
})
it
(
'
mutli interface
'
,
function
()
{
const
interfacePath
=
path
.
join
(
__dirname
,
'
./lib/components/third/double.interface
'
);
const
content
=
fs
.
readFileSync
(
interfacePath
,
{
encoding
:
'
utf-8
'
});
try
{
getInterfaceCode
({
interfacePath
,
content
});
}
catch
(
e
)
{
expect
(
!!~
e
.
message
.
indexOf
(
`multi <script cml-type='interface'></script> has define in `
)).
to
.
be
.
equal
(
true
)
}
})
it
(
'
include src error
'
,
function
()
{
const
interfacePath
=
path
.
join
(
__dirname
,
'
./lib/components/third/include1.interface
'
);
const
content
=
fs
.
readFileSync
(
interfacePath
,
{
encoding
:
'
utf-8
'
});
try
{
getInterfaceCode
({
interfacePath
,
content
});
}
catch
(
e
)
{
expect
(
!!~
e
.
message
.
indexOf
(
`not define include src attribute in`
)).
to
.
be
.
equal
(
true
)
}
})
it
(
'
include src not file
'
,
function
()
{
const
interfacePath
=
path
.
join
(
__dirname
,
'
./lib/components/third/include2.interface
'
);
const
content
=
fs
.
readFileSync
(
interfacePath
,
{
encoding
:
'
utf-8
'
});
try
{
getInterfaceCode
({
interfacePath
,
content
});
}
catch
(
e
)
{
expect
(
!!~
e
.
message
.
indexOf
(
`not find file:`
)).
to
.
be
.
equal
(
true
)
}
})
})
packages/mvvm-interface-parser/test/getMethodCode.test.js
浏览文件 @
f340c454
...
...
@@ -3,12 +3,11 @@ const expect = require('chai').expect;
const
getMethodCode
=
require
(
'
../lib/getMethodCode.js
'
);
const
path
=
require
(
'
path
'
);
const
fs
=
require
(
'
fs
'
);
const
cmlUtils
=
require
(
'
chameleon-tool-utils
'
)
describe
(
'
mvvm-interface-parser/getMethodCode
'
,
function
()
{
it
(
'
getMethodCode
'
,
function
()
{
const
interfacePath
=
path
.
join
(
__dirname
,
'
./lib/components/second/second.interface
'
);
const
content
=
fs
.
readFileSync
(
interfacePath
,
{
encoding
:
'
utf-8
'
})
let
result1
=
getMethodCode
({
interfacePath
,
content
,
cmlType
:
'
web
'
,
resolve
:
cmlUtils
.
resolveSync
});
let
result1
=
getMethodCode
({
interfacePath
,
content
,
cmlType
:
'
web
'
});
let
firstInterfacePath
=
path
.
join
(
__dirname
,
'
./lib/components/first/first.interface
'
);
expect
(
result1
.
contentFilePath
).
to
.
be
.
equal
(
firstInterfacePath
)
expect
(
!!~
result1
.
devDeps
.
indexOf
(
firstInterfacePath
)).
to
.
be
.
equal
(
true
)
...
...
@@ -18,11 +17,51 @@ describe('mvvm-interface-parser/getMethodCode', function() {
it
(
'
getMethodCode src
'
,
function
()
{
const
interfacePath
=
path
.
join
(
__dirname
,
'
./lib/components/third.interface
'
);
const
content
=
fs
.
readFileSync
(
interfacePath
,
{
encoding
:
'
utf-8
'
})
let
result1
=
getMethodCode
({
interfacePath
,
content
,
cmlType
:
'
weex
'
,
resolve
:
cmlUtils
.
resolveSync
});
let
result1
=
getMethodCode
({
interfacePath
,
content
,
cmlType
:
'
weex
'
});
let
contentPath
=
path
.
join
(
__dirname
,
'
./lib/components/thirdmethod.js
'
);
expect
(
result1
.
contentFilePath
).
to
.
be
.
equal
(
contentPath
)
expect
(
!!~
result1
.
devDeps
.
indexOf
(
contentPath
)).
to
.
be
.
equal
(
true
)
expect
(
!!~
result1
.
content
.
indexOf
(
'
thirdmethods
'
)).
to
.
be
.
equal
(
true
);
})
it
(
'
getMethodCode include not src
'
,
function
()
{
const
interfacePath
=
path
.
join
(
__dirname
,
'
./lib/components/methodinclude.interface
'
);
const
content
=
fs
.
readFileSync
(
interfacePath
,
{
encoding
:
'
utf-8
'
});
try
{
getMethodCode
({
interfacePath
,
content
,
cmlType
:
'
weex
'
});
}
catch
(
e
)
{
expect
(
!!~
e
.
message
.
indexOf
(
`not define include src attribute:`
)).
to
.
be
.
equal
(
true
)
}
})
it
(
'
getMethodCode include src error
'
,
function
()
{
const
interfacePath
=
path
.
join
(
__dirname
,
'
./lib/components/methodsrcerror.interface
'
);
const
content
=
fs
.
readFileSync
(
interfacePath
,
{
encoding
:
'
utf-8
'
});
try
{
getMethodCode
({
interfacePath
,
content
,
cmlType
:
'
weex
'
});
}
catch
(
e
)
{
expect
(
!!~
e
.
message
.
indexOf
(
`not find file:`
)).
to
.
be
.
equal
(
true
)
}
})
it
(
'
getMethodCode not find
'
,
function
()
{
const
interfacePath
=
path
.
join
(
__dirname
,
'
./lib/components/third.interface
'
);
const
content
=
fs
.
readFileSync
(
interfacePath
,
{
encoding
:
'
utf-8
'
});
try
{
getMethodCode
({
interfacePath
,
content
,
cmlType
:
'
demo
'
});
}
catch
(
e
)
{
expect
(
!!~
e
.
message
.
indexOf
(
`not find <script cml-type=`
)).
to
.
be
.
equal
(
true
)
}
})
it
(
'
getMethodCode script src not find
'
,
function
()
{
const
interfacePath
=
path
.
join
(
__dirname
,
'
./lib/components/partsrcerror.interface
'
);
const
content
=
fs
.
readFileSync
(
interfacePath
,
{
encoding
:
'
utf-8
'
});
try
{
getMethodCode
({
interfacePath
,
content
,
cmlType
:
'
weex
'
});
}
catch
(
e
)
{
expect
(
!!~
e
.
message
.
indexOf
(
`not find file`
)).
to
.
be
.
equal
(
true
)
}
})
})
packages/mvvm-interface-parser/test/lib/components/methodinclude.interface
0 → 100644
浏览文件 @
f340c454
<include></include>
packages/mvvm-interface-parser/test/lib/components/methodsrcerror.interface
0 → 100644
浏览文件 @
f340c454
<include src="../../sdf.interfaces"></include>
\ No newline at end of file
packages/mvvm-interface-parser/test/lib/components/partsrcerror.interface
0 → 100644
浏览文件 @
f340c454
<script cml-type="weex" src="../../sdf.js"></script>
\ No newline at end of file
packages/mvvm-interface-parser/test/lib/components/third/double.interface
0 → 100644
浏览文件 @
f340c454
<include src="../third.interface"></include>
<script cml-type="interface"></script>
\ No newline at end of file
packages/mvvm-interface-parser/test/lib/components/third/include1.interface
0 → 100644
浏览文件 @
f340c454
<include>
</include>
\ No newline at end of file
packages/mvvm-interface-parser/test/lib/components/third/include2.interface
0 → 100644
浏览文件 @
f340c454
<include src="../../sdf.interface">
</include>
\ No newline at end of file
packages/mvvm-interface-parser/test/lib/components/third/multi.interface
0 → 100644
浏览文件 @
f340c454
<script cml-type="interface"></script>
<script cml-type="interface"></script>
\ No newline at end of file
packages/mvvm-interface-parser/test/lib/components/third/not.interface
0 → 100644
浏览文件 @
f340c454
<script cml-type="interface" src="../thild.interface"></script>
packages/mvvm-interface-parser/test/lib/components/third/third.interface
0 → 100644
浏览文件 @
f340c454
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录