feima-shortcuts 0.2.0 → 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 +15 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "feima-shortcuts",
|
|
3
|
-
"version": "0.2.
|
|
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);
|
|
@@ -106,11 +107,12 @@ const emit = defineEmits<Emits>();
|
|
|
106
107
|
/**
|
|
107
108
|
* 生成index.ts模板
|
|
108
109
|
*/
|
|
109
|
-
function generateIndexTemplate(componentName) {
|
|
110
|
+
function generateIndexTemplate(componentName, options = {}) {
|
|
111
|
+
const vueEntry = 'index';
|
|
110
112
|
return `import type { App } from "vue";
|
|
111
|
-
import ${componentName}
|
|
113
|
+
import ${componentName}Base from "./src/${vueEntry}.vue";
|
|
112
114
|
|
|
113
|
-
export const ${componentName} = ${componentName}
|
|
115
|
+
export const ${componentName} = ${componentName}Base;
|
|
114
116
|
|
|
115
117
|
export default {
|
|
116
118
|
install(app: App) {
|
|
@@ -123,10 +125,11 @@ export default {
|
|
|
123
125
|
/**
|
|
124
126
|
* 生成测试文件模板
|
|
125
127
|
*/
|
|
126
|
-
function generateTestTemplate(componentName) {
|
|
128
|
+
function generateTestTemplate(componentName, options = {}) {
|
|
129
|
+
const vueEntry = 'index';
|
|
127
130
|
return `import { describe, it, expect } from 'vitest';
|
|
128
131
|
import { mount } from '@vue/test-utils';
|
|
129
|
-
import ${componentName} from '../src/${
|
|
132
|
+
import ${componentName} from '../src/${vueEntry}.vue';
|
|
130
133
|
|
|
131
134
|
describe('${componentName}', () => {
|
|
132
135
|
it('renders properly', () => {
|
|
@@ -140,7 +143,7 @@ describe('${componentName}', () => {
|
|
|
140
143
|
/**
|
|
141
144
|
* 更新主入口文件
|
|
142
145
|
*/
|
|
143
|
-
function updateMainIndex(componentName) {
|
|
146
|
+
function updateMainIndex(componentName, options = {}) {
|
|
144
147
|
const indexPath = path.resolve(process.cwd(), 'src/index.ts');
|
|
145
148
|
|
|
146
149
|
if (!fs.existsSync(indexPath)) {
|
|
@@ -154,7 +157,8 @@ function updateMainIndex(componentName) {
|
|
|
154
157
|
const nameWithoutF = componentName.replace(/^F/, '');
|
|
155
158
|
const kebabName = nameWithoutF.replace(/([A-Z])/g, '-$1').toLowerCase().replace(/^-/, '');
|
|
156
159
|
const folderName = `f-${kebabName}`;
|
|
157
|
-
const
|
|
160
|
+
const importPath = `../packages/${kebabName}`;
|
|
161
|
+
const importLine = `import ${componentName}Installer, { ${componentName} } from "${importPath}";`;
|
|
158
162
|
|
|
159
163
|
// 查找现有的导入语句位置,保持原有格式
|
|
160
164
|
const importMatch = content.match(/(import.*from "\.\/.*";\s*)+/);
|