From 5c527dfab06eede8657ce837f75dcedd407589dd Mon Sep 17 00:00:00 2001 From: GJHack Date: Thu, 23 Nov 2023 10:34:18 +1000 Subject: [PATCH] init --- README.md | 3 ++ admin/src/components/Initializer/index.js | 26 ++++++++++ admin/src/components/PluginIcon/index.js | 12 +++++ admin/src/index.js | 63 +++++++++++++++++++++++ admin/src/pages/App/index.js | 25 +++++++++ admin/src/pages/HomePage/index.js | 20 +++++++ admin/src/pluginId.js | 5 ++ admin/src/translations/en.json | 1 + admin/src/translations/fr.json | 1 + admin/src/utils/getTrad.js | 5 ++ package.json | 42 +++++++++++++++ server/bootstrap.js | 5 ++ server/config/index.js | 6 +++ server/content-types/index.js | 3 ++ server/controllers/index.js | 7 +++ server/controllers/my-controller.js | 10 ++++ server/destroy.js | 5 ++ server/index.js | 25 +++++++++ server/middlewares/index.js | 3 ++ server/policies/index.js | 3 ++ server/register.js | 5 ++ server/routes/index.js | 10 ++++ server/services/index.js | 7 +++ server/services/my-service.js | 7 +++ strapi-admin.js | 3 ++ strapi-server.js | 3 ++ 26 files changed, 305 insertions(+) create mode 100644 README.md create mode 100644 admin/src/components/Initializer/index.js create mode 100644 admin/src/components/PluginIcon/index.js create mode 100644 admin/src/index.js create mode 100644 admin/src/pages/App/index.js create mode 100644 admin/src/pages/HomePage/index.js create mode 100644 admin/src/pluginId.js create mode 100644 admin/src/translations/en.json create mode 100644 admin/src/translations/fr.json create mode 100644 admin/src/utils/getTrad.js create mode 100644 package.json create mode 100644 server/bootstrap.js create mode 100644 server/config/index.js create mode 100644 server/content-types/index.js create mode 100644 server/controllers/index.js create mode 100644 server/controllers/my-controller.js create mode 100644 server/destroy.js create mode 100644 server/index.js create mode 100644 server/middlewares/index.js create mode 100644 server/policies/index.js create mode 100644 server/register.js create mode 100644 server/routes/index.js create mode 100644 server/services/index.js create mode 100644 server/services/my-service.js create mode 100644 strapi-admin.js create mode 100644 strapi-server.js diff --git a/README.md b/README.md new file mode 100644 index 0000000..2a3bc35 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Strapi plugin exchange + +A quick description of exchange. diff --git a/admin/src/components/Initializer/index.js b/admin/src/components/Initializer/index.js new file mode 100644 index 0000000..71dc50e --- /dev/null +++ b/admin/src/components/Initializer/index.js @@ -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; diff --git a/admin/src/components/PluginIcon/index.js b/admin/src/components/PluginIcon/index.js new file mode 100644 index 0000000..e2bb2d5 --- /dev/null +++ b/admin/src/components/PluginIcon/index.js @@ -0,0 +1,12 @@ +/** + * + * PluginIcon + * + */ + +import React from 'react'; +import { Puzzle } from '@strapi/icons'; + +const PluginIcon = () => ; + +export default PluginIcon; diff --git a/admin/src/index.js b/admin/src/index.js new file mode 100644 index 0000000..23240d8 --- /dev/null +++ b/admin/src/index.js @@ -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); + }, +}; diff --git a/admin/src/pages/App/index.js b/admin/src/pages/App/index.js new file mode 100644 index 0000000..c87a263 --- /dev/null +++ b/admin/src/pages/App/index.js @@ -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 ( +
+ + + + +
+ ); +}; + +export default App; diff --git a/admin/src/pages/HomePage/index.js b/admin/src/pages/HomePage/index.js new file mode 100644 index 0000000..d807766 --- /dev/null +++ b/admin/src/pages/HomePage/index.js @@ -0,0 +1,20 @@ +/* + * + * HomePage + * + */ + +import React from 'react'; +// import PropTypes from 'prop-types'; +import pluginId from '../../pluginId'; + +const HomePage = () => { + return ( +
+

{pluginId}'s HomePage

+

Happy coding

+
+ ); +}; + +export default HomePage; diff --git a/admin/src/pluginId.js b/admin/src/pluginId.js new file mode 100644 index 0000000..695317c --- /dev/null +++ b/admin/src/pluginId.js @@ -0,0 +1,5 @@ +import pluginPkg from '../../package.json'; + +const pluginId = pluginPkg.name.replace(/^(@[^-,.][\w,-]+\/|strapi-)plugin-/i, ''); + +export default pluginId; diff --git a/admin/src/translations/en.json b/admin/src/translations/en.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/admin/src/translations/en.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/admin/src/translations/fr.json b/admin/src/translations/fr.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/admin/src/translations/fr.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/admin/src/utils/getTrad.js b/admin/src/utils/getTrad.js new file mode 100644 index 0000000..d0a071b --- /dev/null +++ b/admin/src/utils/getTrad.js @@ -0,0 +1,5 @@ +import pluginId from '../pluginId'; + +const getTrad = (id) => `${pluginId}.${id}`; + +export default getTrad; diff --git a/package.json b/package.json new file mode 100644 index 0000000..7ecfe66 --- /dev/null +++ b/package.json @@ -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" +} diff --git a/server/bootstrap.js b/server/bootstrap.js new file mode 100644 index 0000000..2aa48af --- /dev/null +++ b/server/bootstrap.js @@ -0,0 +1,5 @@ +'use strict'; + +module.exports = ({ strapi }) => { + // bootstrap phase +}; diff --git a/server/config/index.js b/server/config/index.js new file mode 100644 index 0000000..56b5ae6 --- /dev/null +++ b/server/config/index.js @@ -0,0 +1,6 @@ +'use strict'; + +module.exports = { + default: {}, + validator() {}, +}; diff --git a/server/content-types/index.js b/server/content-types/index.js new file mode 100644 index 0000000..8b46fbb --- /dev/null +++ b/server/content-types/index.js @@ -0,0 +1,3 @@ +'use strict'; + +module.exports = {}; diff --git a/server/controllers/index.js b/server/controllers/index.js new file mode 100644 index 0000000..c8c47b5 --- /dev/null +++ b/server/controllers/index.js @@ -0,0 +1,7 @@ +'use strict'; + +const myController = require('./my-controller'); + +module.exports = { + myController, +}; diff --git a/server/controllers/my-controller.js b/server/controllers/my-controller.js new file mode 100644 index 0000000..0757fc5 --- /dev/null +++ b/server/controllers/my-controller.js @@ -0,0 +1,10 @@ +'use strict'; + +module.exports = ({ strapi }) => ({ + index(ctx) { + ctx.body = strapi + .plugin('exchange') + .service('myService') + .getWelcomeMessage(); + }, +}); diff --git a/server/destroy.js b/server/destroy.js new file mode 100644 index 0000000..75f32f4 --- /dev/null +++ b/server/destroy.js @@ -0,0 +1,5 @@ +'use strict'; + +module.exports = ({ strapi }) => { + // destroy phase +}; diff --git a/server/index.js b/server/index.js new file mode 100644 index 0000000..5b524b1 --- /dev/null +++ b/server/index.js @@ -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, +}; diff --git a/server/middlewares/index.js b/server/middlewares/index.js new file mode 100644 index 0000000..8b46fbb --- /dev/null +++ b/server/middlewares/index.js @@ -0,0 +1,3 @@ +'use strict'; + +module.exports = {}; diff --git a/server/policies/index.js b/server/policies/index.js new file mode 100644 index 0000000..8b46fbb --- /dev/null +++ b/server/policies/index.js @@ -0,0 +1,3 @@ +'use strict'; + +module.exports = {}; diff --git a/server/register.js b/server/register.js new file mode 100644 index 0000000..437d48e --- /dev/null +++ b/server/register.js @@ -0,0 +1,5 @@ +'use strict'; + +module.exports = ({ strapi }) => { + // registeration phase +}; diff --git a/server/routes/index.js b/server/routes/index.js new file mode 100644 index 0000000..4158ea3 --- /dev/null +++ b/server/routes/index.js @@ -0,0 +1,10 @@ +module.exports = [ + { + method: 'GET', + path: '/', + handler: 'myController.index', + config: { + policies: [], + }, + }, +]; diff --git a/server/services/index.js b/server/services/index.js new file mode 100644 index 0000000..8d643e9 --- /dev/null +++ b/server/services/index.js @@ -0,0 +1,7 @@ +'use strict'; + +const myService = require('./my-service'); + +module.exports = { + myService, +}; diff --git a/server/services/my-service.js b/server/services/my-service.js new file mode 100644 index 0000000..f565002 --- /dev/null +++ b/server/services/my-service.js @@ -0,0 +1,7 @@ +'use strict'; + +module.exports = ({ strapi }) => ({ + getWelcomeMessage() { + return 'Welcome to Strapi 🚀'; + }, +}); diff --git a/strapi-admin.js b/strapi-admin.js new file mode 100644 index 0000000..2d1a3d9 --- /dev/null +++ b/strapi-admin.js @@ -0,0 +1,3 @@ +'use strict'; + +module.exports = require('./admin/src').default; diff --git a/strapi-server.js b/strapi-server.js new file mode 100644 index 0000000..8a908be --- /dev/null +++ b/strapi-server.js @@ -0,0 +1,3 @@ +'use strict'; + +module.exports = require('./server');