Skip to content

Commit

Permalink
args改为函数获取
Browse files Browse the repository at this point in the history
  • Loading branch information
volatile-static committed Sep 26, 2023
1 parent ba33207 commit 56e1940
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {

import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const plugins = args == 'charts'
const plugins = args() == 'charts'
? require('../docs/dist/plugins.json') as PluginInfo[]
: [];
const pluginMap: { [name: string]: PluginMapInfo } =
Expand Down Expand Up @@ -358,6 +358,8 @@ export default async function getChartOptions() {
if (process.env.NODE_ENV != 'development')
for (const plugin of plugins)
await fetchInfo(plugin);
if (Object.values(pluginMap).some(info => !info.author?.avatar))
throw new Error('插件数据不完整!');

// 仅供测试时用
// writeFile('../docs/dist/charts-debug.json', JSON.stringify(pluginMap, null, 2));
Expand Down
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import { progressPlugins, renderMarkdown } from "./get_plugins_info";
if (!process.env.GITHUB_TOKEN) throw new Error("GITHUB_TOKEN 未设置");
export const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });
export const dist = "../docs/dist";
export const args = process.argv.slice(2)[0];

export function args() {
return <"releases" | "charts">process.argv.slice(2)[0];
}

async function main(mode: "releases" | "charts" | string) {
const quota = (
Expand Down Expand Up @@ -61,7 +63,7 @@ async function main(mode: "releases" | "charts" | string) {
}


main(args).catch((err) => {
main(args()).catch((err) => {
console.log(err);
process.exit(1);
});

0 comments on commit 56e1940

Please sign in to comment.