Initial Strapi plugin project
This commit is contained in:
2
admin/custom.d.ts
vendored
Normal file
2
admin/custom.d.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
declare module '@strapi/design-system/*';
|
||||
declare module '@strapi/design-system';
|
||||
19
admin/src/components/Initializer.tsx
Normal file
19
admin/src/components/Initializer.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
import { useEffect, useRef } from 'react';
|
||||
|
||||
import { PLUGIN_ID } from '../pluginId';
|
||||
|
||||
type InitializerProps = {
|
||||
setPlugin: (id: string) => void;
|
||||
};
|
||||
|
||||
const Initializer = ({ setPlugin }: InitializerProps) => {
|
||||
const ref = useRef(setPlugin);
|
||||
|
||||
useEffect(() => {
|
||||
ref.current(PLUGIN_ID);
|
||||
}, []);
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
export { Initializer };
|
||||
5
admin/src/components/PluginIcon.tsx
Normal file
5
admin/src/components/PluginIcon.tsx
Normal file
@@ -0,0 +1,5 @@
|
||||
import { PuzzlePiece } from '@strapi/icons';
|
||||
|
||||
const PluginIcon = () => <PuzzlePiece />;
|
||||
|
||||
export { PluginIcon };
|
||||
43
admin/src/index.ts
Normal file
43
admin/src/index.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { getTranslation } from './utils/getTranslation';
|
||||
import { PLUGIN_ID } from './pluginId';
|
||||
import { Initializer } from './components/Initializer';
|
||||
import { PluginIcon } from './components/PluginIcon';
|
||||
|
||||
export default {
|
||||
register(app: any) {
|
||||
app.addMenuLink({
|
||||
to: `plugins/${PLUGIN_ID}`,
|
||||
icon: PluginIcon,
|
||||
intlLabel: {
|
||||
id: `${PLUGIN_ID}.plugin.name`,
|
||||
defaultMessage: PLUGIN_ID,
|
||||
},
|
||||
Component: async () => {
|
||||
const { App } = await import('./pages/App');
|
||||
|
||||
return App;
|
||||
},
|
||||
});
|
||||
|
||||
app.registerPlugin({
|
||||
id: PLUGIN_ID,
|
||||
initializer: Initializer,
|
||||
isReady: false,
|
||||
name: PLUGIN_ID,
|
||||
});
|
||||
},
|
||||
|
||||
async registerTrads({ locales }: { locales: string[] }) {
|
||||
return Promise.all(
|
||||
locales.map(async (locale) => {
|
||||
try {
|
||||
const { default: data } = await import(`./translations/${locale}.json`);
|
||||
|
||||
return { data, locale };
|
||||
} catch {
|
||||
return { data: {}, locale };
|
||||
}
|
||||
})
|
||||
);
|
||||
},
|
||||
};
|
||||
15
admin/src/pages/App.tsx
Normal file
15
admin/src/pages/App.tsx
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Page } from '@strapi/strapi/admin';
|
||||
import { Routes, Route } from 'react-router-dom';
|
||||
|
||||
import { HomePage } from './HomePage';
|
||||
|
||||
const App = () => {
|
||||
return (
|
||||
<Routes>
|
||||
<Route index element={<HomePage />} />
|
||||
<Route path="*" element={<Page.Error />} />
|
||||
</Routes>
|
||||
);
|
||||
};
|
||||
|
||||
export { App };
|
||||
16
admin/src/pages/HomePage.tsx
Normal file
16
admin/src/pages/HomePage.tsx
Normal file
@@ -0,0 +1,16 @@
|
||||
import { Main } from '@strapi/design-system';
|
||||
import { useIntl } from 'react-intl';
|
||||
|
||||
import { getTranslation } from '../utils/getTranslation';
|
||||
|
||||
const HomePage = () => {
|
||||
const { formatMessage } = useIntl();
|
||||
|
||||
return (
|
||||
<Main>
|
||||
<h1>Welcome to {formatMessage({ id: getTranslation('plugin.name') })}</h1>
|
||||
</Main>
|
||||
);
|
||||
};
|
||||
|
||||
export { HomePage };
|
||||
1
admin/src/pluginId.ts
Normal file
1
admin/src/pluginId.ts
Normal file
@@ -0,0 +1 @@
|
||||
export const PLUGIN_ID = 'checkbox-list';
|
||||
1
admin/src/translations/en.json
Normal file
1
admin/src/translations/en.json
Normal file
@@ -0,0 +1 @@
|
||||
{}
|
||||
5
admin/src/utils/getTranslation.ts
Normal file
5
admin/src/utils/getTranslation.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { PLUGIN_ID } from '../pluginId';
|
||||
|
||||
const getTranslation = (id: string) => `${PLUGIN_ID}.${id}`;
|
||||
|
||||
export { getTranslation };
|
||||
10
admin/tsconfig.build.json
Normal file
10
admin/tsconfig.build.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"extends": "./tsconfig",
|
||||
"include": ["./src", "./custom.d.ts"],
|
||||
"exclude": ["**/*.test.ts", "**/*.test.tsx"],
|
||||
"compilerOptions": {
|
||||
"rootDir": "../",
|
||||
"baseUrl": ".",
|
||||
"outDir": "./dist"
|
||||
}
|
||||
}
|
||||
8
admin/tsconfig.json
Normal file
8
admin/tsconfig.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "@strapi/typescript-utils/tsconfigs/admin",
|
||||
"include": ["./src", "./custom.d.ts"],
|
||||
"compilerOptions": {
|
||||
"rootDir": "../",
|
||||
"baseUrl": "."
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user