Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: a huge update #25

Merged
merged 11 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install pnpm
uses: pnpm/action-setup@v2
uses: pnpm/action-setup@v3

- name: Set node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 16.x
node-version-file: .nvmrc
cache: pnpm
registry-url: 'https://registry.npmjs.org'

Expand All @@ -31,7 +31,10 @@ jobs:
- name: Install Dependencies
run: pnpm i

- name: PNPM build
run: pnpm run build

- name: Publish to NPM
run: pnpm publish --access public --no-git-checks
run: pnpm -r publish --access public --no-git-checks
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@ lib-cov
logs
node_modules
temp

manifest.json
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
55 changes: 17 additions & 38 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,53 +1,31 @@
{
// Enable the ESlint flat config support
"eslint.experimental.useFlatConfig": true,

// Disable the default formatter, use eslint instead
"prettier.enable": false,
"editor.formatOnSave": false,

// Auto fix
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.fixAll.eslint": "explicit",
"source.organizeImports": "never"
},

// Silent the stylistic rules in you IDE, but still auto fix them
"eslint.rules.customizations": [
{
"rule": "style/*",
"severity": "off"
},
{
"rule": "*-indent",
"severity": "off"
},
{
"rule": "*-spacing",
"severity": "off"
},
{
"rule": "*-spaces",
"severity": "off"
},
{
"rule": "*-order",
"severity": "off"
},
{
"rule": "*-dangle",
"severity": "off"
},
{
"rule": "*-newline",
"severity": "off"
},
{
"rule": "*quotes",
"severity": "off"
},
{
"rule": "*semi",
"severity": "off"
}
{ "rule": "style/*", "severity": "off" },
{ "rule": "format/*", "severity": "off" },
{ "rule": "*-indent", "severity": "off" },
{ "rule": "*-spacing", "severity": "off" },
{ "rule": "*-spaces", "severity": "off" },
{ "rule": "*-order", "severity": "off" },
{ "rule": "*-dangle", "severity": "off" },
{ "rule": "*-newline", "severity": "off" },
{ "rule": "*quotes", "severity": "off" },
{ "rule": "*semi", "severity": "off" }
],

// Enable eslint for all supported languages
"eslint.validate": [
"javascript",
Expand All @@ -59,6 +37,7 @@
"markdown",
"json",
"jsonc",
"yaml"
"yaml",
"toml"
]
}
9 changes: 9 additions & 0 deletions bump.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from 'bumpp'

export default defineConfig({
files: [
'package.json',
'packages/core/package.json',
'packages/schema/package.json',
],
})
52 changes: 16 additions & 36 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "@uni-helper/vite-plugin-uni-manifest",
"type": "module",
"version": "0.2.3",
"packageManager": "[email protected]",
"private": true,
"packageManager": "[email protected]",
"description": "Use TypeScript to write manifest.json of uni-app",
"author": "KeJun",
"license": "MIT",
Expand All @@ -14,47 +15,26 @@
"bugs": "https://github.com/uni-helper/vite-plugin-uni-manifest/issues",
"keywords": [],
"sideEffects": false,
"exports": {
".": {
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
}
},
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "unbuild",
"dev": "unbuild --stub",
"play": "nr -C playground dev:h5",
"stub": "pnpm -r --filter=./packages/* --parallel run stub",
"dev": "pnpm stub",
"build": "rimraf --glob packages/*/dist && pnpm -r --filter=./packages/* run build && pnpm -r run build-post",
"play:mp-weixin": "pnpm dev && npm -C packages/playground run dev:mp-weixin",
"build:mp-weixin": "pnpm build && npm -C packages/playground run build:mp-weixin",
"play:h5": "pnpm dev && npm -C packages/playground run dev:h5",
"build:h5": "pnpm build && npm -C packages/playground run build:h5",
ModyQyW marked this conversation as resolved.
Show resolved Hide resolved
"prepublishOnly": "pnpm build",
"release": "bumpp",
"start": "esno src/index.ts",
"test": "vitest",
"lint": "eslint .",
"lint:fix": "eslint . --fix"
},
"dependencies": {
"c12": "^1.4.2",
"type-fest": "^4.4.0"
},
"devDependencies": {
"@antfu/eslint-config": "1.0.0-beta.25",
"@types/node": "^18.18.4",
"bumpp": "^9.2.0",
"eslint": "^8.51.0",
"esno": "^0.17.0",
"typescript": "^5.2.2",
"unbuild": "^2.0.0",
"vite": "^4.4.11"
"@antfu/eslint-config": "^2.16.0",
"@types/node": "^20.12.7",
"bumpp": "^9.4.1",
"eslint": "^8.57.0",
"rimraf": "^5.0.5",
"typescript": "^5.4.5",
"unbuild": "^2.0.0"
}
}
136 changes: 136 additions & 0 deletions packages/core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# @uni-helper/vite-plugin-uni-pages
ModyQyW marked this conversation as resolved.
Show resolved Hide resolved

File system-based routing for uni-app applications using Vite.

<a href="https://www.npmjs.com/package/@uni-helper/vite-plugin-uni-pages"><img src="https://img.shields.io/npm/v/@uni-helper/vite-plugin-uni-pages" alt="NPM version"></a></p>

English | [简体中文](./README.Zh-CN.md)

## Installation

```bash
pnpm i -D @uni-helper/vite-plugin-uni-pages
```

## Usage

```ts
// vite.config.ts
import { defineConfig } from 'vite'
import Uni from '@dcloudio/vite-plugin-uni'
import UniPages from '@uni-helper/vite-plugin-uni-pages'

// It is recommended to put it in front of Uni
export default defineConfig({
plugins: [UniPages(), Uni()],
})
```

Define global properties in `pages.config.(ts|mts|cts|js|cjs|mjs|json)`, You can use like `#ifdef H5` in the file.

```ts
// pages.config.ts
import { defineUniPages } from '@uni-helper/vite-plugin-uni-pages'

export default defineUniPages({
// You can also define pages fields, which have the highest priority.priority.
pages: [],
globalStyle: {
navigationBarTextStyle: 'black',
navigationBarTitleText: '@uni-helper',
},
})
```

Now all pages will be found automatically!

### SFC custom block for Route Data

Add route meta to the route by adding a `<route>` block to the SFC. This will be
directly added to the route after it is generated, and will override it.

You can specific a parser to use using `<route lang="yaml">`, or set a default
ModyQyW marked this conversation as resolved.
Show resolved Hide resolved
parser using `routeBlockLang` option.

- **Supported parser:** JSON, JSON5, YAML
- **Default:** JSON5

```html
<!-- index.vue -->
<!-- use type to set index -->
<route type="home">
{
"style": { "navigationBarTitleText": "@uni-helper" }
}
</route>

<!-- other.vue -->
<route lang="yaml">
style:
navigationBarTitleText: "@uni-helper"
</route>
```

Import the virtual module to access the metadata of all pages

```ts
/// <reference types="@uni-helper/vite-plugin-uni-pages/client" />
import { pages } from 'virtual:uni-pages'

console.log(pages)
```

## Configuration

```ts
export interface Options {
/**
* Whether to scan and merge pages in pages.json
* @default true
*/
mergePages: boolean

/**
* Paths to the directory to search for page components.
* @default 'src/pages'
*/
dir: string

/**
* pages.json dir
* @default "src"
*/
outDir: string

/**
* exclude page
* @default []
*/
exclude: string[]

/**
* Set the default route block parser, or use `<route lang="xxx">` in SFC route block
* @default 'json5'
*/
routeBlockLang: 'json5' | 'json' | 'yaml' | 'yml'

onBeforeLoadUserConfig: (ctx: PageContext) => void
onAfterLoadUserConfig: (ctx: PageContext) => void
onBeforeScanPages: (ctx: PageContext) => void
onAfterScanPages: (ctx: PageContext) => void
onBeforeMergePageMetaData: (ctx: PageContext) => void
onAfterMergePageMetaData: (ctx: PageContext) => void
onBeforeWriteFile: (ctx: PageContext) => void
onAfterWriteFile: (ctx: PageContext) => void
}
```

## TODO

- [x] only update the changed page
- [x] [vite-plugin-uni-middleware](https://github.com/uni-helper/vite-plugin-uni-middleware)
- [x] pages [type](./src/config/types.ts)

## Acknowledgement

- [vite-plugin-pages](https://github.com/hannoeru/vite-plugin-pages.git)
3 changes: 1 addition & 2 deletions build.config.ts → packages/core/build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export default defineBuildConfig({
clean: true,
rollup: {
emitCJS: true,
inlineDependencies: true,
},
failOnWarn: false,
externals: ['vite'],
})
47 changes: 47 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "@uni-helper/vite-plugin-uni-manifest",
"type": "module",
"version": "0.2.18",
"description": "File system based routing for uni-app applications using Vite",
"author": "KeJun",
"license": "MIT",
"homepage": "https://github.com/uni-helper/vite-plugin-uni-manifest#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/uni-helper/vite-plugin-uni-manifest.git"
},
"bugs": "https://github.com/uni-helper/vite-plugin-uni-manifest/issues",
"keywords": [],
"sideEffects": false,
"exports": {
".": {
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
}
},
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "unbuild",
"stub": "unbuild --stub"
},
"peerDependencies": {
"vite": "^4.0.0 || ^5.0.0"
},
"dependencies": {
"c12": "^1.10.0"
},
"devDependencies": {
"vite": "^5.2.10"
}
}
File renamed without changes.
Loading