Skip to content

Commit

Permalink
feat: use top level await (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin authored Aug 11, 2022
1 parent 2cef9f6 commit eca01ef
Show file tree
Hide file tree
Showing 16 changed files with 5,664 additions and 4,814 deletions.
5 changes: 5 additions & 0 deletions .changeset/few-doors-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"dl-iconfont": patch
---

fix: add missing package fields
5 changes: 5 additions & 0 deletions .changeset/smart-owls-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"dl-iconfont": minor
---

feat: use top level await
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
iconfont.js
lib
!/.github
!/.*.cjs
11 changes: 10 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
{
"extends": "@1stg"
"root": true,
"extends": "@1stg",
"overrides": [
{
"files": ".github/*.yml",
"rules": {
"unicorn/filename-case": "off"
}
}
]
}
13 changes: 11 additions & 2 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
github: [JounQin]
open_collective: rxts
github:
- JounQin
- 1stG
- rxts
- unts
patreon: 1stG
open_collective: unts
custom:
- https://opencollective.com/1stG
- https://opencollective.com/rxts
- https://afdian.net/@JounQin
10 changes: 2 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ jobs:
strategy:
matrix:
node:
- 12
- 14
- 16
- 18
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
Expand All @@ -24,17 +24,11 @@ jobs:
node-version: ${{ matrix.node }}
cache: yarn

- name: Link Yarn global binaries into PATH
run: echo "$(yarn global bin)" >> $GITHUB_PATH

- name: Install Dependencies
run: yarn --frozen-lockfile

- name: Build, Lint and test
run: |
yarn build
yarn lint
yarn typecov
run: yarn run-p build lint typecov
env:
EFF_NO_LINK_RULES: true
PARSER_NO_WATCH: true
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
fetch-depth: 0

- name: Setup Node.js 14.x
uses: actions/setup-node@v2
- name: Setup Node.js 16
uses: actions/setup-node@v3
with:
node-version: 14.x
node-version: 16
cache: yarn

- name: Install Dependencies
run: yarn --frozen-lockfile

- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@master
uses: changesets/action@v1
with:
# This expects you to have a script called release which does a build for your packages and calls changeset publish
publish: yarn release
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/size-limit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Size Limit

on:
pull_request_target:
branches:
- main

jobs:
size-limit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Setup Node.js 16
uses: actions/setup-node@v3
with:
node-version: 16
cache: yarn

- name: Install Dependencies
run: yarn --frozen-lockfile

- uses: andresz1/size-limit-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
skip_step: install
script: yarn size-limit --json
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ node_modules
iconfont.js
.*cache
*.log
*.tsbuildinfo
2 changes: 2 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tasks:
- init: yarn && yarn build
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
# dl-iconfont

[![GitHub Actions](https://github.com/rx-ts/dl-iconfont/workflows/CI/badge.svg)](https://github.com/rx-ts/dl-iconfont/actions/workflows/ci.yml)
[![Codacy Grade](https://img.shields.io/codacy/grade/cd566ae9ad834d838695c65b3a362b96)](https://www.codacy.com/gh/rx-ts/dl-iconfont)
[![type-coverage](https://img.shields.io/badge/dynamic/json.svg?label=type-coverage&prefix=%E2%89%A5&suffix=%&query=$.typeCoverage.atLeast&uri=https%3A%2F%2Fraw.githubusercontent.com%2Frx-ts%2Fdl-iconfont%2Fmain%2Fpackage.json)](https://github.com/plantain-00/type-coverage)
[![GitHub Actions](https://github.com/un-ts/dl-iconfont/workflows/CI/badge.svg)](https://github.com/un-ts/dl-iconfont/actions/workflows/ci.yml)
[![Language grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/un-ts/dl-iconfont.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/un-ts/dl-iconfont/context:javascript)
[![type-coverage](https://img.shields.io/badge/dynamic/json.svg?label=type-coverage&prefix=%E2%89%A5&suffix=%&query=$.typeCoverage.atLeast&uri=https%3A%2F%2Fraw.githubusercontent.com%2Fun-ts%2Fdl-iconfont%2Fmain%2Fpackage.json)](https://github.com/plantain-00/type-coverage)
[![npm](https://img.shields.io/npm/v/dl-iconfont.svg)](https://www.npmjs.com/package/dl-iconfont)
[![GitHub Release](https://img.shields.io/github/release/rx-ts/dl-iconfont)](https://github.com/rx-ts/dl-iconfont/releases)

[![David Peer](https://img.shields.io/david/peer/rx-ts/dl-iconfont.svg)](https://david-dm.org/rx-ts/dl-iconfont?type=peer)
[![David](https://img.shields.io/david/rx-ts/dl-iconfont.svg)](https://david-dm.org/rx-ts/dl-iconfont)
[![David Dev](https://img.shields.io/david/dev/rx-ts/dl-iconfont.svg)](https://david-dm.org/rx-ts/dl-iconfont?type=dev)
[![GitHub Release](https://img.shields.io/github/release/un-ts/dl-iconfont)](https://github.com/un-ts/dl-iconfont/releases)

[![Conventional Commits](https://img.shields.io/badge/conventional%20commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
[![Renovate enabled](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovatebot.com)
Expand Down
76 changes: 60 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,60 @@
"version": "0.1.1",
"type": "module",
"description": "An iconfont downloader via puppeteer.",
"repository": "https://github.com/rx-ts/dl-iconfont.git",
"repository": "https://github.com/un-ts/dl-iconfont.git",
"author": "Zhenggang Su <[email protected]>",
"contributors": [
"JounQin <[email protected]>"
],
"donate": {
"recipients": [
{
"name": "unts",
"platform": "opencollective",
"address": "https://opencollective.com/unts",
"weight": 60
},
{
"name": "rxts",
"platform": "opencollective",
"address": "https://opencollective.com/rxts",
"weight": 20
},
{
"name": "1stG",
"email": "[email protected]",
"weight": 20,
"platforms": [
{
"platform": "opencollective",
"address": "https://opencollective.com/1stG"
},
{
"platform": "patreon",
"address": "https://www.patreon.com/1stG"
}
]
}
]
},
"funding": "https://opencollective.com/unts",
"license": "MIT",
"engines": {
"node": ">=12"
"node": "^14.18.0 || >=16.0.0"
},
"bin": {
"dli": "./bin/cli.js",
"dl-iconfont": "./bin/cli.js",
"iconfont-dl": "./bin/cli.js"
},
"main": "lib/index.cjs",
"module": "lib",
"exports": {
"types": "./lib/index.d.ts",
"import": "./lib/index.js",
"require": "./lib/index.cjs"
},
"types": "lib",
"files": [
"lib"
],
Expand All @@ -35,35 +71,43 @@
"build": "run-p build:*",
"build:r": "r -f cjs",
"build:tsc": "tsc -b",
"dev": "yarn ts ./src/cli.ts",
"dev": "tsx ./src/cli.ts",
"lint": "run-p lint:*",
"lint:es": "eslint . -f friendly",
"lint:tsc": "tsc --noEmit",
"prepare": "simple-git-hooks && yarn-deduplicate --strategy fewer || exit 0",
"prerelease": "yarn build",
"release": "changeset publish",
"ts": "node --loader ts-node/esm",
"typecov": "type-coverage"
},
"dependencies": {
"dotenv": "^10.0.0",
"got": "^11.8.2",
"puppeteer": "^10.2.0",
"tslib": "^2.3.1"
"dotenv": "^16.0.1",
"got": "^12.3.1",
"puppeteer": "^16.1.0",
"tslib": "^2.4.0"
},
"devDependencies": {
"@1stg/lib-config": "^4.0.0",
"@changesets/changelog-github": "^0.4.1",
"@changesets/cli": "^2.17.0",
"@types/puppeteer": "^5.4.4",
"ts-node": "^10.2.1",
"tslint": "^6.1.3",
"type-coverage": "^2.18.2",
"typescript": "^4.4.3"
"@1stg/lib-config": "^9.0.2",
"@changesets/changelog-github": "^0.4.6",
"@changesets/cli": "^2.24.2",
"@types/puppeteer": "^5.4.6",
"@types/web": "^0.0.71",
"size-limit": "^8.0.0",
"size-limit-preset-node-lib": "^0.1.0",
"tsx": "^3.8.1",
"type-coverage": "^2.22.0",
"typescript": "^4.7.4",
"yarn-deduplicate": "^5.0.0"
},
"publishConfig": {
"access": "public"
},
"size-limit": [
{
"path": "lib/cli.js",
"limit": "550B"
}
],
"typeCoverage": {
"atLeast": 100,
"cache": true,
Expand Down
39 changes: 16 additions & 23 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,20 @@ const {

const DOWNLOAD_FILE = process.argv[2] || ICONFONT_DOWNLOAD_FILE

const main = async () => {
const jsUrl = await fetchJsUrl({
projectId: ICONFONT_PROJECT_ID!,
login: ICONFONT_LOGIN!,
password: ICONFONT_PASSWORD!,
headless: !['0', 'false'].includes(PUPPETEER_HEADLESS!),
})
if (DOWNLOAD_FILE) {
console.log(
`[dl-iconfont]: downloading \`${jsUrl!}\` into \`${DOWNLOAD_FILE}\``,
)
await download(jsUrl!, DOWNLOAD_FILE)
} else {
console.log(
'[dl-iconfont] no `ICONFONT_DOWNLOAD_FILE` provided, you can use the environment variable or `dli ICONFONT_DOWNLOAD_FILE` to download the js file automatically',
)
console.log(`[dl-iconfont]: ${jsUrl!}`)
}
}

main().catch((err: Error) => {
console.error(err)
process.exitCode = 1
const jsUrl = await fetchJsUrl({
projectId: ICONFONT_PROJECT_ID!,
login: ICONFONT_LOGIN!,
password: ICONFONT_PASSWORD!,
headless: !['0', 'false'].includes(PUPPETEER_HEADLESS!),
})
if (DOWNLOAD_FILE) {
console.log(
`[dl-iconfont]: downloading \`${jsUrl!}\` into \`${DOWNLOAD_FILE}\``,
)
await download(jsUrl!, DOWNLOAD_FILE)
} else {
console.log(
'[dl-iconfont] no `ICONFONT_DOWNLOAD_FILE` provided, you can use the environment variable or `dli ICONFONT_DOWNLOAD_FILE` to download the js file automatically',
)
console.log(`[dl-iconfont]: ${jsUrl!}`)
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fs from 'fs'
import fs from 'node:fs'

import got from 'got'
import puppeteer from 'puppeteer'
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "@1stg/tsconfig/dom-lib",
"extends": "@1stg/tsconfig/node16",
"compilerOptions": {
"baseUrl": ".",
"rootDir": "src",
Expand Down
Loading

0 comments on commit eca01ef

Please sign in to comment.