Skip to content

Commit bbb5b11

Browse files
committed
feat: init
0 parents  commit bbb5b11

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+13171
-0
lines changed

.editorconfig

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_size = 2
6+
indent_style = space
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
[*.md]
13+
trim_trailing_whitespace = false
14+
15+
[manifest.json]
16+
indent_size = 4
17+
18+
[pages.json]
19+
indent_size = 4

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.cache
2+
.DS_Store
3+
.idea
4+
*.log
5+
*.tgz
6+
coverage
7+
dist
8+
lib-cov
9+
node_modules
10+
temp

.husky/pre-commit

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npx lint-staged

.npmrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
shamefully-hoist=true
2+
strict-peer-dependencies=false
3+
ignore-workspace-root-check=true

.vscode/settings.json

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
// Enable the ESlint flat config support
3+
"eslint.experimental.useFlatConfig": true,
4+
5+
// Disable the default formatter, use eslint instead
6+
"prettier.enable": false,
7+
"editor.formatOnSave": false,
8+
9+
// Auto fix
10+
"editor.codeActionsOnSave": {
11+
"source.fixAll.eslint": "explicit",
12+
"source.organizeImports": "never"
13+
},
14+
15+
// Silent the stylistic rules in you IDE, but still auto fix them
16+
"eslint.rules.customizations": [
17+
{ "rule": "style/*", "severity": "off" },
18+
{ "rule": "format/*", "severity": "off" },
19+
{ "rule": "*-indent", "severity": "off" },
20+
{ "rule": "*-spacing", "severity": "off" },
21+
{ "rule": "*-spaces", "severity": "off" },
22+
{ "rule": "*-order", "severity": "off" },
23+
{ "rule": "*-dangle", "severity": "off" },
24+
{ "rule": "*-newline", "severity": "off" },
25+
{ "rule": "*quotes", "severity": "off" },
26+
{ "rule": "*semi", "severity": "off" }
27+
],
28+
29+
// Enable eslint for all supported languages
30+
"eslint.validate": [
31+
"javascript",
32+
"javascriptreact",
33+
"typescript",
34+
"typescriptreact",
35+
"vue",
36+
"html",
37+
"markdown",
38+
"json",
39+
"jsonc",
40+
"yaml",
41+
"toml"
42+
],
43+
44+
"files.associations": {
45+
"manifest.json": "jsonc",
46+
"pages.json": "jsonc"
47+
}
48+
49+
}

eslint.config.js

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import antfu from '@antfu/eslint-config';
2+
3+
export default antfu(
4+
{
5+
ignores: [
6+
'**/shims-uni-app.d.ts',
7+
],
8+
},
9+
{
10+
// style
11+
rules: {
12+
'style/quote-props': ['error', 'as-needed'],
13+
'style/semi': ['error', 'always'],
14+
'style/max-statements-per-line': ['error', { max: 1 }],
15+
curly: ['warn', 'all'],
16+
'style/member-delimiter-style': ['warn', {
17+
multiline: { delimiter: 'semi', requireLast: true },
18+
singleline: { delimiter: 'semi', requireLast: false },
19+
multilineDetection: 'brackets',
20+
}],
21+
'import/order': [
22+
'warn',
23+
{
24+
groups: ['type', 'builtin', 'external', 'internal', 'parent', 'sibling', 'index', 'object'],
25+
alphabetize: { order: 'asc', caseInsensitive: true },
26+
warnOnUnassignedImports: false,
27+
},
28+
],
29+
},
30+
},
31+
{
32+
files: [
33+
'packages/playground/**/*.vue',
34+
'packages/playground/**/*.ts',
35+
],
36+
rules: {
37+
'no-console': 'off',
38+
},
39+
},
40+
{
41+
files: ['**/manifest.json', '**/pages.json'],
42+
rules: {
43+
indent: ['error', 4],
44+
'jsonc/indent': ['error', 4],
45+
},
46+
},
47+
);

lint-staged.config.mjs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default {
2+
'*.{js,jsx,ts,tsx,vue}': () => {
3+
return [
4+
'npm run typecheck',
5+
'npm run lint:fix',
6+
];
7+
},
8+
};

package.json

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "vite-plugin-uni-macros",
3+
"type": "module",
4+
"version": "0.0.1",
5+
"description": "",
6+
"author": "Edwin Xu",
7+
"license": "MIT",
8+
"keywords": [],
9+
"scripts": {
10+
"build": "rimraf --glob packages/*/dist && pnpm -r --filter=./packages/* run build",
11+
"dev:h5": "pnpm build && pnpm --filter=./packages/playground dev:h5",
12+
"typecheck": "tsc -p . --noEmit",
13+
"lint": "eslint .",
14+
"lint:fix": "pnpm lint --fix",
15+
"test": "vitest"
16+
},
17+
"devDependencies": {
18+
"@antfu/eslint-config": "^2.8.3",
19+
"@antfu/utils": "^0.7.7",
20+
"@babel/generator": "^7.23.6",
21+
"@dcloudio/types": "^3.4.8",
22+
"@types/babel__generator": "^7.6.8",
23+
"@types/debug": "^4.1.12",
24+
"@types/node": "^20.11.28",
25+
"@vue-macros/common": "^1.10.1",
26+
"ast-walker-scope": "^0.6.1",
27+
"bumpp": "^9.4.0",
28+
"debug": "^4.3.4",
29+
"eslint": "^8.57.0",
30+
"husky": "^9.0.11",
31+
"lint-staged": "^15.2.2",
32+
"magic-string": "^0.30.8",
33+
"rimraf": "^5.0.5",
34+
"typescript": "^5.4.2",
35+
"unbuild": "^2.0.0",
36+
"unconfig": "^0.3.11",
37+
"unplugin": "^1.10.0",
38+
"vitest": "^1.4.0"
39+
}
40+
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { defineBuildConfig } from 'unbuild';
2+
3+
export default defineBuildConfig({
4+
entries: ['src/index'],
5+
declaration: true,
6+
clean: true,
7+
rollup: {
8+
emitCJS: true,
9+
inlineDependencies: true,
10+
},
11+
externals: ['vite'],
12+
failOnWarn: false,
13+
});
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare module globalThis {
2+
export const definePage: typeof import('.').definePage;
3+
}

packages/define-pages-json/index.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference path="./client.d.ts" />
2+
3+
export * from './dist';
4+
5+
export { default } from './dist';
+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"name": "@uni-helper/vite-plugin-define-pages-json",
3+
"type": "module",
4+
"version": "0.0.1",
5+
"description": "Define uniapp pages.json dynamically.",
6+
"author": "Edwin Xu",
7+
"license": "MIT",
8+
"homepage": "https://github.com/uni-helper/vite-plugin-uni-macros",
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/uni-helper/vite-plugin-uni-macros.git"
12+
},
13+
"bugs": "https://github.com/uni-helper/vite-plugin-uni-macros/issues",
14+
"keywords": [],
15+
"sideEffects": false,
16+
"exports": {
17+
".": {
18+
"import": {
19+
"types": "./index.d.ts",
20+
"default": "./dist/index.mjs"
21+
},
22+
"require": {
23+
"types": "./index.d.ts",
24+
"default": "./dist/index.cjs"
25+
}
26+
},
27+
"./client": {
28+
"types": "./client.d.ts"
29+
}
30+
},
31+
"main": "./dist/index.cjs",
32+
"module": "./dist/index.mjs",
33+
"types": "./index.d.ts",
34+
"files": [
35+
"client.d.ts",
36+
"dist",
37+
"index.d.ts",
38+
"shims-uni-app.d.ts"
39+
],
40+
"scripts": {
41+
"build": "unbuild",
42+
"stub": "unbuild --stub"
43+
},
44+
"dependencies": {
45+
"@antfu/utils": "^0.7.7",
46+
"@babel/core": "^7.24.3",
47+
"@babel/generator": "^7.23.6",
48+
"@babel/traverse": "^7.24.1",
49+
"@babel/types": "^7.24.0",
50+
"@vue/compiler-core": "^3.4.21",
51+
"@vue/compiler-sfc": "^3.4.21",
52+
"ast-kit": "^0.12.1",
53+
"debug": "^4.3.4",
54+
"fast-glob": "^3.3.2",
55+
"tsx": "^4.7.1",
56+
"unconfig": "^0.3.11"
57+
},
58+
"devDependencies": {
59+
"@types/babel__core": "^7.20.5",
60+
"@types/babel__generator": "^7.6.8",
61+
"@types/babel__traverse": "^7.20.5",
62+
"@types/debug": "^4.1.12"
63+
}
64+
}
+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import type { DebugType } from './utils';
2+
import path from 'node:path';
3+
import process from 'node:process';
4+
import { OUTPUT_NAME } from './constant';
5+
import { enableDebug } from './utils';
6+
7+
export interface UserConfig {
8+
9+
/**
10+
* Project's root path
11+
* @default resolves to the `root` value from Vite config.
12+
*/
13+
root?: string;
14+
15+
/**
16+
* pages.json dir
17+
* @default "src"
18+
*/
19+
basePath?: string;
20+
21+
/**
22+
* Generate TypeScript declaration for pages path
23+
* Accept path related to project root
24+
* null to disable it
25+
* @default basePath
26+
*/
27+
dts?: string | null;
28+
29+
/**
30+
* Paths to the directory to search for page components.
31+
* @default 'src/pages'
32+
*/
33+
pages?: string;
34+
35+
/**
36+
* all root directories loaded by subPackages
37+
* @default []
38+
*/
39+
subPackages?: string[];
40+
41+
/**
42+
* exclude page
43+
* @default ['node_modules', '.git', '** /__*__/ **']
44+
*/
45+
exclude?: string[];
46+
47+
/**
48+
* enable debug log
49+
* @default false
50+
*/
51+
debug?: boolean | DebugType;
52+
}
53+
54+
export interface ResolvedConfig extends Required<UserConfig> {
55+
pagesJsonFile: string;
56+
}
57+
58+
let resolvedConfig: ResolvedConfig | undefined;
59+
60+
export function resolveConfig(useConfig: UserConfig): ResolvedConfig {
61+
const {
62+
root = process.cwd(),
63+
basePath = 'src',
64+
dts,
65+
pages = 'src/pages',
66+
subPackages = [],
67+
exclude = ['node_modules', '.git', '**/__*__/**'],
68+
debug = false,
69+
} = useConfig;
70+
71+
enableDebug(debug);
72+
73+
resolvedConfig = {
74+
root,
75+
get dts() {
76+
return dts === undefined
77+
? path.resolve(root, basePath)
78+
: dts;
79+
},
80+
pages,
81+
subPackages,
82+
get basePath() {
83+
return path.resolve(root, basePath);
84+
},
85+
exclude,
86+
debug,
87+
get pagesJsonFile() {
88+
return path.join(root, basePath, OUTPUT_NAME);
89+
},
90+
};
91+
92+
return resolvedConfig!;
93+
}
94+
95+
export function getConfig() {
96+
if (!resolvedConfig) {
97+
return resolveConfig({});
98+
}
99+
100+
return resolvedConfig;
101+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export const PAGES_CONFIG_FILE = 'pages.json';
2+
export const PAGES_CONFIG_EXT = ['ts', 'mts', 'cts', 'js', 'cjs', 'mjs'];
3+
4+
export const OUTPUT_NAME = 'pages.json';
5+
6+
export const FILE_EXTENSIONS = ['vue', 'nvue', 'uvue'];
7+
8+
export const DEFINE_PAGE = 'definePage';

0 commit comments

Comments
 (0)