Skip to content
This repository was archived by the owner on Jan 14, 2022. It is now read-only.

Commit 6e9d028

Browse files
committed
Merge pull request #2 from manifoldjs/dev-0.5.0-default-fix
add filter so default images don't get moved if they are not needed
2 parents 3fc1322 + f6b1eb7 commit 6e9d028

File tree

3 files changed

+43
-15
lines changed

3 files changed

+43
-15
lines changed

lib/fileTools.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,15 @@ function syncFiles (source, target, options, callback) {
207207
if (info.isDirectory()) {
208208
return syncFiles(sourceFile, path.join(target, fileOrDir));
209209
}
210-
210+
211+
// check to see if file should be skipped
212+
if (options.filter) {
213+
var check = options.filter(fileOrDir);
214+
if (check === false) {
215+
return;
216+
}
217+
}
218+
211219
// synchronize a single file
212220
var targetFile = path.join(target, fileOrDir);
213221
return syncFile(sourceFile, targetFile);

lib/platformBase.js

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ function PlatformBase (id, name, packageName, baseDir) {
9999

100100
/**
101101
* Returns an array of icons files as defined in the manifest. The method assumes that all icons
102-
* are defined as properties of an 'icons' member, for example:
102+
* are are square and defined as properties of an 'icons' member, for example:
103103
* "icons": {
104104
* "30": "/images/smalllogo.png",
105105
* "50": "/images/storelogo.png",
@@ -112,8 +112,25 @@ function PlatformBase (id, name, packageName, baseDir) {
112112
};
113113

114114
/**
115-
* Adds an icon file to the manifest. The method assumes that all icons are
116-
* defined as properties of an 'icons' member, for example:
115+
* Receives the size (e.g. '50x50') of an icon and returns the corresponding icon element
116+
* from the manifest or undefined if not found. The method assumes that all icons
117+
* are square and defined as properties of an 'icons' member, for example:
118+
* "icons": {
119+
* "30": "/images/smalllogo.png",
120+
* "50": "/images/storelogo.png",
121+
* "150": "/images/logo.png"
122+
* }
123+
* Platforms should override this method if the manifest icons use a different format.
124+
*/
125+
self.getManifestIcon = function (manifest, size) {
126+
// assumes icons are square
127+
var dimensions = size.toLowerCase().split('x');
128+
return manifest.icons && manifest.icons[dimensions[0]];
129+
};
130+
131+
/**
132+
* Adds an icon file with the specified size (e.g. '50x50') to the manifest. The method
133+
* assumes that all icons are square and defined as properties of an 'icons' member, for example:
117134
* "icons": {
118135
* "30": "/images/smalllogo.png",
119136
* "50": "/images/storelogo.png",
@@ -141,9 +158,6 @@ function PlatformBase (id, name, packageName, baseDir) {
141158
var iconList = manifest.icons;
142159
return Q.resolve().then(function () {
143160
if (iconList) {
144-
// var icons = Array.isArray(iconList) ?
145-
// iconList.map(function (icon) { return icon.src; }) :
146-
// Object.keys(iconList).map(function (size) { return manifest.icons[size]; });
147161
var icons = self.getManifestIcons(manifest);
148162

149163
var downloadTasks = icons.map(function (icon) {
@@ -166,7 +180,15 @@ function PlatformBase (id, name, packageName, baseDir) {
166180
// copy default platform icons to replace any missing icons
167181
.then(function () {
168182
var defaultImagesDir = path.join(self.baseDir, 'assets', 'images');
169-
return fileTools.syncFiles(defaultImagesDir, imagesDir).then(function (files) {
183+
return fileTools.syncFiles(defaultImagesDir, imagesDir, {
184+
// filter out default images that do not need to be moved over
185+
filter: function (file) {
186+
// determine the icon dimensions assuming a convention where
187+
// the file name specifies the icon's size (e.g. '50x50.png')
188+
var size = path.basename(file, path.extname(file));
189+
return !self.getManifestIcon(manifest, size);
190+
}
191+
}).then(function (files) {
170192
files.forEach(function (file) {
171193
// make path relative to imagesDir
172194
var filePath = path.relative(imagesDir, file);
@@ -181,7 +203,7 @@ function PlatformBase (id, name, packageName, baseDir) {
181203
return Q.reject(err);
182204
}
183205

184-
self.warn('No default icons were found to copy for the \'' + self.id + '\' platform.');
206+
self.debug('No default icons were found to copy for the \'' + self.id + '\' platform.');
185207
});
186208
})
187209
.nodeify(callback);

lib/processTools.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ function getCommandPath(currentPath, command) {
127127
return undefined;
128128
}
129129

130-
var testPath = path.join(currentPath, 'node_modules', '.bin', command);
130+
var testPath = path.join(currentPath, node_modules, '.bin', command);
131131
return Q.nfcall(fs.stat, testPath).then(function (fileInfo) {
132132
if (fileInfo.isFile()) {
133133
return Q.resolve(testPath);
@@ -137,16 +137,14 @@ function getCommandPath(currentPath, command) {
137137
return Q.reject(err);
138138
}
139139

140-
currentPath = currentPath.substring(0, currentPath.lastIndexOf(path.sep));
140+
currentPath = currentPath.substring(0, currentPath.lastIndexOf(path.sep));
141141
if (currentPath.indexOf(node_modules) >= 0) {
142142
if (currentPath.substr(currentPath.length - node_modules.length) === node_modules) {
143143
currentPath = currentPath.substring(0, currentPath.length - node_modules.length);
144-
}
145-
146-
return getCommandPath(currentPath, command);
144+
}
147145
}
148146

149-
return undefined;
147+
return getCommandPath(currentPath, command);
150148
});
151149
}
152150

0 commit comments

Comments
 (0)