From fb2940d1ef64e3f17a3337fc8648cd97b62d1552 Mon Sep 17 00:00:00 2001 From: WindomZ Date: Tue, 4 Jul 2017 21:11:58 +0800 Subject: [PATCH 1/5] feat: support .ciscript.yml --- loader.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) 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 => From 984010246ae88a1a6e418fc4308fca2cd1423266 Mon Sep 17 00:00:00 2001 From: WindomZ Date: Tue, 4 Jul 2017 21:12:13 +0800 Subject: [PATCH 2/5] test: support .ciscript.yml --- tests/config/.ciscript.yml | 3 +++ tests/loader.test.js | 10 ++++++++++ tests/shell.test.js | 9 +++++++++ 3 files changed, 22 insertions(+) create mode 100644 tests/config/.ciscript.yml 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); + }); }); From 740113b677f93e4e88c963f61a9530563ac781b6 Mon Sep 17 00:00:00 2001 From: WindomZ Date: Tue, 4 Jul 2017 22:55:14 +0800 Subject: [PATCH 3/5] update README.md --- README.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 767c94b..75ffd01 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 @@ -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 From 18f901132c24a5dada24e30788d2884e03c34b49 Mon Sep 17 00:00:00 2001 From: WindomZ Date: Tue, 4 Jul 2017 23:23:09 +0800 Subject: [PATCH 4/5] update package.json to v1.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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", From 450b24213f52de7c6f760fb3c6aec78ff2f7d4e0 Mon Sep 17 00:00:00 2001 From: WindomZ Date: Tue, 4 Jul 2017 23:27:24 +0800 Subject: [PATCH 5/5] update dir -> directory --- README.md | 2 +- ci-script.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 75ffd01..0f451ea 100644 --- a/README.md +++ b/README.md @@ -31,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. 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.