@varlet/cli 1.27.3 → 1.27.6

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,9 +1,9 @@
1
1
  export declare function getExampleRoutePath(examplePath: string): string;
2
- export declare function getComponentDocsRoutePath(componentDocsPath: string): string;
3
- export declare function getRootDocsRoutePath(rootDocsPath: string): string;
4
- export declare function findExamplePaths(): Promise<string[]>;
5
- export declare function findComponentDocsPaths(): Promise<string[]>;
6
- export declare function findRootDocsPaths(): Promise<string[]>;
2
+ export declare function getComponentDocRoutePath(componentDocsPath: string): string;
3
+ export declare function getRootDocRoutePath(rootDocsPath: string): string;
4
+ export declare function findExamples(): Promise<string[]>;
5
+ export declare function findComponentDocs(): Promise<string[]>;
6
+ export declare function findRootDocs(): Promise<string[]>;
7
7
  export declare function buildMobileSiteRoutes(): Promise<void>;
8
8
  export declare function buildPcSiteRoutes(): Promise<void>;
9
9
  export declare function buildSiteSource(): Promise<void>;
@@ -60,15 +60,10 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
60
60
  }
61
61
  return to.concat(ar || Array.prototype.slice.call(from));
62
62
  };
63
- var __importDefault = (this && this.__importDefault) || function (mod) {
64
- return (mod && mod.__esModule) ? mod : { "default": mod };
65
- };
66
63
  Object.defineProperty(exports, "__esModule", { value: true });
67
- exports.buildSiteEntry = exports.buildSiteSource = exports.buildPcSiteRoutes = exports.buildMobileSiteRoutes = exports.findRootDocsPaths = exports.findComponentDocsPaths = exports.findExamplePaths = exports.getRootDocsRoutePath = exports.getComponentDocsRoutePath = exports.getExampleRoutePath = void 0;
68
- var slash_1 = __importDefault(require("slash"));
64
+ exports.buildSiteEntry = exports.buildSiteSource = exports.buildPcSiteRoutes = exports.buildMobileSiteRoutes = exports.findRootDocs = exports.findComponentDocs = exports.findExamples = exports.getRootDocRoutePath = exports.getComponentDocRoutePath = exports.getExampleRoutePath = void 0;
69
65
  var constant_1 = require("../shared/constant");
70
66
  var fs_extra_1 = require("fs-extra");
71
- var path_1 = require("path");
72
67
  var fsUtils_1 = require("../shared/fsUtils");
73
68
  var varlet_config_1 = require("../config/varlet.config");
74
69
  var EXAMPLE_COMPONENT_NAME_RE = /\/([-\w]+)\/example\/index.vue/;
@@ -79,89 +74,39 @@ function getExampleRoutePath(examplePath) {
79
74
  return '/' + ((_a = examplePath.match(EXAMPLE_COMPONENT_NAME_RE)) === null || _a === void 0 ? void 0 : _a[1]);
80
75
  }
81
76
  exports.getExampleRoutePath = getExampleRoutePath;
82
- function getComponentDocsRoutePath(componentDocsPath) {
77
+ function getComponentDocRoutePath(componentDocsPath) {
83
78
  var _a;
84
79
  var _b = __read((_a = componentDocsPath.match(COMPONENT_DOCS_RE)) !== null && _a !== void 0 ? _a : [], 3), routePath = _b[1], language = _b[2];
85
80
  return "/".concat(language, "/").concat(routePath);
86
81
  }
87
- exports.getComponentDocsRoutePath = getComponentDocsRoutePath;
88
- function getRootDocsRoutePath(rootDocsPath) {
82
+ exports.getComponentDocRoutePath = getComponentDocRoutePath;
83
+ function getRootDocRoutePath(rootDocsPath) {
89
84
  var _a;
90
85
  var _b = __read((_a = rootDocsPath.match(ROOT_DOCS_RE)) !== null && _a !== void 0 ? _a : [], 3), routePath = _b[1], language = _b[2];
91
86
  return "/".concat(language, "/").concat(routePath);
92
87
  }
93
- exports.getRootDocsRoutePath = getRootDocsRoutePath;
94
- function findExamplePaths() {
95
- return __awaiter(this, void 0, void 0, function () {
96
- var dir, buildPath, existPath, slashPath;
97
- return __generator(this, function (_a) {
98
- switch (_a.label) {
99
- case 0: return [4 /*yield*/, (0, fs_extra_1.readdir)(constant_1.SRC_DIR)];
100
- case 1:
101
- dir = _a.sent();
102
- buildPath = function (filename) { return (0, path_1.resolve)(constant_1.SRC_DIR, filename, constant_1.EXAMPLE_DIR_NAME, constant_1.EXAMPLE_DIR_INDEX); };
103
- existPath = function (filename) { return (0, fs_extra_1.pathExistsSync)(buildPath(filename)); };
104
- slashPath = function (filename) { return (0, slash_1.default)(buildPath(filename)); };
105
- return [2 /*return*/, dir.filter(existPath).map(slashPath)];
106
- }
107
- });
108
- });
88
+ exports.getRootDocRoutePath = getRootDocRoutePath;
89
+ function findExamples() {
90
+ return (0, fsUtils_1.glob)("".concat(constant_1.SRC_DIR, "/**/").concat(constant_1.EXAMPLE_DIR_NAME, "/").concat(constant_1.EXAMPLE_DIR_INDEX));
109
91
  }
110
- exports.findExamplePaths = findExamplePaths;
111
- function findComponentDocsPaths() {
112
- return __awaiter(this, void 0, void 0, function () {
113
- var dir, buildPath, existPath, collectRoutePath;
114
- return __generator(this, function (_a) {
115
- switch (_a.label) {
116
- case 0: return [4 /*yield*/, (0, fs_extra_1.readdir)(constant_1.SRC_DIR)];
117
- case 1:
118
- dir = _a.sent();
119
- buildPath = function (filename) { return (0, path_1.resolve)(constant_1.SRC_DIR, filename, constant_1.DOCS_DIR_NAME); };
120
- existPath = function (filename) { return (0, fs_extra_1.pathExistsSync)(buildPath(filename)); };
121
- collectRoutePath = function (routePaths, filename) {
122
- var dirPath = buildPath(filename);
123
- (0, fs_extra_1.readdirSync)(dirPath).forEach(function (mdName) {
124
- var path = (0, path_1.resolve)(dirPath, mdName);
125
- (0, fsUtils_1.isMD)(path) && routePaths.push((0, slash_1.default)(path));
126
- });
127
- return routePaths;
128
- };
129
- return [2 /*return*/, dir.filter(existPath).reduce(collectRoutePath, [])];
130
- }
131
- });
132
- });
92
+ exports.findExamples = findExamples;
93
+ function findComponentDocs() {
94
+ return (0, fsUtils_1.glob)("".concat(constant_1.SRC_DIR, "/**/").concat(constant_1.DOCS_DIR_NAME, "/*.md"));
133
95
  }
134
- exports.findComponentDocsPaths = findComponentDocsPaths;
135
- function findRootDocsPaths() {
136
- return __awaiter(this, void 0, void 0, function () {
137
- var dir, buildPath, existPath, slashPath;
138
- return __generator(this, function (_a) {
139
- switch (_a.label) {
140
- case 0:
141
- if (!(0, fs_extra_1.pathExistsSync)(constant_1.ROOT_DOCS_DIR)) {
142
- return [2 /*return*/, []];
143
- }
144
- return [4 /*yield*/, (0, fs_extra_1.readdir)(constant_1.ROOT_DOCS_DIR)];
145
- case 1:
146
- dir = _a.sent();
147
- buildPath = function (filename) { return (0, path_1.resolve)(constant_1.ROOT_DOCS_DIR, filename); };
148
- existPath = function (filename) { return (0, fsUtils_1.isMD)(buildPath(filename)); };
149
- slashPath = function (filename) { return (0, slash_1.default)(buildPath(filename)); };
150
- return [2 /*return*/, dir.filter(existPath).map(slashPath)];
151
- }
152
- });
153
- });
96
+ exports.findComponentDocs = findComponentDocs;
97
+ function findRootDocs() {
98
+ return (0, fsUtils_1.glob)("".concat(constant_1.ROOT_DOCS_DIR, "/*.md"));
154
99
  }
155
- exports.findRootDocsPaths = findRootDocsPaths;
100
+ exports.findRootDocs = findRootDocs;
156
101
  function buildMobileSiteRoutes() {
157
102
  return __awaiter(this, void 0, void 0, function () {
158
- var examplePaths, routes, source;
103
+ var examples, routes, source;
159
104
  return __generator(this, function (_a) {
160
105
  switch (_a.label) {
161
- case 0: return [4 /*yield*/, findExamplePaths()];
106
+ case 0: return [4 /*yield*/, findExamples()];
162
107
  case 1:
163
- examplePaths = _a.sent();
164
- routes = examplePaths.map(function (examplePath) { return "\n {\n path: '".concat(getExampleRoutePath(examplePath), "',\n // @ts-ignore\n component: () => import('").concat(examplePath, "')\n }"); });
108
+ examples = _a.sent();
109
+ routes = examples.map(function (example) { return "\n {\n path: '".concat(getExampleRoutePath(example), "',\n // @ts-ignore\n component: () => import('").concat(example, "')\n }"); });
165
110
  source = "export default [ ".concat(routes.join(','), "\n]");
166
111
  return [4 /*yield*/, (0, fsUtils_1.outputFileSyncOnChange)(constant_1.SITE_MOBILE_ROUTES, source)];
167
112
  case 2:
@@ -174,14 +119,14 @@ function buildMobileSiteRoutes() {
174
119
  exports.buildMobileSiteRoutes = buildMobileSiteRoutes;
175
120
  function buildPcSiteRoutes() {
176
121
  return __awaiter(this, void 0, void 0, function () {
177
- var _a, componentDocsPaths, rootDocsPaths, componentDocsRoutes, rootDocsRoutes, source;
122
+ var _a, componentDocs, rootDocs, componentDocsRoutes, rootDocsRoutes, source;
178
123
  return __generator(this, function (_b) {
179
124
  switch (_b.label) {
180
- case 0: return [4 /*yield*/, Promise.all([findComponentDocsPaths(), findRootDocsPaths()])];
125
+ case 0: return [4 /*yield*/, Promise.all([findComponentDocs(), findRootDocs()])];
181
126
  case 1:
182
- _a = __read.apply(void 0, [_b.sent(), 2]), componentDocsPaths = _a[0], rootDocsPaths = _a[1];
183
- componentDocsRoutes = componentDocsPaths.map(function (componentDocsPath) { return "\n {\n path: '".concat(getComponentDocsRoutePath(componentDocsPath), "',\n // @ts-ignore\n component: () => import('").concat(componentDocsPath, "')\n }"); });
184
- rootDocsRoutes = rootDocsPaths.map(function (rootDocsPath) { return "\n {\n path: '".concat(getRootDocsRoutePath(rootDocsPath), "',\n // @ts-ignore\n component: () => import('").concat(rootDocsPath, "')\n }"); });
127
+ _a = __read.apply(void 0, [_b.sent(), 2]), componentDocs = _a[0], rootDocs = _a[1];
128
+ componentDocsRoutes = componentDocs.map(function (componentDoc) { return "\n {\n path: '".concat(getComponentDocRoutePath(componentDoc), "',\n // @ts-ignore\n component: () => import('").concat(componentDoc, "')\n }"); });
129
+ rootDocsRoutes = rootDocs.map(function (rootDoc) { return "\n {\n path: '".concat(getRootDocRoutePath(rootDoc), "',\n // @ts-ignore\n component: () => import('").concat(rootDoc, "')\n }"); });
185
130
  source = "export default [ ".concat(__spreadArray(__spreadArray([], __read(componentDocsRoutes), false), [rootDocsRoutes], false).join(','), "\n]");
186
131
  (0, fsUtils_1.outputFileSyncOnChange)(constant_1.SITE_PC_ROUTES, source);
187
132
  return [2 /*return*/];
@@ -13,3 +13,4 @@ export declare const bigCamelize: (s: string) => string;
13
13
  export declare const camelize: (s: string) => string;
14
14
  export declare function smartAppendFileSync(file: string, code: string): void;
15
15
  export declare function outputFileSyncOnChange(path: string, code: string): void;
16
+ export declare function glob(pattern: string): Promise<string[]>;
@@ -35,11 +35,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
36
  }
37
37
  };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
38
41
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.outputFileSyncOnChange = exports.smartAppendFileSync = exports.camelize = exports.bigCamelize = exports.replaceExt = exports.isPublicDir = exports.isLess = exports.isScript = exports.isDTS = exports.isTSX = exports.isJSX = exports.isSFC = exports.isDir = exports.isMD = exports.getPublicDirs = void 0;
42
+ exports.glob = exports.outputFileSyncOnChange = exports.smartAppendFileSync = exports.camelize = exports.bigCamelize = exports.replaceExt = exports.isPublicDir = exports.isLess = exports.isScript = exports.isDTS = exports.isTSX = exports.isJSX = exports.isSFC = exports.isDir = exports.isMD = exports.getPublicDirs = void 0;
40
43
  var path_1 = require("path");
41
44
  var fs_extra_1 = require("fs-extra");
42
45
  var constant_1 = require("./constant");
46
+ var glob_1 = __importDefault(require("glob"));
43
47
  function getPublicDirs() {
44
48
  return __awaiter(this, void 0, void 0, function () {
45
49
  var srcDir;
@@ -97,3 +101,16 @@ function outputFileSyncOnChange(path, code) {
97
101
  }
98
102
  }
99
103
  exports.outputFileSyncOnChange = outputFileSyncOnChange;
104
+ function glob(pattern) {
105
+ return new Promise(function (resolve, reject) {
106
+ (0, glob_1.default)(pattern, function (err, files) {
107
+ if (err) {
108
+ reject(err);
109
+ }
110
+ else {
111
+ resolve(files);
112
+ }
113
+ });
114
+ });
115
+ }
116
+ exports.glob = glob;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/cli",
3
- "version": "1.27.3",
3
+ "version": "1.27.6",
4
4
  "description": "cli of varlet",
5
5
  "bin": {
6
6
  "varlet-cli": "./lib/index.js"
@@ -27,15 +27,19 @@
27
27
  "bugs": {
28
28
  "url": "https://github.com/varletjs/varlet/issues"
29
29
  },
30
+ "scripts": {
31
+ "dev": "tsc --watch",
32
+ "build": "tsc"
33
+ },
30
34
  "gitHead": "ee9c3866bedad96c86365b0f9888a3a6bb781b1f",
31
35
  "dependencies": {
32
36
  "@babel/core": "^7.14.8",
33
37
  "@babel/helper-plugin-utils": "^7.14.5",
34
38
  "@babel/preset-env": "^7.14.8",
35
39
  "@babel/preset-typescript": "^7.14.5",
36
- "@varlet/icons": "1.27.3",
37
- "@varlet/markdown-vite-plugin": "1.27.3",
38
- "@varlet/touch-emulator": "1.27.3",
40
+ "@varlet/icons": "workspace:*",
41
+ "@varlet/markdown-vite-plugin": "workspace:*",
42
+ "@varlet/touch-emulator": "workspace:*",
39
43
  "@vitejs/plugin-vue": "2.2.0",
40
44
  "@vitejs/plugin-vue-jsx": "1.3.5",
41
45
  "@vue/babel-plugin-jsx": "1.1.1",
@@ -75,7 +79,7 @@
75
79
  "@types/semver": "^7.3.9"
76
80
  },
77
81
  "peerDependencies": {
78
- "@varlet/touch-emulator": "1.27.3",
82
+ "@varlet/touch-emulator": "workspace:*",
79
83
  "@vue/test-utils": "^2.0.0-rc.6",
80
84
  "clipboard": "^2.0.6",
81
85
  "live-server": "^1.2.1",
@@ -83,10 +87,5 @@
83
87
  "vue": "3.2.25",
84
88
  "@vue/runtime-core": "3.2.16",
85
89
  "vue-router": "4.0.12"
86
- },
87
- "scripts": {
88
- "dev": "tsc --watch",
89
- "build": "tsc"
90
- },
91
- "readme": "# @varlet/cli\n\n开箱即用的 `Vue3组件库` 快速成型工具,提供了一系列命令和工具去解决组件库开发上的问题\n\n### 特性\n\n- 1.开箱即用的组件库开发环境\n- 2.开箱即用的组件库编译工具,支持导出 `esm` 和 `umd` 两种模块代码\n- 3.基于配置文件的组件库文档站点,支持百度统计和主题定制\n- 4.支持 `单文件组件(sfc)` 和 `tsx,jsx` 两种风格的组件库编写风格\n- 5.开箱即用的代码检查工具\n- 6.开箱即用的单元测试工具\n- 7.开箱即用的代码发布工具,发布到 npm 和 github, 并自动生成更新日志\n- 8.支持 `Typescript`\n- 9.支持 `暗黑模式`\n- 10.基于 `pnpm`\n\n### 快速开始\n\n`@varlet/cli` 内置了 `单文件组件(sfc)` 和 `tsx, jsx` 两种风格的组件库项目模板,可以通过 `gen` 命令直接生成。\n帮助用户直接进入组件本身的开发,推荐使用 `pnpm` 作为包管理工具。\n\n```shell\n# 安装命令行工具\npnpm add @varlet/cli -g\n# 使用 gen 命令生成项目\nvarlet-cli gen 项目名\ncd 项目名\npnpm install\npnpm dev\n```\n\n然后通过简单修改一些组件库模板的基础信息,就可以开始组件库的开发了\n\n## 高级定制\n\n### 配置文件\n\n项目根目录下的 `varlet.config.js` 用来管理整个组件库项目的具体细节\n\n| 参数 | 说明 | 类型 | 默认值 |\n| ----- | -------------- | -------- | ---------- |\n| `host` | 开发服务器主机 | _number_ | `localhost` |\n| `port` | 开发服务器端口 | _number_ | `8080` |\n| `name` | 组件库全名\t| _string_ | `Varlet` |\n| `namespace` | 组件库命名空间, 会作为组件前缀 | _string_ | `var` |\n| `title` | 文档中组件库的标题 | _string_ | `VARLET` |\n| `logo` | 文档中组件库的logo | _string_ | `-` |\n| `defaultLanguage` | 文档默认语言 | _string_ | `zh-CN` |\n| `useMobile` | 是否显示右侧手机预览 | _boolean_ | `false` |\n| `themes` | 文档主题 | _SiteThemes_ | `-` |\n| `darkThemes` | 暗黑模式文档主题 | _SiteThemes_ | `-` |\n| `highlight` | 文档代码片段样式相关 | _SiteHighlight_ | `-` |\n| `analysis` | 文档统计相关 | _SiteAnalysis_ | `-` |\n| `pc` | pc端文档结构配置 | _SitePC_ | `-` |\n| `mobile` | mobile端文档结构配置 | _SiteMobile_ | `-` |\n| `moduleCompatible` | 模块兼容配置 | _Record<string, string>_ | `-` |\n\n#### 模块适配对象\n\n一些外部依赖可能需要进行模块语法的适配,以达到可以正确编译到 `commonjs` 和 `esmodule` 的目的,例如 `dayjs` 的 `esmodule` 写法是\n\n```js\nimport dayjs from 'dayjs/esm'\n```\n\n而为了构建 `commonjs` 时的写法是\n\n```js\nimport * as dayjs from 'dayjs'\n```\n\n在项目中我们拥抱 `esmodule` 模块使用第一种写法,并做如下配置进行适配\n\n```js\n// varlet.config.js\nmodule.exports = {\n moduleCompatible: {\n \"import dayjs from 'dayjs/esm'\\n\": \"import * as dayjs from 'dayjs'\\n\"\n }\n}\n```\n\n#### SiteThemes\n\n主题变量相关,由于默认的主题变量可能时常修改,以 `varlet` 官方文档的主题为准\n\n| 参数 |\n| ----- |\n| `color-body` |\n| `color-bar` |\n| `color-sub-bar` |\n| `color-text` |\n| `color-sub-text` |\n| `color-border` |\n| `color-shadow` |\n| `color-introduce-border` |\n| `color-primary` |\n| `color-link` |\n| `color-type` |\n| `color-progress` |\n| `color-progress-track` |\n| `color-side-bar` |\n| `color-side-bar-active-background` |\n| `color-app-bar` |\n| `color-nav-button-hover-background` |\n| `color-mobile-cell-hover` |\n| `color-pc-language-active` |\n| `color-pc-language-active-background` |\n| `color-mobile-language-active` |\n| `color-mobile-language-active-background` |\n| `color-hl-background` |\n| `color-hl-code` |\n| `color-hl-border` |\n| `color-hl-group-a` |\n| `color-hl-group-b` |\n| `color-hl-group-c` |\n| `color-hl-group-d` |\n| `color-hl-group-e` |\n| `color-hl-group-f` |\n| `color-hl-group-g` |\n| `color-hl-group-h` |\n| `color-hl-group-i` |\n\n#### SiteHighlight\n\n代码片段高亮,基于[highlight.js](https://highlightjs.org/)\n\n| 参数 | 说明 | 类型 | 默认值 |\n| ----- | -------------- | -------- | ---------- |\n| `style` | highlight的css地址 | _string_ | `-` |\n\n#### SiteAnalysis\n\n统计埋点相关\n\n| 参数 | 说明 | 类型 | 默认值 |\n| ----- | -------------- | -------- | ---------- |\n| `baidu` | 百度统计脚本地址 | _string_ | `-` |\n\n#### SitePC, SiteMobile\n\n文档结构部分相关,示例配置如下\n\n```js\nmodule.exports = {\n pc: {\n redirect: '/home',\n title: {\n 'zh-CN': '一个组件库',\n },\n header: {\n darkMode: null,\n i18n: null,\n github: 'https://github.com/varletjs/varlet',\n },\n menu: [\n {\n text: {\n 'zh-CN': '开发指南',\n },\n // 侧边栏菜单目录\n type: 1,\n },\n {\n text: {\n 'zh-CN': '基本介绍',\n },\n doc: 'home',\n // 索引项目根目录下的md文档\n type: 3,\n },\n {\n text: {\n 'zh-CN': '基础组件',\n },\n type: 1,\n },\n {\n text: {\n 'zh-CN': 'Button 按钮',\n },\n doc: 'button',\n // 索引组件根目录下的md文档\n type: 2,\n },\n ],\n },\n mobile: {\n redirect: '/home',\n title: {\n 'zh-CN': '一个组件库',\n },\n header: {\n darkMode: null,\n i18n: null,\n playground: null,\n github: 'https://github.com/varletjs/varlet',\n },\n },\n}\n```\n\n### 命令相关\n\n#### 启动开发服务器\n\n```shell\nvarlet-cli dev\n```\n\n#### 构建文档站点\n\n```shell\nvarlet-cli build\n```\n\n#### 预览文档站点\n\n```shell\nvarlet-cli preview\n```\n\n#### 构建组件库代码\n\n```shell\nvarlet-cli compile\n```\n\n#### 执行所有的单元测试\n\n```shell\nvarlet-cli test\n```\n\n#### 以 watch 模式执行单元测试\n\n```shell\nvarlet-cli test -w\nor\nvarlet-cli test -wa\n```\n\n#### 检查代码\n\n```shell\nvarlet-cli lint\n```\n\n#### 校验提交信息\n\n```shell\nvarlet-cli commit-lint\n```\n\n#### 生成更新日志\n\n```shell\nvarlet-cli changelog\n```\n\n#### 发布组件库\n\n```shell\nvarlet-cli release\n```\n\n#### 生成一个项目模板\n```shell\nvarlet-cli gen <projectName>\n```\n\n### babel\n\n对 `babel` 进行配置,首先在 `package.json` 中指定目标浏览器\n\n```json\n{\n \"browserslist\": [\n \"Chrome >= 51\",\n \"iOS >= 10\"\n ]\n}\n```\n\n创建 `babel.config,js`\n\n```js\n// babel.config.js\nmodule.exports = {\n presets: [\n [\n '@varlet/cli/preset',\n {\n loose: process.env.NODE_ENV === 'compile',\n },\n ],\n ],\n}\n```\n\n### git 和 npm\n\n#### git-hook\n\n`simple-git-hooks`,`lint-staged` 配合 `eslint`,`stylelint`,`varlet-cli commit-lint` 做commit前的检查,`package.json` 配置如下\n\n```json\n{\n \"simple-git-hooks\": {\n \"pre-commit\": \"pnpm exec lint-staged --allow-empty --concurrent false\",\n \"commit-msg\": \"npx --no-install varlet-cli commit-lint $1\"\n },\n \"lint-staged\": {\n \"*.{ts,tsx,js,vue,less}\": \"prettier --write\",\n \"*.{ts,tsx,js,vue}\": \"eslint --fix\",\n \"*.{vue,css,less}\": \"stylelint --fix\"\n },\n \"eslintConfig\": {\n \"root\": true,\n \"ignorePatterns\": [\n \"es/**\",\n \"umd/**\",\n \"site/**\",\n \"public/**\",\n \"src/*/__tests__/**\",\n \".varlet/**\"\n ],\n \"extends\": [\n \"@varlet\"\n ]\n },\n \"stylelint\": {\n \"extends\": [\n \"@varlet/stylelint-config\"\n ],\n \"ignoreFiles\": [\n \"es/**\",\n \"umd/**\",\n \"site/**\",\n \"coverage/**\",\n \"public/**\",\n \"highlight/**\"\n ]\n }\n}\n```\n\n挂载钩子\n\n```shell\nnpx simple-git-hooks\n```\n\n创建 `.prettierignore`\n\n```text\n// .prettierignore\ncoverage/**\nes/**\numd/**\nsite/**\npublic/**\nsrc/*/__tests__/**\n*.md\n```\n\n### typescript\n\n创建 `tsconfig.json`\n\n```json\n{\n \"compilerOptions\": {\n \"strict\": true,\n \"downlevelIteration\": true,\n \"declaration\": true,\n \"skipLibCheck\": true,\n \"esModuleInterop\": true,\n \"allowJs\": true,\n \"lib\": [\"esnext\", \"dom\"],\n \"allowSyntheticDefaultImports\": true,\n \"jsx\": \"preserve\"\n }\n}\n```\n\n#### 发布前注意\n\n1. `npm` 的仓库源必须指向 `npm` 官方镜像\n2. 执行 `npm login` 进行登录\n\n### Contributors\n\n<a href=\"https://github.com/varletjs/varlet/graphs/contributors\">\n <img src=\"https://contrib.rocks/image?repo=haoziqaq/varlet\" />\n</a>"
90
+ }
92
91
  }
@@ -14,6 +14,10 @@
14
14
  >
15
15
  <var-site-icon name="content-copy" size="18" />
16
16
  </var-site-button>
17
+
18
+ <var-site-button text round @click="toPlayground" v-if="playground">
19
+ <var-site-icon name="code-json" size="18" />
20
+ </var-site-button>
17
21
  </div>
18
22
  <div
19
23
  :id="`clip-target-${cid}`"
@@ -38,7 +42,7 @@ import config from '@config'
38
42
  import { defineComponent, nextTick, ref, onMounted } from 'vue'
39
43
  import { doubleRaf } from '../utils/elements'
40
44
  import { get } from 'lodash-es'
41
- import { getPCLocationInfo } from '../../utils'
45
+ import { getPCLocationInfo, utoa } from '../../utils'
42
46
  import type { Ref } from 'vue'
43
47
 
44
48
  let clipId = 0
@@ -50,13 +54,20 @@ export default defineComponent({
50
54
  [Button.name]: Button,
51
55
  [Icon.name]: Icon
52
56
  },
53
- setup() {
57
+ props: {
58
+ playgroundIgnore: {
59
+ type: Boolean,
60
+ default: false
61
+ }
62
+ },
63
+ setup(props) {
54
64
  const code: Ref<HTMLElement | null> = ref(null)
55
65
  const cid: Ref<number> = ref(clipId++)
56
66
  const fold: Ref = ref(get(config, 'pc.fold'))
57
67
  const disabledFold: Ref<boolean> = ref(false)
58
68
  const clipboard: Ref = ref(get(config, 'pc.clipboard', {}))
59
69
  const height: Ref<number> = ref(-1)
70
+ const playground: Ref<string | undefined> = ref(!props.playgroundIgnore ? get(config, 'pc.header.playground') : undefined )
60
71
  let timer: any = null
61
72
 
62
73
  const toggle = async () => {
@@ -82,6 +93,24 @@ export default defineComponent({
82
93
  }
83
94
  }
84
95
 
96
+ const toPlayground = () => {
97
+ const scriptStart = '<script setup>\n'
98
+ const scriptEnd = '<\/script>'
99
+ const injectImport = 'import { installVarletUI } from \'./varlet-repl-plugin.js\'\n'
100
+ const injectCall = '\ninstallVarletUI()\n'
101
+ let codeText = code.value?.innerText ?? ''
102
+
103
+ if (codeText.includes(scriptStart)) {
104
+ codeText = codeText.replace(scriptStart, `${scriptStart}${injectImport}`)
105
+ codeText = codeText.replace(scriptEnd, `${injectCall}${scriptEnd}`)
106
+ } else {
107
+ codeText = `${scriptStart}${injectImport}${injectCall}<\/script>\n\n${codeText}`
108
+ }
109
+
110
+ const file = { 'App.vue': codeText }
111
+ window.open(`${playground.value}/#${utoa(JSON.stringify(file))}`)
112
+ }
113
+
85
114
  onMounted(() => {
86
115
  const trigger = new Clipboard(`#clip-trigger-${cid.value}`)
87
116
 
@@ -101,7 +130,9 @@ export default defineComponent({
101
130
  fold,
102
131
  disabledFold,
103
132
  clipboard,
104
- toggle
133
+ playground,
134
+ toggle,
135
+ toPlayground
105
136
  }
106
137
  }
107
138
  })
package/site/utils.ts CHANGED
@@ -156,3 +156,7 @@ export function watchDarkMode(dark: StyleVars, cb?: (themes: 'darkThemes' | 'the
156
156
  cb?.(themes)
157
157
  })
158
158
  }
159
+
160
+ export function utoa(data: string): string {
161
+ return btoa(unescape(encodeURIComponent(data)))
162
+ }
@@ -5,7 +5,7 @@ module.exports = {
5
5
  port: 8080,
6
6
  title: 'VARLET',
7
7
  themesKey: 'VARLET_THEMES',
8
- logo: 'https://varlet.gitee.io/varlet-ui/varlet_icon.png',
8
+ logo: 'https://varlet-varletjs.vercel.app/varlet_icon.png',
9
9
  defaultLanguage: 'zh-CN',
10
10
  highlight: {
11
11
  /**
@@ -30,7 +30,7 @@ module.exports = {
30
30
  'en-US': 'English',
31
31
  },
32
32
  github: 'https://github.com/varletjs/varlet',
33
- playground: 'https://varlet.gitee.io/varlet-ui-playground',
33
+ playground: 'https://varlet-ui-playground.vercel.app',
34
34
  darkMode: true,
35
35
  },
36
36
  clipboard: {
package/LICENCE DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2020 varlet
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.