From 2586b49f31248ff66abb71b52a51e32e4b522009 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 10 Aug 2020 17:26:00 +0800 Subject: [PATCH] Bump xo from 0.25.4 to 0.32.1 (#5) * Bump xo from 0.25.4 to 0.32.1 Bumps [xo](https://github.com/xojs/xo) from 0.25.4 to 0.32.1. - [Release notes](https://github.com/xojs/xo/releases) - [Commits](https://github.com/xojs/xo/compare/v0.25.4...v0.32.1) Signed-off-by: dependabot-preview[bot] * chore(prettier): apply prettier code style Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> Co-authored-by: dailyrandomphoto --- .editorconfig | 9 +++ .github/auto-merge.yml | 8 +- .prettierignore | 7 ++ .prettierrc.json | 13 ++++ README.md | 17 ++--- lib/group-by-lang.js | 4 +- lib/index.js | 167 ++++++++++++++++++++++++----------------- lib/opml.js | 8 +- package.json | 12 +-- test/group-by-lang.js | 38 +++++----- test/index.js | 2 +- 11 files changed, 171 insertions(+), 114 deletions(-) create mode 100644 .editorconfig create mode 100644 .prettierignore create mode 100644 .prettierrc.json diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..c6c8b36 --- /dev/null +++ b/.editorconfig @@ -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 diff --git a/.github/auto-merge.yml b/.github/auto-merge.yml index d35c18c..aadd871 100644 --- a/.github/auto-merge.yml +++ b/.github/auto-merge.yml @@ -4,7 +4,7 @@ minApprovals: reportStatus: true rules: -- minApprovals: - OWNER: 1 -- minApprovals: - MEMBER: 2 + - minApprovals: + OWNER: 1 + - minApprovals: + MEMBER: 2 diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..6f94628 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,7 @@ +coverage/** +node_modules/** +dist/** +build/** +.nyc_output/** +LICENSE +documents/** diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000..3ef8726 --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,13 @@ +{ + "overrides": [ + { + "files": ["**/*.js", "**/*.jsx"], + "options": { + "singleQuote": true, + "jsxSingleQuote": true, + "trailingComma": "none", + "bracketSpacing": true + } + } + ] +} diff --git a/README.md b/README.md index 90a6146..b2169b7 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,7 @@ [![NPM Version][npm-version-image]][npm-url] [![LICENSE][license-image]][license-url] [![Build Status][travis-image]][travis-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 Generator to generate README of Developer Blog Directory. @@ -15,15 +14,19 @@ npm install dev-blog-directory-readme-generator ``` ## Usages + ```sh $ npx readme-gen RAW_DATA_PATH ``` + e.g. + ```sh $ npx readme-gen ../dev-blog-directory-raw/documents ``` ## TOODs + - [x] separate files by Languages. - [x] add feed links (RSS, OPML) - [ ] lastest published date @@ -37,20 +40,16 @@ $ npx readme-gen ../dev-blog-directory-raw/documents - [dev-blog-directory-save-yaml-cli](https://github.com/dailyrandomphoto/dev-blog-directory-save-yaml-cli) - A CLI for saves the YAML format blog list to `documents/*.yml`. ## License + Copyright (c) 2020 [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-readme-generator [travis-url]: https://travis-ci.org/dev-blog-directory/dev-blog-directory-readme-generator -[coveralls-url]: https://coveralls.io/github/dev-blog-directory/dev-blog-directory-readme-generator?branch=master [license-url]: LICENSE -[dependencies-url]: https://david-dm.org/dev-blog-directory/dev-blog-directory-readme-generator -[devDependencies-url]: https://david-dm.org/dev-blog-directory/dev-blog-directory-readme-generator?type=dev - +[code-style-prettier-url]: https://github.com/prettier/prettier [npm-downloads-image]: https://img.shields.io/npm/dm/dev-blog-directory-readme-generator [npm-version-image]: https://img.shields.io/npm/v/dev-blog-directory-readme-generator [license-image]: https://img.shields.io/npm/l/dev-blog-directory-readme-generator [travis-image]: https://img.shields.io/travis/dev-blog-directory/dev-blog-directory-readme-generator -[coveralls-image]: https://img.shields.io/coveralls/github/dev-blog-directory/dev-blog-directory-readme-generator -[dependencies-image]: https://img.shields.io/david/dev-blog-directory/dev-blog-directory-readme-generator -[devDependencies-image]: https://img.shields.io/david/dev/dev-blog-directory/dev-blog-directory-readme-generator +[code-style-prettier-image]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square diff --git a/lib/group-by-lang.js b/lib/group-by-lang.js index aa1ff12..92db559 100644 --- a/lib/group-by-lang.js +++ b/lib/group-by-lang.js @@ -6,9 +6,9 @@ function groupByLang(blogs) { return group; } - blogs.forEach(blog => { + blogs.forEach((blog) => { const langs = blog.langs || ['en']; - langs.forEach(lang => { + langs.forEach((lang) => { group[lang] = group[lang] || []; group[lang].push(blog); }); diff --git a/lib/index.js b/lib/index.js index c0d7aae..b343313 100755 --- a/lib/index.js +++ b/lib/index.js @@ -2,34 +2,35 @@ 'use strict'; -const {resolve, dirname} = require('path'); +const { resolve, dirname } = require('path'); const fs = require('fs-extra'); const readFiles = require('node-read-yaml-files'); -const {slugify} = require('transliteration'); -const {getNativeName} = require('iso-639-1'); -const {Feeds} = require('feed-db'); +const { slugify } = require('transliteration'); +const { getNativeName } = require('iso-639-1'); +const { Feeds } = require('feed-db'); const groupByLang = require('./group-by-lang.js'); const DEST_PATH = resolve(process.cwd(), './dist/readme.md'); const FEED_DB = resolve(process.cwd(), './feed-db.json'); -const {generate} = require('./opml.js'); +const { generate } = require('./opml.js'); function main(path) { - return fs.remove(dirname(DEST_PATH)) + return fs + .remove(dirname(DEST_PATH)) .then(() => fs.mkdirp(dirname(DEST_PATH))) - .then(() => readFiles(path, {flatten: true})) - .then(docs => docs.filter(doc => doc && typeof doc.url === 'string')) - .then(docs => docs.sort(compare)) - .then(blogs => { + .then(() => readFiles(path, { flatten: true })) + .then((docs) => docs.filter((doc) => doc && typeof doc.url === 'string')) + .then((docs) => docs.sort(compare)) + .then((blogs) => { const feeds = new Feeds(FEED_DB); updateFeeds(blogs, feeds); console.log('All blogs count: ' + blogs.length); return blogs; }) .then(groupByLang) - .then(group => makeReadmeByLang(group).concat(makeOpmlByLang(group))) - .then(makeJobs => Promise.all(makeJobs)) + .then((group) => makeReadmeByLang(group).concat(makeOpmlByLang(group))) + .then((makeJobs) => Promise.all(makeJobs)) .then(() => console.log('All Done!')) - .catch(error => console.error('something exploded', error)); + .catch((error) => console.error('something exploded', error)); } function compare(a, b) { @@ -65,36 +66,37 @@ function compareString(a, b) { return 0; } -function sharpenName(str) { - str = unicode2Latin(str); +function sharpenName(string) { + string = unicode2Latin(string); // ignore upper and lowercase - str = str.toLowerCase().trim(); + string = string.toLowerCase().trim(); // Arrange non-alphabetic names after 'z' - if (!/^[A-Za-z]/.test(str)) { - return '\uFFFF' + str; + if (!/^[A-Za-z]/.test(string)) { + return '\uFFFF' + string; } - return str; + return string; } -function unicode2Latin(str) { - str = slugify(str); - return str; +function unicode2Latin(string) { + string = slugify(string); + return string; } function makeReadmeByLang(group) { const allLangs = Object.keys(group).sort(); - return allLangs.map(lang => { - const filePath = lang === 'en' ? DEST_PATH : DEST_PATH.replace('.md', `-${lang}.md`); + return allLangs.map((lang) => { + const filePath = + lang === 'en' ? DEST_PATH : DEST_PATH.replace('.md', `-${lang}.md`); return Promise.resolve(group[lang]) - .then(blogs => { + .then((blogs) => { console.log(`[${lang}] blogs in README count: ${blogs.length}`); return blogs; }) - .then(blogs => makeReadme(blogs, lang, allLangs)) - .then(readme => fs.writeFileSync(filePath, readme)) + .then((blogs) => makeReadme(blogs, lang, allLangs)) + .then((readme) => fs.writeFileSync(filePath, readme)) .then(() => console.log(`Done!\nGenerated ${filePath}`)); }); } @@ -108,32 +110,44 @@ function makeReadme(blogs, lang, allLangs) { readme.push('A comprehensive list of blogs of developers and teams.
'); readme.push('**Recommend your favorite developer blogs.**'); readme.push(''); - readme.push('> Generated from [dev-blog-directory-raw](https://github.com/dailyrandomphoto/dev-blog-directory-raw).'); + readme.push( + '> Generated from [dev-blog-directory-raw](https://github.com/dailyrandomphoto/dev-blog-directory-raw).' + ); readme.push(''); - readme.push(`| ${allLangs.map(lang2 => { - if (lang2 === lang) { - return `**${getNativeName(lang2)}**`; - } - - if (lang2 === 'en') { - return `[${getNativeName(lang2)}](readme.md)`; - } - - return `[${getNativeName(lang2)}](readme-${lang2}.md)`; - }).join(' | ')} |`); + readme.push( + `| ${allLangs + .map((lang2) => { + if (lang2 === lang) { + return `**${getNativeName(lang2)}**`; + } + + if (lang2 === 'en') { + return `[${getNativeName(lang2)}](readme.md)`; + } + + return `[${getNativeName(lang2)}](readme-${lang2}.md)`; + }) + .join(' | ')} |` + ); const opmlFilename = lang === 'en' ? 'readme.opml' : `readme-${lang}.opml`; readme.push(''); - readme.push(`Get [OPML](https://raw.githubusercontent.com/dev-blog-directory/dev-blog-directory/master/${opmlFilename})`); + readme.push( + `Get [OPML](https://raw.githubusercontent.com/dev-blog-directory/dev-blog-directory/master/${opmlFilename})` + ); readme.push(''); readme.push(getHeader()); readme.push(''); - blogs.forEach(blog => { + blogs.forEach((blog) => { const startLetter = sharpenName(blog.name).charCodeAt(0); if (letter !== startLetter) { letter = startLetter; // If a-z if (letter <= 122) { - readme.push(`\n## ${String.fromCharCode(startLetter - 32)} [[top](#developer-blog-directory)]\n`); + readme.push( + `\n## ${String.fromCharCode( + startLetter - 32 + )} [[top](#developer-blog-directory)]\n` + ); } else { readme.push('\n## # [[top](#developer-blog-directory)]\n'); } @@ -144,29 +158,35 @@ function makeReadme(blogs, lang, allLangs) { readme.push(''); readme.push('## Contribution'); readme.push('Contributions are always welcome!'); - readme.push('[Contribution Guidelines](https://github.com/dailyrandomphoto/dev-blog-directory-raw#contribution-guidelines).'); + readme.push( + '[Contribution Guidelines](https://github.com/dailyrandomphoto/dev-blog-directory-raw#contribution-guidelines).' + ); readme.push(''); readme.push('## License'); - readme.push('Copyright (c) 2020 [dailyrandomphoto](https://github.com/dailyrandomphoto). Licensed under the [Creative Commons Attribution 4.0 International License](https://creativecommons.org/licenses/by/4.0/).'); + readme.push( + 'Copyright (c) 2020 [dailyrandomphoto](https://github.com/dailyrandomphoto). Licensed under the [Creative Commons Attribution 4.0 International License](https://creativecommons.org/licenses/by/4.0/).' + ); return readme.join('\n'); } function getHeader() { - const arr = []; + const array = []; // // arr.push('| D | E | V | . | B | L | O | G | . |\n'); - arr.push('| D | I | R | E | C | T | O | R | Y |\n'); - arr.push('| --- | --- | --- | --- | --- | --- | --- | --- | --- |\n'); + array.push('| D | I | R | E | C | T | O | R | Y |\n'); + array.push('| --- | --- | --- | --- | --- | --- | --- | --- | --- |\n'); // Loop A-Z for (let i = 65; i <= 90; i++) { - arr.push(`| [${String.fromCharCode(i)}](#${String.fromCharCode(i + 32)}-top) `); + array.push( + `| [${String.fromCharCode(i)}](#${String.fromCharCode(i + 32)}-top) ` + ); if ((i - 64) % 9 === 0) { - arr.push('|\n'); + array.push('|\n'); } } // Last one - # - arr.push('| [#](#-top) |'); - return arr.join(''); + array.push('| [#](#-top) |'); + return array.join(''); } function makeItem(blog) { @@ -180,8 +200,8 @@ function makeItem(blog) { } if (blog.categories || blog.tags) { - const arr = [].concat(blog.categories || []).concat(blog.tags || []); - const tags = arr.map(i => '`#' + i + '`').join(' '); + const array = [].concat(blog.categories || []).concat(blog.tags || []); + const tags = array.map((i) => '`#' + i + '`').join(' '); result.push(`
${tags}`); } @@ -189,7 +209,7 @@ function makeItem(blog) { } function updateFeeds(blogs, feeds) { - blogs.forEach(blog => { + blogs.forEach((blog) => { const feedUrl = blog.feed; if (!feedUrl) { blog.feed = (feeds.getFeed(blog.url) || {}).feedUrl; @@ -199,36 +219,44 @@ function updateFeeds(blogs, feeds) { function makeOpmlByLang(group) { const allLangs = Object.keys(group).sort(); - return allLangs.map(lang => { - const filePath = lang === 'en' ? DEST_PATH.replace('.md', '.opml') : DEST_PATH.replace('.md', `-${lang}.opml`); + return allLangs.map((lang) => { + const filePath = + lang === 'en' + ? DEST_PATH.replace('.md', '.opml') + : DEST_PATH.replace('.md', `-${lang}.opml`); return Promise.resolve(group[lang]) - .then(blogs => blogs.filter(blog => Boolean(blog.feed))) - .then(blogs => { + .then((blogs) => blogs.filter((blog) => Boolean(blog.feed))) + .then((blogs) => { console.log(`[${lang}] blogs in OPML count: ${blogs.length}`); return blogs; }) - .then(blogs => generate(blogs, lang)) - .then(xml => fs.writeFileSync(filePath, xml)) + .then((blogs) => generate(blogs, lang)) + .then((xml) => fs.writeFileSync(filePath, xml)) .then(() => console.log(`Done!\nGenerated ${filePath}`)); }); } -function exit(msg) { - if (msg) { - console.error('\n' + msg); +function exit(message) { + if (message) { + console.error('\n' + message); } - if (require.main === module) { // Called directly + if (require.main === module) { + // Called directly process.exit(1); - } else { // Required as a module - throw msg; + } else { + // Required as a module + throw message; } } -if (require.main === module) { // Called directly +if (require.main === module) { + // Called directly const filename = process.argv.slice(2, 3)[0]; if (!filename) { - exit('Usage: readme-gen RAW_DATA_PATH\n e.g.: $ npx readme-gen ../dev-blog-directory-raw/documents'); + exit( + 'Usage: readme-gen RAW_DATA_PATH\n e.g.: $ npx readme-gen ../dev-blog-directory-raw/documents' + ); } const filepath = resolve(process.cwd(), filename); @@ -236,6 +264,7 @@ if (require.main === module) { // Called directly console.log('file name: ' + filename); console.log('full path: ' + filepath); main(filepath); -} else { // Required as a module +} else { + // Required as a module module.exports = main; } diff --git a/lib/opml.js b/lib/opml.js index acfbcf6..1f0b0ea 100644 --- a/lib/opml.js +++ b/lib/opml.js @@ -2,7 +2,7 @@ const opml = require('opml-generator'); const format = require('xml-formatter'); -const {getNativeName} = require('iso-639-1'); +const { getNativeName } = require('iso-639-1'); function generate(blogs, lang) { const header = { @@ -12,7 +12,7 @@ function generate(blogs, lang) { ownerName: 'https://github.com/dailyrandomphoto' }; - const outlines = blogs.map(blog => ({ + const outlines = blogs.map((blog) => ({ type: 'rss', text: blog.name, title: blog.name, @@ -20,7 +20,7 @@ function generate(blogs, lang) { htmlUrl: blog.url })); - return format(opml(header, outlines), {collapseContent: true}); + return format(opml(header, outlines), { collapseContent: true }); } -module.exports = {generate}; +module.exports = { generate }; diff --git a/package.json b/package.json index 7e9bf85..adcbfeb 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,8 @@ }, "scripts": { "demo": "readme-gen documents", - "lint": "xo", - "lint:fix": "xo --fix", + "lint": "prettier --write . && xo", + "lint:fix": "prettier --write . && xo --fix", "test": "mocha test/index.js", "test:cov": "nyc npm run test", "test:loop": "while npm test --silent; do :; done" @@ -27,8 +27,8 @@ "chai": "^4.2.0", "mocha": "^8.1.1", "nyc": "^15.1.0", - "unlink-self": "latest", - "xo": "^0.25.3" + "prettier": "^2.0.5", + "xo": "^0.32.1" }, "keywords": [ "readme", @@ -56,8 +56,10 @@ "homepage": "https://github.com/dev-blog-directory/dev-blog-directory-readme-generator#readme", "xo": { "space": 2, + "prettier": true, "rules": { - "promise/prefer-await-to-then": 0 + "promise/prefer-await-to-then": 0, + "capitalized-comments": 0 }, "overrides": [ { diff --git a/test/group-by-lang.js b/test/group-by-lang.js index 350d72c..0684ba8 100644 --- a/test/group-by-lang.js +++ b/test/group-by-lang.js @@ -1,6 +1,6 @@ 'use strict'; -const {expect} = require('chai'); +const { expect } = require('chai'); const groupByLang = require('../lib/group-by-lang.js'); describe('groupByLang', () => { @@ -12,9 +12,7 @@ describe('groupByLang', () => { }); it('default lang - en', () => { - const blogs = [ - {url: 'http://blog.com/1'} - ]; + const blogs = [{ url: 'http://blog.com/1' }]; const result = groupByLang(blogs); expect(result).to.be.an('object'); expect(result.en).to.be.an('array').to.have.lengthOf(1); @@ -24,14 +22,14 @@ describe('groupByLang', () => { it('multi langs', () => { const blogs = [ - {url: 'http://blog.com/1'}, - {url: 'http://blog.com/2', langs: ['zh']}, - {url: 'http://blog.com/3', langs: ['ko']}, - {url: 'http://blog.com/4', langs: ['ja']}, - {url: 'http://blog.com/5', langs: ['en']}, - {url: 'http://blog.com/6', langs: ['zh']}, - {url: 'http://blog.com/7', langs: ['ko']}, - {url: 'http://blog.com/8', langs: ['ja']} + { url: 'http://blog.com/1' }, + { url: 'http://blog.com/2', langs: ['zh'] }, + { url: 'http://blog.com/3', langs: ['ko'] }, + { url: 'http://blog.com/4', langs: ['ja'] }, + { url: 'http://blog.com/5', langs: ['en'] }, + { url: 'http://blog.com/6', langs: ['zh'] }, + { url: 'http://blog.com/7', langs: ['ko'] }, + { url: 'http://blog.com/8', langs: ['ja'] } ]; const result = groupByLang(blogs); expect(result).to.be.an('object'); @@ -46,14 +44,14 @@ describe('groupByLang', () => { it('multi langs 2', () => { const blogs = [ - {url: 'http://blog.com/1'}, - {url: 'http://blog.com/2', langs: ['zh', 'en']}, - {url: 'http://blog.com/3', langs: ['ko', 'en']}, - {url: 'http://blog.com/4', langs: ['ja', 'en']}, - {url: 'http://blog.com/5', langs: ['en', 'ko']}, - {url: 'http://blog.com/6', langs: ['zh', 'ko']}, - {url: 'http://blog.com/7', langs: ['ko']}, - {url: 'http://blog.com/8', langs: ['ja']} + { url: 'http://blog.com/1' }, + { url: 'http://blog.com/2', langs: ['zh', 'en'] }, + { url: 'http://blog.com/3', langs: ['ko', 'en'] }, + { url: 'http://blog.com/4', langs: ['ja', 'en'] }, + { url: 'http://blog.com/5', langs: ['en', 'ko'] }, + { url: 'http://blog.com/6', langs: ['zh', 'ko'] }, + { url: 'http://blog.com/7', langs: ['ko'] }, + { url: 'http://blog.com/8', langs: ['ja'] } ]; const result = groupByLang(blogs); expect(result).to.be.an('object'); diff --git a/test/index.js b/test/index.js index b08a0a6..2afd72a 100644 --- a/test/index.js +++ b/test/index.js @@ -1,6 +1,6 @@ 'use strict'; -const {expect} = require('chai'); +const { expect } = require('chai'); const main = require('../lib'); describe('dev-blog-directory-readme-generator', () => {