@varlet/vite-plugins 2.10.0 → 2.10.1-alpha.1682608027166

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/copy.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- import type { Plugin } from 'vite';
2
- export interface CopyPath {
3
- from: string;
4
- to: string;
5
- type: 'folder' | 'file';
6
- }
7
- export interface CopyOptions {
8
- paths: CopyPath[];
9
- }
10
- export declare function copy(options: CopyOptions): Plugin;
1
+ import type { Plugin } from 'vite';
2
+ export interface CopyPath {
3
+ from: string;
4
+ to: string;
5
+ type: 'folder' | 'file';
6
+ }
7
+ export interface CopyOptions {
8
+ paths: CopyPath[];
9
+ }
10
+ export declare function copy(options: CopyOptions): Plugin;
package/lib/copy.js CHANGED
@@ -1,18 +1,18 @@
1
- import fse from 'fs-extra';
2
- const { copySync, copyFileSync } = fse;
3
- export function copy(options) {
4
- return {
5
- name: 'vite-plugin-varlet-copy',
6
- buildStart() {
7
- options.paths.forEach((copyPath) => {
8
- try {
9
- ;
10
- (copyPath.type === 'folder' ? copySync : copyFileSync)(copyPath.from, copyPath.to);
11
- }
12
- catch (e) {
13
- this.warn(e);
14
- }
15
- });
16
- },
17
- };
18
- }
1
+ import fse from 'fs-extra';
2
+ const { copySync, copyFileSync } = fse;
3
+ export function copy(options) {
4
+ return {
5
+ name: 'vite-plugin-varlet-copy',
6
+ buildStart() {
7
+ options.paths.forEach((copyPath) => {
8
+ try {
9
+ ;
10
+ (copyPath.type === 'folder' ? copySync : copyFileSync)(copyPath.from, copyPath.to);
11
+ }
12
+ catch (e) {
13
+ this.warn(e);
14
+ }
15
+ });
16
+ },
17
+ };
18
+ }
package/lib/html.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { Plugin } from 'vite';
2
- export interface HtmlOptions {
3
- data?: Record<string, string>;
4
- }
5
- export declare function html(options: HtmlOptions): Plugin;
1
+ import type { Plugin } from 'vite';
2
+ export interface HtmlOptions {
3
+ data?: Record<string, string>;
4
+ }
5
+ export declare function html(options: HtmlOptions): Plugin;
package/lib/html.js CHANGED
@@ -1,12 +1,12 @@
1
- import ejs from 'ejs';
2
- export function html(options) {
3
- return {
4
- name: 'vite-plugin-varlet-html',
5
- transformIndexHtml: {
6
- order: 'pre',
7
- transform(html) {
8
- return ejs.render(html, options.data);
9
- },
10
- },
11
- };
12
- }
1
+ import ejs from 'ejs';
2
+ export function html(options) {
3
+ return {
4
+ name: 'vite-plugin-varlet-html',
5
+ transformIndexHtml: {
6
+ order: 'pre',
7
+ transform(html) {
8
+ return ejs.render(html, options.data);
9
+ },
10
+ },
11
+ };
12
+ }
package/lib/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from './markdown.js';
2
- export * from './html.js';
3
- export * from './inlineCss.js';
4
- export * from './copy.js';
1
+ export * from './markdown.js';
2
+ export * from './html.js';
3
+ export * from './inlineCss.js';
4
+ export * from './copy.js';
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export * from './markdown.js';
2
- export * from './html.js';
3
- export * from './inlineCss.js';
4
- export * from './copy.js';
1
+ export * from './markdown.js';
2
+ export * from './html.js';
3
+ export * from './inlineCss.js';
4
+ export * from './copy.js';
@@ -1,7 +1,7 @@
1
- import type { Plugin } from 'vite';
2
- export interface InlineCssOptions {
3
- cssFile: string;
4
- jsFile: string;
5
- onEnd?(): void;
6
- }
7
- export declare function inlineCss(options: InlineCssOptions): Plugin;
1
+ import type { Plugin } from 'vite';
2
+ export interface InlineCssOptions {
3
+ cssFile: string;
4
+ jsFile: string;
5
+ onEnd?(): void;
6
+ }
7
+ export declare function inlineCss(options: InlineCssOptions): Plugin;
package/lib/inlineCss.js CHANGED
@@ -1,29 +1,29 @@
1
- import fse from 'fs-extra';
2
- const { pathExistsSync, writeFileSync, readFileSync, removeSync } = fse;
3
- export function inlineCss(options) {
4
- return {
5
- name: 'vite-plugin-varlet-inline-css',
6
- apply: 'build',
7
- closeBundle() {
8
- const { cssFile, jsFile, onEnd } = options;
9
- if (!pathExistsSync(cssFile)) {
10
- this.warn('css file cannot found');
11
- onEnd === null || onEnd === void 0 ? void 0 : onEnd();
12
- return;
13
- }
14
- if (!pathExistsSync(jsFile)) {
15
- this.error('js file cannot found');
16
- onEnd === null || onEnd === void 0 ? void 0 : onEnd();
17
- return;
18
- }
19
- const cssCode = readFileSync(cssFile, 'utf-8');
20
- const jsCode = readFileSync(jsFile, 'utf-8');
1
+ import fse from 'fs-extra';
2
+ const { pathExistsSync, writeFileSync, readFileSync, removeSync } = fse;
3
+ export function inlineCss(options) {
4
+ return {
5
+ name: 'vite-plugin-varlet-inline-css',
6
+ apply: 'build',
7
+ closeBundle() {
8
+ const { cssFile, jsFile, onEnd } = options;
9
+ if (!pathExistsSync(cssFile)) {
10
+ this.warn('css file cannot found');
11
+ onEnd === null || onEnd === void 0 ? void 0 : onEnd();
12
+ return;
13
+ }
14
+ if (!pathExistsSync(jsFile)) {
15
+ this.error('js file cannot found');
16
+ onEnd === null || onEnd === void 0 ? void 0 : onEnd();
17
+ return;
18
+ }
19
+ const cssCode = readFileSync(cssFile, 'utf-8');
20
+ const jsCode = readFileSync(jsFile, 'utf-8');
21
21
  const injectCode = `;(function(){var style=document.createElement('style');style.type='text/css';\
22
22
  style.rel='stylesheet';style.appendChild(document.createTextNode(\`${cssCode.replace(/\\/g, '\\\\')}\`));\
23
- var head=document.querySelector('head');head.appendChild(style)})();`;
24
- writeFileSync(jsFile, `${injectCode}${jsCode}`);
25
- removeSync(cssFile);
26
- onEnd === null || onEnd === void 0 ? void 0 : onEnd();
27
- },
28
- };
29
- }
23
+ var head=document.querySelector('head');head.appendChild(style)})();`;
24
+ writeFileSync(jsFile, `${injectCode}${jsCode}`);
25
+ removeSync(cssFile);
26
+ onEnd === null || onEnd === void 0 ? void 0 : onEnd();
27
+ },
28
+ };
29
+ }
package/lib/markdown.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { Plugin } from 'vite';
2
- export interface MarkdownOptions {
3
- style?: string;
4
- }
5
- export declare function markdown(options: MarkdownOptions): Plugin;
1
+ import type { Plugin } from 'vite';
2
+ export interface MarkdownOptions {
3
+ style?: string;
4
+ }
5
+ export declare function markdown(options: MarkdownOptions): Plugin;
package/lib/markdown.js CHANGED
@@ -1,80 +1,80 @@
1
- import markdownIt from 'markdown-it';
2
- import hljs from 'highlight.js';
3
- import { kebabCase } from '@varlet/shared';
4
- function htmlWrapper(html) {
5
- const matches = html.matchAll(/<h3>(.*?)<\/h3>/g);
6
- const hGroup = html
7
- .replace(/<h3>/g, () => {
8
- const content = matches.next().value[1];
9
- return `:::<h3 id="${content}"><router-link to="#${content}">#</router-link>`;
10
- })
11
- .replace(/<h2/g, ':::<h2')
12
- .split(':::');
13
- const cardGroup = hGroup
14
- .map((fragment) => (fragment.includes('<h3') ? `<div class="card">${fragment}</div>` : fragment))
15
- .join('');
16
- return cardGroup.replace(/<code>/g, '<code v-pre>');
17
- }
18
- function extractComponents(source) {
19
- const componentRE = /import (.+) from ['"].+['"]/;
20
- const importRE = /import .+ from ['"].+['"]/g;
21
- const vueRE = /```vue((.|\r|\n)*?)```/g;
22
- const imports = [];
23
- const components = [];
24
- source = source.replace(vueRE, (_, p1) => {
25
- const partImports = p1.match(importRE);
26
- const partComponents = partImports === null || partImports === void 0 ? void 0 : partImports.map((importer) => {
27
- importer = importer.replace(/(\n|\r)/g, '');
28
- const component = importer.replace(componentRE, '$1');
29
- !imports.includes(importer) && imports.push(importer);
30
- !components.includes(component) && components.push(component);
31
- return `<${kebabCase(component)} />`;
32
- });
33
- return partComponents ? `<div class="varlet-component-preview">${partComponents.join('\n')}</div>` : '';
34
- });
35
- return {
36
- imports,
37
- components,
38
- source,
39
- };
40
- }
41
- function injectCodeExample(source) {
42
- const codeRE = /(<pre class="hljs">(.|\r|\n)*?<\/pre>)/g;
43
- return source.replace(codeRE, (str) => {
44
- const flags = [
45
- '// playground-ignore\n',
46
- '<span class="hljs-meta">#</span><span class="bash"> playground-ignore</span>\n',
47
- '<span class="hljs-comment">// playground-ignore</span>\n',
48
- '<span class="hljs-comment">/* playground-ignore */</span>\n',
49
- '<span class="hljs-comment">&lt;!-- playground-ignore --&gt;</span>\n',
50
- ];
51
- const attr = flags.some((flag) => str.includes(flag)) ? 'playground-ignore' : '';
52
- str = flags.reduce((str, flag) => str.replace(flag, ''), str);
53
- return `<var-site-code-example ${attr}>${str}</var-site-code-example>`;
54
- });
55
- }
56
- function highlight(str, lang, style) {
57
- let link = '';
58
- if (style) {
59
- link = '<link class="hljs-style" rel="stylesheet" href="' + style + '"/>';
60
- }
61
- if (lang && hljs.getLanguage(lang)) {
62
- return ('<pre class="hljs"><code>' +
63
- link +
64
- hljs.highlight(str, { language: lang, ignoreIllegals: true }).value +
65
- '</code></pre>');
66
- }
67
- return '';
68
- }
69
- function markdownToVue(source, options) {
70
- const { source: vueSource, imports, components } = extractComponents(source);
71
- const md = markdownIt({
72
- html: true,
73
- highlight: (str, lang) => highlight(str, lang, options.style),
74
- });
75
- let templateString = htmlWrapper(md.render(vueSource));
76
- templateString = templateString.replace(/process.env/g, '<span>process.env</span>');
77
- templateString = injectCodeExample(templateString);
1
+ import markdownIt from 'markdown-it';
2
+ import hljs from 'highlight.js';
3
+ import { kebabCase } from '@varlet/shared';
4
+ function htmlWrapper(html) {
5
+ const matches = html.matchAll(/<h3>(.*?)<\/h3>/g);
6
+ const hGroup = html
7
+ .replace(/<h3>/g, () => {
8
+ const content = matches.next().value[1];
9
+ return `:::<h3 id="${content}"><router-link to="#${content}">#</router-link>`;
10
+ })
11
+ .replace(/<h2/g, ':::<h2')
12
+ .split(':::');
13
+ const cardGroup = hGroup
14
+ .map((fragment) => (fragment.includes('<h3') ? `<div class="card">${fragment}</div>` : fragment))
15
+ .join('');
16
+ return cardGroup.replace(/<code>/g, '<code v-pre>');
17
+ }
18
+ function extractComponents(source) {
19
+ const componentRE = /import (.+) from ['"].+['"]/;
20
+ const importRE = /import .+ from ['"].+['"]/g;
21
+ const vueRE = /```vue((.|\r|\n)*?)```/g;
22
+ const imports = [];
23
+ const components = [];
24
+ source = source.replace(vueRE, (_, p1) => {
25
+ const partImports = p1.match(importRE);
26
+ const partComponents = partImports === null || partImports === void 0 ? void 0 : partImports.map((importer) => {
27
+ importer = importer.replace(/(\n|\r)/g, '');
28
+ const component = importer.replace(componentRE, '$1');
29
+ !imports.includes(importer) && imports.push(importer);
30
+ !components.includes(component) && components.push(component);
31
+ return `<${kebabCase(component)} />`;
32
+ });
33
+ return partComponents ? `<div class="varlet-component-preview">${partComponents.join('\n')}</div>` : '';
34
+ });
35
+ return {
36
+ imports,
37
+ components,
38
+ source,
39
+ };
40
+ }
41
+ function injectCodeExample(source) {
42
+ const codeRE = /(<pre class="hljs">(.|\r|\n)*?<\/pre>)/g;
43
+ return source.replace(codeRE, (str) => {
44
+ const flags = [
45
+ '// playground-ignore\n',
46
+ '<span class="hljs-meta">#</span><span class="bash"> playground-ignore</span>\n',
47
+ '<span class="hljs-comment">// playground-ignore</span>\n',
48
+ '<span class="hljs-comment">/* playground-ignore */</span>\n',
49
+ '<span class="hljs-comment">&lt;!-- playground-ignore --&gt;</span>\n',
50
+ ];
51
+ const attr = flags.some((flag) => str.includes(flag)) ? 'playground-ignore' : '';
52
+ str = flags.reduce((str, flag) => str.replace(flag, ''), str);
53
+ return `<var-site-code-example ${attr}>${str}</var-site-code-example>`;
54
+ });
55
+ }
56
+ function highlight(str, lang, style) {
57
+ let link = '';
58
+ if (style) {
59
+ link = '<link class="hljs-style" rel="stylesheet" href="' + style + '"/>';
60
+ }
61
+ if (lang && hljs.getLanguage(lang)) {
62
+ return ('<pre class="hljs"><code>' +
63
+ link +
64
+ hljs.highlight(str, { language: lang, ignoreIllegals: true }).value +
65
+ '</code></pre>');
66
+ }
67
+ return '';
68
+ }
69
+ function markdownToVue(source, options) {
70
+ const { source: vueSource, imports, components } = extractComponents(source);
71
+ const md = markdownIt({
72
+ html: true,
73
+ highlight: (str, lang) => highlight(str, lang, options.style),
74
+ });
75
+ let templateString = htmlWrapper(md.render(vueSource));
76
+ templateString = templateString.replace(/process.env/g, '<span>process.env</span>');
77
+ templateString = injectCodeExample(templateString);
78
78
  return `
79
79
  <template><div class="varlet-site-doc">${templateString}</div></template>
80
80
 
@@ -87,31 +87,31 @@ export default {
87
87
  }
88
88
  }
89
89
  </script>
90
- `;
91
- }
92
- export function markdown(options) {
93
- return {
94
- name: 'vite-plugin-varlet-markdown',
95
- enforce: 'pre',
96
- transform(source, id) {
97
- if (!/\.md$/.test(id)) {
98
- return;
99
- }
100
- try {
101
- return markdownToVue(source, options);
102
- }
103
- catch (e) {
104
- this.error(e);
105
- return '';
106
- }
107
- },
108
- async handleHotUpdate(ctx) {
109
- if (!/\.md$/.test(ctx.file))
110
- return;
111
- const readSource = ctx.read;
112
- ctx.read = async function () {
113
- return markdownToVue(await readSource(), options);
114
- };
115
- },
116
- };
117
- }
90
+ `;
91
+ }
92
+ export function markdown(options) {
93
+ return {
94
+ name: 'vite-plugin-varlet-markdown',
95
+ enforce: 'pre',
96
+ transform(source, id) {
97
+ if (!/\.md$/.test(id)) {
98
+ return;
99
+ }
100
+ try {
101
+ return markdownToVue(source, options);
102
+ }
103
+ catch (e) {
104
+ this.error(e);
105
+ return '';
106
+ }
107
+ },
108
+ async handleHotUpdate(ctx) {
109
+ if (!/\.md$/.test(ctx.file))
110
+ return;
111
+ const readSource = ctx.read;
112
+ ctx.read = async function () {
113
+ return markdownToVue(await readSource(), options);
114
+ };
115
+ },
116
+ };
117
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/vite-plugins",
3
- "version": "2.10.0",
3
+ "version": "2.10.1-alpha.1682608027166",
4
4
  "type": "module",
5
5
  "description": "vite plugins of varlet",
6
6
  "main": "lib/index.js",
@@ -25,7 +25,7 @@
25
25
  "fs-extra": "^9.0.1",
26
26
  "highlight.js": "^10.7.2",
27
27
  "markdown-it": "^12.2.3",
28
- "@varlet/shared": "2.10.0"
28
+ "@varlet/shared": "2.10.1-alpha.1682608027166"
29
29
  },
30
30
  "devDependencies": {
31
31
  "vite": "^4.0.4",