Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ESLint support #37

Merged
merged 5 commits into from
Jul 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/node_modules/*
**/coverage/*
12 changes: 12 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": [
"airbnb",
"prettier",
"prettier/react"
],
"rules": {
"react/jsx-filename-extension": [1, { "extensions": [".js"] }],
"import/extensions": "off"
},
"root": true
}
14 changes: 7 additions & 7 deletions .storybook.native/index.android.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { AppRegistry, NativeModules } from 'react-native';
import { getStorybookUI, configure } from '@storybook/react-native';
import { loadStories } from './story-loader';
import './addons';
import url from 'url';
import url from "url";
import { AppRegistry, NativeModules } from "react-native";
import { getStorybookUI, configure } from "@storybook/react-native";
import { loadStories } from "./story-loader";
import "./addons";

configure(loadStories, module);

const { hostname } = url.parse(NativeModules.SourceCode.scriptURL);

const StorybookUI = getStorybookUI({
port: 7007,
host: hostname,
host: hostname
});

AppRegistry.registerComponent('storybooknative', () => StorybookUI);
AppRegistry.registerComponent("storybooknative", () => StorybookUI);
14 changes: 7 additions & 7 deletions .storybook.native/index.ios.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { AppRegistry, NativeModules } from 'react-native';
import { getStorybookUI, configure } from '@storybook/react-native';
import { loadStories } from './story-loader';
import './addons';
import url from 'url';
import url from "url";
import { AppRegistry, NativeModules } from "react-native";
import { getStorybookUI, configure } from "@storybook/react-native";
import { loadStories } from "./story-loader";
import "./addons";

configure(loadStories, module);

const { hostname } = url.parse(NativeModules.SourceCode.scriptURL);

const StorybookUI = getStorybookUI({
port: 7007,
host: hostname,
host: hostname
});

AppRegistry.registerComponent('storybooknative', () => StorybookUI);
AppRegistry.registerComponent("storybooknative", () => StorybookUI);
70 changes: 34 additions & 36 deletions lib/cli/cli.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"use strict";

const fs = require("fs");
const path = require("path");

Expand All @@ -11,30 +9,17 @@ const fileTemplates = require("./templates");

const repositoryRoot = path.join(__dirname, "../../");

module.exports = () => {
subcommander.command("add component", {
desc: "create a new component",
callback: addComponent
function writeStubFiles(variables) {
const packageRoot = path.join(
repositoryRoot,
"packages",
variables.packageName
);
mkdirp.sync(packageRoot);
fileTemplates(variables).forEach(([template, fileName]) => {
fs.writeFileSync(path.join(packageRoot, fileName), template(variables));
});

const multiSubCommand = ["add component"].filter(command => {
const subcommands = command.split(" ").length;
return process.argv.slice(2, 2 + subcommands).join(" ") === command;
})[0];

if (multiSubCommand) {
const matchLength = multiSubCommand.split(" ").length;
process.argv = process.argv
.slice(0, 2)
.concat(process.argv.slice(2, 2 + matchLength).join(" "))
.concat(process.argv.slice(2 + matchLength));
} else {
subcommander.usage();
process.exit(1);
}

subcommander.parse();
};
}

function addComponent() {
const component = process.argv[3];
Expand All @@ -44,7 +29,7 @@ function addComponent() {
'\n\nUsage:\n$ times-components add component ComponentName "Component Description"';
const argumentOrUsage = (argument, message) => {
if (!argument) {
console.error(message + usage);
console.error(message + usage); // eslint-disable-line no-console
process.exit(1);
}
};
Expand All @@ -68,14 +53,27 @@ function addComponent() {
});
}

function writeStubFiles(variables) {
const packageRoot = path.join(
repositoryRoot,
"packages",
variables.packageName
);
mkdirp.sync(packageRoot);
fileTemplates(variables).forEach(([template, fileName]) => {
fs.writeFileSync(path.join(packageRoot, fileName), template(variables));
module.exports = () => {
subcommander.command("add component", {
desc: "create a new component",
callback: addComponent
});
}

const multiSubCommand = ["add component"].filter(command => {
const subcommands = command.split(" ").length;
return process.argv.slice(2, 2 + subcommands).join(" ") === command;
})[0];

if (multiSubCommand) {
const matchLength = multiSubCommand.split(" ").length;
process.argv = process.argv
.slice(0, 2)
.concat(process.argv.slice(2, 2 + matchLength).join(" "))
.concat(process.argv.slice(2 + matchLength));
} else {
subcommander.usage();
process.exit(1);
}

subcommander.parse();
};
2 changes: 2 additions & 0 deletions lib/cli/cli.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-env jest */

import path from "path";
import fs from "fs";

Expand Down
9 changes: 5 additions & 4 deletions lib/cli/package-json.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
"use strict";

module.exports = variables => ({
name: "@timescomponents/" + variables.packageName,
name: `@timescomponents/${variables.packageName}`,
version: variables.version || "0.0.1",
description: variables.packageDescription,
main: variables.packageName + ".js",
main: `${variables.packageName}.js`,
scripts: {
flow: "node_modules/flow-bin/cli.js",
"test:watch": `jest ${variables.packageName}.test.js --bail --verbose --watch`,
Expand Down Expand Up @@ -48,5 +46,8 @@ module.exports = variables => ({
react: "16.0.0-alpha.6",
"react-dom": "15.5.4",
"react-native-web": "0.0.97"
},
peerDependencies: {
"@storybook/react-native": "3.1.6"
}
});
12 changes: 6 additions & 6 deletions lib/cli/templates.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"use strict";

const handlebars = require("handlebars");

const packageJson = require("./package-json");
Expand All @@ -24,7 +22,9 @@ storiesOf("{{{component}}}", module).add("{{{component}}}", () =>
);
`);

const testFile = handlebars.compile(`import "react-native";
const testFile = handlebars.compile(`/* eslint-env jest */

import "react-native";
import React from "react";
import {{{component}}} from "./{{{packageName}}}";
import renderer from "react-test-renderer";
Expand Down Expand Up @@ -71,9 +71,9 @@ const packageJsonFile = variables =>
JSON.stringify(packageJson(variables), null, 2);

module.exports = variables => [
[indexFile, variables.packageName + ".js"],
[testFile, variables.packageName + ".test.js"],
[storyFile, variables.packageName + ".stories.js"],
[indexFile, `${variables.packageName}.js`],
[testFile, `${variables.packageName}.test.js`],
[storyFile, `${variables.packageName}.stories.js`],
[licenseFile, "LICENSE"],
[packageJsonFile, "package.json"]
];
23 changes: 15 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
],
"lint-staged": {
"**/*.js": [
"eslint . --fix",
"prettier --write",
"git add"
]
Expand Down Expand Up @@ -64,26 +65,32 @@
"@storybook/addon-actions": "3.0.0",
"@storybook/react": "3.0.0",
"@storybook/react-native": "3.0.0",
"coveralls": "^2.13.1",
"jest": "^20.0.4",
"lcov-result-merger": "^1.2.0",
"coveralls": "2.13.1",
"eslint": "3.19.0",
"eslint-config-airbnb": "15.0.1",
"eslint-config-prettier": "2.3.0",
"eslint-plugin-import": "2.6.1",
"eslint-plugin-jsx-a11y": "5.1.1",
"eslint-plugin-react": "7.1.0",
"jest": "20.0.4",
"lcov-result-merger": "1.2.0",
"lerna": "2.0.0-rc.5",
"lint-staged": "^4.0.0",
"pre-commit": "^1.2.2",
"lint-staged": "4.0.0",
"pre-commit": "1.2.2",
"prettier": "1.4.2",
"react": "16.0.0-alpha.6",
"react-dom": "15.5.4",
"react-native": "0.44.2",
"react-native": "0.44.1",
"react-native-storybook-loader": "1.3.1",
"react-native-web": "0.0.97",
"rimraf": "^2.6.1",
"rimraf": "2.6.1",
"url": "0.11.0"
},
"dependencies": {
"dashify": "0.2.2",
"global": "4.3.2",
"handlebars": "4.0.10",
"mkdirp": "^0.5.1",
"mkdirp": "0.5.1",
"sort-pkg": "1.1.0",
"subcommander": "1.0.0"
}
Expand Down
23 changes: 10 additions & 13 deletions packages/author/author.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
import React, { Component } from "react";
import React from "react";
import { StyleSheet, Text, View } from "react-native";

export default class Author extends Component {
render() {
return (
<View style={styles.container}>
<Text>
Author Bios!
</Text>
</View>
);
}
}

const styles = StyleSheet.create({
container: {
flex: 1,
Expand All @@ -21,3 +9,12 @@ const styles = StyleSheet.create({
backgroundColor: "#F5EFEB"
}
});

const Author = () =>
<View style={styles.container}>
<Text>
Author Bios!
</Text>
</View>;

export default Author;
5 changes: 4 additions & 1 deletion packages/author/author.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/* eslint-env jest */

import "react-native";
import React from "react";
import Author from "./author";
import renderer from "react-test-renderer";

import Author from "./author";

it("renders correctly", () => {
const tree = renderer.create(<Author />).toJSON();

Expand Down
5 changes: 4 additions & 1 deletion packages/author/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@
"babel-preset-react-native": "1.9.2",
"flow-bin": "0.42.0",
"jest": "20.0.4",
"react-native": "0.44.2",
"react-test-renderer": "15.5.4",
"webpack": "2.6.1"
},
"dependencies": {
"react": "16.0.0-alpha.6",
"react-dom": "15.5.4",
"react-native": "0.44.1",
"react-native-web": "0.0.96"
},
"peerDependencies": {
"@storybook/react-native": "3.1.6"
}
}