cordova-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jsoref <...@git.apache.org>
Subject [GitHub] cordova-firefoxos pull request: Discover b2g ports
Date Fri, 01 Aug 2014 18:06:47 GMT
Github user jsoref commented on a diff in the pull request:

    https://github.com/apache/cordova-firefoxos/pull/20#discussion_r15709986
  
    --- Diff: bin/lib/b2g.js ---
    @@ -0,0 +1,74 @@
    +#!/usr/bin/env node
    +
    +/*
    +Licensed to the Apache Software Foundation (ASF) under one
    +or more contributor license agreements. See the NOTICE file
    +distributed with this work for additional information
    +regarding copyright ownership. The ASF licenses this file
    +to you under the Apache License, Version 2.0 (the
    +"License"); you may not use this file except in compliance
    +with the License. You may obtain a copy of the License at
    +
    +http://www.apache.org/licenses/LICENSE-2.0
    +
    +Unless required by applicable law or agreed to in writing,
    +software distributed under the License is distributed on an
    +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +KIND, either express or implied. See the License for the
    +specific language governing permissions and limitations
    +under the License.
    +*/
    +
    +var	exec = require('shelljs').exec,
    +    args  = process.argv,
    +    os = process.platform,
    +    B2G_BIN_OSX = 'b2g/B2G.app/Contents/MacOS/b2g-bin',
    +	FX_PROFILES_OSX = 'Library/Application Support/Firefox/Profiles/',
    +	B2G_BIN_LINUX = 'b2g/b2g-bin',
    +	FX_PROFILES_LINUX = '.mozilla/firefox/',
    +	NETSTAT_CMD = 'netstat -lnptu',
    +	LSOF_CMD = 'lsof -i -n -P -sTCP:LISTEN';
    +
    +exports.discoverPorts = function (callback) {
    +	
    +	var ports = [];
    + 
    +	if (os == 'darwin') {
    +		var output = exec(LSOF_CMD, {silent: true}).output;
    +		var regex = /^b2g[-bin]?.*[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:([0-9]*)/;
    +		var lines = output.split('\n');
    +		for (var line=0; line < lines.length; line++) {
    +			var matches = regex.exec(lines[line]);
    +			
    +			if (matches && +matches[1] != 2828)
    +				ports.push(+matches[1])
    +		}
    + 
    +	} else
    +	if (os == 'linux') {
    +		var output = exec(NETSTAT_CMD, {silent: true}).output;
    +		var regex = /tcp.*[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:([0-9]+).*LISTEN.*\/b2g[-bin]?/
    +		var lines = output.split('\n');
    +		for (var line=0; line < lines.length; line++) {
    +			var matches = regex.exec(lines[line]);
    +			
    +			if (matches && +matches[1] != 2828)
    +				ports.push(+matches[1])
    +		}
    + 
    +	} else {
    +		return callback(new Error("OS not supported for running"))
    +	}
    + 
    +	callback(null, ports)
    + 
    +}
    +
    +if (require.main === module) {
    +    (function() {
    +        exports.discoverPorts(function(err, ports){
    +        	if (err) return console.log(err)
    --- End diff --
    
    don't use tabs.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message