2014-11-19 08:45:56 -04:00
|
|
|
_ = require('lodash')
|
2014-11-26 13:12:39 -04:00
|
|
|
|
|
|
|
# TODO: This should be fetch from the server
|
2014-11-24 08:54:35 -04:00
|
|
|
DEVICES = require('./device-data.json')
|
2014-11-19 08:45:56 -04:00
|
|
|
|
2014-12-05 14:48:47 -04:00
|
|
|
# Get display name for a device
|
|
|
|
#
|
|
|
|
# For a list of supported devices, see getSupportedDevices()
|
|
|
|
#
|
|
|
|
# @param {String} device device name
|
|
|
|
# @return {String} device display name or 'Unknown'
|
|
|
|
#
|
|
|
|
# @example Get display name
|
|
|
|
# console.log resin.device.getDisplayName('raspberry-pi') # Raspberry Pi
|
|
|
|
# console.log resin.device.getDisplayName('rpi') # Raspberry Pi
|
|
|
|
#
|
2014-11-19 08:45:56 -04:00
|
|
|
exports.getDisplayName = (device) ->
|
2014-11-24 09:09:39 -04:00
|
|
|
if _.indexOf(exports.getSupportedDevices(), device) isnt -1
|
|
|
|
return device
|
|
|
|
|
2014-11-24 08:54:35 -04:00
|
|
|
for key, value of DEVICES
|
|
|
|
if _.indexOf(value.names, device) isnt -1
|
2014-11-19 08:45:56 -04:00
|
|
|
return key
|
2014-11-19 08:50:11 -04:00
|
|
|
return 'Unknown'
|
2014-11-24 08:25:45 -04:00
|
|
|
|
2014-12-05 14:48:47 -04:00
|
|
|
# Get device slug
|
|
|
|
#
|
|
|
|
# @param {String} device device name
|
|
|
|
# @return {String} device slug or 'unknown'
|
|
|
|
#
|
|
|
|
# @example Get device slug
|
|
|
|
# console.log resin.device.getDeviceSlug('Raspberry Pi') # raspberry-pi
|
|
|
|
#
|
2014-11-24 09:03:02 -04:00
|
|
|
exports.getDeviceSlug = (device) ->
|
|
|
|
displayName = exports.getDisplayName(device)
|
|
|
|
return DEVICES[displayName]?.slug or 'unknown'
|
|
|
|
|
2014-12-05 14:48:47 -04:00
|
|
|
# Get a list of supported devices
|
|
|
|
#
|
|
|
|
# @return {Array<String>} a list of all supported devices, by their display names
|
|
|
|
#
|
|
|
|
# @example Get all supported devices
|
|
|
|
# devices = resin.device.getSupportedDevices()
|
|
|
|
# console.log(devices)
|
|
|
|
#
|
2014-11-24 08:25:45 -04:00
|
|
|
exports.getSupportedDevices = ->
|
2014-11-24 09:03:02 -04:00
|
|
|
return _.keys(DEVICES)
|