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