Skip to content

Commit

Permalink
Merge pull request #303 from ndaidong/7.2.1
Browse files Browse the repository at this point in the history
7.2.1
  • Loading branch information
ndaidong authored Sep 20, 2022
2 parents bcd6d36 + 38b8c10 commit 64e308d
Show file tree
Hide file tree
Showing 17 changed files with 38,400 additions and 507 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Extract main article, main image and meta data from URL.
## Demo

- [Give it a try!](https://demos.pwshub.com/article-parser)
- [Example FaaS](https://extract-article.deta.dev/?url=https://www.freethink.com/technology/virtual-world)
- [Example FaaS](https://extract-article.deta.dev/?url=https://dev.to/ndaidong/how-to-make-your-mongodb-container-more-secure-1646)

## Install & Usage

Expand Down Expand Up @@ -317,15 +317,13 @@ View [default options](https://github.com/ndaidong/article-parser/blob/main/src/
Read [sanitize-html](https://www.npmjs.com/package/sanitize-html#what-are-the-default-options) docs for more info.
## Test
## Quick evaluation
```bash
git clone https://github.com/ndaidong/article-parser.git
cd article-parser
npm i
npm test
pnpm i
# quick evaluation
npm run eval {URL_TO_PARSE_ARTICLE}
```
Expand Down
43 changes: 17 additions & 26 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* build.js
* @ndaidong
**/
**/

import { readFileSync, writeFileSync, copyFileSync, rmSync, mkdirSync } from 'fs'

Expand All @@ -22,25 +22,29 @@ const comment = [
`published under ${pkg.license} license`
].join(' - ')

/**
* @type {import('esbuild').BuildOptions}
* */
const baseOpt = {
entryPoints: ['src/main.js'],
bundle: true,
charset: 'utf8',
target: ['es2020', 'node14'],
pure: ['console.log', 'debug', 'alert'],
legalComments: 'none',
minify: true,
write: true,
sourcemap: 'external',
external: ['canvas']
minify: false,
sourcemap: false,
write: true
}

/**
* @type {import('esbuild').BuildOptions}
*/
const esmVersion = {
...baseOpt,
platform: 'browser',
format: 'esm',
outfile: `dist/${pkg.name}.esm.js`,
banner: {
js: comment
}
}
buildSync(esmVersion)

const cjsVersion = {
...baseOpt,
platform: 'node',
Expand All @@ -54,29 +58,16 @@ const cjsVersion = {
buildSync(cjsVersion)

const cjspkg = {
name: pkg.name + '-cjs',
name: pkg.name,
version: pkg.version,
main: `./${pkg.name}.js`
}

writeFileSync(
'dist/cjs/package.json',
JSON.stringify(cjspkg, null, ' '),
'utf8'
)

/**
* @type {import('esbuild').BuildOptions}
*/
const browserVersion = {
...baseOpt,
platform: 'browser',
format: 'esm',
outfile: `dist/${pkg.name}.browser.js`,
banner: {
js: comment
}
}
buildSync(browserVersion)

// copy types definition to cjs dir
copyFileSync('./index.d.ts', 'dist/cjs/index.d.ts')
26 changes: 20 additions & 6 deletions build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import {

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

const esmFile = `./dist/${pkg.name}.esm.js`
const cjsFile = `./dist/cjs/${pkg.name}.js`
const cjsPkg = JSON.parse(readFileSync('./dist/cjs/package.json'))
const cjsTypesFile = './dist/cjs/index.d.ts'
const cjsType = './dist/cjs/index.d.ts'

describe('Validate commonjs version output', () => {
test(`Check if ${cjsFile} created`, () => {
expect(existsSync(cjsFile)).toBeTruthy()
})
test('Check if cjs package info updated', () => {
expect(cjsPkg.name).toEqual(`${pkg.name}-cjs`)
expect(cjsPkg.version).toEqual(pkg.version)
test('Check if cjs type copied', () => {
expect(existsSync(cjsType)).toBeTruthy()
})
const constent = readFileSync(cjsFile, 'utf8')
const lines = constent.split('\n')
Expand All @@ -28,7 +28,21 @@ describe('Validate commonjs version output', () => {
expect(lines[0].includes(pkg.author)).toBeTruthy()
expect(lines[0].includes(pkg.license)).toBeTruthy()
})
test(`Check if ${cjsTypesFile} created`, () => {
expect(existsSync(cjsTypesFile)).toBeTruthy()
test('Check if cjs package info updated', () => {
expect(cjsPkg.name).toEqual(pkg.name)
expect(cjsPkg.version).toEqual(pkg.version)
})
})

describe('Validate ESM version output', () => {
test(`Check if ${esmFile} created`, () => {
expect(existsSync(esmFile)).toBeTruthy()
})
const constent = readFileSync(esmFile, '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()
})
})
157 changes: 0 additions & 157 deletions dist/article-parser.browser.js

This file was deleted.

7 changes: 0 additions & 7 deletions dist/article-parser.browser.js.map

This file was deleted.

Loading

0 comments on commit 64e308d

Please sign in to comment.