Skip to content
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
4 changes: 4 additions & 0 deletions __tests__/file.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ describe('findMarkdownFiles', () => {
'name': 'readme-with-nested-markdown.md',
'path': resolve(__dirname, 'fixtures/readme-with-nested-markdown.md'),
},
{
'name': 'readme-with-params.md',
'path': resolve(__dirname, 'fixtures/readme-with-params.md'),
},
{
'name': 'readme-with-weird-headers.md',
'path': resolve(__dirname, 'fixtures/readme-with-weird-headers.md'),
Expand Down
214 changes: 214 additions & 0 deletions __tests__/fixtures/readme-with-params.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
# dockops [![build status](https://secure.travis-ci.org/technote-space/dockops.png)](http://travis-ci.org/technote-space/dockops)

docker convenience functions on top of dockerode

<!-- START doctoc generated TOC please keep comment here to allow auto update param::entryPrefix::-:: -->
<!-- param::mode::github.com:: -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<!-- param::isNotitle::false:: param::maxHeaderLevel::8:: -->
**Table of Contents** *generated with [DocToc](https://github.com/technote-space/doctoc)*

- [Installation](#installation)
- [API](#api)
- [License](#license)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

```js
var dockops = require('dockops')
var docker = dockops.createDocker({ dockerhost: dockerhost });

var images = new dockops.Images(docker);
dockops.logEvents(images, 'verbose');

var containers = new dockops.Containers(docker);
dockops.logEvents(containers, 'verbose');

build('test:uno', testUnoTar, function () {
build('toast:uno', toastUnoTar, function () {

containers.run(.. // run test:uno and toast:uno containers

containers.listRunning(function (err, res) {
inspect(res);
containers.stopRemoveGroup('test', function (err, res) {
containers.listRunning(function (err, res) {
inspect(res);
http.request({ port: 49222 }, function (res) {
console.log('--------------------------')
inspect({ status: res.statusCode, headers: res.headers })
res.pipe(process.stdout)
}).end()
})
})
})
})
})
```
[full example](https://github.com/technote-space/dockops/blob/master/example/create-wipe.js)
![output](https://github.com/technote-space/dockops/raw/master/assets/output.gif)
## Installation
npm install dockops
## API
<!-- START docme generated API please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN docme TO UPDATE -->
<div>
<div class="jsdoc-githubify">
<section>
<article>
<div class="container-overview">
<dl class="details">
</dl>
</div>
<dl>
<dt>
<h4 class="name" id="dockops::Containers"><span class="type-signature"></span>dockops::Containers<span class="signature">(docker)</span><span class="type-signature"> &rarr; {Object}</span></h4>
</dt>
<dd>
<div class="description">
<p>Creates a new containers instance that will use the given docker instance to communicate with docker.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>docker</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="description last"><p>dockerode instance to communicate with docker</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy">
<li>
<a href="https://github.com/technote-space/dockops/blob/master/containers.js">containers.js</a>
<span>, </span>
<a href="https://github.com/technote-space/dockops/blob/master/containers.js#L24">lineno 24</a>
</li>
</ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>initialized containers</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Object</span>
</dd>
</dl>
</dd>
<dt>
<h4 class="name" id="dockops::Containers::activePorts"><span class="type-signature"></span>dockops::Containers::activePorts<span class="signature">(cb)</span><span class="type-signature"></span></h4>
</dt>
<dd>
<div class="description">
<p>Lists all running containers by the ports they expose.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>cb</code></td>
<td class="type">
<span class="param-type">function</span>
</td>
<td class="description last"><p>called back with list of containers hashed by their port number</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy">
<li>
<a href="https://github.com/technote-space/dockops/blob/master/containers.js">containers.js</a>
<span>, </span>
<a href="https://github.com/technote-space/dockops/blob/master/containers.js#L275">lineno 275</a>
</li>
</ul></dd>
</dl>
</dd>
<dt>
<h4 class="name" id="dockops::Containers::clean"><span class="type-signature"></span>dockops::Containers::clean<span class="signature">(id, cb)</span><span class="type-signature"></span></h4>
</dt>
<dd>
<div class="description">
<p>Stops and/or kills and then removes a container.</p>
<p>Heavy machinery clean operation.
It was useful when running on arch with docker not always working as promised.
This may not be needed anymore as docker got more stable.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>id</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>container id</p></td>
</tr>
<tr>
<td class="name"><code>cb</code></td>
<td class="type">
<span class="param-type">function</span>
</td>
<td class="description last"><p>called back after container was cleaned or maximum attempts were exceeded</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy">
<li>
<a href="https://github.com/technote-space/dockops/blob/master/containers.js">containers.js</a>
<span>, </span>
<a href="https://github.com/technote-space/dockops/blob/master/containers.js#L97">lineno 97</a>
</li>
</ul></dd>
</dl>
</dd>
</article>
</section>
</div>
*generated with [docme](https://github.com/technote-space/docme)*
</div>
<!-- END docme generated API please keep comment here to allow auto update -->
<h2>^License</h2>
MIT
73 changes: 73 additions & 0 deletions __tests__/params.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/* eslint-disable no-magic-numbers */
import {extractParams, getStartSection, getParamsSection} from '../src/lib/params';
import {CLOSING_COMMENT, OPENING_COMMENT} from '../src';

describe('extractParams', () => {
const opening = OPENING_COMMENT.replace('\n', ' ');
it('should return params', () => {
expect(extractParams(opening)).toEqual({});
expect(extractParams(opening + '<!-- param::maxHeaderLevel::2:: param::isNotitle::true:: param::isFolding::false:: param::processAll::1:: param::updateOnly::0:: param::isCustomMode:::: -->')).toEqual({
maxHeaderLevel: 2,
isNotitle: true,
isFolding: false,
processAll: true,
updateOnly: false,
isCustomMode: false,
});
expect(extractParams(opening + '<!-- param::mode::test mode:: param::moduleName::test name:: param::title:::: param::entryPrefix::-:: -->')).toEqual({
mode: 'test mode',
moduleName: 'test name',
title: '',
entryPrefix: '-',
});
expect(extractParams(opening + '<!-- param::customTemplate::<ul>${ITEMS}</ul>:: param::itemTemplate::<li><a href="${LINK}" target="_blank">${TEXT}</a></li>:: param::separator:::: -->')).toEqual({
customTemplate: '<ul>${ITEMS}</ul>',
itemTemplate: '<li><a href="${LINK}" target="_blank">${TEXT}</a></li>',
separator: '',
});
expect(extractParams(opening + '<!-- param::test1:::: param::test2:::: -->')).toEqual({});
});
});

describe('getStartSection', () => {
it('should return empty if hasStart is false', () => {
expect(getStartSection(['<!-- param::test1::test1:: -->', '<!-- param::test2::test2:: -->'], {
hasStart: false,
hasEnd: false,
startIdx: -1,
endIdx: -1,
})).toEqual([]);
});

it('should return start line', () => {
expect(getStartSection(['', ...OPENING_COMMENT.split('\n'), '<!-- param::test1::test1:: -->', '<!-- param::test2::test2:: -->'], {
hasStart: true,
hasEnd: true,
startIdx: 1,
endIdx: 5,
})).toEqual([OPENING_COMMENT.split('\n')[0]]);
});

it('should return start section', () => {
expect(getStartSection(['', ...OPENING_COMMENT.split('\n'), '<!-- param::test1::test1:: -->', '<!-- param::test2::test2:: -->', 'title', '', CLOSING_COMMENT, '', ''], {
hasStart: true,
hasEnd: true,
startIdx: 1,
endIdx: 7,
})).toEqual([...OPENING_COMMENT.split('\n'), '<!-- param::test1::test1:: -->', '<!-- param::test2::test2:: -->']);
});
});

describe('getParamsSection', () => {
it('should return empty if no options', () => {
expect(getParamsSection({})).toBe('');
});

it('should return params section', () => {
expect(getParamsSection({
mode: 'test mode',
isNotitle: true,
isFolding: false,
})).toBe(['', '<!-- param::mode::test mode:: -->', '<!-- param::isNotitle::true:: -->', '<!-- param::isFolding::false:: -->'].join('\n'));
});
});
68 changes: 68 additions & 0 deletions __tests__/transform-override-params.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* eslint-disable no-magic-numbers */
import {resolve} from 'path';
import {readFileSync} from 'fs';
import {transform} from '../src';

describe('transform', () => {
it('override params', () => {
const content = readFileSync(resolve(__dirname, 'fixtures/readme-with-params.md'), 'utf8');
const headers = transform(content, {isNotitle: true, isFolding: false, maxHeaderLevel: 1, entryPrefix: '*'});

expect(headers.wrappedToc.split('\n')).toEqual(
[
'<!-- START doctoc generated TOC please keep comment here to allow auto update -->',
'<!-- DON\'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->',
'<!-- param::entryPrefix::-:: -->',
'<!-- param::mode::github.com:: -->',
'<!-- param::isNotitle::false:: -->',
'<!-- param::maxHeaderLevel::8:: -->',
'**Table of Contents** *generated with [DocToc](https://github.com/technote-space/doctoc)*',
'',
'- [Installation](#installation)',
'- [API](#api)',
' - [dockops::Containers(docker) → {Object}](#dockopscontainersdocker-%E2%86%92-object)',
' - [Parameters:](#parameters)',
' - [Returns:](#returns)',
' - [dockops::Containers::activePorts(cb)](#dockopscontainersactiveportscb)',
' - [Parameters:](#parameters-1)',
' - [dockops::Containers::clean(id, cb)](#dockopscontainerscleanid-cb)',
' - [Parameters:](#parameters-2)',
'- [^License](#license)',
'',
'<!-- END doctoc generated TOC please keep comment here to allow auto update -->',
],
);
});

it('not override params', () => {
const content = readFileSync(resolve(__dirname, 'fixtures/readme-with-params.md'), 'utf8');
const headers = transform(content, {isFolding: true, title: 'Test title'});

expect(headers.wrappedToc.split('\n')).toEqual(
[
'<!-- START doctoc generated TOC please keep comment here to allow auto update -->',
'<!-- DON\'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->',
'<!-- param::entryPrefix::-:: -->',
'<!-- param::mode::github.com:: -->',
'<!-- param::isNotitle::false:: -->',
'<!-- param::maxHeaderLevel::8:: -->',
'<details>',
'<summary>Test title</summary>',
'',
'- [Installation](#installation)',
'- [API](#api)',
' - [dockops::Containers(docker) → {Object}](#dockopscontainersdocker-%E2%86%92-object)',
' - [Parameters:](#parameters)',
' - [Returns:](#returns)',
' - [dockops::Containers::activePorts(cb)](#dockopscontainersactiveportscb)',
' - [Parameters:](#parameters-1)',
' - [dockops::Containers::clean(id, cb)](#dockopscontainerscleanid-cb)',
' - [Parameters:](#parameters-2)',
'- [^License](#license)',
'',
'</details>',
'<!-- END doctoc generated TOC please keep comment here to allow auto update -->',
],
);
});
});
Loading