Skip to content

Commit

Permalink
Apply Prettier code style
Browse files Browse the repository at this point in the history
  • Loading branch information
dailyrandomphoto committed Aug 7, 2020
1 parent b502c0d commit ddbfb79
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 31 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
1 change: 1 addition & 0 deletions .new.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ categories:
tags:
- JavaScript
---

7 changes: 7 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
coverage/**
node_modules/**
dist/**
build/**
.nyc_output/**
LICENSE
documents/**
13 changes: 13 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"overrides": [
{
"files": ["**/*.js", "**/*.jsx"],
"options": {
"singleQuote": true,
"jsxSingleQuote": true,
"trailingComma": "none",
"bracketSpacing": true
}
}
]
}
15 changes: 5 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
[![NPM Version][npm-version-image]][npm-url]
[![LICENSE][license-image]][license-url]
[![Build Status][travis-image]][travis-url]
[![Coverage Status][coveralls-image]][coveralls-url]
[![dependencies Status][dependencies-image]][dependencies-url]
[![devDependencies Status][devDependencies-image]][devDependencies-url]
[![code style: prettier][code-style-prettier-image]][code-style-prettier-url]

A CLI for saves the YAML format blog list to `documents/*.yml`.

Expand All @@ -16,6 +14,7 @@ npm install dev-blog-directory-save-yaml-cli
```

## Usages

```sh
$ npx save-blog [--merge] [YAMLFILE]

Expand All @@ -34,20 +33,16 @@ If `YAMLFILE` is not provided, `new.yml` will be used.
- [dev-blog-directory-save-json-cli](https://github.com/dailyrandomphoto/dev-blog-directory-save-json-cli) - A CLI for saves the JSON format blog list to `documents/*.yml`.

## License

Copyright (c) 2019 [dailyrandomphoto][my-url]. Licensed under the [MIT license][license-url].

[my-url]: https://github.com/dailyrandomphoto
[npm-url]: https://www.npmjs.com/package/dev-blog-directory-save-yaml-cli
[travis-url]: https://travis-ci.org/dailyrandomphoto/dev-blog-directory-save-yaml-cli
[coveralls-url]: https://coveralls.io/github/dailyrandomphoto/dev-blog-directory-save-yaml-cli?branch=master
[license-url]: LICENSE
[dependencies-url]: https://david-dm.org/dailyrandomphoto/dev-blog-directory-save-yaml-cli
[devDependencies-url]: https://david-dm.org/dailyrandomphoto/dev-blog-directory-save-yaml-cli?type=dev

[code-style-prettier-url]: https://github.com/prettier/prettier
[npm-downloads-image]: https://img.shields.io/npm/dm/dev-blog-directory-save-yaml-cli
[npm-version-image]: https://img.shields.io/npm/v/dev-blog-directory-save-yaml-cli
[license-image]: https://img.shields.io/npm/l/dev-blog-directory-save-yaml-cli
[travis-image]: https://img.shields.io/travis/dailyrandomphoto/dev-blog-directory-save-yaml-cli
[coveralls-image]: https://img.shields.io/coveralls/github/dailyrandomphoto/dev-blog-directory-save-yaml-cli
[dependencies-image]: https://img.shields.io/david/dailyrandomphoto/dev-blog-directory-save-yaml-cli
[devDependencies-image]: https://img.shields.io/david/dev/dailyrandomphoto/dev-blog-directory-save-yaml-cli
[code-style-prettier-image]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square
30 changes: 17 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,41 @@
'use strict';

const fs = require('fs');
const {resolve} = require('path');
const { resolve } = require('path');
const read = require('node-read-yaml');
const {FAILSAFE_SCHEMA} = require('node-read-yaml');
const {saveAll} = require('dev-blog-directory-save');
const { FAILSAFE_SCHEMA } = require('node-read-yaml');
const { saveAll } = require('dev-blog-directory-save');
const newFilename = 'new.yml';
const templateFilename = '.new.yml';

function main(filepath, reset, options) {
return read(filepath, {multi: true, schema: FAILSAFE_SCHEMA})
.then(docs => docs.filter(doc => doc && typeof doc === 'object'))
.then(docs => saveAll(docs, options))
return read(filepath, { multi: true, schema: FAILSAFE_SCHEMA })
.then((docs) => docs.filter((doc) => doc && typeof doc === 'object'))
.then((docs) => saveAll(docs, options))
.then(() => {
if (reset === true) {
fs.copyFileSync(templateFilename, filepath);
}
});
}

function exit(msg) {
if (msg) {
console.error('\n' + msg);
function exit(message) {
if (message) {
console.error('\n' + message);

process.exit(1);
}

process.exit(0);
}

if (require.main === module) { // Called directly
const argv = require('minimist')(process.argv.slice(2), {boolean: ['merge']});
if (require.main === module) {
// Called directly
const argv = require('minimist')(process.argv.slice(2), {
boolean: ['merge']
});
let filename = argv._[0];
const options = {merge: Boolean(argv.merge)};
const options = { merge: Boolean(argv.merge) };
let reset = false;
if (!filename) {
filename = newFilename;
Expand All @@ -50,6 +53,7 @@ if (require.main === module) { // Called directly
console.log('Done!');
})
.catch(exit);
} else { // Required as a module
} else {
// Required as a module
module.exports = main;
}
1 change: 1 addition & 0 deletions new.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ categories:
tags:
- JavaScript
---

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
},
"scripts": {
"demo": "save-blog",
"lint": "xo",
"lint:fix": "xo --fix",
"lint": "prettier --write . && xo",
"lint:fix": "prettier --write . && xo --fix",
"test": "mocha test.js",
"test:cov": "nyc npm run test",
"test:loop": "while npm test --silent; do :; done",
Expand All @@ -28,6 +28,7 @@
"dev-blog-directory-save-yaml-cli": "file:.",
"mocha": "^8.1.1",
"nyc": "^15.1.0",
"prettier": "latest",
"unlink-self": "latest",
"xo": "^0.32.1"
},
Expand Down Expand Up @@ -58,8 +59,10 @@
"homepage": "https://github.com/dailyrandomphoto/dev-blog-directory-save-yaml-cli#readme",
"xo": {
"space": 2,
"prettier": true,
"rules": {
"promise/prefer-await-to-then": 0
"promise/prefer-await-to-then": 0,
"capitalized-comments": 0
},
"overrides": [
{
Expand Down
11 changes: 6 additions & 5 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ const fs = require('fs-extra');
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
const {expect} = chai;
const { expect } = chai;
const main = require('dev-blog-directory-save-yaml-cli');
const {YAMLException} = require('node-read-yaml');
const { YAMLException } = require('node-read-yaml');

describe('dev-blog-directory-save-yaml-cli', () => {
before(() => {
return fs.remove('./documents')
return fs
.remove('./documents')
.then(() => {
console.log('remove ./documents success!');
})
.catch(error => {
.catch((error) => {
console.error(error);
});
});
Expand All @@ -40,6 +41,6 @@ describe('dev-blog-directory-save-yaml-cli', () => {
});

it('with merge option', () => {
return expect(main('new.yml', false, {merge: true})).to.be.fulfilled;
return expect(main('new.yml', false, { merge: true })).to.be.fulfilled;
});
});

0 comments on commit ddbfb79

Please sign in to comment.