Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
GJHack committed Nov 23, 2023
0 parents commit 5c527df
Show file tree
Hide file tree
Showing 26 changed files with 305 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Strapi plugin exchange

A quick description of exchange.
26 changes: 26 additions & 0 deletions admin/src/components/Initializer/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
*
* Initializer
*
*/

import { useEffect, useRef } from 'react';
import PropTypes from 'prop-types';
import pluginId from '../../pluginId';

const Initializer = ({ setPlugin }) => {
const ref = useRef();
ref.current = setPlugin;

useEffect(() => {
ref.current(pluginId);
}, []);

return null;
};

Initializer.propTypes = {
setPlugin: PropTypes.func.isRequired,
};

export default Initializer;
12 changes: 12 additions & 0 deletions admin/src/components/PluginIcon/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
*
* PluginIcon
*
*/

import React from 'react';
import { Puzzle } from '@strapi/icons';

const PluginIcon = () => <Puzzle />;

export default PluginIcon;
63 changes: 63 additions & 0 deletions admin/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { prefixPluginTranslations } from '@strapi/helper-plugin';
import pluginPkg from '../../package.json';
import pluginId from './pluginId';
import Initializer from './components/Initializer';
import PluginIcon from './components/PluginIcon';

const name = pluginPkg.strapi.name;

export default {
register(app) {
app.addMenuLink({
to: `/plugins/${pluginId}`,
icon: PluginIcon,
intlLabel: {
id: `${pluginId}.plugin.name`,
defaultMessage: name,
},
Component: async () => {
const component = await import(/* webpackChunkName: "[request]" */ './pages/App');

return component;
},
permissions: [
// Uncomment to set the permissions of the plugin here
// {
// action: '', // the action name should be plugin::plugin-name.actionType
// subject: null,
// },
],
});
app.registerPlugin({
id: pluginId,
initializer: Initializer,
isReady: false,
name,
});
},

bootstrap(app) {},
async registerTrads({ locales }) {
const importedTrads = await Promise.all(
locales.map((locale) => {
return import(
/* webpackChunkName: "translation-[request]" */ `./translations/${locale}.json`
)
.then(({ default: data }) => {
return {
data: prefixPluginTranslations(data, pluginId),
locale,
};
})
.catch(() => {
return {
data: {},
locale,
};
});
})
);

return Promise.resolve(importedTrads);
},
};
25 changes: 25 additions & 0 deletions admin/src/pages/App/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
*
* This component is the skeleton around the actual pages, and should only
* contain code that should be seen on all pages. (e.g. navigation bar)
*
*/

import React from 'react';
import { Switch, Route } from 'react-router-dom';
import { AnErrorOccurred } from '@strapi/helper-plugin';
import pluginId from '../../pluginId';
import HomePage from '../HomePage';

const App = () => {
return (
<div>
<Switch>
<Route path={`/plugins/${pluginId}`} component={HomePage} exact />
<Route component={AnErrorOccurred} />
</Switch>
</div>
);
};

export default App;
20 changes: 20 additions & 0 deletions admin/src/pages/HomePage/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
*
* HomePage
*
*/

import React from 'react';
// import PropTypes from 'prop-types';
import pluginId from '../../pluginId';

const HomePage = () => {
return (
<div>
<h1>{pluginId}&apos;s HomePage</h1>
<p>Happy coding</p>
</div>
);
};

export default HomePage;
5 changes: 5 additions & 0 deletions admin/src/pluginId.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import pluginPkg from '../../package.json';

const pluginId = pluginPkg.name.replace(/^(@[^-,.][\w,-]+\/|strapi-)plugin-/i, '');

export default pluginId;
1 change: 1 addition & 0 deletions admin/src/translations/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions admin/src/translations/fr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
5 changes: 5 additions & 0 deletions admin/src/utils/getTrad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import pluginId from '../pluginId';

const getTrad = (id) => `${pluginId}.${id}`;

export default getTrad;
42 changes: 42 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "exchange",
"version": "0.0.0",
"description": "This is the description of the plugin.",
"strapi": {
"name": "exchange",
"description": "Description of Exchange plugin",
"kind": "plugin",
"displayName": "Exchange"
},
"dependencies": {
"@strapi/design-system": "^1.6.3",
"@strapi/helper-plugin": "^4.6.0",
"@strapi/icons": "^1.6.3",
"prop-types": "^15.7.2"
},
"devDependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^5.3.4",
"styled-components": "^5.3.6"
},
"peerDependencies": {
"react": "^17.0.0 || ^18.0.0",
"react-dom": "^17.0.0 || ^18.0.0",
"react-router-dom": "^5.3.4",
"styled-components": "^5.3.6"
},
"author": {
"name": "A Strapi developer"
},
"maintainers": [
{
"name": "A Strapi developer"
}
],
"engines": {
"node": ">=16.0.0 <=20.x.x",
"npm": ">=6.0.0"
},
"license": "MIT"
}
5 changes: 5 additions & 0 deletions server/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = ({ strapi }) => {
// bootstrap phase
};
6 changes: 6 additions & 0 deletions server/config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

module.exports = {
default: {},
validator() {},
};
3 changes: 3 additions & 0 deletions server/content-types/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = {};
7 changes: 7 additions & 0 deletions server/controllers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

const myController = require('./my-controller');

module.exports = {
myController,
};
10 changes: 10 additions & 0 deletions server/controllers/my-controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

module.exports = ({ strapi }) => ({
index(ctx) {
ctx.body = strapi
.plugin('exchange')
.service('myService')
.getWelcomeMessage();
},
});
5 changes: 5 additions & 0 deletions server/destroy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = ({ strapi }) => {
// destroy phase
};
25 changes: 25 additions & 0 deletions server/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

const register = require('./register');
const bootstrap = require('./bootstrap');
const destroy = require('./destroy');
const config = require('./config');
const contentTypes = require('./content-types');
const controllers = require('./controllers');
const routes = require('./routes');
const middlewares = require('./middlewares');
const policies = require('./policies');
const services = require('./services');

module.exports = {
register,
bootstrap,
destroy,
config,
controllers,
routes,
services,
contentTypes,
policies,
middlewares,
};
3 changes: 3 additions & 0 deletions server/middlewares/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = {};
3 changes: 3 additions & 0 deletions server/policies/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = {};
5 changes: 5 additions & 0 deletions server/register.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = ({ strapi }) => {
// registeration phase
};
10 changes: 10 additions & 0 deletions server/routes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = [
{
method: 'GET',
path: '/',
handler: 'myController.index',
config: {
policies: [],
},
},
];
7 changes: 7 additions & 0 deletions server/services/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

const myService = require('./my-service');

module.exports = {
myService,
};
7 changes: 7 additions & 0 deletions server/services/my-service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

module.exports = ({ strapi }) => ({
getWelcomeMessage() {
return 'Welcome to Strapi 🚀';
},
});
3 changes: 3 additions & 0 deletions strapi-admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = require('./admin/src').default;
3 changes: 3 additions & 0 deletions strapi-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = require('./server');

0 comments on commit 5c527df

Please sign in to comment.