@qse/edu-scripts 1.12.5 → 1.13.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/CHANGELOG.md +4 -0
- package/docs/debug.md +17 -0
- package/docs/refactor-react-16.md +1 -4
- package/lib/auto-refactor.js +1 -1
- package/lib/deploy.js +41 -12
- package/lib/utils/changeDeployVersion.js +14 -0
- package/package.json +1 -1
- package/src/auto-refactor.js +1 -1
- package/src/deploy.js +39 -11
- package/src/utils/changeDeployVersion.js +11 -0
- package/tsconfig.json +2 -1
package/CHANGELOG.md
CHANGED
package/docs/debug.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# 代码调试
|
|
2
|
+
|
|
3
|
+
## 使用 `React Developer Tools` 调试
|
|
4
|
+
|
|
5
|
+
1. 安装 `React Developer Tools` 插件
|
|
6
|
+
2. 打开控制台(F12)
|
|
7
|
+
3. 切换到 `Component` 标签页
|
|
8
|
+
4. 选中需要查看的组件,可以看到 `state/props/hooks` 等信息
|
|
9
|
+
|
|
10
|
+
## 使用 vscode 调试代码
|
|
11
|
+
|
|
12
|
+
1. 打开 `JavaScript Debug Terminal` 终端,输入 `npm run start` 命令启动项目。
|
|
13
|
+
|
|
14
|
+

|
|
15
|
+
|
|
16
|
+
2. 按住 `ctrl/command` 点击 `http://localhost:port` 打开链接
|
|
17
|
+
3. 代码里打断点,网页点击触发断点
|
|
@@ -19,11 +19,8 @@ frame 项目 react15 升级 react16 指南
|
|
|
19
19
|
```html
|
|
20
20
|
<script src="//static.qsepay.net/lib/react15.4.1_fastclick1.0.6_natty-storage2.0.2-fetch2.4.2_common2.js"></script>
|
|
21
21
|
|
|
22
|
-
将上面这条 CDN
|
|
22
|
+
将上面这条 CDN 替换成下面这条
|
|
23
23
|
|
|
24
|
-
<!-- 一般使用这条 -->
|
|
25
|
-
<script src="//static.qsepay.net/lib/react16.14_fastclick1.0.6_natty-storage2.0.2-fetch2.4.2_common31.js"></script>
|
|
26
|
-
<!-- 如果需要 axios 请使用这条 -->
|
|
27
24
|
<script src="//static.qsepay.net/lib/react16.14_fastclick1.0.6_natty-storage2.0.2-fetch2.4.2_axios0.21.1_common31.js"></script>
|
|
28
25
|
```
|
|
29
26
|
|
package/lib/auto-refactor.js
CHANGED
|
@@ -144,7 +144,7 @@ module.exports = async function autoRefactor() {
|
|
|
144
144
|
scripts.postversion = 'npm run build && npm run deploy';
|
|
145
145
|
});
|
|
146
146
|
await step('删除 babel/webpack 相关依赖', spinner => {
|
|
147
|
-
const deleteRe = /(babel|autoprefixer|webpack|loader|less|css|sass|hmr|ssh-sftp|regenerator-runtime|nowa)/i;
|
|
147
|
+
const deleteRe = /(babel|autoprefixer|webpack|loader|less|css|sass|hmr|ssh-sftp|regenerator-runtime|nowa|prettier)/i;
|
|
148
148
|
const deletePkgs = {
|
|
149
149
|
dependencies: [],
|
|
150
150
|
devDependencies: []
|
package/lib/deploy.js
CHANGED
|
@@ -71,6 +71,18 @@ async function normalDeploy(args) {
|
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
function dateTime() {
|
|
75
|
+
let date = new Date();
|
|
76
|
+
date = new Date(date.getTime() - date.getTimezoneOffset() * 60000);
|
|
77
|
+
return date.toISOString().replace(/T/, ' ').replace(/\..+/, '');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function updateLogContent(content, info) {
|
|
81
|
+
const lines = content.trim().split('\n');
|
|
82
|
+
lines.push(`[${dateTime()}] ${JSON.stringify(info)}\n`);
|
|
83
|
+
return lines.slice(0, 50).join('\n');
|
|
84
|
+
}
|
|
85
|
+
|
|
74
86
|
async function upload(opts) {
|
|
75
87
|
// 上传dist文件
|
|
76
88
|
const {
|
|
@@ -92,22 +104,39 @@ async function normalDeploy(args) {
|
|
|
92
104
|
// 创建本地临时文件夹,位置在 `opts.localPath` 下的 `__tmp__` 文件夹
|
|
93
105
|
fs.mkdirSync(tmpDir, {
|
|
94
106
|
recursive: true
|
|
95
|
-
}); // 拉取远程文件到本地
|
|
96
|
-
|
|
97
|
-
await sftp.fastGet(remoteFile, tmpFile); // 读取本地文件内容
|
|
98
|
-
|
|
99
|
-
let code = await fs.readFile(tmpFile, {
|
|
100
|
-
encoding: 'utf-8'
|
|
101
107
|
});
|
|
102
|
-
|
|
108
|
+
const info = {
|
|
103
109
|
name: pkg.name,
|
|
104
110
|
version: pkg.version,
|
|
105
111
|
grayscale: appConfig.grayscale
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
112
|
+
};
|
|
113
|
+
{
|
|
114
|
+
// 拉取远程文件到本地
|
|
115
|
+
await sftp.fastGet(remoteFile, tmpFile); // 读取本地文件内容
|
|
116
|
+
|
|
117
|
+
let code = await fs.readFile(tmpFile, {
|
|
118
|
+
encoding: 'utf-8'
|
|
119
|
+
});
|
|
120
|
+
code = changeDeployVersion(code, info);
|
|
121
|
+
await sftp.fastPut(tmpFile, remoteFile + '.bak');
|
|
122
|
+
await fs.writeFile(tmpFile, code); // 将修改完的内容传回服务器
|
|
123
|
+
|
|
124
|
+
await sftp.fastPut(tmpFile, remoteFile);
|
|
125
|
+
}
|
|
126
|
+
{
|
|
127
|
+
const remoteLogFile = remoteFile + '.log';
|
|
128
|
+
const tmpLogFile = tmpFile + '.log';
|
|
129
|
+
let content = '';
|
|
130
|
+
|
|
131
|
+
try {
|
|
132
|
+
await sftp.fastGet(remoteLogFile, tmpLogFile);
|
|
133
|
+
content = await fs.readFile(tmpLogFile, 'utf-8');
|
|
134
|
+
} catch (error) {}
|
|
135
|
+
|
|
136
|
+
content = updateLogContent(content, info);
|
|
137
|
+
await fs.writeFile(tmpLogFile, content);
|
|
138
|
+
await sftp.fastPut(tmpLogFile, remoteLogFile);
|
|
139
|
+
}
|
|
111
140
|
spinner.succeed('已更新 ver.js 版本配置');
|
|
112
141
|
} catch (e) {
|
|
113
142
|
spinner.fail(`自动修改 ver.js 失败,请手动修改`);
|
|
@@ -94,6 +94,19 @@ function changeDeployVersion(code, pkg) {
|
|
|
94
94
|
path.node.properties.push(t.objectProperty(t.identifier(keyName), t.stringLiteral(version)));
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* @param {babel.NodePath<t.ObjectExpression>} path
|
|
99
|
+
*/
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
function deleteModuleComments(path) {
|
|
103
|
+
path.traverse({
|
|
104
|
+
ObjectExpression(path) {
|
|
105
|
+
delete path.node.leadingComments;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
});
|
|
109
|
+
}
|
|
97
110
|
/**
|
|
98
111
|
* @param {babel.NodePath<t.VariableDeclarator>} path
|
|
99
112
|
*/
|
|
@@ -114,6 +127,7 @@ function changeDeployVersion(code, pkg) {
|
|
|
114
127
|
addModuleToTarget(targetPath);
|
|
115
128
|
}
|
|
116
129
|
|
|
130
|
+
deleteModuleComments(targetPath);
|
|
117
131
|
return format(generate(ast, {
|
|
118
132
|
minified: true
|
|
119
133
|
}).code, {
|
package/package.json
CHANGED
package/src/auto-refactor.js
CHANGED
|
@@ -134,7 +134,7 @@ module.exports = async function autoRefactor() {
|
|
|
134
134
|
|
|
135
135
|
await step('删除 babel/webpack 相关依赖', (spinner) => {
|
|
136
136
|
const deleteRe =
|
|
137
|
-
/(babel|autoprefixer|webpack|loader|less|css|sass|hmr|ssh-sftp|regenerator-runtime|nowa)/i
|
|
137
|
+
/(babel|autoprefixer|webpack|loader|less|css|sass|hmr|ssh-sftp|regenerator-runtime|nowa|prettier)/i
|
|
138
138
|
|
|
139
139
|
const deletePkgs = {
|
|
140
140
|
dependencies: [],
|
package/src/deploy.js
CHANGED
|
@@ -55,6 +55,17 @@ async function normalDeploy(args) {
|
|
|
55
55
|
return { tmpDir, tmpFile, remoteFile, tmpBase }
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
function dateTime() {
|
|
59
|
+
let date = new Date()
|
|
60
|
+
date = new Date(date.getTime() - date.getTimezoneOffset() * 60000)
|
|
61
|
+
return date.toISOString().replace(/T/, ' ').replace(/\..+/, '')
|
|
62
|
+
}
|
|
63
|
+
function updateLogContent(content, info) {
|
|
64
|
+
const lines = content.trim().split('\n')
|
|
65
|
+
lines.push(`[${dateTime()}] ${JSON.stringify(info)}\n`)
|
|
66
|
+
return lines.slice(0, 50).join('\n')
|
|
67
|
+
}
|
|
68
|
+
|
|
58
69
|
async function upload(opts) {
|
|
59
70
|
// 上传dist文件
|
|
60
71
|
const { sftp, opts: fullOpts } = await sshSftp(opts)
|
|
@@ -69,21 +80,38 @@ async function normalDeploy(args) {
|
|
|
69
80
|
// 创建本地临时文件夹,位置在 `opts.localPath` 下的 `__tmp__` 文件夹
|
|
70
81
|
fs.mkdirSync(tmpDir, { recursive: true })
|
|
71
82
|
|
|
72
|
-
|
|
73
|
-
await sftp.fastGet(remoteFile, tmpFile)
|
|
74
|
-
|
|
75
|
-
// 读取本地文件内容
|
|
76
|
-
let code = await fs.readFile(tmpFile, { encoding: 'utf-8' })
|
|
77
|
-
code = changeDeployVersion(code, {
|
|
83
|
+
const info = {
|
|
78
84
|
name: pkg.name,
|
|
79
85
|
version: pkg.version,
|
|
80
86
|
grayscale: appConfig.grayscale,
|
|
81
|
-
}
|
|
87
|
+
}
|
|
82
88
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
89
|
+
{
|
|
90
|
+
// 拉取远程文件到本地
|
|
91
|
+
await sftp.fastGet(remoteFile, tmpFile)
|
|
92
|
+
|
|
93
|
+
// 读取本地文件内容
|
|
94
|
+
let code = await fs.readFile(tmpFile, { encoding: 'utf-8' })
|
|
95
|
+
code = changeDeployVersion(code, info)
|
|
96
|
+
|
|
97
|
+
await sftp.fastPut(tmpFile, remoteFile + '.bak')
|
|
98
|
+
await fs.writeFile(tmpFile, code)
|
|
99
|
+
// 将修改完的内容传回服务器
|
|
100
|
+
await sftp.fastPut(tmpFile, remoteFile)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
{
|
|
104
|
+
const remoteLogFile = remoteFile + '.log'
|
|
105
|
+
const tmpLogFile = tmpFile + '.log'
|
|
106
|
+
let content = ''
|
|
107
|
+
try {
|
|
108
|
+
await sftp.fastGet(remoteLogFile, tmpLogFile)
|
|
109
|
+
content = await fs.readFile(tmpLogFile, 'utf-8')
|
|
110
|
+
} catch (error) {}
|
|
111
|
+
content = updateLogContent(content, info)
|
|
112
|
+
await fs.writeFile(tmpLogFile, content)
|
|
113
|
+
await sftp.fastPut(tmpLogFile, remoteLogFile)
|
|
114
|
+
}
|
|
87
115
|
|
|
88
116
|
spinner.succeed('已更新 ver.js 版本配置')
|
|
89
117
|
} catch (e) {
|
|
@@ -80,6 +80,16 @@ function changeDeployVersion(code, pkg) {
|
|
|
80
80
|
path.node.properties.push(t.objectProperty(t.identifier(keyName), t.stringLiteral(version)))
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* @param {babel.NodePath<t.ObjectExpression>} path
|
|
85
|
+
*/
|
|
86
|
+
function deleteModuleComments(path) {
|
|
87
|
+
path.traverse({
|
|
88
|
+
ObjectExpression(path) {
|
|
89
|
+
delete path.node.leadingComments
|
|
90
|
+
},
|
|
91
|
+
})
|
|
92
|
+
}
|
|
83
93
|
|
|
84
94
|
/**
|
|
85
95
|
* @param {babel.NodePath<t.VariableDeclarator>} path
|
|
@@ -105,6 +115,7 @@ function changeDeployVersion(code, pkg) {
|
|
|
105
115
|
} else {
|
|
106
116
|
addModuleToTarget(targetPath)
|
|
107
117
|
}
|
|
118
|
+
deleteModuleComments(targetPath)
|
|
108
119
|
|
|
109
120
|
return format(generate(ast, { minified: true }).code, {
|
|
110
121
|
parser: 'babel',
|