mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
Inject commit hash to registry
This commit is contained in:
parent
39df9d6ca7
commit
5c80c0af46
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
## 搭建开发环境
|
## 搭建开发环境
|
||||||
|
|
||||||
- 需要安装 [Node.js](https://nodejs.org/en/download/), [Visual Studio Code](https://code.visualstudio.com/) 和 [yarn](https://yarnpkg.com/getting-started/install#global-install).
|
- 需要安装 [Node.js](https://nodejs.org/en/download/) (>= 14.0), [Visual Studio Code](https://code.visualstudio.com/) 和 [yarn](https://yarnpkg.com/getting-started/install#global-install).
|
||||||
- 将项目 Fork 至自己账户后, 克隆至本地
|
- 将项目 Fork 至自己账户后, 克隆至本地
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
|
|||||||
@ -193,6 +193,8 @@ export interface ComponentMetadata extends FunctionalMetadata {
|
|||||||
i18n?: Record<string, LanguagePack>
|
i18n?: Record<string, LanguagePack>
|
||||||
/** 作者信息 */
|
/** 作者信息 */
|
||||||
author?: Author | Author[]
|
author?: Author | Author[]
|
||||||
|
/** 编译时的 commit hash, 由 Babel 注入, 不需要手动填写 */
|
||||||
|
commitHash?: string
|
||||||
}
|
}
|
||||||
/** 用户组件的非函数基本信息, 用于直接保存为 JSON */
|
/** 用户组件的非函数基本信息, 用于直接保存为 JSON */
|
||||||
export type UserComponentMetadata = Omit<ComponentMetadata, keyof FunctionalMetadata>
|
export type UserComponentMetadata = Omit<ComponentMetadata, keyof FunctionalMetadata>
|
||||||
|
|||||||
28
webpack/commit-hash.js
Normal file
28
webpack/commit-hash.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
const { compilationInfo } = require('./compilation-info')
|
||||||
|
const nodePath = require('path')
|
||||||
|
|
||||||
|
module.exports = function (babel) {
|
||||||
|
const { types } = babel
|
||||||
|
return {
|
||||||
|
visitor: {
|
||||||
|
ExportNamedDeclaration(path, state) {
|
||||||
|
const { filename } = state.file.opts
|
||||||
|
const isFromRegistry = filename.startsWith(nodePath.resolve('./registry'))
|
||||||
|
const isEntryFile = nodePath.basename(filename) === 'index.ts'
|
||||||
|
if (!(isFromRegistry && isEntryFile)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const { node } = path
|
||||||
|
node.declaration?.declarations?.forEach(d => {
|
||||||
|
if (!['component', 'plugin'].includes(d.id?.name)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (d.init.type !== 'ObjectExpression') {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
d.init.properties.push(types.objectProperty(types.identifier('commitHash'), types.stringLiteral(compilationInfo.commitHash)))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -14,6 +14,7 @@ const babelLoader = {
|
|||||||
],
|
],
|
||||||
plugins: [
|
plugins: [
|
||||||
['@babel/plugin-proposal-class-properties'],
|
['@babel/plugin-proposal-class-properties'],
|
||||||
|
'./webpack/commit-hash.js',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user