mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 19:33:02 +03:00
🛠 Moved Pretty-CLI into Ghost-Utils repo
- this was originally created in the slimer repo, as that's where it was first used - it's also used in migrate, should be used in gscan, and hopefully eventually, will also be part of Ghost-CLI - therefore, it belongs somewhere more general
This commit is contained in:
commit
93dbcef099
6
ghost/pretty-cli/.eslintrc.js
Normal file
6
ghost/pretty-cli/.eslintrc.js
Normal file
@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
plugins: ['ghost'],
|
||||
extends: [
|
||||
'plugin:ghost/node',
|
||||
]
|
||||
};
|
21
ghost/pretty-cli/LICENSE
Normal file
21
ghost/pretty-cli/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018-2019 Ghost Foundation
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
46
ghost/pretty-cli/README.md
Normal file
46
ghost/pretty-cli/README.md
Normal file
@ -0,0 +1,46 @@
|
||||
# Pretty CLI
|
||||
|
||||
A mini-module to style a [sywac](http://sywac.io/) instance in a standard way
|
||||
|
||||
## Install
|
||||
|
||||
Either: `npm install @tryghost/pretty-cli --save`
|
||||
|
||||
Or: `yarn add @tryghost/pretty-cli`
|
||||
|
||||
## Usage
|
||||
|
||||
E.g. `const prettyCLI = require('@tryghost/pretty-cli');`
|
||||
|
||||
`prettyCLI` is a pre-styled instance of the [sywac](http://sywac.io/) API.
|
||||
|
||||
See the [sywac quickstart](http://sywac.io/docs/) and [config guide](http://sywac.io/docs/sync-config.html) for full usage.
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
#!/usr/bin/env node
|
||||
const prettyCLI = require('@tryghost/pretty-cli');
|
||||
|
||||
|
||||
prettyCLI
|
||||
.command({
|
||||
flags: 'myTask [option]',
|
||||
desc: 'Run myTask',
|
||||
run: (argv) => { ... do something here }
|
||||
})
|
||||
.parseAndExit();
|
||||
```
|
||||
|
||||
You can also grab a fresh instance of the api with `prettyCLI.Api.get()`.
|
||||
|
||||
The style rules used are available at `prettyCLI.styles`.
|
||||
|
||||
## Test
|
||||
|
||||
- `yarn lint` run just eslint
|
||||
- `yarn test` run lint && tests
|
||||
|
||||
# Copyright & License
|
||||
|
||||
Copyright (c) 2018-2019 Ghost Foundation - Released under the [MIT license](LICENSE).
|
1
ghost/pretty-cli/index.js
Normal file
1
ghost/pretty-cli/index.js
Normal file
@ -0,0 +1 @@
|
||||
module.exports = require('./lib/pretty-cli');
|
30
ghost/pretty-cli/lib/pretty-cli.js
Normal file
30
ghost/pretty-cli/lib/pretty-cli.js
Normal file
@ -0,0 +1,30 @@
|
||||
const Api = require('sywac/api');
|
||||
const styles = require('./styles');
|
||||
const ui = require('./ui');
|
||||
/**
|
||||
* Pretty CLI
|
||||
*
|
||||
* A mini-module to style a sywac instance in a standard way
|
||||
*/
|
||||
|
||||
// Exports a pre-configured version of sywac
|
||||
module.exports = Api.get()
|
||||
// Use help & version with short forms AND
|
||||
// group them into a Global Options group to keep them separate from per-command options
|
||||
.help('-h, --help', {group: 'Global Options:'})
|
||||
.version('-v, --version', {group: 'Global Options:'})
|
||||
// Load our style rules
|
||||
.style(styles)
|
||||
// Add some padding at the end
|
||||
.epilogue(' ')
|
||||
// If no command is passed, output the help menu
|
||||
.showHelpByDefault();
|
||||
|
||||
// Expose a clean version, just in case
|
||||
module.exports.Api = Api;
|
||||
|
||||
// Export the styles
|
||||
module.exports.styles = styles;
|
||||
|
||||
// Export our ui tools
|
||||
module.exports.ui = ui;
|
21
ghost/pretty-cli/lib/styles.js
Normal file
21
ghost/pretty-cli/lib/styles.js
Normal file
@ -0,0 +1,21 @@
|
||||
const chalk = require('chalk');
|
||||
|
||||
module.exports = {
|
||||
// Usage: script [options] etc
|
||||
usagePrefix: (str) => {
|
||||
return chalk.yellow(str.slice(0, 6)) + '\n ' + str.slice(7);
|
||||
},
|
||||
// Options: Arguments: etc
|
||||
group: str => chalk.yellow(str),
|
||||
// --help etc
|
||||
flags: str => chalk.green(str),
|
||||
// [required] [boolean] etc
|
||||
hints: str => chalk.dim(str),
|
||||
// Use different style when a type is invalid
|
||||
groupError: str => chalk.red(str),
|
||||
flagsError: str => chalk.red(str),
|
||||
descError: str => chalk.yellow(str),
|
||||
hintsError: str => chalk.red(str),
|
||||
// style error messages
|
||||
messages: str => chalk.red(str)
|
||||
};
|
15
ghost/pretty-cli/lib/ui.js
Normal file
15
ghost/pretty-cli/lib/ui.js
Normal file
@ -0,0 +1,15 @@
|
||||
const chalk = require('chalk');
|
||||
const log = (...args) => console.log(...args); // eslint-disable-line no-console
|
||||
|
||||
module.exports.log = log;
|
||||
module.exports.log.error = (...args) => {
|
||||
log(chalk.red('error'), ...args);
|
||||
};
|
||||
|
||||
module.exports.log.info = (...args) => {
|
||||
log(chalk.cyan('info'), ...args);
|
||||
};
|
||||
|
||||
module.exports.log.ok = (...args) => {
|
||||
log(chalk.green('ok'), ...args);
|
||||
};
|
31
ghost/pretty-cli/package.json
Normal file
31
ghost/pretty-cli/package.json
Normal file
@ -0,0 +1,31 @@
|
||||
{
|
||||
"name": "@tryghost/pretty-cli",
|
||||
"version": "1.1.4",
|
||||
"description": "A mini-module to style a sywac instance in a standard way",
|
||||
"repository": "https://github.com/TryGhost/slimer/tree/master/packages/pretty-cli",
|
||||
"author": "Ghost Foundation",
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"dev": "echo \"Implement me!\"",
|
||||
"test": "NODE_ENV=testing mocha ./test/**/*.test.js",
|
||||
"lint": "eslint . --ext .js --cache",
|
||||
"posttest": "yarn lint"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"lib"
|
||||
],
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "6.0.2",
|
||||
"should": "13.2.3",
|
||||
"sinon": "7.2.7"
|
||||
},
|
||||
"dependencies": {
|
||||
"chalk": "^2.4.1",
|
||||
"sywac": "^1.2.1"
|
||||
}
|
||||
}
|
6
ghost/pretty-cli/test/.eslintrc.js
Normal file
6
ghost/pretty-cli/test/.eslintrc.js
Normal file
@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
plugins: ['ghost'],
|
||||
extends: [
|
||||
'plugin:ghost/test',
|
||||
]
|
||||
};
|
32
ghost/pretty-cli/test/pretty-cli.test.js
Normal file
32
ghost/pretty-cli/test/pretty-cli.test.js
Normal file
@ -0,0 +1,32 @@
|
||||
// Switch these lines once there are useful utils
|
||||
// const testUtils = require('./utils');
|
||||
require('./utils');
|
||||
|
||||
const prettyCLI = require('../lib/pretty-cli');
|
||||
|
||||
// Check the API is as we depend on in other modules;
|
||||
describe('API', function () {
|
||||
it('Exposes styled-sywac, styles & the sywac API', function () {
|
||||
// Detect a basic prestyled sywac instance
|
||||
prettyCLI.should.be.an.Object().with.property('types');
|
||||
prettyCLI.parseAndExit.should.be.a.Function();
|
||||
|
||||
// Detect the basic sywac Api
|
||||
prettyCLI.Api.should.be.a.Function();
|
||||
prettyCLI.Api.get.should.be.a.Function();
|
||||
|
||||
// Detect style rules
|
||||
prettyCLI.styles.should.be.an.Object();
|
||||
prettyCLI.styles.should.have.properties([
|
||||
'usagePrefix',
|
||||
'group',
|
||||
'flags',
|
||||
'hints',
|
||||
'groupError',
|
||||
'flagsError',
|
||||
'descError',
|
||||
'hintsError',
|
||||
'messages'
|
||||
]);
|
||||
});
|
||||
});
|
11
ghost/pretty-cli/test/utils/assertions.js
Normal file
11
ghost/pretty-cli/test/utils/assertions.js
Normal file
@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Custom Should Assertions
|
||||
*
|
||||
* Add any custom assertions to this file.
|
||||
*/
|
||||
|
||||
// Example Assertion
|
||||
// should.Assertion.add('ExampleAssertion', function () {
|
||||
// this.params = {operator: 'to be a valid Example Assertion'};
|
||||
// this.obj.should.be.an.Object;
|
||||
// });
|
11
ghost/pretty-cli/test/utils/index.js
Normal file
11
ghost/pretty-cli/test/utils/index.js
Normal file
@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Test Utilities
|
||||
*
|
||||
* Shared utils for writing tests
|
||||
*/
|
||||
|
||||
// Require overrides - these add globals for tests
|
||||
require('./overrides');
|
||||
|
||||
// Require assertions - adds custom should assertions
|
||||
require('./assertions');
|
10
ghost/pretty-cli/test/utils/overrides.js
Normal file
10
ghost/pretty-cli/test/utils/overrides.js
Normal file
@ -0,0 +1,10 @@
|
||||
// This file is required before any test is run
|
||||
|
||||
// Taken from the should wiki, this is how to make should global
|
||||
// Should is a global in our eslint test config
|
||||
global.should = require('should').noConflict();
|
||||
should.extend();
|
||||
|
||||
// Sinon is a simple case
|
||||
// Sinon is a global in our eslint test config
|
||||
global.sinon = require('sinon');
|
Loading…
Reference in New Issue
Block a user