-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(okam-build): add toutiao mini program support
- Loading branch information
Showing
41 changed files
with
433 additions
and
267 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ test/example/ | |
test/test.js | ||
wx_dist | ||
ant_dist | ||
tt_dist | ||
node_modules |
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,19 @@ | ||
/** | ||
* @file Build wx mini program config | ||
* @author xxx | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const merge = require('../../../').merge; | ||
|
||
module.exports = merge({}, require('./base.config'), { | ||
output: { | ||
dir: 'tt_dist', | ||
depDir: 'src/common' | ||
}, | ||
localPolyfill: [ | ||
'async', | ||
'promise' | ||
] | ||
}); |
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,49 @@ | ||
/** | ||
* @file The config for building toutiao mini program | ||
* @author [email protected] | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const merge = require('../util').merge; | ||
const baseConf = require('./base'); | ||
|
||
module.exports = merge({}, baseConf, { | ||
output: { | ||
|
||
/** | ||
* 输出的文件路径映射定义 | ||
* | ||
* @type {Object} | ||
*/ | ||
pathMap: { | ||
projectConfig: 'project.config.json', | ||
entryScript: 'app.js', | ||
entryStyle: 'app.ttss', | ||
appConfig: 'app.json' | ||
}, | ||
|
||
/** | ||
* 输出的自定义组件各个部分文件的后缀名 | ||
* | ||
* @type {Object} | ||
*/ | ||
componentPartExtname: { | ||
script: 'js', | ||
style: 'ttss', | ||
tpl: 'ttml', | ||
config: 'json' | ||
} | ||
}, | ||
|
||
processors: { | ||
cssImport: { | ||
processor: 'postcss', // using the existed postcss processor | ||
extnames: ['ttss'], | ||
rext: 'ttss', | ||
options: { | ||
plugins: ['cssImport'] | ||
} | ||
} | ||
} | ||
}); |
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
8 changes: 8 additions & 0 deletions
8
packages/okam-build/lib/processor/template/plugins/event/tt-event-plugin.js
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,8 @@ | ||
/** | ||
* @file Toutiao template event attribute transform plugin | ||
* @author [email protected] | ||
*/ | ||
|
||
'use strict'; | ||
|
||
module.exports = require('./swan-event-plugin'); |
12 changes: 12 additions & 0 deletions
12
packages/okam-build/lib/processor/template/plugins/tt-syntax-plugin.js
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,12 @@ | ||
/** | ||
* @file Mini program view template syntax transform plugin: okam syntax -> toutiao syntax | ||
* @author [email protected] | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const {createSyntaxPlugin} = require('./helper'); | ||
const transformers = require('../transform/tt'); | ||
|
||
module.exports = createSyntaxPlugin(transformers); | ||
|
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
32 changes: 0 additions & 32 deletions
32
packages/okam-build/lib/processor/template/transform/ant/data-bind.js
This file was deleted.
Oops, something went wrong.
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
35 changes: 9 additions & 26 deletions
35
packages/okam-build/lib/processor/template/transform/ant/key.js
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 |
---|---|---|
@@ -1,32 +1,15 @@ | ||
/** | ||
* @file 解析支付宝小程序的key | ||
* @author zhoudan03 | ||
* @file Transform ant for key syntax | ||
* @author [email protected] | ||
*/ | ||
|
||
module.exports = function (attrs, name, tplOpts) { | ||
let {logger, file} = tplOpts; | ||
const itemName = attrs['a:for-item'] || 'item'; | ||
let value = attrs[name]; | ||
'use strict'; | ||
|
||
// a:key的值只允许以下两种情况,否则不做处理,但给出警告 | ||
// 1.用*this标识遍历数组的元素自身, | ||
// 2.用遍历数组的元素的属性名称 | ||
if (value === itemName) { | ||
value = '*this'; | ||
} | ||
else if (value.includes('.')) { | ||
const array = value.split('.'); | ||
if (array[0] === itemName) { | ||
value = array[1]; | ||
} | ||
else { | ||
logger.warn(`${file.path} key value '${attrs[name]}' maybe not valid`); | ||
} | ||
} | ||
else { | ||
logger.warn(`${file.path} key value '${attrs[name]}' maybe not valid`); | ||
} | ||
const transformKey = require('../base/key'); | ||
|
||
attrs['a:key'] = value; | ||
delete attrs[':key']; | ||
module.exports = function (attrs, name, tplOpts, opts) { | ||
transformKey(attrs, name, tplOpts, Object.assign({ | ||
forItemDirectiveName: 'a:for-item', | ||
forKeyDirectiveName: 'a:key' | ||
}, opts)); | ||
}; |
28 changes: 6 additions & 22 deletions
28
packages/okam-build/lib/processor/template/transform/ant/tpl.js
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 |
---|---|---|
@@ -1,30 +1,14 @@ | ||
/** | ||
* @file Transform include/import tpl syntax | ||
* @file Transform ant tpl syntax | ||
* @author [email protected] | ||
*/ | ||
|
||
'use strict'; | ||
|
||
/* eslint-disable fecs-min-vars-per-destructure */ | ||
const {PLAIN_OBJECT_REGEXP} = require('../base/constant'); | ||
const DATA_ATTR = ':data'; | ||
const transformTpl = require('../base/tpl'); | ||
|
||
module.exports = function transformTplElement(element, tplOpts) { | ||
element.name = 'template'; | ||
|
||
let {attribs: attrs} = element; | ||
if (!attrs.hasOwnProperty(DATA_ATTR)) { | ||
return; | ||
} | ||
|
||
let dataValue = attrs[DATA_ATTR]; | ||
if (typeof dataValue === 'string') { | ||
dataValue = dataValue.trim(); | ||
if (PLAIN_OBJECT_REGEXP.test(dataValue)) { | ||
dataValue = `{${dataValue}}`; | ||
} | ||
} | ||
|
||
delete attrs[DATA_ATTR]; | ||
attrs.data = dataValue; | ||
module.exports = function (attrs, name, tplOpts, opts) { | ||
transformTpl(attrs, name, tplOpts, Object.assign({ | ||
transformDataAttr: true | ||
}, opts)); | ||
}; |
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
Oops, something went wrong.