Skip to content

Commit

Permalink
Merge pull request #26 from ndaidong/v5.0.0rc1
Browse files Browse the repository at this point in the history
v5.0.0rc1
  • Loading branch information
ndaidong authored Jan 4, 2022
2 parents 84d2268 + dff3a3f commit cc967be
Show file tree
Hide file tree
Showing 27 changed files with 5,525 additions and 2,759 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
node_version: [10.14.2, 14.x, 15.x, 16.x, 17.x]
node_version: [14.x, 15.x, 16.x, 17.x]

steps:
- uses: actions/checkout@v2
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ coverage
yarn.lock
coverage.lcov
package-lock.json
pnpm-lock.yaml

output.json
24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@ Load and parse RSS/ATOM data from given feed url.
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=ndaidong_feed-reader&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=ndaidong_feed-reader)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

## Demo

### Usage

```bash
npm install feed-reader
```
- [Give it a try!](https://demos.pwshub.com/feed-reader)
- [Example FaaS](https://extractor.pwshub.com/feed/parse?url=https://news.google.com/rss&apikey=demo-orePhhidnWKWPvF8EYKap7z55cN)

Then
### Usage

```js
const {
read
} = require('feed-reader')
import { read } from 'feed-reader'

// with CommonJS environments
// const { read } = require('feed-reader/dist/cjs/feed-reader.js')

const url = 'https://news.google.com/rss'

Expand All @@ -31,6 +30,13 @@ read(url).then((feed) => {
})
```

##### Note:

> Since Node.js v14, ECMAScript modules [have became the official standard format](https://nodejs.org/docs/latest-v14.x/api/esm.html#esm_modules_ecmascript_modules).
> Just ensure that you are [using module system](https://nodejs.org/api/packages.html#determining-module-system) and enjoy with ES6 import/export syntax.

## APIs

- [.read(String url)](#readstring-url)
Expand Down
53 changes: 53 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* build.js
* @ndaidong
**/

import { readFileSync, writeFileSync } from 'fs'
import { execSync } from 'child_process'

import { buildSync } from 'esbuild'

const pkg = JSON.parse(readFileSync('./package.json'))

execSync('rm -rf dist')
execSync('mkdir dist')

const buildTime = (new Date()).toISOString()
const comment = [
`// ${pkg.name}@${pkg.version}, by ${pkg.author}`,
`built with esbuild at ${buildTime}`,
`published under ${pkg.license} license`
].join(' - ')

const baseOpt = {
entryPoints: ['src/main.js'],
bundle: true,
charset: 'utf8',
target: ['es2020', 'node14'],
minify: false,
write: true
}

const cjsVersion = {
...baseOpt,
platform: 'node',
format: 'cjs',
mainFields: ['main'],
outfile: `dist/cjs/${pkg.name}.js`,
banner: {
js: comment
}
}
buildSync(cjsVersion)

const cjspkg = {
name: pkg.name + '-cjs',
version: pkg.version,
main: `./${pkg.name}.js`
}
writeFileSync(
'dist/cjs/package.json',
JSON.stringify(cjspkg, null, ' '),
'utf8'
)
25 changes: 25 additions & 0 deletions build.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// release.test

/* eslint-env jest */

import {
existsSync,
readFileSync
} from 'fs'

const pkg = JSON.parse(readFileSync('./package.json'))

const cjsFile = `./dist/cjs/${pkg.name}.js`

describe('Validate commonjs version output', () => {
test(`Check if ${cjsFile} created`, () => {
expect(existsSync(cjsFile)).toBeTruthy()
})
const constent = readFileSync(cjsFile, 'utf8')
const lines = constent.split('\n')
test('Check if file meta contains package info', () => {
expect(lines[0].includes(`${pkg.name}@${pkg.version}`)).toBeTruthy()
expect(lines[0].includes(pkg.author)).toBeTruthy()
expect(lines[0].includes(pkg.license)).toBeTruthy()
})
})
24 changes: 24 additions & 0 deletions cjs-eval.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// cjs-eval.js

const { writeFileSync } = require('fs')

const { read } = require('./dist/cjs/feed-reader.js')

const extractFromUrl = async (url) => {
try {
const art = await read(url)
console.log(art)
writeFileSync('./output.json', JSON.stringify(art), 'utf8')
} catch (err) {
console.trace(err)
}
}

const init = (argv) => {
if (argv.length === 3) {
return extractFromUrl(argv[2])
}
return 'Nothing to do!'
}

init(process.argv)
Loading

0 comments on commit cc967be

Please sign in to comment.