-
Notifications
You must be signed in to change notification settings - Fork 694
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chameleon-loader prepareParseUsingComponents
- Loading branch information
yangyiliang
committed
Jan 25, 2019
1 parent
91b4d0a
commit 21e0709
Showing
6 changed files
with
86 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
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') | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
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); | ||
} | ||
}) | ||
}) | ||
}) | ||
|
||
|
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters