Skip to content

Commit 8d534ed

Browse files
✨ feat: Update build
1 parent 64debd6 commit 8d534ed

File tree

18 files changed

+141
-104
lines changed

18 files changed

+141
-104
lines changed

.github/workflows/release.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
name: Build
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v3
13+
- uses: actions/checkout@v4
1414

1515
- name: Install bun
1616
uses: oven-sh/setup-bun@v1
@@ -52,3 +52,9 @@ jobs:
5252
git push
5353
env:
5454
GH_TOKEN: ${{ secrets.GH_TOKEN }}
55+
56+
- name: Release
57+
run: bun run release
58+
env:
59+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
60+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ test-output
4141
# misc
4242
# add other ignore file below
4343
public
44-
.prettierrc.js
45-
.eslintrc.js
46-
.remarkrc.js
44+
.prettierrc.*js
45+
.eslintrc.*js
46+
.remarkrc.*js
4747
.env
48-
bun.lockb
48+
bun.lockb

.prettierrc.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('@lobehub/lint').prettier;

.releaserc.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('@lobehub/lint').semanticRelease;

.remarkrc.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('@lobehub/lint').remarklint;

package.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
2-
"name": "@lobehub/lobe-chat-plugins",
2+
"name": "@lobehub/plugins-index",
33
"version": "0.0.0",
4-
"private": true,
54
"description": "LobeChat Plugins Index",
65
"homepage": "https://github.com/lobehub/lobe-chat-plugins",
76
"repository": {
@@ -11,13 +10,18 @@
1110
"license": "MIT",
1211
"author": "LobeHub <i@lobehub.com>",
1312
"type": "module",
13+
"main": "public/index.json",
14+
"files": [
15+
"public"
16+
],
1417
"scripts": {
1518
"awesome": "bun scripts/build.ts && bun scripts/updateAwesome.ts",
1619
"build": "bun scripts/build.ts",
1720
"format": "bun scripts/format.ts",
1821
"lint": "eslint \"scripts/**/*.ts\" --fix",
1922
"lint:md": "remark . --quiet --output",
2023
"prettier": "prettier -c --write \"**/*.{json,ts,md}\"",
24+
"release": "semantic-release",
2125
"sync": "bun scripts/sync.ts",
2226
"test": "bun scripts/test.ts"
2327
},
@@ -30,6 +34,7 @@
3034
"@types/node": "^20.14.14",
3135
"consola": "^3.2.3",
3236
"dayjs": "^1.11.12",
37+
"dirty-json": "^0.9.2",
3338
"dotenv": "^16.4.5",
3439
"eslint": "^8.57.0",
3540
"fs-extra": "^11.2.0",
@@ -40,8 +45,13 @@
4045
"remark": "^14.0.3",
4146
"remark-cli": "^11.0.0",
4247
"remark-pangu": "^2.2.0",
48+
"semantic-release": "^21.1.2",
4349
"typescript": "^5.5.4",
4450
"zod": "^3.23.8",
4551
"zod-to-json-schema": "^3.23.2"
52+
},
53+
"publishConfig": {
54+
"access": "public",
55+
"registry": "https://registry.npmjs.org"
4656
}
4757
}

scripts/build.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { consola } from 'consola';
2+
import { readJSONSync, writeJSONSync } from 'fs-extra';
23
import { cloneDeep, merge } from 'lodash-es';
34
import { resolve } from 'node:path';
45

56
import { formatAndCheckSchema } from './check';
67
import { config, localesDir, meta, plugins, pluginsDir, publicDir } from './const';
7-
import { checkDir, findDuplicates, readJSON, writeJSON } from './utils';
8+
import { checkDir, findDuplicates } from './utils';
89

910
const build = async () => {
1011
checkDir(publicDir);
@@ -18,37 +19,42 @@ const build = async () => {
1819

1920
for (const file of plugins) {
2021
if (file.isFile()) {
21-
const data = readJSON(resolve(pluginsDir, file.name));
22+
const data = readJSONSync(resolve(pluginsDir, file.name));
2223
const plugin = formatAndCheckSchema(data);
2324
if (!list[config.entryLocale]) list[config.entryLocale] = [];
2425
list[config.entryLocale].push(plugin);
2526
for (const locale of config.outputLocales) {
2627
if (!list[locale]) list[locale] = [];
2728
const localeFilePath = resolve(localesDir, file.name.replace('.json', `.${locale}.json`));
28-
const localeData = readJSON(localeFilePath);
29+
const localeData = readJSONSync(localeFilePath);
2930
list[locale].push(merge(cloneDeep(plugin), localeData));
3031
}
3132
}
3233
}
3334

3435
for (const locale of [config.entryLocale, ...config.outputLocales]) {
35-
// @ts-ignore
3636
pluginsIndex.plugins = list[locale].sort(
37+
// @ts-ignore
3738
(a, b) => new Date(b.createdAt) - new Date(a.createdAt),
3839
);
3940

4041
let tags: string[] = [];
4142

42-
pluginsIndex.plugins.forEach((plugin) => {
43+
for (const plugin of pluginsIndex.plugins) {
4344
tags = [...tags, ...plugin.meta.tags];
44-
});
45+
}
4546

4647
tags = findDuplicates(tags);
4748

4849
pluginsIndex.tags = tags;
4950

50-
const name = locale === config.entryLocale ? `index.json` : `index.${locale}.json`;
51-
writeJSON(resolve(publicDir, name), pluginsIndex, false);
51+
const name = `index.${locale}.json`;
52+
53+
if (locale === config.entryLocale) {
54+
writeJSONSync(resolve(publicDir, `index.json`), pluginsIndex);
55+
}
56+
writeJSONSync(resolve(publicDir, name), pluginsIndex);
57+
5258
consola.success(`build ${name}`);
5359
}
5460
};

scripts/category.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import { consola } from 'consola';
22
import 'dotenv/config';
3-
import { ChatOpenAI } from 'langchain/chat_models/openai';
43
import { HumanMessage, SystemMessage } from 'langchain/schema';
54

6-
import { category, config } from './const';
7-
8-
const model = new ChatOpenAI(
9-
{ modelName: config.modelName, temperature: 0 },
10-
{ baseURL: process.env.OPENAI_PROXY_URL },
11-
);
5+
import { category } from './const';
6+
import { model } from './model';
127

138
export const addCategory = async (json) => {
149
consola.info(`category generating...`);

scripts/check.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ export const checkUniqueIdentifier = (arr) => {
2323
let duplicates = [];
2424
let set = new Set();
2525

26-
for (let i = 0; i < arr.length; i++) {
27-
if (set.has(arr[i])) {
28-
duplicates.push(arr[i]);
26+
for (const element of arr) {
27+
if (set.has(element)) {
28+
duplicates.push(element);
2929
} else {
30-
set.add(arr[i]);
30+
set.add(element);
3131
}
3232
}
3333

scripts/const.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
1-
import { readdirSync } from 'node:fs';
2-
import { resolve } from 'node:path';
1+
import { readdirSync } from "node:fs";
2+
import { resolve } from "node:path";
33

4-
import { readJSON } from './utils';
4+
import { readJSONSync } from "fs-extra";
55

6-
export const root = resolve(__dirname, '..');
6+
export const root = resolve(__dirname, "..");
77

8-
export const pluginsDir = resolve(root, './src');
9-
export const localesDir = resolve(root, './locales');
10-
export const publicDir = resolve(root, 'public');
8+
export const pluginsDir = resolve(root, "./src");
9+
export const localesDir = resolve(root, "./locales");
10+
export const publicDir = resolve(root, "public");
1111

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

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

17-
export const indexPath = resolve(publicDir, 'index.json');
18-
export const indexCnPath = resolve(publicDir, 'index.zh-CN.json');
17+
export const indexPath = resolve(publicDir, "index.json");
18+
export const indexCnPath = resolve(publicDir, "index.zh-CN.json");
1919

20-
export const readmePath = resolve(root, 'README.md');
21-
export const readmeCnPath = resolve(root, 'README.zh-CN.md');
20+
export const readmePath = resolve(root, "README.md");
21+
export const readmeCnPath = resolve(root, "README.zh-CN.md");
2222

23-
export const metaPath = resolve(root, 'meta.json');
24-
export const meta = readJSON(metaPath);
23+
export const metaPath = resolve(root, "meta.json");
24+
export const meta = readJSONSync(metaPath);
2525

26-
export const readmeSplit = '<!-- AWESOME PLUGINS -->';
26+
export const readmeSplit = "<!-- AWESOME PLUGINS -->";
2727

28-
export const SYNC_URL = 'https://openai-collections.chat-plugin.lobehub.com';
28+
export const SYNC_URL = "https://openai-collections.chat-plugin.lobehub.com";
2929

3030
export const category = [
31-
'gaming-entertainment',
32-
'lifestyle',
33-
'media-generate',
34-
'science-education',
35-
'social',
36-
'stocks-finance',
37-
'tools',
38-
'web-search',
31+
"gaming-entertainment",
32+
"lifestyle",
33+
"media-generate",
34+
"science-education",
35+
"social",
36+
"stocks-finance",
37+
"tools",
38+
"web-search",
3939
];
4040

41-
export const config = require('../.i18nrc.js');
41+
export const config = require("../.i18nrc.js");

0 commit comments

Comments
 (0)