Skip to content
This repository has been archived by the owner on Jan 8, 2023. It is now read-only.

Commit

Permalink
🎉 chore: 初始化
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Feb 15, 2021
1 parent 352296f commit e2d67a9
Show file tree
Hide file tree
Showing 20 changed files with 353 additions and 111 deletions.
2 changes: 1 addition & 1 deletion .changelogrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module.exports = {
scopeDisplayName: {
'*': '杂项',
script: '脚本',
scripts: '脚本',
changelog: '日志',
Expand All @@ -9,4 +8,5 @@ module.exports = {
types: '类型',
readme: '说明文档',
},
titleLanguage: 'zh-CN',
};
17 changes: 4 additions & 13 deletions .releaserc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,11 @@ module.exports = {
'@semantic-release/changelog', //此处会调用上一个插件生成的新增日志,然后合并到原有日志中
{
changelogFile: 'CHANGELOG.md',
changelogTitle: '# umi-chrome-extensions-template 更新日志',
changelogTitle: '# 更新日志',
},
],
'@semantic-release/npm', //如果是npm包会自动更新版本号并发布
[
'@semantic-release/github',
{
assets: [
{
path: 'dist-zip/release.zip',
label: 'release.${nextRelease.gitTag}.zip',
},
],
},
], // 推送代码回到GitHub
['@semantic-release/github'], // 推送代码回到GitHub
[
'@semantic-release/git', //发布release
{
Expand All @@ -43,7 +33,8 @@ module.exports = {
'CHANGELOG.md',
'package.json',
],
message: ':bookmark: chore(release): v${nextRelease.version} [skip ci]',
message:
':bookmark: chore(release): v${nextRelease.version} [skip ci]\n\n ${nextRelease.notes}',
},
],
],
Expand Down
68 changes: 0 additions & 68 deletions CHANGELOG.md

This file was deleted.

16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

[![Test CI status][test-ci]][test-ci-url] [![Release CI][release-ci]][deploy-ci-url] [![Coverage][coverage]][codecov-url]

[version-url]: https://img.shields.io/github/v/release/arvinxx/umi-plugin-develop-template
[license-url]: https://img.shields.io/github/license/arvinxx/umi-plugin-develop-template
[version-url]: https://img.shields.io/github/v/release/arvinxx/umi-plugin-figma
[license-url]: https://img.shields.io/github/license/arvinxx/umi-plugin-figma

<!-- semantic-release -->

Expand All @@ -14,15 +14,15 @@

<!-- coverage -->

[coverage]: https://codecov.io/gh/arvinxx/umi-plugin-develop-template/branch/master/graph/badge.svg
[codecov-url]: https://codecov.io/gh/arvinxx/umi-plugin-develop-template/branch/master
[coverage]: https://codecov.io/gh/arvinxx/umi-plugin-figma/branch/master/graph/badge.svg
[codecov-url]: https://codecov.io/gh/arvinxx/umi-plugin-figma/branch/master

<!-- Github CI -->

[test-ci]: https://github.com/arvinxx/umi-plugin-develop-template/workflows/Test%20CI/badge.svg
[release-ci]: https://github.com/arvinxx/umi-plugin-develop-template/workflows/Release%20CI/badge.svg
[test-ci-url]: https://github.com/arvinxx/umi-plugin-develop-template/actions?query=workflow%3A%22Test+CI%22
[deploy-ci-url]: https://github.com/arvinxx/umi-plugin-develop-template/actions?query=workflow%3A%22Release+CI%22
[test-ci]: https://github.com/arvinxx/umi-plugin-figma/workflows/Test%20CI/badge.svg
[release-ci]: https://github.com/arvinxx/umi-plugin-figma/workflows/Release%20CI/badge.svg
[test-ci-url]: https://github.com/arvinxx/umi-plugin-figma/actions?query=workflow%3A%22Test+CI%22
[deploy-ci-url]: https://github.com/arvinxx/umi-plugin-figma/actions?query=workflow%3A%22Release+CI%22

用于开发 umi 插件的模板

Expand Down
12 changes: 2 additions & 10 deletions document/config/config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import { defineConfig } from 'umi';
import { resolve } from 'path';

const isProdSite =
// 不是预览模式 同时是生产环境
process.env.NODE_ENV === 'production';

export default defineConfig({
title: 'umi-plugin-develop-module',
title: 'umi-plugin-figma',
mode: 'site',
// 部署在非根目录时, base 和 publicPath 都需要配置
base: '/',
publicPath: isProdSite ? '/umi-plugin-develop-module/' : '/',
extraBabelPlugins: [
[
'import',
Expand All @@ -25,7 +17,7 @@ export default defineConfig({
null,
{
title: 'GitHub',
path: 'https://github.com/arvinxx/umi-plugin-develop-template',
path: 'https://github.com/arvinxx/umi-plugin-figma',
},
],
dynamicImport: {
Expand Down
2 changes: 1 addition & 1 deletion document/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ title: 介绍
order: 1
---

# umi-plugin-develop-template
# umi-plugin-figma
2 changes: 2 additions & 0 deletions example/figma/main.ts
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 removed example/public/logo/logo@128.png
Binary file not shown.
Binary file removed example/public/logo/logo@16.png
Binary file not shown.
Binary file removed example/public/logo/logo@32.png
Binary file not shown.
Binary file removed example/public/logo/logo@48.png
Binary file not shown.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "umi-plugin-develop-template",
"version": "1.1.0",
"name": "umi-plugin-figma",
"version": "0.0.0",
"main": "lib/index.js",
"description": "a umi plugin {{template}}",
"description": "a umi plugin to develop figma plugin",
"authors": {
"name": "Arvin Xu",
"email": "arvinx@foxmail.com"
Expand All @@ -11,10 +11,10 @@
"access": "public",
"registry": "https://registry.npmjs.org/"
},
"homepage": "https://github.com/arvinxx/umi-plugin-develop-template#readme",
"homepage": "https://github.com/arvinxx/umi-plugin-figma#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/arvinxx/umi-plugin-develop-template.git"
"url": "git+https://github.com/arvinxx/umi-plugin-figma.git"
},
"scripts": {
"start": "npm run build && npm run example:dev",
Expand Down
39 changes: 39 additions & 0 deletions src/functions/base.ts
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;
});
};
71 changes: 71 additions & 0 deletions src/functions/config.ts
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(),
});
},
},
});
};
4 changes: 4 additions & 0 deletions src/functions/index.ts
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';
35 changes: 35 additions & 0 deletions src/functions/main.ts
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);
};
18 changes: 18 additions & 0 deletions src/functions/manifest.ts
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;
});
};

0 comments on commit e2d67a9

Please sign in to comment.