@dypnb/dev-tools 1.0.11 → 1.0.13

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dypnb/dev-tools",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "description": "开发时的提效工具",
5
5
  "main": "lib/bundle.cjs.js",
6
6
  "jsnext:main": "lib/bundle.esm.js",
@@ -69,7 +69,6 @@
69
69
  },
70
70
  "files": [
71
71
  "dist/*",
72
- "src/*",
73
72
  "*.json"
74
73
  ],
75
74
  "browserslist": [
package/src/dome.vue DELETED
@@ -1,25 +0,0 @@
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>
@@ -1,40 +0,0 @@
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
- }
@@ -1,122 +0,0 @@
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
-