Skip to content

Commit

Permalink
🔧 chore: Update workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
canisminor1990 committed Oct 19, 2023
1 parent 14d364b commit 746aa1a
Show file tree
Hide file tree
Showing 15 changed files with 280 additions and 48 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ jobs:
run: bun run format
env:
OPENAI_TOKEN: ${{ secrets.OPENAI_TOKEN }}

- name: Awesome
run: bun run awesome

- name: Prettier
run: |
echo "module.exports = require('@lobehub/lint').prettier;" >> .prettierrc.js
echo "module.exports = require('@lobehub/lint').remarklint;" >> .remarkrc.cjs
bun run lint:md
echo "module.exports = require('@lobehub/lint').prettier;" >> .prettierrc.cjs
bun run prettier
- name: Commit changes
Expand Down
1 change: 1 addition & 0 deletions .i18nrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ module.exports = {
selectors: ['meta.title', 'meta.description', 'meta.tags'],
entryLocale: 'en-US',
outputLocales: ['zh-CN', 'ru-RU'],
// outputLocales: ['zh-CN', 'zh-TW', 'ru-RU', 'ja-JP', 'ko-KR'],
};
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,65 @@ If you wish to add a plugin onto the index, make an entry in `plugins` directory

</div>


## 🕶 Awesome Plugins

<!-- AWESOME PLUGINS -->

### Website Crawler

<sup>By **[@LobeHub](https://github.com/lobehub/chat-plugin-web-crawler)** on **2023-08-17**</sup>

Extract content from web links

`web` `content-crawler`

<div align="right">

[![][back-to-top]](#readme-top)

</div>

---

### Search Engine

<sup>By **[@LobeHub](https://github.com/lobehub/chat-plugin-search-engine)** on **2023-08-15**</sup>

Query search engine to get information

`web` `search`

<div align="right">

[![][back-to-top]](#readme-top)

</div>

---

### Realtime Weather

<sup>By **[@LobeHub](https://github.com/lobehub/chat-plugin-realtime-weather)** on **2023-08-12**</sup>

Get realtime weather information

`weather` `realtime`

<div align="right">

[![][back-to-top]](#readme-top)

</div>

<!-- AWESOME PLUGINS -->

<div align="right">

[![][back-to-top]](#readme-top)

</div>

## 🛳 Self Hosting

If you want to deploy this service by yourself, you can follow the steps below.
Expand Down
58 changes: 58 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,64 @@

</div>

## 🕶 Awesome Plugins

<!-- AWESOME PLUGINS -->

### 网站爬虫

<sup>By **[@LobeHub](https://github.com/lobehub/chat-plugin-web-crawler)** on **2023-08-17**</sup>

从网页链接中提取内容

`网页` `内容爬取器`

<div align="right">

[![][back-to-top]](#readme-top)

</div>

---

### 搜索引擎

<sup>By **[@LobeHub](https://github.com/lobehub/chat-plugin-search-engine)** on **2023-08-15**</sup>

查询搜索引擎以获取信息

`网络` `搜索`

<div align="right">

[![][back-to-top]](#readme-top)

</div>

---

### 实时天气

<sup>By **[@LobeHub](https://github.com/lobehub/chat-plugin-realtime-weather)** on **2023-08-12**</sup>

获取实时天气信息

`天气` `实时`

<div align="right">

[![][back-to-top]](#readme-top)

</div>

<!-- AWESOME PLUGINS -->

<div align="right">

[![][back-to-top]](#readme-top)

</div>

## 🛳 自主托管

如果您想自己部署此服务,可以按照以下步骤操作
Expand Down
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
},
"license": "MIT",
"author": "LobeHub <[email protected]>",
"type": "module",
"scripts": {
"build": "node scripts/build.mjs",
"format": "node scripts/format.mjs",
"lint": "eslint \"scripts/**/*.mjs\" --fix",
"lint:md": "remark . --quiet --frail --output",
"prettier": "prettier -c --write \"**/*.{json,mjs,md}\"",
"test": "node scripts/test.mjs"
"awesome": "bun scripts/build.ts && bun scripts/updateAwesome.ts",
"build": "bun scripts/build.ts",
"format": "bun scripts/format.ts",
"lint": "eslint \"scripts/**/*.ts\" --fix",
"lint:md": "remark . --quiet --output",
"prettier": "prettier -c --write \"**/*.{json,ts,md}\"",
"test": "bun scripts/test.ts"
},
"devDependencies": {
"@lobehub/chat-plugin-sdk": "latest",
Expand Down
18 changes: 15 additions & 3 deletions scripts/build.mjs → scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { consola } from 'consola';
import { cloneDeep, merge } from 'lodash-es';
import { resolve } from 'node:path';

import { formatAndCheckSchema } from './check.mjs';
import { config, localesDir, meta, plugins, pluginsDir, publicDir } from './const.mjs';
import { checkDir, readJSON, writeJSON } from './utils.mjs';
import { formatAndCheckSchema } from './check';
import { config, localesDir, meta, plugins, pluginsDir, publicDir } from './const';
import { checkDir, readJSON, writeJSON, findDuplicates } from './utils';

const build = async () => {
checkDir(publicDir);
Expand Down Expand Up @@ -32,7 +32,19 @@ const build = async () => {
}

for (const locale of [config.entryLocale, ...config.outputLocales]) {
// @ts-ignore
pluginsIndex.plugins = list[locale].sort((a, b) => new Date(b.createAt) - new Date(a.createAt));

let tags: string[] = [];

pluginsIndex.plugins.forEach((plugin) => {
tags = [...tags, ...plugin.meta.tags];
});

tags = findDuplicates(tags);

pluginsIndex.tags = tags

const name = locale === config.entryLocale ? `index.json` : `index.${locale}.json`;
writeJSON(resolve(publicDir, name), pluginsIndex, false);
consola.success(`build ${name}`);
Expand Down
2 changes: 1 addition & 1 deletion scripts/check.mjs → scripts/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { pluginMetaSchema } from '@lobehub/chat-plugin-sdk';
import { consola } from 'consola';
import dayjs from 'dayjs';

import { meta } from './const.mjs';
import { meta } from './const';

export const formatAndCheckSchema = (plugin) => {
if (!plugin.schemaVersion) plugin.schemaVersion = meta.schemaVersion;
Expand Down
16 changes: 14 additions & 2 deletions scripts/const.mjs → scripts/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,30 @@ import { readdirSync } from 'node:fs';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';

import { readJSON } from './utils.mjs';
import { readJSON } from './utils';

export const __filename = fileURLToPath(import.meta.url);
export const __dirname = dirname(__filename);
export const root = resolve(__dirname, '..');

export const pluginsDir = resolve(root, './plugins');
export const localesDir = resolve(root, './locales');
export const publicDir = resolve(root, 'public');

export const plugins = readdirSync(pluginsDir, { withFileTypes: true });
export const pluginLocales = readdirSync(localesDir, { withFileTypes: true });

export const templatePath = resolve(root, 'plugin-template.json');

export const indexPath = resolve(publicDir, 'index.json');
export const indexCnPath = resolve(publicDir, 'index.zh-CN.json');

export const readmePath = resolve(root, 'README.md');
export const readmeCnPath = resolve(root, 'README.zh-CN.md');

export const metaPath = resolve(root, 'meta.json');
export const meta = readJSON(metaPath);
export const publicDir = resolve(root, 'public');

export const readmeSplit = '<!-- AWESOME PLUGINS -->';

export { default as config } from '../.i18nrc.js';
10 changes: 5 additions & 5 deletions scripts/format.mjs → scripts/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { get, kebabCase, merge, set } from 'lodash-es';
import { existsSync } from 'node:fs';
import { resolve } from 'node:path';

import { formatAndCheckSchema } from './check.mjs';
import { config, localesDir, metaPath, plugins, pluginsDir, templatePath } from './const.mjs';
import { formatFilenames } from './formatFilename.mjs';
import { translateJSON } from './i18n.mjs';
import { checkJSON, readJSON, split, writeJSON } from './utils.mjs';
import { formatAndCheckSchema } from './check';
import { config, localesDir, metaPath, plugins, pluginsDir, templatePath } from './const';
import { formatFilenames } from './formatFilename';
import { translateJSON } from './i18n';
import { checkJSON, readJSON, split, writeJSON } from './utils';

const formatJSON = async (fileName, checkType) => {
consola.start(fileName);
Expand Down
4 changes: 2 additions & 2 deletions scripts/formatFilename.mjs → scripts/formatFilename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { consola } from 'consola';
import { renameSync } from 'node:fs';
import { resolve } from 'node:path';

import { localesDir, pluginLocales, plugins, pluginsDir } from './const.mjs';
import { checkJSON, readJSON } from './utils.mjs';
import { localesDir, pluginLocales, plugins, pluginsDir } from './const';
import { checkJSON, readJSON } from './utils';

const formatFilenameById = (fileName) => {
const filePath = resolve(pluginsDir, fileName);
Expand Down
2 changes: 1 addition & 1 deletion scripts/i18n.mjs → scripts/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'dotenv/config';
import { ChatOpenAI } from 'langchain/chat_models/openai';
import { HumanMessage, SystemMessage } from 'langchain/schema';

import { config } from './const.mjs';
import { config } from './const';

if (!process.env.OPENAI_TOKEN) {
consola.error('cannot find OPENAI_TOKEN in env');
Expand Down
6 changes: 3 additions & 3 deletions scripts/test.mjs → scripts/test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { consola } from 'consola';
import { resolve } from 'node:path';

import { checkUniqueIdentifier, formatAndCheckSchema } from './check.mjs';
import { plugins, pluginsDir, root } from './const.mjs';
import { readJSON } from './utils.mjs';
import { checkUniqueIdentifier, formatAndCheckSchema } from './check';
import { plugins, pluginsDir, root } from './const';
import { readJSON } from './utils';

const runTest = () => {
const identifiers = [];
Expand Down
51 changes: 51 additions & 0 deletions scripts/updateAwesome.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { readFileSync, writeFileSync } from 'node:fs';
import { resolve } from 'node:path';

import { indexCnPath, indexPath, publicDir, readmeCnPath, readmePath } from './const';
import { updateAwesomeReadme, readJSON } from './utils';

const updateAwesome = (filePath: string, md: string, plugins, locale?: string) => {
const data:string[] = [];

plugins.forEach(({ identifier, author, createAt, homepage, meta }, i) => {
const pluginConfigPath = resolve(
publicDir,
[identifier, locale, 'json'].filter(Boolean).join('.'),
);
const header = `### ${meta.title}`;
const subHeader = `<sup>By **[@${author}](${homepage})** on **${createAt}**</sup>`;
const desc = [
`${meta.description}`,
`${meta.tags
.filter(Boolean)
.map((tag) => `\`${tag}\``)
.join(' ')}`,
].join('\n\n');

const body:string = [
i !== 0 ? '---' : false,
header,
subHeader,
desc,
`<div align="right">\n\n[![][back-to-top]](#readme-top)\n\n</div>`,
]
.filter(Boolean)
.join('\n\n');
data.push(body);
});

const newMd = updateAwesomeReadme(md, data.join('\n\n'));

writeFileSync(filePath, newMd, 'utf-8');
};

const runUpdateAwesome = () => {
const readmeCn = readFileSync(readmeCnPath, 'utf-8');
const readme = readFileSync(readmePath, 'utf-8');
const index = readJSON(indexPath);
const indexCn = readJSON(indexCnPath);
updateAwesome(readmePath, readme, index.plugins);
updateAwesome(readmeCnPath, readmeCn, indexCn.plugins, 'zh-CN');
};

runUpdateAwesome();
24 changes: 0 additions & 24 deletions scripts/utils.mjs

This file was deleted.

Loading

0 comments on commit 746aa1a

Please sign in to comment.