@dypnb/dev-tools 1.0.4 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +8 -5
- package/src/dome.vue +25 -0
- package/src/gen-page/config.js +40 -0
- package/src/gen-page/index.js +122 -0
- package/src/gen-page/template.js +568 -0
- package/src/gen-swagger/index.js +228 -0
- package/src/index.js +12 -0
- package/src/publish-server/index.js +130 -0
- package/src/utils/index.js +85 -0
- package/src/wx-server-notice/README.md +59 -0
- package/src/wx-server-notice/api.js +45 -0
- package/src/wx-server-notice/images/qiyewx-1.png +0 -0
- package/src/wx-server-notice/images/qiyewx-2.png +0 -0
- package/src/wx-server-notice/images/qiyewx-3-1.png +0 -0
- package/src/wx-server-notice/images/qiyewx-3-2.png +0 -0
- package/src/wx-server-notice/images/qiyewx-3.png +0 -0
- package/src/wx-server-notice/images/qiyewx-4.png +0 -0
- package/src/wx-server-notice/images/qiyewx-5-1.jpg +0 -0
- package/src/wx-server-notice/images/qiyewx-5.jpg +0 -0
- package/src/wx-server-notice/images/qiyewx-6.png +0 -0
- package/src/wx-server-notice/index.js +62 -0
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@dypnb/dev-tools",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.6",
|
4
4
|
"description": "开发时的提效工具",
|
5
5
|
"main": "lib/bundle.cjs.js",
|
6
6
|
"jsnext:main": "lib/bundle.esm.js",
|
@@ -16,14 +16,16 @@
|
|
16
16
|
"genPage": "node ./dist/genPage/index.js",
|
17
17
|
"docs:dev": "vitepress dev docs --host ",
|
18
18
|
"docs:build": "vitepress build docs",
|
19
|
-
"docs:preview": "vitepress preview docs"
|
19
|
+
"docs:preview": "vitepress preview docs",
|
20
|
+
"publishD": "dyp-publish"
|
20
21
|
},
|
21
22
|
"bin": {
|
22
|
-
"dyp-publish": "
|
23
|
-
"dyp-genPage": "
|
24
|
-
"dyp-genSwagger": "
|
23
|
+
"dyp-publish": "./src/publish-server/index.js",
|
24
|
+
"dyp-genPage": "./src/gen-page/index.js",
|
25
|
+
"dyp-genSwagger": "dist/gen-page/index.js"
|
25
26
|
},
|
26
27
|
"dependencies": {
|
28
|
+
"@dypnb/dev-tools": "^1.0.5",
|
27
29
|
"axios": "^1.4.0",
|
28
30
|
"chalk": "4.1.0",
|
29
31
|
"execa": "^5.1.1",
|
@@ -68,6 +70,7 @@
|
|
68
70
|
},
|
69
71
|
"files": [
|
70
72
|
"dist/*",
|
73
|
+
"src/*",
|
71
74
|
"*.json"
|
72
75
|
],
|
73
76
|
"browserslist": [
|
package/src/dome.vue
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
<template>
|
2
|
+
<div class='dome'>
|
3
|
+
<button>测试</button>
|
4
|
+
</div>
|
5
|
+
</template>
|
6
|
+
<script>
|
7
|
+
export default {
|
8
|
+
components: {
|
9
|
+
},
|
10
|
+
data() {
|
11
|
+
return {
|
12
|
+
}
|
13
|
+
},
|
14
|
+
created() {
|
15
|
+
},
|
16
|
+
mounted() {
|
17
|
+
},
|
18
|
+
computed: {
|
19
|
+
},
|
20
|
+
methods: {
|
21
|
+
},
|
22
|
+
}
|
23
|
+
</script>
|
24
|
+
<style scoped lang='scss'>
|
25
|
+
</style>
|
@@ -0,0 +1,40 @@
|
|
1
|
+
// 导入模板
|
2
|
+
import templateData from "./template.js";
|
3
|
+
export default {
|
4
|
+
// 是否命令行创建
|
5
|
+
isEnter: true,
|
6
|
+
// 文件名
|
7
|
+
name: 'genPageTable',
|
8
|
+
// 默认 view 目录下生成,如果需要指定父目录则写入 fatherFileName
|
9
|
+
path: 'dome',
|
10
|
+
// 子文件配置
|
11
|
+
child: [
|
12
|
+
{
|
13
|
+
name: 'index.vue',
|
14
|
+
template: (params = {}) => {
|
15
|
+
return templateData.tablePageTemplate({
|
16
|
+
// 文件标题,替换模板
|
17
|
+
title: 'pageTable',
|
18
|
+
...params,
|
19
|
+
})
|
20
|
+
},
|
21
|
+
templateConfig: {
|
22
|
+
|
23
|
+
},
|
24
|
+
},
|
25
|
+
{
|
26
|
+
name: 'constants.js',
|
27
|
+
template: (params = {}) => {
|
28
|
+
return templateData.constantsTemplate ({
|
29
|
+
// 文件标题,替换模板
|
30
|
+
title: 'pageTable',
|
31
|
+
...params,
|
32
|
+
})
|
33
|
+
},
|
34
|
+
templateConfig: {
|
35
|
+
// 文件标题,替换模板
|
36
|
+
title: '',
|
37
|
+
},
|
38
|
+
},
|
39
|
+
]
|
40
|
+
}
|
@@ -0,0 +1,122 @@
|
|
1
|
+
#! /usr/bin/env node
|
2
|
+
import path from "path";
|
3
|
+
import fs from "fs";
|
4
|
+
import { getGlobalConfig, getDirname, log, successLog, errorLog } from "../utils/index.js";
|
5
|
+
import defaultConfig from "./config.js";
|
6
|
+
const __dirname = getDirname();
|
7
|
+
const resolve = (...file) => path.resolve(__dirname, ...file);
|
8
|
+
|
9
|
+
async function getGenPageConfig() {
|
10
|
+
return await getGlobalConfig('genPageConfig');
|
11
|
+
}
|
12
|
+
|
13
|
+
// 模板配置
|
14
|
+
getGenPageConfig().then(res => {
|
15
|
+
const genPageConfig = res || defaultConfig;
|
16
|
+
if (!genPageConfig) {
|
17
|
+
errorLog('全局模板未配置,使用默认配置')
|
18
|
+
}
|
19
|
+
genPage(genPageConfig);
|
20
|
+
});
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
// 生成文件
|
26
|
+
const generateFile = (path, data) => {
|
27
|
+
if (fs.existsSync(path)) {
|
28
|
+
errorLog(`${path}文件已存在`)
|
29
|
+
return
|
30
|
+
}
|
31
|
+
fs.writeFileSync(path, data, 'utf8', err => {
|
32
|
+
if (err) {
|
33
|
+
errorLog(err.message)
|
34
|
+
reject(err)
|
35
|
+
} else {
|
36
|
+
resolve(true)
|
37
|
+
}
|
38
|
+
})
|
39
|
+
}
|
40
|
+
|
41
|
+
function dotExistDirectoryCreate(directory) {
|
42
|
+
return new Promise((resolve) => {
|
43
|
+
mkdirs(directory, function() {
|
44
|
+
resolve(true)
|
45
|
+
})
|
46
|
+
})
|
47
|
+
}
|
48
|
+
// 递归创建目录
|
49
|
+
function mkdirs(directory, callback) {
|
50
|
+
var exists = fs.existsSync(directory)
|
51
|
+
if (exists) {
|
52
|
+
callback()
|
53
|
+
} else {
|
54
|
+
mkdirs(path.dirname(directory), function() {
|
55
|
+
fs.mkdirSync(directory)
|
56
|
+
callback()
|
57
|
+
})
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
|
62
|
+
async function genPageProcess(config, enterName) {
|
63
|
+
// 组件名称
|
64
|
+
const pageName = !enterName ? config.name : enterName;
|
65
|
+
// Vue页面组件路径
|
66
|
+
const pathStr = !config.path ? `${process.env.PWD}/src/views` : `${process.env.PWD}/src/views/${config.path}`;
|
67
|
+
const pagePath = resolve(pathStr, pageName)
|
68
|
+
|
69
|
+
// 判断组件文件夹是否存在
|
70
|
+
const hasComponentExists = fs.existsSync(pagePath)
|
71
|
+
if (hasComponentExists) {
|
72
|
+
errorLog(`${pageName}页面已存在`)
|
73
|
+
if (pageName) {
|
74
|
+
process.stdin.emit('end')
|
75
|
+
}
|
76
|
+
return
|
77
|
+
} else {
|
78
|
+
log(`正在生成${pageName}目录 ${pagePath}`)
|
79
|
+
await dotExistDirectoryCreate(pagePath)
|
80
|
+
}
|
81
|
+
try {
|
82
|
+
// // 获取组件名
|
83
|
+
// if (enterName.includes('/')) {
|
84
|
+
// const inputArr = enterName.split('/')
|
85
|
+
// pageName = inputArr[inputArr.length - 1]
|
86
|
+
// } else {
|
87
|
+
// pageName = enterName
|
88
|
+
// }
|
89
|
+
|
90
|
+
config.child.forEach((item) => {
|
91
|
+
const filePath = resolve(pagePath, item.name)
|
92
|
+
log(`正在生成子文件${item.name} ${filePath}`)
|
93
|
+
generateFile(filePath, item.template({name: pageName}))
|
94
|
+
})
|
95
|
+
|
96
|
+
successLog('生成成功')
|
97
|
+
} catch (e) {
|
98
|
+
errorLog(e.message)
|
99
|
+
}
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
function genPage(config) {
|
104
|
+
if (!config.isEnter) {
|
105
|
+
genPageProcess(config);
|
106
|
+
} else {
|
107
|
+
log('请输入要生成的页面组件名称、会生成在 views/目录下')
|
108
|
+
process.stdin.on('data', async chunk => {
|
109
|
+
// 组件名称
|
110
|
+
const enterName = String(chunk).trim().toString();
|
111
|
+
genPageProcess(config, enterName);
|
112
|
+
process.stdin.emit('end')
|
113
|
+
})
|
114
|
+
|
115
|
+
process.stdin.on('end', () => {
|
116
|
+
log('exit')
|
117
|
+
process.exit()
|
118
|
+
})
|
119
|
+
}
|
120
|
+
}
|
121
|
+
|
122
|
+
|