diff --git a/Makefile b/Makefile index e53a01b1..cbba9b05 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,14 @@ .PHONY: check check: + @yarn install --prefer-offline @./bin/setup +.PHONY: setup +setup: .git/hooks/pre-commit + @cp bin/pre-commit.hook .git/hooks/pre-commit + SUBDIRS := $(shell find -maxdepth 2 -mindepth 2 -name 'Makefile' -printf '%h/.\n') -TARGETS := clean install test # whatever else, but must not contain '/' +TARGETS := install clean test lint # whatever else, but must not contain '/' # foo/.all bar/.all foo/.clean bar/.clean SUBDIRS_TARGETS := \ @@ -21,4 +26,4 @@ $(TARGETS): %: $(addsuffix %,$(SUBDIRS)) # $(@F) is .all, with leading period # $(@F:.%=%) is just all $(SUBDIRS_TARGETS): - $(MAKE) -C $(@D) $(@F:.%=%) + $(MAKE) --no-print-directory -C $(@D) $(@F:.%=%) diff --git a/bin/deploy b/bin/deploy index 0b42edf8..7bdb6e64 100755 --- a/bin/deploy +++ b/bin/deploy @@ -6,20 +6,26 @@ # set -euo pipefail -INCLUDE=$(dirname $(readlink -f $0)) -. $INCLUDE/setup_tools +# Beware of CDPATH gotchas causing cd not to work correctly when a user +# has set this in their environment +# https://bosker.wordpress.com/2012/02/12/bash-scripters-beware-of-the-cdpath/ +unset CDPATH + +readonly INCLUDE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +# shellcheck source=bin/setup-tools +. "${INCLUDE}"/setup-tools echo ">> Logging into $_DOCKER_REGISTRY" -docker login -e="." -u="$_DOCKER_LOGIN_USERNAME" -p="$_DOCKER_LOGIN_PASSWORD" $_DOCKER_REGISTRY +docker login -e="." -u="$_DOCKER_LOGIN_USERNAME" -p="$_DOCKER_LOGIN_PASSWORD" "$_DOCKER_REGISTRY" echo ">> Installing captain" curl -sSL https://raw.githubusercontent.com/tomgco/captain/master/install.sh | bash export PATH=$HOME/.captain/bin:$PATH git stash -u echo ">> running captain build" -captain build -N $_DOCKER_REGISTRY/yldio/joyent-dashboard- +captain build -N "$_DOCKER_REGISTRY/yldio/joyent-dashboard-" echo ">> running captain push" -captain push -N $_DOCKER_REGISTRY/yldio/joyent-dashboard- +captain push -N "$_DOCKER_REGISTRY/yldio/joyent-dashboard-" git stash apply diff --git a/bin/pre-commit.hook b/bin/pre-commit.hook new file mode 100755 index 00000000..3ff10eef --- /dev/null +++ b/bin/pre-commit.hook @@ -0,0 +1,60 @@ +#! /usr/bin/env bash + +# +# Prelude - make bash behave sanely +# http://redsymbol.net/articles/unofficial-bash-strict-mode/ +# +set -euo pipefail + +# Make pushd & popd silent +pushd () { + command pushd "$@" > /dev/null +} + +popd () { + command popd "$@" > /dev/null +} + +export EXIT_CODE=0 + + +function lint_changed() { + # Allow lint to be ran from outside of the root directory + local git_root + git_root=$(git rev-parse --show-cdup) + git_root=${git_root:-./} + + local subdirs + subdirs=$(find "$git_root" -maxdepth 2 -mindepth 2 -name 'Makefile' -printf '%h\n') + + + for directory in $subdirs + do + pushd "$directory" + + local npm_bin="node_modules/.bin" + local eslint="$npm_bin/eslint" + + function lint() { + local to_lint + to_lint=$(git diff --staged --diff-filter=ACMTUXB --name-only -- '*.j'{s,sx}) + echo $to_lint + echo $eslint + + if [ "$to_lint" ]; then + $eslint "$to_lint" -c ".eslintrc" || EXIT_CODE=$? + fi + } + + lint + popd + done +} + +lint_changed +if [[ "$EXIT_CODE" -gt "0" ]]; then + exit $EXIT_CODE +fi +make test + +echo "⚡️ changed files pass eslint! ⚡️" diff --git a/bin/setup b/bin/setup index e3d770ff..fe0fc014 100755 --- a/bin/setup +++ b/bin/setup @@ -11,7 +11,8 @@ IFS=$'\n\t' unset CDPATH readonly INCLUDE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -. "${INCLUDE}"/setup_tools +# shellcheck source=bin/setup-tools +. "${INCLUDE}"/setup-tools # # Main diff --git a/bin/setup_tools b/bin/setup-tools similarity index 100% rename from bin/setup_tools rename to bin/setup-tools diff --git a/cloudapi-graphql/Makefile b/cloudapi-graphql/Makefile index 5bc2b2b3..646949de 100644 --- a/cloudapi-graphql/Makefile +++ b/cloudapi-graphql/Makefile @@ -17,3 +17,7 @@ test: .PHONY: start start: npm run start + +.PHONY: lint +lint: + @$(shell npm bin)/eslint src diff --git a/cloudapi-graphql/src/api/request.js b/cloudapi-graphql/src/api/request.js index 0a022702..3a4d8b89 100644 --- a/cloudapi-graphql/src/api/request.js +++ b/cloudapi-graphql/src/api/request.js @@ -5,7 +5,7 @@ const bunyan = require('bunyan'); const pkg = require('../../package.json'); var log = bunyan.createLogger({ - name: pkg.name, + name: pkg.name }); var client = cloudapi.createClient({ diff --git a/cloudapi-graphql/src/endpoint.js b/cloudapi-graphql/src/endpoint.js index 1df73b88..181d7693 100644 --- a/cloudapi-graphql/src/endpoint.js +++ b/cloudapi-graphql/src/endpoint.js @@ -5,4 +5,4 @@ module.exports = graphqlHTTP(() => ({ schema: schema, graphiql: true, pretty: true -})); \ No newline at end of file +})); diff --git a/cloudapi-graphql/src/schema/types/firewall-rule.js b/cloudapi-graphql/src/schema/types/firewall-rule.js index 62efd9f8..35810c7c 100644 --- a/cloudapi-graphql/src/schema/types/firewall-rule.js +++ b/cloudapi-graphql/src/schema/types/firewall-rule.js @@ -77,15 +77,15 @@ module.exports = new GraphQLObjectType({ description: { type: GraphQLString, description: 'Human-readable description for the rule' + }, + machines: { + type: new GraphQLList(MachineType), + description: 'Lists all instances a firewall rule is applied to', + resolve: (root) => { + return api.firewallRules.listMachines({ + id: root.id + }); + } } - // machines: { - // type: new GraphQLList(MachineType), - // description: 'Lists all instances a firewall rule is applied to', - // resolve: (root) => { - // return api.firewallRules.listMachines({ - // id: root.id - // }); - // } - // } } }); diff --git a/frontend/Makefile b/frontend/Makefile index 027945a9..d422a31a 100644 --- a/frontend/Makefile +++ b/frontend/Makefile @@ -21,3 +21,7 @@ compile: install .PHONY: start start: npm run production + +.PHONY: lint +lint: + @$(shell npm bin)/eslint src diff --git a/package.json b/package.json new file mode 100644 index 00000000..b9b560f5 --- /dev/null +++ b/package.json @@ -0,0 +1,24 @@ +{ + "name": "joyent-dashboard", + "version": "1.0.0", + "description": "## Project Management", + "main": "index.js", + "scripts": { + "test": "make test", + "precommit": "make -j4 lint", + "prepush": "make test" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/yldio/joyent-dashboard.git" + }, + "author": "", + "license": "UNLICENSED", + "bugs": { + "url": "https://github.com/yldio/joyent-dashboard/issues" + }, + "homepage": "https://github.com/yldio/joyent-dashboard#readme", + "dependencies": { + "husky": "^0.11.9" + } +} diff --git a/ui/Makefile b/ui/Makefile index d26be7e8..7a98e3f9 100644 --- a/ui/Makefile +++ b/ui/Makefile @@ -13,3 +13,7 @@ install-production: .PHONY: clean clean: @rm -rf node_modules + +.PHONY: lint +lint: + @$(shell npm bin)/eslint src diff --git a/ui/src/components/row/index.js b/ui/src/components/row/index.js index 0a11669a..6250eb74 100644 --- a/ui/src/components/row/index.js +++ b/ui/src/components/row/index.js @@ -38,7 +38,7 @@ const getClasses = (props) => { const bps = (() => { if (value === true) { - return breakpoints + return breakpoints; } if (Array.isArray(value)) { diff --git a/ui/yarn.lock b/ui/yarn.lock index b8b55c2d..c18ac9fa 100644 --- a/ui/yarn.lock +++ b/ui/yarn.lock @@ -2198,34 +2198,7 @@ escope@^3.6.0: esrecurse "^4.1.0" estraverse "^4.1.1" -eslint-config-semistandard@^7.0.0: - version "7.0.0" - resolved "https://registry.yarnpkg.com/eslint-config-semistandard/-/eslint-config-semistandard-7.0.0.tgz#f803493f56a5172f7f59c35ae648360b41f2ff71" - -eslint-config-standard@^6.2.0: - version "6.2.0" - resolved "https://registry.yarnpkg.com/eslint-config-standard/-/eslint-config-standard-6.2.0.tgz#1d2384ee074de6f6b6c0f2bbe976863032565aee" - -eslint-plugin-babel@^3.3.0: - version "3.3.0" - resolved "https://registry.yarnpkg.com/eslint-plugin-babel/-/eslint-plugin-babel-3.3.0.tgz#2f494aedcf6f4aa4e75b9155980837bc1fbde193" - -eslint-plugin-promise@^3.3.0: - version "3.3.0" - resolved "https://registry.yarnpkg.com/eslint-plugin-promise/-/eslint-plugin-promise-3.3.0.tgz#20a1ef58b4243ffdaef82ee9360a02353a7cca89" - -eslint-plugin-react@^6.4.1: - version "6.4.1" - resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-6.4.1.tgz#7d1aade747db15892f71eee1fea4addf97bcfa2b" - dependencies: - doctrine "^1.2.2" - jsx-ast-utils "^1.3.1" - -eslint-plugin-standard@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/eslint-plugin-standard/-/eslint-plugin-standard-2.0.1.tgz#3589699ff9c917f2c25f76a916687f641c369ff3" - -eslint@^3.8.1: +eslint: version "3.8.1" resolved "https://registry.yarnpkg.com/eslint/-/eslint-3.8.1.tgz#7d02db44cd5aaf4fa7aa489e1f083baa454342ba" dependencies: @@ -2263,6 +2236,33 @@ eslint@^3.8.1: text-table "~0.2.0" user-home "^2.0.0" +eslint-config-semistandard@^7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/eslint-config-semistandard/-/eslint-config-semistandard-7.0.0.tgz#f803493f56a5172f7f59c35ae648360b41f2ff71" + +eslint-config-standard@^6.2.0: + version "6.2.0" + resolved "https://registry.yarnpkg.com/eslint-config-standard/-/eslint-config-standard-6.2.0.tgz#1d2384ee074de6f6b6c0f2bbe976863032565aee" + +eslint-plugin-babel@^3.3.0: + version "3.3.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-babel/-/eslint-plugin-babel-3.3.0.tgz#2f494aedcf6f4aa4e75b9155980837bc1fbde193" + +eslint-plugin-promise@^3.3.0: + version "3.3.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-promise/-/eslint-plugin-promise-3.3.0.tgz#20a1ef58b4243ffdaef82ee9360a02353a7cca89" + +eslint-plugin-react@^6.4.1: + version "6.4.1" + resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-6.4.1.tgz#7d1aade747db15892f71eee1fea4addf97bcfa2b" + dependencies: + doctrine "^1.2.2" + jsx-ast-utils "^1.3.1" + +eslint-plugin-standard@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/eslint-plugin-standard/-/eslint-plugin-standard-2.0.1.tgz#3589699ff9c917f2c25f76a916687f641c369ff3" + espower-location-detector@^0.1.1: version "0.1.2" resolved "https://registry.yarnpkg.com/espower-location-detector/-/espower-location-detector-0.1.2.tgz#d43be738af3e0b18197eeb5c22b95512dee6b83c" diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 00000000..bcdb328a --- /dev/null +++ b/yarn.lock @@ -0,0 +1,23 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 +ci-info@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-1.0.0.tgz#dc5285f2b4e251821683681c381c3388f46ec534" + +husky: + version "0.11.9" + resolved "https://registry.yarnpkg.com/husky/-/husky-0.11.9.tgz#28cd1dc16bffdca1d4d93592814e5f3c327b38ee" + dependencies: + is-ci "^1.0.9" + normalize-path "^1.0.0" + +is-ci@^1.0.9: + version "1.0.10" + resolved "https://registry.yarnpkg.com/is-ci/-/is-ci-1.0.10.tgz#f739336b2632365061a9d48270cd56ae3369318e" + dependencies: + ci-info "^1.0.0" + +normalize-path@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-1.0.0.tgz#32d0e472f91ff345701c15a8311018d3b0a90379" +