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

Adds command structure, and the ability to use async functions #8

Merged
merged 2 commits into from
Oct 4, 2016
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"presets": [
"es2015"
"es2015",
"stage-3"
],
"plugins": ["transform-flow-strip-types"]
"plugins": [
"transform-flow-strip-types",
"transform-regenerator"
]
}
29 changes: 29 additions & 0 deletions .vscode/spell.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"language": "en",
"ignoreWordsList": [
"GitHub",
"GitLab"
],
"mistakeTypeToStatus": {
"Passive voice": "Hint",
"Spelling": "Error",
"Complex Expression": "Disable",
"Hidden Verbs": "Information",
"Hyphen Required": "Disable",
"Redundant Expression": "Disable",
"Did you mean...": "Disable",
"Repeated Word": "Warning",
"Missing apostrophe": "Warning",
"Cliches": "Disable",
"Missing Word": "Disable",
"Make I uppercase": "Warning"
},
"languageIDs": [
"markdown",
"plaintext"
],
"ignoreRegExp": [
"/\\(.*\\.(jpg|jpeg|png|md|gif|JPG|JPEG|PNG|MD|GIF)\\)/g",
"/((http|https|ftp|git)\\S*)/g"
]
}
15 changes: 9 additions & 6 deletions VISION.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@ A year in, [Danger](https://github.com/danger/danger) is doing just fine. See th

The amount of issues we get in comparison to the number of downloads on Rubygems makes me feel pretty confident about her state of production quality and maturity. I wanted to start thinking about the larger patterns in software. At Artsy, we are starting to use JavaScript in many, many places.

I've explored [running JavaScript](https://github.com/danger/danger/pull/423) from the ruby Danger, ([example](https://github.com/artsy/emission/blob/d58b3d57bf41100e3cce3c2c1b1c4d6c19581a68/Dangerfile.js)) but this pattern isn't going to work on the larger scale: You cannot use npm modules, nor work with babel to transpile your `Dangerfile.js`. That isn't going to work.
I've explored [running JavaScript](https://github.com/danger/danger/pull/423) from the ruby Danger, ([example](https://github.com/artsy/emission/blob/d58b3d57bf41100e3cce3c2c1b1c4d6c19581a68/Dangerfile.js)) but this pattern isn't going to work on the larger scale: You cannot use npm modules, nor work with babel to transpile your `Dangerfile.js` and the requirements on the project to [include are too high](https://github.com/artsy/emission/pull/233). That isn't going to work.

This comes at the same time as thinking about a hosted version of Danger. This time around we can limit the exposed API to only something that can be obtained over the API on a hosted server.
This comes at the same time as thinking about a hosted version of Danger. With the NPM version we can limit the exposed API to only something that can be obtained over the API on a hosted server. By doing this, a hosted Danger does not need to clone and run the associated projects. This is essential for my sanity. I cannot run multiple [servers like CocoaDocs](http://cocoadocs.org). So far, I'm calling this Peril.

One technique for doing this is to lazy load information required, e.g. by default only get the PR metadata, and file changed.
I _do not_ know how to deal with babel-y compilation stuff, or danger plugins to work in Peril. Figure I'll know more about the systems as I get there.

One technique for doing this is to lazy load information required, e.g. by default only get the PR metadata, and file changed. I think memoized get functions in ES6 will be useful there.

### So, initial vision?

* As few dependencies as possible
* Feel native to JS
* Provide Flow/TypeScript types for Danger objects
* Be API agnostic from day one
* If an exposed API can't be done via the APIs, it can't be done for that platform
* Provide Flow/TypeScript types for Danger API
* Be platform API agnostic from day one
* If an exposed end-user API can't be done via the platform APIs, it can't be done for that platform
E.g. if GitLab had an API not available on GitHub, then for GitHub we cannot do that same thing. Platform APIs dictates the end-user experience.
* Re-use abstractions from the Gem when possible, it took a long time to get those
* Re-use CI source detection from Ruby Danger

Expand Down
65 changes: 65 additions & 0 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Automate your culture",
"main": "distribution/danger.js",
"bin": {
"danger": "distribution/runner.js"
"danger": "distribution/commands/runner.js"
},
"scripts": {
"test": "jest",
Expand Down Expand Up @@ -36,6 +36,7 @@
"babel-plugin-transform-flow-strip-types": "^6.8.0",
"babel-polyfill": "^6.13.0",
"babel-preset-es2015": "^6.16.0",
"babel-preset-stage-3": "^6.17.0",
"eslint": "^3.3.1",
"eslint-config-standard": "^6.0.0-beta.3",
"eslint-plugin-flow-vars": "^0.5.0",
Expand All @@ -46,6 +47,7 @@
"jest-cli": "^15.1.1"
},
"dependencies": {
"babel-polyfill": "^6.16.0",
"commander": "^2.9.0"
}
}
13 changes: 13 additions & 0 deletions source/commands/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var program = require("commander")

import { version } from "../../package.json"

// Provides the root node to the command-line architecture

program
.version(version)
.command("run", "Runs danger on your local system", {isDefault: true})
.command("init", "Creates a new Dangerfile.js")
.command("local", "Runs your changes against ")

export default program
8 changes: 8 additions & 0 deletions source/commands/danger-local.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @flow

var program = require("commander")

program
.parse(process.argv)

console.log("Not Yet implmented")
8 changes: 8 additions & 0 deletions source/commands/danger-pr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @flow

var program = require("commander")

program
.parse(process.argv)

console.log("Not Yet implmented")
14 changes: 2 additions & 12 deletions source/runner.js → source/commands/danger-run.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
#! /usr/bin/env node
// @flow

var program = require("commander")
import { version } from "../package.json"
import { getCISourceForEnv } from "./ci_source/ci_source_selector"

import { getCISourceForEnv } from "../ci_source/ci_source_selector"

program
.version(version)
.option("-h, --head [commitish]", "TODO: Set the head commitish")
.option("-b, --base [commitish]", "TODO: Set the base commitish")
.option("-f, --fail-on-errors", "TODO: Fail on errors")
.parse(process.argv)

// program["head"]
// if (program.head) console.log(" - peppers")
// if (program.base) console.log(" - pineapple")
// if (program.fail_on_errors) console.log(" - bbq")

// console.log(" - %s cheese", program.cheese)

let source = getCISourceForEnv(process.env)
if (source) {
console.log("OK?")
Expand All @@ -29,4 +20,3 @@ if (source) {
console.log("Could not find a CI source for this run")
process.exit(0)
}

8 changes: 8 additions & 0 deletions source/commands/runner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#! /usr/bin/env node
// @flow

// This is needed so that other files can use async funcs
import "babel-polyfill"

import app from "./app"
app.parse(process.argv)
1 change: 1 addition & 0 deletions source/danger.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @flow
// This file represents the module that is exposed as the danger API
import "babel-polyfill"

type DangerGit = {
modified_files: string[],
Expand Down