Remove non-standard "type annotations"

Since we're not actually using Flow.
This commit is contained in:
Nick Farina
2015-07-17 08:57:56 -07:00
parent 94ad9eddcb
commit bf5fc50fa6
8 changed files with 44 additions and 44 deletions

View File

@@ -42,7 +42,7 @@ export default function() {
function runServer(options) { function runServer(options) {
// get all installed providers // get all installed providers
let providers:Array<Provider> = Provider.installed(); let providers = Provider.installed(); // array of Provider
// load and validate providers - check for valid package.json, etc. // load and validate providers - check for valid package.json, etc.
try { try {
@@ -60,7 +60,7 @@ function listInstalledProviders(options) {
// Encapsulates configuring a provider via the command line. // Encapsulates configuring a provider via the command line.
class CliProviderSetup { class CliProviderSetup {
constructor(providerName: string, options:object) { constructor(providerName, options) {
// if you didn't specify a provider, print help // if you didn't specify a provider, print help
if (!providerName) { if (!providerName) {
@@ -88,8 +88,8 @@ class CliProviderSetup {
console.log(''); console.log('');
// apply configuration values entered by the user // apply configuration values entered by the user
for (let key:string in result) { for (let key in result) {
let value:object = result[key]; let value = result[key];
User.config.set(`${this.providerName}.${key}`, value); User.config.set(`${this.providerName}.${key}`, value);
} }
@@ -128,11 +128,11 @@ class CliProviderSetup {
} }
// builds a "schema" obejct for the prompt lib based on the provider's config spec // builds a "schema" obejct for the prompt lib based on the provider's config spec
buildPromptSchema(): object { buildPromptSchema() {
let properties = {}; let properties = {};
for (let key:string in this.providerModule.config) { for (let key in this.providerModule.config) {
let spec:object = this.providerModule.config[key]; let spec = this.providerModule.config[key];
// do we have a value for this config key currently? // do we have a value for this config key currently?
let currentValue = User.config.get(`${this.providerName}.${key}`); let currentValue = User.config.get(`${this.providerName}.${key}`);

View File

@@ -2,18 +2,18 @@ import fs from 'fs';
export class Config { export class Config {
constructor(path:string, data:object = {}) { constructor(path, data = {}) {
this.path = path; this.path = path;
this.data = data; this.data = data;
} }
get(key:string) { get(key) {
this.validateKey(key); this.validateKey(key);
let [providerName, keyName] = key.split("."); let [providerName, keyName] = key.split(".");
return this.data[providerName] && this.data[providerName][keyName]; return this.data[providerName] && this.data[providerName][keyName];
} }
set(key:string, value:object) { set(key, value) {
this.validateKey(key); this.validateKey(key);
let [providerName, keyName] = key.split("."); let [providerName, keyName] = key.split(".");
this.data[providerName] = this.data[providerName] || {}; this.data[providerName] = this.data[providerName] || {};
@@ -21,12 +21,12 @@ export class Config {
this.save(); this.save();
} }
validateKey(key:string) { validateKey(key) {
if (key.split(".").length != 2) if (key.split(".").length != 2)
throw new Error(`The config key '${key}' is invalid. Configuration keys must be in the form [my-provider].[myKey]`); throw new Error(`The config key '${key}' is invalid. Configuration keys must be in the form [my-provider].[myKey]`);
} }
static load(configPath: string): Config { static load(configPath) {
// load up the previous config if found // load up the previous config if found
if (fs.existsSync(configPath)) if (fs.existsSync(configPath))
return new Config(configPath, JSON.parse(fs.readFileSync(configPath))); return new Config(configPath, JSON.parse(fs.readFileSync(configPath)));

View File

@@ -10,5 +10,5 @@ import { Logger } from './logger';
export const HOMEBRIDGE_VERSION = JSON.parse(fs.readFileSync('package.json')).version; export const HOMEBRIDGE_VERSION = JSON.parse(fs.readFileSync('package.json')).version;
// HomeBridge API // HomeBridge API
export let config = User.config; export let config = User.config; // instance of Config
export let logger = Logger.forProvider; export let logger = Logger.forProvider; // logger('provider-name') -> instance of Logger

View File

@@ -12,28 +12,28 @@ let loggerCache = {};
export class Logger { export class Logger {
constructor(providerName: string) { constructor(providerName) {
this.providerName = providerName; this.providerName = providerName;
} }
debug(msg: string) { debug(msg) {
if (DEBUG_ENABLED) if (DEBUG_ENABLED)
this.log('debug', msg); this.log('debug', msg);
} }
info(msg: string) { info(msg) {
this.log('info', msg); this.log('info', msg);
} }
warn(msg: string) { warn(msg) {
this.log('warn', msg); this.log('warn', msg);
} }
error(msg: string) { error(msg) {
this.log('error', msg); this.log('error', msg);
} }
log(level: string, msg: string) { log(level, msg) {
if (level == 'debug') if (level == 'debug')
msg = chalk.gray(msg); msg = chalk.gray(msg);
@@ -49,7 +49,7 @@ export class Logger {
console.log(msg); console.log(msg);
} }
static forProvider(providerName: string): Logger { static forProvider(providerName) {
return loggerCache[providerName] || (loggerCache[providerName] = new Logger(providerName)); return loggerCache[providerName] || (loggerCache[providerName] = new Logger(providerName));
} }
} }

View File

@@ -7,15 +7,15 @@ import { HOMEBRIDGE_VERSION } from './homebridge';
// This class represents a HomeBridge Provider that may or may not be installed. // This class represents a HomeBridge Provider that may or may not be installed.
export class Provider { export class Provider {
constructor(name:string) { constructor(name) {
this.name = name; this.name = name;
} }
get path():string { get path() {
return path.join(User.providersPath, this.name); return path.join(User.providersPath, this.name);
} }
load(options:object = {}):object { load(options = {}) {
// does this provider exist at all? // does this provider exist at all?
if (!fs.existsSync(this.path)) { if (!fs.existsSync(this.path)) {
@@ -23,8 +23,8 @@ export class Provider {
} }
// check for a package.json // check for a package.json
let pjsonPath:string = path.join(this.path, "package.json"); let pjsonPath = path.join(this.path, "package.json");
let pjson:object = null; let pjson = null;
if (!fs.existsSync(pjsonPath)) { if (!fs.existsSync(pjsonPath)) {
throw new Error(`Provider ${this.name} does not contain a package.json.`); throw new Error(`Provider ${this.name} does not contain a package.json.`);
@@ -43,7 +43,7 @@ export class Provider {
throw new Error(`Provider ${this.name} does not contain a valid HomeBridge version requirement.`); throw new Error(`Provider ${this.name} does not contain a valid HomeBridge version requirement.`);
} }
let versionRequired:string = pjson.engines.homebridge; let versionRequired = pjson.engines.homebridge;
// make sure the version is satisfied by the currently running version of HomeBridge // make sure the version is satisfied by the currently running version of HomeBridge
if (!semver.satisfies(HOMEBRIDGE_VERSION, versionRequired)) { if (!semver.satisfies(HOMEBRIDGE_VERSION, versionRequired)) {
@@ -51,21 +51,21 @@ export class Provider {
} }
// figure out the main module - index.js unless otherwise specified // figure out the main module - index.js unless otherwise specified
let main:string = pjson.main || "./index.js"; let main = pjson.main || "./index.js";
let mainPath:string = path.join(this.path, main); let mainPath = path.join(this.path, main);
// try to require() it // try to require() it
let loadedProvider:object = require(mainPath); let loadedProvider = require(mainPath);
// pull out the configuration data, if any // pull out the configuration data, if any
let providerConfig = loadedProvider.config; let providerConfig = loadedProvider.config;
// verify that all required values are present // verify that all required values are present
if (providerConfig && !options.skipConfigCheck) { if (providerConfig && !options.skipConfigCheck) {
for (let key:string in providerConfig) { for (let key in providerConfig) {
let configParams:object = providerConfig[key]; let configParams = providerConfig[key];
if (configParams.required && !User.config.get(`${this.name}-${key}`)) { if (configParams.required && !User.config.get(`${this.name}-${key}`)) {
throw new Error(`Provider ${this.name} requires the config value ${key} to be set.`); throw new Error(`Provider ${this.name} requires the config value ${key} to be set.`);
@@ -77,15 +77,15 @@ export class Provider {
} }
// Gets all providers installed on the local system // Gets all providers installed on the local system
static installed():Array<Provider> { static installed() {
let providers:Array<Provider> = []; let providers = [];
let names:Array<string> = fs.readdirSync(User.providersPath); let names = fs.readdirSync(User.providersPath);
for (let name:string of names) { for (let name of names) {
// reconstruct full path // reconstruct full path
let fullPath:string = path.join(User.providersPath, name); let fullPath = path.join(User.providersPath, name);
// we only care about directories // we only care about directories
if (!fs.statSync(fullPath).isDirectory()) continue; if (!fs.statSync(fullPath).isDirectory()) continue;

View File

@@ -3,7 +3,7 @@ import { User, Config } from './user';
export class Server { export class Server {
constructor(providers:object) { constructor(providers) {
this.providers = providers; // providers[name] = loaded provider JS module this.providers = providers; // providers[name] = loaded provider JS module
} }

View File

@@ -7,24 +7,24 @@ import { Config } from './config';
// //
// global cached config // global cached config
let config:Config; let config;
export class User { export class User {
static get config():Config { static get config() {
return config || (config = Config.load(User.configPath)); return config || (config = Config.load(User.configPath));
} }
static get storagePath():string { static get storagePath() {
let home = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE; let home = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE;
return path.join(home, ".homebridge"); return path.join(home, ".homebridge");
} }
static get configPath():string { static get configPath() {
return path.join(User.storagePath, "config.json"); return path.join(User.storagePath, "config.json");
} }
static get providersPath():string { static get providersPath() {
return path.join(User.storagePath, "providers"); return path.join(User.storagePath, "providers");
} }
} }

View File

@@ -1,6 +1,6 @@
// Converts "accessToken" to "Access Token" // Converts "accessToken" to "Access Token"
export function camelCaseToRegularForm(camelCase: string): string { export function camelCaseToRegularForm(camelCase) {
return camelCase return camelCase
// insert a space before all caps // insert a space before all caps
.replace(/([A-Z])/g, ' $1') .replace(/([A-Z])/g, ' $1')