-
Notifications
You must be signed in to change notification settings - Fork 28
增加在线签名功能 #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
增加在线签名功能 #51
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import http from 'http' | ||
| import fs from 'fs' | ||
| import path from 'path' | ||
| import { URL } from 'url' | ||
| import { colorconsole } from '@hap-toolkit/shared-utils' | ||
|
|
||
| function SignOnlinePlugin(options) { | ||
| this.options = options | ||
| } | ||
|
|
||
| SignOnlinePlugin.prototype.apply = function (compiler) { | ||
| const options = this.options | ||
|
|
||
| compiler.hooks.done.tapAsync('SignOnlinePlugin', function (stats, cb) { | ||
| const requestPath = options.request | ||
| if (!requestPath || typeof requestPath !== 'string') { | ||
| colorconsole.error(`### App Server ### 请求线上接口无效,请检查`) | ||
| cb() | ||
| return | ||
| } | ||
| const ext = options.signOnlineRpks ? 'rpks' : 'rpk' | ||
| const pkgName = options.name | ||
| const versionName = options.versionName | ||
| const noSignFile = `${pkgName}.nosign.${versionName}.${ext}` | ||
|
|
||
| const noSignFilePath = path.join(options.output, noSignFile) | ||
|
|
||
| const distFileName = `${pkgName}.${options.sign}.${versionName}.${ext}` | ||
| const distFilePath = path.join(options.output, distFileName) | ||
| const distFileStream = fs.createWriteStream(distFilePath) | ||
|
|
||
| let form = null | ||
|
|
||
| const file = fs.createReadStream(noSignFilePath) | ||
|
|
||
| if (options.formData && options.formData(file)) { | ||
| form = options.formData(file) | ||
| } | ||
|
|
||
| form && Object.assign(options.headers(), form.getHeaders()) | ||
|
|
||
| const url = new URL(requestPath) | ||
| const param = { | ||
| host: url.hostname, | ||
| port: url.port, | ||
| path: url.pathname, | ||
| method: 'POST', | ||
| timeout: 10000, | ||
| headers: options.headers | ||
| } | ||
| const req = http | ||
| .request(param, (res) => { | ||
| colorconsole.log(`### App Loader ### 请求接口的状态码:${res.statusCode}`) | ||
| res.pipe(distFileStream, { end: false }) | ||
| res.on('end', (data) => { | ||
| if (res.statusCode === 200) { | ||
| distFileStream.end() | ||
| colorconsole.log( | ||
| `### App Loader ### 请求线上签名成功,dist目录生成文件:${distFileName}` | ||
| ) | ||
| cb() | ||
| } | ||
| }) | ||
| }) | ||
| .on('error', (err) => { | ||
| colorconsole.error(`### App Server ### 请求线上签名错误,错误信息: ${err.message} $`) | ||
| cb(err) | ||
| }) | ||
| .on('timeout', function () { | ||
| colorconsole.warn( | ||
| `### App Server ### 请求线上签名网络超时,请检查网络与接口地址 ${ | ||
| form | ||
| ? '' | ||
| : '缺少FormData对象,请在配置文件quickapp.config.js里面定义的params函数返回FormData对象' | ||
| }` | ||
| ) | ||
| req.abort() | ||
| }) | ||
| form && form.pipe(req) | ||
| }) | ||
| } | ||
|
|
||
| export default SignOnlinePlugin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.