Skip to content

Commit 64284dd

Browse files
committed
setup the plugin repo
1 parent 56e3b83 commit 64284dd

File tree

28 files changed

+348
-0
lines changed

28 files changed

+348
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
*
3+
* Initializer
4+
*
5+
*/
6+
7+
import { useEffect, useRef } from 'react';
8+
import pluginId from '../../pluginId';
9+
10+
type InitializerProps = {
11+
setPlugin: (id: string) => void;
12+
};
13+
14+
const Initializer = ({ setPlugin }: InitializerProps) => {
15+
const ref = useRef(setPlugin);
16+
17+
useEffect(() => {
18+
ref.current(pluginId);
19+
}, []);
20+
21+
return null;
22+
};
23+
24+
export default Initializer;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
*
3+
* PluginIcon
4+
*
5+
*/
6+
7+
import React from 'react';
8+
import { Puzzle } from '@strapi/icons';
9+
10+
const PluginIcon = () => <Puzzle />;
11+
12+
export default PluginIcon;

admin/src/index.tsx

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { prefixPluginTranslations } from '@strapi/helper-plugin';
2+
3+
import pluginPkg from '../../package.json';
4+
import pluginId from './pluginId';
5+
import Initializer from './components/Initializer';
6+
import PluginIcon from './components/PluginIcon';
7+
8+
const name = pluginPkg.strapi.name;
9+
10+
export default {
11+
register(app: any) {
12+
app.addMenuLink({
13+
to: `/plugins/${pluginId}`,
14+
icon: PluginIcon,
15+
intlLabel: {
16+
id: `${pluginId}.plugin.name`,
17+
defaultMessage: name,
18+
},
19+
Component: async () => {
20+
const component = await import(/* webpackChunkName: "[request]" */ './pages/App');
21+
22+
return component;
23+
},
24+
permissions: [
25+
// Uncomment to set the permissions of the plugin here
26+
// {
27+
// action: '', // the action name should be plugin::plugin-name.actionType
28+
// subject: null,
29+
// },
30+
],
31+
});
32+
const plugin = {
33+
id: pluginId,
34+
initializer: Initializer,
35+
isReady: false,
36+
name,
37+
};
38+
39+
app.registerPlugin(plugin);
40+
},
41+
42+
bootstrap(app: any) {},
43+
44+
async registerTrads(app: any) {
45+
const { locales } = app;
46+
47+
const importedTrads = await Promise.all(
48+
(locales as any[]).map((locale) => {
49+
return import(`./translations/${locale}.json`)
50+
.then(({ default: data }) => {
51+
return {
52+
data: prefixPluginTranslations(data, pluginId),
53+
locale,
54+
};
55+
})
56+
.catch(() => {
57+
return {
58+
data: {},
59+
locale,
60+
};
61+
});
62+
})
63+
);
64+
65+
return Promise.resolve(importedTrads);
66+
},
67+
};

admin/src/pages/App/index.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
*
3+
* This component is the skeleton around the actual pages, and should only
4+
* contain code that should be seen on all pages. (e.g. navigation bar)
5+
*
6+
*/
7+
8+
import React from 'react';
9+
import { Switch, Route } from 'react-router-dom';
10+
import { AnErrorOccurred } from '@strapi/helper-plugin';
11+
import pluginId from '../../pluginId';
12+
import HomePage from '../HomePage';
13+
14+
const App = () => {
15+
return (
16+
<div>
17+
<Switch>
18+
<Route path={`/plugins/${pluginId}`} component={HomePage} exact />
19+
<Route component={AnErrorOccurred} />
20+
</Switch>
21+
</div>
22+
);
23+
};
24+
25+
export default App;

admin/src/pages/HomePage/index.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
*
3+
* HomePage
4+
*
5+
*/
6+
7+
import React from 'react';
8+
import pluginId from '../../pluginId';
9+
10+
const HomePage = () => {
11+
return (
12+
<div>
13+
<h1>{pluginId}&apos;s HomePage</h1>
14+
<p>Happy coding</p>
15+
</div>
16+
);
17+
};
18+
19+
export default HomePage;

admin/src/pluginId.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import pluginPkg from '../../package.json';
2+
3+
const pluginId = pluginPkg.name.replace(/^(@[^-,.][\w,-]+\/|strapi-)plugin-/i, '');
4+
5+
export default pluginId;

admin/src/translations/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

admin/src/translations/fr.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

admin/src/utils/getTrad.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import pluginId from '../pluginId';
2+
3+
const getTrad = (id: string) => `${pluginId}.${id}`;
4+
5+
export default getTrad;

custom.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
declare module '@strapi/design-system/*';
2+
declare module '@strapi/design-system';
3+
declare module '@strapi/icons';
4+
declare module '@strapi/icons/*';
5+
declare module '@strapi/helper-plugin';

package.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"name": "firebase-auth",
3+
"version": "0.0.0",
4+
"description": "This is the description of the plugin.",
5+
"strapi": {
6+
"name": "firebase-auth",
7+
"description": "Description of firebase-auth plugin",
8+
"kind": "plugin"
9+
},
10+
"dependencies": {
11+
"@strapi/design-system": "^1.6.3",
12+
"@strapi/helper-plugin": "^4.6.0",
13+
"@strapi/icons": "^1.6.3",
14+
"prop-types": "^15.7.2"
15+
},
16+
"devDependencies": {
17+
"@strapi/typescript-utils": "^4.6.0",
18+
"@types/react": "^17.0.53",
19+
"@types/react-dom": "^18.0.28",
20+
"@types/react-router-dom": "^5.3.3",
21+
"@types/styled-components": "^5.1.26",
22+
"react": "^18.2.0",
23+
"react-dom": "^18.2.0",
24+
"react-router-dom": "^5.3.4",
25+
"styled-components": "^5.3.6",
26+
"typescript": "5.0.4"
27+
},
28+
"peerDependencies": {
29+
"react": "^17.0.0 || ^18.0.0",
30+
"react-dom": "^17.0.0 || ^18.0.0",
31+
"react-router-dom": "^5.3.4",
32+
"styled-components": "^5.3.6"
33+
},
34+
"author": {
35+
"name": "A Strapi developer"
36+
},
37+
"maintainers": [
38+
{
39+
"name": "A Strapi developer"
40+
}
41+
],
42+
"engines": {
43+
"node": ">=16.0.0 <=20.x.x",
44+
"npm": ">=6.0.0"
45+
},
46+
"scripts": {
47+
"develop": "tsc -p tsconfig.server.json -w",
48+
"build": "tsc -p tsconfig.server.json"
49+
},
50+
"license": "MIT"
51+
}

server/bootstrap.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { Strapi } from '@strapi/strapi';
2+
3+
export default ({ strapi }: { strapi: Strapi }) => {
4+
// bootstrap phase
5+
};

server/config/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default {
2+
default: {},
3+
validator() {},
4+
};

server/content-types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default {};

server/controllers/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import myController from './my-controller';
2+
3+
export default {
4+
myController,
5+
};

server/controllers/my-controller.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Strapi } from '@strapi/strapi';
2+
3+
export default ({ strapi }: { strapi: Strapi }) => ({
4+
index(ctx) {
5+
ctx.body = strapi
6+
.plugin('firebase-auth')
7+
.service('myService')
8+
.getWelcomeMessage();
9+
},
10+
});

server/destroy.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { Strapi } from '@strapi/strapi';
2+
3+
export default ({ strapi }: { strapi: Strapi }) => {
4+
// destroy phase
5+
};

server/index.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import register from './register';
2+
import bootstrap from './bootstrap';
3+
import destroy from './destroy';
4+
import config from './config';
5+
import contentTypes from './content-types';
6+
import controllers from './controllers';
7+
import routes from './routes';
8+
import middlewares from './middlewares';
9+
import policies from './policies';
10+
import services from './services';
11+
12+
export default {
13+
register,
14+
bootstrap,
15+
destroy,
16+
config,
17+
controllers,
18+
routes,
19+
services,
20+
contentTypes,
21+
policies,
22+
middlewares,
23+
};

server/middlewares/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default {};

server/policies/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default {};

server/register.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { Strapi } from '@strapi/strapi';
2+
3+
export default ({ strapi }: { strapi: Strapi }) => {
4+
// registeration phase
5+
};

server/routes/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default [
2+
{
3+
method: 'GET',
4+
path: '/',
5+
handler: 'myController.index',
6+
config: {
7+
policies: [],
8+
},
9+
},
10+
];

server/services/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import myService from './my-service';
2+
3+
export default {
4+
myService,
5+
};

server/services/my-service.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Strapi } from '@strapi/strapi';
2+
3+
export default ({ strapi }: { strapi: Strapi }) => ({
4+
getWelcomeMessage() {
5+
return 'Welcome to Strapi 🚀';
6+
},
7+
});

strapi-admin.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
module.exports = require('./admin/src').default;

strapi-server.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
module.exports = require('./dist/server');

tsconfig.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"extends": "@strapi/typescript-utils/tsconfigs/admin",
3+
4+
"compilerOptions": {
5+
"target": "ESNext",
6+
"strict": true
7+
},
8+
9+
"include": ["admin", "custom.d.ts"],
10+
11+
"exclude": [
12+
"node_modules/",
13+
"dist/",
14+
15+
// Do not include server files in the server compilation
16+
"server/",
17+
// Do not include test files
18+
"**/*.test.ts"
19+
]
20+
}

tsconfig.server.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"extends": "@strapi/typescript-utils/tsconfigs/server",
3+
4+
"compilerOptions": {
5+
"outDir": "dist",
6+
"rootDir": "."
7+
},
8+
9+
"include": [
10+
// Include the root directory
11+
"server",
12+
// Force the JSON files in the src folder to be included
13+
"server/**/*.json"
14+
],
15+
16+
"exclude": [
17+
"node_modules/",
18+
"dist/",
19+
20+
// Do not include admin files in the server compilation
21+
"admin/",
22+
// Do not include test files
23+
"**/*.test.ts"
24+
]
25+
}

0 commit comments

Comments
 (0)