This repository has been archived by the owner on Jan 8, 2023. It is now read-only.
generated from arvinxx/umi-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
353 additions
and
111 deletions.
There are no files selected for viewing
This file contains 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 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 was deleted.
Oops, something went wrong.
This file contains 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 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 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 |
---|---|---|
|
@@ -3,4 +3,4 @@ title: 介绍 | |
order: 1 | ||
--- | ||
|
||
# umi-plugin-develop-template | ||
# umi-plugin-figma |
This file contains 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,2 @@ | ||
console.log('test umi plugin figma'); | ||
figma.closePlugin('Hello, World!'); |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains 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 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,39 @@ | ||
import type { IApi, IRoute } from 'umi'; | ||
|
||
/** | ||
* 将 umi 的配置修改成可以用于生成插件文件的状态 | ||
* @param api | ||
*/ | ||
export default (api: IApi) => { | ||
api.modifyConfig((config) => { | ||
// 需要将页面按照 mpa 进行打包输出 | ||
config.mpa = {}; | ||
|
||
// 导出的 HTML 路由需要带 html 后缀 | ||
config.exportStatic = { | ||
htmlSuffix: true, | ||
}; | ||
|
||
// const { figma } = config; | ||
|
||
config.devServer = { | ||
...config.devServer, | ||
// 将插件所需的文件全部写入到 dist 目录 | ||
writeToDisk: (filePath) => { | ||
const isUmiFile = filePath.match(/umi\./); | ||
const isHotUpdateFile = filePath.match(/hot-update\.js.*/); | ||
return !(isUmiFile || isHotUpdateFile); | ||
}, | ||
}; | ||
|
||
return config; | ||
}); | ||
|
||
api.chainWebpack((config) => { | ||
// 删除 hmr 插件 | ||
// 保证figma 本地可正常执行 | ||
config.plugins.delete('hmr'); | ||
|
||
return config; | ||
}); | ||
}; |
This file contains 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,71 @@ | ||
import type { IApi } from 'umi'; | ||
import { join } from 'path'; | ||
import fse from 'fs-extra'; | ||
import { baseDevURL, isDev } from '../utils'; | ||
|
||
declare module 'umi' { | ||
interface BaseIConfig { | ||
figma: Manifest; | ||
} | ||
} | ||
|
||
/** | ||
* 定义插件结构 | ||
* @param api | ||
*/ | ||
export default (api: IApi) => { | ||
const pkg = fse.readJSONSync( | ||
join(api.paths.absSrcPath!, '..', 'package.json'), | ||
); | ||
|
||
// figma 插件结构 | ||
api.describe({ | ||
key: 'figma', | ||
config: { | ||
default: { | ||
name: pkg.name || 'umi extension figma', | ||
api: '1.0.0', | ||
main: '@/figma/main', | ||
id: 'umi-plugin-develop-figma', | ||
}, | ||
/** | ||
* 校验器 | ||
* @param joi | ||
*/ | ||
schema(joi) { | ||
const separator = joi.object({ | ||
separator: joi.boolean().truthy(), | ||
}); | ||
const basicMenuItem = joi.object({ | ||
name: joi.string().required(), | ||
command: joi.string().required(), | ||
}); | ||
const SubMenu = joi.object({ | ||
name: joi.string().required(), | ||
menu: joi.object().required(), | ||
}); | ||
|
||
const menuItem = joi.alternatives(basicMenuItem, separator, SubMenu); | ||
|
||
const relaunchButton = joi.object({ | ||
command: joi.string().required(), | ||
name: joi.string().required(), | ||
multipleSelection: joi.boolean(), | ||
}); | ||
|
||
return joi.object({ | ||
name: joi.string().required(), | ||
id: joi.string().required(), | ||
api: joi.string().required(), | ||
main: joi.string().required(), | ||
ui: joi.alternatives(joi.string(), joi.object()), | ||
menu: joi.array().items(menuItem), | ||
relaunchButtons: joi.array().items(relaunchButton), | ||
enableProposedApi: joi.boolean(), | ||
enablePrivatePluginApi: joi.boolean(), | ||
build: joi.string(), | ||
}); | ||
}, | ||
}, | ||
}); | ||
}; |
This file contains 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 |
---|---|---|
@@ -1 +1,5 @@ | ||
export { default as DevHTML } from './devHTML'; | ||
export { default as ManifestGenerator } from './manifest'; | ||
export { default as ConfigSchema } from './config'; | ||
export { default as BaseConfig } from './base'; | ||
export { default as MainScript } from './main'; |
This file contains 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,35 @@ | ||
import { join } from 'path'; | ||
import fse from 'fs-extra'; | ||
import type { IApi } from 'umi'; | ||
|
||
/** | ||
* 将 background 添加到打包对象中 | ||
* 并在输出结果中添加 background 脚本 | ||
* @param api | ||
*/ | ||
export default (api: IApi) => { | ||
const { paths } = api.service; | ||
|
||
api.chainWebpack((config) => { | ||
const { main } = <Manifest>api.config.figma; | ||
|
||
// 将 main 作为一个入口插入打包对象中 | ||
|
||
config.entry('main').add(main); | ||
return config; | ||
}); | ||
|
||
const replaceOutputBackgroundPath = () => { | ||
const filepath = join(paths.absOutputPath!, 'manifest.json'); | ||
|
||
const manifest: Manifest = fse.readJSONSync(filepath); | ||
|
||
if (manifest.main) { | ||
manifest.main = 'main.js'; | ||
} | ||
|
||
fse.writeJSONSync(filepath, manifest); | ||
}; | ||
api.onDevCompileDone(replaceOutputBackgroundPath); | ||
api.onBuildComplete(replaceOutputBackgroundPath); | ||
}; |
This file contains 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,18 @@ | ||
import type { IApi } from 'umi'; | ||
import GenerateJsonPlugin from 'generate-json-webpack-plugin'; | ||
|
||
/** | ||
* 生成 manifest.json 文件 | ||
* @param api | ||
*/ | ||
export default (api: IApi) => { | ||
api.chainWebpack((config) => { | ||
const manifest = <Manifest>api.config.figma; | ||
|
||
config | ||
.plugin('toJSON') | ||
.use(GenerateJsonPlugin, ['manifest.json', manifest]); | ||
|
||
return config; | ||
}); | ||
}; |
Oops, something went wrong.