11/*
22 * @Author : 曹捷
33 * @Date : 2021-11-11 17:29:49
4- * @LastEditors : 曹捷
5- * @LastEditTime : 2022-01-20 21:20:40
4+ * @LastEditors : seepine
5+ * @LastEditTime : 2022-07-17 21:13:44
66 * @Description : fileContent
77 */
88/**
@@ -12,53 +12,51 @@ const demoBlockContainers = require("./common/containers");
1212const { hash, path } = require ( "@vuepress/utils" ) ;
1313const prepareClientAppEnhanceFile = require ( "./prepareClientAppEnhanceFile" ) ;
1414const chokidar = require ( "chokidar" ) ;
15- module . exports = ( options = { } , app ) => {
16- options = Object . assign (
17- {
18- components : { } ,
19- componentsDir : null ,
20- componentsPatterns : [ "**/*.vue" ] ,
21- getComponentName : ( filename ) =>
22- path . trimExt ( filename . replace ( / \/ | \\ / g, "-" ) ) ,
23- } ,
24- options
25- ) ;
26- const optionsHash = hash ( options ) ;
27- const { componentsDir, componentsPatterns } = options ;
28- return {
29- // clientAppEnhanceFiles: path.resolve(__dirname, './enhanceAppFile.js'),
30- clientAppEnhanceFiles : ( ) =>
31- prepareClientAppEnhanceFile ( app , options , optionsHash ) ,
32- extendsMarkdown : ( md ) => {
33- md . use ( demoBlockContainers ( options ) ) ;
34- // const render = md.render;
35- // md.render = (...args) => {
36- // let result = render.call(md, ...args);
37- // if (result.indexOf("pre-render-demo") !== -1) {
38- // const { template, script, style } = renderDemoBlock(result);
39- // result.html = template;
40- // result.dataBlockString = `${script}\n${style}\n${result.dataBlockString}`;
41- // let page = `${template}\n${script}\n${style}`;
42- // console.log("🚀 ~ file: index.js ~ line 36 ~ page", page);
43- // return page;
44- // }
45- // return result;
46- // };
47- } ,
48- onWatched : ( app , watchers ) => {
49- if ( componentsDir ) {
50- const componentsWatcher = chokidar . watch ( componentsPatterns , {
51- cwd : componentsDir ,
52- ignoreInitial : true ,
53- } ) ;
54- componentsWatcher . on ( "add" , ( ) => {
55- prepareClientAppEnhanceFile ( app , options , optionsHash ) ;
56- } ) ;
57- componentsWatcher . on ( "unlink" , ( ) => {
58- prepareClientAppEnhanceFile ( app , options , optionsHash ) ;
59- } ) ;
60- watchers . push ( componentsWatcher ) ;
61- }
62- } ,
15+ module . exports = ( options = { } ) => {
16+ return ( app ) => {
17+ if ( ! options . path ) {
18+ throw Error (
19+ "[vuepress-plugin-demo-block-vue3]:not find componentsDir,please BlockDemo({path:__dirname})"
20+ ) ;
21+ }
22+ options = Object . assign (
23+ {
24+ components : { } ,
25+ componentsDir : path . resolve ( options . path , "../examples" ) ,
26+ componentsPatterns : [ "**/*.vue" ] ,
27+ getComponentName : ( filename ) =>
28+ path . trimExt ( filename . replace ( / \/ | \\ / g, "-" ) ) ,
29+ } ,
30+ options
31+ ) ;
32+ const optionsHash = hash ( options ) ;
33+ const { componentsDir, componentsPatterns } = options ;
34+ return {
35+ name : "vuepress-plugin-demo-block-vue3" ,
36+ clientConfigFile : path . resolve (
37+ options . path ,
38+ ".temp/register-components/client.js"
39+ ) ,
40+ onInitialized : ( ) =>
41+ prepareClientAppEnhanceFile ( app , options , optionsHash ) ,
42+ extendsMarkdown : ( md ) => {
43+ md . use ( demoBlockContainers ( options ) ) ;
44+ } ,
45+ onWatched : ( app , watchers ) => {
46+ if ( componentsDir ) {
47+ const componentsWatcher = chokidar . watch ( componentsPatterns , {
48+ cwd : componentsDir ,
49+ ignoreInitial : true ,
50+ } ) ;
51+ componentsWatcher . on ( "add" , ( ) => {
52+ prepareClientAppEnhanceFile ( app , options , optionsHash ) ;
53+ } ) ;
54+ componentsWatcher . on ( "unlink" , ( ) => {
55+ prepareClientAppEnhanceFile ( app , options , optionsHash ) ;
56+ } ) ;
57+ watchers . push ( componentsWatcher ) ;
58+ }
59+ } ,
60+ } ;
6361 } ;
6462} ;
0 commit comments