hyfcli 1.0.0 → 1.0.2
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.
Potentially problematic release.
This version of hyfcli might be problematic. Click here for more details.
- package/bin/index.js +7 -2
- package/bin/index.js.map +1 -1
- package/bin/index.mjs +7 -2
- package/bin/index.mjs.map +1 -1
- package/bin/modules/request/config.ts +21 -0
- package/bin/modules/request/index.ts +113 -0
- package/bin/modules/request/status.ts +22 -0
- package/bin/modules/request/types.ts +7 -0
- package/bin/modules/router/index.ts +29 -0
- package/bin/modules/router/modules/404.ts +9 -0
- package/bin/modules/router/modules/about.ts +9 -0
- package/bin/modules/router/modules/home.ts +10 -0
- package/bin/modules/router/modules/login.ts +10 -0
- package/bin/modules/router/modules/redirect.ts +4 -0
- package/bin/modules/store/home/index.ts +22 -0
- package/bin/modules/store/home/types.ts +0 -0
- package/bin/modules/store/index.ts +5 -0
- package/bin/template/component.tsx.ejs +10 -0
- package/bin/template/component.vue.ejs +9 -0
- package/bin/template/router.ejs +8 -0
- package/bin/template/store.ejs +22 -0
- package/lib/config/repo.js +8 -0
- package/lib/core/actions.js +166 -0
- package/lib/core/create-project.js +125 -0
- package/lib/core/help-options.js +8 -0
- package/lib/core/print-welcome.js +19 -0
- package/lib/index.js +55 -0
- package/lib/modules/request/config.ts +21 -0
- package/lib/modules/request/index.ts +113 -0
- package/lib/modules/request/status.ts +22 -0
- package/lib/modules/request/types.ts +7 -0
- package/lib/modules/router/index.ts +29 -0
- package/lib/modules/router/modules/404.ts +9 -0
- package/lib/modules/router/modules/about.ts +9 -0
- package/lib/modules/router/modules/home.ts +10 -0
- package/lib/modules/router/modules/login.ts +10 -0
- package/lib/modules/router/modules/redirect.ts +4 -0
- package/lib/modules/store/home/index.ts +22 -0
- package/lib/modules/store/home/types.ts +0 -0
- package/lib/modules/store/index.ts +5 -0
- package/lib/template/component.tsx.ejs +10 -0
- package/lib/template/component.vue.ejs +9 -0
- package/lib/template/router.ejs +8 -0
- package/lib/template/store.ejs +22 -0
- package/lib/utils/checkDirExist.js +13 -0
- package/lib/utils/ejs-render.js +21 -0
- package/lib/utils/exec-command.js +13 -0
- package/lib/utils/print-log.js +15 -0
- package/lib/utils/text-position.js +50 -0
- package/lib/utils/writeFile.js +15 -0
- package/package.json +4 -2
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { defineStore } from 'pinia';
|
|
2
|
+
const useHomeStore = defineStore('home', {
|
|
3
|
+
// state: ():自定义类型 => ({}) 例如: state: (): IHomeState => ({})
|
|
4
|
+
state: () => ({
|
|
5
|
+
username: 'admin',
|
|
6
|
+
accessToken: '',
|
|
7
|
+
roles: []
|
|
8
|
+
}),
|
|
9
|
+
getters: {},
|
|
10
|
+
|
|
11
|
+
actions: {}
|
|
12
|
+
// 开启持久化存储
|
|
13
|
+
// persist: {
|
|
14
|
+
// key: "home", // 存储的key
|
|
15
|
+
// storage: sessionStorage, // 默认是localStorage
|
|
16
|
+
// // 默认情况下,Pinia 会将整个 state 保存到持久化存储中。
|
|
17
|
+
// // pick:[], 挑选出需要存储的state
|
|
18
|
+
// // omit: [], 排除不需要存储的state
|
|
19
|
+
// },
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export default useHomeStore;
|
|
File without changes
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { defineStore } from 'pinia';
|
|
2
|
+
const use<%=name%>Store = defineStore('<%=name.toLowerCase()%>', {
|
|
3
|
+
// state: ():自定义类型 => ({}) 例如: state: (): IHomeState => ({})
|
|
4
|
+
state: () => ({
|
|
5
|
+
username: 'admin',
|
|
6
|
+
accessToken: '',
|
|
7
|
+
roles: []
|
|
8
|
+
}),
|
|
9
|
+
getters: {},
|
|
10
|
+
|
|
11
|
+
actions: {}
|
|
12
|
+
// 开启持久化存储
|
|
13
|
+
// persist: {
|
|
14
|
+
// key: "home", // 存储的key
|
|
15
|
+
// storage: sessionStorage, // 默认是localStorage
|
|
16
|
+
// // 默认情况下,Pinia 会将整个 state 保存到持久化存储中。
|
|
17
|
+
// // pick:[], 挑选出需要存储的state
|
|
18
|
+
// // omit: [], 排除不需要存储的state
|
|
19
|
+
// },
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export default use<%=name%>Store;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
|
|
3
|
+
module.exports = function checkDirExist(dirName) {
|
|
4
|
+
return new Promise((resolve, reject) => {
|
|
5
|
+
fs.access(dirName, fs.constants.F_OK, (err) => {
|
|
6
|
+
if (err) {
|
|
7
|
+
resolve(false);
|
|
8
|
+
} else {
|
|
9
|
+
resolve(true);
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const ejs = require("ejs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
function renderEjs(template, data) {
|
|
4
|
+
return new Promise((resolve, reject) => {
|
|
5
|
+
const templatePath = `../template/${template}`;
|
|
6
|
+
console.log(template);
|
|
7
|
+
const absolutePath = path.resolve(__dirname, templatePath);
|
|
8
|
+
|
|
9
|
+
ejs.renderFile(absolutePath, data, (err, str) => {
|
|
10
|
+
if (err) {
|
|
11
|
+
reject(err);
|
|
12
|
+
} else {
|
|
13
|
+
resolve(str);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = {
|
|
20
|
+
renderEjs,
|
|
21
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const { spawn } = require("child_process");
|
|
2
|
+
const checkDirExist = require("./checkDirExist");
|
|
3
|
+
module.exports = async function execCommand(...args) {
|
|
4
|
+
return new Promise((resolve, reject) => {
|
|
5
|
+
const childProcess = spawn(...args); // 启用 shell });
|
|
6
|
+
childProcess.stdout.pipe(process.stdout);
|
|
7
|
+
childProcess.stderr.pipe(process.stderr);
|
|
8
|
+
childProcess.on("close", (code) => {
|
|
9
|
+
console.log("code::", code);
|
|
10
|
+
resolve();
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const chalk = require("chalk");
|
|
2
|
+
function printLogForInstall(projectName) {
|
|
3
|
+
console.log(chalk.yellow(`--`.repeat(30)));
|
|
4
|
+
console.log("");
|
|
5
|
+
console.log(chalk.green(` cd ${projectName}`));
|
|
6
|
+
console.log(chalk.green(` pnpm install`));
|
|
7
|
+
console.log(chalk.green(` pnpm run dev`));
|
|
8
|
+
console.log("");
|
|
9
|
+
console.log(chalk.yellow(`--`.repeat(30)));
|
|
10
|
+
process.exit(0);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = {
|
|
14
|
+
printLogForInstall,
|
|
15
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文本居中
|
|
3
|
+
* @type {string} text
|
|
4
|
+
* @param {number} width
|
|
5
|
+
* @return {string}
|
|
6
|
+
*/
|
|
7
|
+
function centerLine(text, width = process.stdout.columns || 80) {
|
|
8
|
+
const pad = Math.max(0, Math.floor((width - text.length) / 2));
|
|
9
|
+
|
|
10
|
+
return " ".repeat(pad) + text;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Figlet 文本居中
|
|
15
|
+
* @type {string} figletText
|
|
16
|
+
* @param {number} width
|
|
17
|
+
* @return {string}
|
|
18
|
+
*/
|
|
19
|
+
function centerFiglet(figletText, width = process.stdout.columns || 80) {
|
|
20
|
+
const lines = figletText.split("\n");
|
|
21
|
+
return lines
|
|
22
|
+
.map((line) => {
|
|
23
|
+
const trimmed = line.trimEnd(); // 保留左侧空白,去除右侧多余空格
|
|
24
|
+
const pad = Math.max(0, Math.floor((width - trimmed.length) / 2));
|
|
25
|
+
return " ".repeat(pad) + trimmed;
|
|
26
|
+
})
|
|
27
|
+
.join("\n");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 自定义文本位置
|
|
32
|
+
* @param {string} figletText Figlet 文本
|
|
33
|
+
* @param {number} pad 左侧空白
|
|
34
|
+
* @returns {string}
|
|
35
|
+
*
|
|
36
|
+
*/
|
|
37
|
+
function positionFiglet(figletText, pad = 10) {
|
|
38
|
+
const lines = figletText.split("\n");
|
|
39
|
+
return lines
|
|
40
|
+
.map((line) => {
|
|
41
|
+
const trimmed = line.trimEnd(); // 保留左侧空白,去除右侧多余空格
|
|
42
|
+
return " ".repeat(pad) + trimmed;
|
|
43
|
+
})
|
|
44
|
+
.join("\n");
|
|
45
|
+
}
|
|
46
|
+
module.exports = {
|
|
47
|
+
centerLine,
|
|
48
|
+
centerFiglet,
|
|
49
|
+
positionFiglet,
|
|
50
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const fs = require("node:fs/promises");
|
|
2
|
+
|
|
3
|
+
async function writeFile(filePath, data) {
|
|
4
|
+
try {
|
|
5
|
+
await fs.writeFile(filePath, data, {
|
|
6
|
+
encoding: "utf-8",
|
|
7
|
+
});
|
|
8
|
+
} catch (error) {
|
|
9
|
+
console.log("创建文件失败:", error);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = {
|
|
14
|
+
writeFile,
|
|
15
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hyfcli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "一个项目开发脚手架工具",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"template"
|
|
18
18
|
],
|
|
19
19
|
"files": [
|
|
20
|
-
"./bin"
|
|
20
|
+
"./bin",
|
|
21
|
+
"./lib"
|
|
21
22
|
],
|
|
22
23
|
"author": "hyf",
|
|
23
24
|
"license": "ISC",
|
|
@@ -33,6 +34,7 @@
|
|
|
33
34
|
"ora": "^4.1.1"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
37
|
+
"shx": "^0.4.0",
|
|
36
38
|
"tsup": "^8.5.1",
|
|
37
39
|
"typescript": "^6.0.3"
|
|
38
40
|
}
|