Skip to content

Commit

Permalink
0.0.1
Browse files Browse the repository at this point in the history
- basic functionality
  • Loading branch information
gabrielcsapo committed Aug 22, 2017
0 parents commit c7253c0
Show file tree
Hide file tree
Showing 36 changed files with 2,905 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
build
coverage
docs
28 changes: 28 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"extends": [
"eslint:recommended",
"plugin:react/recommended"
],
"globals": {
"config": true
},
"env": {
"es6": true,
"node": true,
"browser": true
},
"rules": {
"react/prop-types": 0,
"react/jsx-key": 0
},
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"plugins": [
"react"
]
}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
.nyc_output
coverage
package-lock.json
.DS_Store
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 0.0.1 (08/22/2017)

- basic functionality
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# build.sh

> 🔨 run and visualize the build process
<!-- TOC depthFrom:2 depthTo:6 withLinks:1 updateOnSave:1 orderedList:0 -->

- [Installation](#installation)
- [Usage](#usage)

<!-- /TOC -->

## Installation

```
npm install build.sh -g
```

## Usage

> commit a `build.yml` file to your project root
```
pipeline:
{key}:
- {command}
- {command}
```

To invoke about the pipeline simply run `build` at the project root.

The terminal output will show the pipeline being run and eventually will open the browser to the location of the final report.

This build pipeline:

```yaml
output: ./docs
pipeline:
install:
- npm --version
- node --version
- npm install
lint:
- npm run lint
build:
- npm run coverage
test:
- npm test
docs:
- npm run generate-docs
```
Will yield the following results:
![example.png](./docs/example.png)
Sometimes things go as planned and certain build phases will fail and that will yield:
![fail.png](./docs/fail.png)
An important factor when dealing with build pipelines is the persistence of environment variables and git information which is recorded and accessible via the `Information` tab:

![information.png](./docs/information.png)
3 changes: 3 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- [ ] capture any changes that weren't committed to git
- [ ] document and test using build.sh as a module
- [ ] capture the build pipeline config if it exists (display this under a tab named Config)
87 changes: 87 additions & 0 deletions bin/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/usr/bin/env node

const program = require('commander');
const path = require('path');

const fs = require('fs');
const yaml = require('js-yaml');
const ora = require('ora');
const open = require('opn');
const ms = require('ms');

const Git = require('../src/git');
const Compile = require('../src/compile');
const Pipeline = require('../src/pipeline');

program
.version(require('../package.json').version)
.option('-c, --config [file]', 'the input file for the build pipeline to run', path.resolve(process.cwd(), 'build.yml'))
.parse(process.argv);

const { config } = program;

const spinner = ora('Parsing build.yml').start();

try {
const pkg = require(path.resolve(process.cwd(), 'package.json'));
const doc = yaml.safeLoad(fs.readFileSync(config, 'utf8'));
const { pipeline, output } = doc;

spinner.text = 'Running pipeline';

const events = Pipeline(pipeline);
const start = process.hrtime();

events.on('stage:start', (stage) => {
spinner.text = `Starting stage ${stage}`;
});

events.on('stage:start:command', (stage, command) => {
spinner.text = `Running command ${command} on stage ${stage}`;
});

events.on('error', (error) => {
spinner.fail(`pipeline failed with error ${error}`);
});

events.on('end', (results) => {
spinner.text = 'Capturing git information';

Git()
.then((info) => {
spinner.text = 'Compiling report';

Compile({
config: {
git: info,
name: pkg.name,
description: pkg.description,
source: pkg.repository.url,
process: {
versions: process.versions,
env: process.env,
arch: process.arch,
platform: process.platform,
release: process.release,
version: process.version,
features: process.features,
config: process.config
},
pipeline: results
},
output: path.resolve(output) || process.cwd() + '/build'
}, () => {
const reportLocation = path.resolve((path.resolve(output) || process.cwd() + '/build'), 'index.html');
const end = process.hrtime(start);
spinner.succeed(`Report compiled [${ms(((end[0] * 1e9) + end[1]) / 1e6)}]\nLocated at ${reportLocation}`);
open(reportLocation, { wait: false });
});
})
.catch((error) => {
spinner.fail(`Failed trying to get git information ${error}`)
})
});

} catch (error) {
spinner.fail(`Something went really wrong ${error}`);
}
14 changes: 14 additions & 0 deletions build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
output: ./docs
pipeline:
install:
- npm --version
- node --version
- npm install
lint:
- npm run lint
build:
- npm run coverage
test:
- npm test
docs:
- npm run generate-docs
148 changes: 148 additions & 0 deletions docs/code/git.js.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>git.js - Documentation</title>

<script src="scripts/prettify/prettify.js"></script>
<script src="scripts/prettify/lang-css.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
</head>
<body>

<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>

<label for="nav-trigger" class="overlay"></label>

<nav>
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-src_git.html">src/git</a><ul class='methods'><li data-type='method'><a href="module-src_git.html#~git">git</a></li></ul></li><li><a href="module-src_pipeline.html">src/pipeline</a><ul class='methods'><li data-type='method'><a href="module-src_pipeline.html#~pipeline">pipeline</a></li></ul></li></ul>
</nav>

<div id="main">

<h1 class="page-title">git.js</h1>







<section>
<article>
<pre class="prettyprint source linenums"><code>/**
* @module src/git
*/

const { exec } = require('child_process');
const fs = require('fs');
const path = require('path');

/**
* get's the current git information for the project being processed
* @method git
* @param {Object=} options
* @param {String=} options.directory - the directory to check for git information
* @returns {Promise}
*/
module.exports = function git(options) {
let { directory } = options || {};
directory = directory || process.cwd();

return new Promise((resolve, reject) => {
// check if the directory contains git
if (!fs.existsSync(path.resolve(directory, '.git'))) {
return reject('directory does not contain git');
}

const git = {
commit: '',
author_name: '',
author_email: '',
author_date: '',
committer_name: '',
committer_email: '',
committer_date: '',
message: '',
branch: '',
remotes: {
name: '',
url: ''
}
};

exec("git log --pretty=format:'%H\n%an\n%ae\n%at\n%cn\n%ce\n%ct\n%s' -1", {
cwd: directory
}, (err, response) => {
if (err) {
return reject(err);
}
const raw = response.split('\n');

git.commit = raw[0];
git.author_name = raw[1];
git.author_email = raw[2];
git.author_date = raw[3];
git.committer_name = raw[4];
git.committer_email = raw[5];
git.committer_date = raw[6];
git.message = raw[7];

exec("git symbolic-ref --short HEAD", {
cwd: directory
}, (err, branch) => {

git.branch = branch.replace('\n', '') || process.env.BRANCH_NAME;

exec("git remote -v", {
cwd: directory
}, (err, response) => {
if (err) {
return reject(err);
}

response.split("\n").forEach((remote) => {
if (!/\s\(push\)$/.test(remote)) {
return;
}
remote = remote.split(/\s+/);
git.remotes.name = remote[0];
git.remotes.url = remote[1];
});

if (!git.remotes.url || !git.remotes.name) {
return reject('no remote found');
}

return resolve(git);
});
});
});
});
}
</code></pre>
</article>
</section>




</div>

<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.4</a> on Tue Aug 22 2017 00:33:11 GMT-0700 (PDT) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
<script src="scripts/linenumber.js"></script>
</body>
</html>
Loading

0 comments on commit c7253c0

Please sign in to comment.