diff --git a/README.md b/README.md index 767c94b..0f451ea 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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. @@ -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 diff --git a/ci-script.js b/ci-script.js index fcc6096..ea48a86 100755 --- a/ci-script.js +++ b/ci-script.js @@ -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. diff --git a/loader.js b/loader.js index 83d5e70..addff65 100644 --- a/loader.js +++ b/loader.js @@ -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; @@ -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 => diff --git a/package.json b/package.json index 7c81626..c8c08e5 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/tests/config/.ciscript.yml b/tests/config/.ciscript.yml new file mode 100644 index 0000000..4823039 --- /dev/null +++ b/tests/config/.ciscript.yml @@ -0,0 +1,3 @@ +# see https://github.com/WindomZ/ci-script +script: + - echo 'Success!' diff --git a/tests/loader.test.js b/tests/loader.test.js index 88c3e57..dda1469 100644 --- a/tests/loader.test.js +++ b/tests/loader.test.js @@ -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); + }); }); diff --git a/tests/shell.test.js b/tests/shell.test.js index 53a4eeb..c100585 100644 --- a/tests/shell.test.js +++ b/tests/shell.test.js @@ -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); + }); });