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

[TIMOB-19512] Updated npm deps include node-appc 0.2.32. Added alpha … #7266

Merged
merged 1 commit into from
Oct 2, 2015
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
45 changes: 31 additions & 14 deletions iphone/cli/commands/_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ var appc = require('node-appc'),
jsanalyze = require('titanium-sdk/lib/jsanalyze'),
moment = require('moment'),
path = require('path'),
pngSize = require('png-size'),
spawn = require('child_process').spawn,
ti = require('titanium-sdk'),
util = require('util'),
Expand Down Expand Up @@ -4168,18 +4167,22 @@ iOSBuilder.prototype.copyResources = function copyResources(next) {
deviceFamily = this.deviceFamily,
missingIcons = [],
defaultIcon = path.join(this.projectDir, 'DefaultIcon.png'),
defaultIconChanged = false;
defaultIconChanged = false,
defaultIconHasAlpha = false;

if (fs.existsSync(defaultIcon)) {
var defaultIconPrev = this.previousBuildManifest.files && this.previousBuildManifest.files['DefaultIcon.png'],
defaultIconStat = fs.statSync(defaultIcon),
defaultIconMtime = JSON.parse(JSON.stringify(defaultIconStat.mtime)),
defaultIconHash = this.hash(fs.readFileSync(defaultIcon));
defaultIconContents = fs.readFileSync(defaultIcon),
defaultIconHash = this.hash(defaultIconContents);

if (!defaultIconPrev || defaultIconPrev.size !== defaultIconStat.size || defaultIconPrev.mtime !== defaultIconMtime || defaultIconPrev.hash !== defaultIconHash) {
defaultIconChanged = true;
}

defaultIconHasAlpha = appc.image.pngInfo(defaultIconContents).alpha;

this.currentBuildManifest.files['DefaultIcon.png'] = {
hash: defaultIconHash,
mtime: defaultIconMtime,
Expand Down Expand Up @@ -4218,23 +4221,28 @@ iOSBuilder.prototype.copyResources = function copyResources(next) {

var meta = lookup[info.tag],
contents = fs.readFileSync(info.src),
size = pngSize(contents),
pngInfo = appc.image.pngInfo(contents),
w = meta.width * meta.scale,
h = meta.height * meta.scale;

// check that the app icon is square
if (size.width !== size.height) {
this.logger.warn(__('Skipping app icon %s because dimensions (%sx%s) are not equal', info.src.replace(this.projectDir + '/', '').cyan, size.width, size.height));
if (pngInfo.width !== pngInfo.height) {
this.logger.warn(__('Skipping app icon %s because dimensions (%sx%s) are not equal', info.src.replace(this.projectDir + '/', '').cyan, pngInfo.width, pngInfo.height));
return;
}

// validate the app icon meets the requirements
if (size.width !== w) {
this.logger.warn(__('Expected app icon %s to be %sx%s, but was %sx%s, skipping', info.src.replace(this.projectDir + '/', '').cyan, size.width, size.height, w, w));
if (pngInfo.width !== w) {
this.logger.warn(__('Expected app icon %s to be %sx%s, but was %sx%s, skipping', info.src.replace(this.projectDir + '/', '').cyan, pngInfo.width, pngInfo.height, w, w));
return;
}

this.logger.debug(__('Found valid app icon %s (%sx%s)', info.src.replace(this.projectDir + '/', '').cyan, size.width, size.height));
if (pngInfo.alpha) {
this.logger.warn(__('Skipping %s because app icons must not have an alpha channel', info.src.replace(this.projectDir + '/', '').cyan));
throw new Error();
}

this.logger.debug(__('Found valid app icon %s (%sx%s)', info.src.replace(this.projectDir + '/', '').cyan, pngInfo.width, pngInfo.height));

// inject images into the app icon set
meta.idioms.forEach(function (idiom) {
Expand Down Expand Up @@ -4274,10 +4282,15 @@ iOSBuilder.prototype.copyResources = function copyResources(next) {
}

var contents = fs.readFileSync(src),
size = pngSize(contents);
pngInfo = appc.image.pngInfo(contents);

if (pngInfo.width !== artwork.size || pngInfo.height !== artwork.size) {
this.logger.warn(__('Skipping %s because dimensions (%sx%s) are wrong; should be %sx%s', artwork.filename.cyan, pngInfo.width, pngInfo.height, artwork.size, artwork.size));
throw new Error();
}

if (size.width !== artwork.size || size.height !== artwork.size) {
this.logger.warn(__('Skipping %s because dimensions (%sx%s) are wrong; should be %sx%s', artwork.filename.cyan, size.width, size.height, artwork.size, artwork.size));
if (pngInfo.alpha) {
this.logger.warn(__('Skipping %s because iTunesArtwork must not have an alpha channel', artwork.filename.cyan));
throw new Error();
}

Expand Down Expand Up @@ -4329,9 +4342,9 @@ iOSBuilder.prototype.copyResources = function copyResources(next) {
// check if the icon was previously resized
if (!defaultIconChanged && fs.existsSync(dest)) {
var contents = fs.readFileSync(dest),
size = pngSize(contents);
pngInfo = appc.image.pngInfo(contents);

if (size.width === width && size.height === height) {
if (pngInfo.width === width && pngInfo.height === height) {
this.logger.trace(__('Found generated %sx%s app icon: %s', width, height, dest.cyan));
// icon looks good, no need to generate it!
return;
Expand All @@ -4353,6 +4366,10 @@ iOSBuilder.prototype.copyResources = function copyResources(next) {
writeAssetContentsFile.call(this, path.join(appIconSetDir, 'Contents.json'), appIconSet);

if (missingIcons.length) {
if (defaultIconHasAlpha) {
return next(new Error(__('DefaultIcon.png cannot be used because it contains an alpha channel')));
}

this.logger.debug(__n(
'Missing %s app icon, generating missing icon',
'Missing %s app icons, generating missing icons',
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.