@varlet/cli 2.7.4-alpha.1675694992985 → 2.7.4

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.
@@ -1,10 +1,18 @@
1
+ import { type VarletConfig } from '../config/varlet.config.js';
2
+ export interface TemplateHighlightCompilerOptions {
3
+ md: string;
4
+ json: string;
5
+ titleAttributes: RegExp;
6
+ titleEvents: RegExp;
7
+ titleSlots: RegExp;
8
+ }
1
9
  export declare const replaceDot: (s: string) => string;
10
+ export declare const replaceVersion: (s: string) => string;
2
11
  export declare const replaceUnderline: (s: string) => string;
3
12
  export declare function parseTable(table: string): string[][];
4
13
  export declare function compileTable(md: string, titleRe: RegExp): string;
5
- export declare function compileTags(table: Record<string, any>, tags: Record<string, any>, componentName: string, varletConfig: Record<string, any>): void;
6
- export declare function compileAttributes(table: Record<string, any>, attributes: Record<string, any>, componentName: string, varletConfig: Record<string, any>): void;
7
- export declare function compileWebTypes(table: Record<string, any>, webTypes: Record<string, any>, componentName: string, varletConfig: Record<string, any>): void;
8
- export declare function compileMD(path: string, tags: Record<string, any>, attributes: Record<string, any>, webTypes: Record<string, any>, varletConfig: Record<string, any>): void;
9
- export declare function compileDir(path: string, tags: Record<string, any>, attributes: Record<string, any>, webTypes: Record<string, any>, varletConfig: Record<string, any>): void;
14
+ export declare function compileWebTypes(table: Record<string, any>, webTypes: Record<string, any>, componentName: string, varletConfig: Required<VarletConfig>): void;
15
+ export declare function compileMD(path: string, webTypes: Record<string, any>, varletConfig: Required<VarletConfig>, options: TemplateHighlightCompilerOptions): void;
16
+ export declare function compileDir(path: string, webTypes: Record<string, any>, varletConfig: Required<VarletConfig>, options: TemplateHighlightCompilerOptions): void;
17
+ export declare function compileLanguageMD(varletConfig: Required<VarletConfig>, options: TemplateHighlightCompilerOptions): void;
10
18
  export declare function compileTemplateHighlight(): Promise<void>;
@@ -1,13 +1,14 @@
1
1
  import fse from 'fs-extra';
2
- import { SRC_DIR, HL_MD, HL_API_RE, HL_COMPONENT_NAME_RE, HL_TITLE_ATTRIBUTES_RE, HL_TITLE_EVENTS_RE, HL_TITLE_SLOTS_RE, HL_WEB_TYPES_JSON, HL_DIR, HL_TAGS_JSON, HL_ATTRIBUTES_JSON, } from '../shared/constant.js';
2
+ import { SRC_DIR, HL_DIR, HL_API_RE, HL_COMPONENT_NAME_RE, HL_EN_MD, HL_EN_TITLE_ATTRIBUTES_RE, HL_EN_TITLE_EVENTS_RE, HL_EN_TITLE_SLOTS_RE, HL_EN_WEB_TYPES_JSON, HL_ZH_MD, HL_ZH_TITLE_ATTRIBUTES_RE, HL_ZH_TITLE_EVENTS_RE, HL_ZH_TITLE_SLOTS_RE, HL_ZH_WEB_TYPES_JSON, } from '../shared/constant.js';
3
3
  import { resolve } from 'path';
4
4
  import { getCliVersion, isDir, isMD } from '../shared/fsUtils.js';
5
5
  import { get } from 'lodash-es';
6
6
  import { getVarletConfig } from '../config/varlet.config.js';
7
- const { ensureDir, readdirSync, readFileSync, writeFile } = fse;
7
+ const { ensureDir, readdirSync, readFileSync, writeFileSync } = fse;
8
8
  const TABLE_HEAD_RE = /\s*\|.*\|\s*\n\s*\|.*---+\s*\|\s*\n+/;
9
9
  const TABLE_FOOT_RE = /(\|\s*$)|(\|\s*\n(?!\s*\|))/;
10
10
  export const replaceDot = (s) => s.replace(/`/g, '');
11
+ export const replaceVersion = (s) => s.replace(/\*\*\*.+\*\*\*/g, '').trim();
11
12
  export const replaceUnderline = (s) => s.replace(/_/g, '');
12
13
  export function parseTable(table) {
13
14
  const rows = table.split('\n').filter(Boolean);
@@ -41,24 +42,10 @@ export function compileTable(md, titleRe) {
41
42
  md = md.slice(0, tableFootMatched.index + tableFootMatched[0].length);
42
43
  return md.replace(/\\\|/g, '__varlet_axis__').trim();
43
44
  }
44
- export function compileTags(table, tags, componentName, varletConfig) {
45
- tags[`${get(varletConfig, 'namespace')}-${componentName}`] = {
46
- attributes: table.attributesTable.map((row) => replaceDot(row[0])),
47
- };
48
- }
49
- export function compileAttributes(table, attributes, componentName, varletConfig) {
50
- table.attributesTable.forEach((row) => {
51
- const attrNamespace = `${get(varletConfig, 'namespace')}-${componentName}/${replaceDot(row[0])}`;
52
- attributes[attrNamespace] = {
53
- type: replaceUnderline(row[2]),
54
- description: `${row[1]} 默认值:${replaceDot(row[3])}`,
55
- };
56
- });
57
- }
58
45
  export function compileWebTypes(table, webTypes, componentName, varletConfig) {
59
46
  const { attributesTable, eventsTable, slotsTable } = table;
60
47
  const attributes = attributesTable.map((row) => ({
61
- name: replaceDot(row[0]),
48
+ name: replaceVersion(replaceDot(row[0])),
62
49
  description: row[1],
63
50
  default: replaceDot(row[3]),
64
51
  value: {
@@ -67,11 +54,11 @@ export function compileWebTypes(table, webTypes, componentName, varletConfig) {
67
54
  },
68
55
  }));
69
56
  const events = eventsTable.map((row) => ({
70
- name: replaceDot(row[0]),
57
+ name: replaceVersion(replaceDot(row[0])),
71
58
  description: row[1],
72
59
  }));
73
60
  const slots = slotsTable.map((row) => ({
74
- name: replaceDot(row[0]),
61
+ name: replaceVersion(replaceDot(row[0])),
75
62
  description: row[1],
76
63
  }));
77
64
  webTypes.contributions.html.tags.push({
@@ -81,37 +68,31 @@ export function compileWebTypes(table, webTypes, componentName, varletConfig) {
81
68
  slots,
82
69
  });
83
70
  }
84
- export function compileMD(path, tags, attributes, webTypes, varletConfig) {
85
- if (!path.endsWith(HL_MD)) {
71
+ export function compileMD(path, webTypes, varletConfig, options) {
72
+ if (!path.endsWith(options.md)) {
86
73
  return;
87
74
  }
88
75
  const md = readFileSync(path, 'utf-8');
89
76
  const componentName = path.match(HL_COMPONENT_NAME_RE)[2];
90
- const attributesTable = parseTable(compileTable(md, HL_TITLE_ATTRIBUTES_RE));
91
- const eventsTable = parseTable(compileTable(md, HL_TITLE_EVENTS_RE));
92
- const slotsTable = parseTable(compileTable(md, HL_TITLE_SLOTS_RE));
77
+ const attributesTable = parseTable(compileTable(md, options.titleAttributes));
78
+ const eventsTable = parseTable(compileTable(md, options.titleEvents));
79
+ const slotsTable = parseTable(compileTable(md, options.titleSlots));
93
80
  const table = {
94
81
  attributesTable,
95
82
  eventsTable,
96
83
  slotsTable,
97
84
  };
98
85
  compileWebTypes(table, webTypes, componentName, varletConfig);
99
- compileTags(table, tags, componentName, varletConfig);
100
- compileAttributes(table, attributes, componentName, varletConfig);
101
86
  }
102
- export function compileDir(path, tags, attributes, webTypes, varletConfig) {
87
+ export function compileDir(path, webTypes, varletConfig, options) {
103
88
  const dir = readdirSync(path);
104
89
  dir.forEach((filename) => {
105
90
  const filePath = resolve(path, filename);
106
- isDir(filePath) && compileDir(filePath, tags, attributes, webTypes, varletConfig);
107
- isMD(filePath) && compileMD(filePath, tags, attributes, webTypes, varletConfig);
91
+ isDir(filePath) && compileDir(filePath, webTypes, varletConfig, options);
92
+ isMD(filePath) && compileMD(filePath, webTypes, varletConfig, options);
108
93
  });
109
94
  }
110
- export async function compileTemplateHighlight() {
111
- await ensureDir(HL_DIR);
112
- const varletConfig = await getVarletConfig();
113
- const tags = {};
114
- const attributes = {};
95
+ export function compileLanguageMD(varletConfig, options) {
115
96
  const webTypes = {
116
97
  $schema: 'https://raw.githubusercontent.com/JetBrains/web-types/master/schema/web-types.json',
117
98
  framework: 'vue',
@@ -124,10 +105,24 @@ export async function compileTemplateHighlight() {
124
105
  },
125
106
  },
126
107
  };
127
- compileDir(SRC_DIR, tags, attributes, webTypes, varletConfig);
128
- await Promise.all([
129
- writeFile(HL_WEB_TYPES_JSON, JSON.stringify(webTypes, null, 2)),
130
- writeFile(HL_TAGS_JSON, JSON.stringify(tags, null, 2)),
131
- writeFile(HL_ATTRIBUTES_JSON, JSON.stringify(attributes, null, 2)),
132
- ]);
108
+ compileDir(SRC_DIR, webTypes, varletConfig, options);
109
+ writeFileSync(options.json, JSON.stringify(webTypes, null, 2));
110
+ }
111
+ export async function compileTemplateHighlight() {
112
+ await ensureDir(HL_DIR);
113
+ const varletConfig = await getVarletConfig();
114
+ compileLanguageMD(varletConfig, {
115
+ md: HL_EN_MD,
116
+ json: HL_EN_WEB_TYPES_JSON,
117
+ titleAttributes: HL_EN_TITLE_ATTRIBUTES_RE,
118
+ titleEvents: HL_EN_TITLE_EVENTS_RE,
119
+ titleSlots: HL_EN_TITLE_SLOTS_RE,
120
+ });
121
+ compileLanguageMD(varletConfig, {
122
+ md: HL_ZH_MD,
123
+ json: HL_ZH_WEB_TYPES_JSON,
124
+ titleAttributes: HL_ZH_TITLE_ATTRIBUTES_RE,
125
+ titleEvents: HL_ZH_TITLE_EVENTS_RE,
126
+ titleSlots: HL_ZH_TITLE_SLOTS_RE,
127
+ });
133
128
  }
@@ -29,16 +29,19 @@ export declare const SITE_PC_DIR: string;
29
29
  export declare const SITE_PC_ROUTES: string;
30
30
  export declare const SITE_MOBILE_ROUTES: string;
31
31
  export declare const SITE_CONFIG: string;
32
+ export declare const HL_DIR: string;
32
33
  export declare const HL_COMPONENT_NAME_RE: RegExp;
33
34
  export declare const HL_API_RE: RegExp;
34
- export declare const HL_TITLE_ATTRIBUTES_RE: RegExp;
35
- export declare const HL_TITLE_EVENTS_RE: RegExp;
36
- export declare const HL_TITLE_SLOTS_RE: RegExp;
37
- export declare const HL_MD = "zh-CN.md";
38
- export declare const HL_DIR: string;
39
- export declare const HL_TAGS_JSON: string;
40
- export declare const HL_ATTRIBUTES_JSON: string;
41
- export declare const HL_WEB_TYPES_JSON: string;
35
+ export declare const HL_EN_TITLE_ATTRIBUTES_RE: RegExp;
36
+ export declare const HL_EN_TITLE_EVENTS_RE: RegExp;
37
+ export declare const HL_EN_TITLE_SLOTS_RE: RegExp;
38
+ export declare const HL_EN_MD = "en-US.md";
39
+ export declare const HL_EN_WEB_TYPES_JSON: string;
40
+ export declare const HL_ZH_TITLE_ATTRIBUTES_RE: RegExp;
41
+ export declare const HL_ZH_TITLE_EVENTS_RE: RegExp;
42
+ export declare const HL_ZH_TITLE_SLOTS_RE: RegExp;
43
+ export declare const HL_ZH_MD = "zh-CN.md";
44
+ export declare const HL_ZH_WEB_TYPES_JSON: string;
42
45
  export declare const ICONS_DIST_DIR: string;
43
46
  export declare const ICONS_CSS_DIR: string;
44
47
  export declare const ICONS_PNG_DIR: string;
@@ -33,16 +33,19 @@ export const SITE_PC_ROUTES = resolve(CWD, '.varlet/pc.routes.ts');
33
33
  export const SITE_MOBILE_ROUTES = resolve(CWD, '.varlet/mobile.routes.ts');
34
34
  export const SITE_CONFIG = resolve(CWD, '.varlet/site.config.json');
35
35
  // template highlight
36
+ export const HL_DIR = resolve(CWD, 'highlight');
36
37
  export const HL_COMPONENT_NAME_RE = /.*(\/|\\)(.+)(\/|\\)docs(\/|\\)/;
37
38
  export const HL_API_RE = /##\s*API\n+/;
38
- export const HL_TITLE_ATTRIBUTES_RE = /###\s*属性\s*\n+/;
39
- export const HL_TITLE_EVENTS_RE = /###\s*事件\s*\n+/;
40
- export const HL_TITLE_SLOTS_RE = /###\s*插槽\s*\n+/;
41
- export const HL_MD = 'zh-CN.md';
42
- export const HL_DIR = resolve(CWD, 'highlight');
43
- export const HL_TAGS_JSON = resolve(HL_DIR, 'tags.json');
44
- export const HL_ATTRIBUTES_JSON = resolve(HL_DIR, 'attributes.json');
45
- export const HL_WEB_TYPES_JSON = resolve(HL_DIR, 'web-types.json');
39
+ export const HL_EN_TITLE_ATTRIBUTES_RE = /###\s*Props\s*\n+/;
40
+ export const HL_EN_TITLE_EVENTS_RE = /###\s*Events\s*\n+/;
41
+ export const HL_EN_TITLE_SLOTS_RE = /###\s*Slots\s*\n+/;
42
+ export const HL_EN_MD = 'en-US.md';
43
+ export const HL_EN_WEB_TYPES_JSON = resolve(HL_DIR, 'web-types.en-US.json');
44
+ export const HL_ZH_TITLE_ATTRIBUTES_RE = /###\s*属性\s*\n+/;
45
+ export const HL_ZH_TITLE_EVENTS_RE = /###\s*事件\s*\n+/;
46
+ export const HL_ZH_TITLE_SLOTS_RE = /###\s*插槽\s*\n+/;
47
+ export const HL_ZH_MD = 'zh-CN.md';
48
+ export const HL_ZH_WEB_TYPES_JSON = resolve(HL_DIR, 'web-types.zh-CN.json');
46
49
  // icons
47
50
  export const ICONS_DIST_DIR = resolve(CWD, 'dist');
48
51
  export const ICONS_CSS_DIR = resolve(ICONS_DIST_DIR, 'css');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/cli",
3
- "version": "2.7.4-alpha.1675694992985",
3
+ "version": "2.7.4",
4
4
  "type": "module",
5
5
  "description": "cli of varlet",
6
6
  "bin": {
@@ -68,8 +68,8 @@
68
68
  "vite": "4.0.4",
69
69
  "vue": "3.2.25",
70
70
  "vue-jest": "^5.0.0-alpha.8",
71
- "@varlet/vite-plugins": "2.7.4-alpha.1675694992985",
72
- "@varlet/shared": "2.7.4-alpha.1675694992985"
71
+ "@varlet/vite-plugins": "2.7.4",
72
+ "@varlet/shared": "2.7.4"
73
73
  },
74
74
  "devDependencies": {
75
75
  "@types/babel__core": "^7.1.12",
@@ -82,8 +82,8 @@
82
82
  "@types/semver": "^7.3.9",
83
83
  "@types/inquirer": "^9.0.2",
84
84
  "@types/sharp": "0.31.1",
85
- "@varlet/icons": "2.7.4-alpha.1675694992985",
86
- "@varlet/touch-emulator": "2.7.4-alpha.1675694992985"
85
+ "@varlet/icons": "2.7.4",
86
+ "@varlet/touch-emulator": "2.7.4"
87
87
  },
88
88
  "peerDependencies": {
89
89
  "@vue/runtime-core": "3.2.16",
@@ -93,8 +93,8 @@
93
93
  "lodash-es": "^4.17.21",
94
94
  "vue": "3.2.25",
95
95
  "vue-router": "4.0.12",
96
- "@varlet/icons": "2.7.4-alpha.1675694992985",
97
- "@varlet/touch-emulator": "2.7.4-alpha.1675694992985"
96
+ "@varlet/icons": "2.7.4",
97
+ "@varlet/touch-emulator": "2.7.4"
98
98
  },
99
99
  "scripts": {
100
100
  "dev": "tsc --watch",
@@ -419,6 +419,11 @@ iframe {
419
419
  }
420
420
  }
421
421
 
422
+ strong {
423
+ font-size: 12px;
424
+ font-weight: normal;
425
+ }
426
+
422
427
  .card {
423
428
  border-radius: 4px;
424
429
  background: var(--site-config-color-bar);
@@ -5,11 +5,7 @@
5
5
  "main": "lib/varlet.cjs.js",
6
6
  "module": "es/index.mjs",
7
7
  "typings": "types/index.d.ts",
8
- "vetur": {
9
- "tags": "highlight/tags.json",
10
- "attributes": "highlight/attributes.json"
11
- },
12
- "web-types": "highlight/web-types.json",
8
+ "web-types": "highlight/web-types.en-US.json",
13
9
  "keywords": [
14
10
  "Vue",
15
11
  "UI"
@@ -5,11 +5,7 @@
5
5
  "main": "lib/varlet.cjs.js",
6
6
  "module": "es/index.mjs",
7
7
  "typings": "types/index.d.ts",
8
- "vetur": {
9
- "tags": "highlight/tags.json",
10
- "attributes": "highlight/attributes.json"
11
- },
12
- "web-types": "highlight/web-types.json",
8
+ "web-types": "highlight/web-types.en-US.json",
13
9
  "keywords": [
14
10
  "Vue",
15
11
  "UI"