Skip to content

Commit

Permalink
feat: init via sao-evillt-nm again
Browse files Browse the repository at this point in the history
  • Loading branch information
2nthony committed May 12, 2019
1 parent 96e9566 commit 403dd98
Show file tree
Hide file tree
Showing 5 changed files with 628 additions and 5,375 deletions.
12 changes: 6 additions & 6 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)
MIT License

Copyright (c) evillt <ijoec123@gmail.com> (https://github.com/evillt)
Copyright (c) evillt <ijoec123@gmail.com> (https://evila.me)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
97 changes: 63 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,78 +1,87 @@
# vue-auto-routes

> A **hack way** to auto generate vue routes.
> Auto generate vue routes
[![NPM version](https://flat.badgen.net/npm/v/vue-auto-routes?icon=npm)](https://npmjs.com/package/vue-auto-routes)
![NPM downloads](https://flat.badgen.net/npm/dt/vue-auto-routes?icon=npm)
![License](https://flat.badgen.net/npm/license/vue-auto-routes)
[![NPM version](https://badgen.net/npm/v/vue-auto-routes)](https://npmjs.com/package/vue-auto-routes)
[![NPM download](https://badgen.net/npm/dm/vue-auto-routes)](https://npmjs.com/package/vue-auto-routes)
[![CircleCI](https://badgen.net/circleci/github/evillt/vue-auto-routes?icon=circleci)](https://circleci.com/gh/evillt/vue-auto-routes/tree/master)
[![License](https://badgen.net/npm/license/vue-auto-routes)](./LICENSE)
[![donate](https://badgen.net/badge/support%20me/donate/f2a)](https://patreon.com/evillt)

# Install
## Install

```bash
```console
yarn add vue-auto-routes
# prefer npm
npm i vue-auto-routes -S
```

# Usage
## Usage

Example directory
We assume your directory looks like this:

```js
// index.vue -> /
// about.vue -> /about
// user.vue -> /user
// user/index.vue -> /user, child ''
// user/friends.vue -> /user, child 'friends'
// catalog/index.vue -> /catalog
// catalog/specials.vue -> /catalog/specials
// _path.vue -> /:path
// {path}.vue -> /:path props: true
// 404.vue -> *
```
src
├── views
│ ├── index.vue
│ └── about.vue
└── webpack.config.js
```

See [https://router.vuejs.org/guide/essentials/passing-props.html#boolean-mode](https://router.vuejs.org/guide/essentials/passing-props.html#boolean-mode)

But SHOULD NOT create two or more same route files.

webpack.config.js
Then in your `webpack.config.js`:

```js
const VueAutoRoutes = require('vue-auto-routes/lib/plugin')
const VueAutoRoutes = require('vue-auto-routes/plugin')

module.exports = {
plugins: [
new VueAutoRoutes({
dir: require('path').resolve(__dirname, 'src/pages')
dir: require('path').resolve(__dirname, 'src/views')
})
]
}
```

router.js
And in your `router.js`:

```js
import { routes } from 'vue-auto-routes'

export default new VueRouter({ routes })
```

## Files Convertion

```js
// index.vue -> /
// about.vue -> /about
// user.vue -> /user
// user/index.vue -> /user, child ''
// user/friends.vue -> /user, child 'friends'
// catalog/index.vue -> /catalog
// catalog/specials.vue -> /catalog/specials
// _path.vue -> /:path
// {path}.vue -> /:path props: true
// 404.vue -> *
```

# API

`new VueAutoRoutes(options: object)`
`new VueAutoRoutes(options)`

## options

Since `v1.1.11` options for [@ream/collect-fs-routes v1.0.2](https://github.com/ream/collect-fs-routes#api), but **differences** with these following

### dir

- Type: `string`
- Required: `true`

Pages directory, it should be an _**absolute path**_.
Routes directory, it should be an _**absolute path**_.

### ~~componentPrefix~~

### match

- Type: `string` `RegExp`
- Default: `'vue'` `/\.vue$/`

Expand All @@ -81,22 +90,29 @@ It used to match page components.
We use `,` to split match file extension when is a string.

### watchMode

- Type: `boolean`
- Default: `true` in `webpack-dev-server` and `webpack-dev-middleware`, `false` otherwise

Watching pages directory to auto update routes.

### default404

- Type: `boolean`
- Default: `true`

Use internal 404 page for mismatch route. You can create a `404.{#match}` in your `dir` to instead of it or set it `false`.

# Other

[@ream/collect-fs-routes](https://github.com/ream/collect-fs-routes#optionsdir) Offical usage like.

```js
const { collectRoutes, renderRoutes, renderRoutesMap } = require('vue-auto-routes/lib/collect-fs-routes')
const {
collectRoutes,
renderRoutes,
renderRoutesMap
} = require('vue-auto-routes/lib/collect-fs-routes')

const routes = await collectRoutes(options)
const routesString = renderRoutes(routes)
Expand All @@ -105,5 +121,18 @@ const routesMap = renderRoutesMap(routes) // Get a fullPath list of each route

Options for [options](#options)

# License
MIT
## Contributing

1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D

## Author

**vue-auto-routes** © [evillt](https://github.com/evillt), Released under the [MIT](./LICENSE) License.

Authored and maintained by **EVILLT** with help from contributors ([list](https://github.com/evillt/vue-auto-routes/contributors)).

> [evila.me](https://evila.me) · GitHub [@evillt](https://github.com/evillt) · Twitter [@evillt](https://twitter.com/evillt)
23 changes: 23 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: 2
jobs:
build:
docker:
- image: circleci/node:latest
branches:
ignore:
- gh-pages
- /release\/.*/
steps:
- checkout
- restore_cache:
key: dependency-cache-{{ checksum "yarn.lock" }}
- run:
name: Install dependencies
command: yarn
- save_cache:
key: dependency-cache-{{ checksum "yarn.lock" }}
paths:
- ./node_modules
- run:
name: Release
command: npx semantic-release
53 changes: 25 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,41 @@
{
"name": "vue-auto-routes",
"description": "A hack way to auto generate vue routes",
"version": "1.4.1",
"main": "index.js",
"author": "evila <ijoec123@gmail.com>",
"description": "Auto generate vue routes",
"version": "0.0.0",
"license": "MIT",
"repository": {
"type": "git",
"url": "evillt/vue-auto-routes"
},
"author": "evillt <ijoec123@gmail.com> (https://evila.me)",
"main": "index.js",
"files": [
"lib",
"plugin.js",
"404.vue"
],
"scripts": {
"install": "echo 'export const routes = []' > index.js",
"example": "dvan example/index.js --config example/dvan.config.js --no-clear-console",
"dev": "yarn example --dev",
"build": "yarn example"
},
"repository": {
"type": "git",
"url": "evillt/vue-auto-routes"
"install": "echo 'export const routes = []' > index.js"
},
"homepage": "https://github.com/evillt/vue-auto-routes",
"keywords": [
"vue",
"router",
"vue-router",
"vue-auto-routes",
"it-works"
],
"dependencies": {
"lodash.sortby": "^4.7.0"
},
"xo": {
"space": true,
"prettier": true
},
"devDependencies": {
"dvan": "^2.2.2",
"vue": "^2.5.21",
"vue-router": "^3.0.2",
"vue-template-compiler": "^2.5.21"
"husky": "^1.0.0-rc.13",
"lint-staged": "^7.2.0",
"prettier": "^1.17.0"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"linters": {
"*.{js,json,md}": [
"prettier --write",
"git add"
]
}
}
}
Loading

0 comments on commit 403dd98

Please sign in to comment.