meixifrontserve 0.6.94 → 0.6.96

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.
@@ -1,93 +1,93 @@
1
- #! /usr/bin/env node
2
- const ServerController = require('./serveController')
3
- const urlConfig = require('../config/urlConfig');
4
-
5
- const getEnvFileTemplate = require('../config/envFileTemplate')
6
- const path = require("path");
7
- const fs = require('fs');
8
- const packageJson = require("../config/package.json");
9
- const childProcess = require("child_process");
10
- const {exec} = childProcess;
11
- const shell = require('shelljs');
12
-
13
- // 打包环境
14
- class EnvByBuildController extends ServerController {
15
-
16
- constructor(projectName, envType) {
17
- super(projectName);
18
- this.port = 8888;
19
- this.envName = '';
20
- this.envType = envType;
21
-
22
- this.urlConfig = null;
23
-
24
- }
25
-
26
- async onStart() {
27
- await super.onStart();
28
- this.onRunServe();
29
- }
30
-
31
-
32
- async createEnvFiles() {
33
- this.urlConfig = urlConfig[`${this.verName}`];
34
-
35
- console.log(this.urlConfig);
36
-
37
- let envFileParams = {
38
- envName: this.envName,
39
- proxy: '/proxy',
40
- systemId: this.projectParams.systemId,
41
- systemName: this.projectParams.systemName,
42
- apiUrl: '/api/',
43
- systemUrl: this.getSystemUrl(),
44
- authUrl: this.urlConfig.authUrl,
45
- wsUrl: this.urlConfig.wsUrl,
46
- verName: this.verName,
47
- }
48
- return getEnvFileTemplate(envFileParams);
49
-
50
- }
51
-
52
-
53
- async getServerPort() {
54
-
55
- let flag = await this.isPortAvailable(this.port);
56
-
57
- if (!flag) {
58
- this.port += 1;
59
- return false;
60
- }
61
- return true;
62
-
63
- }
64
-
65
-
66
- writeEnvFile(fileContent) {
67
- const press = process.cwd();
68
- const fileUrl = path.join(press, `./.env.${this.envType}`);
69
- fs.writeFileSync(fileUrl, fileContent);
70
-
71
- }
72
-
73
-
74
- onRunServe() {
75
- console.log('正在下载依赖');
76
- exec('npm install --legacy-peer-deps', async (error, stdout, stderr) => {
77
- console.log(error);
78
- if (!error) {
79
- shell.exec(`npm run build:${this.envType}`, (error, stdout, stderr) => {
80
- console.log(error);
81
- })
82
- } else {
83
- console.error('依赖下载失败!')
84
- }
85
- });
86
-
87
- }
88
-
89
-
90
- }
91
-
92
-
93
- module.exports = EnvByBuildController;
1
+ #! /usr/bin/env node
2
+ const ServerController = require('./serveController')
3
+ const urlConfig = require('../config/urlConfig');
4
+
5
+ const getEnvFileTemplate = require('../config/envFileTemplate')
6
+ const path = require("path");
7
+ const fs = require('fs');
8
+ const packageJson = require("../config/package.json");
9
+ const childProcess = require("child_process");
10
+ const {exec} = childProcess;
11
+ const shell = require('shelljs');
12
+
13
+ // 打包环境
14
+ class EnvByBuildController extends ServerController {
15
+
16
+ constructor(projectName, envType) {
17
+ super(projectName);
18
+ this.port = 8888;
19
+ this.envName = '';
20
+ this.envType = envType;
21
+
22
+ this.urlConfig = null;
23
+
24
+ }
25
+
26
+ async onStart() {
27
+ await super.onStart();
28
+ this.onRunServe();
29
+ }
30
+
31
+
32
+ async createEnvFiles() {
33
+ this.urlConfig = urlConfig[`${this.verName}`];
34
+
35
+ console.log(this.urlConfig);
36
+
37
+ let envFileParams = {
38
+ envName: this.envName,
39
+ proxy: '/proxy',
40
+ systemId: this.projectParams.systemId,
41
+ systemName: this.projectParams.systemName,
42
+ apiUrl: '/api/',
43
+ systemUrl: this.getSystemUrl(),
44
+ authUrl: this.urlConfig.authUrl,
45
+ wsUrl: this.urlConfig.wsUrl,
46
+ verName: this.verName,
47
+ }
48
+ return getEnvFileTemplate(envFileParams);
49
+
50
+ }
51
+
52
+
53
+ async getServerPort() {
54
+
55
+ let flag = await this.isPortAvailable(this.port);
56
+
57
+ if (!flag) {
58
+ this.port += 1;
59
+ return false;
60
+ }
61
+ return true;
62
+
63
+ }
64
+
65
+
66
+ writeEnvFile(fileContent) {
67
+ const press = process.cwd();
68
+ const fileUrl = path.join(press, `./.env.${this.envType}`);
69
+ fs.writeFileSync(fileUrl, fileContent);
70
+
71
+ }
72
+
73
+
74
+ onRunServe() {
75
+ console.log('正在下载依赖');
76
+ exec('npm install --legacy-peer-deps', async (error, stdout, stderr) => {
77
+ console.log(error);
78
+ if (!error) {
79
+ shell.exec(`npm run build:${this.envType}`, (error, stdout, stderr) => {
80
+ console.log(error);
81
+ })
82
+ } else {
83
+ console.error('依赖下载失败!')
84
+ }
85
+ });
86
+
87
+ }
88
+
89
+
90
+ }
91
+
92
+
93
+ module.exports = EnvByBuildController;
@@ -1,21 +1,21 @@
1
- const EnvByBuildController = require('./envByBuildController');
2
-
3
-
4
- class EnvByPreController extends EnvByBuildController {
5
- constructor(projectName, envType) {
6
- super(projectName, envType);
7
- this.envName = 'preview'
8
- this.envType = 'pre'
9
- this.verName = 'pre'
10
- }
11
-
12
-
13
- getSystemUrl() {
14
- this.urlConfig.urlPrefixes.splice(1, 0, this.projectParams.urlPrefix[`${this.envType}`]);
15
- return this.urlConfig.urlPrefixes.toString().replace(/,/g, '.');
16
- }
17
-
18
- }
19
-
20
-
21
- module.exports = EnvByPreController;
1
+ const EnvByBuildController = require('./envByBuildController');
2
+
3
+
4
+ class EnvByPreController extends EnvByBuildController {
5
+ constructor(projectName, envType) {
6
+ super(projectName, envType);
7
+ this.envName = 'preview'
8
+ this.envType = 'pre'
9
+ this.verName = 'pre'
10
+ }
11
+
12
+
13
+ getSystemUrl() {
14
+ this.urlConfig.urlPrefixes.splice(1, 0, this.projectParams.urlPrefix[`${this.envType}`]);
15
+ return this.urlConfig.urlPrefixes.toString().replace(/,/g, '.');
16
+ }
17
+
18
+ }
19
+
20
+
21
+ module.exports = EnvByPreController;
@@ -1,20 +1,20 @@
1
- const EnvByBuildController = require('./envByBuildController');
2
-
3
-
4
- class EnvByProdController extends EnvByBuildController {
5
- constructor(projectName, envType) {
6
- super(projectName, envType);
7
- this.envName = 'production'
8
- this.envType = 'prod'
9
- this.verName = 'prod'
10
- }
11
-
12
-
13
- getSystemUrl() {
14
- this.urlConfig.urlPrefixes.splice(0, 0, this.projectParams.urlPrefix[`${this.envType}`]);
15
- return this.urlConfig.urlPrefixes.toString().replace(/,/g, '.');
16
- }
17
- }
18
-
19
-
20
- module.exports = EnvByProdController
1
+ const EnvByBuildController = require('./envByBuildController');
2
+
3
+
4
+ class EnvByProdController extends EnvByBuildController {
5
+ constructor(projectName, envType) {
6
+ super(projectName, envType);
7
+ this.envName = 'production'
8
+ this.envType = 'prod'
9
+ this.verName = 'prod'
10
+ }
11
+
12
+
13
+ getSystemUrl() {
14
+ this.urlConfig.urlPrefixes.splice(0, 0, this.projectParams.urlPrefix[`${this.envType}`]);
15
+ return this.urlConfig.urlPrefixes.toString().replace(/,/g, '.');
16
+ }
17
+ }
18
+
19
+
20
+ module.exports = EnvByProdController
@@ -1,21 +1,21 @@
1
- const EnvByBuildController = require('./envByBuildController');
2
-
3
-
4
- class EnvByTest2Controller extends EnvByBuildController {
5
- constructor(projectName, envType) {
6
- super(projectName, envType);
7
- this.envName = 'testing'
8
- this.envType = 'testing'
9
- this.verName = 'test2ing'
10
- }
11
-
12
-
13
- getSystemUrl() {
14
- this.urlConfig.urlPrefixes.splice(1, 0, this.projectParams.urlPrefix[`${this.envType}`]);
15
- return this.urlConfig.urlPrefixes.toString().replace(/,/g, '.');
16
- }
17
-
18
- }
19
-
20
-
21
- module.exports = EnvByTest2Controller;
1
+ const EnvByBuildController = require('./envByBuildController');
2
+
3
+
4
+ class EnvByTest2Controller extends EnvByBuildController {
5
+ constructor(projectName, envType) {
6
+ super(projectName, envType);
7
+ this.envName = 'testing'
8
+ this.envType = 'testing'
9
+ this.verName = 'test2ing'
10
+ }
11
+
12
+
13
+ getSystemUrl() {
14
+ this.urlConfig.urlPrefixes.splice(1, 0, this.projectParams.urlPrefix[`${this.envType}`]);
15
+ return this.urlConfig.urlPrefixes.toString().replace(/,/g, '.');
16
+ }
17
+
18
+ }
19
+
20
+
21
+ module.exports = EnvByTest2Controller;
@@ -1,178 +1,178 @@
1
- // rollupBuild打包
2
- // umd.js
3
- const path = require("path");
4
- const fs = require("fs");
5
- const child_process = require("child_process");
6
- const needle = require("needle");
7
- const {error} = require("shelljs");
8
- const {apiConfig, ossBuckConfig} = require("./apiConfig");
9
-
10
- class RollupBuildController {
11
- constructor(env) {
12
-
13
- this.rollupBuildTarget = null;
14
- this.commandStr = null;
15
- this.env = env;
16
-
17
- }
18
-
19
-
20
- beforeRunServe() {
21
- let flag = true;
22
-
23
- // 获取配置的文件信息
24
- const press = process.cwd();
25
- let configPath = path.join(press, './rollupBuildTarget.json');
26
-
27
- // 判断是否存在文件
28
- flag = fs.existsSync('./rollupBuildTarget.json');
29
- if (flag) {
30
- this.rollupBuildTarget = JSON.parse(fs.readFileSync(configPath).toString());
31
- let str = ''
32
- for (let rollupBuildTargetKey in this.rollupBuildTarget) {
33
- let paramsStr = `${this.rollupBuildTarget[`${rollupBuildTargetKey}`][`source`]}-lib/${rollupBuildTargetKey}.umd.js`
34
- if (!str) {
35
- str += `${this.checkPlatform()} / --pathTarget ${paramsStr}`
36
- } else {
37
- str += `-${paramsStr}`
38
- }
39
- this.commandStr = str;
40
- console.log(str);
41
- }
42
- }
43
-
44
-
45
- return flag;
46
- }
47
-
48
- runServe() {
49
- if (this.beforeRunServe()) {
50
- child_process.exec(`${this.commandStr}`, async (error, stdout, statusbar) => {
51
-
52
-
53
- console.log(error);
54
-
55
- if (!error) {
56
- console.log('开始准备上传文件');
57
- const press = process.cwd();
58
- for (let rollupBuildTargetKey in this.rollupBuildTarget) {
59
- let configPath = path.join(press, `./lib/${rollupBuildTargetKey}.umd.js`);
60
- let fileContent = fs.readFileSync(configPath);
61
- try {
62
- let ossParams = await this.netApiToAuth();
63
- let ossUrl = await this.netToFileToOss(ossParams, fileContent, rollupBuildTargetKey);
64
-
65
- if (ossUrl) {
66
- // 调用微模块管理接口
67
- await this.netToMicoModuleAPi(ossUrl, rollupBuildTargetKey)
68
-
69
- }
70
- } catch (error) {
71
- console.log(error);
72
- }
73
-
74
- }
75
- } else {
76
- //
77
- console.log('微模块打包失败!')
78
- }
79
- })
80
-
81
- } else {
82
- console.log('当前无微模块打包');
83
- process.exit();
84
- }
85
-
86
- }
87
-
88
-
89
- // 获取oss上传的key
90
- netApiToAuth() {
91
- const date = new Date();
92
- let time = `${date.getFullYear()}${date.getMonth() + 1}${date.getDate()}`
93
- return new Promise((resolve, reject) => {
94
- console.log(`${apiConfig[`${this.env}`]}/files/osssource/common/oss/policy`)
95
- needle.post(`${apiConfig[`${this.env}`]}/files/osssource/common/oss/policy`, {
96
- filepath: `${ossBuckConfig[`${this.env}`]}${time}`
97
- }, (error, res) => {
98
- console.log(error);
99
- if (!error) {
100
- resolve(res.body.data);
101
- }
102
-
103
- });
104
-
105
- })
106
-
107
- }
108
-
109
- // 上传至oss
110
- netToFileToOss(ossParams, fileContent, fileName) {
111
-
112
- return new Promise((resolve, reject) => {
113
- let {accessKeyId, signature, host, policy, dir} = ossParams;
114
- const key = `${dir}/${fileName}`
115
- const ossUrl = `${host}/${key}`
116
-
117
- needle.post(host, {
118
- OSSAccessKeyId: accessKeyId,
119
- signature: signature,
120
- policy: policy,
121
- key: key,
122
- url: host,
123
- success_action_status: "200",
124
- file: fileContent.toLocaleString()
125
- }, {
126
- multipart: true,
127
- }, (error, res) => {
128
- if (!error) {
129
- // 返回文件的路径
130
- resolve(ossUrl);
131
- } else {
132
- resolve(false);
133
- }
134
- });
135
- })
136
-
137
-
138
- }
139
-
140
-
141
- //
142
- netToMicoModuleAPi(ossUrl, rollupBuildTargetKey) {
143
- return new Promise((resolve, reject) => {
144
- console.log('开始调用微模块管理接口')
145
- const ver = new Date().valueOf();
146
- needle.post(`${apiConfig[`${this.env}`]}/admin/client/backlog/front/code/record`, {
147
- tag: rollupBuildTargetKey,
148
- version: ver,
149
- downloadUrl: ossUrl
150
- }, {
151
- headers: {'content-type': 'application/json'}
152
- }, (error, res) => {
153
- if (!error) {
154
- resolve(true);
155
- } else {
156
- resolve(false);
157
- }
158
- });
159
- })
160
-
161
- }
162
-
163
-
164
- checkPlatform() {
165
- switch (process.platform) {
166
- case 'darwin':
167
- return 'sudo meixirollupbuild -b'
168
- case "win32":
169
- return 'meixirollupbuild -b'
170
- default:
171
- return 'meixirollupbuild -b'
172
- }
173
- }
174
-
175
- }
176
-
177
-
178
- module.exports = RollupBuildController;
1
+ // rollupBuild打包
2
+ // umd.js
3
+ const path = require("path");
4
+ const fs = require("fs");
5
+ const child_process = require("child_process");
6
+ const needle = require("needle");
7
+ const {error} = require("shelljs");
8
+ const {apiConfig, ossBuckConfig} = require("./apiConfig");
9
+
10
+ class RollupBuildController {
11
+ constructor(env) {
12
+
13
+ this.rollupBuildTarget = null;
14
+ this.commandStr = null;
15
+ this.env = env;
16
+
17
+ }
18
+
19
+
20
+ beforeRunServe() {
21
+ let flag = true;
22
+
23
+ // 获取配置的文件信息
24
+ const press = process.cwd();
25
+ let configPath = path.join(press, './rollupBuildTarget.json');
26
+
27
+ // 判断是否存在文件
28
+ flag = fs.existsSync('./rollupBuildTarget.json');
29
+ if (flag) {
30
+ this.rollupBuildTarget = JSON.parse(fs.readFileSync(configPath).toString());
31
+ let str = ''
32
+ for (let rollupBuildTargetKey in this.rollupBuildTarget) {
33
+ let paramsStr = `${this.rollupBuildTarget[`${rollupBuildTargetKey}`][`source`]}-lib/${rollupBuildTargetKey}.umd.js`
34
+ if (!str) {
35
+ str += `${this.checkPlatform()} / --pathTarget ${paramsStr}`
36
+ } else {
37
+ str += `-${paramsStr}`
38
+ }
39
+ this.commandStr = str;
40
+ console.log(str);
41
+ }
42
+ }
43
+
44
+
45
+ return flag;
46
+ }
47
+
48
+ runServe() {
49
+ if (this.beforeRunServe()) {
50
+ child_process.exec(`${this.commandStr}`, async (error, stdout, statusbar) => {
51
+
52
+
53
+ console.log(error);
54
+
55
+ if (!error) {
56
+ console.log('开始准备上传文件');
57
+ const press = process.cwd();
58
+ for (let rollupBuildTargetKey in this.rollupBuildTarget) {
59
+ let configPath = path.join(press, `./lib/${rollupBuildTargetKey}.umd.js`);
60
+ let fileContent = fs.readFileSync(configPath);
61
+ try {
62
+ let ossParams = await this.netApiToAuth();
63
+ let ossUrl = await this.netToFileToOss(ossParams, fileContent, rollupBuildTargetKey);
64
+
65
+ if (ossUrl) {
66
+ // 调用微模块管理接口
67
+ await this.netToMicoModuleAPi(ossUrl, rollupBuildTargetKey)
68
+
69
+ }
70
+ } catch (error) {
71
+ console.log(error);
72
+ }
73
+
74
+ }
75
+ } else {
76
+ //
77
+ console.log('微模块打包失败!')
78
+ }
79
+ })
80
+
81
+ } else {
82
+ console.log('当前无微模块打包');
83
+ process.exit();
84
+ }
85
+
86
+ }
87
+
88
+
89
+ // 获取oss上传的key
90
+ netApiToAuth() {
91
+ const date = new Date();
92
+ let time = `${date.getFullYear()}${date.getMonth() + 1}${date.getDate()}`
93
+ return new Promise((resolve, reject) => {
94
+ console.log(`${apiConfig[`${this.env}`]}/files/osssource/common/oss/policy`)
95
+ needle.post(`${apiConfig[`${this.env}`]}/files/osssource/common/oss/policy`, {
96
+ filepath: `${ossBuckConfig[`${this.env}`]}${time}`
97
+ }, (error, res) => {
98
+ console.log(error);
99
+ if (!error) {
100
+ resolve(res.body.data);
101
+ }
102
+
103
+ });
104
+
105
+ })
106
+
107
+ }
108
+
109
+ // 上传至oss
110
+ netToFileToOss(ossParams, fileContent, fileName) {
111
+
112
+ return new Promise((resolve, reject) => {
113
+ let {accessKeyId, signature, host, policy, dir} = ossParams;
114
+ const key = `${dir}/${fileName}`
115
+ const ossUrl = `${host}/${key}`
116
+
117
+ needle.post(host, {
118
+ OSSAccessKeyId: accessKeyId,
119
+ signature: signature,
120
+ policy: policy,
121
+ key: key,
122
+ url: host,
123
+ success_action_status: "200",
124
+ file: fileContent.toLocaleString()
125
+ }, {
126
+ multipart: true,
127
+ }, (error, res) => {
128
+ if (!error) {
129
+ // 返回文件的路径
130
+ resolve(ossUrl);
131
+ } else {
132
+ resolve(false);
133
+ }
134
+ });
135
+ })
136
+
137
+
138
+ }
139
+
140
+
141
+ //
142
+ netToMicoModuleAPi(ossUrl, rollupBuildTargetKey) {
143
+ return new Promise((resolve, reject) => {
144
+ console.log('开始调用微模块管理接口')
145
+ const ver = new Date().valueOf();
146
+ needle.post(`${apiConfig[`${this.env}`]}/admin/client/backlog/front/code/record`, {
147
+ tag: rollupBuildTargetKey,
148
+ version: ver,
149
+ downloadUrl: ossUrl
150
+ }, {
151
+ headers: {'content-type': 'application/json'}
152
+ }, (error, res) => {
153
+ if (!error) {
154
+ resolve(true);
155
+ } else {
156
+ resolve(false);
157
+ }
158
+ });
159
+ })
160
+
161
+ }
162
+
163
+
164
+ checkPlatform() {
165
+ switch (process.platform) {
166
+ case 'darwin':
167
+ return 'sudo meixirollupbuild -b'
168
+ case "win32":
169
+ return 'meixirollupbuild -b'
170
+ default:
171
+ return 'meixirollupbuild -b'
172
+ }
173
+ }
174
+
175
+ }
176
+
177
+
178
+ module.exports = RollupBuildController;