create-pubinfo 2.0.0-beta.8 → 2.0.0-rc.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/dist/index.js +352 -306
- package/package.json +13 -13
- package/templates/pubinfo-template/.browserslistrc +5 -0
- package/templates/pubinfo-template/.editorconfig +10 -0
- package/templates/pubinfo-template/.env +5 -0
- package/templates/pubinfo-template/.env.development +6 -0
- package/templates/pubinfo-template/.env.production +10 -0
- package/templates/pubinfo-template/_gitignore +37 -0
- package/templates/pubinfo-template/_npmrc +5 -0
- package/templates/pubinfo-template/commitlint.config.js +66 -0
- package/templates/pubinfo-template/eslint.config.ts +3 -0
- package/templates/pubinfo-template/index.html +47 -0
- package/templates/pubinfo-template/openapi.config.ts +33 -0
- package/templates/pubinfo-template/package.json +53 -0
- package/templates/pubinfo-template/pubinfo.config.ts +9 -0
- package/templates/pubinfo-template/public/browser_upgrade/chrome.png +0 -0
- package/templates/pubinfo-template/public/browser_upgrade/edge.png +0 -0
- package/templates/pubinfo-template/public/browser_upgrade/index.css +49 -0
- package/templates/pubinfo-template/public/loading.css +92 -0
- package/templates/pubinfo-template/src/App.vue +7 -0
- package/templates/pubinfo-template/src/api/modules/auth/index.ts +3 -0
- package/templates/pubinfo-template/src/api/modules/auth/renzhengfuwu.ts +145 -0
- package/templates/pubinfo-template/src/api/modules/auth/typings.d.ts +97 -0
- package/templates/pubinfo-template/src/api/request.ts +125 -0
- package/templates/pubinfo-template/src/assets/icons/logo.svg +1 -0
- package/templates/pubinfo-template/src/assets/icons/process-management.svg +1 -0
- package/templates/pubinfo-template/src/assets/icons/workbench.svg +1 -0
- package/templates/pubinfo-template/src/assets/images/login-bg.webp +0 -0
- package/templates/pubinfo-template/src/assets/images/login-bg_dark.webp +0 -0
- package/templates/pubinfo-template/src/assets/images/login-small.png +0 -0
- package/templates/pubinfo-template/src/assets/images/login-small_dark.webp +0 -0
- package/templates/pubinfo-template/src/components/UIProvider/index.vue +51 -0
- package/templates/pubinfo-template/src/layouts/index.vue +38 -0
- package/templates/pubinfo-template/src/main.ts +22 -0
- package/templates/pubinfo-template/src/modules/auth.ts +20 -0
- package/templates/pubinfo-template/src/modules/rbac.ts +11 -0
- package/templates/pubinfo-template/src/routes/index.ts +71 -0
- package/templates/pubinfo-template/src/routes/modules/demo/breadcrumb.example.ts +62 -0
- package/templates/pubinfo-template/src/routes/modules/demo/link.ts +15 -0
- package/templates/pubinfo-template/src/routes/modules/demo/multilevel.menu.example.ts +68 -0
- package/templates/pubinfo-template/src/routes/modules/demo/other.page.ts +37 -0
- package/templates/pubinfo-template/src/routes/modules/demo/single.ts +14 -0
- package/templates/pubinfo-template/src/settings.ts +8 -0
- package/templates/pubinfo-template/src/stores/index.ts +2 -0
- package/templates/pubinfo-template/src/stores/modules/conter.ts +16 -0
- package/templates/pubinfo-template/src/views/demo/breadcrumb_example/detail1.vue +11 -0
- package/templates/pubinfo-template/src/views/demo/breadcrumb_example/detail2.vue +11 -0
- package/templates/pubinfo-template/src/views/demo/breadcrumb_example/list1.vue +11 -0
- package/templates/pubinfo-template/src/views/demo/breadcrumb_example/list2.vue +11 -0
- package/templates/pubinfo-template/src/views/demo/multilevel_menu_example/level2/level3/page1.vue +11 -0
- package/templates/pubinfo-template/src/views/demo/multilevel_menu_example/level2/level3/page2.vue +11 -0
- package/templates/pubinfo-template/src/views/demo/multilevel_menu_example/level2/page.vue +11 -0
- package/templates/pubinfo-template/src/views/demo/multilevel_menu_example/page.vue +11 -0
- package/templates/pubinfo-template/src/views/demo/other_page/des.vue +13 -0
- package/templates/pubinfo-template/src/views/demo/other_page/index.vue +25 -0
- package/templates/pubinfo-template/src/views/demo/preview-empty/index.vue +17 -0
- package/templates/pubinfo-template/src/views/demo/single/index.vue +13 -0
- package/templates/pubinfo-template/src/views/system/index.vue +5 -0
- package/templates/pubinfo-template/src/views/system/login/components/LoginForm.vue +29 -0
- package/templates/pubinfo-template/src/views/system/login/components/LoginWithPhone.vue +213 -0
- package/templates/pubinfo-template/src/views/system/login/components/PasswordLogin.vue +194 -0
- package/templates/pubinfo-template/src/views/system/login/components/Savephone.vue +17 -0
- package/templates/pubinfo-template/src/views/system/login/components/Useragreement.vue +26 -0
- package/templates/pubinfo-template/src/views/system/login/composables.ts +84 -0
- package/templates/pubinfo-template/src/views/system/login/index.vue +147 -0
- package/templates/pubinfo-template/stylelint.config.js +3 -0
- package/templates/pubinfo-template/tsconfig.json +3 -0
- package/templates/pubinfo-template/uno.config.ts +17 -0
- package/dist/index.cjs +0 -364
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { Component, MaybeRef } from 'vue';
|
|
2
|
+
import { getAuthLoginValidCode } from '@/api/modules/auth';
|
|
3
|
+
import { useActiveElement } from '@vueuse/core';
|
|
4
|
+
import { useRequest } from 'alova/client';
|
|
5
|
+
|
|
6
|
+
interface LoginTabs {
|
|
7
|
+
title: string
|
|
8
|
+
component: Component
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function useLoginTabs() {
|
|
12
|
+
const tabs: LoginTabs[] = [
|
|
13
|
+
{
|
|
14
|
+
title: '账号登录',
|
|
15
|
+
component: defineAsyncComponent(() => import('./components/PasswordLogin.vue')),
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
title: '手机号登录',
|
|
19
|
+
component: defineAsyncComponent(() => import('./components/LoginWithPhone.vue')),
|
|
20
|
+
},
|
|
21
|
+
];
|
|
22
|
+
const initialTab = ref(0);
|
|
23
|
+
|
|
24
|
+
function changeActiveTab(activeTab: number): void {
|
|
25
|
+
initialTab.value = activeTab;
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
tabs,
|
|
29
|
+
initialTab,
|
|
30
|
+
changeActiveTab,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function useCaptchas() {
|
|
35
|
+
const { send, onSuccess } = useRequest(getAuthLoginValidCode({ size: '100x40' }));
|
|
36
|
+
const captcha = ref('');
|
|
37
|
+
const captchaHash = ref('');
|
|
38
|
+
|
|
39
|
+
onSuccess(({ data }) => {
|
|
40
|
+
const { key, plaintext } = data.data!;
|
|
41
|
+
|
|
42
|
+
const imgUrl = `data:image/png;base64,${plaintext}`;
|
|
43
|
+
captcha.value = imgUrl;
|
|
44
|
+
captchaHash.value = key!;
|
|
45
|
+
});
|
|
46
|
+
return {
|
|
47
|
+
send,
|
|
48
|
+
captcha,
|
|
49
|
+
captchaHash,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function useFocusElement() {
|
|
54
|
+
const activeElement = useActiveElement();
|
|
55
|
+
const focusElementDataId = computed(() =>
|
|
56
|
+
activeElement.value?.dataset?.id || 'null',
|
|
57
|
+
);
|
|
58
|
+
return {
|
|
59
|
+
focusElementDataId,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function useCountdown(initialTime: MaybeRef<number> = 60) {
|
|
64
|
+
const count = ref(toValue(initialTime));
|
|
65
|
+
const isStart = computed(() => {
|
|
66
|
+
return toValue(count) !== toValue(initialTime);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
function start() {
|
|
70
|
+
count.value--;
|
|
71
|
+
const timer = setInterval(() => {
|
|
72
|
+
count.value--;
|
|
73
|
+
if (count.value === 0) {
|
|
74
|
+
clearInterval(timer);
|
|
75
|
+
count.value = toValue(initialTime);
|
|
76
|
+
}
|
|
77
|
+
}, 1000);
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
count,
|
|
81
|
+
start,
|
|
82
|
+
isStart,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import LoginFrom from './components/LoginForm.vue';
|
|
3
|
+
|
|
4
|
+
defineOptions({
|
|
5
|
+
name: 'Login',
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
const title = ref(import.meta.env.VITE_APP_TITLE);
|
|
9
|
+
|
|
10
|
+
const designDescription = [
|
|
11
|
+
{
|
|
12
|
+
title: '快速',
|
|
13
|
+
description: '快速搭建技术中台系统',
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
title: '灵活',
|
|
17
|
+
description: '灵活配置系统功能',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
title: '便捷',
|
|
21
|
+
description: '高效提升系统开发效率',
|
|
22
|
+
},
|
|
23
|
+
];
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<template>
|
|
27
|
+
<div class="warp">
|
|
28
|
+
<div class="warp-blank">
|
|
29
|
+
<div
|
|
30
|
+
relative
|
|
31
|
+
top="7vh"
|
|
32
|
+
left="5vw"
|
|
33
|
+
scale="100 sm:100 smd:100 md:100 xl:110 2xl:120"
|
|
34
|
+
transform-origin="top-left"
|
|
35
|
+
transition-all
|
|
36
|
+
hidden
|
|
37
|
+
smd:block
|
|
38
|
+
>
|
|
39
|
+
<div class="logo-group">
|
|
40
|
+
<PubinfoIcon
|
|
41
|
+
name="logo"
|
|
42
|
+
color="transparent"
|
|
43
|
+
mr="10px"
|
|
44
|
+
:size="32"
|
|
45
|
+
/>
|
|
46
|
+
<span text="black dark:[#C9D6EF]">{{ title }}</span>
|
|
47
|
+
</div>
|
|
48
|
+
<div class="title-group">
|
|
49
|
+
<span text="black dark:[#C9D6EF]">一体化技术架构 一站式技术支撑</span>
|
|
50
|
+
<div flex="~ row" mt="30px">
|
|
51
|
+
<div
|
|
52
|
+
v-for="(item, index) in designDescription"
|
|
53
|
+
:key="index"
|
|
54
|
+
w-84px
|
|
55
|
+
h-36px
|
|
56
|
+
bg="#2F6BFF"
|
|
57
|
+
rounded-20px
|
|
58
|
+
text="20px #F7F7F7 dark:[#fff]"
|
|
59
|
+
font-normal
|
|
60
|
+
flex="~ center"
|
|
61
|
+
mr="15px"
|
|
62
|
+
>
|
|
63
|
+
{{ item.title }}
|
|
64
|
+
</div>
|
|
65
|
+
</div>
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
</div>
|
|
69
|
+
<div
|
|
70
|
+
h-full
|
|
71
|
+
bg="[rgba(255,255,255,0.1)] smd:[rgba(255,255,255,1)] dark:[#0F1E3B]"
|
|
72
|
+
backdrop-blur-sm
|
|
73
|
+
w="full smd:1/2 xl:800px 2xl:900px"
|
|
74
|
+
transition-all
|
|
75
|
+
flex="~ col"
|
|
76
|
+
justify-between
|
|
77
|
+
pb="40px"
|
|
78
|
+
relative
|
|
79
|
+
>
|
|
80
|
+
<div
|
|
81
|
+
smd:hidden
|
|
82
|
+
flex="~ row center"
|
|
83
|
+
w-full
|
|
84
|
+
h-200px
|
|
85
|
+
absolute
|
|
86
|
+
disable="none"
|
|
87
|
+
>
|
|
88
|
+
<PubinfoIcon
|
|
89
|
+
name="logo"
|
|
90
|
+
color="transparent"
|
|
91
|
+
:size="42"
|
|
92
|
+
mr-15px
|
|
93
|
+
/>
|
|
94
|
+
<span text="33px" font="bold">{{ title }}</span>
|
|
95
|
+
</div>
|
|
96
|
+
<div
|
|
97
|
+
w-full
|
|
98
|
+
flex="~"
|
|
99
|
+
justify-center
|
|
100
|
+
pt="20vh"
|
|
101
|
+
>
|
|
102
|
+
<LoginFrom />
|
|
103
|
+
</div>
|
|
104
|
+
</div>
|
|
105
|
+
</div>
|
|
106
|
+
</template>
|
|
107
|
+
|
|
108
|
+
<style scoped>
|
|
109
|
+
.warp {
|
|
110
|
+
--at-apply: relative flex flex-row w-full h-full overflow-hidden;
|
|
111
|
+
background: url("@/assets/images/login-bg.webp") no-repeat;
|
|
112
|
+
background-size: cover;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.warp .warp-blank {
|
|
116
|
+
--at-apply: flex-auto basis-0 overflow-hidden;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.warp .logo-group {
|
|
120
|
+
--at-apply: flex flex-row items-center h-33px mb-35px text-6 font-400 text-[#151e26];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.warp .title-group {
|
|
124
|
+
--at-apply: h-52px text-38px font-800 text-[#072347] tracking-[1.5px];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
@media (width < 1024px) {
|
|
128
|
+
.warp {
|
|
129
|
+
background: url("@/assets/images/login-small.png") no-repeat left;
|
|
130
|
+
background-size: cover;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
[data-theme="dark"] {
|
|
135
|
+
.warp {
|
|
136
|
+
background: url("@/assets/images/login-bg_dark.webp") no-repeat;
|
|
137
|
+
background-size: cover;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
@media (width < 1024px) {
|
|
141
|
+
.warp {
|
|
142
|
+
background: url("@/assets/images/login-small_dark.webp") no-repeat left;
|
|
143
|
+
background-size: cover;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
</style>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { presetUnocss } from 'pubinfo/node';
|
|
2
|
+
import { defineConfig } from 'unocss';
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
presets: [
|
|
6
|
+
presetUnocss(),
|
|
7
|
+
],
|
|
8
|
+
|
|
9
|
+
content: {
|
|
10
|
+
pipeline: {
|
|
11
|
+
include: [
|
|
12
|
+
/\.(vue|svelte|[jt]sx|mdx?|astro|elm|php|phtml|html)($|\?)/,
|
|
13
|
+
'src/routes/**/*.ts',
|
|
14
|
+
],
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
});
|
package/dist/index.cjs
DELETED
|
@@ -1,364 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
-
for (let key of __getOwnPropNames(from))
|
|
11
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
-
}
|
|
14
|
-
return to;
|
|
15
|
-
};
|
|
16
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
-
mod
|
|
23
|
-
));
|
|
24
|
-
|
|
25
|
-
// src/index.ts
|
|
26
|
-
var import_commander = require("commander");
|
|
27
|
-
var import_consola6 = __toESM(require("consola"), 1);
|
|
28
|
-
|
|
29
|
-
// package.json
|
|
30
|
-
var package_default = {
|
|
31
|
-
name: "create-pubinfo",
|
|
32
|
-
type: "module",
|
|
33
|
-
version: "2.0.0-beta.8",
|
|
34
|
-
description: "\u521D\u59CB\u5316\u9879\u76EE\u6846\u67B6",
|
|
35
|
-
author: "Werheng <werheng.zhang@gmail.com>",
|
|
36
|
-
license: "MIT",
|
|
37
|
-
bin: {
|
|
38
|
-
pubinfo: "./dist/index.js"
|
|
39
|
-
},
|
|
40
|
-
files: [
|
|
41
|
-
"dist"
|
|
42
|
-
],
|
|
43
|
-
scripts: {
|
|
44
|
-
dev: "tsup --watch src",
|
|
45
|
-
build: "tsup",
|
|
46
|
-
cli: "tsx src/index.ts",
|
|
47
|
-
"cli:clean": "rimraf ./my-app",
|
|
48
|
-
lint: "eslint . --cache --fix"
|
|
49
|
-
},
|
|
50
|
-
dependencies: {
|
|
51
|
-
"@inquirer/prompts": "^5.5.0",
|
|
52
|
-
"ansi-colors": "^4.1.3",
|
|
53
|
-
cfonts: "^3.3.0",
|
|
54
|
-
commander: "^12.1.0",
|
|
55
|
-
confbox: "^0.1.8",
|
|
56
|
-
consola: "^3.4.0",
|
|
57
|
-
giget: "^1.2.5",
|
|
58
|
-
ofetch: "^1.4.1",
|
|
59
|
-
ora: "^8.2.0",
|
|
60
|
-
rimraf: "^6.0.1",
|
|
61
|
-
semver: "^7.7.1"
|
|
62
|
-
},
|
|
63
|
-
devDependencies: {
|
|
64
|
-
"@types/node": "^22.13.9",
|
|
65
|
-
tsup: "^8.4.0"
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
// src/command/init.ts
|
|
70
|
-
var import_node_fs2 = require("fs");
|
|
71
|
-
var import_node_process2 = __toESM(require("process"), 1);
|
|
72
|
-
var import_prompts = require("@inquirer/prompts");
|
|
73
|
-
var import_ansi_colors = __toESM(require("ansi-colors"), 1);
|
|
74
|
-
var import_consola3 = __toESM(require("consola"), 1);
|
|
75
|
-
|
|
76
|
-
// src/constant.ts
|
|
77
|
-
var REMOTE_URL = "http://43.143.107.174:80/templates";
|
|
78
|
-
var PKG_NAME = "monorepo-project-template";
|
|
79
|
-
var VERSION_FILE = "version.json";
|
|
80
|
-
var SETTING_FILE_PATH = "src/settings.default.ts";
|
|
81
|
-
var OPENAPI_FILE_PATH = "openapi.config.ts";
|
|
82
|
-
var APPS_DIR = "apps";
|
|
83
|
-
var APPS = [
|
|
84
|
-
{ name: "\u7528\u6237\u6743\u9650\u7CFB\u7EDF\uFF08rbac\uFF09", value: "rbac" }
|
|
85
|
-
// { name: '初始化项目模板(admin)', value: 'admin' },
|
|
86
|
-
];
|
|
87
|
-
var METADATA_DIR = "configs/metadata";
|
|
88
|
-
var META_FILENAME = "pubinfo.json";
|
|
89
|
-
|
|
90
|
-
// src/fetch.ts
|
|
91
|
-
var import_node_process = __toESM(require("process"), 1);
|
|
92
|
-
var import_consola = __toESM(require("consola"), 1);
|
|
93
|
-
var import_ofetch = require("ofetch");
|
|
94
|
-
var import_ora = __toESM(require("ora"), 1);
|
|
95
|
-
var import_semver = require("semver");
|
|
96
|
-
async function fetchVersion() {
|
|
97
|
-
const versions = await (0, import_ofetch.ofetch)(`${REMOTE_URL}/${VERSION_FILE}`);
|
|
98
|
-
versions.sort((v1, v2) => -(0, import_semver.compare)(v1, v2));
|
|
99
|
-
return {
|
|
100
|
-
latest: versions[0],
|
|
101
|
-
list: versions
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
async function fetchData() {
|
|
105
|
-
const spinner = (0, import_ora.default)({
|
|
106
|
-
text: "\u68C0\u6D4B\u7F51\u7EDC\u8FDE\u63A5...",
|
|
107
|
-
color: "blue"
|
|
108
|
-
});
|
|
109
|
-
spinner.start();
|
|
110
|
-
try {
|
|
111
|
-
const version = await fetchVersion();
|
|
112
|
-
return {
|
|
113
|
-
version
|
|
114
|
-
};
|
|
115
|
-
} catch (error) {
|
|
116
|
-
if (error.message.includes(REMOTE_URL)) {
|
|
117
|
-
error.message = error.message.replace(REMOTE_URL, "[REMOTE_URL]");
|
|
118
|
-
}
|
|
119
|
-
import_consola.default.error(`\u7F51\u7EDC\u8FDE\u63A5\u5F02\u5E38: ${error.message}`);
|
|
120
|
-
import_node_process.default.exit(1);
|
|
121
|
-
} finally {
|
|
122
|
-
spinner.stop();
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// src/utils.ts
|
|
127
|
-
var import_node_fs = require("fs");
|
|
128
|
-
var import_promises = require("fs/promises");
|
|
129
|
-
var import_confbox = require("confbox");
|
|
130
|
-
var import_consola2 = __toESM(require("consola"), 1);
|
|
131
|
-
function rewriteFile(path, fn) {
|
|
132
|
-
if (!(0, import_node_fs.existsSync)(path)) {
|
|
133
|
-
import_consola2.default.error(`RewriteFile fail: ${path} does not exist`);
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
try {
|
|
137
|
-
const content = (0, import_node_fs.readFileSync)(path, { encoding: "utf-8" });
|
|
138
|
-
(0, import_node_fs.writeFileSync)(path, fn(content));
|
|
139
|
-
} catch (error) {
|
|
140
|
-
import_consola2.default.error(`RewriteFile fail: ${error}`);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
async function readJSON(path) {
|
|
144
|
-
const blob = await (0, import_promises.readFile)(path, "utf-8");
|
|
145
|
-
let parsed;
|
|
146
|
-
try {
|
|
147
|
-
parsed = (0, import_confbox.parseJSON)(blob);
|
|
148
|
-
} catch {
|
|
149
|
-
parsed = (0, import_confbox.parseJSONC)(blob);
|
|
150
|
-
}
|
|
151
|
-
return parsed;
|
|
152
|
-
}
|
|
153
|
-
async function writeJSON(path, json) {
|
|
154
|
-
await (0, import_promises.writeFile)(path, (0, import_confbox.stringifyJSON)(json));
|
|
155
|
-
}
|
|
156
|
-
function assignValues(target, source) {
|
|
157
|
-
for (const [key, value] of Object.entries(source)) {
|
|
158
|
-
target[key] = value;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
function validateInput(input2) {
|
|
162
|
-
const forbiddenChars = /[<>:"/\\|?*\s]/;
|
|
163
|
-
if (forbiddenChars.test(input2)) {
|
|
164
|
-
return '\u9519\u8BEF\u63D0\u793A: \u8BE5\u503C\u4E0D\u80FD\u5305\u542B\u7A7A\u683C\u6216\u8005\u975E\u6CD5\u5B57\u7B26 (\u4F8B\u5982, <>:"/\\|?*).';
|
|
165
|
-
}
|
|
166
|
-
return true;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// src/command/init.ts
|
|
170
|
-
async function init() {
|
|
171
|
-
const { version } = await fetchData();
|
|
172
|
-
const answer = {};
|
|
173
|
-
try {
|
|
174
|
-
answer.dir = await (0, import_prompts.input)({ message: "\u76EE\u5F55\u540D\u79F0\uFF08dir\uFF09", default: "my-app", validate: validateInput });
|
|
175
|
-
answer.key = await (0, import_prompts.input)({ message: "\u9879\u76EE\u6807\u8BC6\uFF08key\uFF09", default: answer.dir, validate: validateInput });
|
|
176
|
-
if ((0, import_node_fs2.existsSync)(answer.dir)) {
|
|
177
|
-
const overwrite = await (0, import_prompts.confirm)({ message: `\u76EE\u5F55 ${import_ansi_colors.default.cyan(answer.dir)} \u5DF2\u5B58\u5728\uFF0C\u662F\u5426\u8986\u76D6\uFF1F` });
|
|
178
|
-
if (!overwrite) {
|
|
179
|
-
throw Error;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
answer.version = await (0, import_prompts.input)({
|
|
183
|
-
message: "\u6846\u67B6\u7248\u672C\u53F7\uFF08version\uFF09",
|
|
184
|
-
default: version.latest,
|
|
185
|
-
validate: (input2) => {
|
|
186
|
-
if (!version.list.includes(input2)) {
|
|
187
|
-
return `\u7248\u672C\u53F7: ${import_ansi_colors.default.bold(input2)} \u4E0D\u5B58\u5728, \u5F53\u524D\u6700\u65B0\u7248\u672C\u53F7: ${import_ansi_colors.default.bold(version.latest)}.`;
|
|
188
|
-
}
|
|
189
|
-
return true;
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
answer.apps = await (0, import_prompts.checkbox)({
|
|
193
|
-
message: "\u9009\u62E9\u5E94\u7528\u6A21\u5757\uFF08apps\uFF09",
|
|
194
|
-
choices: APPS,
|
|
195
|
-
validate: (input2) => {
|
|
196
|
-
if (input2.length === 0) {
|
|
197
|
-
return "\u8BF7\u81F3\u5C11\u9009\u62E9\u4E00\u4E2A\u5E94\u7528";
|
|
198
|
-
}
|
|
199
|
-
return true;
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
answer.openapi = await (0, import_prompts.confirm)({
|
|
203
|
-
message: "\u8FD0\u884C\u65F6\u81EA\u52A8\u751F\u6210\u63A5\u53E3\u5BF9\u63A5\u6587\u4EF6\uFF0C\u82E5\u5173\u95ED\u53EF\u901A\u8FC7\u6307\u4EE4\u751F\u6210\uFF08openapi\uFF09",
|
|
204
|
-
default: false
|
|
205
|
-
});
|
|
206
|
-
return answer;
|
|
207
|
-
} catch {
|
|
208
|
-
import_consola3.default.fail("\u64CD\u4F5C\u7EC8\u6B62");
|
|
209
|
-
import_node_process2.default.exit(1);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// src/download.ts
|
|
214
|
-
var import_node_process3 = __toESM(require("process"), 1);
|
|
215
|
-
var import_ansi_colors2 = __toESM(require("ansi-colors"), 1);
|
|
216
|
-
var import_consola4 = __toESM(require("consola"), 1);
|
|
217
|
-
var import_giget = require("giget");
|
|
218
|
-
var import_ora2 = __toESM(require("ora"), 1);
|
|
219
|
-
var import_semver2 = require("semver");
|
|
220
|
-
var pubinfo = async (input2, { auth }) => {
|
|
221
|
-
const semver = (0, import_semver2.coerce)(input2);
|
|
222
|
-
return {
|
|
223
|
-
name: "pubinfo",
|
|
224
|
-
version: input2,
|
|
225
|
-
headers: { Authorization: `token ${auth}` },
|
|
226
|
-
tar: `${REMOTE_URL}/${PKG_NAME}-${semver?.version}.tar.gz`
|
|
227
|
-
};
|
|
228
|
-
};
|
|
229
|
-
async function download(options) {
|
|
230
|
-
const finish = loading();
|
|
231
|
-
try {
|
|
232
|
-
await (0, import_giget.downloadTemplate)(`pubinfo:${PKG_NAME}-${options.version}`, {
|
|
233
|
-
providers: { pubinfo },
|
|
234
|
-
force: true,
|
|
235
|
-
forceClean: true,
|
|
236
|
-
// auth: options.auth,
|
|
237
|
-
dir: options.dir
|
|
238
|
-
});
|
|
239
|
-
} catch (error) {
|
|
240
|
-
if (error.message.includes(REMOTE_URL)) {
|
|
241
|
-
error.message = error.message.replace(REMOTE_URL, "[REMOTE_URL]");
|
|
242
|
-
}
|
|
243
|
-
import_consola4.default.error(`\u4E0B\u8F7D\u5931\u8D25: ${error.message}`);
|
|
244
|
-
import_node_process3.default.exit(1);
|
|
245
|
-
} finally {
|
|
246
|
-
finish();
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
function loading() {
|
|
250
|
-
const startTime = Date.now();
|
|
251
|
-
const spinner = (0, import_ora2.default)({
|
|
252
|
-
text: "\u4E0B\u8F7D\u4E2D...",
|
|
253
|
-
color: "green"
|
|
254
|
-
});
|
|
255
|
-
spinner.start();
|
|
256
|
-
return () => {
|
|
257
|
-
const { green, yellow } = import_ansi_colors2.default;
|
|
258
|
-
spinner.stop();
|
|
259
|
-
import_consola4.default.success(`${green("\u4E0B\u8F7D\u5B8C\u6210, \u7528\u65F6")} ${yellow(`${Date.now() - startTime}`)} ${green("ms.")}`);
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
// src/log.ts
|
|
264
|
-
var import_cfonts = __toESM(require("cfonts"), 1);
|
|
265
|
-
function bootstrop() {
|
|
266
|
-
printLoGo("PUBINFO");
|
|
267
|
-
function printLoGo(logo) {
|
|
268
|
-
import_cfonts.default.say(logo, {
|
|
269
|
-
font: "simple3d",
|
|
270
|
-
align: "left",
|
|
271
|
-
background: "transparent",
|
|
272
|
-
letterSpacing: 1,
|
|
273
|
-
lineHeight: 1,
|
|
274
|
-
space: true,
|
|
275
|
-
maxLength: 0,
|
|
276
|
-
spaceless: false,
|
|
277
|
-
gradient: ["blue", "magenta"],
|
|
278
|
-
independentGradient: false,
|
|
279
|
-
transitionGradient: false,
|
|
280
|
-
env: "node"
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
// src/rewrite.ts
|
|
286
|
-
var import_node_fs3 = require("fs");
|
|
287
|
-
var import_node_path = require("path");
|
|
288
|
-
var import_node_process4 = __toESM(require("process"), 1);
|
|
289
|
-
var import_consola5 = __toESM(require("consola"), 1);
|
|
290
|
-
var import_rimraf = require("rimraf");
|
|
291
|
-
async function rewrite(options) {
|
|
292
|
-
const { dir } = options;
|
|
293
|
-
const root = import_node_process4.default.cwd();
|
|
294
|
-
const projectDir = (0, import_node_path.resolve)(root, dir);
|
|
295
|
-
writeMetaJSON((0, import_node_path.resolve)(projectDir, METADATA_DIR), options);
|
|
296
|
-
writeApps((0, import_node_path.resolve)(projectDir, APPS_DIR), options);
|
|
297
|
-
}
|
|
298
|
-
async function writeMetaJSON(metaDir, options) {
|
|
299
|
-
const { key, version, apps, openapi } = options;
|
|
300
|
-
const path = (0, import_node_path.resolve)(metaDir, META_FILENAME);
|
|
301
|
-
try {
|
|
302
|
-
const json = await readJSON(path);
|
|
303
|
-
assignValues(json, {
|
|
304
|
-
key,
|
|
305
|
-
version,
|
|
306
|
-
apps,
|
|
307
|
-
openapi
|
|
308
|
-
});
|
|
309
|
-
await writeJSON(path, json);
|
|
310
|
-
} catch (error) {
|
|
311
|
-
import_consola5.default.error(`\u521D\u59CB\u5316 metadata \u5931\u8D25: ${error}`);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
function writeApps(appsDir, options) {
|
|
315
|
-
const { key, apps = [], openapi } = options;
|
|
316
|
-
if (!(0, import_node_fs3.existsSync)(appsDir)) {
|
|
317
|
-
import_consola5.default.error(`\u521D\u59CB\u5316 apps \u5931\u8D25: ${appsDir} \u4E0D\u5B58\u5728`);
|
|
318
|
-
return;
|
|
319
|
-
}
|
|
320
|
-
try {
|
|
321
|
-
(0, import_node_fs3.readdirSync)(appsDir).forEach((app) => {
|
|
322
|
-
const appPath = (0, import_node_path.resolve)(appsDir, app);
|
|
323
|
-
const settingPath = (0, import_node_path.resolve)(appPath, SETTING_FILE_PATH);
|
|
324
|
-
const openapiPath = (0, import_node_path.resolve)(appPath, OPENAPI_FILE_PATH);
|
|
325
|
-
if (!apps.includes(app)) {
|
|
326
|
-
(0, import_rimraf.rimrafSync)(appPath);
|
|
327
|
-
return;
|
|
328
|
-
}
|
|
329
|
-
rewriteFile(settingPath, (content) => {
|
|
330
|
-
return content.replace(/storagePrefix:\s*'([^']*)'/g, `storagePrefix: '${key}'`);
|
|
331
|
-
});
|
|
332
|
-
rewriteFile(openapiPath, (content) => {
|
|
333
|
-
return content.replace(/enabled:[^,]+,/g, `enabled: ${openapi},`);
|
|
334
|
-
});
|
|
335
|
-
});
|
|
336
|
-
} catch (error) {
|
|
337
|
-
import_consola5.default.error(`\u521D\u59CB\u5316 apps \u5931\u8D25: ${error}`);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
// src/index.ts
|
|
342
|
-
async function main() {
|
|
343
|
-
const program = new import_commander.Command();
|
|
344
|
-
program.name(package_default.name).description(package_default.description).version(package_default.version);
|
|
345
|
-
program.description("\u521D\u59CB\u5316\u6846\u67B6").action(async () => {
|
|
346
|
-
bootstrop();
|
|
347
|
-
try {
|
|
348
|
-
const answer = await init();
|
|
349
|
-
await download(answer);
|
|
350
|
-
await rewrite(answer);
|
|
351
|
-
} catch (error) {
|
|
352
|
-
import_consola6.default.error(error);
|
|
353
|
-
}
|
|
354
|
-
});
|
|
355
|
-
program.command("create").description("\u521B\u5EFA\u4E00\u4E2A\u65B0\u7684\u5E94\u7528").argument("<app-name>", "\u5E94\u7528\u540D\u79F0").action((name) => {
|
|
356
|
-
import_consola6.default.info("\u521B\u5EFA\u4E00\u4E2A\u65B0\u7684\u5E94\u7528", name);
|
|
357
|
-
});
|
|
358
|
-
program.command("status").description("\u67E5\u770B\u6846\u67B6\u72B6\u6001").action(() => {
|
|
359
|
-
});
|
|
360
|
-
program.command("update").description("\u66F4\u65B0\u6846\u67B6\u7248\u672C").action(() => {
|
|
361
|
-
});
|
|
362
|
-
program.parse();
|
|
363
|
-
}
|
|
364
|
-
main();
|