-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat: plugin public files (close: #1491) #1494
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
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0a6ca7e
initial commit
shigma b57869d
Update util.js
shigma 69abe97
Merge branch 'support-array-options' into plugin-public-files
shigma a46905e
mergeable patterns
shigma 62814ad
Merge branch 'master' into plugin-public-files
shigma 89c3f8b
initiate jest
shigma 0c8a4c4
Merge branch 'master' into plugin-public-files
shigma 4d50c42
add test case
shigma 010deae
bump copy-webpack-plugin version
shigma 3890859
another test case
shigma 13a660b
add docs
shigma f6ed7b7
feat(plugin): resolve conflicts typo and separate publics files into …
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ node_modules | |
TODOs.md | ||
packages/@vuepress/shared-utils/lib/ | ||
types | ||
**/.vuepress/dist |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# @vuepress/plugin-public-files | ||
|
||
> plugin for register public files | ||
|
||
See [documentation](https://v1.vuepress.vuejs.org/plugin/official/plugin-public-files.html). |
1 change: 1 addition & 0 deletions
1
packages/@vuepress/plugin-public-files/__tests__/docs-1/.dotfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dotfile |
1 change: 1 addition & 0 deletions
1
packages/@vuepress/plugin-public-files/__tests__/docs-1/.dotfolder/foo.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.dotfolder/foo.txt |
5 changes: 5 additions & 0 deletions
5
packages/@vuepress/plugin-public-files/__tests__/docs-1/.vuepress/config.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
plugins: [ | ||
[require('../../..')] | ||
] | ||
} |
1 change: 1 addition & 0 deletions
1
packages/@vuepress/plugin-public-files/__tests__/docs-1/.vuepress/public/.dotfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dotfile |
1 change: 1 addition & 0 deletions
1
packages/@vuepress/plugin-public-files/__tests__/docs-1/.vuepress/public/.dotfolder/foo.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.dotfolder/foo.txt |
1 change: 1 addition & 0 deletions
1
packages/@vuepress/plugin-public-files/__tests__/docs-1/.vuepress/public/bar/foo.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bar/foo.txt |
1 change: 1 addition & 0 deletions
1
packages/@vuepress/plugin-public-files/__tests__/docs-1/.vuepress/public/foo.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
foo.txt |
3 changes: 3 additions & 0 deletions
3
packages/@vuepress/plugin-public-files/__tests__/docs-1/.vuepress/theme/layouts/Layout.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<template> | ||
<Content /> | ||
</template> |
1 change: 1 addition & 0 deletions
1
packages/@vuepress/plugin-public-files/__tests__/docs-1/bar/baz.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bar/baz.txt |
1 change: 1 addition & 0 deletions
1
packages/@vuepress/plugin-public-files/__tests__/docs-1/bar/readme.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bar/readme |
1 change: 1 addition & 0 deletions
1
packages/@vuepress/plugin-public-files/__tests__/docs-1/baz.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
baz.txt |
1 change: 1 addition & 0 deletions
1
packages/@vuepress/plugin-public-files/__tests__/docs-1/readme.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
readme |
9 changes: 9 additions & 0 deletions
9
packages/@vuepress/plugin-public-files/__tests__/docs-2/.vuepress/config.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
plugins: [ | ||
[require('../../..'), { | ||
from: '_assets', | ||
to: 'assets', | ||
ignore: ['*.ignore'], | ||
}] | ||
] | ||
} |
1 change: 1 addition & 0 deletions
1
packages/@vuepress/plugin-public-files/__tests__/docs-2/.vuepress/public/foo.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
foo.txt |
3 changes: 3 additions & 0 deletions
3
packages/@vuepress/plugin-public-files/__tests__/docs-2/.vuepress/theme/layouts/Layout.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<template> | ||
<Content /> | ||
</template> |
1 change: 1 addition & 0 deletions
1
packages/@vuepress/plugin-public-files/__tests__/docs-2/_assets/.dotfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dotfile |
1 change: 1 addition & 0 deletions
1
packages/@vuepress/plugin-public-files/__tests__/docs-2/_assets/.dotfolder/foo.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.dotfolder/foo.txt |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
packages/@vuepress/plugin-public-files/__tests__/docs-2/_assets/baz.ignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
baz |
3 changes: 3 additions & 0 deletions
3
packages/@vuepress/plugin-public-files/__tests__/docs-2/readme.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
readme | ||
|
||
 |
54 changes: 54 additions & 0 deletions
54
packages/@vuepress/plugin-public-files/__tests__/index.spec.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* @jest-environment node | ||
*/ | ||
|
||
const { createApp } = require('@vuepress/core') | ||
const { path: { resolve }, fs } = require('@vuepress/shared-utils') | ||
|
||
function testForExistence (app, name, existence = true) { | ||
test(`${existence ? '' : 'in'}existence: ${name}`, () => { | ||
expect(fs.existsSync(resolve(app.outDir, name))).toBe(existence) | ||
}) | ||
} | ||
|
||
describe('plugin-public-files: source folder', () => { | ||
const app = createApp({ | ||
sourceDir: resolve(__dirname, 'docs-1') | ||
}) | ||
|
||
beforeAll(async () => { | ||
await app.process() | ||
await app.build() | ||
}, 60000) | ||
|
||
testForExistence(app, 'foo.txt') | ||
testForExistence(app, 'baz.txt') | ||
testForExistence(app, 'bar/foo.txt') | ||
testForExistence(app, 'bar/baz.txt') | ||
testForExistence(app, 'index.html') | ||
testForExistence(app, 'readme.md', false) | ||
testForExistence(app, '.dotfile', false) | ||
testForExistence(app, '.dotfolder', false) | ||
testForExistence(app, 'bar/readme.md', false) | ||
}) | ||
|
||
describe('plugin-public-files: assets folder', () => { | ||
const app = createApp({ | ||
sourceDir: resolve(__dirname, 'docs-2') | ||
}) | ||
|
||
beforeAll(async () => { | ||
await app.process() | ||
await app.build() | ||
}, 60000) | ||
|
||
testForExistence(app, 'foo.txt') | ||
testForExistence(app, 'assets/bar.png') | ||
testForExistence(app, 'assets/.dotfile') | ||
testForExistence(app, 'assets/.dotfolder/foo.txt') | ||
testForExistence(app, 'bar.png', false) | ||
testForExistence(app, 'baz.ignore', false) | ||
testForExistence(app, '.dotfile', false) | ||
testForExistence(app, '.dotfolder', false) | ||
testForExistence(app, 'assets/baz.ignore', false) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const { | ||
fs: { existsSync }, | ||
path: { resolve } | ||
} = require('@vuepress/shared-utils') | ||
const CopyPlugin = require('copy-webpack-plugin') | ||
const mergeable = require('vuepress-mergeable') | ||
|
||
module.exports = mergeable((patterns, context) => ({ | ||
name: `@vuepress/plugin-public-files`, | ||
|
||
chainWebpack (config) { | ||
if (!Array.isArray(patterns)) patterns = [patterns] | ||
|
||
config | ||
.plugin('copy') | ||
.use(CopyPlugin, [patterns.map((pattern) => { | ||
pattern = typeof pattern === 'string' | ||
? { from: pattern } | ||
: { ...pattern } | ||
|
||
// `from` will be resolved based on `sourceDir` | ||
pattern.from = resolve(context.sourceDir, pattern.from || '') | ||
if (!existsSync(pattern.from)) return | ||
|
||
// `to` will be resolved based on `outDir` | ||
pattern.to = resolve(context.outDir, pattern.to || '') | ||
|
||
// ignore dotfiles and markdown by default | ||
pattern.ignore = pattern.ignore || ['.*', '.*/**', '*.md'] | ||
|
||
return pattern | ||
}).filter(p => p)]) | ||
} | ||
}), 'flat') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"name": "@vuepress/plugin-public-files", | ||
"version": "1.0.4", | ||
"description": "register-public-files plugin for vuepress", | ||
"main": "index.js", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/vuejs/vuepress.git", | ||
"directory": "packages/@vuepress/plugin-public-files" | ||
}, | ||
"scripts": { | ||
"build": "vuepress build __tests__/docs-1", | ||
"jest": "jest .*\\.spec\\.js$" | ||
}, | ||
"keywords": [ | ||
"documentation", | ||
"vue", | ||
"vuepress", | ||
"generator" | ||
], | ||
"author": "Shigma <[email protected]>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/vuejs/vuepress/issues" | ||
}, | ||
"homepage": "https://github.com/vuejs/vuepress/packages/@vuepress/plugin-public-files#readme", | ||
"dependencies": { | ||
"@vuepress/core": "^1.0.4", | ||
"@vuepress/shared-utils": "^1.0.4", | ||
"copy-webpack-plugin": "^5.0.3", | ||
"vuepress-mergeable": "^1.0.1" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
--- | ||
title: public-files | ||
metaTitle: public files plugin | VuePress | ||
--- | ||
|
||
# [@vuepress/plugin-public-files](https://github.com/vuejs/vuepress/tree/master/packages/@vuepress/plugin-public-files) | ||
|
||
> public files plugin | ||
|
||
## Installation | ||
|
||
```bash | ||
yarn add -D @vuepress/plugin-public-files | ||
# OR npm install -D @vuepress/plugin-public-files | ||
``` | ||
|
||
## Usage | ||
|
||
### Default Usage | ||
|
||
```js | ||
module.exports = { | ||
plugins: [ | ||
// includes all files in `sourceDir` | ||
// ignore dotfiles and markdown | ||
"@vuepress/public-files" | ||
] | ||
}; | ||
``` | ||
|
||
### An Array of Patterns | ||
|
||
```js | ||
module.exports = { | ||
plugins: [ | ||
[ | ||
"@vuepress/public-files", | ||
[ | ||
".vuepress/another-public", | ||
".vuepress/one-more-public", | ||
".vuepress/public-file.txt" | ||
] | ||
] | ||
] | ||
}; | ||
``` | ||
|
||
### object style of pattern | ||
|
||
See: [https://github.com/webpack-contrib/copy-webpack-plugin#patterns](https://github.com/webpack-contrib/copy-webpack-plugin#patterns) | ||
|
||
```js | ||
module.exports = { | ||
plugins: [ | ||
[ | ||
"@vuepress/public-files", | ||
{ | ||
from: "_assets", // resolved based on sourceDir | ||
to: "assets", // resolved based on outDir | ||
ignore: [ | ||
/* glob patterns to be ignored */ | ||
] | ||
} | ||
] | ||
] | ||
}; | ||
``` | ||
|
||
::: tip | ||
In fact we support specifying a list of strings or objects. | ||
::: | ||
|
||
### Use Multiple Times | ||
|
||
```js | ||
module.exports = { | ||
plugins: [ | ||
[ | ||
"@vuepress/public-files", | ||
[".vuepress/another-public", ".vuepress/one-more-public"] | ||
], | ||
[ | ||
"@vuepress/public-files", | ||
{ | ||
from: "_assets", | ||
to: "assets", | ||
ignore: [ | ||
/* globs */ | ||
] | ||
} | ||
] | ||
] | ||
}; | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.