Skip to content

Commit

Permalink
feat: first blood, should just work
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin committed Jan 5, 2024
1 parent 93ac8d5 commit 95af0e2
Show file tree
Hide file tree
Showing 22 changed files with 3,136 additions and 2,783 deletions.
2 changes: 1 addition & 1 deletion .codesandbox/ci.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"node": "16",
"node": "18",
"sandboxes": []
}
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ dist
lib
CHANGELOG.md
/auto-imports.d.ts
/pnpm-lock.yaml
!/.github
!/.*.cjs
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
SKIP_YARN_COREPACK_CHECK: 1

- name: Install Dependencies
run: yarn --no-immutable
run: yarn --immutable
env:
SKIP_YARN_COREPACK_CHECK: 1

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ jobs:
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
queries: +security-and-quality

- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
with:
category: '/language:${{ matrix.language }}'
30 changes: 30 additions & 0 deletions .github/workflows/release-beta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Release beta

on:
pull_request:
branches: main

jobs:
release_beta:
name: Release Beta
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Enable Corepack
run: corepack enable

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: yarn

- name: Install dependencies
run: yarn --immutable

- name: Release beta
run: yarn release:beta
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ jobs:
cache: yarn

- name: Install Dependencies
run: yarn --no-immutable
run: yarn --immutable

- name: Create Release Pull Request or Publish to npm
uses: changesets/action@v1
with:
publish: yarn release
version: yarn changeset version
commit: 'chore: release preversion'
title: 'chore: release preversion'
version: yarn run version
publish: yarn release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/size-limit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
cache: yarn

- name: Install Dependencies
run: yarn --no-immutable
run: yarn --immutable

- uses: andresz1/size-limit-action@v1
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.type-coverage
.vercel
.yarn/*
!.yarn/patches
!.yarn/plugins
coverage
dist
Expand Down
1 change: 1 addition & 0 deletions .stylelintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ coverage
dist
lib
LICENSE
*.js
*.json
*.lock
*.log
Expand Down
24 changes: 24 additions & 0 deletions .yarn/patches/size-limit-node-esbuild-npm-0.3.0-6e195b31b7.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
diff --git a/lib/index.js b/lib/index.js
index 104d30a2166acc5af090f3ff8c0b8fed2339b3cd..f9823d3e62a0c649f3f2e2cfccabbcb0b30f4fb6 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -36,13 +36,16 @@ export default [
if (!check.esbuildOutfile) {
check.esbuildOutfile = join(tmpdir(), `size-limit-${nanoid()}`);
}
+ const defaultEsbuldConfig = await getConfig(config, check, check.esbuildOutfile);
if (check.config) {
const esbuildConfig = (await import(check.config));
- setPlatformNode((check.esbuildConfig =
- 'default' in esbuildConfig ? esbuildConfig.default : esbuildConfig));
+ setPlatformNode((check.esbuildConfig = {
+ ...defaultEsbuldConfig,
+ ...('default' in esbuildConfig ? esbuildConfig.default : esbuildConfig),
+ }));
}
else {
- check.esbuildConfig = setPlatformNode(await getConfig(config, check, check.esbuildOutfile));
+ check.esbuildConfig = setPlatformNode(defaultEsbuldConfig);
if (check.modifyEsbuildConfig) {
check.esbuildConfig = check.modifyEsbuildConfig(check.esbuildConfig);
}
31 changes: 23 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
[![Code Style: Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
[![changesets](https://img.shields.io/badge/maintained%20with-changesets-176de3.svg)](https://github.com/changesets/changesets)

A simple library boilerplate.
> A tiny cli helps you to publish alpha/beta versions to npm before releasing the final latest version
## TOC <!-- omit in toc -->

- [Usage](#usage)
- [Install](#install)
- [CLI](#cli)
- [API](#api)
- [Sponsors](#sponsors)
- [Backers](#backers)
Expand All @@ -30,21 +31,35 @@ A simple library boilerplate.

```sh
# pnpm
pnpm add preversion
pnpm add -D preversion

# yarn
yarn add preversion
yarn add -D preversion

# npm
npm i preversion
npm i -D preversion
```

### API
### CLI

```log
Usage: preversion [options]
A tiny cli helps you to publish alpha/beta versions to npm before releasing the final latest version
```js
import echo from 'preversion'
Options:
-V, --version output the version number
-b, --branch [string] optional specified branch to be pushed after releasing successfully
-m, --message [string] optional commit message when `branch` option enabled (default: "chore: release preversion v{{version}}")
-v, --preversion [string] optional specified version to be released
-t, --tag [string] optional specified npm tag to be released
-h, --help display help for command
```

### API

echo()
```ts
import { getPreversionTag, getPreversion, preversion } from 'preversion'
```

## Sponsors
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
Expand Down
79 changes: 42 additions & 37 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "preversion",
"version": "0.1.0",
"type": "module",
"description": "A simple library boilerplate.",
"description": "A tiny cli helps you to publish alpha/beta versions to npm before releasing the final latest version",
"repository": "git+https://github.com/un-ts/preversion.git",
"author": "JounQin (https://www.1stG.me) <[email protected]>",
"funding": "https://opencollective.com/unts",
Expand All @@ -11,7 +11,15 @@
"engines": {
"node": ">=18.0.0"
},
"exports": "./src/index.ts",
"bin": "./lib/cli.js",
"main": "./lib/index.cjs",
"module": "./lib/index.js",
"exports": {
"types": "./lib/index.d.ts",
"import": "./lib/index.js",
"require": "./lib/index.cjs"
},
"types": "./lib/index.d.ts",
"files": [
"lib",
"!**/*.tsbuildinfo"
Expand All @@ -22,78 +30,75 @@
"release"
],
"scripts": {
"build": "concurrently 'yarn:build:*'",
"build": "concurrently -r 'yarn:build:*'",
"build:r": "r -f cjs",
"build:tsc": "tsc -p src",
"dev": "vitest",
"docs:build": "vite build docs --emptyOutDir",
"docs:dev": "vite docs",
"lint": "concurrently 'yarn:lint:*'",
"lint": "concurrently -r 'yarn:lint:*'",
"lint:es": "eslint . --cache -f friendly --max-warnings 10",
"lint:style": "stylelint . --cache",
"lint:tsc": "tsc --noEmit",
"prepare": "simple-git-hooks",
"release": "yarn build && yarn changeset publish",
"release:beta": "yarn build && node ./lib/cli",
"serve": "vite preview docs",
"test": "vitest run --coverage",
"typecov": "type-coverage",
"vercel-build": "yarn docs:build"
"vercel-build": "yarn docs:build",
"version": "changeset version && yarn --no-immutable"
},
"dependencies": {
"tslib": "^2.6.2"
"@pkgr/core": "^0.1.0",
"commander": "^11.1.0",
"semver": "^7.5.4"
},
"devDependencies": {
"@1stg/app-config": "^9.0.1",
"@1stg/lib-config": "^12.0.1",
"@1stg/app-config": "^10.0.1",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.1",
"@commitlint/cli": "^18.4.3",
"@commitlint/cli": "^18.4.4",
"@mdx-js/rollup": "^3.0.0",
"@pkgr/rollup": "^4.1.3",
"@pkgr/rollup": "^5.0.0",
"@size-limit/preset-small-lib": "^11.0.1",
"@types/mdx": "^2.0.10",
"@types/node": "^20.10.4",
"@types/react": "^18.2.42",
"@types/react-dom": "^18.2.17",
"@types/web": "^0.0.125",
"@types/node": "^20.10.6",
"@types/react": "^18.2.46",
"@types/react-dom": "^18.2.18",
"@types/semver": "^7.5.6",
"@types/web": "^0.0.134",
"@vitejs/plugin-react-swc": "^3.5.0",
"@vitest/coverage-v8": "^1.0.2",
"@vitest/coverage-v8": "^1.1.3",
"concurrently": "^8.2.2",
"eslint": "^8.55.0",
"github-markdown-css": "^5.4.0",
"eslint": "^8.56.0",
"github-markdown-css": "^5.5.0",
"lint-staged": "^15.2.0",
"prettier": "^3.1.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.20.1",
"react-router-dom": "^6.21.1",
"rehype-slug": "^6.0.0",
"remark-gfm": "^4.0.0",
"simple-git-hooks": "^2.9.0",
"size-limit": "^11.0.1",
"stylelint": "^15.11.0",
"type-coverage": "^2.27.0",
"size-limit-preset-node-lib": "^0.3.0",
"stylelint": "^16.1.0",
"type-coverage": "^2.27.1",
"typescript": "^5.3.3",
"unplugin-auto-import": "^0.17.2",
"vite": "^5.0.6",
"vitest": "^1.0.4"
"unplugin-auto-import": "^0.17.3",
"vite": "^5.0.11",
"vitest": "^1.1.3"
},
"resolutions": {
"@commitlint/cli": "^18.4.3",
"lint-staged": "^15.2.0",
"rollup": "^4.6.1"
},
"publishConfig": {
"main": "./lib/index.cjs",
"module": "./lib/index.js",
"exports": {
"types": "./lib/index.d.ts",
"import": "./lib/index.js",
"require": "./lib/index.cjs"
},
"types": "./lib/index.d.ts"
"prettier": "^3.1.1",
"size-limit-node-esbuild@npm:^0.3.0": "patch:size-limit-node-esbuild@npm%3A0.3.0#~/.yarn/patches/size-limit-node-esbuild-npm-0.3.0-6e195b31b7.patch"
},
"size-limit": [
{
"path": "lib/index.js"
"config": "size-limit.esbuild.js",
"path": "lib/cli.js",
"limit": "22kB"
}
],
"typeCoverage": {
Expand Down
3 changes: 3 additions & 0 deletions size-limit.esbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
format: 'esm',
}
46 changes: 46 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { fileURLToPath } from 'node:url'

import { cjsRequire } from '@pkgr/core'
import { program } from 'commander'

import type { PackageJson } from './types.js'

import { pkg, preversion } from './index.js'

const {
PREVERSION_BRANCH,
PREVERSION_MESSAGE,
PREVERSION_VERSION,
PREVERSION_TAG,
} = process.env

const { name, description, version } = cjsRequire(
fileURLToPath(new URL('../package.json', import.meta.url)),
) as PackageJson

program
.name(name)
.description(description!)
.version(version)
.option(
'-b, --branch [string]',
'optional specified branch to be pushed after releasing successfully',
PREVERSION_BRANCH,
)
.option(
'-m, --message [string]',
'optional commit message when `branch` option enabled',
PREVERSION_MESSAGE || `chore: release ${pkg.name} v{{version}}`,
)
.option(
'-v, --preversion [string]',
'optional specified version to be released',
PREVERSION_VERSION,
)
.option(
'-t, --tag [string]',
'optional specified npm tag to be released',
PREVERSION_TAG,
)
.action(preversion)
.parse(process.argv)

Check warning on line 46 in src/cli.ts

View check run for this annotation

Codecov / codecov/patch

src/cli.ts#L1-L46

Added lines #L1 - L46 were not covered by tests
Loading

0 comments on commit 95af0e2

Please sign in to comment.