├── .editorconfig ├── .gitattributes ├── .gitignore ├── .travis.yml ├── cli.js ├── license ├── package.json ├── readme.md └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [{package.json,*.yml}] 11 | indent_style = space 12 | indent_size = 2 13 | 14 | [*.md] 15 | trim_trailing_whitespace = false 16 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '5' 4 | - '4' 5 | -------------------------------------------------------------------------------- /cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 'use strict' 3 | const minimist = require('minimist') 4 | const saikou = require('saikou') 5 | const fetch = require('node-fetch') 6 | const Spin = require('io-spin') 7 | const update = require('update-notifier') 8 | const pkg = require('./package') 9 | require('colorful').toxic() 10 | 11 | update({pkg}).notify() 12 | 13 | const argv = minimist(process.argv.slice(2), {'--': true}) 14 | const number = argv._[0] || 1 15 | const color = typeof argv.color === 'undefined' || argv.color 16 | 17 | if (number === 'h') { 18 | const spin = new Spin() 19 | spin.start() 20 | fetch('http://api.hitokoto.us/rand') 21 | .then(data => data.json()) 22 | .then(data => { 23 | spin.stop() 24 | if (color) { 25 | console.log(`${data.hitokoto.cyan} ${data.source ? ` ${'--'.grey}${data.source.magenta}` : ''}`) 26 | } else { 27 | console.log(`${data.hitokoto} ${data.source ? ` ${'--'}${data.source}` : ''}`) 28 | } 29 | }) 30 | .catch(err => console.log(err.stack)) 31 | } else { 32 | for (let i = 0; i < number; i++) { 33 | if (color) { 34 | console.log(saikou().cyan) 35 | } else { 36 | console.log(saikou()) 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) EGOIST <0x142857@gmail.com> (github.com/egoist) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "saikou-cli", 3 | "version": "0.1.1", 4 | "description": "your cli and saikou!", 5 | "license": "MIT", 6 | "repository": "egoist/saikou-cli", 7 | "author": { 8 | "name": "EGOIST", 9 | "email": "0x142857@gmail.com", 10 | "url": "github.com/egoist" 11 | }, 12 | "bin": { 13 | "saikou": "cli.js" 14 | }, 15 | "engines": { 16 | "node": ">=4" 17 | }, 18 | "scripts": { 19 | "test": "xo && ava" 20 | }, 21 | "files": [ 22 | "cli.js" 23 | ], 24 | "keywords": [ 25 | "cli-app", 26 | "cli", 27 | "saikou", 28 | "acg" 29 | ], 30 | "dependencies": { 31 | "colorful": "^2.1.0", 32 | "io-spin": "^0.2.2", 33 | "minimist": "^1.2.0", 34 | "node-fetch": "^1.3.3", 35 | "saikou": "0.0.1", 36 | "update-notifier": "^0.6.0" 37 | }, 38 | "devDependencies": { 39 | "ava": "^0.8.0", 40 | "execa": "^0.2.2", 41 | "xo": "^0.12.1" 42 | }, 43 | "xo": { 44 | "semicolon": false 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # saikou-cli [![Build Status](https://travis-ci.org/egoist/saikou-cli.svg?branch=master)](https://travis-ci.org/egoist/saikou-cli) 2 | 3 | > your cli and saikou! 4 | 5 | ![preview](http://i.imgur.com/A3OT1Ea.png) 6 | 7 | ## CLI 8 | 9 | ``` 10 | $ npm install --global saikou-cli 11 | ``` 12 | 13 | ```bash 14 | $ saikou [number] 15 | # eg: saikou 4 16 | # eg: saikou 17 | 18 | $ saikou h 19 | # fetch from http://hitokoto.us 20 | ``` 21 | 22 | ## Related 23 | 24 | 25 | - [saikou](https://github.com/egoist/saikou): The api used by this module 26 | 27 | 28 | 29 | ## License 30 | 31 | MIT © [EGOIST](https://github.com/egoist) 32 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava' 2 | import execa from 'execa' 3 | 4 | test('moegirl', async t => { 5 | const {stdout} = await execa.shell('node cli.js 2') 6 | t.same(stdout.split('\n').length, 2) 7 | }) 8 | 9 | /* 10 | test('yiyan', async t => { 11 | const {stdout} = await execa.shell('node cli.js h').catch(err => t.fail(err)) 12 | t.same(typeof stdout, 'string') 13 | }) 14 | */ 15 | --------------------------------------------------------------------------------