@varlet/cli 2.9.3-alpha.1679537809832 → 2.9.3

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/node/bin.js CHANGED
@@ -131,6 +131,13 @@ program
131
131
  const { commitLint } = await import('./commands/commitLint.js');
132
132
  return commitLint(option);
133
133
  });
134
+ program
135
+ .command('checklist <gitParams>')
136
+ .description('Display a checklist for confirmation')
137
+ .action(async (option) => {
138
+ const { checklist } = await import('./commands/checklist.js');
139
+ return checklist(option);
140
+ });
134
141
  program.on('command:*', async ([cmd]) => {
135
142
  const { default: logger } = await import('./shared/logger.js');
136
143
  program.outputHelp();
@@ -0,0 +1,6 @@
1
+ export interface CheckBlock {
2
+ type: string;
3
+ list: string[];
4
+ }
5
+ export declare function getCheckBlocks(html: string): CheckBlock[];
6
+ export declare function checklist(gitParams: string): Promise<void>;
@@ -0,0 +1,61 @@
1
+ import fse from 'fs-extra';
2
+ import markdownIt from 'markdown-it';
3
+ import logger from '../shared/logger.js';
4
+ import { CHECKLIST_FILE } from '../shared/constant.js';
5
+ import { COMMIT_MESSAGE_RE, isVersionCommitMessage, getCommitMessage } from './commitLint.js';
6
+ const { readFileSync, existsSync } = fse;
7
+ const blockRE = /<h3>(.|\n|\r)+?<\/ul>/g;
8
+ const typeRE = /<h3>(.+)<\/h3>/;
9
+ const childrenRE = /<ul>(.|\n|\r)+<\/ul>/;
10
+ const childRE = /<li>(.|\n|\r)+?<\/li>/g;
11
+ export function getCheckBlocks(html) {
12
+ var _a;
13
+ const blocks = (_a = html.match(blockRE)) !== null && _a !== void 0 ? _a : [];
14
+ const checkBlocks = [];
15
+ blocks.forEach((block) => {
16
+ var _a, _b;
17
+ const type = (_a = block.match(typeRE)) === null || _a === void 0 ? void 0 : _a[1];
18
+ const childrenBlock = (_b = block.match(childrenRE)) === null || _b === void 0 ? void 0 : _b[0];
19
+ if (!type || !childrenBlock) {
20
+ return;
21
+ }
22
+ const children = childrenBlock.match(childRE);
23
+ if (!children) {
24
+ return;
25
+ }
26
+ const list = children.map((child) => {
27
+ return child
28
+ .replaceAll('<li>', '')
29
+ .replaceAll('</li>', '')
30
+ .replaceAll('<p>', '')
31
+ .replaceAll('</p>', '')
32
+ .replaceAll('\n', '');
33
+ });
34
+ checkBlocks.push({
35
+ type,
36
+ list,
37
+ });
38
+ });
39
+ return checkBlocks;
40
+ }
41
+ export async function checklist(gitParams) {
42
+ var _a, _b, _c, _d, _e;
43
+ const commitMessage = getCommitMessage(gitParams);
44
+ if (isVersionCommitMessage(commitMessage) || !existsSync(CHECKLIST_FILE)) {
45
+ return;
46
+ }
47
+ const content = readFileSync(CHECKLIST_FILE, 'utf-8');
48
+ const html = markdownIt().render(content);
49
+ const checkBlocks = getCheckBlocks(html);
50
+ if (!checkBlocks.length) {
51
+ logger.warning('Cannot find anything need to checked');
52
+ return;
53
+ }
54
+ const type = (_a = commitMessage.match(COMMIT_MESSAGE_RE)) === null || _a === void 0 ? void 0 : _a[1];
55
+ const typeChildren = (_c = (_b = checkBlocks.find((checkBlock) => checkBlock.type === type)) === null || _b === void 0 ? void 0 : _b.list) !== null && _c !== void 0 ? _c : [];
56
+ const commonChildren = (_e = (_d = checkBlocks.find((checkBlock) => checkBlock.type === 'common')) === null || _d === void 0 ? void 0 : _d.list) !== null && _e !== void 0 ? _e : [];
57
+ const list = [...commonChildren, ...typeChildren];
58
+ logger.title('\nIt is recommended that you check the following information before pushing:\n');
59
+ logger.warning(`${list.map((item) => `🔔 ${item}`).join('\n')}\n`);
60
+ logger.title('If there are changes that need to be amended, please use git commit --amend to resolve.');
61
+ }
@@ -1 +1,4 @@
1
+ export declare const COMMIT_MESSAGE_RE: RegExp;
2
+ export declare function isVersionCommitMessage(message: string): string | false | null;
3
+ export declare function getCommitMessage(gitParams: string): string;
1
4
  export declare function commitLint(gitParams: string): void;
@@ -2,13 +2,16 @@ import logger from '../shared/logger.js';
2
2
  import semver from 'semver';
3
3
  import fse from 'fs-extra';
4
4
  const { readFileSync } = fse;
5
- function isVersion(message) {
5
+ export const COMMIT_MESSAGE_RE = /^(revert|fix|feat|docs|perf|test|types|style|build|chore|release|refactor)(\(.+\))?!?: (.|\n)+/;
6
+ export function isVersionCommitMessage(message) {
6
7
  return message.startsWith('v') && semver.valid(message.slice(1));
7
8
  }
9
+ export function getCommitMessage(gitParams) {
10
+ return readFileSync(gitParams, 'utf-8').trim();
11
+ }
8
12
  export function commitLint(gitParams) {
9
- const message = readFileSync(gitParams, 'utf-8').trim();
10
- const COMMIT_MESSAGE_RE = /^(revert|fix|feat|docs|perf|test|types|style|build|chore|release|refactor)(\(.+\))?!?: (.|\n)+/;
11
- if (!isVersion(message) && !COMMIT_MESSAGE_RE.test(message)) {
13
+ const commitMessage = getCommitMessage(gitParams);
14
+ if (!isVersionCommitMessage(commitMessage) && !COMMIT_MESSAGE_RE.test(commitMessage)) {
12
15
  logger.error(`Commit message invalid`);
13
16
  logger.warning(`\
14
17
  The rules for commit messages are as follows
@@ -12,3 +12,4 @@ export * from './commands/changelog.js';
12
12
  export * from './commands/preview.js';
13
13
  export * from './commands/vite.js';
14
14
  export * from './commands/extension.js';
15
+ export * from './commands/checklist.js';
package/lib/node/index.js CHANGED
@@ -12,3 +12,4 @@ export * from './commands/changelog.js';
12
12
  export * from './commands/preview.js';
13
13
  export * from './commands/vite.js';
14
14
  export * from './commands/extension.js';
15
+ export * from './commands/checklist.js';
@@ -21,6 +21,7 @@ export declare const TESTS_DIR_NAME = "__tests__";
21
21
  export declare const GENERATORS_DIR: string;
22
22
  export declare const UI_PACKAGE_JSON: string;
23
23
  export declare const CLI_PACKAGE_JSON: string;
24
+ export declare const CHECKLIST_FILE: string;
24
25
  export declare const SITE: string;
25
26
  export declare const SITE_OUTPUT_PATH: string;
26
27
  export declare const SITE_PUBLIC_PATH: string;
@@ -23,6 +23,7 @@ export const TESTS_DIR_NAME = '__tests__';
23
23
  export const GENERATORS_DIR = resolve(dirname, '../../../template/generators');
24
24
  export const UI_PACKAGE_JSON = resolve(CWD, 'package.json');
25
25
  export const CLI_PACKAGE_JSON = resolve(dirname, '../../../package.json');
26
+ export const CHECKLIST_FILE = resolve(CWD, 'CHECKLIST.md');
26
27
  // site
27
28
  export const SITE = resolve(dirname, '../../../site');
28
29
  export const SITE_OUTPUT_PATH = resolve(CWD, 'site');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/cli",
3
- "version": "2.9.3-alpha.1679537809832",
3
+ "version": "2.9.3",
4
4
  "type": "module",
5
5
  "description": "cli of varlet",
6
6
  "bin": {
@@ -69,8 +69,9 @@
69
69
  "vue": "3.2.25",
70
70
  "vue-jest": "^5.0.0-alpha.8",
71
71
  "webfont": "^9.0.0",
72
- "@varlet/shared": "2.9.3-alpha.1679537809832",
73
- "@varlet/vite-plugins": "2.9.3-alpha.1679537809832"
72
+ "markdown-it": "^12.2.3",
73
+ "@varlet/shared": "2.9.3",
74
+ "@varlet/vite-plugins": "2.9.3"
74
75
  },
75
76
  "devDependencies": {
76
77
  "@types/babel__core": "^7.1.12",
@@ -83,8 +84,9 @@
83
84
  "@types/node": "^18.7.20",
84
85
  "@types/semver": "^7.3.9",
85
86
  "@types/sharp": "0.31.1",
86
- "@varlet/icons": "2.9.3-alpha.1679537809832",
87
- "@varlet/touch-emulator": "2.9.3-alpha.1679537809832"
87
+ "@types/markdown-it": "^12.2.3",
88
+ "@varlet/icons": "2.9.3",
89
+ "@varlet/touch-emulator": "2.9.3"
88
90
  },
89
91
  "peerDependencies": {
90
92
  "@vue/runtime-core": "3.2.16",
@@ -94,8 +96,8 @@
94
96
  "lodash-es": "^4.17.21",
95
97
  "vue": "3.2.25",
96
98
  "vue-router": "4.0.12",
97
- "@varlet/icons": "2.9.3-alpha.1679537809832",
98
- "@varlet/touch-emulator": "2.9.3-alpha.1679537809832"
99
+ "@varlet/icons": "2.9.3",
100
+ "@varlet/touch-emulator": "2.9.3"
99
101
  },
100
102
  "scripts": {
101
103
  "dev": "tsc --watch",