Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ALOY-378b] fix copying order so that platform assets take precedence #381

Merged
merged 1 commit into from
May 2, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions Alloy/commands/compile/compilerUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,10 @@ exports.inspectRequireNode = function(node) {

exports.copyWidgetResources = function(resources, resourceDir, widgetId, opts) {
opts = opts || {};
var platform;
if (compilerConfig && compilerConfig.alloyConfig && compilerConfig.alloyConfig.platform) {
platform = compilerConfig.alloyConfig.platform;
}
_.each(resources, function(dir) {
if (!path.existsSync(dir)) { return; }
logger.trace('WIDGET_SRC=' + path.relative(compilerConfig.dir.project, dir));
Expand Down Expand Up @@ -568,6 +572,28 @@ exports.copyWidgetResources = function(resources, resourceDir, widgetId, opts) {
});
logger.trace(' ');
});
if(opts.theme) {
// if this widget has been themed, copy its theme assets atop the stock ones
var widgetThemeDir = path.join(compilerConfig.dir.project, 'app', 'themes', opts.theme, 'widgets', widgetId);
if(fs.existsSync(widgetThemeDir)) {
logger.trace('Processing themed widgets');
var widgetAssetSourceDir = path.join(widgetThemeDir, 'assets');
var widgetAssetTargetDir = path.join(resourceDir, widgetId);
if(fs.existsSync(widgetAssetSourceDir)) {
wrench.copyDirSyncRecursive(widgetAssetSourceDir, widgetAssetTargetDir, {preserve: true});
}
// platform-specific assets from the widget must override those of the theme
if(platform && path.existsSync(path.join(resources[0], platform))) {
wrench.copyDirSyncRecursive(path.join(resources[0], platform), widgetAssetTargetDir, {preserve: true});
}
// however platform-specific theme assets must override the platform assets from the widget
if(platform && path.existsSync(path.join(widgetAssetSourceDir, platform))) {
logger.trace('Processing platform-specific theme assets for the ' + widgetId + ' widget');
widgetAssetSourceDir = path.join(widgetAssetSourceDir, platform);
wrench.copyDirSyncRecursive(widgetAssetSourceDir, widgetAssetTargetDir, {preserve: true});
}
}
}
};

function updateImplicitNamspaces(platform) {
Expand Down
33 changes: 2 additions & 31 deletions Alloy/commands/compile/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,36 +266,6 @@ module.exports = function(args, program) {
}
});
}
if(collection.manifest && theme) {
// this is a widget and a theme is being applied
if(fs.existsSync(path.join(paths.app, 'themes', theme, 'widgets', collection.manifest.id, 'assets'))) {
// the widget has been themed and has assets to copy
logger.info('Processing theme assets for ' + collection.manifest.id + ' widget');
var widgetAssetSourceDir = path.join(paths.app, 'themes', theme, 'widgets', collection.manifest.id, 'assets');
var widgetAssetTargetDir = path.join(paths.resources, titaniumFolder, collection.manifest.id);
logger.info('>>>>> widgetAssetSourceDir: ' + widgetAssetSourceDir);
logger.info('>>>>> widgetAssetTargetDir: ' + widgetAssetTargetDir);
_.each(fs.readdirSync(widgetAssetSourceDir), function(file) {
if((fs.statSync(path.join(widgetAssetSourceDir, file))).isFile()) {
logger.info('>>>>> file: ' + file);
fs.writeFileSync(path.join(widgetAssetTargetDir, file), fs.readFileSync(path.join(widgetAssetSourceDir, file), {encoding:'binary'}), {encoding:'binary'});
}
});
logger.info('---------------------------');
// check for platform-specifc assets and copy them if they exist
if(fs.existsSync(path.join(paths.app, 'themes', theme, 'widgets', collection.manifest.id, 'assets', buildPlatform))) {
widgetAssetSourceDir = path.join(paths.app, 'themes', theme, 'widgets', collection.manifest.id, 'assets', buildPlatform);
logger.info('>>>>> widgetAssetSourceDir: ' + widgetAssetSourceDir);
logger.info('Processing platform-specific theme assets for ' + collection.manifest.id + ' widget');
_.each(fs.readdirSync(widgetAssetSourceDir), function(file) {
if((fs.statSync(path.join(widgetAssetSourceDir, file))).isFile()) {
logger.info('>>>>> file: ' + file);
fs.writeFileSync(path.join(widgetAssetTargetDir, file), fs.readFileSync(path.join(widgetAssetSourceDir, file), {encoding:'binary'}), {encoding:'binary'});
}
});
}
}
}
});
logger.info('');

Expand Down Expand Up @@ -681,7 +651,8 @@ function parseAlloyComponent(view, dir, manifest, noView) {
{
filter: new RegExp('^(?:' + otherPlatforms.join('|') + ')[\\/\\\\]'),
exceptions: otherPlatforms,
titaniumFolder: titaniumFolder
titaniumFolder: titaniumFolder,
theme: theme
}
);
targetFilepath = path.join(
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.