feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
63
common/_templates/_plugins/SelectTeamPlugin.ts
Normal file
63
common/_templates/_plugins/SelectTeamPlugin.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import type {
|
||||
IPlugin,
|
||||
IHooks,
|
||||
IPromptsHookParams,
|
||||
} from "rush-init-project-plugin";
|
||||
import { readFileSync } from 'fs';
|
||||
import path from 'path';
|
||||
import JSON5 from '../../autoinstallers/plugins/node_modules/json5'
|
||||
|
||||
const rushJson = JSON5.parse(
|
||||
readFileSync(
|
||||
path.resolve(__dirname, '../../../rush.json')
|
||||
).toString('utf-8')
|
||||
);
|
||||
|
||||
export default class SelectTeamPlugin implements IPlugin {
|
||||
apply(hooks: IHooks): void {
|
||||
hooks.prompts.tap("SelectTeamPlugin", (prompts: IPromptsHookParams) => {
|
||||
|
||||
// 只留下以team-为前缀的
|
||||
const teamNamePrefix = /^team-/;
|
||||
const choices = rushJson.allowedProjectTags.filter(
|
||||
teamName => teamNamePrefix.test(teamName)
|
||||
).map(
|
||||
teamName => teamName.replace(teamNamePrefix, '')
|
||||
);
|
||||
|
||||
// unshift一个问题,使得用户选择完模版后展示该问题。
|
||||
prompts.promptQueue.unshift({
|
||||
type: "list",
|
||||
name: "team",
|
||||
message: "Select your team",
|
||||
choices,
|
||||
default: 0, // 默认选择choices[0]
|
||||
});
|
||||
|
||||
const projectFolderPrompt = prompts.promptQueue.find(
|
||||
item => item.name === 'projectFolder'
|
||||
);
|
||||
projectFolderPrompt.default = (answers) => {
|
||||
// 文件夹名去除scope,如 @coze-arch/foo -> foo
|
||||
const folderDir = answers.packageName.split('/').slice(-1)[0];
|
||||
return `packages/${answers.team}/${folderDir}`
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
50
common/_templates/_plugins/SetDefaultAuthorPlugin.ts
Normal file
50
common/_templates/_plugins/SetDefaultAuthorPlugin.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import type { IPlugin, IHooks, IPromptsHookParams } from 'rush-init-project-plugin';
|
||||
// FIXME:
|
||||
// 按照 https://github.com/bytemate/rush-plugins/blob/main/rush-plugins/rush-init-project-plugin/docs/init_project_configuration.md
|
||||
// 一文的指引,无法正确 resolve 到对应模块,暂时没找到解决方案,故此处先用相对路径引用
|
||||
// 未来需要调整为正常的 node_modules 引用方式
|
||||
import { createLog } from '../../autoinstallers/plugins/node_modules/rush-init-project-plugin';
|
||||
import { exec } from './utils';
|
||||
|
||||
export default class SetDefaultAuthorPlugin implements IPlugin {
|
||||
private readonly logger = createLog({
|
||||
prefix: SetDefaultAuthorPlugin.name
|
||||
});
|
||||
|
||||
apply(hooks: IHooks): void {
|
||||
hooks.prompts.tap(SetDefaultAuthorPlugin.name, async (prompts: IPromptsHookParams) => {
|
||||
const prompAuthorEmail = prompts.promptQueue.find((r) => r.name === 'authorName');
|
||||
if (prompAuthorEmail) {
|
||||
const userEmail = String(await exec(this.logger, 'git', ['config', '--get', 'user.email']));
|
||||
Object.assign(prompAuthorEmail, {
|
||||
default() {
|
||||
return userEmail;
|
||||
},
|
||||
validate(author: string) {
|
||||
return /@bytedance\.com$/.test(author);
|
||||
}
|
||||
});
|
||||
|
||||
hooks.answers.tap("authorPrefix", (answers) => {
|
||||
answers.authorPrefix = userEmail.split('@')?.[0] ?? '';
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
32
common/_templates/_plugins/SetFornaxChildAppPlugin.ts
Normal file
32
common/_templates/_plugins/SetFornaxChildAppPlugin.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import type { IHooks, IPlugin, IPromptsHookParams } from 'rush-init-project-plugin';
|
||||
import { parseCommandLineArguments } from './utils/parse-args';
|
||||
|
||||
export default class FornaxPlugin implements IPlugin {
|
||||
apply(hooks: IHooks): void {
|
||||
hooks.answers.tap('FornaxPlugin', (answers) => {
|
||||
if(answers.template === 'fornax-child-app') {
|
||||
if(answers.packageName.startsWith('@flow-devops/fornax-')) {
|
||||
answers.childAppName = answers.packageName.replace('@flow-devops/fornax-','');
|
||||
} else {
|
||||
throw new Error('The initialization of field childAppName failed because the packageName is invalid. Please use "@flow-devops/fornax-xxx."');
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
41
common/_templates/_plugins/ShowChatAreaTemplatePlugin.ts
Normal file
41
common/_templates/_plugins/ShowChatAreaTemplatePlugin.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import type { IPlugin, IHooks, ITemplatesHook, IPromptsHookParams } from 'rush-init-project-plugin';
|
||||
// FIXME:
|
||||
// 按照 https://github.com/bytemate/rush-plugins/blob/main/rush-plugins/rush-init-project-plugin/docs/init_project_configuration.md
|
||||
// 一文的指引,无法正确 resolve 到对应模块,暂时没找到解决方案,故此处先用相对路径引用
|
||||
// 未来需要调整为正常的 node_modules 引用方式
|
||||
import { getTemplatesFolder, getTemplateNameList } from '../../autoinstallers/plugins/node_modules/rush-init-project-plugin/lib/logic/templateFolder';
|
||||
import { parseCommandLineArguments } from './utils/parse-args';
|
||||
|
||||
export default class ShowChatAreaTemplatePlugin implements IPlugin {
|
||||
apply(hooks: IHooks): void {
|
||||
const args = parseCommandLineArguments();
|
||||
|
||||
const answer = JSON.parse(args.answer ?? '{}');
|
||||
const isShowChatAreaTemplate = answer['showChatAreaTemplate'];
|
||||
|
||||
hooks.templates.tap("ShowChatAreaTemplatePlugin", (templates: ITemplatesHook) => {
|
||||
const templateFolder: string = getTemplatesFolder();
|
||||
const templateNameList = getTemplateNameList(templateFolder)
|
||||
|
||||
const filteredNormalTemplateNameList = templateNameList.filter(item => !item.templateFolder?.includes('chat-'));
|
||||
|
||||
templates.templates.push(...(isShowChatAreaTemplate ? templateNameList : filteredNormalTemplateNameList ));
|
||||
});
|
||||
}
|
||||
}
|
||||
25
common/_templates/_plugins/global.config.ts
Normal file
25
common/_templates/_plugins/global.config.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import type { IConfig } from '../../autoinstallers/plugins/node_modules/rush-init-project-plugin';
|
||||
import ShowChatAreaTemplatePlugin from './ShowChatAreaTemplatePlugin';
|
||||
import SetFornaxChildAppPlugin from './SetFornaxChildAppPlugin';
|
||||
|
||||
const config: IConfig = {
|
||||
plugins: [new ShowChatAreaTemplatePlugin(), new SetFornaxChildAppPlugin()]
|
||||
};
|
||||
|
||||
export default config;
|
||||
37
common/_templates/_plugins/utils/index.ts
Normal file
37
common/_templates/_plugins/utils/index.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import type { ILogger } from 'rush-init-project-plugin';
|
||||
// eslint-disable-next-line @infra/no-deep-relative-import
|
||||
import { spawnSync } from 'child_process';
|
||||
|
||||
const exec = (logger: ILogger, cmd: string, args: string[]): string | undefined => {
|
||||
try {
|
||||
if (!cmd) {
|
||||
return undefined;
|
||||
}
|
||||
logger?.verbose(`Exec: ${cmd}`);
|
||||
const { stdout } = spawnSync(cmd, args);
|
||||
const result = stdout.toString();
|
||||
logger?.verbose(`Cmd res: ${result}`);
|
||||
return result.trim();
|
||||
} catch (err) {
|
||||
logger?.error(String(err));
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
|
||||
export { exec };
|
||||
41
common/_templates/_plugins/utils/parse-args.ts
Normal file
41
common/_templates/_plugins/utils/parse-args.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import process from 'process';
|
||||
|
||||
// parseArgs.ts
|
||||
export function parseCommandLineArguments() {
|
||||
const args = process.argv.slice(2);
|
||||
const result: Record<string, string> = {};
|
||||
|
||||
// 循环遍历所有参数
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
// 检查当前参数是否是一个选项(以 "--" 开头)
|
||||
if (args[i].startsWith('--')) {
|
||||
const key = args[i].substring(2); // 移除 "--" 前缀
|
||||
|
||||
// 检查下一个参数是否存在,且不是另一个选项
|
||||
if (i + 1 < args.length && !args[i + 1].startsWith('--')) {
|
||||
result[key] = args[i + 1]; // 将下一个参数作为当前选项的值
|
||||
i++; // 跳过下一个参数,因为它已经被处理为当前选项的值
|
||||
} else {
|
||||
result[key] = ''; // 如果没有值,只设置选项的键
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { mergeConfig } from 'vite';
|
||||
import svgr from 'vite-plugin-svgr';
|
||||
|
||||
/** @type { import('@storybook/react-vite').StorybookConfig } */
|
||||
const config = {
|
||||
stories: ['../stories/**/*.mdx', '../stories/**/*.stories.tsx'],
|
||||
addons: [
|
||||
'@storybook/addon-links',
|
||||
'@storybook/addon-essentials',
|
||||
'@storybook/addon-onboarding',
|
||||
'@storybook/addon-interactions',
|
||||
],
|
||||
framework: {
|
||||
name: '@storybook/react-vite',
|
||||
options: {},
|
||||
},
|
||||
docs: {
|
||||
autodocs: 'tag',
|
||||
},
|
||||
viteFinal: config =>
|
||||
mergeConfig(config, {
|
||||
plugins: [
|
||||
svgr({
|
||||
svgrOptions: {
|
||||
native: false,
|
||||
},
|
||||
}),
|
||||
],
|
||||
}),
|
||||
};
|
||||
export default config;
|
||||
@@ -0,0 +1,14 @@
|
||||
/** @type { import('@storybook/react').Preview } */
|
||||
const preview = {
|
||||
parameters: {
|
||||
actions: { argTypesRegex: "^on[A-Z].*" },
|
||||
controls: {
|
||||
matchers: {
|
||||
color: /(background|color)$/i,
|
||||
date: /Date$/i,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default preview;
|
||||
@@ -0,0 +1,5 @@
|
||||
const { defineConfig } = require('@coze-arch/stylelint-config');
|
||||
|
||||
module.exports = defineConfig({
|
||||
extends: [],
|
||||
});
|
||||
16
common/_templates/chat-plugin-readonly-standard/README.md
Normal file
16
common/_templates/chat-plugin-readonly-standard/README.md
Normal file
@@ -0,0 +1,16 @@
|
||||
# {{ packageName }}
|
||||
|
||||
> Project template for react component with storybook.
|
||||
|
||||
## Features
|
||||
|
||||
- [x] eslint & ts
|
||||
- [x] esm bundle
|
||||
- [x] umd bundle
|
||||
- [x] storybook
|
||||
|
||||
## Commands
|
||||
|
||||
- init: `rush update`
|
||||
- dev: `npm run dev`
|
||||
- build: `npm run build`
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"operationSettings": [
|
||||
{
|
||||
"operationName": "test:cov",
|
||||
"outputFolderNames": ["coverage"]
|
||||
},
|
||||
{
|
||||
"operationName": "ts-check",
|
||||
"outputFolderNames": ["dist"]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
const { defineConfig } = require('@coze-arch/eslint-config');
|
||||
|
||||
module.exports = defineConfig({
|
||||
packageRoot: __dirname,
|
||||
preset: 'web',
|
||||
rules: {},
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
import SelectTeamPlugin from '../_plugins/SelectTeamPlugin';
|
||||
import SetDefaultAuthorPlugin from '../_plugins/SetDefaultAuthorPlugin';
|
||||
import type { IConfig } from '../../autoinstallers/plugins/node_modules/rush-init-project-plugin';
|
||||
|
||||
const config: IConfig = {
|
||||
plugins: [new SetDefaultAuthorPlugin(), new SelectTeamPlugin()],
|
||||
defaultProjectConfiguration: {
|
||||
tags:['level-3']
|
||||
}
|
||||
};
|
||||
|
||||
export default config;
|
||||
52
common/_templates/chat-plugin-readonly-standard/package.json
Normal file
52
common/_templates/chat-plugin-readonly-standard/package.json
Normal file
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"name": "{{ packageName }}",
|
||||
"version": "0.0.1",
|
||||
"description": "{{ description }}",
|
||||
"license": "Apache-2.0",
|
||||
"author": "{{ authorName }}",
|
||||
"maintainers": [],
|
||||
"main": "src/index.tsx",
|
||||
"scripts": {
|
||||
"build": "exit 0",
|
||||
"dev": "storybook dev -p 6006",
|
||||
"lint": "eslint ./ --cache",
|
||||
"test": "vitest --run --passWithNoTests",
|
||||
"test:cov": "npm run test -- --coverage"
|
||||
},
|
||||
"dependencies": {
|
||||
"@coze-common/chat-area": "workspace:*",
|
||||
"classnames": "^2.3.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@coze-arch/bot-typings": "workspace:*",
|
||||
"@coze-arch/eslint-config": "workspace:*",
|
||||
"@coze-arch/stylelint-config": "workspace:*",
|
||||
"@coze-arch/ts-config": "workspace:*",
|
||||
"@coze-arch/vitest-config": "workspace:*",
|
||||
"@storybook/addon-essentials": "^7.6.7",
|
||||
"@storybook/addon-interactions": "^7.6.7",
|
||||
"@storybook/addon-links": "^7.6.7",
|
||||
"@storybook/addon-onboarding": "^1.0.10",
|
||||
"@storybook/blocks": "^7.6.7",
|
||||
"@storybook/react": "^7.6.7",
|
||||
"@storybook/react-vite": "^7.6.7",
|
||||
"@storybook/test": "^7.6.7",
|
||||
"@testing-library/jest-dom": "^6.1.5",
|
||||
"@testing-library/react": "^14.1.2",
|
||||
"@testing-library/react-hooks": "^8.0.1",
|
||||
"@types/react": "18.2.37",
|
||||
"@types/react-dom": "18.2.15",
|
||||
"@vitest/coverage-v8": "~3.0.5",
|
||||
"react": "~18.2.0",
|
||||
"react-dom": "~18.2.0",
|
||||
"storybook": "^7.6.7",
|
||||
"stylelint": "^15.11.0",
|
||||
|
||||
"vite-plugin-svgr": "~3.3.0",
|
||||
"vitest": "~3.0.5"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": ">=18.2.0",
|
||||
"react-dom": ">=18.2.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type FC } from 'react';
|
||||
|
||||
type IProps = Record<string, unknown>;
|
||||
|
||||
export const BizMessageInnerAddonBottom: FC<IProps> = () => (
|
||||
<div>hello world</div>
|
||||
);
|
||||
18
common/_templates/chat-plugin-readonly-standard/src/index.ts
Normal file
18
common/_templates/chat-plugin-readonly-standard/src/index.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { type PluginRegistryEntry } from '@coze-common/chat-area';
|
||||
|
||||
import { type PluginBizContext } from './types/biz-context';
|
||||
import { BizPlugin } from './plugin';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention -- 插件命名大写开头符合预期
|
||||
export const BizPluginRegistry: PluginRegistryEntry<PluginBizContext> = {
|
||||
/**
|
||||
* 贯穿插件生命周期、组件的上下文
|
||||
*/
|
||||
createPluginBizContext() {
|
||||
return {};
|
||||
},
|
||||
/**
|
||||
* 插件本体
|
||||
*/
|
||||
Plugin: BizPlugin,
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
import {
|
||||
PluginMode,
|
||||
PluginName,
|
||||
ReadonlyChatAreaPlugin,
|
||||
createReadonlyLifeCycleServices,
|
||||
createCustomComponents,
|
||||
} from '@coze-common/chat-area';
|
||||
|
||||
import { type PluginBizContext } from './types/biz-context';
|
||||
import { bizLifeCycleServiceGenerator } from './services/life-cycle';
|
||||
import { BizMessageInnerAddonBottom } from './custom-components/message-inner-addon-bottom';
|
||||
|
||||
export class BizPlugin extends ReadonlyChatAreaPlugin<PluginBizContext> {
|
||||
/**
|
||||
* 插件类型
|
||||
* PluginMode.Readonly = 只读模式
|
||||
* PluginMode.Writeable = 可写模式
|
||||
*/
|
||||
public pluginMode = PluginMode.Readonly;
|
||||
/**
|
||||
* 插件名称
|
||||
* 请点 PluginName 里面去定义
|
||||
*/
|
||||
public pluginName = PluginName.Demo;
|
||||
|
||||
/**
|
||||
* 生命周期服务
|
||||
*/
|
||||
public lifeCycleServices = createReadonlyLifeCycleServices(
|
||||
this,
|
||||
bizLifeCycleServiceGenerator,
|
||||
);
|
||||
|
||||
/**
|
||||
* 自定义组件
|
||||
*/
|
||||
public customComponents = createCustomComponents({
|
||||
MessageInnerBottomSlot: BizMessageInnerAddonBottom,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { type ReadonlyAppLifeCycleServiceGenerator } from '@coze-common/chat-area';
|
||||
|
||||
import { type PluginBizContext } from '../../types/biz-context';
|
||||
|
||||
export const appLifeCycleServiceGenerator: ReadonlyAppLifeCycleServiceGenerator<
|
||||
PluginBizContext
|
||||
> = plugin => ({});
|
||||
@@ -0,0 +1,7 @@
|
||||
import { type ReadonlyCommandLifeCycleServiceGenerator } from '@coze-common/chat-area';
|
||||
|
||||
import { type PluginBizContext } from '../../types/biz-context';
|
||||
|
||||
export const commandLifeCycleServiceGenerator: ReadonlyCommandLifeCycleServiceGenerator<
|
||||
PluginBizContext
|
||||
> = plugin => ({});
|
||||
@@ -0,0 +1,16 @@
|
||||
import { type ReadonlyLifeCycleServiceGenerator } from '@coze-common/chat-area';
|
||||
|
||||
import { type PluginBizContext } from '../../types/biz-context';
|
||||
import { renderLifeCycleServiceGenerator } from './render';
|
||||
import { messageLifeCycleServiceGenerator } from './message';
|
||||
import { commandLifeCycleServiceGenerator } from './command';
|
||||
import { appLifeCycleServiceGenerator } from './app';
|
||||
|
||||
export const bizLifeCycleServiceGenerator: ReadonlyLifeCycleServiceGenerator<
|
||||
PluginBizContext
|
||||
> = plugin => ({
|
||||
appLifeCycleService: appLifeCycleServiceGenerator(plugin),
|
||||
messageLifeCycleService: messageLifeCycleServiceGenerator(plugin),
|
||||
commandLifeCycleService: commandLifeCycleServiceGenerator(plugin),
|
||||
renderLifeCycleService: renderLifeCycleServiceGenerator(plugin),
|
||||
});
|
||||
@@ -0,0 +1,7 @@
|
||||
import { type ReadonlyMessageLifeCycleServiceGenerator } from '@coze-common/chat-area';
|
||||
|
||||
import { type PluginBizContext } from '../../types/biz-context';
|
||||
|
||||
export const messageLifeCycleServiceGenerator: ReadonlyMessageLifeCycleServiceGenerator<
|
||||
PluginBizContext
|
||||
> = plugin => ({});
|
||||
@@ -0,0 +1,7 @@
|
||||
import { type ReadonlyRenderLifeCycleServiceGenerator } from '@coze-common/chat-area';
|
||||
|
||||
import { type PluginBizContext } from '../../types/biz-context';
|
||||
|
||||
export const renderLifeCycleServiceGenerator: ReadonlyRenderLifeCycleServiceGenerator<
|
||||
PluginBizContext
|
||||
> = plugin => ({});
|
||||
@@ -0,0 +1 @@
|
||||
export type PluginBizContext = Record<string, unknown>;
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { DemoComponent } from '../src';
|
||||
|
||||
export default {
|
||||
title: 'Example/Demo',
|
||||
component: DemoComponent,
|
||||
parameters: {
|
||||
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
|
||||
layout: 'centered',
|
||||
},
|
||||
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
|
||||
tags: ['autodocs'],
|
||||
// More on argTypes: https://storybook.js.org/docs/api/argtypes
|
||||
argTypes: {},
|
||||
};
|
||||
|
||||
// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
|
||||
export const Base = {
|
||||
args: {
|
||||
name: 'tecvan',
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
import { Meta } from "@storybook/blocks";
|
||||
|
||||
<Meta title="Hello world" />
|
||||
|
||||
<div className="sb-container">
|
||||
<div className='sb-section-title'>
|
||||
# Hello world
|
||||
|
||||
Hello world
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
{`
|
||||
.sb-container {
|
||||
margin-bottom: 48px;
|
||||
}
|
||||
|
||||
.sb-section {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
img {
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.sb-section-title {
|
||||
margin-bottom: 32px;
|
||||
}
|
||||
`}
|
||||
</style>
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"extends": "@coze-arch/ts-config/tsconfig.web.json",
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"rootDir": "src",
|
||||
"jsx": "react-jsx",
|
||||
"lib": ["DOM", "ESNext"],
|
||||
"module": "ESNext",
|
||||
"target": "ES2020",
|
||||
"moduleResolution": "bundler"
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"exclude": ["**/*"],
|
||||
"compilerOptions": {
|
||||
"composite": true
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.misc.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"extends": "@coze-arch/ts-config/tsconfig.base.json",
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"compilerOptions": {
|
||||
"rootDir": "./",
|
||||
"outDir": "./dist",
|
||||
"jsx": "react-jsx",
|
||||
"lib": ["DOM", "ESNext"],
|
||||
"module": "ESNext",
|
||||
"target": "ES2020",
|
||||
"moduleResolution": "bundler"
|
||||
},
|
||||
"include": ["__tests__", "vitest.config.ts", "stories"],
|
||||
"exclude": ["./dist"],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.build.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { defineConfig } from '@coze-arch/vitest-config';
|
||||
|
||||
export default defineConfig({
|
||||
dirname: __dirname,
|
||||
preset: 'web',
|
||||
});
|
||||
@@ -0,0 +1,31 @@
|
||||
import { mergeConfig } from 'vite';
|
||||
import svgr from 'vite-plugin-svgr';
|
||||
|
||||
/** @type { import('@storybook/react-vite').StorybookConfig } */
|
||||
const config = {
|
||||
stories: ['../stories/**/*.mdx', '../stories/**/*.stories.tsx'],
|
||||
addons: [
|
||||
'@storybook/addon-links',
|
||||
'@storybook/addon-essentials',
|
||||
'@storybook/addon-onboarding',
|
||||
'@storybook/addon-interactions',
|
||||
],
|
||||
framework: {
|
||||
name: '@storybook/react-vite',
|
||||
options: {},
|
||||
},
|
||||
docs: {
|
||||
autodocs: 'tag',
|
||||
},
|
||||
viteFinal: config =>
|
||||
mergeConfig(config, {
|
||||
plugins: [
|
||||
svgr({
|
||||
svgrOptions: {
|
||||
native: false,
|
||||
},
|
||||
}),
|
||||
],
|
||||
}),
|
||||
};
|
||||
export default config;
|
||||
@@ -0,0 +1,14 @@
|
||||
/** @type { import('@storybook/react').Preview } */
|
||||
const preview = {
|
||||
parameters: {
|
||||
actions: { argTypesRegex: "^on[A-Z].*" },
|
||||
controls: {
|
||||
matchers: {
|
||||
color: /(background|color)$/i,
|
||||
date: /Date$/i,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default preview;
|
||||
@@ -0,0 +1,5 @@
|
||||
const { defineConfig } = require('@coze-arch/stylelint-config');
|
||||
|
||||
module.exports = defineConfig({
|
||||
extends: [],
|
||||
});
|
||||
16
common/_templates/chat-plugin-writeable-standard/README.md
Normal file
16
common/_templates/chat-plugin-writeable-standard/README.md
Normal file
@@ -0,0 +1,16 @@
|
||||
# {{ packageName }}
|
||||
|
||||
> Project template for react component with storybook.
|
||||
|
||||
## Features
|
||||
|
||||
- [x] eslint & ts
|
||||
- [x] esm bundle
|
||||
- [x] umd bundle
|
||||
- [x] storybook
|
||||
|
||||
## Commands
|
||||
|
||||
- init: `rush update`
|
||||
- dev: `npm run dev`
|
||||
- build: `npm run build`
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"operationSettings": [
|
||||
{
|
||||
"operationName": "test:cov",
|
||||
"outputFolderNames": ["coverage"]
|
||||
},
|
||||
{
|
||||
"operationName": "ts-check",
|
||||
"outputFolderNames": ["dist"]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
const { defineConfig } = require('@coze-arch/eslint-config');
|
||||
|
||||
module.exports = defineConfig({
|
||||
packageRoot: __dirname,
|
||||
preset: 'web',
|
||||
rules: {},
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
import SelectTeamPlugin from '../_plugins/SelectTeamPlugin';
|
||||
import SetDefaultAuthorPlugin from '../_plugins/SetDefaultAuthorPlugin';
|
||||
import type { IConfig } from '../../autoinstallers/plugins/node_modules/rush-init-project-plugin';
|
||||
|
||||
const config: IConfig = {
|
||||
plugins: [new SetDefaultAuthorPlugin(), new SelectTeamPlugin()],
|
||||
defaultProjectConfiguration: {
|
||||
tags:['level-3']
|
||||
}
|
||||
};
|
||||
|
||||
export default config;
|
||||
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"name": "{{ packageName }}",
|
||||
"version": "0.0.1",
|
||||
"description": "{{ description }}",
|
||||
"license": "Apache-2.0",
|
||||
"author": "{{ authorName }}",
|
||||
"maintainers": [],
|
||||
"main": "src/index.tsx",
|
||||
"scripts": {
|
||||
"build": "exit 0",
|
||||
"dev": "storybook dev -p 6006",
|
||||
"lint": "eslint ./ --cache",
|
||||
"test": "vitest --run --passWithNoTests",
|
||||
"test:cov": "npm run test -- --coverage"
|
||||
},
|
||||
"dependencies": {
|
||||
"@coze-common/chat-area": "workspace:*",
|
||||
"classnames": "^2.3.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@coze-arch/bot-typings": "workspace:*",
|
||||
"@coze-arch/eslint-config": "workspace:*",
|
||||
"@coze-arch/stylelint-config": "workspace:*",
|
||||
"@coze-arch/ts-config": "workspace:*",
|
||||
"@coze-arch/vitest-config": "workspace:*",
|
||||
"@storybook/addon-essentials": "^7.6.7",
|
||||
"@storybook/addon-interactions": "^7.6.7",
|
||||
"@storybook/addon-links": "^7.6.7",
|
||||
"@storybook/addon-onboarding": "^1.0.10",
|
||||
"@storybook/blocks": "^7.6.7",
|
||||
"@storybook/react": "^7.6.7",
|
||||
"@storybook/react-vite": "^7.6.7",
|
||||
"@storybook/test": "^7.6.7",
|
||||
"@testing-library/jest-dom": "^6.1.5",
|
||||
"@testing-library/react": "^14.1.2",
|
||||
"@testing-library/react-hooks": "^8.0.1",
|
||||
"@types/react": "18.2.37",
|
||||
"@types/react-dom": "18.2.15",
|
||||
"@vitest/coverage-v8": "~3.0.5",
|
||||
"react": "~18.2.0",
|
||||
"react-dom": "~18.2.0",
|
||||
"storybook": "^7.6.7",
|
||||
"stylelint": "^15.11.0",
|
||||
|
||||
"vite-plugin-svgr": "~3.3.0",
|
||||
"vitest": "~3.0.5"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": ">=18.2.0",
|
||||
"react-dom": ">=18.2.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type FC } from 'react';
|
||||
|
||||
type IProps = Record<string, unknown>;
|
||||
|
||||
export const BizMessageInnerAddonBottom: FC<IProps> = () => (
|
||||
<div>hello world</div>
|
||||
);
|
||||
@@ -0,0 +1,18 @@
|
||||
import { type PluginRegistryEntry } from '@coze-common/chat-area';
|
||||
|
||||
import { type PluginBizContext } from './types/biz-context';
|
||||
import { BizPlugin } from './plugin';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention -- 插件命名大写开头符合预期
|
||||
export const BizPluginRegistry: PluginRegistryEntry<PluginBizContext> = {
|
||||
/**
|
||||
* 贯穿插件生命周期、组件的上下文
|
||||
*/
|
||||
createPluginBizContext() {
|
||||
return {};
|
||||
},
|
||||
/**
|
||||
* 插件本体
|
||||
*/
|
||||
Plugin: BizPlugin,
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
import {
|
||||
PluginMode,
|
||||
PluginName,
|
||||
WriteableChatAreaPlugin,
|
||||
createCustomComponents,
|
||||
createWriteableLifeCycleServices,
|
||||
} from '@coze-common/chat-area';
|
||||
|
||||
import { type PluginBizContext } from './types/biz-context';
|
||||
import { bizLifeCycleServiceGenerator } from './services/life-cycle';
|
||||
import { BizMessageInnerAddonBottom } from './custom-components/message-inner-addon-bottom';
|
||||
|
||||
export class BizPlugin extends WriteableChatAreaPlugin<PluginBizContext> {
|
||||
/**
|
||||
* 插件类型
|
||||
* PluginMode.Readonly = 只读模式
|
||||
* PluginMode.Writeable = 可写模式
|
||||
*/
|
||||
public pluginMode = PluginMode.Writeable;
|
||||
/**
|
||||
* 插件名称
|
||||
* 请点 PluginName 里面去定义
|
||||
*/
|
||||
public pluginName = PluginName.Demo;
|
||||
|
||||
/**
|
||||
* 生命周期服务
|
||||
*/
|
||||
public lifeCycleServices = createWriteableLifeCycleServices(
|
||||
this,
|
||||
bizLifeCycleServiceGenerator,
|
||||
);
|
||||
|
||||
/**
|
||||
* 自定义组件
|
||||
*/
|
||||
public customComponents = createCustomComponents({
|
||||
MessageInnerBottomSlot: BizMessageInnerAddonBottom,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { type WriteableAppLifeCycleServiceGenerator } from '@coze-common/chat-area';
|
||||
|
||||
import { type PluginBizContext } from '../../types/biz-context';
|
||||
|
||||
export const appLifeCycleServiceGenerator: WriteableAppLifeCycleServiceGenerator<
|
||||
PluginBizContext
|
||||
> = plugin => ({});
|
||||
@@ -0,0 +1,7 @@
|
||||
import { type WriteableCommandLifeCycleServiceGenerator } from '@coze-common/chat-area';
|
||||
|
||||
import { type PluginBizContext } from '../../types/biz-context';
|
||||
|
||||
export const commandLifeCycleServiceGenerator: WriteableCommandLifeCycleServiceGenerator<
|
||||
PluginBizContext
|
||||
> = plugin => ({});
|
||||
@@ -0,0 +1,16 @@
|
||||
import { type WriteableLifeCycleServiceGenerator } from '@coze-common/chat-area';
|
||||
|
||||
import { type PluginBizContext } from '../../types/biz-context';
|
||||
import { renderLifeCycleServiceGenerator } from './render';
|
||||
import { messageLifeCycleServiceGenerator } from './message';
|
||||
import { commandLifeCycleServiceGenerator } from './command';
|
||||
import { appLifeCycleServiceGenerator } from './app';
|
||||
|
||||
export const bizLifeCycleServiceGenerator: WriteableLifeCycleServiceGenerator<
|
||||
PluginBizContext
|
||||
> = plugin => ({
|
||||
appLifeCycleService: appLifeCycleServiceGenerator(plugin),
|
||||
messageLifeCycleService: messageLifeCycleServiceGenerator(plugin),
|
||||
commandLifeCycleService: commandLifeCycleServiceGenerator(plugin),
|
||||
renderLifeCycleService: renderLifeCycleServiceGenerator(plugin),
|
||||
});
|
||||
@@ -0,0 +1,7 @@
|
||||
import { type WriteableMessageLifeCycleServiceGenerator } from '@coze-common/chat-area';
|
||||
|
||||
import { type PluginBizContext } from '../../types/biz-context';
|
||||
|
||||
export const messageLifeCycleServiceGenerator: WriteableMessageLifeCycleServiceGenerator<
|
||||
PluginBizContext
|
||||
> = plugin => ({});
|
||||
@@ -0,0 +1,7 @@
|
||||
import { type WriteableRenderLifeCycleServiceGenerator } from '@coze-common/chat-area';
|
||||
|
||||
import { type PluginBizContext } from '../../types/biz-context';
|
||||
|
||||
export const renderLifeCycleServiceGenerator: WriteableRenderLifeCycleServiceGenerator<
|
||||
PluginBizContext
|
||||
> = plugin => ({});
|
||||
@@ -0,0 +1 @@
|
||||
export type PluginBizContext = Record<string, unknown>;
|
||||
1
common/_templates/chat-plugin-writeable-standard/src/typings.d.ts
vendored
Normal file
1
common/_templates/chat-plugin-writeable-standard/src/typings.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/// <reference types='@coze-arch/bot-typings' />
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { DemoComponent } from '../src';
|
||||
|
||||
export default {
|
||||
title: 'Example/Demo',
|
||||
component: DemoComponent,
|
||||
parameters: {
|
||||
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
|
||||
layout: 'centered',
|
||||
},
|
||||
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
|
||||
tags: ['autodocs'],
|
||||
// More on argTypes: https://storybook.js.org/docs/api/argtypes
|
||||
argTypes: {},
|
||||
};
|
||||
|
||||
// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
|
||||
export const Base = {
|
||||
args: {
|
||||
name: 'tecvan',
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
import { Meta } from "@storybook/blocks";
|
||||
|
||||
<Meta title="Hello world" />
|
||||
|
||||
<div className="sb-container">
|
||||
<div className='sb-section-title'>
|
||||
# Hello world
|
||||
|
||||
Hello world
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
{`
|
||||
.sb-container {
|
||||
margin-bottom: 48px;
|
||||
}
|
||||
|
||||
.sb-section {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
img {
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.sb-section-title {
|
||||
margin-bottom: 32px;
|
||||
}
|
||||
`}
|
||||
</style>
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"extends": "@coze-arch/ts-config/tsconfig.web.json",
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"rootDir": "src",
|
||||
"jsx": "react-jsx",
|
||||
"lib": ["DOM", "ESNext"],
|
||||
"module": "ESNext",
|
||||
"target": "ES2020",
|
||||
"moduleResolution": "bundler"
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"exclude": ["**/*"],
|
||||
"compilerOptions": {
|
||||
"composite": true
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.misc.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"extends": "@coze-arch/ts-config/tsconfig.web.json",
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"compilerOptions": {
|
||||
"rootDir": "./",
|
||||
"outDir": "./dist",
|
||||
"jsx": "react-jsx",
|
||||
"lib": ["DOM", "ESNext"],
|
||||
"module": "ESNext",
|
||||
"target": "ES2020",
|
||||
"moduleResolution": "bundler"
|
||||
},
|
||||
"include": ["__tests__", "vitest.config.ts", "stories"],
|
||||
"exclude": ["./dist"],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.build.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { defineConfig } from '@coze-arch/vitest-config';
|
||||
|
||||
export default defineConfig({
|
||||
dirname: __dirname,
|
||||
preset: 'web',
|
||||
});
|
||||
31
common/_templates/component/.storybook/main.js
Normal file
31
common/_templates/component/.storybook/main.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import { mergeConfig } from 'vite';
|
||||
import svgr from 'vite-plugin-svgr';
|
||||
|
||||
/** @type { import('@storybook/react-vite').StorybookConfig } */
|
||||
const config = {
|
||||
stories: ['../stories/**/*.mdx', '../stories/**/*.stories.tsx'],
|
||||
addons: [
|
||||
'@storybook/addon-links',
|
||||
'@storybook/addon-essentials',
|
||||
'@storybook/addon-onboarding',
|
||||
'@storybook/addon-interactions',
|
||||
],
|
||||
framework: {
|
||||
name: '@storybook/react-vite',
|
||||
options: {},
|
||||
},
|
||||
docs: {
|
||||
autodocs: 'tag',
|
||||
},
|
||||
viteFinal: config =>
|
||||
mergeConfig(config, {
|
||||
plugins: [
|
||||
svgr({
|
||||
svgrOptions: {
|
||||
native: false,
|
||||
},
|
||||
}),
|
||||
],
|
||||
}),
|
||||
};
|
||||
export default config;
|
||||
14
common/_templates/component/.storybook/preview.js
Normal file
14
common/_templates/component/.storybook/preview.js
Normal file
@@ -0,0 +1,14 @@
|
||||
/** @type { import('@storybook/react').Preview } */
|
||||
const preview = {
|
||||
parameters: {
|
||||
actions: { argTypesRegex: "^on[A-Z].*" },
|
||||
controls: {
|
||||
matchers: {
|
||||
color: /(background|color)$/i,
|
||||
date: /Date$/i,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default preview;
|
||||
5
common/_templates/component/.stylelintrc.js
Normal file
5
common/_templates/component/.stylelintrc.js
Normal file
@@ -0,0 +1,5 @@
|
||||
const { defineConfig } = require('@coze-arch/stylelint-config');
|
||||
|
||||
module.exports = defineConfig({
|
||||
extends: [],
|
||||
});
|
||||
16
common/_templates/component/README.md
Normal file
16
common/_templates/component/README.md
Normal file
@@ -0,0 +1,16 @@
|
||||
# {{ packageName }}
|
||||
|
||||
> Project template for react component with storybook.
|
||||
|
||||
## Features
|
||||
|
||||
- [x] eslint & ts
|
||||
- [x] esm bundle
|
||||
- [x] umd bundle
|
||||
- [x] storybook
|
||||
|
||||
## Commands
|
||||
|
||||
- init: `rush update`
|
||||
- dev: `npm run dev`
|
||||
- build: `npm run build`
|
||||
0
common/_templates/component/__tests__/.gitkeep
Normal file
0
common/_templates/component/__tests__/.gitkeep
Normal file
12
common/_templates/component/config/rush-project.json
Normal file
12
common/_templates/component/config/rush-project.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"operationSettings": [
|
||||
{
|
||||
"operationName": "test:cov",
|
||||
"outputFolderNames": ["coverage"]
|
||||
},
|
||||
{
|
||||
"operationName": "ts-check",
|
||||
"outputFolderNames": ["dist"]
|
||||
}
|
||||
]
|
||||
}
|
||||
7
common/_templates/component/eslint.config.js
Normal file
7
common/_templates/component/eslint.config.js
Normal file
@@ -0,0 +1,7 @@
|
||||
const { defineConfig } = require('@coze-arch/eslint-config');
|
||||
|
||||
module.exports = defineConfig({
|
||||
packageRoot: __dirname,
|
||||
preset: 'web',
|
||||
rules: {},
|
||||
});
|
||||
12
common/_templates/component/init.config.ts
Normal file
12
common/_templates/component/init.config.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import type { IConfig } from '../../autoinstallers/plugins/node_modules/rush-init-project-plugin';
|
||||
import SelectTeamPlugin from '../_plugins/SelectTeamPlugin';
|
||||
import SetDefaultAuthorPlugin from '../_plugins/SetDefaultAuthorPlugin';
|
||||
|
||||
const config: IConfig = {
|
||||
plugins: [new SetDefaultAuthorPlugin(), new SelectTeamPlugin()],
|
||||
defaultProjectConfiguration: {
|
||||
tags:['level-3']
|
||||
}
|
||||
};
|
||||
|
||||
export default config;
|
||||
51
common/_templates/component/package.json
Normal file
51
common/_templates/component/package.json
Normal file
@@ -0,0 +1,51 @@
|
||||
{
|
||||
"name": "{{ packageName }}",
|
||||
"version": "0.0.1",
|
||||
"description": "{{ description }}",
|
||||
"license": "Apache-2.0",
|
||||
"author": "{{ authorName }}",
|
||||
"maintainers": [],
|
||||
"main": "src/index.tsx",
|
||||
"scripts": {
|
||||
"build": "exit 0",
|
||||
"dev": "storybook dev -p 6006",
|
||||
"lint": "eslint ./ --cache",
|
||||
"test": "vitest --run --passWithNoTests",
|
||||
"test:cov": "npm run test -- --coverage"
|
||||
},
|
||||
"dependencies": {
|
||||
"classnames": "^2.3.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@coze-arch/bot-typings": "workspace:*",
|
||||
"@coze-arch/eslint-config": "workspace:*",
|
||||
"@coze-arch/stylelint-config": "workspace:*",
|
||||
"@coze-arch/ts-config": "workspace:*",
|
||||
"@coze-arch/vitest-config": "workspace:*",
|
||||
"@storybook/addon-essentials": "^7.6.7",
|
||||
"@storybook/addon-interactions": "^7.6.7",
|
||||
"@storybook/addon-links": "^7.6.7",
|
||||
"@storybook/addon-onboarding": "^1.0.10",
|
||||
"@storybook/blocks": "^7.6.7",
|
||||
"@storybook/react": "^7.6.7",
|
||||
"@storybook/react-vite": "^7.6.7",
|
||||
"@storybook/test": "^7.6.7",
|
||||
"@testing-library/jest-dom": "^6.1.5",
|
||||
"@testing-library/react": "^14.1.2",
|
||||
"@testing-library/react-hooks": "^8.0.1",
|
||||
"@types/react": "18.2.37",
|
||||
"@types/react-dom": "18.2.15",
|
||||
"@vitest/coverage-v8": "~3.0.5",
|
||||
"react": "~18.2.0",
|
||||
"react-dom": "~18.2.0",
|
||||
"storybook": "^7.6.7",
|
||||
"stylelint": "^15.11.0",
|
||||
|
||||
"vite-plugin-svgr": "~3.3.0",
|
||||
"vitest": "~3.0.5"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": ">=18.2.0",
|
||||
"react-dom": ">=18.2.0"
|
||||
}
|
||||
}
|
||||
1
common/_templates/component/src/assets/react.svg
Normal file
1
common/_templates/component/src/assets/react.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 4.0 KiB |
BIN
common/_templates/component/src/assets/rspack.png
Normal file
BIN
common/_templates/component/src/assets/rspack.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.6 KiB |
3
common/_templates/component/src/demo/index.module.less
Normal file
3
common/_templates/component/src/demo/index.module.less
Normal file
@@ -0,0 +1,3 @@
|
||||
.foo {
|
||||
font-size: 24px;
|
||||
}
|
||||
47
common/_templates/component/src/demo/index.tsx
Normal file
47
common/_templates/component/src/demo/index.tsx
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import React, { useState } from 'react';
|
||||
|
||||
import classNames from 'classnames';
|
||||
|
||||
import PngDemo from '../assets/rspack.png';
|
||||
import SVGDemo, { ReactComponent as SVGComponent } from '../assets/react.svg';
|
||||
|
||||
import s from './index.module.less';
|
||||
|
||||
export function DemoComponent(props: { name: string }): JSX.Element {
|
||||
const [foo] = useState('hello world');
|
||||
const { name } = props;
|
||||
return (
|
||||
// font-bold 来自 taiwindcss
|
||||
// 建议优先使用 taiwindcss
|
||||
<div className={classNames(s.foo, 'font-bold')}>
|
||||
{foo} {name}!
|
||||
<div>
|
||||
<div>
|
||||
SVG: <img src={SVGDemo} />
|
||||
</div>
|
||||
<div>
|
||||
SVG Icon: <SVGComponent />
|
||||
</div>
|
||||
<div>
|
||||
PNG: <img src={PngDemo} width={100} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
17
common/_templates/component/src/index.tsx
Normal file
17
common/_templates/component/src/index.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export { DemoComponent } from './demo';
|
||||
1
common/_templates/component/src/typings.d.ts
vendored
Normal file
1
common/_templates/component/src/typings.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/// <reference types='@coze-arch/bot-typings' />
|
||||
37
common/_templates/component/stories/demo.stories.tsx
Normal file
37
common/_templates/component/stories/demo.stories.tsx
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { DemoComponent } from '../src';
|
||||
|
||||
export default {
|
||||
title: 'Example/Demo',
|
||||
component: DemoComponent,
|
||||
parameters: {
|
||||
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
|
||||
layout: 'centered',
|
||||
},
|
||||
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
|
||||
tags: ['autodocs'],
|
||||
// More on argTypes: https://storybook.js.org/docs/api/argtypes
|
||||
argTypes: {},
|
||||
};
|
||||
|
||||
// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
|
||||
export const Base = {
|
||||
args: {
|
||||
name: 'tecvan',
|
||||
},
|
||||
};
|
||||
34
common/_templates/component/stories/hello.mdx
Normal file
34
common/_templates/component/stories/hello.mdx
Normal file
@@ -0,0 +1,34 @@
|
||||
import { Meta } from "@storybook/blocks";
|
||||
|
||||
<Meta title="Hello world" />
|
||||
|
||||
<div className="sb-container">
|
||||
<div className='sb-section-title'>
|
||||
# Hello world
|
||||
|
||||
Hello world
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
{`
|
||||
.sb-container {
|
||||
margin-bottom: 48px;
|
||||
}
|
||||
|
||||
.sb-section {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
img {
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.sb-section-title {
|
||||
margin-bottom: 32px;
|
||||
}
|
||||
`}
|
||||
</style>
|
||||
15
common/_templates/component/tsconfig.build.json
Normal file
15
common/_templates/component/tsconfig.build.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"extends": "@coze-arch/ts-config/tsconfig.web.json",
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"rootDir": "src",
|
||||
"jsx": "react-jsx",
|
||||
"lib": ["DOM", "ESNext"],
|
||||
"module": "ESNext",
|
||||
"target": "ES2020",
|
||||
"moduleResolution": "bundler"
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
15
common/_templates/component/tsconfig.json
Normal file
15
common/_templates/component/tsconfig.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"exclude": ["**/*"],
|
||||
"compilerOptions": {
|
||||
"composite": true
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.misc.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
20
common/_templates/component/tsconfig.misc.json
Normal file
20
common/_templates/component/tsconfig.misc.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"extends": "@coze-arch/ts-config/tsconfig.web.json",
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"compilerOptions": {
|
||||
"rootDir": "./",
|
||||
"outDir": "./dist",
|
||||
"jsx": "react-jsx",
|
||||
"lib": ["DOM", "ESNext"],
|
||||
"module": "ESNext",
|
||||
"target": "ES2020",
|
||||
"moduleResolution": "bundler"
|
||||
},
|
||||
"include": ["__tests__", "vitest.config.ts", "stories"],
|
||||
"exclude": ["./dist"],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.build.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
6
common/_templates/component/vitest.config.ts
Normal file
6
common/_templates/component/vitest.config.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { defineConfig } from '@coze-arch/vitest-config';
|
||||
|
||||
export default defineConfig({
|
||||
dirname: __dirname,
|
||||
preset: 'web',
|
||||
});
|
||||
1
common/_templates/node-core/README.md
Normal file
1
common/_templates/node-core/README.md
Normal file
@@ -0,0 +1 @@
|
||||
# {{ packageName }}
|
||||
0
common/_templates/node-core/__tests__/.gitkeep
Normal file
0
common/_templates/node-core/__tests__/.gitkeep
Normal file
12
common/_templates/node-core/config/rush-project.json
Normal file
12
common/_templates/node-core/config/rush-project.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"operationSettings": [
|
||||
{
|
||||
"operationName": "test:cov",
|
||||
"outputFolderNames": ["coverage"]
|
||||
},
|
||||
{
|
||||
"operationName": "ts-check",
|
||||
"outputFolderNames": ["dist"]
|
||||
}
|
||||
]
|
||||
}
|
||||
7
common/_templates/node-core/eslint.config.js
Normal file
7
common/_templates/node-core/eslint.config.js
Normal file
@@ -0,0 +1,7 @@
|
||||
const { defineConfig } = require('@coze-arch/eslint-config');
|
||||
|
||||
module.exports = defineConfig({
|
||||
packageRoot: __dirname,
|
||||
preset: 'node',
|
||||
rules: {},
|
||||
});
|
||||
28
common/_templates/node-core/init.config.ts
Normal file
28
common/_templates/node-core/init.config.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import type { IConfig } from '../../autoinstallers/plugins/node_modules/rush-init-project-plugin';
|
||||
import SelectTeamPlugin from '../_plugins/SelectTeamPlugin';
|
||||
import SetDefaultAuthorPlugin from '../_plugins/SetDefaultAuthorPlugin';
|
||||
|
||||
const config: IConfig = {
|
||||
plugins: [new SetDefaultAuthorPlugin(), new SelectTeamPlugin()],
|
||||
defaultProjectConfiguration: {
|
||||
tags:['level-3']
|
||||
}
|
||||
};
|
||||
|
||||
export default config;
|
||||
26
common/_templates/node-core/package.json
Normal file
26
common/_templates/node-core/package.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "{{ packageName }}",
|
||||
"version": "0.0.1",
|
||||
"description": "{{ description }}",
|
||||
"license": "Apache-2.0",
|
||||
"author": "{{ authorName }}",
|
||||
"maintainers": [],
|
||||
"main": "src/index.ts",
|
||||
"scripts": {
|
||||
"build": "exit 0",
|
||||
"lint": "eslint ./ --cache",
|
||||
"test": "vitest --run --passWithNoTests",
|
||||
"test:cov": "npm run test -- --coverage"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"@coze-arch/eslint-config": "workspace:*",
|
||||
"@coze-arch/ts-config": "workspace:*",
|
||||
"@coze-arch/vitest-config": "workspace:*",
|
||||
"@types/node": "^18",
|
||||
"@vitest/coverage-v8": "~3.0.5",
|
||||
|
||||
"vitest": "~3.0.5",
|
||||
"sucrase": "^3.32.0"
|
||||
}
|
||||
}
|
||||
17
common/_templates/node-core/src/index.ts
Normal file
17
common/_templates/node-core/src/index.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export const foo = 'bar';
|
||||
13
common/_templates/node-core/tsconfig.build.json
Normal file
13
common/_templates/node-core/tsconfig.build.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"extends": "@coze-arch/ts-config/tsconfig.node.json",
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"rootDir": "src",
|
||||
"module": "CommonJS",
|
||||
"target": "ES2020",
|
||||
"moduleResolution": "node"
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
15
common/_templates/node-core/tsconfig.json
Normal file
15
common/_templates/node-core/tsconfig.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"exclude": ["**/*"],
|
||||
"compilerOptions": {
|
||||
"composite": true
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.misc.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
18
common/_templates/node-core/tsconfig.misc.json
Normal file
18
common/_templates/node-core/tsconfig.misc.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"extends": "@coze-arch/ts-config/tsconfig.node.json",
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"compilerOptions": {
|
||||
"rootDir": "./",
|
||||
"outDir": "./dist",
|
||||
"module": "CommonJS",
|
||||
"target": "ES2020",
|
||||
"moduleResolution": "node"
|
||||
},
|
||||
"include": ["__tests__", "vitest.config.ts"],
|
||||
"exclude": ["./dist"],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.build.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
22
common/_templates/node-core/vitest.config.ts
Normal file
22
common/_templates/node-core/vitest.config.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { defineConfig } from '@coze-arch/vitest-config';
|
||||
|
||||
export default defineConfig({
|
||||
dirname: __dirname,
|
||||
preset: 'node',
|
||||
});
|
||||
5
common/_templates/rsbuild-web/.stylelintrc.js
Normal file
5
common/_templates/rsbuild-web/.stylelintrc.js
Normal file
@@ -0,0 +1,5 @@
|
||||
const { defineConfig } = require('@coze-arch/stylelint-config');
|
||||
|
||||
module.exports = defineConfig({
|
||||
extends: [],
|
||||
});
|
||||
6
common/_templates/rsbuild-web/README.md
Normal file
6
common/_templates/rsbuild-web/README.md
Normal file
@@ -0,0 +1,6 @@
|
||||
# [🦀️ Rsbuild](https://rsbuild.dev/zh/guide/start/index) & React App
|
||||
Web项目初始化模板,已包含功能:
|
||||
* react + react-router
|
||||
* slardar
|
||||
* less(module), [tailwindcss](https://tailwindcss.com/docs)
|
||||
* vitest
|
||||
0
common/_templates/rsbuild-web/__tests__/.gitkeep
Normal file
0
common/_templates/rsbuild-web/__tests__/.gitkeep
Normal file
17
common/_templates/rsbuild-web/config/rush-project.json
Normal file
17
common/_templates/rsbuild-web/config/rush-project.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/rush/v5/rush-project.schema.json",
|
||||
"operationSettings": [
|
||||
{
|
||||
"operationName": "build",
|
||||
"outputFolderNames": ["output"]
|
||||
},
|
||||
{
|
||||
"operationName": "test:cov",
|
||||
"outputFolderNames": ["coverage"]
|
||||
},
|
||||
{
|
||||
"operationName": "ts-check",
|
||||
"outputFolderNames": ["dist"]
|
||||
}
|
||||
]
|
||||
}
|
||||
6
common/_templates/rsbuild-web/eslint.config.js
Normal file
6
common/_templates/rsbuild-web/eslint.config.js
Normal file
@@ -0,0 +1,6 @@
|
||||
const { defineConfig } = require('@coze-arch/eslint-config');
|
||||
|
||||
module.exports = defineConfig({
|
||||
preset: 'web',
|
||||
packageRoot: __dirname,
|
||||
});
|
||||
12
common/_templates/rsbuild-web/index.html
Normal file
12
common/_templates/rsbuild-web/index.html
Normal file
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>{{ packageName }}</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
</body>
|
||||
</html>
|
||||
12
common/_templates/rsbuild-web/init.config.ts
Normal file
12
common/_templates/rsbuild-web/init.config.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import type { IConfig } from '../../autoinstallers/plugins/node_modules/rush-init-project-plugin';
|
||||
import SelectTeamPlugin from '../_plugins/SelectTeamPlugin';
|
||||
import SetDefaultAuthorPlugin from '../_plugins/SetDefaultAuthorPlugin';
|
||||
|
||||
const config: IConfig = {
|
||||
plugins: [new SetDefaultAuthorPlugin(), new SelectTeamPlugin()],
|
||||
defaultProjectConfiguration: {
|
||||
tags:['level-4']
|
||||
}
|
||||
};
|
||||
|
||||
export default config;
|
||||
45
common/_templates/rsbuild-web/package.json
Normal file
45
common/_templates/rsbuild-web/package.json
Normal file
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"name": "{{ packageName }}",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"description": "{{ description }}",
|
||||
"keywords": [],
|
||||
"license": "Apache-2.0",
|
||||
"author": "{{ authorName }}",
|
||||
"maintainers": [],
|
||||
"sideEffects": false,
|
||||
"scripts": {
|
||||
"build": "rsbuild build",
|
||||
"dev": "rsbuild dev",
|
||||
"lint": "eslint ./ --cache --quiet",
|
||||
"preview": "rsbuild preview",
|
||||
"test": "vitest --run --passWithNoTests",
|
||||
"test:cov": "vitest --run --passWithNoTests --coverage"
|
||||
},
|
||||
"dependencies": {
|
||||
"@coze-arch/logger": "workspace:*",
|
||||
"react": "~18.2.0",
|
||||
"react-dom": "~18.2.0",
|
||||
"react-error-boundary": "^4.0.9",
|
||||
"react-router-dom": "^6.11.1",
|
||||
"zustand": "^4.4.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@coze-arch/eslint-config": "workspace:*",
|
||||
"@coze-arch/ts-config": "workspace:*",
|
||||
"@coze-arch/vitest-config": "workspace:*",
|
||||
"@coze-arch/stylelint-config": "workspace:*",
|
||||
"@rsbuild/core": "^0.2.18",
|
||||
"@rsbuild/plugin-react": "^0.2.18",
|
||||
"@slardar/web": "1.7.0",
|
||||
"@types/react": "18.2.37",
|
||||
"@types/react-dom": "18.2.15",
|
||||
"@vitest/coverage-v8": "~3.0.5",
|
||||
"autoprefixer": "^10.4.16",
|
||||
"postcss": "^8.4.32",
|
||||
"postcss-loader": "^7.3.3",
|
||||
"tailwindcss": "~3.3.3",
|
||||
|
||||
"vitest": "~3.0.5"
|
||||
}
|
||||
}
|
||||
15
common/_templates/rsbuild-web/rsbuild.config.ts
Normal file
15
common/_templates/rsbuild-web/rsbuild.config.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import tailwindcss from 'tailwindcss';
|
||||
import { pluginReact } from '@rsbuild/plugin-react';
|
||||
import { defineConfig } from '@rsbuild/core';
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [pluginReact()],
|
||||
html: {
|
||||
template: './index.html',
|
||||
},
|
||||
tools: {
|
||||
postcss(config) {
|
||||
config.postcssOptions?.plugins?.push(tailwindcss);
|
||||
},
|
||||
},
|
||||
});
|
||||
24
common/_templates/rsbuild-web/scm_build.sh
Normal file
24
common/_templates/rsbuild-web/scm_build.sh
Normal file
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -ex
|
||||
|
||||
# Switch cwd to the project folder
|
||||
cd $(dirname "$0")
|
||||
|
||||
# Import the utilities functions
|
||||
source ../../scripts/scm_base.sh
|
||||
|
||||
# Clean up the build directory
|
||||
rm -rf dist
|
||||
rm -rf "${ROOT_DIR}"/output
|
||||
|
||||
# Prepare
|
||||
prepare_environment
|
||||
|
||||
# Install the dependencies
|
||||
install_project_deps
|
||||
|
||||
build_project
|
||||
|
||||
mkdir -p ${ROOT_DIR}/output
|
||||
cp -r ./dist/* ${ROOT_DIR}/output/
|
||||
44
common/_templates/rsbuild-web/src/app.tsx
Normal file
44
common/_templates/rsbuild-web/src/app.tsx
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { RouterProvider, createBrowserRouter } from 'react-router-dom';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
import slardar from '@slardar/web';
|
||||
import { reporter } from '@coze-arch/logger';
|
||||
|
||||
import { Page1 } from './pages/page1';
|
||||
import { MainPage } from './pages/main';
|
||||
|
||||
const router = createBrowserRouter([
|
||||
{
|
||||
path: '/',
|
||||
children: [
|
||||
{ path: 'page1', element: <Page1 /> },
|
||||
{ path: '', element: <MainPage /> },
|
||||
{ path: '*', element: <div>404</div> },
|
||||
],
|
||||
},
|
||||
]);
|
||||
|
||||
export function App() {
|
||||
useEffect(() => {
|
||||
reporter.info({ message: 'Ok fine' });
|
||||
reporter.init(slardar);
|
||||
}, []);
|
||||
|
||||
return <RouterProvider router={router} />;
|
||||
}
|
||||
8
common/_templates/rsbuild-web/src/assets/react.svg
Normal file
8
common/_templates/rsbuild-web/src/assets/react.svg
Normal file
@@ -0,0 +1,8 @@
|
||||
<svg width="100%" height="100%" viewBox="-10.5 -9.45 21 18.9" fill="#357da1" xmlns="http://www.w3.org/2000/svg">
|
||||
<circle cx="0" cy="0" r="2" fill="#357da1"></circle>
|
||||
<g stroke="#357da1" stroke-width="1" fill="none">
|
||||
<ellipse rx="10" ry="4.5"></ellipse>
|
||||
<ellipse rx="10" ry="4.5" transform="rotate(60)"></ellipse>
|
||||
<ellipse rx="10" ry="4.5" transform="rotate(120)"></ellipse>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 404 B |
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user