修复node包

This commit is contained in:
唐明明
2022-06-15 15:13:01 +08:00
parent a135d6bed4
commit e5207d5b7f
744 changed files with 66977 additions and 1737 deletions

108
node_modules/uni-read-pages/README.md generated vendored Normal file
View File

@@ -0,0 +1,108 @@
# uni-read-pages
![coverage](https://img.shields.io/badge/coverage%20-98%25-green) ![npm](https://img.shields.io/badge/npm%20-v2.6.11-blue) ![license](https://img.shields.io/badge/license-MIT-red) ![size](https://img.shields.io/badge/size-1.48%20kb-yellowgreen)
通过 [vue.config.js](https://cli.vuejs.org/zh/config/) 配合此库,可以随心所欲的读取 `pages.json` 下的所有配置
## 安装
您可以使用 `Yarn``npm` 安装该软件包(选择一个):
##### Yarn
```sh
yarn add uni-read-pages
```
##### npm
```sh
npm install uni-read-pages
```
## 开始
配置 `vue.config.js` 通过 `webpack` 注入全局变量 [查看文档](https://www.webpackjs.com/plugins/define-plugin/)
#### 配置 `vue.config.js`
```js
//vue.config.js
const TransformPages = require('uni-read-pages')
const tfPages = new TransformPages()
module.exports = {
configureWebpack: {
plugins: [
new tfPages.webpack.DefinePlugin({
ROUTES: JSON.stringify(tfPages.routes)
})
]
}
}
```
借助`webpack.DefinePlugin` 轻松注入全局变量。`ROUTES` 及可全局使用
#### 使用
```js
// xxx.vue
<script>
export default {
data() {
return {
title: 'Hello'
}
},
onLoad() {
console.log(ROUTES)
},
}
</script>
```
## API
#### options
```js
//默认值
const CONFIG={
cli:false, //当前是否为脚手架初始化的项目
includes:['path','aliasPath','name'] //需要获取包涵的字段
}
```
#### Instance method
* **getPagesRoutes**
* 通过读取 `pages.json` 文件 生成直接可用的routes
* **parsePages(pageCallback, subPageCallback)**
* 单条page对象解析
* **resolvePath(dir)**
* 解析绝对路径
#### Instance attr
* **CONFIG**
* 当前配置项
* **webpack**
* 当前工程下需要用到 `webpack`
* **uniPagesJSON**
* 当前 `uni-app` 内置对象,可以通过此属性调用一些内置方法
* **routes**
* 通过 **includes** 解析后得到的路由表 **可直接使用**
#### getter
* **pagesJson**
* 获取所有 `pages.json` 下的内容 返回 `json`
#### uniPagesJSON method
* getMainEntry()
* getNVueMainEntry()
* parsePages (pagesJson, pageCallback, subPageCallback)
* parseEntry (pagesJson)
* getPagesJson()
* parsePagesJson (content, loader)
#### uniPagesJSON attr
* pagesJsonJsFileName //默认值 pages.js

83
node_modules/uni-read-pages/index.js generated vendored Normal file
View File

@@ -0,0 +1,83 @@
const path = require('path')
const CONFIG = {
includes: ['path', 'aliasPath', 'name']
}
const rootPath = path.resolve(process.cwd(), 'node_modules');
/** 解析绝对路径
* @param {Object} dir
*/
function resolvePath(dir) {
return path.resolve(rootPath, dir);
}
class TransformPages {
constructor(config) {
config = {
...CONFIG,
...config
};
this.CONFIG = config;
this.webpack = require(resolvePath('webpack'));
this.uniPagesJSON = require(resolvePath('@dcloudio/uni-cli-shared/lib/pages.js'));
this.routes = this.getPagesRoutes().concat(this.getNotMpRoutes());
}
/**
* 获取所有pages.json下的内容 返回json
*/
get pagesJson() {
return this.uniPagesJSON.getPagesJson();
}
/**
* 通过读取pages.json文件 生成直接可用的routes
*/
getPagesRoutes(pages = this.pagesJson.pages, rootPath = null) {
const routes = [];
for (let i = 0; i < pages.length; i++) {
const item = pages[i];
const route = {};
for (let j = 0; j < this.CONFIG.includes.length; j++) {
const key = this.CONFIG.includes[j];
let value = item[key];
if (key === 'path') {
value = rootPath ? `/${rootPath}/${value}` : `/${value}`
}
if (key === 'aliasPath' && i == 0 && rootPath == null) {
route[key] = route[key] || '/'
} else if (value !== undefined) {
route[key] = value;
}
}
routes.push(route);
}
return routes;
}
/**
* 解析小程序分包路径
*/
getNotMpRoutes() {
const {
subPackages
} = this.pagesJson;
let routes = [];
if (subPackages == null || subPackages.length == 0) {
return [];
}
for (let i = 0; i < subPackages.length; i++) {
const subPages = subPackages[i].pages;
const root = subPackages[i].root;
const subRoutes = this.getPagesRoutes(subPages, root);
routes = routes.concat(subRoutes)
}
return routes
}
/**
* 单条page对象解析
* @param {Object} pageCallback
* @param {Object} subPageCallback
*/
parsePages(pageCallback, subPageCallback) {
this.uniPagesJSON.parsePages(this.pagesJson, pageCallback, subPageCallback)
}
}
module.exports = TransformPages

25
node_modules/uni-read-pages/package.json generated vendored Normal file
View File

@@ -0,0 +1,25 @@
{
"name": "uni-read-pages",
"version": "1.0.5",
"description": "read `pages.json` file to generate the routes table",
"main": "index.js",
"directories": {
"example": "examples"
},
"scripts": {
"postinstall": "node -e \"console.log('\\x1b[91m','\\n\\n uni-simple-router 垫脚片,欢迎下载!\\n \\n 开源不易,需要鼓励。去给 uni-read-pages 项目 点个 star 吧 \\n\\n')\"",
"dev": "webpack --watch --progress --config webpack/webpack.dev.js",
"build": "webpack --progress --config webpack/webpack.prod.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/SilurianYang/uni-read-pages.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/SilurianYang/uni-read-pages/issues"
},
"homepage": "https://github.com/SilurianYang/uni-read-pages#readme"
}