@ctzy-web-client/create-web-client 1.0.6 → 1.0.8

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.
Files changed (25) hide show
  1. package/bin/create-web-client.js +225 -169
  2. package/bin/utils/index.js +105 -73
  3. package/lib/download.js +184 -9
  4. package/lib/generator.js +142 -9
  5. package/package.json +30 -30
  6. package/templates/qiankun-subapp-vue-template/jsconfig.json +1 -1
  7. package/templates/qiankun-subapp-vue-template/mocks/test.js +1 -0
  8. package/templates/qiankun-subapp-vue-template/package.json +2 -1
  9. package/templates/qiankun-subapp-vue-template/src/interceptors/AppRequestInterceptors.js +2 -1
  10. package/templates/qiankun-subapp-vue-template/src/interceptors/AppRouterInterceptors.js +2 -1
  11. package/templates/qiankun-subapp-vue-template/src/main.js +2 -1
  12. package/templates/qiankun-subapp-vue-template/src/models/TestDataModel.js +2 -1
  13. package/templates/qiankun-subapp-vue-template/src/pages/form/index.vue +3 -2
  14. package/templates/qiankun-subapp-vue-template/src/pages/home/index.vue +2 -1
  15. package/templates/qiankun-subapp-vue-template/src/services/TestServices.js +2 -1
  16. package/templates/qiankun-subapp-vue-template/vite.config.ts +1 -1
  17. package/templates/qiankun-vue-template/jsconfig.json +1 -0
  18. package/templates/qiankun-vue-template/package.json +2 -1
  19. package/templates/qiankun-vue-template/src/main.js +3 -2
  20. package/templates/qiankun-vue-template/src/pages/app/index.vue +2 -1
  21. package/templates/qiankun-vue-template/src/services/ApplicaitionService.js +1 -0
  22. package/templates/qiankun-vue-template/src/services/UserService.js +1 -0
  23. package/templates/web-client-vue-template/package.json +1 -0
  24. package/lib/download2.js +0 -129
  25. package/lib/generator2.js +0 -80
package/lib/download.js CHANGED
@@ -1,9 +1,184 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var download = require('./download2.js');
6
-
7
-
8
-
9
- exports["default"] = download["default"];
1
+ var downloadUrl = require('download');
2
+ var gitclone = require('git-clone');
3
+ var rm = require('rimraf').sync;
4
+
5
+ /**
6
+ * Expose `download`.
7
+ */
8
+
9
+ module.exports = download;
10
+
11
+ /**
12
+ * Download `repo` to `dest` and callback `fn(err)`.
13
+ *
14
+ * @param {String} repo
15
+ * @param {String} dest
16
+ * @param {Object} opts
17
+ * @param {Function} fn
18
+ */
19
+
20
+ function download(repo, dest, opts, fn) {
21
+ if (typeof opts === 'function') {
22
+ fn = opts;
23
+ opts = null;
24
+ }
25
+ opts = opts || {};
26
+ var clone = opts.clone || false;
27
+
28
+ repo = normalize(repo);
29
+
30
+ var url = repo.url || getUrl(repo, clone);
31
+
32
+ if (clone) {
33
+ gitclone(
34
+ url,
35
+ dest,
36
+ {
37
+ checkout: repo.checkout,
38
+ shallow: repo.checkout === 'master',
39
+ },
40
+ function (err) {
41
+ if (err === undefined) {
42
+ rm(dest + '/.git');
43
+ fn();
44
+ } else {
45
+ fn(err);
46
+ }
47
+ }
48
+ );
49
+ } else {
50
+ downloadUrl(url, dest, {
51
+ extract: true,
52
+ strip: 1,
53
+ mode: '666',
54
+ headers: {
55
+ accept: 'application/zip',
56
+ },
57
+ })
58
+ .then(function (data) {
59
+ fn();
60
+ })
61
+ .catch(function (err) {
62
+ fn(err);
63
+ });
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Normalize a repo string.
69
+ *
70
+ * @param {String} repo
71
+ * @return {Object}
72
+ */
73
+
74
+ function normalize(repo) {
75
+ var regex = /^(?:(direct):([^#]+)(?:#(.+))?)$/;
76
+ var match = regex.exec(repo);
77
+
78
+ if (match) {
79
+ var url = match[2];
80
+ var checkout = match[3] || 'master';
81
+
82
+ return {
83
+ type: 'direct',
84
+ url: url,
85
+ checkout: checkout,
86
+ };
87
+ } else {
88
+ regex =
89
+ /^(?:(github|gitlab|bitbucket):)?(?:(.+):)?([^\/]+)\/([^#]+)(?:#(.+))?$/;
90
+ match = regex.exec(repo);
91
+ var type = match[1] || 'baswebapp';
92
+ var origin = match[2] || null;
93
+ var owner = match[3];
94
+ var name = match[4];
95
+ var checkout = match[5] || 'master';
96
+
97
+ if (origin == null) {
98
+ if (type === 'github') origin = 'github.com';
99
+ else if (type === 'gitlab') origin = 'gitlab.com';
100
+ else if (type === 'bitbucket') origin = 'bitbucket.com';
101
+ else if (type === 'baswebapp') origin = 'gitlab.baswebapp.cn';
102
+ }
103
+
104
+ return {
105
+ type: type,
106
+ origin: origin,
107
+ owner: owner,
108
+ name: name,
109
+ checkout: checkout,
110
+ };
111
+ }
112
+ }
113
+
114
+ /**
115
+ * Adds protocol to url in none specified
116
+ *
117
+ * @param {String} url
118
+ * @return {String}
119
+ */
120
+
121
+ function addProtocol(origin, clone) {
122
+ if (!/^(f|ht)tps?:\/\//i.test(origin)) {
123
+ if (clone) origin = 'git@' + origin;
124
+ else origin = 'https://' + origin;
125
+ }
126
+
127
+ return origin;
128
+ }
129
+
130
+ /**
131
+ * Return a zip or git url for a given `repo`.
132
+ *
133
+ * @param {Object} repo
134
+ * @return {String}
135
+ */
136
+
137
+ function getUrl(repo, clone) {
138
+ var url;
139
+
140
+ // Get origin with protocol and add trailing slash or colon (for ssh)
141
+ var origin = addProtocol(repo.origin, clone);
142
+ if (/^git\@/i.test(origin)) origin = origin + ':';
143
+ else origin = origin + '/';
144
+
145
+ // Build url
146
+ if (clone) {
147
+ url = origin + repo.owner + '/' + repo.name + '.git';
148
+ } else {
149
+ if (repo.type === 'github')
150
+ url =
151
+ origin +
152
+ repo.owner +
153
+ '/' +
154
+ repo.name +
155
+ '/archive/' +
156
+ repo.checkout +
157
+ '.zip';
158
+ else if (repo.type === 'gitlab')
159
+ url =
160
+ origin +
161
+ repo.owner +
162
+ '/' +
163
+ repo.name +
164
+ '/repository/archive.zip?ref=' +
165
+ repo.checkout;
166
+ else if (repo.type === 'baswebapp')
167
+ url =
168
+ 'http://gitlab.baswebapp.cn/bwa//' +
169
+ repo.name +
170
+ '/repository/archive.zip?ref=' +
171
+ repo.checkout;
172
+ else if (repo.type === 'bitbucket')
173
+ url =
174
+ origin +
175
+ repo.owner +
176
+ '/' +
177
+ repo.name +
178
+ '/get/' +
179
+ repo.checkout +
180
+ '.zip';
181
+ }
182
+
183
+ return url;
184
+ }
package/lib/generator.js CHANGED
@@ -1,9 +1,142 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var generator = require('./generator2.js');
6
-
7
-
8
-
9
- exports["default"] = generator["default"];
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const isBinary = require('isbinaryfile');
4
+ const ora = require('ora');
5
+ const home = require('user-home');
6
+ const download = require('./download');
7
+
8
+ /**
9
+ * 生成
10
+ * @param {String} dir 目录
11
+ * @param {*} files
12
+ * @param {*} base
13
+ * @param {*} rootOptions
14
+ */
15
+ async function generate(dir, files, base = '', rootOptions = {}) {
16
+ const glob = require('glob');
17
+
18
+ glob
19
+ .sync('**/*', {
20
+ cwd: dir,
21
+ nodir: true,
22
+ })
23
+ .forEach((rawPath) => {
24
+ const sourcePath = path.resolve(dir, rawPath);
25
+
26
+ const filename = path.join(base, rawPath);
27
+
28
+ //是否是二进制文件
29
+ if (isBinary.sync(sourcePath)) {
30
+ //如果是直接返回流
31
+ files[filename] = fs.readFileSync(sourcePath); // return buffer
32
+ } else {
33
+ //读取文件内容
34
+ let content = fs.readFileSync(sourcePath, 'utf-8');
35
+
36
+ if (path.basename(filename) === 'manifest.json') {
37
+ content = content.replace('{{name}}', rootOptions.projectName || '');
38
+ }
39
+
40
+ //_aaa.js => aaa.js
41
+ if (filename.charAt(0) === '_' && filename.charAt(1) !== '_') {
42
+ files[`.${filename.slice(1)}`] = content;
43
+ }
44
+ //__aaa.js => _aaa.js
45
+ else if (filename.charAt(0) === '_' && filename.charAt(1) === '_') {
46
+ files[`${filename.slice(1)}`] = content;
47
+ }
48
+ //原模原样拷贝
49
+ else {
50
+ files[filename] = content;
51
+ }
52
+ }
53
+ });
54
+ }
55
+
56
+ module.exports = (api, options, rootOptions) => {
57
+ //扩展package配置
58
+ // api.extendPackage(pkg => {
59
+ // return {
60
+ // dependencies: {
61
+ // "axios": "^0.19.2",
62
+ // "core-js": "^3.6.5",
63
+ // "vue": "^2.6.11",
64
+ // "vue-router": "^3.2.0",
65
+ // "vuex": "^3.4.0"
66
+ // },
67
+ // devDependencies: {
68
+ // "@vue/cli-plugin-babel": "^4.5.0",
69
+ // "@vue/cli-service": "^4.5.0",
70
+ // "babel-plugin-import": "^1.13.0",
71
+ // "less": "^3.0.4",
72
+ // "less-loader": "^5.0.0",
73
+ // "vue-template-compiler": "^2.6.11"
74
+ // }
75
+ // }
76
+ // });
77
+
78
+ // if (options.template === 'bwa/bwa-template-h5') {
79
+ // api.extendPackage(pkg => {
80
+ // return {
81
+ // dependencies: {
82
+ // "vant": "^2.10.3"
83
+ // },
84
+ // devDependencies: {
85
+
86
+ // }
87
+ // }
88
+ // })
89
+ // }
90
+ // else if (options.template === 'bwa/bwa-template-news') {
91
+ // api.extendPackage(pkg => {
92
+ // return {
93
+ // dependencies: {
94
+ // "vue-i18n": "^8.18.2"
95
+ // },
96
+ // devDependencies: {
97
+
98
+ // }
99
+ // }
100
+ // })
101
+ // }
102
+
103
+ api.render(async function (files) {
104
+ Object.keys(files).forEach((name) => {
105
+ delete files[name];
106
+ });
107
+
108
+ let _template = options.repo || options.template;
109
+ let _base = '';
110
+
111
+ //获取公共模版内容
112
+ // await generate(path.resolve(__dirname, './template/common'), files);
113
+
114
+ let _spinner = ora('模板下载中...');
115
+
116
+ //下载到根目录
117
+ let _tmpDir = path.join(
118
+ home,
119
+ '.bwa-app/templates',
120
+ _template.replace(/[/:]/g, '-')
121
+ );
122
+
123
+ _spinner.start();
124
+
125
+ await new Promise((resolve, reject) => {
126
+ //http://gitlab.baswebapp.cn/bwa/bwa-template-h5.git
127
+ //开始下载 /bwa/bwa-template-h5/repository/archive.zip?ref=master
128
+ download(_template, _tmpDir, (err) => {
129
+ //下载完成
130
+ _spinner.stop();
131
+
132
+ if (err) {
133
+ return reject(err);
134
+ }
135
+
136
+ resolve();
137
+ });
138
+ });
139
+
140
+ await generate(_tmpDir, files, _base);
141
+ });
142
+ };
package/package.json CHANGED
@@ -1,30 +1,30 @@
1
- {
2
- "name": "@ctzy-web-client/create-web-client",
3
- "version": "1.0.6",
4
- "description": "创建 web client 项目模板工具",
5
- "main": "index.js",
6
- "files": [
7
- "bin/",
8
- "lib/",
9
- "index.js",
10
- "templates/"
11
- ],
12
- "bin": {
13
- "create-web-client": "index.js"
14
- },
15
- "author": "tommy",
16
- "license": "MIT",
17
- "dependencies": {
18
- "cross-spawn": "^7.0.3",
19
- "download": "^8.0.0",
20
- "git-clone": "^0.2.0",
21
- "glob": "^8.0.3",
22
- "isbinaryfile": "^5.0.0",
23
- "kolorist": "^1.6.0",
24
- "minimist": "^1.2.7",
25
- "ora": "^6.1.2",
26
- "prompts": "^2.4.2",
27
- "rimraf": "^3.0.2",
28
- "user-home": "^3.0.0"
29
- }
30
- }
1
+ {
2
+ "name": "@ctzy-web-client/create-web-client",
3
+ "version": "1.0.8",
4
+ "description": "创建 web client 项目模板工具",
5
+ "main": "index.js",
6
+ "files": [
7
+ "bin/",
8
+ "lib/",
9
+ "index.js",
10
+ "templates/"
11
+ ],
12
+ "bin": {
13
+ "create-web-client": "index.js"
14
+ },
15
+ "author": "tommy",
16
+ "license": "MIT",
17
+ "dependencies": {
18
+ "cross-spawn": "^7.0.3",
19
+ "download": "^8.0.0",
20
+ "git-clone": "^0.2.0",
21
+ "glob": "^8.0.3",
22
+ "isbinaryfile": "^5.0.0",
23
+ "kolorist": "^1.6.0",
24
+ "minimist": "^1.2.7",
25
+ "ora": "^6.1.2",
26
+ "prompts": "^2.4.2",
27
+ "rimraf": "^3.0.2",
28
+ "user-home": "^3.0.0"
29
+ }
30
+ }
@@ -2,4 +2,4 @@
2
2
  "compilerOptions": {
3
3
  "experimentalDecorators": true
4
4
  }
5
- }
5
+ }
@@ -58,3 +58,4 @@ export default [
58
58
  },
59
59
  },
60
60
  ];
61
+
@@ -28,7 +28,8 @@
28
28
  "element-plus": "^2.2.19",
29
29
  "vue": "^3.2.41",
30
30
  "vue-router": "^4.1.6",
31
- "web-base-client-vue": "^1.0.7",
31
+ "@ctzy-web-client/web-base-client-vue": "^1.0.7",
32
32
  "vite-plugin-qiankun": "^1.0.15"
33
33
  }
34
34
  }
35
+
@@ -1,5 +1,5 @@
1
1
  import { service } from '@ctzy-web-client/ioc-annotations';
2
- import { RequestInterceptors } from 'web-base-client-vue';
2
+ import { RequestInterceptors } from '@ctzy-web-client/web-base-client-vue';
3
3
 
4
4
  @service(RequestInterceptors)
5
5
  export default class AppRequestInterceptors extends RequestInterceptors {
@@ -48,3 +48,4 @@ export default class AppRequestInterceptors extends RequestInterceptors {
48
48
  return Promise.reject(new Error('请求错误'));
49
49
  }
50
50
  }
51
+
@@ -1,5 +1,5 @@
1
1
  import { service } from '@ctzy-web-client/ioc-annotations';
2
- import { RouterInterceptors } from 'web-base-client-vue';
2
+ import { RouterInterceptors } from '@ctzy-web-client/web-base-client-vue';
3
3
 
4
4
  @service(RouterInterceptors)
5
5
  export default class AppRouterInterceptors extends RouterInterceptors {
@@ -23,3 +23,4 @@ export default class AppRouterInterceptors extends RouterInterceptors {
23
23
  return next();
24
24
  }
25
25
  }
26
+
@@ -1,4 +1,4 @@
1
- import { Application } from 'web-base-client-vue';
1
+ import { Application } from '@ctzy-web-client/web-base-client-vue';
2
2
  import { qiankunWindow } from 'vite-plugin-qiankun/es/helper';
3
3
  import WebClientComponent from '@ctzy-web-client/plugin-component-vue';
4
4
  import "@ctzy-web-client/plugin-component-vue/style"
@@ -21,3 +21,4 @@ const applicaiton = new Application(appName, {
21
21
  });
22
22
 
23
23
  applicaiton.use(WebClientComponent).mount('#app');
24
+
@@ -1,4 +1,4 @@
1
- import { dataTable, tableColumn, dataForm, formColumn } from 'web-base-client-vue';
1
+ import { dataTable, tableColumn, dataForm, formColumn } from '@ctzy-web-client/web-base-client-vue';
2
2
 
3
3
  @dataTable({ name: 'test', title: '测试数据模型' })
4
4
  @dataForm({ name: 'test', title: '测试' })
@@ -43,3 +43,4 @@ export default class TestDataModel {
43
43
  @formColumn({ title: '状态' })
44
44
  status = '';
45
45
  }
46
+
@@ -76,7 +76,7 @@
76
76
  </template>
77
77
  <script>
78
78
  import { ref, reactive, watch, computed } from 'vue';
79
- import { useDataForm } from 'web-base-client-vue';
79
+ import { useDataForm } from '@ctzy-web-client/web-base-client-vue';
80
80
  import TestDataModel from '../../models/TestDataModel';
81
81
  export const route = '/form/:id?';
82
82
  export const parent = '';
@@ -108,7 +108,7 @@ export default {
108
108
  return;
109
109
  }
110
110
 
111
- // 隐藏选中列
111
+ // 隐藏选中�?
112
112
  dataForm.value.getColumn(columnNames[status - 1]).hide();
113
113
  }
114
114
  );
@@ -118,3 +118,4 @@ export default {
118
118
  };
119
119
  </script>
120
120
  <style scoped></style>
121
+
@@ -33,7 +33,7 @@
33
33
  </BwaDataTable>
34
34
  </template>
35
35
  <script>
36
- import { useService, useDataTable } from 'web-base-client-vue';
36
+ import { useService, useDataTable } from '@ctzy-web-client/web-base-client-vue';
37
37
  import TestServices from '../../services/TestServices';
38
38
  import TestDataModel from '../../models/TestDataModel';
39
39
  export const route = '/';
@@ -55,3 +55,4 @@ export default {
55
55
  };
56
56
  </script>
57
57
  <style scoped></style>
58
+
@@ -1,5 +1,5 @@
1
1
  import { service, inject } from '@ctzy-web-client/ioc-annotations';
2
- import { SimpleOrm } from 'web-base-client-vue';
2
+ import { SimpleOrm } from '@ctzy-web-client/web-base-client-vue';
3
3
  import TestDataModel from '../models/TestDataModel';
4
4
 
5
5
  /**
@@ -19,3 +19,4 @@ export default class TestServices {
19
19
  console.log(testDataList);
20
20
  }
21
21
  }
22
+
@@ -38,7 +38,7 @@ export default defineConfig(({ mode, command }) => {
38
38
  viteExternalsPlugin({
39
39
  'vue': "Vue",
40
40
  'vue-router': "VueRouter",
41
- "web-base-client-vue": "WebClientVue",
41
+ "@ctzy-web-client/web-base-client-vue": "WebClientVue",
42
42
  "@ctzy-web-client/plugin-component-vue": "WebClientPluginComponentVue",
43
43
  })
44
44
  );
@@ -3,3 +3,4 @@
3
3
  "experimentalDecorators": true
4
4
  }
5
5
  }
6
+
@@ -28,6 +28,7 @@
28
28
  "vite-plugin-qiankun": "^1.0.15",
29
29
  "vue": "^3.2.41",
30
30
  "vue-router": "^4.1.6",
31
- "web-base-client-vue": "^1.0.7"
31
+ "@ctzy-web-client/web-base-client-vue": "^1.0.7"
32
32
  }
33
33
  }
34
+
@@ -1,5 +1,5 @@
1
- import * as WebClientVue from 'web-base-client-vue';
2
- import { Application } from 'web-base-client-vue';
1
+ import * as WebClientVue from '@ctzy-web-client/web-base-client-vue';
2
+ import { Application } from '@ctzy-web-client/web-base-client-vue';
3
3
  import WebClientPluginComponentVue from '@ctzy-web-client/plugin-component-vue';
4
4
  import { qiankunWindow } from 'vite-plugin-qiankun/es/helper';
5
5
  import '@ctzy-web-client/plugin-component-vue/style/index.css';
@@ -19,3 +19,4 @@ const applicaiton = new Application('base', {
19
19
  });
20
20
 
21
21
  applicaiton.mount('#app');
22
+
@@ -3,7 +3,7 @@
3
3
  </template>
4
4
 
5
5
  <script setup>
6
- import { BwaMicroApplication } from 'web-base-client-vue';
6
+ import { BwaMicroApplication } from '@ctzy-web-client/web-base-client-vue';
7
7
 
8
8
  defineOptions({
9
9
  name: 'App',
@@ -13,3 +13,4 @@ defineOptions({
13
13
  <script>
14
14
  export const route = '/:appName*';
15
15
  </script>
16
+
@@ -4,3 +4,4 @@ import { service } from "@ctzy-web-client/ioc-annotations";
4
4
  export class ApplicationService {
5
5
 
6
6
  }
7
+
@@ -2,3 +2,4 @@ import { service } from '@ctzy-web-client/ioc-annotations';
2
2
 
3
3
  @service()
4
4
  export class UserService {}
5
+
@@ -16,3 +16,4 @@
16
16
  "vite": "^3.2.0"
17
17
  }
18
18
  }
19
+