Skip to content

Commit

Permalink
fix(dev-server): Fix port detecting
Browse files Browse the repository at this point in the history
  • Loading branch information
d4rkr00t committed Apr 23, 2017
1 parent 31b3978 commit 092a6c6
Show file tree
Hide file tree
Showing 11 changed files with 399 additions and 263 deletions.
7 changes: 4 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// prettier-ignore
{
"parser": "babel-eslint",
"env": {
Expand Down Expand Up @@ -157,7 +158,7 @@
"func-names": [0],
"func-style": [0],
"indent": [2, 2],
"jsx-quotes": [2, "prefer-single"],
"jsx-quotes": [2, "prefer-double"],
"key-spacing": [2, {
"beforeColon": false,
"afterColon": true
Expand Down Expand Up @@ -200,10 +201,10 @@
}],
"one-var-declaration-per-line": [0],
"operator-assignment": [0],
"operator-linebreak": [2, "before"],
"operator-linebreak": [0],
"padded-blocks": [0],
"quote-props": [2, "as-needed"],
"quotes": [2, "single"],
"quotes": [0],
"require-jsdoc": [0],
"semi": [2, "always"],
"semi-spacing": [2, {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
"chalk": "1.1.3",
"connect-history-api-fallback": "1.3.0",
"css-loader": "0.28.0",
"detect-port": "1.1.1",
"eslint": "3.19.0",
"eslint-loader": "1.7.1",
"eslint-plugin-react": "6.10.3",
Expand Down Expand Up @@ -100,6 +99,7 @@
"nsp": "2.6.3",
"pmm": "1.3.1",
"pre-commit": "1.2.2",
"prettier": "^1.2.2",
"rimraf": "2.6.1"
},
"config": {
Expand Down
21 changes: 12 additions & 9 deletions src/analytics.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
/* @flow */

import querystring from 'querystring';
import Insight from 'insight';
import pkg from '../package.json';
import querystring from "querystring";
import Insight from "insight";
import pkg from "../package.json";

const trackingCode = 'UA-88006586-1';
const trackingProvider = 'google';
const trackingCode = "UA-88006586-1";
const trackingProvider = "google";
const insight = new Insight({ trackingCode, trackingProvider, pkg });

export function askPermission(cb: Function) {
if (insight.optOut === undefined) { // eslint-disable-line
// eslint-disable-next-line
if (insight.optOut === undefined) {
return insight.askPermission(null, cb);
}
cb();
Expand All @@ -28,9 +29,11 @@ export function track(path: string[], input: string[], flags: CLIFlags) {

if (!input[0]) {
return flags.version
? setImmediate(() => insight.track('aik', 'version'))
: setImmediate(() => insight.track('aik', 'help'));
? setImmediate(() => insight.track("aik", "version"))
: setImmediate(() => insight.track("aik", "help"));
}

setImmediate(() => insight.track('aik', ...path, '?' + querystring.stringify(filteredFlags)));
setImmediate(() =>
insight.track("aik", ...path, "?" + querystring.stringify(filteredFlags))
);
}
6 changes: 3 additions & 3 deletions src/build-command.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* @flow */
import runWebpackBuilder from './webpack-build';
import createParams from './utils/params';
import runWebpackBuilder from "./webpack-build";
import createParams from "./utils/params";

/**
* Aik build command
*/
export default function aikBuild(input: string[], flags: CLIFlags): Promise<*> {
const [filename] = input;
const params = createParams(filename, flags, '', true);
const params = createParams(filename, flags, "", true);
return runWebpackBuilder(filename, flags, params);
}
53 changes: 32 additions & 21 deletions src/dev-server-command.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
/* @flow */

import { execSync } from 'child_process';
import fs from 'fs';
import readline from 'readline';
import opn from 'opn';
import { outputFile } from 'fs-extra';
import resolveModule from 'resolve';
import createWebpackDevServer from './webpack-dev-server';
import createNgrokTunnel from './ngrok';
import createParams from './utils/params';
import { execSync } from "child_process";
import fs from "fs";
import readline from "readline";
import opn from "opn";
import { outputFile } from "fs-extra";
import resolveModule from "resolve";
import createWebpackDevServer from "./webpack-dev-server";
import createNgrokTunnel from "./ngrok";
import createParams from "./utils/params";
import {
devServerFileDoesNotExistMsg, devServerInvalidBuildMsg, fileDoesNotExistMsg,
devServerReactRequired, devServerInstallingModuleMsg, devServerSkipInstallingModuleMsg
} from './utils/messages';
devServerFileDoesNotExistMsg,
devServerInvalidBuildMsg,
fileDoesNotExistMsg,
devServerReactRequired,
devServerInstallingModuleMsg,
devServerSkipInstallingModuleMsg
} from "./utils/messages";

export function requestCreatingAnEntryPoint(filename: string): Promise<boolean> {
export function requestCreatingAnEntryPoint(
filename: string
): Promise<boolean> {
return new Promise((resolve, reject) => {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});

rl.question('Create it? (Y/n): ', (answer: string) => {
rl.question("Create it? (Y/n): ", (answer: string) => {
rl.close();
if (!answer || answer === 'Y' || answer === 'y') {
if (!answer || answer === "Y" || answer === "y") {
return resolve(true);
}

Expand All @@ -36,7 +42,7 @@ export function requestCreatingAnEntryPoint(filename: string): Promise<boolean>

export function createFile(filename: string): Promise<*> {
return new Promise((resolve, reject) => {
outputFile(filename, '', err => {
outputFile(filename, "", err => {
if (err) {
return reject(err);
}
Expand All @@ -62,15 +68,20 @@ function installModule(moduleName: string) {
/**
* Aik dev server command
*/
export default async function aikDevServer(input: string[], flags: CLIFlags): Promise<*> {
export default async function aikDevServer(
input: string[],
flags: CLIFlags
): Promise<*> {
const [filename] = input;

try {
fs.statSync(filename);
} catch (error) {
devServerFileDoesNotExistMsg(filename);

const shouldCreateAnEntryPoint = await requestCreatingAnEntryPoint(filename);
const shouldCreateAnEntryPoint = await requestCreatingAnEntryPoint(
filename
);
if (shouldCreateAnEntryPoint) {
await createFile(filename);
}
Expand All @@ -80,11 +91,11 @@ export default async function aikDevServer(input: string[], flags: CLIFlags): Pr

if (flags.react) {
devServerReactRequired();
await installModule('react');
await installModule('react-dom');
await installModule("react");
await installModule("react-dom");
}

const ngrokUrl: NgrokUrl = flags.ngrok && await createNgrokTunnel(flags);
const ngrokUrl: NgrokUrl = flags.ngrok && (await createNgrokTunnel(flags));
const params: AikParams = createParams(filename, flags, ngrokUrl, false);
await createWebpackDevServer(filename, flags, params);

Expand Down
156 changes: 78 additions & 78 deletions src/eslint-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,103 +10,103 @@ module.exports = {

parserOptions: {
ecmaVersion: 2017,
sourceType: 'module',
sourceType: "module",
impliedStrict: true,
ecmaFeatures: {
jsx: true,
generators: true
}
},

plugins: ['react'],
plugins: ["react"],

rules: {
// http://eslint.org/docs/rules/

// Possible errors
'no-cond-assign': 'warn',
'no-constant-condition': 'warn',
'no-dupe-args': 'warn',
'no-dupe-keys': 'warn',
'no-duplicate-case': 'warn',
'no-empty-character-class': 'warn',
'no-empty': 'warn',
'no-ex-assign': 'warn',
'no-extra-semi': 'warn',
'no-func-assign': 'warn',
'no-invalid-regexp': 'warn',
'no-irregular-whitespace': 'warn',
'no-negated-in-lhs': 'warn',
'no-obj-calls': 'warn',
'no-unexpected-multiline': 'warn',
'no-unreachable': 'warn',
'use-isnan': 'warn',
'valid-typeof': 'warn',
'require-await': 'warn',
"no-cond-assign": "warn",
"no-constant-condition": "warn",
"no-dupe-args": "warn",
"no-dupe-keys": "warn",
"no-duplicate-case": "warn",
"no-empty-character-class": "warn",
"no-empty": "warn",
"no-ex-assign": "warn",
"no-extra-semi": "warn",
"no-func-assign": "warn",
"no-invalid-regexp": "warn",
"no-irregular-whitespace": "warn",
"no-negated-in-lhs": "warn",
"no-obj-calls": "warn",
"no-unexpected-multiline": "warn",
"no-unreachable": "warn",
"use-isnan": "warn",
"valid-typeof": "warn",
"require-await": "warn",

// Best practices
'array-callback-return': 'warn',
'guard-for-in': 'warn',
'no-div-regex': 'warn',
'no-empty-pattern': 'warn',
'no-eq-null': 'warn',
'no-eval': 'warn',
'no-extend-native': 'warn',
'no-extra-bind': 'warn',
'no-extra-label': 'warn',
'no-fallthrough': 'warn',
'no-global-assign': 'warn',
'no-implied-eval': 'warn',
'no-invalid-this': 'warn',
'no-labels': 'warn',
'no-lone-blocks': 'warn',
'no-new-func': 'warn',
'no-self-assign': 'warn',
'no-self-compare': 'warn',
'no-unmodified-loop-condition': 'warn',
'no-unused-expressions': 'warn',
'no-unused-labels': 'warn',
'no-useless-call': 'warn',
'no-useless-escape': 'warn',
'no-useless-concat': 'warn',
'no-useless-return': 'warn',
'no-void': 'warn',
'no-with': 'warn',
"array-callback-return": "warn",
"guard-for-in": "warn",
"no-div-regex": "warn",
"no-empty-pattern": "warn",
"no-eq-null": "warn",
"no-eval": "warn",
"no-extend-native": "warn",
"no-extra-bind": "warn",
"no-extra-label": "warn",
"no-fallthrough": "warn",
"no-global-assign": "warn",
"no-implied-eval": "warn",
"no-invalid-this": "warn",
"no-labels": "warn",
"no-lone-blocks": "warn",
"no-new-func": "warn",
"no-self-assign": "warn",
"no-self-compare": "warn",
"no-unmodified-loop-condition": "warn",
"no-unused-expressions": "warn",
"no-unused-labels": "warn",
"no-useless-call": "warn",
"no-useless-escape": "warn",
"no-useless-concat": "warn",
"no-useless-return": "warn",
"no-void": "warn",
"no-with": "warn",

// Variables
'no-delete-var': 'warn',
'no-label-var': 'warn',
'no-undef-init': 'warn',
'no-undef': 'warn',
'no-unused-vars': 'warn',
"no-delete-var": "warn",
"no-label-var": "warn",
"no-undef-init": "warn",
"no-undef": "warn",
"no-unused-vars": "warn",

// ECMAScript 6
'constructor-super': 'warn',
'no-class-assign': 'warn',
'no-const-assign': 'warn',
'no-dupe-class-members': 'warn',
'no-duplicate-imports': 'warn',
'no-new-symbol': 'warn',
'no-this-before-super': 'warn',
'no-useless-computed-key': 'warn',
'no-useless-constructor': 'warn',
'no-useless-rename': 'warn',
'require-yield': 'warn',
"constructor-super": "warn",
"no-class-assign": "warn",
"no-const-assign": "warn",
"no-dupe-class-members": "warn",
"no-duplicate-imports": "warn",
"no-new-symbol": "warn",
"no-this-before-super": "warn",
"no-useless-computed-key": "warn",
"no-useless-constructor": "warn",
"no-useless-rename": "warn",
"require-yield": "warn",

// https://github.com/yannickcr/eslint-plugin-react
'react/jsx-key': 'warn',
'react/jsx-no-comment-textnodes': 'warn',
'react/jsx-no-duplicate-props': ['warn', { ignoreCase: true }],
'react/jsx-no-undef': 'warn',
'react/jsx-pascal-case': ['warn', { allowAllCaps: true }],
'react/jsx-uses-react': 'warn',
'react/jsx-uses-vars': 'warn',
'react/no-danger-with-children': 'warn',
'react/no-deprecated': 'warn',
'react/no-direct-mutation-state': 'warn',
'react/no-is-mounted': 'warn',
'react/react-in-jsx-scope': 'warn',
'react/require-render-return': 'warn',
'react/style-prop-object': 'warn'
"react/jsx-key": "warn",
"react/jsx-no-comment-textnodes": "warn",
"react/jsx-no-duplicate-props": ["warn", { ignoreCase: true }],
"react/jsx-no-undef": "warn",
"react/jsx-pascal-case": ["warn", { allowAllCaps: true }],
"react/jsx-uses-react": "warn",
"react/jsx-uses-vars": "warn",
"react/no-danger-with-children": "warn",
"react/no-deprecated": "warn",
"react/no-direct-mutation-state": "warn",
"react/no-is-mounted": "warn",
"react/react-in-jsx-scope": "warn",
"react/require-render-return": "warn",
"react/style-prop-object": "warn"
}
};
Loading

0 comments on commit 092a6c6

Please sign in to comment.