
import { start as startPot, resolveConfig } from 'pot-js';
import { resolve } from 'path';
import { init, defaultConfigFilename } from './config';
import workspace from './utils/workspace';
import { appLogger } from './utils/logger';
import outputHost from 'output-host';
import { isUndefined } from 'lodash';

export default async function start(options = {}) {
	const config = init(await resolveConfig({
		config: defaultConfigFilename,
		configWalk: true,
		...options,
		workspace,
		configToEnv: 'CLAYPOT_CONFIG',
		entry: resolve(__dirname, 'app.js'),
	}));

	await startPot(config);

	const enableHttps = config.ssl.enable;

	const logger = appLogger.info.bind(appLogger);

	if ((!config.outputHost && !isUndefined(config.outputHost)) ||
		config.production) {
		return;
	}

	outputHost({
		port: config.port,
		name: config.name,
		useCopy: !config.production && !enableHttps,
		logger,
	});

	if (enableHttps) {
		outputHost({
			port: config.ssl.port,
			name: `${config.name} HTTPS`,
			protocol: 'https',
			useCopy: !config.production,
			logger,
		});

	}
}

@@ -286,16 +286,26 @@
 ndefined
+, isObject
  %7D from 
@@ -786,16 +786,97 @@
 rn;%0A%09%7D%0A%0A
+%09const outputHostConfig = isObject(config.outputHost) ? config.outputHost : %7B%7D;%0A%0A
 %09outputH
@@ -881,16 +881,16 @@
 tHost(%7B%0A
-
 %09%09port: 
@@ -980,16 +980,39 @@
 logger,%0A
+%09%09...outputHostConfig,%0A
 %09%7D);%0A%0A%09i
@@ -1157,16 +1157,16 @@
 uction,%0A
-
 %09%09%09logge
@@ -1168,16 +1168,40 @@
 logger,%0A
+%09%09%09...outputHostConfig,%0A
 %09%09%7D);%0A%0A%09

add `outputHost` config