function buildConfigChanged(previous, current) { if (current.REBUILD == 1) { utils.log('rebuild', 'rebuild forced by use of special env like' + 'LOCALE_BASEDIR, GAIA_DISTRIBUTION_DIR or REBUILD'); return true; } let flags = []; // We don't detect FLAGS in blacklist because we don't have to rebuild again // if someone specifies them. let blacklist = ['REBUILD', 'P', 'VERBOSE']; for (let flag in current) { if (blacklist.indexOf(flag) === -1 && current[flag] !== previous[flag]) { flags.push(flag); } } if (flags.length > 0) { utils.log('rebuild', 'build config has been changed: ' + flags.join(', ')); } return flags.length > 0; }
locales.forEach(function(locale, index) { if (manifest.entry_points) { // localization for entry_points in manifest. for (var name in manifest.entry_points) { var ep = manifest.entry_points[name]; if (!ep.locales) { utils.log(MODNAME, 'locales field doesn\'t exist in entry point "' + name + '" in ' + manifest.name + ' manifest file.'); isEntryPointsTranslated = false; continue; } if (!localesProps[index].entry_points[name]) { utils.log(MODNAME, 'Translation of ' + locale + ' is not ' + 'available for entry point "' + name + '" in ' + manifest.name + ' manifest file.'); isEntryPointsTranslated = false; continue; } ep.locales[locale] = localesProps[index].entry_points[name]; } } if (manifest.locales) { manifest.locales[locale] = localesProps[index].default; } else if (!isEntryPointsTranslated) { utils.log(MODNAME, 'locales field doesn\'t exist in ' + manifest.name + ' manifest file.'); } });
_localFetcher: function () { var memory = utils.prefs(this.type), version_property = (this.type == 'bugs' ? 'version' : (this.type + 'Version')); // nothing in storage, or it's so old it doesn't have a version if (!memory || !memory.hasOwnProperty(version_property)) { // return what's on disk utils.log('fetching ' + this.type + ' from disk'); return JSON.parse(utils.syncGet('databases/' + this.type + '.json')); } // on upgrades, see if bugs.json shipped w/ the extension is more recent if (this.just_upgraded) { var disk = JSON.parse(utils.syncGet('databases/' + this.type + '.json')); // when upgrading from a version with hash instead of timestamp, return disk if (typeof memory[this.type + 'Version'] !== 'number') { utils.log('fetching ' + this.type + ' from disk'); return disk; } if (disk[version_property] > memory[version_property]) { utils.log('fetching ' + this.type + ' from disk'); return disk; } } utils.log('fetching ' + this.type + ' from memory'); return memory; },
doAddTaskDone:function(data){ isTaskSubmiting = false; var self = this; if(data.resp){ try{ var ret = data.resp.ret; var _errorMsg = ''; if(ret==0){ var _res = data.resp.res; var _len = _res.length; var addedNum = 0 var addedIndexs = []; var oi; var link; for( var i=0; i<_len; i++ ){ if( _res[i].result == 0 ){ if( typeof addingTasks[_res[i].id] !== 'undefined' ){ oi = addingTasks[_res[i].id]; link = DataManager.oriResources(oi); link.isAdded = true; addedIndexs.push({index:oi, item:link}) } addedNum ++ ; }else if( _res[i].result == 8 ){ _errorMsg = taskTips.urlNotVideo; }else if( _res[i].result == 6 || _res[i].result == 2 ){ _errorMsg = taskTips.paramError; }else{ _errorMsg = taskTips.svrError; } } addedNum > 0 ? DataManager.noticeController( DataEventTypes.AddListStateChangeEvent, { param : 'added', urls:addedIndexs }) : DataManager.noticeController( DataEventTypes.AddListStateChangeEvent, {param : 'error', urls:addedIndexs }); return; /* if( addedNum == 0 ) _errorMsg = taskTips.taskContainsError; base.log([2,_errorMsg]);*/ //DataManager.noticeController( DataEventTypes.AddListStateChangeEvent, {param : 'error'} ); }else{ if(ret==1){ _errorMsg = taskTips.userInfoError; } else if(ret==3) _errorMsg = taskTips.timeout; else _errorMsg = taskTips.svrError; DataManager.noticeController( DataEventTypes.AddListStateChangeEvent, {param : 'error', urls:[] }); base.log(_errorMsg); } }catch(e){ DataManager.noticeController( DataEventTypes.AddListStateChangeEvent, {param : 'error', urls:[] }); } }else{ _errorMsg = taskTips.svrError; base.log(_errorMsg); DataManager.noticeController( DataEventTypes.AddListStateChangeEvent, {param : 'error', urls:[] }); } },
module.exports = function(request,response) { try { var requestUrl = url.parse(request.url) var path = requestUrl.pathname var params = querystring.parse(requestUrl.query) var headers = request.headers // note: http lowers case for us so we don't have to worry about case-insensitivity var body = getRequestBody(request).wait() utils.log("path " + path) var explicitHandler = explicitRouting(path, headers) // case ins var resourcesHandler = resourcesRouting(path, headers) var handler = explicitHandler || resourcesHandler // explicit handler is default if(explicitHandler && resourcesHandler) { utils.log("ERROR: Explicit and implicit routes found for path "+path) } if(handler) { var result = handler(params, body.toString('utf8')) } else { var result = {code: 404, body: "You must be lost"} } } catch(e) { var result = {code: 500, body: "Sorry, something broke - we'll fix it soon!"} utils.log("Something borked: ",e) } writeResponse(result, response) }
function(enabledLayoutIds, downloadableLayoutIds) { var enabledLayoutIdSet = this._expandLayoutIdSet(enabledLayoutIds); var downloadableLayoutIdSet = this._expandLayoutIdSet(downloadableLayoutIds); utils.log('keyboard-load-layouts', 'The enabled layouts are set to: ' + [...enabledLayoutIdSet].join(', ')); utils.log('keyboard-load-layouts', 'The downloadable layouts are set to: ' + [...downloadableLayoutIdSet].join(', ')); if (enabledLayoutIdSet.size === 0) { throw new Error('KeyboardLayoutConfigurator: No layout specified?'); } this.layoutDetails = []; // We need to track the dict separately here -- // because we want to set all layouts using the same dictionary to be // considered preloaded. var imEngineDictIdSet = new Set(); enabledLayoutIdSet.forEach(function(layoutId) { var detail = new KeyboardLayoutDetail(layoutId); detail.load(this.appDir); if (detail.dictFile) { imEngineDictIdSet.add(detail.imEngineId + '/' + detail.dictFilePath); } this.layoutDetails.push(detail); }, this); downloadableLayoutIdSet.forEach(function(layoutId) { if (enabledLayoutIdSet.has(layoutId)) { return; } var detail = new KeyboardLayoutDetail(layoutId); detail.load(this.appDir); this.layoutDetails.push(detail); }, this); this.layoutDetails.sort(function(a, b) { if (a.id > b.id) { return 1; } else if (a.id < b.id) { return -1; } throw new Error('KeyboardLayoutConfigurator: ' + 'Found two identical layout id: ' + a.id); }); this.layoutDetails.forEach(function(detail) { if (imEngineDictIdSet.has(detail.imEngineId + '/' + detail.dictFilePath)) { detail.dictPreloaded = true; } }); };
done: function(data) { if (data.exitCode !== 0) { var errStr = 'Error writing git commit file!\n' + 'stderr: \n' + stderr + '\nstdout: ' + stdout; utils.log('settings-app-build', errStr); throw new Error(errStr); // FIXME: this is currently ignored } else { utils.log('settings-app-build', 'Writing git commit information ' + 'to: ' + commitFile.path); utils.writeContent(commitFile, stdout); } }
done: function(data) { if (data.exitCode !== 0) { var errStr = 'Error writing git commit file!\n' + 'stderr: \n' + stderr + '\nstdout: ' + stdout; utils.log('settings-app-build', errStr); utils.log('settings-app-build', 'fallback to execute git by shell'); // FIXME: see comment on executeGitByShell() executeGitByShell(gitDir.path, commitFile.path); } else { utils.log('settings-app-build', 'Writing git commit information ' + 'to: ' + commitFile.path); utils.writeContent(commitFile, stdout); } }
grid.forEach(function(screen) { if (screen.length > MAX_ICONS_PER_PAGE) { utils.log('svoperapps.js', 'WARNING: More apps than ' + MAX_ICONS_PER_PAGE + ' in screen ' + counter); } counter++; });
// read the app postion customization part in variant.json and write the result // to APPS_CONF_FILENAME. function customizeAppPosition(data, profilePath, distributionPath) { utils.log('svoperapps.js', 'fetch config'); // generating metadata var apps = data.apps; var outputHomescreen = {}; data.operators.forEach(function(operator) { // Build an array with the apps for one operator and check if id is valid if (!operator.apps) { return; } var row = []; var rowHomescreen = []; operator.apps.forEach(function(app) { var appId = app.id; if (!apps[appId]) { throw new Error('Invalid application id: ' + appId); } row.push(appId); if (!apps[appId].manifestURL) { throw new Error('manifestURL not found for application: ' + appId); } app.manifestURL = apps[appId].manifestURL; delete app.id; rowHomescreen.push(app); }); // For each mcc-mnc create an object with its apps array and add it to // output for (var i = 0; i < operator['mcc-mnc'].length; i++) { outputHomescreen[operator['mcc-mnc'][i]] = rowHomescreen; } }); return outputHomescreen; }
CommAppBuilder.prototype.generateCustomizeResources = function() { if (!this.gaia.distributionDir) { return; } var variantFile = utils.getFile(this.gaia.distributionDir, 'variant.json'); if (variantFile.exists()) { var resources = this.getSingleVariantResources(variantFile); var resourceDirFile = utils.getFile(this.stageDir.path, 'resources'); utils.ensureFolderExists(resourceDirFile); var customizationFile = utils.getFile(this.stageDir.path, 'resources', 'customization.json'); utils.writeContent(customizationFile, JSON.stringify(resources.conf)); resources.files.forEach(function(file) { if (file instanceof Ci.nsILocalFile) { file.copyTo(resourceDirFile, file.leafName); } else { var resourceFile = resourceDirFile.clone(); resourceFile.append(file.filename); utils.writeContent(resourceFile, JSON.stringify(file.content)); } }); } else { utils.log(variantFile.path + ' not found. Single variant resources will' + ' not be added.\n'); } };
update: function(status) { utils.log('hud#update', status); if (status) { this.t.setText(this.text(status)); } return this; }
OperatorAppBuilder.prototype.generateCustomizeResources = function() { if (!this.gaia.distributionDir) { return; } var variantFile = utils.getFile(this.gaia.distributionDir, 'variant.json'); if (variantFile.exists()) { var resources = this.getSingleVariantResources(variantFile); var resourceDirFile = utils.getFile(this.stageDir.path, 'resources'); utils.ensureFolderExists(resourceDirFile); var customizationFile = utils.getFile(this.stageDir.path, 'resources', 'customization.json'); utils.writeContent(customizationFile, JSON.stringify(resources.json)); resources.fileList.forEach(function(file) { if (!file.filename && !file.content) { utils.copyFileTo(file.path, resourceDirFile.path, file.leafName); } else { var resourceFile = utils.getFile(resourceDirFile.path, file.filename); utils.writeContent(resourceFile, JSON.stringify(file.content)); } }); } else { utils.log('operatorvariant', 'Single variant resources will not be added since ' + variantFile.path + ' not found'); } };
processes.forEach(function(proc) { var exitValue = utils.getProcessExitCode(proc.instance); if (exitValue !== 0) { failed = true; utils.log('failed', 'building ' + proc.name + ' app failed with exit code ' + exitValue); } });
function dirChanged(previous, current, dir) { for (let filepath in current) { if (current[filepath] > previous[filepath] || !previous[filepath]) { utils.log('rebuild', 'file has been changed: ' + dir + '/' + filepath); return true; } } return false; }
exports.execute = function(options) { var scanningDirs = options.GAIA_APPDIRS.split(' '); var sharedPath = utils.getFile(options.GAIA_DIR, 'shared').path; scanningDirs.push(sharedPath); var current = getTimestamp(scanningDirs); var timestampFile = utils.getFile(options.STAGE_DIR, 'timestamp.json'); var rebuildAppDirs = []; if (timestampFile.exists()) { let record = utils.getJSON(timestampFile); let previous = record.timestamp; let sharedChanged = dirChanged(previous[sharedPath] || {}, current[sharedPath], sharedPath); let configChanged = buildConfigChanged(record.build_config, options); // Rebuild everything if any BUILD_CONFIG attribute changed or if any // shared/ file changed if (configChanged || sharedChanged) { rebuildAppDirs = scanningDirs; } // Rebuild any app that has any of its source file modified or external app else { for (let appDir in current) { if (dirChanged(previous[appDir] || {}, current[appDir], appDir)) { rebuildAppDirs.push(appDir); } } // Force rebuilding all apps with custom build.js file or unpakcage // external apps which are always named by random uuid // These uuid apps may clean up later in bug 1020259 scanningDirs.forEach(function(appDir) { var buildFile = utils.getFile(appDir, 'build', 'build.js'); var webapp = utils.getWebapp(appDir, options.GAIA_DOMAIN, options.GAIA_SCHEME, options.GAIA_PORT, options.STAGE_DIR) || {}; if ((buildFile.exists() || (utils.isExternalApp(webapp) && !webapp.pckManifest)) && rebuildAppDirs.indexOf(appDir) === -1) { rebuildAppDirs.push(appDir); } }); } } else { rebuildAppDirs = scanningDirs; } utils.writeContent(timestampFile, JSON.stringify({ build_config: options, timestamp: current }, null, 2)); utils.log('rebuild', 'rebuildAppDirs: ' + JSON.stringify(rebuildAppDirs)); return rebuildAppDirs; };
function getAppRegExp(options) { var appRegExp; try { appRegExp = utils.getAppNameRegex(options.BUILD_APP_NAME); } catch (e) { utils.log('utils', 'Using an invalid regular expression for APP ' + 'environment variable, APP=' + options.BUILD_APP_NAME); throw e; } return appRegExp; }
function(filePath) { if (jsSuffix.test(filePath)) { try { var file = utils.getFile(filePath); var content = utils.getFileContent(file); utils.writeContent(file, jsmin(content).code); } catch(e) { utils.log('Error minifying content: ' + filePath); } } });
return function() { if(fs.existsSync(filepath)) // todo: add 304 Not Modified response to enable browser caching // todo: look into the 'age' and 'expires' header - should we use them in place of max-age? return {body: getFile(), gzip:gzip, headers: {'content-type': mimeType, 'cache-control': 'public, max-age='+config.staticsCacheLength}} else { utils.log("File not found: "+filepath) return {code:404, body:''} } }
ini[locale].forEach(function(path) { var targetFile = utils.getFile(iniFile.parent.path, path); var propFile = getPropertiesFile(webapp, targetFile.path); if (!propFile.exists()) { utils.log(MODNAME, 'Properties file not found: ' + propFile.path); return; } if (targetFile.exists()) { targetFile.remove(false); } propFile.copyTo(targetFile.parent, targetFile.leafName); });
links.forEach(function(link) { var resURL = link.getAttribute('href'); var realURL = resURL; // if the resource URL is a subject to branding, then // add official/unofficial to the path if (utils.isSubjectToBranding(utils.dirname(resURL))) { realURL = utils.joinPath(utils.dirname(resURL), self.official === '1' ? 'official' : 'unofficial', utils.basename(resURL)); isOfficialBranding = true; } else { isOfficialBranding = false; } // XXX: We should use @formFactor for device specific L10N support, // isSubjectToDeviceType should be removed after bug 936532 landed. if (utils.isSubjectToDeviceType(resURL)) { realURL = utils.joinPath(utils.dirname(resURL), self.deviceType, utils.basename(resURL)); } for (var loc of self.locales) { var relPathInApp = file.parent.path.substr(webapp.buildDirectoryFile.path.length); var resFile = getResourceFile(webapp, relPathInApp, realURL, loc, isOfficialBranding); var isShared = /\.?\/?shared\//.test(realURL); var destFile; if (isShared) { destFile = utils.getFile(webapp.buildDirectoryFile.path, realURL.replace('{locale}', loc)); } else { destFile = utils.getFile(webapp.buildDirectoryFile.path, relPathInApp, realURL.replace('{locale}', loc)); } if (!resFile.exists()) { if (self.localeBasedir !== null) { utils.log(MODNAME, 'Resource file not found: ' + resFile.path); } continue; } utils.ensureFolderExists(destFile.parent); resFile.copyTo(destFile.parent, destFile.leafName); } });
MailBoxMessageListViewModel.prototype.populateMessageBody = function (oMessage) { if (oMessage) { if (Remote.message(this.onMessageResponse, oMessage.folderFullNameRaw, oMessage.uid)) { Data.messageLoading(true); } else { Utils.log('Error: Unknown message request: ' + oMessage.folderFullNameRaw + ' ~ ' + oMessage.uid + ' [e-101]'); } } };
Slide.prototype.copyEle = function($source, $distance, type) { if (!$source instanceof jQuery && !$distance instanceof jQuery) { g_utils.log('Slide:: copyEle: $source and $distance must be exists'); return; } var $source_copy = $source.clone(); if (type === 'prependTo') { $source_copy.prependTo($distance); } else if (type === 'appendTo') { $source_copy.appendTo($distance); } };
Slide.prototype.animate = function(first_argument) { var that = this, _viewsize = g_base.viewSize, _ele = g_base.element, _panel = g_base.panel, _triggerType = g_base.triggerType, _triggers = g_base.triggers, $_allTriggers = [], $_ele = $(_ele), $_panel = $(_panel), $firstEle, $lastEle, _panelLength = $_panel.length, _panelSize = $_panel.outerWidth(true) * _panelLength, extendLength; if ($_ele.length === 0 || _panelLength === 0) { g_utils.log('Slide::animate: element and panel must be exists!'); return; } // set _panelLength g_base._panelLength = _panelLength; extendLength = _viewsize; $firstEle = $_panel.slice(0, extendLength); $lastEle = $_panel.slice(_panelLength - extendLength, _panelLength); // copy element to distance this.copyEle($firstEle, $_ele, 'appendTo'); this.copyEle($lastEle, $_ele, 'prependTo'); // init margin left $_ele.css('margin-left', -extendLength * $_panel.outerWidth(true)); // store all trigger for (var i = 0; t = _triggers[i]; i++) { $_allTriggers.push($(t)); } that.funtimeout = window.setTimeout(function() { if(!g_base._isAnimating) { that.transition(); } that.funtimeout = window.setTimeout(arguments.callee, g_base.duration); }, g_base.duration); };
webapps.forEach(function(app) { let appDir = app.appDirPath; let appDirFile = utils.getFile(appDir); let appOptions = utils.cloneJSON(options); let stageAppDir = utils.getFile(options.STAGE_DIR, appDirFile.leafName); appOptions.APP_DIR = appDirFile.path; appOptions.STAGE_APP_DIR = stageAppDir.path; let buildFile = utils.getFile(appDir, 'build', 'build.js'); // A workaround for bug 1093267 if (buildFile.exists()) { utils.log('app', 'building ' + appDirFile.leafName + ' app...'); if (parseInt(options.P) > 0) { // A workaround for bug 1093267 if (appDir.indexOf('communications') !== -1) { communications = utils.spawnProcess('build-app', appOptions); processes.push({ name: 'communications', instance: communications }); } else { processes.push({ name: appDirFile.leafName, instance: utils.spawnProcess('build-app', appOptions) }); } } else { require('./build-app').execute(appOptions); } } // Do not spawn a new process since too many processes will slow it down else { // A workaround for bug 1093267 if (appDir.indexOf('callscreen') !== -1) { if (communications) { utils.processEvents(function () { return { wait: utils.processIsRunning(communications) }; }); } } utils.copyToStage(appOptions); appOptions.webapp = app; nodeHelper.require('./post-app', appOptions); } });
list.forEach((fileName) => { fileName.unshift(stagePath); utils.log('preprocessor', flag, enable, fileName); var file = utils.getFile.apply(this, fileName); var fileContent = utils.getFileContent(file); var type; if (htmlSuffix.test(file.path)) { type = 'html'; } else if (jsSuffix.test(file.path)) { type = 'js'; } else if (cssSuffix.test(file.path)) { type = 'css'; } var replacedContent = processContent(flag, enable, fileContent, type); utils.writeContent(file, replacedContent); });
Backbone.sync = function(method, model, options) { utils.log('Backbone.sync', 'Sync: ' + method); switch (method) { case "read": return readSync(model, options); case "update": return updateSync(model, options); case "create": return createSync(model, options); case "delete": return deleteSync(model, options); } };
var localesForManifest = self.locales.filter(function(locale) { var parent = webapp.sourceDirectoryFile.parent.leafName; var propFile = utils.getFile(self.localeBasedir, locale, parent, webapp.sourceDirectoryName, 'manifest.properties'); if (!propFile.exists() ) { // we don't show warning message if it isn't in "apps" directory. if (locale !== 'en-US' && parent === 'apps') { utils.log(MODNAME, 'App "' + webapp.sourceDirectoryName + '" doesn\'t have app manifest localization. A .properties file is' + ' missing at following path: ' + propFile.path); } return false; } var content = utils.getFileContent(propFile); localesProps.push(parseManifestProperties(content)); return true; });
WallPaperAppBuilder.prototype.copyDistributionWallpapers = function() { if (!this.gaia.distributionDir) { return; } var dir = utils.getFile(this.gaia.distributionDir, 'wallpapers'); if (!dir.exists()) { return; } utils.log('Include wallpapers in distribution directory ...\n'); var files = utils.ls(dir); files.forEach(function(file) { file.copyTo(this.wallpaperDir, file.leafName); }, this); };
WallPaperAppBuilder.prototype.copyWallpapers = function() { if (!this.configPath) { throw new Error('device config path not found'); } var dir = utils.getFile(this.configPath, 'wallpapers'); if (!dir.exists()) { return; } utils.log('Include wallpapers in app configuration directory ...\n'); var files = utils.ls(dir); files.forEach(function(file) { file.copyTo(this.wallpaperDir, file.leafName); }, this); };