sunq-cli 0.0.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/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # sunq-cli
2
+
3
+ ![npm 版本](https://img.shields.io/badge/sunq-cli_v0.0.1-green)
4
+
5
+ ## 简介
6
+
7
+ - 快速搭建前端项目的命令行工具
8
+
9
+ ## 安装
10
+
11
+ ```bash
12
+ npm install sunq-cli -g
13
+ ```
14
+
15
+ ## 使用
16
+
17
+ ```bash
18
+ # 使用模板创建新项目
19
+ sq create
20
+
21
+ # 执行项目文件夹并选择模板创建新项目
22
+ sq create [projectName]
23
+ ```
package/bin/index.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ require("../dist/index.cjs"); // 执行打包好的dist/index.cjs文件
package/dist/index.cjs ADDED
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+
3
+ var commander = require("commander");
4
+ var prompts = require("@inquirer/prompts");
5
+ var simpleGit = require("simple-git");
6
+ var createLogger = require("progress-estimator");
7
+ var chalk = require("chalk");
8
+ var path = require("node:path");
9
+ var fs = require("fs-extra");
10
+
11
+ var version = "0.0.1";
12
+
13
+ const logger = createLogger({
14
+ spinner: {
15
+ interval: 80,
16
+ frames: [
17
+ "\u280B",
18
+ "\u2819",
19
+ "\u2839",
20
+ "\u2838",
21
+ "\u283C",
22
+ "\u2834",
23
+ "\u2826",
24
+ "\u2827",
25
+ "\u2807",
26
+ "\u280F",
27
+ ].map((i) => {
28
+ return chalk.green(i);
29
+ }),
30
+ },
31
+ });
32
+ const options = {
33
+ baseDir: process.cwd(),
34
+ binary: "git",
35
+ maxConcurrentProcesses: 6,
36
+ };
37
+ const clone = async (url, projectName, actions) => {
38
+ const git = simpleGit.simpleGit(options);
39
+ try {
40
+ await logger(
41
+ git.clone(url, projectName, actions),
42
+ "\u4EE3\u7801\u4E0B\u8F7D\u4E2D...",
43
+ {
44
+ estimate: 7e3,
45
+ // 预计展示下载的时长
46
+ },
47
+ );
48
+ console.log(chalk.green("\u4EE3\u7801\u4E0B\u8F7D\u6210\u529F"));
49
+ console.log(chalk.blackBright("==========================="));
50
+ console.log(
51
+ chalk.blackBright(
52
+ "====\u6B22\u8FCE\u4F7F\u7528sunq-cli\u811A\u624B\u67B6====",
53
+ ),
54
+ );
55
+ console.log(chalk.blackBright("==========================="));
56
+ console.log();
57
+ console.log();
58
+ console.log(
59
+ chalk.blackBright(
60
+ "====\u8BF7\u4F7F\u7528pnpm install \u5B89\u88C5\u4F9D\u8D56====",
61
+ ),
62
+ );
63
+ console.log(
64
+ chalk.blackBright("====pnpm run dev \u8FD0\u884C\u9879\u76EE===="),
65
+ );
66
+ } catch (error) {
67
+ console.error(chalk.red("\u4E0B\u8F7D\u4EE3\u7801\u5931\u8D25"));
68
+ }
69
+ };
70
+
71
+ const templates = /* @__PURE__ */ new Map([
72
+ [
73
+ "vue-ts-admin",
74
+ {
75
+ name: "vue-ts-admin",
76
+ downloadUrl: "https://github.com/sunqinginging/sq-vue-admin.git",
77
+ description: "vue3\u540E\u53F0\u7BA1\u7406\u7CFB\u7EDF\u6A21\u677F",
78
+ branch: "main",
79
+ },
80
+ ],
81
+ ]);
82
+ function isOverWrite(filename) {
83
+ console.warn(`${filename}\u6587\u4EF6\u5939\u5DF2\u5B58\u5728`);
84
+ return prompts.select({
85
+ message: "\u662F\u5426\u8986\u76D6\uFF1F",
86
+ choices: [
87
+ {
88
+ name: "\u8986\u76D6",
89
+ value: true,
90
+ },
91
+ {
92
+ name: "\u53D6\u6D88",
93
+ value: false,
94
+ },
95
+ ],
96
+ });
97
+ }
98
+ async function create(projectName) {
99
+ const templateList = Array.from(templates).map((item) => {
100
+ const [name, info] = item;
101
+ return {
102
+ name,
103
+ value: info,
104
+ description: info.description,
105
+ };
106
+ });
107
+ if (!projectName) {
108
+ projectName = await prompts.input({
109
+ message: "\u8BF7\u8F93\u5165\u9879\u76EE\u540D\u79F0",
110
+ });
111
+ }
112
+ const filePath = path.resolve(process.cwd(), projectName);
113
+ if (fs.existsSync(filePath)) {
114
+ const run = await isOverWrite(filePath);
115
+ if (run) {
116
+ await fs.remove(filePath);
117
+ } else {
118
+ return;
119
+ }
120
+ }
121
+ const templateSelectItem = await prompts.select({
122
+ message: "\u8BF7\u9009\u62E9\u6A21\u677F",
123
+ choices: templateList,
124
+ });
125
+ if (templateSelectItem) {
126
+ clone(templateSelectItem.downloadUrl, projectName, [
127
+ "-b",
128
+ templateSelectItem.branch,
129
+ ]);
130
+ }
131
+ console.log(templateSelectItem);
132
+ }
133
+
134
+ const program = new commander.Command("sq");
135
+ program.version(version, "-v,--version");
136
+ program
137
+ .command("create")
138
+ .description("\u521B\u5EFA\u4E00\u4E2A\u65B0\u9879\u76EE")
139
+ .argument("[name]", "\u9879\u76EE\u540D\u79F0")
140
+ .action(async (dirname) => {
141
+ console.log(dirname);
142
+ create(dirname);
143
+ });
144
+ program.parse();