Skip to content

Commit

Permalink
feat: pull vite plugin generate dts https://github.com/vtrbo/vite-plu…
Browse files Browse the repository at this point in the history
  • Loading branch information
vtrbo committed Apr 28, 2024
1 parent fb03316 commit 6312264
Show file tree
Hide file tree
Showing 27 changed files with 5,728 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: [vtrbo]
57 changes: 57 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: CI

on:
push:
branches:
- main

pull_request:
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set node
uses: actions/setup-node@v3
with:
node-version: 16.x

- name: Setup
run: npm i -g @antfu/ni

- name: Install
run: nci

- name: Lint
run: nr lint

test:
runs-on: ${{ matrix.os }}

strategy:
matrix:
node: [16.x, 18.x]
os: [ubuntu-latest, windows-latest, macos-latest]
fail-fast: false

steps:
- uses: actions/checkout@v3
- name: Set node ${{ matrix.node }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}

- name: Setup
run: npm i -g @antfu/ni

- name: Install
run: nci

- name: Build
run: nr build

- name: Test
run: nr test
22 changes: 22 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Release

on:
push:
tags:
- 'v*'

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-node@v3
with:
node-version: 16.x

- run: npx changelogithub
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
93 changes: 93 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
.DS_Store

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
~/
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# parcel-bundler cache (https://parceljs.org/)
.cache
chche
.temp
temp

# next.js build output
.next

# nuxt.js build output
.nuxt

# vuepress build output
.vuepress/dist

# Build output
dist

# Serverless directories
.serverless

# IDE
.idea
.vscode

# Svelte
/.svelte-kit

# generate
**/components.d.ts
types/auto-*.ts
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignore-workspace-root-check=true
shamefully-hoist=true
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,24 @@
# vite-plugin-meta-env-dts
自动扫描env的环境变量生成类型声明

[![NPM version](https://img.shields.io/npm/v/vite-plugin-meta-env-dts?color=a1b858&label=)](https://www.npmjs.com/package/vite-plugin-meta-env-dts)

vite-plugin-meta-env-dts for [vite](https://github.com/vitejs/vite).

## Install

```bash
npm i vite-plugin-meta-env-dts
```

```js
// vite.config.js
import metaEnvDts from 'vite-plugin-meta-env-dts'

export default defineConfig({
plugins: [metaEnvDts({ /* options */ })],
})
```

## License

[MIT](LICENSE) License © 2024 [XParCai](https://github.com/xparcai)
3 changes: 3 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import defineEslintConfig from '@antfu/eslint-config'

export default defineEslintConfig()
76 changes: 76 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"name": "vite-plugin-meta-env-dts",
"type": "module",
"version": "0.0.0",
"description": "Automatically generate type declarations based on env.* files.",
"license": "MIT",
"homepage": "https://github.com/xparcai/vite-plugin-meta-env-dts#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/xparcai/vite-plugin-meta-env-dts.git"
},
"bugs": {
"url": "https://github.com/xparcai/vite-plugin-meta-env-dts/issues"
},
"keywords": [
"vite",
"vite-plugin"
],
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"require": "./dist/index.cjs"
},
"./*": "./*"
},
"main": "dist/index.cjs",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"typesVersions": {
"*": {
"*": [
"./dist/*",
"./*"
]
}
},
"files": [
"dist"
],
"scripts": {
"build": "tsup",
"build:fix": "esno scripts/postbuild.ts",
"dev": "tsup --watch src",
"start": "esno src/index.ts",
"play": "npm -C playground run dev",
"lint": "eslint .",
"prepublishOnly": "npm run build",
"release": "bumpp && npm publish",
"test": "vitest"
},
"dependencies": {
"chokidar": "^3.6.0",
"debug": "^4.3.4",
"fast-glob": "^3.3.2",
"fs-extra": "^11.2.0",
"vite": "^5.2.10"
},
"devDependencies": {
"@antfu/eslint-config": "^2.16.0",
"@types/debug": "^4.1.12",
"@types/fs-extra": "^11.0.4",
"@types/node": "^20.12.7",
"@vtrbo/utils": "^0.4.1",
"bumpp": "^9.4.0",
"chalk": "^5.3.0",
"cross-env": "^7.0.3",
"eslint": "8.57.0",
"esno": "^4.7.0",
"nodemon": "^3.1.0",
"rimraf": "^5.0.5",
"tsup": "^8.0.2",
"typescript": "^5.4.5",
"vitest": "^1.5.2"
}
}
10 changes: 10 additions & 0 deletions playground/.env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
VITE_PROJECT_NAME=generate-dts # 项目信息
VITE_NAME="ABC
d";
# 版本
# 我是两行的注释
VITE_VERSION=122
# 测试一下很多个空格
VITE_GE="0"
VITE_OBJECT="{ name: 'abc', value: '123' }"
VITE_ARRAY=123
13 changes: 13 additions & 0 deletions playground/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div id="app"></div>
<a href="/__inspect/module?id=./main.ts&index=2" target="_blank" style="text-decoration: none; margin-top:10px; display: block;">visit /__inspect/ to inspect the intermediate state</a>
<script type="module" src="main.ts"></script>
</body>
</html>
1 change: 1 addition & 0 deletions playground/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
document.getElementById('app')!.innerHTML = '__VITE_PLUGIN__'
11 changes: 11 additions & 0 deletions playground/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"private": true,
"scripts": {
"dev": "cross-env DEBUG=vite-plugin-meta-env-dts:* vite --port 9999",
"build": "vite build"
},
"devDependencies": {
"vite": "^5.2.10",
"vite-plugin-inspect": "^0.8.4"
}
}
24 changes: 24 additions & 0 deletions playground/types/auto-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Auto Generate By vite-plugin-meta-env-dts
// https://github.com/xparcai/vite-plugin-meta-env-dts
interface ImportMetaEnv {
/**
* 项目信息
*/
readonly VITE_PROJECT_NAME: string
readonly VITE_NAME: string
/**
* 版本
* 我是两行的注释
*/
readonly VITE_VERSION: number
/**
* 测试一下很多个空格
*/
readonly VITE_GE: string
readonly VITE_OBJECT: string
readonly VITE_ARRAY: number
}

interface ImportMeta {
readonly env: ImportMetaEnv
}
10 changes: 10 additions & 0 deletions playground/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from 'vite'
import Inspect from 'vite-plugin-inspect'
import VitePlugin from '../src'

export default defineConfig({
plugins: [
Inspect(),
VitePlugin(),
],
})
Loading

0 comments on commit 6312264

Please sign in to comment.