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

v1.1.0 #3

Merged
merged 5 commits into from
Jul 4, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
## Features

- [x] _cli_ - Command line interface.
- [x] _travis_ - Automatically loads `.travis.yml` file and executes the inside `scripts`.
- [x] _travis_ - Automatically loads `.travis.yml` file and executes the inside `script`.
- [x] _custom_ - Higher priority custom `.ciscript.yml` file, optional.

## Install

Expand All @@ -30,7 +31,7 @@ npm install -g ci-script
```bash
$ ci-script -h

Usage: ci-script [options] [dir]
Usage: ci-script [options] [directory]

Execute the CI script.

Expand All @@ -39,6 +40,21 @@ $ ci-script -h
-v, -V, --version, version output the version number
```

## Configuration

If you need to customize the `.ciscript.yml` file, the rules configured like this:
```yaml
script:
# commands are written in order.
- echo "One"
- echo "Two"
- echo "Three"
```

can also copy the `script` in the `.travis.yml` file, then customize it.

> Note: `.ciscript.yml` is optional.

## Example

```bash
Expand Down
2 changes: 1 addition & 1 deletion ci-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const shell = require('./shell');

function outputHelp() {
process.stdout.write(`
Usage: ci-script [options] [dir]
Usage: ci-script [options] [directory]

Execute the CI scripts.

Expand Down
16 changes: 10 additions & 6 deletions loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ const path = require('path');

const yaml = require('js-yaml');

function loadSyncTravis(dir) {
let filePath = path.join(path.resolve(dir || process.cwd()), '.travis.yml');
fs.accessSync(filePath, fs.R_OK);

function loadScripts(dir) {
dir = path.resolve(dir || process.cwd());
let filePath = path.join(dir, '.ciscript.yml');
try {
fs.accessSync(filePath, fs.R_OK);
} catch (e) {
filePath = path.join(dir, '.travis.yml');
}
let doc = yaml.safeLoad(fs.readFileSync(filePath, 'utf8'));
if (doc.script && Array.isArray(doc.script)) {
return doc.script;
Expand All @@ -20,11 +24,11 @@ function loadSyncTravis(dir) {
}

function loadSync(dir) {
return loadSyncTravis(dir);
return loadScripts(dir);
}

function* load(dir) {
return yield loadSyncTravis(dir);
return yield loadScripts(dir);
}

module.exports.load = dir =>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ci-script",
"version": "1.0.1",
"version": "1.1.0",
"description": "Just execute the CI scripts.",
"preferGlobal": true,
"main": "index.js",
Expand Down
3 changes: 3 additions & 0 deletions tests/config/.ciscript.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# see https://github.com/WindomZ/ci-script
script:
- echo 'Success!'
10 changes: 10 additions & 0 deletions tests/loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,14 @@ test('loader pass', async t => {
.catch(e => {
t.fail(e);
});

await loader
.load('tests/config')
.then(r => {
t.not(r, []);
t.pass();
})
.catch(e => {
t.fail(e);
});
});
9 changes: 9 additions & 0 deletions tests/shell.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,13 @@ test('shell pass', async t => {
.catch(() => {
t.pass();
});

await shell
.exec('tests/config')
.then(() => {
t.pass();
})
.catch(e => {
t.fail(e);
});
});