-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from ndaidong/refactor
v3.0.0
- Loading branch information
Showing
36 changed files
with
839 additions
and
1,170 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# GitHub actions | ||
# https://docs.github.com/en/free-pro-team@latest/actions | ||
|
||
name: ci-test | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
test: | ||
|
||
runs-on: ubuntu-20.04 | ||
|
||
strategy: | ||
matrix: | ||
node_version: [10.14.2, 14.x, 15.x, 16.x, 17.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: setup Node.js v${{ matrix.node_version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node_version }} | ||
|
||
- name: run npm scripts | ||
run: | | ||
npm i -g standard | ||
npm install | ||
npm run lint | ||
npm run build --if-present | ||
npm run test | ||
- name: sync to coveralls | ||
uses: coverallsapp/[email protected] | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: cache node modules | ||
uses: actions/cache@v2 | ||
with: | ||
path: ~/.npm | ||
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | ||
restore-keys: | | ||
${{ runner.os }}-node- | ||
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Type definitions | ||
|
||
export function parse(url: string): Promise<FeedData>; | ||
|
||
|
||
export interface FeedData { | ||
link?: string; | ||
title?: string; | ||
description?: string; | ||
generator?: string; | ||
language?: string; | ||
updated?: date; | ||
entries?: array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const { readFileSync, writeFileSync, existsSync } = require('fs') | ||
|
||
const isValidUrl = require('./src/utils/isValidUrl') | ||
const { parse } = require('./index') | ||
|
||
const extractFromUrl = async (url) => { | ||
try { | ||
const art = await parse(url) | ||
console.log(art) | ||
writeFileSync('./output.json', JSON.stringify(art), 'utf8') | ||
} catch (err) { | ||
console.trace(err) | ||
} | ||
} | ||
|
||
const extractFromFile = async (fpath) => { | ||
try { | ||
const xml = readFileSync(fpath, 'utf8') | ||
const art = await parse(xml) | ||
console.log(art) | ||
writeFileSync('./output.json', JSON.stringify(art), 'utf8') | ||
} catch (err) { | ||
console.trace(err) | ||
} | ||
} | ||
|
||
const init = (argv) => { | ||
if (argv.length === 3) { | ||
const input = argv[2] | ||
const isUrl = isValidUrl(input) | ||
return isUrl ? extractFromUrl(input) : existsSync(input) ? extractFromFile(input) : false | ||
} | ||
return 'Nothing to do!' | ||
} | ||
|
||
init(process.argv) |
Oops, something went wrong.