Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DiDi
Chameleon
提交
21e07093
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,发现更多精彩内容 >>
提交
21e07093
编写于
1月 25, 2019
作者:
Y
yangyiliang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
chameleon-loader prepareParseUsingComponents
上级
91b4d0ac
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
86 addition
and
18 deletion
+86
-18
packages/chameleon-loader/src/loader.js
packages/chameleon-loader/src/loader.js
+6
-16
packages/chameleon-loader/src/loaderMethods.js
packages/chameleon-loader/src/loaderMethods.js
+20
-0
packages/chameleon-loader/test/src/loaderMethods.test.js
packages/chameleon-loader/test/src/loaderMethods.test.js
+58
-0
packages/chameleon-loader/test/src/project/src/components/com1.cml
...chameleon-loader/test/src/project/src/components/com1.cml
+0
-0
packages/chameleon-loader/test/src/project/src/pages/page1.cml
...ges/chameleon-loader/test/src/project/src/pages/page1.cml
+0
-0
packages/chameleon-tool-utils/src/index.js
packages/chameleon-tool-utils/src/index.js
+2
-2
未找到文件。
packages/chameleon-loader/src/loader.js
浏览文件 @
21e07093
...
@@ -15,6 +15,7 @@ var jsonHandler = require('./cml-compile/json-handle.js');
...
@@ -15,6 +15,7 @@ var jsonHandler = require('./cml-compile/json-handle.js');
const
{
getScriptCode
}
=
require
(
'
./interface-check/getScriptCode.js
'
);
const
{
getScriptCode
}
=
require
(
'
./interface-check/getScriptCode.js
'
);
const
cmlUtils
=
require
(
'
chameleon-tool-utils
'
);
const
cmlUtils
=
require
(
'
chameleon-tool-utils
'
);
const
prehandle
=
require
(
'
./utils/prehandle.js
'
);
const
prehandle
=
require
(
'
./utils/prehandle.js
'
);
const
loaderMethods
=
require
(
'
./loaderMethods
'
);
let
jsonObject
=
{};
let
jsonObject
=
{};
module
.
exports
=
function
(
content
)
{
module
.
exports
=
function
(
content
)
{
...
@@ -442,24 +443,13 @@ module.exports = function (content) {
...
@@ -442,24 +443,13 @@ module.exports = function (content) {
* }]
* }]
*/
*/
function
prepareParseUsingComponents
(
originObj
)
{
function
prepareParseUsingComponents
(
originObj
)
{
return
Object
.
keys
(
originObj
).
map
(
key
=>
{
return
loaderMethods
.
prepareParseUsingComponents
({
let
value
=
originObj
[
key
];
loaderContext
:
self
,
let
{
filePath
,
refUrl
}
=
cmlUtils
.
handleComponentUrl
(
context
,
self
.
resourcePath
,
value
,
cmlType
);
context
,
// 如果是node_modules中的refUrl中会变成npm,替换成node_modules后再查找组件
originObj
,
if
(
~
value
.
indexOf
(
'
/npm
'
)
&&
filePath
===
''
)
{
cmlType
value
=
value
.
replace
(
'
/npm/
'
,
'
/node_modules/
'
);
filePath
=
cmlUtils
.
handleComponentUrl
(
context
,
self
.
resourcePath
,
value
,
cmlType
).
filePath
;
}
return
{
tagName
:
key
,
refUrl
,
filePath
,
isNative
:
!
filePath
.
endsWith
(
'
.cml
'
)
}
})
})
}
}
// done
// done
return
output
return
output
}
}
...
...
packages/chameleon-loader/src/loaderMethods.js
0 → 100644
浏览文件 @
21e07093
const
cmlUtils
=
require
(
'
chameleon-tool-utils
'
);
exports
.
prepareParseUsingComponents
=
function
({
loaderContext
,
context
,
originObj
,
cmlType
})
{
return
Object
.
keys
(
originObj
).
map
(
key
=>
{
let
value
=
originObj
[
key
];
let
{
filePath
,
refUrl
}
=
cmlUtils
.
handleComponentUrl
(
context
,
loaderContext
.
resourcePath
,
value
,
cmlType
);
// 如果是node_modules中的refUrl中会变成npm,替换成/node_modules/后再查找组件
if
(
~
value
.
indexOf
(
'
/npm
'
)
&&
filePath
===
''
)
{
value
=
value
.
replace
(
/
(
.*
?)
npm
\/
/g
,
'
/node_modules/
'
);
filePath
=
cmlUtils
.
handleComponentUrl
(
context
,
loaderContext
.
resourcePath
,
value
,
cmlType
).
filePath
;
}
return
{
tagName
:
key
,
refUrl
,
filePath
,
isNative
:
!
filePath
.
endsWith
(
'
.cml
'
)
}
})
}
packages/chameleon-loader/test/src/loaderMethods.test.js
0 → 100644
浏览文件 @
21e07093
const
loaderMethods
=
require
(
'
../../src/loaderMethods.js
'
);
const
expect
=
require
(
'
chai
'
).
expect
;
const
path
=
require
(
'
path
'
);
describe
(
'
prepareParseUsingComponents
'
,
function
(){
it
(
'
/npm/
'
,
function
()
{
let
originObj
=
{
scroller
:
'
/npm/cml-ui/scroller/scroller
'
}
let
loaderContext
=
{
resourcePath
:
path
.
join
(
__dirname
,
'
./project/src/pages/page1.cml
'
)
}
let
context
=
path
.
join
(
__dirname
,
'
./project
'
);
let
result
=
loaderMethods
.
prepareParseUsingComponents
({
loaderContext
,
context
,
originObj
,
cmlType
:
'
wx
'
});
let
expectPath
=
path
.
join
(
__dirname
,
'
./project/node_modules/cml-ui/scroller/scroller.cml
'
)
console
.
log
(
result
)
result
.
forEach
(
item
=>
{
if
(
item
.
tagName
===
'
scroller
'
)
{
expect
(
item
.
filePath
).
to
.
be
.
equal
(
expectPath
);
expect
(
item
.
isNative
).
to
.
be
.
equal
(
false
);
}
})
})
it
(
'
../npm/
'
,
function
()
{
let
originObj
=
{
scroller
:
'
./../npm/cml-ui/scroller/scroller
'
}
let
loaderContext
=
{
resourcePath
:
path
.
join
(
__dirname
,
'
./project/src/pages/page1.cml
'
)
}
let
context
=
path
.
join
(
__dirname
,
'
./project
'
);
let
result
=
loaderMethods
.
prepareParseUsingComponents
({
loaderContext
,
context
,
originObj
,
cmlType
:
'
wx
'
});
let
expectPath
=
path
.
join
(
__dirname
,
'
./project/node_modules/cml-ui/scroller/scroller.cml
'
)
result
.
forEach
(
item
=>
{
if
(
item
.
tagName
===
'
scroller
'
)
{
expect
(
item
.
filePath
).
to
.
be
.
equal
(
expectPath
);
expect
(
item
.
isNative
).
to
.
be
.
equal
(
false
);
}
})
})
})
packages/chameleon-loader/test/src/project/src/components/com1.cml
0 → 100644
浏览文件 @
21e07093
packages/chameleon-loader/test/src/project/src/pages/page1.cml
0 → 100644
浏览文件 @
21e07093
packages/chameleon-tool-utils/src/index.js
浏览文件 @
21e07093
...
@@ -732,7 +732,7 @@ _.findInterfaceFile = function(context, cmlFilePath, comPath) {
...
@@ -732,7 +732,7 @@ _.findInterfaceFile = function(context, cmlFilePath, comPath) {
_
.
npmComponentRefPath
=
function
(
componentAbsolutePath
,
context
)
{
_
.
npmComponentRefPath
=
function
(
componentAbsolutePath
,
context
)
{
let
refUrl
=
''
;
let
refUrl
=
''
;
refUrl
=
path
.
relative
(
context
,
componentAbsolutePath
);
refUrl
=
path
.
relative
(
context
,
componentAbsolutePath
);
refUrl
=
refUrl
.
replace
(
'
node_modules
'
,
'
npm
'
);
refUrl
=
refUrl
.
replace
(
/node_modules/g
,
'
npm
'
);
refUrl
=
_
.
handleWinPath
(
refUrl
);
refUrl
=
_
.
handleWinPath
(
refUrl
);
if
(
refUrl
[
0
]
!==
'
/
'
)
{
if
(
refUrl
[
0
]
!==
'
/
'
)
{
refUrl
=
'
/
'
+
refUrl
refUrl
=
'
/
'
+
refUrl
...
@@ -893,7 +893,7 @@ _.getEntryPath = function (filePath, context) {
...
@@ -893,7 +893,7 @@ _.getEntryPath = function (filePath, context) {
let
entryName
;
let
entryName
;
if
(
~
filePath
.
indexOf
(
'
node_modules
'
))
{
if
(
~
filePath
.
indexOf
(
'
node_modules
'
))
{
entryName
=
path
.
relative
(
root
,
filePath
);
entryName
=
path
.
relative
(
root
,
filePath
);
entryName
=
entryName
.
replace
(
'
node_modules
'
,
'
npm
'
);
entryName
=
entryName
.
replace
(
/node_modules/g
,
'
npm
'
);
}
else
{
}
else
{
entryName
=
path
.
relative
(
projectPath
,
filePath
);
entryName
=
path
.
relative
(
projectPath
,
filePath
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录