Last active
February 13, 2024 17:41
-
-
Save zo0m/2e81102fc177fc4b4897581549b1fc85 to your computer and use it in GitHub Desktop.
replace Ti.UI.createWindow with (require("/app/ui/kit").createWindow || Ti.UI.createWindow)
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
var sourceMapper = require('./sourceMapper'); | |
var logger; | |
function log(message) { | |
if (logger) { | |
logger.info(`[fc][alloy.jmk]: ${message}`); | |
} | |
} | |
task('pre:load', (event, alloyLogger) => { | |
logger = alloyLogger; | |
projectDirectory = event.dir.project; | |
sourceMapper.OPTIONS_OUTPUT.presets = sourceMapper.OPTIONS_OUTPUT.presets || []; | |
sourceMapper.OPTIONS_OUTPUT.presets.push({ | |
plugins: [ | |
[addDefaultModule], | |
], | |
}); | |
}); | |
function addDefaultModule(_ref) { | |
log(`addDefaultModule()`) | |
var types = _ref.types; | |
const visitor = { | |
CallExpression(path) { | |
const {callee, arguments: args} = path.node; | |
const customTagsCreateNames = [ | |
'div', 'FancyButton', 'Row', 'Form' | |
].map(tag => `create${tag}`); | |
if ( | |
types.isMemberExpression(callee) && | |
callee.object && | |
callee.object.object && | |
callee.object.property && | |
types.isIdentifier(callee.object.object, {name: 'Ti'}) && | |
types.isIdentifier(callee.object.property, {name: 'UI'}) && | |
callee.property && | |
callee.property.name && | |
`${callee.property.name}`.startsWith('create') && | |
customTagsCreateNames.indexOf(`${callee.property.name}`) >= 0 | |
) { | |
const createFunctionName = callee.property.name; | |
// log(`[CallExpression] replace Ti.UI.${createFunctionName} with (require("/app/ui/kit").${createFunctionName} || Ti.UI.${createFunctionName})`); | |
// replace Ti.UI.createWindow with (require("/app/ui/kit").createWindow || Ti.UI.createWindow) | |
path.replaceWith( | |
types.callExpression( | |
types.logicalExpression( | |
'||', | |
types.memberExpression( | |
types.callExpression( | |
types.identifier('require'), | |
[types.stringLiteral('/app/ui/kit')] | |
), | |
types.identifier(createFunctionName) | |
), | |
types.memberExpression( | |
types.memberExpression( | |
types.identifier('Ti'), | |
types.identifier('UI') | |
), | |
types.identifier(createFunctionName) | |
) | |
), | |
args | |
) | |
); | |
} | |
} | |
}; | |
return { | |
pre: function (state) { | |
}, | |
visitor | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment