chore: remove old plugin generator in favor of plugin:init

This commit is contained in:
Alexandre Bodin 2024-03-21 15:52:10 +01:00
parent 1d0d1e6bc3
commit 5cee1a4b36
63 changed files with 0 additions and 1002 deletions

View File

@ -1,103 +0,0 @@
# From https://github.com/Danimoth/gitattributes/blob/master/Web.gitattributes
# Handle line endings automatically for files detected as text
# and leave all files detected as binary untouched.
* text=auto
#
# The above will handle all files NOT found below
#
#
## These files are text and should be normalized (Convert crlf => lf)
#
# source code
*.php text
*.css text
*.sass text
*.scss text
*.less text
*.styl text
*.js text eol=lf
*.coffee text
*.json text
*.htm text
*.html text
*.xml text
*.svg text
*.txt text
*.ini text
*.inc text
*.pl text
*.rb text
*.py text
*.scm text
*.sql text
*.sh text
*.bat text
# templates
*.ejs text
*.hbt text
*.jade text
*.haml text
*.hbs text
*.dot text
*.tmpl text
*.phtml text
# git config
.gitattributes text
.gitignore text
.gitconfig text
# code analysis config
.jshintrc text
.jscsrc text
.jshintignore text
.csslintrc text
# misc config
*.yaml text
*.yml text
.editorconfig text
# build config
*.npmignore text
*.bowerrc text
# Heroku
Procfile text
.slugignore text
# Documentation
*.md text
LICENSE text
AUTHORS text
#
## These files are binary and should be left untouched
#
# (binary is a macro for -text -diff)
*.png binary
*.jpg binary
*.jpeg binary
*.gif binary
*.ico binary
*.mov binary
*.mp4 binary
*.mp3 binary
*.flv binary
*.fla binary
*.swf binary
*.gz binary
*.zip binary
*.7z binary
*.ttf binary
*.eot binary
*.woff binary
*.pyc binary
*.pdf binary

View File

@ -1,10 +0,0 @@
# Don't check auto-generated stuff into git
coverage
node_modules
stats.json
package-lock.json
# Cruft
.DS_Store
npm-debug.log
.idea

View File

@ -1,26 +0,0 @@
/**
*
* 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;

View File

@ -1,12 +0,0 @@
/**
*
* PluginIcon
*
*/
import React from 'react';
import { Puzzle } from '@strapi/icons';
const PluginIcon = () => <Puzzle />;
export default PluginIcon;

View File

@ -1,61 +0,0 @@
import { prefixPluginTranslations } from './utils/prefixPluginTranslations';
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('./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(`./translations/${locale}.json`)
.then(({ default: data }) => {
return {
data: prefixPluginTranslations(data, pluginId),
locale,
};
})
.catch(() => {
return {
data: {},
locale,
};
});
})
);
return Promise.resolve(importedTrads);
},
};

View File

@ -1,25 +0,0 @@
/**
*
* 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 index element={<HomePage />} />
<Route path="*" element={<AnErrorOccurred />} />
</Switch>
</div>
);
};
export default App;

View File

@ -1,20 +0,0 @@
/*
*
* 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;

View File

@ -1,5 +0,0 @@
import pluginPkg from '../../package.json';
const pluginId = pluginPkg.name.replace(/^(@[^-,.][\w,-]+\/|strapi-)plugin-/i, '');
export default pluginId;

View File

@ -1,5 +0,0 @@
import pluginId from '../pluginId';
const getTrad = (id) => `${pluginId}.${id}`;
export default getTrad;

View File

@ -1,11 +0,0 @@
const prefixPluginTranslations = (trad, pluginId) => {
if (!pluginId) {
throw new TypeError("pluginId can't be empty");
}
return Object.keys(trad).reduce((acc, current) => {
acc[`${pluginId}.${current}`] = trad[current];
return acc;
}, {});
};
export { prefixPluginTranslations };

View File

@ -1,5 +0,0 @@
'use strict';
module.exports = ({ strapi }) => {
// bootstrap phase
};

View File

@ -1,6 +0,0 @@
'use strict';
module.exports = {
default: {},
validator() {},
};

View File

@ -1,3 +0,0 @@
'use strict';
module.exports = {};

View File

@ -1,7 +0,0 @@
'use strict';
const myController = require('./my-controller');
module.exports = {
myController,
};

View File

@ -1,10 +0,0 @@
'use strict';
module.exports = ({ strapi }) => ({
index(ctx) {
ctx.body = strapi
.plugin('{{ pluginName }}')
.service('myService')
.getWelcomeMessage();
},
});

View File

@ -1,5 +0,0 @@
'use strict';
module.exports = ({ strapi }) => {
// destroy phase
};

View File

@ -1,25 +0,0 @@
'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,
};

View File

@ -1,3 +0,0 @@
'use strict';
module.exports = {};

View File

@ -1,3 +0,0 @@
'use strict';
module.exports = {};

View File

@ -1,5 +0,0 @@
'use strict';
module.exports = ({ strapi }) => {
// register phase
};

View File

@ -1,10 +0,0 @@
module.exports = [
{
method: 'GET',
path: '/',
handler: 'myController.index',
config: {
policies: [],
},
},
];

View File

@ -1,7 +0,0 @@
'use strict';
const myService = require('./my-service');
module.exports = {
myService,
};

View File

@ -1,7 +0,0 @@
'use strict';
module.exports = ({ strapi }) => ({
getWelcomeMessage() {
return 'Welcome to Strapi 🚀';
},
});

View File

@ -1,3 +0,0 @@
'use strict';
module.exports = require('./admin/src').default;

View File

@ -1,3 +0,0 @@
'use strict';
module.exports = require('./server');

View File

@ -1,103 +0,0 @@
# From https://github.com/Danimoth/gitattributes/blob/master/Web.gitattributes
# Handle line endings automatically for files detected as text
# and leave all files detected as binary untouched.
* text=auto
#
# The above will handle all files NOT found below
#
#
## These files are text and should be normalized (Convert crlf => lf)
#
# source code
*.php text
*.css text
*.sass text
*.scss text
*.less text
*.styl text
*.js text eol=lf
*.coffee text
*.json text
*.htm text
*.html text
*.xml text
*.svg text
*.txt text
*.ini text
*.inc text
*.pl text
*.rb text
*.py text
*.scm text
*.sql text
*.sh text
*.bat text
# templates
*.ejs text
*.hbt text
*.jade text
*.haml text
*.hbs text
*.dot text
*.tmpl text
*.phtml text
# git config
.gitattributes text
.gitignore text
.gitconfig text
# code analysis config
.jshintrc text
.jscsrc text
.jshintignore text
.csslintrc text
# misc config
*.yaml text
*.yml text
.editorconfig text
# build config
*.npmignore text
*.bowerrc text
# Heroku
Procfile text
.slugignore text
# Documentation
*.md text
LICENSE text
AUTHORS text
#
## These files are binary and should be left untouched
#
# (binary is a macro for -text -diff)
*.png binary
*.jpg binary
*.jpeg binary
*.gif binary
*.ico binary
*.mov binary
*.mp4 binary
*.mp3 binary
*.flv binary
*.fla binary
*.swf binary
*.gz binary
*.zip binary
*.7z binary
*.ttf binary
*.eot binary
*.woff binary
*.pyc binary
*.pdf binary

View File

@ -1,10 +0,0 @@
# Don't check auto-generated stuff into git
coverage
node_modules
stats.json
package-lock.json
# Cruft
.DS_Store
npm-debug.log
.idea

View File

@ -1,24 +0,0 @@
/**
*
* Initializer
*
*/
import { useEffect, useRef } from 'react';
import pluginId from '../../pluginId';
type InitializerProps = {
setPlugin: (id: string) => void;
};
const Initializer = ({ setPlugin }: InitializerProps) => {
const ref = useRef(setPlugin);
useEffect(() => {
ref.current(pluginId);
}, []);
return null;
};
export default Initializer;

View File

@ -1,12 +0,0 @@
/**
*
* PluginIcon
*
*/
import React from 'react';
import { Puzzle } from '@strapi/icons';
const PluginIcon = () => <Puzzle />;
export default PluginIcon;

View File

@ -1,67 +0,0 @@
import { prefixPluginTranslations } from './utils/prefixPluginTranslations';
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: any) {
app.addMenuLink({
to: `plugins/${pluginId}`,
icon: PluginIcon,
intlLabel: {
id: `${pluginId}.plugin.name`,
defaultMessage: name,
},
Component: async () => {
const component = await import('./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,
// },
],
});
const plugin = {
id: pluginId,
initializer: Initializer,
isReady: false,
name,
};
app.registerPlugin(plugin);
},
bootstrap(app: any) {},
async registerTrads(app: any) {
const { locales } = app;
const importedTrads = await Promise.all(
(locales as any[]).map((locale) => {
return import(`./translations/${locale}.json`)
.then(({ default: data }) => {
return {
data: prefixPluginTranslations(data, pluginId),
locale,
};
})
.catch(() => {
return {
data: {},
locale,
};
});
})
);
return Promise.resolve(importedTrads);
},
};

View File

@ -1,25 +0,0 @@
/**
*
* 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 { Routes, Route } from 'react-router-dom';
import { AnErrorOccurred } from '@strapi/helper-plugin';
import pluginId from '../../pluginId';
import HomePage from '../HomePage';
const App = () => {
return (
<div>
<Routes>
<Route index element={<HomePage />} />
<Route path="*" element={<AnErrorOccurred />} />
</Routes>
</div>
);
};
export default App;

View File

@ -1,19 +0,0 @@
/*
*
* HomePage
*
*/
import React from 'react';
import pluginId from '../../pluginId';
const HomePage = () => {
return (
<div>
<h1>{pluginId}&apos;s HomePage</h1>
<p>Happy coding</p>
</div>
);
};
export default HomePage;

View File

@ -1,5 +0,0 @@
import pluginPkg from '../../package.json';
const pluginId = pluginPkg.name.replace(/^(@[^-,.][\w,-]+\/|strapi-)plugin-/i, '');
export default pluginId;

View File

@ -1,5 +0,0 @@
import pluginId from '../pluginId';
const getTrad = (id: string) => `${pluginId}.${id}`;
export default getTrad;

View File

@ -1,13 +0,0 @@
type TradOptions = Record<string, string>;
const prefixPluginTranslations = (trad: TradOptions, pluginId: string): TradOptions => {
if (!pluginId) {
throw new TypeError("pluginId can't be empty");
}
return Object.keys(trad).reduce((acc, current) => {
acc[`${pluginId}.${current}`] = trad[current];
return acc;
}, {} as TradOptions);
};
export { prefixPluginTranslations };

View File

@ -1,5 +0,0 @@
declare module '@strapi/design-system/*';
declare module '@strapi/design-system';
declare module '@strapi/icons';
declare module '@strapi/icons/*';
declare module '@strapi/helper-plugin';

View File

@ -1,5 +0,0 @@
// import type { Core } from '@strapi/strapi';
export default (/* { strapi }: { strapi: Core.Strapi } */) => {
// bootstrap phase
};

View File

@ -1,4 +0,0 @@
export default {
default: {},
validator() {},
};

View File

@ -1,5 +0,0 @@
import myController from './my-controller';
export default {
myController,
};

View File

@ -1,10 +0,0 @@
import type { Core } from '@strapi/strapi';
export default ({ strapi }: { strapi: Core.Strapi }) => ({
index(ctx) {
ctx.body = strapi
.plugin('{{ pluginName }}')
.service('myService')
.getWelcomeMessage();
},
});

View File

@ -1,5 +0,0 @@
// import type { Core } from '@strapi/strapi';
export default (/* { strapi }: { strapi: Core.Strapi } */) => {
// destroy phase
};

View File

@ -1,23 +0,0 @@
import register from './register';
import bootstrap from './bootstrap';
import destroy from './destroy';
import config from './config';
import contentTypes from './content-types';
import controllers from './controllers';
import routes from './routes';
import middlewares from './middlewares';
import policies from './policies';
import services from './services';
export default {
register,
bootstrap,
destroy,
config,
controllers,
routes,
services,
contentTypes,
policies,
middlewares,
};

View File

@ -1,5 +0,0 @@
// import type { Core } from '@strapi/strapi';
export default (/* { strapi }: { strapi: Core.Strapi } */) => {
// register phase
};

View File

@ -1,10 +0,0 @@
export default [
{
method: 'GET',
path: '/',
handler: 'myController.index',
config: {
policies: [],
},
},
];

View File

@ -1,5 +0,0 @@
import myService from './my-service';
export default {
myService,
};

View File

@ -1,7 +0,0 @@
// import type { Core } from '@strapi/strapi';
export default (/* { strapi }: { strapi: Core.Strapi } */) => ({
getWelcomeMessage() {
return 'Welcome to Strapi 🚀';
},
});

View File

@ -1,3 +0,0 @@
'use strict';
module.exports = require('./admin/src').default;

View File

@ -1,3 +0,0 @@
'use strict';
module.exports = require('./dist/server');

View File

@ -1,20 +0,0 @@
{
"extends": "@strapi/typescript-utils/tsconfigs/admin",
"compilerOptions": {
"target": "ESNext",
"strict": true
},
"include": ["admin", "custom.d.ts"],
"exclude": [
"node_modules/",
"dist/",
// Do not include server files in the server compilation
"server/",
// Do not include test files
"**/*.test.ts"
]
}

View File

@ -1,25 +0,0 @@
{
"extends": "@strapi/typescript-utils/tsconfigs/server",
"compilerOptions": {
"outDir": "dist",
"rootDir": "."
},
"include": [
// Include the root directory
"server",
// Force the JSON files in the src folder to be included
"server/**/*.json"
],
"exclude": [
"node_modules/",
"dist/",
// Do not include admin files in the server compilation
"admin/",
// Do not include test files
"**/*.test.ts"
]
}

View File

@ -4,7 +4,6 @@ import { NodePlopAPI } from 'plop';
import generateApi from './plops/api';
import generateController from './plops/controller';
import generateContentType from './plops/content-type';
import generatePlugin from './plops/plugin';
import generatePolicy from './plops/policy';
import generateMiddleware from './plops/middleware';
import generateMigration from './plops/migration';
@ -19,7 +18,6 @@ export default (plop: NodePlopAPI) => {
generateApi(plop);
generateController(plop);
generateContentType(plop);
generatePlugin(plop);
generatePolicy(plop);
generateMiddleware(plop);
generateMigration(plop);

View File

@ -1,98 +0,0 @@
import { NodePlopAPI } from 'plop';
import chalk from 'chalk';
import tsUtils from '@strapi/typescript-utils';
import { strings } from '@strapi/utils';
import validateInput from './utils/validate-input';
const LANGUAGES = {
javascript: 'JavaScript',
typescript: 'TypeScript',
};
const logInstructions = (pluginName: string, { language }: { language: string }) => {
const maxLength = ` resolve: './src/plugins/${pluginName}'`.length;
const separator = Array(maxLength).fill('─').join('');
const exportInstruction = language === 'js' ? 'module.exports =' : 'export default';
return `
You can now enable your plugin by adding the following in ${chalk.yellow(
`./config/plugins.${language}`
)}
${separator}
${exportInstruction} {
${chalk.gray('// ...')}
${chalk.green(`'${pluginName}'`)}: {
enabled: ${chalk.yellow(true)},
resolve: ${chalk.yellow(`'./src/plugins/${pluginName}'`)}
},
${chalk.gray('// ...')}
}
${separator}
`;
};
export default (plop: NodePlopAPI) => {
// Plugin generator
plop.setGenerator('plugin', {
description: 'Generate a basic plugin',
prompts: [
{
type: 'input',
name: 'pluginName',
message: 'Plugin name',
validate: (input) => validateInput(input),
},
{
type: 'list',
name: 'language',
message: 'Choose your preferred language',
choices: Object.values(LANGUAGES),
default: LANGUAGES.javascript,
},
],
actions(answers) {
if (!answers) {
return [];
}
const isTypescript = answers.language === LANGUAGES.typescript;
const language = isTypescript ? 'ts' : 'js';
const projectLanguage = tsUtils.isUsingTypeScriptSync(process.cwd()) ? 'ts' : 'js';
if (!strings.isKebabCase(answers.pluginName)) {
answers.pluginName = strings.toKebabCase(answers.pluginName);
console.log(
chalk.yellow(
`Strapi only supports kebab-cased names for plugins.\nYour plugin has been automatically renamed to "${answers.pluginName}".`
)
);
}
return [
{
type: 'addMany',
destination: 'plugins/{{ pluginName }}',
base: `files/${language}/plugin`,
templateFiles: `files/${language}/plugin/**`,
},
{
type: 'add',
path: 'plugins/{{ pluginName }}/README.md',
templateFile: `templates/${language}/README.md.hbs`,
},
{
type: 'add',
path: 'plugins/{{ pluginName }}/package.json',
templateFile: `templates/${language}/plugin-package.json.hbs`,
},
() =>
plop.renderString(
logInstructions(answers.pluginName, { language: projectLanguage }),
null
),
];
},
});
};

View File

@ -1,3 +0,0 @@
# Strapi plugin {{ pluginName }}
A quick description of {{ pluginName }}.

View File

@ -1,42 +0,0 @@
{
"name": "{{ pluginName }}",
"version": "0.0.0",
"description": "This is the description of the plugin.",
"strapi": {
"name": "{{ pluginName }}",
"description": "Description of {{titleCase pluginName }} plugin",
"kind": "plugin",
"displayName": "{{titleCase pluginName }}"
},
"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": "^6.0.0",
"styled-components": "^5.3.6"
},
"peerDependencies": {
"react": "^17.0.0 || ^18.0.0",
"react-dom": "^17.0.0 || ^18.0.0",
"react-router-dom": "^6.0.0",
"styled-components": "^5.2.1"
},
"author": {
"name": "A Strapi developer"
},
"maintainers": [
{
"name": "A Strapi developer"
}
],
"engines": {
"node": ">=18.0.0 <=20.x.x",
"npm": ">=6.0.0"
},
"license": "MIT"
}

View File

@ -1,3 +0,0 @@
# Strapi plugin {{ pluginName }}
A quick description of {{ pluginName }}.

View File

@ -1,49 +0,0 @@
{
"name": "{{ pluginName }}",
"version": "0.0.0",
"description": "This is the description of the plugin.",
"strapi": {
"name": "{{ pluginName }}",
"description": "Description of {{ pluginName }} plugin",
"kind": "plugin"
},
"dependencies": {
"@strapi/design-system": "^1.6.3",
"@strapi/helper-plugin": "^4.6.0",
"@strapi/icons": "^1.6.3",
},
"devDependencies": {
"@strapi/typescript-utils": "^4.6.0",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@types/styled-components": "^5.1.26",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-router-dom": "^6.0.0",
"styled-components": "^5.3.6",
"typescript": "5.0.4"
},
"peerDependencies": {
"react": "^17.0.0 || ^18.0.0",
"react-dom": "^17.0.0 || ^18.0.0",
"react-router-dom": "^6.0.0",
"styled-components": "^5.2.1"
},
"author": {
"name": "A Strapi developer"
},
"maintainers": [
{
"name": "A Strapi developer"
}
],
"engines": {
"node": ">=18.0.0 <=20.x.x",
"npm": ">=6.0.0"
},
"scripts": {
"develop": "tsc -p tsconfig.server.json -w",
"build": "tsc -p tsconfig.server.json"
},
"license": "MIT"
}