Skip to content

Commit fb8e7bc

Browse files
committed
Create example plugin / prompt for it
1 parent f554381 commit fb8e7bc

File tree

7 files changed

+51
-6
lines changed

7 files changed

+51
-6
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// plugins.js
2+
3+
// this file should be generated automatically by your plugin system
4+
// It should export a default object which contains plugins.
5+
// A plugin is a named index of "hooks" pointing to a list of Vue components
6+
// implementing that hook.
7+
8+
import MyPlugin from '@/plugins/myplugin'
9+
//
10+
// or, directly here:
11+
//
12+
// var FooPlugin = {
13+
// hooks: {
14+
// "plugins": [FooComponent]
15+
// }
16+
// }
17+
18+
export default {
19+
MyPlugin,
20+
// FooPlugin
21+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<template>
2+
<div>
3+
Greetings from the Foo plugin!
4+
</div>
5+
</template>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import FooComponent from './components/FooComponent.vue'
2+
export default {
3+
hooks: [FooComponent]
4+
}

generator/index.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
const fs = require('fs')
22

3-
module.exports = (api) => {
3+
module.exports = (api, options) => {
44
api.extendPackage({
55
dependencies: {
66
'vue-extensionpoints': '^0.1.4',
77
},
88
})
9-
api.render('./template');
9+
api.render('./template',{
10+
...options,
11+
});
12+
if (options.addExample) {
13+
api.render('./example', {
14+
...options,
15+
});
16+
}
1017

1118
// add import
1219
api.injectImports(api.entryFile,
@@ -32,7 +39,7 @@ module.exports.hooks = (api) => {
3239
const appPath = api.resolve('src/App.vue')
3340
if (fs.existsSync(appPath)) {
3441
let content = fs.readFileSync(appPath, { encoding: 'utf8' })
35-
content = content.replace(/HelloWorld/gi, 'ExtensionpointExample')
42+
content = content.replace(/HelloWorld\b/gi, 'HelloWorldWithPlugins')
3643
fs.writeFileSync(appPath, content)
3744
}
3845
})

generator/template/src/plugins/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
//
1010
// or, directly here:
1111
//
12-
// var BarPlugin = {
12+
// var FooPlugin = {
1313
// hooks: {
14-
// "bar-hook": [BarComponent, BeezComponent]
14+
// "plugins": [FooComponent]
1515
// }
1616
// }
1717

1818
export default {
1919
// MyPlugin,
20-
// BarPlugin
20+
// FooPlugin
2121
}

prompts.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = [
2+
{
3+
name: `addExample`,
4+
type: 'confirm',
5+
message: 'Add example plugin/components?',
6+
default: false,
7+
},
8+
];

0 commit comments

Comments
 (0)