@varlet/cli 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.
Files changed (65) hide show
  1. package/lib/client/appType.d.ts +4 -4
  2. package/lib/client/appType.js +7 -7
  3. package/lib/client/index.d.ts +18 -18
  4. package/lib/client/index.js +109 -109
  5. package/lib/node/bin.d.ts +2 -2
  6. package/lib/node/bin.js +148 -148
  7. package/lib/node/commands/build.d.ts +1 -1
  8. package/lib/node/commands/build.js +15 -15
  9. package/lib/node/commands/changelog.d.ts +5 -5
  10. package/lib/node/commands/changelog.js +20 -20
  11. package/lib/node/commands/checklist.d.ts +6 -6
  12. package/lib/node/commands/checklist.js +64 -64
  13. package/lib/node/commands/commitLint.d.ts +4 -4
  14. package/lib/node/commands/commitLint.js +19 -19
  15. package/lib/node/commands/compile.d.ts +3 -3
  16. package/lib/node/commands/compile.js +31 -31
  17. package/lib/node/commands/create.d.ts +7 -7
  18. package/lib/node/commands/create.js +91 -91
  19. package/lib/node/commands/dev.d.ts +6 -6
  20. package/lib/node/commands/dev.js +42 -42
  21. package/lib/node/commands/extension.d.ts +3 -3
  22. package/lib/node/commands/extension.js +5 -5
  23. package/lib/node/commands/gen.d.ts +7 -7
  24. package/lib/node/commands/gen.js +68 -68
  25. package/lib/node/commands/icons.d.ts +1 -1
  26. package/lib/node/commands/icons.js +82 -82
  27. package/lib/node/commands/jest.d.ts +7 -7
  28. package/lib/node/commands/jest.js +27 -27
  29. package/lib/node/commands/lint.d.ts +1 -1
  30. package/lib/node/commands/lint.js +42 -42
  31. package/lib/node/commands/preview.d.ts +1 -1
  32. package/lib/node/commands/preview.js +18 -18
  33. package/lib/node/commands/release.d.ts +5 -5
  34. package/lib/node/commands/release.js +150 -150
  35. package/lib/node/commands/vite.d.ts +2 -2
  36. package/lib/node/commands/vite.js +14 -14
  37. package/lib/node/compiler/compileModule.d.ts +4 -4
  38. package/lib/node/compiler/compileModule.js +71 -71
  39. package/lib/node/compiler/compileSFC.d.ts +6 -6
  40. package/lib/node/compiler/compileSFC.js +97 -96
  41. package/lib/node/compiler/compileScript.d.ts +13 -13
  42. package/lib/node/compiler/compileScript.js +126 -126
  43. package/lib/node/compiler/compileSiteEntry.d.ts +18 -18
  44. package/lib/node/compiler/compileSiteEntry.js +121 -121
  45. package/lib/node/compiler/compileStyle.d.ts +10 -10
  46. package/lib/node/compiler/compileStyle.js +41 -41
  47. package/lib/node/compiler/compileTemplateHighlight.d.ts +18 -18
  48. package/lib/node/compiler/compileTemplateHighlight.js +128 -128
  49. package/lib/node/compiler/compileTypes.d.ts +2 -2
  50. package/lib/node/compiler/compileTypes.js +40 -40
  51. package/lib/node/config/varlet.config.d.ts +73 -73
  52. package/lib/node/config/varlet.config.js +27 -27
  53. package/lib/node/config/varlet.default.config.d.ts +2 -2
  54. package/lib/node/config/varlet.default.config.js +271 -271
  55. package/lib/node/config/vite.config.d.ts +13 -13
  56. package/lib/node/config/vite.config.js +115 -115
  57. package/lib/node/index.d.ts +15 -15
  58. package/lib/node/index.js +15 -15
  59. package/lib/node/shared/constant.d.ts +51 -51
  60. package/lib/node/shared/constant.js +58 -58
  61. package/lib/node/shared/fsUtils.d.ts +15 -15
  62. package/lib/node/shared/fsUtils.js +54 -54
  63. package/lib/node/shared/logger.d.ts +8 -8
  64. package/lib/node/shared/logger.js +18 -18
  65. package/package.json +7 -7
@@ -1,20 +1,20 @@
1
- import conventionalChangelog from 'conventional-changelog';
2
- import fse from 'fs-extra';
3
- import { createSpinner } from 'nanospinner';
4
- import { resolve as resolvePath } from 'path';
5
- import { CWD } from '../shared/constant.js';
6
- const { createWriteStream } = fse;
7
- export function changelog({ releaseCount = 0, file = 'CHANGELOG.md' } = {}) {
8
- const s = createSpinner('Generating changelog').start();
9
- return new Promise((resolve) => {
10
- conventionalChangelog({
11
- preset: 'angular',
12
- releaseCount,
13
- })
14
- .pipe(createWriteStream(resolvePath(CWD, file)))
15
- .on('close', () => {
16
- s.success({ text: 'Changelog generated success!' });
17
- resolve();
18
- });
19
- });
20
- }
1
+ import conventionalChangelog from 'conventional-changelog';
2
+ import fse from 'fs-extra';
3
+ import { createSpinner } from 'nanospinner';
4
+ import { resolve as resolvePath } from 'path';
5
+ import { CWD } from '../shared/constant.js';
6
+ const { createWriteStream } = fse;
7
+ export function changelog({ releaseCount = 0, file = 'CHANGELOG.md' } = {}) {
8
+ const s = createSpinner('Generating changelog').start();
9
+ return new Promise((resolve) => {
10
+ conventionalChangelog({
11
+ preset: 'angular',
12
+ releaseCount,
13
+ })
14
+ .pipe(createWriteStream(resolvePath(CWD, file)))
15
+ .on('close', () => {
16
+ s.success({ text: 'Changelog generated success!' });
17
+ resolve();
18
+ });
19
+ });
20
+ }
@@ -1,6 +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>;
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>;
@@ -1,64 +1,64 @@
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
- if (!list.length) {
59
- return;
60
- }
61
- logger.title('\nIt is recommended that you check the following information before pushing:\n');
62
- logger.warning(`${list.map((item) => `🔔 ${item}`).join('\n')}\n`);
63
- logger.title('If there are changes that need to be amended, please use git commit --amend to resolve.');
64
- }
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
+ if (!list.length) {
59
+ return;
60
+ }
61
+ logger.title('\nIt is recommended that you check the following information before pushing:\n');
62
+ logger.warning(`${list.map((item) => `🔔 ${item}`).join('\n')}\n`);
63
+ logger.title('If there are changes that need to be amended, please use git commit --amend to resolve.');
64
+ }
@@ -1,4 +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;
4
- export declare function commitLint(gitParams: string): void;
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;
4
+ export declare function commitLint(gitParams: string): void;
@@ -1,18 +1,18 @@
1
- import logger from '../shared/logger.js';
2
- import semver from 'semver';
3
- import fse from 'fs-extra';
4
- const { readFileSync } = fse;
5
- export const COMMIT_MESSAGE_RE = /^(revert|fix|feat|docs|perf|test|types|style|build|chore|release|refactor)(\(.+\))?!?: (.|\n)+/;
6
- export function isVersionCommitMessage(message) {
7
- return message.startsWith('v') && semver.valid(message.slice(1));
8
- }
9
- export function getCommitMessage(gitParams) {
10
- return readFileSync(gitParams, 'utf-8').trim();
11
- }
12
- export function commitLint(gitParams) {
13
- const commitMessage = getCommitMessage(gitParams);
14
- if (!isVersionCommitMessage(commitMessage) && !COMMIT_MESSAGE_RE.test(commitMessage)) {
15
- logger.error(`Commit message invalid`);
1
+ import logger from '../shared/logger.js';
2
+ import semver from 'semver';
3
+ import fse from 'fs-extra';
4
+ const { readFileSync } = fse;
5
+ export const COMMIT_MESSAGE_RE = /^(revert|fix|feat|docs|perf|test|types|style|build|chore|release|refactor)(\(.+\))?!?: (.|\n)+/;
6
+ export function isVersionCommitMessage(message) {
7
+ return message.startsWith('v') && semver.valid(message.slice(1));
8
+ }
9
+ export function getCommitMessage(gitParams) {
10
+ return readFileSync(gitParams, 'utf-8').trim();
11
+ }
12
+ export function commitLint(gitParams) {
13
+ const commitMessage = getCommitMessage(gitParams);
14
+ if (!isVersionCommitMessage(commitMessage) && !COMMIT_MESSAGE_RE.test(commitMessage)) {
15
+ logger.error(`Commit message invalid`);
16
16
  logger.warning(`\
17
17
  The rules for commit messages are as follows
18
18
 
@@ -42,7 +42,7 @@ Allowed types:
42
42
  - revert
43
43
 
44
44
  Commit message reference: https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y
45
- 参考阮一峰Commit message编写指南: https://www.ruanyifeng.com/blog/2016/01/commit_message_change_log.html`);
46
- process.exit(1);
47
- }
48
- }
45
+ 参考阮一峰Commit message编写指南: https://www.ruanyifeng.com/blog/2016/01/commit_message_change_log.html`);
46
+ process.exit(1);
47
+ }
48
+ }
@@ -1,3 +1,3 @@
1
- export declare function removeDir(): Promise<[void, void, void, void]>;
2
- export declare function runTask(taskName: string, task: () => any): Promise<void>;
3
- export declare function compile(): Promise<void>;
1
+ export declare function removeDir(): Promise<[void, void, void, void]>;
2
+ export declare function runTask(taskName: string, task: () => any): Promise<void>;
3
+ export declare function compile(): Promise<void>;
@@ -1,31 +1,31 @@
1
- import logger from '../shared/logger.js';
2
- import fse from 'fs-extra';
3
- import { createSpinner } from 'nanospinner';
4
- import { ES_DIR, HL_DIR, LIB_DIR, UMD_DIR } from '../shared/constant.js';
5
- import { compileBundle, compileModule } from '../compiler/compileModule.js';
6
- import { compileTemplateHighlight } from '../compiler/compileTemplateHighlight.js';
7
- import { compileTypes } from '../compiler/compileTypes.js';
8
- const { remove } = fse;
9
- export function removeDir() {
10
- return Promise.all([remove(ES_DIR), remove(LIB_DIR), remove(HL_DIR), remove(UMD_DIR)]);
11
- }
12
- export async function runTask(taskName, task) {
13
- const s = createSpinner().start({ text: `Compiling ${taskName}` });
14
- try {
15
- await task();
16
- s.success({ text: `Compilation ${taskName} completed!` });
17
- }
18
- catch (e) {
19
- s.error({ text: `Compilation ${taskName} failed!` });
20
- logger.error(e.toString());
21
- }
22
- }
23
- export async function compile() {
24
- process.env.NODE_ENV = 'compile';
25
- await removeDir();
26
- await Promise.all([runTask('types', compileTypes), runTask('template highlight', compileTemplateHighlight)]);
27
- process.env.BABEL_MODULE = 'module';
28
- await runTask('module', compileModule);
29
- process.env.BABEL_MODULE = '';
30
- await runTask('bundle', compileBundle);
31
- }
1
+ import logger from '../shared/logger.js';
2
+ import fse from 'fs-extra';
3
+ import { createSpinner } from 'nanospinner';
4
+ import { ES_DIR, HL_DIR, LIB_DIR, UMD_DIR } from '../shared/constant.js';
5
+ import { compileBundle, compileModule } from '../compiler/compileModule.js';
6
+ import { compileTemplateHighlight } from '../compiler/compileTemplateHighlight.js';
7
+ import { compileTypes } from '../compiler/compileTypes.js';
8
+ const { remove } = fse;
9
+ export function removeDir() {
10
+ return Promise.all([remove(ES_DIR), remove(LIB_DIR), remove(HL_DIR), remove(UMD_DIR)]);
11
+ }
12
+ export async function runTask(taskName, task) {
13
+ const s = createSpinner().start({ text: `Compiling ${taskName}` });
14
+ try {
15
+ await task();
16
+ s.success({ text: `Compilation ${taskName} completed!` });
17
+ }
18
+ catch (e) {
19
+ s.error({ text: `Compilation ${taskName} failed!` });
20
+ logger.error(e.toString());
21
+ }
22
+ }
23
+ export async function compile() {
24
+ process.env.NODE_ENV = 'compile';
25
+ await removeDir();
26
+ await Promise.all([runTask('types', compileTypes), runTask('template highlight', compileTemplateHighlight)]);
27
+ process.env.BABEL_MODULE = 'module';
28
+ await runTask('module', compileModule);
29
+ process.env.BABEL_MODULE = '';
30
+ await runTask('bundle', compileBundle);
31
+ }
@@ -1,7 +1,7 @@
1
- export interface CreateCommandOptions {
2
- name?: string;
3
- locale?: boolean;
4
- sfc?: boolean;
5
- tsx?: boolean;
6
- }
7
- export declare function create(options: CreateCommandOptions): Promise<void>;
1
+ export interface CreateCommandOptions {
2
+ name?: string;
3
+ locale?: boolean;
4
+ sfc?: boolean;
5
+ tsx?: boolean;
6
+ }
7
+ export declare function create(options: CreateCommandOptions): Promise<void>;
@@ -1,91 +1,91 @@
1
- import ejs from 'ejs';
2
- import fse from 'fs-extra';
3
- import logger from '../shared/logger.js';
4
- import { bigCamelize, camelize, kebabCase } from '@varlet/shared';
5
- import inquirer from 'inquirer';
6
- import { get } from 'lodash-es';
7
- import { resolve } from 'path';
8
- import { glob } from '../shared/fsUtils.js';
9
- import { getVarletConfig } from '../config/varlet.config.js';
10
- import { SRC_DIR, dirname } from '../shared/constant.js';
11
- const { removeSync, readFileSync, copySync, pathExistsSync, writeFileSync } = fse;
12
- const { prompt } = inquirer;
13
- async function renderTemplates(componentFolder, componentFolderName, renderData) {
14
- const templates = await glob(`${componentFolder}/**/*.ejs`);
15
- templates.forEach((template) => {
16
- const templateCode = readFileSync(template, { encoding: 'utf-8' });
17
- const code = ejs.render(templateCode, renderData);
18
- const file = template
19
- .replace('[componentName]', camelize(componentFolderName))
20
- .replace('[ComponentName]', bigCamelize(componentFolderName))
21
- .replace('.ejs', '');
22
- writeFileSync(file, code);
23
- removeSync(template);
24
- });
25
- }
26
- export async function create(options) {
27
- logger.title('\n📦📦 Create a component ! \n');
28
- const namespace = get(await getVarletConfig(), 'namespace');
29
- const renderData = {
30
- namespace,
31
- bigCamelizeNamespace: bigCamelize(namespace),
32
- kebabCaseName: 'component-name',
33
- bigCamelizeName: 'ComponentName',
34
- camelizeName: 'componentName',
35
- style: 'vue',
36
- };
37
- const { name } = options.name
38
- ? options
39
- : await prompt({
40
- name: 'name',
41
- message: 'Name of the component created: ',
42
- default: renderData.kebabCaseName,
43
- });
44
- renderData.kebabCaseName = kebabCase(name);
45
- renderData.camelizeName = camelize(name);
46
- renderData.bigCamelizeName = bigCamelize(name);
47
- const componentFolder = resolve(SRC_DIR, renderData.kebabCaseName);
48
- const componentFolderName = renderData.kebabCaseName;
49
- if (pathExistsSync(componentFolder)) {
50
- logger.warning(`${componentFolderName} already exist and cannot be recreated...`);
51
- return;
52
- }
53
- const { locale } = options.locale
54
- ? options
55
- : await prompt({
56
- name: 'locale',
57
- type: 'confirm',
58
- message: 'Whether to use i18n?',
59
- default: false,
60
- });
61
- renderData.locale = locale;
62
- // Determine whether the parameter carries a component style
63
- if (options.sfc || options.tsx) {
64
- renderData.style = options.sfc ? 'vue' : 'tsx';
65
- }
66
- else {
67
- const { style } = await prompt({
68
- name: 'style',
69
- type: 'list',
70
- message: 'Which style do you use to write your component ?',
71
- choices: [
72
- { name: 'sfc', value: 'vue' },
73
- { name: 'tsx', value: 'tsx' },
74
- ],
75
- default: 'vue',
76
- });
77
- renderData.style = style;
78
- }
79
- copySync(resolve(dirname, '../../../template/create'), componentFolder);
80
- await renderTemplates(componentFolder, componentFolderName, renderData);
81
- if (!renderData.locale) {
82
- removeSync(resolve(componentFolder, '/example/locale'));
83
- }
84
- if (renderData.style !== 'vue') {
85
- removeSync(resolve(componentFolder, `${renderData.bigCamelizeName}.vue`));
86
- }
87
- if (renderData.style !== 'tsx') {
88
- removeSync(resolve(componentFolder, `${renderData.bigCamelizeName}.tsx`));
89
- }
90
- logger.success(`Create ${componentFolderName} component success!`);
91
- }
1
+ import ejs from 'ejs';
2
+ import fse from 'fs-extra';
3
+ import logger from '../shared/logger.js';
4
+ import { bigCamelize, camelize, kebabCase } from '@varlet/shared';
5
+ import inquirer from 'inquirer';
6
+ import { get } from 'lodash-es';
7
+ import { resolve } from 'path';
8
+ import { glob } from '../shared/fsUtils.js';
9
+ import { getVarletConfig } from '../config/varlet.config.js';
10
+ import { SRC_DIR, dirname } from '../shared/constant.js';
11
+ const { removeSync, readFileSync, copySync, pathExistsSync, writeFileSync } = fse;
12
+ const { prompt } = inquirer;
13
+ async function renderTemplates(componentFolder, componentFolderName, renderData) {
14
+ const templates = await glob(`${componentFolder}/**/*.ejs`);
15
+ templates.forEach((template) => {
16
+ const templateCode = readFileSync(template, { encoding: 'utf-8' });
17
+ const code = ejs.render(templateCode, renderData);
18
+ const file = template
19
+ .replace('[componentName]', camelize(componentFolderName))
20
+ .replace('[ComponentName]', bigCamelize(componentFolderName))
21
+ .replace('.ejs', '');
22
+ writeFileSync(file, code);
23
+ removeSync(template);
24
+ });
25
+ }
26
+ export async function create(options) {
27
+ logger.title('\n📦📦 Create a component ! \n');
28
+ const namespace = get(await getVarletConfig(), 'namespace');
29
+ const renderData = {
30
+ namespace,
31
+ bigCamelizeNamespace: bigCamelize(namespace),
32
+ kebabCaseName: 'component-name',
33
+ bigCamelizeName: 'ComponentName',
34
+ camelizeName: 'componentName',
35
+ style: 'vue',
36
+ };
37
+ const { name } = options.name
38
+ ? options
39
+ : await prompt({
40
+ name: 'name',
41
+ message: 'Name of the component created: ',
42
+ default: renderData.kebabCaseName,
43
+ });
44
+ renderData.kebabCaseName = kebabCase(name);
45
+ renderData.camelizeName = camelize(name);
46
+ renderData.bigCamelizeName = bigCamelize(name);
47
+ const componentFolder = resolve(SRC_DIR, renderData.kebabCaseName);
48
+ const componentFolderName = renderData.kebabCaseName;
49
+ if (pathExistsSync(componentFolder)) {
50
+ logger.warning(`${componentFolderName} already exist and cannot be recreated...`);
51
+ return;
52
+ }
53
+ const { locale } = options.locale
54
+ ? options
55
+ : await prompt({
56
+ name: 'locale',
57
+ type: 'confirm',
58
+ message: 'Whether to use i18n?',
59
+ default: false,
60
+ });
61
+ renderData.locale = locale;
62
+ // Determine whether the parameter carries a component style
63
+ if (options.sfc || options.tsx) {
64
+ renderData.style = options.sfc ? 'vue' : 'tsx';
65
+ }
66
+ else {
67
+ const { style } = await prompt({
68
+ name: 'style',
69
+ type: 'list',
70
+ message: 'Which style do you use to write your component ?',
71
+ choices: [
72
+ { name: 'sfc', value: 'vue' },
73
+ { name: 'tsx', value: 'tsx' },
74
+ ],
75
+ default: 'vue',
76
+ });
77
+ renderData.style = style;
78
+ }
79
+ copySync(resolve(dirname, '../../../template/create'), componentFolder);
80
+ await renderTemplates(componentFolder, componentFolderName, renderData);
81
+ if (!renderData.locale) {
82
+ removeSync(resolve(componentFolder, '/example/locale'));
83
+ }
84
+ if (renderData.style !== 'vue') {
85
+ removeSync(resolve(componentFolder, `${renderData.bigCamelizeName}.vue`));
86
+ }
87
+ if (renderData.style !== 'tsx') {
88
+ removeSync(resolve(componentFolder, `${renderData.bigCamelizeName}.tsx`));
89
+ }
90
+ logger.success(`Create ${componentFolderName} component success!`);
91
+ }
@@ -1,6 +1,6 @@
1
- interface DevCommandOptions {
2
- force?: boolean;
3
- draft?: boolean;
4
- }
5
- export declare function dev(options: DevCommandOptions): Promise<void>;
6
- export {};
1
+ interface DevCommandOptions {
2
+ force?: boolean;
3
+ draft?: boolean;
4
+ }
5
+ export declare function dev(options: DevCommandOptions): Promise<void>;
6
+ export {};
@@ -1,42 +1,42 @@
1
- import chokidar from 'chokidar';
2
- import fse from 'fs-extra';
3
- import logger from '../shared/logger.js';
4
- import { createServer } from 'vite';
5
- import { SRC_DIR, VARLET_CONFIG } from '../shared/constant.js';
6
- import { buildSiteEntry } from '../compiler/compileSiteEntry.js';
7
- import { getDevConfig } from '../config/vite.config.js';
8
- import { getVarletConfig } from '../config/varlet.config.js';
9
- import { merge } from 'lodash-es';
10
- const { ensureDirSync, pathExistsSync } = fse;
11
- let server;
12
- let watcher;
13
- async function startServer(options) {
14
- var _a;
15
- const isRestart = Boolean(server);
16
- logger.info(`${isRestart ? 'Res' : 'S'}tarting server...`);
17
- // close all instance
18
- server && (await server.close());
19
- watcher && (await watcher.close());
20
- // build all config
21
- await buildSiteEntry((_a = options.draft) !== null && _a !== void 0 ? _a : false);
22
- const varletConfig = await getVarletConfig();
23
- const devConfig = getDevConfig(varletConfig);
24
- const inlineConfig = merge(devConfig, options.force ? { optimizeDeps: { force: true } } : {});
25
- // create all instance
26
- server = await createServer(inlineConfig);
27
- await server.listen();
28
- server.printUrls();
29
- if (pathExistsSync(VARLET_CONFIG)) {
30
- watcher = chokidar.watch(VARLET_CONFIG);
31
- watcher.on('change', () => startServer(options));
32
- }
33
- logger.success(`\n${isRestart ? 'Res' : 'S'}tart successfully!!!`);
34
- if (options.draft) {
35
- logger.title('Server in draft mode!!!');
36
- }
37
- }
38
- export async function dev(options) {
39
- process.env.NODE_ENV = 'development';
40
- ensureDirSync(SRC_DIR);
41
- await startServer(options);
42
- }
1
+ import chokidar from 'chokidar';
2
+ import fse from 'fs-extra';
3
+ import logger from '../shared/logger.js';
4
+ import { createServer } from 'vite';
5
+ import { SRC_DIR, VARLET_CONFIG } from '../shared/constant.js';
6
+ import { buildSiteEntry } from '../compiler/compileSiteEntry.js';
7
+ import { getDevConfig } from '../config/vite.config.js';
8
+ import { getVarletConfig } from '../config/varlet.config.js';
9
+ import { merge } from 'lodash-es';
10
+ const { ensureDirSync, pathExistsSync } = fse;
11
+ let server;
12
+ let watcher;
13
+ async function startServer(options) {
14
+ var _a;
15
+ const isRestart = Boolean(server);
16
+ logger.info(`${isRestart ? 'Res' : 'S'}tarting server...`);
17
+ // close all instance
18
+ server && (await server.close());
19
+ watcher && (await watcher.close());
20
+ // build all config
21
+ await buildSiteEntry((_a = options.draft) !== null && _a !== void 0 ? _a : false);
22
+ const varletConfig = await getVarletConfig();
23
+ const devConfig = getDevConfig(varletConfig);
24
+ const inlineConfig = merge(devConfig, options.force ? { optimizeDeps: { force: true } } : {});
25
+ // create all instance
26
+ server = await createServer(inlineConfig);
27
+ await server.listen();
28
+ server.printUrls();
29
+ if (pathExistsSync(VARLET_CONFIG)) {
30
+ watcher = chokidar.watch(VARLET_CONFIG);
31
+ watcher.on('change', () => startServer(options));
32
+ }
33
+ logger.success(`\n${isRestart ? 'Res' : 'S'}tart successfully!!!`);
34
+ if (options.draft) {
35
+ logger.title('Server in draft mode!!!');
36
+ }
37
+ }
38
+ export async function dev(options) {
39
+ process.env.NODE_ENV = 'development';
40
+ ensureDirSync(SRC_DIR);
41
+ await startServer(options);
42
+ }
@@ -1,3 +1,3 @@
1
- import { type ExtensionMode } from '../config/vite.config.js';
2
- export declare type ExtensionCommandMode = ExtensionMode;
3
- export declare function extension(mode: ExtensionCommandMode): Promise<void>;
1
+ import { type ExtensionMode } from '../config/vite.config.js';
2
+ export declare type ExtensionCommandMode = ExtensionMode;
3
+ export declare function extension(mode: ExtensionCommandMode): Promise<void>;
@@ -1,5 +1,5 @@
1
- import { build } from 'vite';
2
- import { getExtensionConfig } from '../config/vite.config.js';
3
- export async function extension(mode) {
4
- await build(getExtensionConfig(mode));
5
- }
1
+ import { build } from 'vite';
2
+ import { getExtensionConfig } from '../config/vite.config.js';
3
+ export async function extension(mode) {
4
+ await build(getExtensionConfig(mode));
5
+ }
@@ -1,7 +1,7 @@
1
- export interface GenCommandOptions {
2
- name?: string;
3
- i18n?: boolean;
4
- sfc?: boolean;
5
- tsx?: boolean;
6
- }
7
- export declare function gen(options: GenCommandOptions): Promise<void>;
1
+ export interface GenCommandOptions {
2
+ name?: string;
3
+ i18n?: boolean;
4
+ sfc?: boolean;
5
+ tsx?: boolean;
6
+ }
7
+ export declare function gen(options: GenCommandOptions): Promise<void>;