feima-shortcuts 0.1.5-beta.2 → 0.2.1
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/package.json +2 -2
- package/src/scripts/generate/index.js +16 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "feima-shortcuts",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "快捷指令",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"directories": {
|
|
@@ -23,4 +23,4 @@
|
|
|
23
23
|
"uuid": "^9.0.0"
|
|
24
24
|
},
|
|
25
25
|
"packageManager": "pnpm@10.6.3+sha512.bb45e34d50a9a76e858a95837301bfb6bd6d35aea2c5d52094fa497a467c43f5c440103ce2511e9e0a2f89c3d6071baac3358fc68ac6fb75e2ceb3d2736065e6"
|
|
26
|
-
}
|
|
26
|
+
}
|
|
@@ -7,7 +7,8 @@ const docsGenerator = require('./docs');
|
|
|
7
7
|
* @param {Object} answers - 用户输入的答案
|
|
8
8
|
*/
|
|
9
9
|
function generateComponent(answers) {
|
|
10
|
-
|
|
10
|
+
const rawName = answers['component-name'];
|
|
11
|
+
let componentName = rawName;
|
|
11
12
|
|
|
12
13
|
// 确保组件名以F开头且首字母大写
|
|
13
14
|
if (!componentName.startsWith('F')) {
|
|
@@ -17,10 +18,10 @@ function generateComponent(answers) {
|
|
|
17
18
|
// 移除开头的F,然后转换为kebab-case
|
|
18
19
|
const nameWithoutF = componentName.replace(/^F/, '');
|
|
19
20
|
const kebabName = nameWithoutF.replace(/([A-Z])/g, '-$1').toLowerCase().replace(/^-/, '');
|
|
20
|
-
const folderName = `
|
|
21
|
+
const folderName = `packages/${kebabName}`;
|
|
21
22
|
|
|
22
23
|
// 创建组件目录结构
|
|
23
|
-
const componentDir = path.resolve(process.cwd(),
|
|
24
|
+
const componentDir = path.resolve(process.cwd(), folderName);
|
|
24
25
|
const srcDir = path.join(componentDir, 'src');
|
|
25
26
|
const testsDir = path.join(componentDir, '__tests__');
|
|
26
27
|
|
|
@@ -37,7 +38,7 @@ function generateComponent(answers) {
|
|
|
37
38
|
|
|
38
39
|
// 生成Vue组件文件
|
|
39
40
|
const vueTemplate = generateVueTemplate(componentName);
|
|
40
|
-
fs.writeFileSync(path.join(srcDir,
|
|
41
|
+
fs.writeFileSync(path.join(srcDir, `index.vue`), vueTemplate);
|
|
41
42
|
|
|
42
43
|
// 生成index.ts文件
|
|
43
44
|
const indexTemplate = generateIndexTemplate(componentName);
|
|
@@ -71,8 +72,7 @@ function generateComponent(answers) {
|
|
|
71
72
|
function generateVueTemplate(componentName) {
|
|
72
73
|
return `<template>
|
|
73
74
|
<div class="feima-${componentName.toLowerCase()}">
|
|
74
|
-
|
|
75
|
-
<slot></slot>
|
|
75
|
+
${componentName} 组件内容
|
|
76
76
|
</div>
|
|
77
77
|
</template>
|
|
78
78
|
|
|
@@ -107,11 +107,12 @@ const emit = defineEmits<Emits>();
|
|
|
107
107
|
/**
|
|
108
108
|
* 生成index.ts模板
|
|
109
109
|
*/
|
|
110
|
-
function generateIndexTemplate(componentName) {
|
|
110
|
+
function generateIndexTemplate(componentName, options = {}) {
|
|
111
|
+
const vueEntry = 'index';
|
|
111
112
|
return `import type { App } from "vue";
|
|
112
|
-
import ${componentName}
|
|
113
|
+
import ${componentName}Base from "./src/${vueEntry}.vue";
|
|
113
114
|
|
|
114
|
-
export const ${componentName} = ${componentName}
|
|
115
|
+
export const ${componentName} = ${componentName}Base;
|
|
115
116
|
|
|
116
117
|
export default {
|
|
117
118
|
install(app: App) {
|
|
@@ -124,10 +125,11 @@ export default {
|
|
|
124
125
|
/**
|
|
125
126
|
* 生成测试文件模板
|
|
126
127
|
*/
|
|
127
|
-
function generateTestTemplate(componentName) {
|
|
128
|
+
function generateTestTemplate(componentName, options = {}) {
|
|
129
|
+
const vueEntry = 'index';
|
|
128
130
|
return `import { describe, it, expect } from 'vitest';
|
|
129
131
|
import { mount } from '@vue/test-utils';
|
|
130
|
-
import ${componentName} from '../src/${
|
|
132
|
+
import ${componentName} from '../src/${vueEntry}.vue';
|
|
131
133
|
|
|
132
134
|
describe('${componentName}', () => {
|
|
133
135
|
it('renders properly', () => {
|
|
@@ -141,7 +143,7 @@ describe('${componentName}', () => {
|
|
|
141
143
|
/**
|
|
142
144
|
* 更新主入口文件
|
|
143
145
|
*/
|
|
144
|
-
function updateMainIndex(componentName) {
|
|
146
|
+
function updateMainIndex(componentName, options = {}) {
|
|
145
147
|
const indexPath = path.resolve(process.cwd(), 'src/index.ts');
|
|
146
148
|
|
|
147
149
|
if (!fs.existsSync(indexPath)) {
|
|
@@ -155,7 +157,8 @@ function updateMainIndex(componentName) {
|
|
|
155
157
|
const nameWithoutF = componentName.replace(/^F/, '');
|
|
156
158
|
const kebabName = nameWithoutF.replace(/([A-Z])/g, '-$1').toLowerCase().replace(/^-/, '');
|
|
157
159
|
const folderName = `f-${kebabName}`;
|
|
158
|
-
const
|
|
160
|
+
const importPath = `../packages/${kebabName}`;
|
|
161
|
+
const importLine = `import ${componentName}Installer, { ${componentName} } from "${importPath}";`;
|
|
159
162
|
|
|
160
163
|
// 查找现有的导入语句位置,保持原有格式
|
|
161
164
|
const importMatch = content.match(/(import.*from "\.\/.*";\s*)+/);
|