@strapi/generators 4.2.1-alpha.0 → 4.3.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/files/{plugin → js/plugin}/admin/src/components/Initializer/index.js +0 -0
- package/lib/files/{plugin → js/plugin}/admin/src/components/PluginIcon/index.js +0 -0
- package/lib/files/{plugin → js/plugin}/admin/src/index.js +0 -0
- package/lib/files/{plugin → js/plugin}/admin/src/pages/App/index.js +0 -0
- package/lib/files/{plugin → js/plugin}/admin/src/pages/HomePage/index.js +2 -2
- package/lib/files/{plugin → js/plugin}/admin/src/pluginId.js +2 -2
- package/lib/files/{plugin → js/plugin}/admin/src/translations/en.json +0 -0
- package/lib/files/{plugin → js/plugin}/admin/src/translations/fr.json +0 -0
- package/lib/files/{plugin → js/plugin}/admin/src/utils/axiosInstance.js +0 -0
- package/lib/files/{plugin → js/plugin}/admin/src/utils/getTrad.js +0 -0
- package/lib/files/{plugin → js/plugin}/server/bootstrap.js +0 -0
- package/lib/files/{plugin → js/plugin}/server/config/index.js +0 -0
- package/lib/files/{plugin → js/plugin}/server/content-types/index.js +0 -0
- package/lib/files/{plugin → js/plugin}/server/controllers/index.js +0 -0
- package/lib/files/{plugin → js/plugin}/server/controllers/my-controller.js.hbs +2 -2
- package/lib/files/{plugin → js/plugin}/server/destroy.js +0 -0
- package/lib/files/{plugin → js/plugin}/server/index.js +0 -0
- package/lib/files/{plugin → js/plugin}/server/middlewares/index.js +0 -0
- package/lib/files/{plugin → js/plugin}/server/policies/index.js +0 -0
- package/lib/files/{plugin → js/plugin}/server/register.js +0 -0
- package/lib/files/{plugin → js/plugin}/server/routes/index.js +0 -0
- package/lib/files/{plugin → js/plugin}/server/services/index.js +0 -0
- package/lib/files/{plugin → js/plugin}/server/services/my-service.js +0 -0
- package/lib/files/{plugin → js/plugin}/strapi-admin.js +0 -0
- package/lib/files/{plugin → js/plugin}/strapi-server.js +0 -0
- package/lib/files/ts/plugin/admin/src/components/Initializer/index.tsx +25 -0
- package/lib/files/ts/plugin/admin/src/components/PluginIcon/index.tsx +12 -0
- package/lib/files/ts/plugin/admin/src/index.tsx +66 -0
- package/lib/files/ts/plugin/admin/src/pages/App/index.tsx +25 -0
- package/lib/files/ts/plugin/admin/src/pages/HomePage/index.tsx +19 -0
- package/lib/files/ts/plugin/admin/src/pluginId.ts +5 -0
- package/lib/files/ts/plugin/admin/src/translations/en.json +1 -0
- package/lib/files/ts/plugin/admin/src/translations/fr.json +1 -0
- package/lib/files/ts/plugin/admin/src/utils/axiosInstance.ts +40 -0
- package/lib/files/ts/plugin/admin/src/utils/getTrad.ts +5 -0
- package/lib/files/ts/plugin/server/bootstrap.ts +5 -0
- package/lib/files/ts/plugin/server/config/index.ts +4 -0
- package/lib/files/ts/plugin/server/content-types/index.ts +1 -0
- package/lib/files/ts/plugin/server/controllers/index.ts +5 -0
- package/lib/files/ts/plugin/server/controllers/my-controller.ts.hbs +10 -0
- package/lib/files/ts/plugin/server/destroy.ts +5 -0
- package/lib/files/ts/plugin/server/index.ts +23 -0
- package/lib/files/ts/plugin/server/middlewares/index.ts +1 -0
- package/lib/files/ts/plugin/server/policies/index.ts +1 -0
- package/lib/files/ts/plugin/server/register.ts +5 -0
- package/lib/files/ts/plugin/server/routes/index.ts +10 -0
- package/lib/files/ts/plugin/server/services/index.ts +5 -0
- package/lib/files/ts/plugin/server/services/my-service.ts +7 -0
- package/lib/files/ts/plugin/strapi-admin.js +3 -0
- package/lib/files/ts/plugin/strapi-server.js +3 -0
- package/lib/files/ts/plugin/tsconfig.json +25 -0
- package/lib/plops/api.js +10 -6
- package/lib/plops/content-type.js +10 -7
- package/lib/plops/controller.js +6 -2
- package/lib/plops/middleware.js +7 -2
- package/lib/plops/plugin.js +30 -8
- package/lib/plops/policy.js +6 -2
- package/lib/plops/service.js +6 -2
- package/lib/plops/utils/__tests__/get-file-path.test.js +5 -5
- package/lib/templates/{README.md.hbs → js/README.md.hbs} +0 -0
- package/lib/templates/{collection-type-routes.js.hbs → js/collection-type-routes.js.hbs} +0 -0
- package/lib/templates/{content-type.schema.json.hbs → js/content-type.schema.json.hbs} +0 -0
- package/lib/templates/{controller.js.hbs → js/controller.js.hbs} +0 -0
- package/lib/templates/{core-controller.js.hbs → js/core-controller.js.hbs} +0 -0
- package/lib/templates/{core-router.js.hbs → js/core-router.js.hbs} +0 -0
- package/lib/templates/{core-service.js.hbs → js/core-service.js.hbs} +0 -0
- package/lib/templates/{middleware.js.hbs → js/middleware.js.hbs} +0 -0
- package/lib/templates/{plugin-package.json.hbs → js/plugin-package.json.hbs} +0 -0
- package/lib/templates/{policy.js.hbs → js/policy.js.hbs} +0 -0
- package/lib/templates/{service.js.hbs → js/service.js.hbs} +0 -0
- package/lib/templates/{single-route.js.hbs → js/single-route.js.hbs} +0 -0
- package/lib/templates/{single-type-routes.js.hbs → js/single-type-routes.js.hbs} +2 -0
- package/lib/templates/ts/README.md.hbs +3 -0
- package/lib/templates/ts/collection-type-routes.ts.hbs +49 -0
- package/lib/templates/ts/content-type.schema.json.hbs +15 -0
- package/lib/templates/ts/controller.ts.hbs +13 -0
- package/lib/templates/ts/core-controller.ts.hbs +7 -0
- package/lib/templates/ts/core-router.ts.hbs +7 -0
- package/lib/templates/ts/core-service.ts.hbs +7 -0
- package/lib/templates/ts/middleware.js.hbs +14 -0
- package/lib/templates/ts/plugin-package.json.hbs +32 -0
- package/lib/templates/ts/policy.ts.hbs +16 -0
- package/lib/templates/ts/service.ts.hbs +5 -0
- package/lib/templates/ts/single-route.ts.hbs +13 -0
- package/lib/templates/ts/single-type-routes.ts.hbs +31 -0
- package/package.json +4 -3
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import React
|
|
7
|
+
import React from 'react';
|
|
8
8
|
// import PropTypes from 'prop-types';
|
|
9
9
|
import pluginId from '../../pluginId';
|
|
10
10
|
|
|
@@ -17,4 +17,4 @@ const HomePage = () => {
|
|
|
17
17
|
);
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
export default
|
|
20
|
+
export default HomePage;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Initializer
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import React, { useEffect, useRef } from 'react';
|
|
8
|
+
import pluginId from '../../pluginId';
|
|
9
|
+
|
|
10
|
+
type InitializerProps = {
|
|
11
|
+
setPlugin: (id: string) => void;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const Initializer: React.FC<InitializerProps> = ({ setPlugin }) => {
|
|
15
|
+
const ref = useRef<(id: string) => void | null>(null);
|
|
16
|
+
ref.current = setPlugin;
|
|
17
|
+
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
ref.current(pluginId);
|
|
20
|
+
}, []);
|
|
21
|
+
|
|
22
|
+
return null;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default Initializer;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { prefixPluginTranslations } from '@strapi/helper-plugin';
|
|
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) {
|
|
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) {},
|
|
43
|
+
async registerTrads(app) {
|
|
44
|
+
const { locales } = app;
|
|
45
|
+
|
|
46
|
+
const importedTrads = await Promise.all(
|
|
47
|
+
locales.map(locale => {
|
|
48
|
+
return import(`./translations/${locale}.json`)
|
|
49
|
+
.then(({ default: data }) => {
|
|
50
|
+
return {
|
|
51
|
+
data: prefixPluginTranslations(data, pluginId),
|
|
52
|
+
locale,
|
|
53
|
+
};
|
|
54
|
+
})
|
|
55
|
+
.catch(() => {
|
|
56
|
+
return {
|
|
57
|
+
data: {},
|
|
58
|
+
locale,
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
})
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
return Promise.resolve(importedTrads);
|
|
65
|
+
},
|
|
66
|
+
};
|
|
@@ -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 { NotFound } from '@strapi/helper-plugin';
|
|
11
|
+
import pluginId from '../../pluginId';
|
|
12
|
+
import HomePage from '../HomePage';
|
|
13
|
+
|
|
14
|
+
const App: React.VoidFunctionComponent = () => {
|
|
15
|
+
return (
|
|
16
|
+
<div>
|
|
17
|
+
<Switch>
|
|
18
|
+
<Route path={`/plugins/${pluginId}`} component={HomePage} exact />
|
|
19
|
+
<Route component={NotFound} />
|
|
20
|
+
</Switch>
|
|
21
|
+
</div>
|
|
22
|
+
);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default App;
|
|
@@ -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: React.VoidFunctionComponent = () => {
|
|
11
|
+
return (
|
|
12
|
+
<div>
|
|
13
|
+
<h1>{pluginId}'s HomePage</h1>
|
|
14
|
+
<p>Happy coding</p>
|
|
15
|
+
</div>
|
|
16
|
+
);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default HomePage;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* axios with a custom config.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import axios from 'axios';
|
|
6
|
+
import { auth } from '@strapi/helper-plugin';
|
|
7
|
+
|
|
8
|
+
const instance = axios.create({
|
|
9
|
+
baseURL: process.env.STRAPI_ADMIN_BACKEND_URL,
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
instance.interceptors.request.use(
|
|
13
|
+
async (config) => {
|
|
14
|
+
config.headers = {
|
|
15
|
+
Authorization: `Bearer ${auth.getToken()}`,
|
|
16
|
+
Accept: 'application/json',
|
|
17
|
+
'Content-Type': 'application/json',
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
return config;
|
|
21
|
+
},
|
|
22
|
+
(error) => {
|
|
23
|
+
Promise.reject(error);
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
instance.interceptors.response.use(
|
|
28
|
+
(response) => response,
|
|
29
|
+
(error) => {
|
|
30
|
+
// whatever you want to do with the error
|
|
31
|
+
if (error.response?.status === 401) {
|
|
32
|
+
auth.clearAppStorage();
|
|
33
|
+
window.location.reload();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
export default instance;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default {};
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default {};
|
|
@@ -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
|
+
}
|
package/lib/plops/api.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
const { join } = require('path');
|
|
4
4
|
const fs = require('fs-extra');
|
|
5
|
+
const tsUtils = require('@strapi/typescript-utils');
|
|
6
|
+
|
|
5
7
|
const validateInput = require('./utils/validate-input');
|
|
6
8
|
|
|
7
9
|
module.exports = plop => {
|
|
@@ -46,17 +48,19 @@ module.exports = plop => {
|
|
|
46
48
|
],
|
|
47
49
|
actions(answers) {
|
|
48
50
|
const filePath = answers.isPluginApi && answers.plugin ? 'plugins/{{plugin}}' : 'api/{{id}}';
|
|
51
|
+
const currentDir = process.cwd();
|
|
52
|
+
const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
49
53
|
|
|
50
54
|
const baseActions = [
|
|
51
55
|
{
|
|
52
56
|
type: 'add',
|
|
53
|
-
path: `${filePath}/controllers/{{id}}
|
|
54
|
-
templateFile:
|
|
57
|
+
path: `${filePath}/controllers/{{id}}.${language}`,
|
|
58
|
+
templateFile: `templates/${language}/controller.${language}.hbs`,
|
|
55
59
|
},
|
|
56
60
|
{
|
|
57
61
|
type: 'add',
|
|
58
|
-
path: `${filePath}/services/{{id}}
|
|
59
|
-
templateFile:
|
|
62
|
+
path: `${filePath}/services/{{id}}.${language}`,
|
|
63
|
+
templateFile: `templates/${language}/service.${language}.hbs`,
|
|
60
64
|
},
|
|
61
65
|
];
|
|
62
66
|
|
|
@@ -67,8 +71,8 @@ module.exports = plop => {
|
|
|
67
71
|
return [
|
|
68
72
|
{
|
|
69
73
|
type: 'add',
|
|
70
|
-
path: `${filePath}/routes/{{id}}
|
|
71
|
-
templateFile: `templates/single-route.
|
|
74
|
+
path: `${filePath}/routes/{{id}}.${language}`,
|
|
75
|
+
templateFile: `templates/${language}/single-route.${language}.hbs`,
|
|
72
76
|
},
|
|
73
77
|
...baseActions,
|
|
74
78
|
];
|
|
@@ -4,6 +4,7 @@ const { join } = require('path');
|
|
|
4
4
|
const slugify = require('@sindresorhus/slugify');
|
|
5
5
|
const fs = require('fs-extra');
|
|
6
6
|
const { isKebabCase } = require('@strapi/utils');
|
|
7
|
+
const tsUtils = require('@strapi/typescript-utils');
|
|
7
8
|
|
|
8
9
|
const getDestinationPrompts = require('./prompts/get-destination-prompts');
|
|
9
10
|
const getFilePath = require('./utils/get-file-path');
|
|
@@ -81,12 +82,14 @@ module.exports = plop => {
|
|
|
81
82
|
}, {});
|
|
82
83
|
|
|
83
84
|
const filePath = getFilePath(answers.destination);
|
|
85
|
+
const currentDir = process.cwd();
|
|
86
|
+
const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
84
87
|
|
|
85
88
|
const baseActions = [
|
|
86
89
|
{
|
|
87
90
|
type: 'add',
|
|
88
91
|
path: `${filePath}/content-types/{{ singularName }}/schema.json`,
|
|
89
|
-
templateFile:
|
|
92
|
+
templateFile: `templates/${language}/content-type.schema.json.hbs`,
|
|
90
93
|
data: {
|
|
91
94
|
collectionName: slugify(answers.pluralName, { separator: '_' }),
|
|
92
95
|
},
|
|
@@ -120,20 +123,20 @@ module.exports = plop => {
|
|
|
120
123
|
baseActions.push(
|
|
121
124
|
{
|
|
122
125
|
type: 'add',
|
|
123
|
-
path: `${filePath}/controllers/{{singularName}}
|
|
124
|
-
templateFile:
|
|
126
|
+
path: `${filePath}/controllers/{{singularName}}.${language}`,
|
|
127
|
+
templateFile: `templates/${language}/core-controller.${language}.hbs`,
|
|
125
128
|
data: { uid },
|
|
126
129
|
},
|
|
127
130
|
{
|
|
128
131
|
type: 'add',
|
|
129
|
-
path: `${filePath}/services/{{singularName}}
|
|
130
|
-
templateFile:
|
|
132
|
+
path: `${filePath}/services/{{singularName}}.${language}`,
|
|
133
|
+
templateFile: `templates/${language}/core-service.${language}.hbs`,
|
|
131
134
|
data: { uid },
|
|
132
135
|
},
|
|
133
136
|
{
|
|
134
137
|
type: 'add',
|
|
135
|
-
path: `${filePath}/routes/{{singularName}}
|
|
136
|
-
templateFile: `templates/core-router.
|
|
138
|
+
path: `${filePath}/routes/{{singularName}}.${language}`,
|
|
139
|
+
templateFile: `templates/${language}/core-router.${language}.hbs`,
|
|
137
140
|
data: { uid },
|
|
138
141
|
}
|
|
139
142
|
);
|
package/lib/plops/controller.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const tsUtils = require('@strapi/typescript-utils');
|
|
4
|
+
|
|
3
5
|
const getDestinationPrompts = require('./prompts/get-destination-prompts');
|
|
4
6
|
const getFilePath = require('./utils/get-file-path');
|
|
5
7
|
const validateInput = require('./utils/validate-input');
|
|
@@ -19,12 +21,14 @@ module.exports = plop => {
|
|
|
19
21
|
],
|
|
20
22
|
actions(answers) {
|
|
21
23
|
const filePath = getFilePath(answers.destination);
|
|
24
|
+
const currentDir = process.cwd();
|
|
25
|
+
const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
22
26
|
|
|
23
27
|
return [
|
|
24
28
|
{
|
|
25
29
|
type: 'add',
|
|
26
|
-
path: `${filePath}/controllers/{{ id }}
|
|
27
|
-
templateFile:
|
|
30
|
+
path: `${filePath}/controllers/{{ id }}.${language}`,
|
|
31
|
+
templateFile: `templates/${language}/controller.${language}.hbs`,
|
|
28
32
|
},
|
|
29
33
|
];
|
|
30
34
|
},
|
package/lib/plops/middleware.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const tsUtils = require('@strapi/typescript-utils');
|
|
4
|
+
|
|
3
5
|
const getDestinationPrompts = require('./prompts/get-destination-prompts');
|
|
4
6
|
const validateInput = require('./utils/validate-input');
|
|
5
7
|
const getFilePath = require('./utils/get-file-path');
|
|
@@ -19,11 +21,14 @@ module.exports = plop => {
|
|
|
19
21
|
],
|
|
20
22
|
actions(answers) {
|
|
21
23
|
const filePath = getFilePath(answers.destination);
|
|
24
|
+
const currentDir = process.cwd();
|
|
25
|
+
const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
26
|
+
|
|
22
27
|
return [
|
|
23
28
|
{
|
|
24
29
|
type: 'add',
|
|
25
|
-
path: `${filePath}/middlewares/{{ name }}
|
|
26
|
-
templateFile:
|
|
30
|
+
path: `${filePath}/middlewares/{{ name }}.${language}`,
|
|
31
|
+
templateFile: `templates/${language}/middleware.${language}.hbs`,
|
|
27
32
|
},
|
|
28
33
|
];
|
|
29
34
|
},
|
package/lib/plops/plugin.js
CHANGED
|
@@ -1,19 +1,30 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const chalk = require('chalk');
|
|
4
|
+
const { isUsingTypeScriptSync } = require('@strapi/typescript-utils');
|
|
4
5
|
const { isKebabCase, toKebabCase } = require('@strapi/utils');
|
|
6
|
+
|
|
5
7
|
const validateInput = require('./utils/validate-input');
|
|
6
8
|
|
|
7
|
-
const
|
|
9
|
+
const LANGUAGES = {
|
|
10
|
+
javascript: 'JavaScript',
|
|
11
|
+
typescript: 'TypeScript',
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const logInstructions = (pluginName, { language }) => {
|
|
8
15
|
const maxLength = ` resolve: './src/plugins/${pluginName}'`.length;
|
|
9
16
|
const separator = Array(maxLength)
|
|
10
17
|
.fill('─')
|
|
11
18
|
.join('');
|
|
12
19
|
|
|
20
|
+
const exportInstruction = language === 'js' ? 'module.exports =' : 'export default';
|
|
21
|
+
|
|
13
22
|
return `
|
|
14
|
-
You can now enable your plugin by adding the following in ${chalk.yellow(
|
|
23
|
+
You can now enable your plugin by adding the following in ${chalk.yellow(
|
|
24
|
+
`./config/plugins.${language}`
|
|
25
|
+
)}
|
|
15
26
|
${separator}
|
|
16
|
-
|
|
27
|
+
${exportInstruction} {
|
|
17
28
|
${chalk.gray('// ...')}
|
|
18
29
|
${chalk.green(`'${pluginName}'`)}: {
|
|
19
30
|
enabled: ${chalk.yellow(true)},
|
|
@@ -36,8 +47,19 @@ module.exports = plop => {
|
|
|
36
47
|
message: 'Plugin name',
|
|
37
48
|
validate: input => validateInput(input),
|
|
38
49
|
},
|
|
50
|
+
{
|
|
51
|
+
type: 'list',
|
|
52
|
+
name: 'language',
|
|
53
|
+
message: 'Choose your preferred language',
|
|
54
|
+
choices: Object.values(LANGUAGES),
|
|
55
|
+
default: LANGUAGES.javascript,
|
|
56
|
+
},
|
|
39
57
|
],
|
|
40
58
|
actions(answers) {
|
|
59
|
+
const isTypescript = answers.language === LANGUAGES.typescript;
|
|
60
|
+
const language = isTypescript ? 'ts' : 'js';
|
|
61
|
+
const projectLanguage = isUsingTypeScriptSync(process.cwd()) ? 'ts' : 'js';
|
|
62
|
+
|
|
41
63
|
if (!isKebabCase(answers.pluginName)) {
|
|
42
64
|
answers.pluginName = toKebabCase(answers.pluginName);
|
|
43
65
|
console.log(
|
|
@@ -51,20 +73,20 @@ module.exports = plop => {
|
|
|
51
73
|
{
|
|
52
74
|
type: 'addMany',
|
|
53
75
|
destination: 'plugins/{{ pluginName }}',
|
|
54
|
-
base:
|
|
55
|
-
templateFiles:
|
|
76
|
+
base: `files/${language}/plugin`,
|
|
77
|
+
templateFiles: `files/${language}/plugin/**`,
|
|
56
78
|
},
|
|
57
79
|
{
|
|
58
80
|
type: 'add',
|
|
59
81
|
path: 'plugins/{{ pluginName }}/README.md',
|
|
60
|
-
templateFile:
|
|
82
|
+
templateFile: `templates/${language}/README.md.hbs`,
|
|
61
83
|
},
|
|
62
84
|
{
|
|
63
85
|
type: 'add',
|
|
64
86
|
path: 'plugins/{{ pluginName }}/package.json',
|
|
65
|
-
templateFile:
|
|
87
|
+
templateFile: `templates/${language}/plugin-package.json.hbs`,
|
|
66
88
|
},
|
|
67
|
-
() => plop.renderString(logInstructions(answers.pluginName)),
|
|
89
|
+
() => plop.renderString(logInstructions(answers.pluginName, { language: projectLanguage })),
|
|
68
90
|
];
|
|
69
91
|
},
|
|
70
92
|
});
|
package/lib/plops/policy.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const tsUtils = require('@strapi/typescript-utils');
|
|
4
|
+
|
|
3
5
|
const getDestinationPrompts = require('./prompts/get-destination-prompts');
|
|
4
6
|
const validateInput = require('./utils/validate-input');
|
|
5
7
|
const getFilePath = require('./utils/get-file-path');
|
|
@@ -19,12 +21,14 @@ module.exports = plop => {
|
|
|
19
21
|
],
|
|
20
22
|
actions(answers) {
|
|
21
23
|
const filePath = getFilePath(answers.destination);
|
|
24
|
+
const currentDir = process.cwd();
|
|
25
|
+
const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
22
26
|
|
|
23
27
|
return [
|
|
24
28
|
{
|
|
25
29
|
type: 'add',
|
|
26
|
-
path: `${filePath}/policies/{{id}}
|
|
27
|
-
templateFile:
|
|
30
|
+
path: `${filePath}/policies/{{id}}.${language}`,
|
|
31
|
+
templateFile: `templates/${language}/policy.${language}.hbs`,
|
|
28
32
|
},
|
|
29
33
|
];
|
|
30
34
|
},
|
package/lib/plops/service.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const tsUtils = require('@strapi/typescript-utils');
|
|
4
|
+
|
|
3
5
|
const getDestinationPrompts = require('./prompts/get-destination-prompts');
|
|
4
6
|
const getFilePath = require('./utils/get-file-path');
|
|
5
7
|
|
|
@@ -17,12 +19,14 @@ module.exports = plop => {
|
|
|
17
19
|
],
|
|
18
20
|
actions(answers) {
|
|
19
21
|
const filePath = getFilePath(answers.destination);
|
|
22
|
+
const currentDir = process.cwd();
|
|
23
|
+
const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
20
24
|
|
|
21
25
|
return [
|
|
22
26
|
{
|
|
23
27
|
type: 'add',
|
|
24
|
-
path: `${filePath}/services/{{ id }}
|
|
25
|
-
templateFile:
|
|
28
|
+
path: `${filePath}/services/{{ id }}.${language}`,
|
|
29
|
+
templateFile: `templates/${language}/service.${language}.hbs`,
|
|
26
30
|
},
|
|
27
31
|
];
|
|
28
32
|
},
|
|
@@ -6,20 +6,20 @@ describe('Get-File-Path util', () => {
|
|
|
6
6
|
test('with destination set as api', () => {
|
|
7
7
|
const filePath = getFilePath('api');
|
|
8
8
|
expect(filePath).toBe(`api/{{ api }}`);
|
|
9
|
-
})
|
|
9
|
+
});
|
|
10
10
|
|
|
11
11
|
test('with destination set as plugin', () => {
|
|
12
12
|
const filePath = getFilePath('plugin');
|
|
13
13
|
expect(filePath).toBe(`plugins/{{ plugin }}/server`);
|
|
14
|
-
})
|
|
14
|
+
});
|
|
15
15
|
|
|
16
16
|
test('with destination set as root', () => {
|
|
17
17
|
const filePath = getFilePath('root');
|
|
18
18
|
expect(filePath).toBe(`./`);
|
|
19
|
-
})
|
|
19
|
+
});
|
|
20
20
|
|
|
21
21
|
test('with empty destination string', () => {
|
|
22
22
|
const filePath = getFilePath('');
|
|
23
23
|
expect(filePath).toBe(`api/{{ id }}`);
|
|
24
|
-
})
|
|
25
|
-
})
|
|
24
|
+
});
|
|
25
|
+
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
routes: [
|
|
3
|
+
{
|
|
4
|
+
method: 'GET',
|
|
5
|
+
path: '/{{pluralize id}}',
|
|
6
|
+
handler: '{{id}}.find',
|
|
7
|
+
config: {
|
|
8
|
+
policies: [],
|
|
9
|
+
middlewares: [],
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
method: 'GET',
|
|
14
|
+
path: '/{{pluralize id}}/:id',
|
|
15
|
+
handler: '{{id}}.findOne',
|
|
16
|
+
config: {
|
|
17
|
+
policies: [],
|
|
18
|
+
middlewares: [],
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
method: 'POST',
|
|
23
|
+
path: '/{{pluralize id}}',
|
|
24
|
+
handler: '{{id}}.create',
|
|
25
|
+
config: {
|
|
26
|
+
policies: [],
|
|
27
|
+
middlewares: [],
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
method: 'PUT',
|
|
32
|
+
path: '/{{pluralize id}}/:id',
|
|
33
|
+
handler: '{{id}}.update',
|
|
34
|
+
config: {
|
|
35
|
+
policies: [],
|
|
36
|
+
middlewares: [],
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
method: 'DELETE',
|
|
41
|
+
path: '/{{pluralize id}}/:id',
|
|
42
|
+
handler: '{{id}}.delete',
|
|
43
|
+
config: {
|
|
44
|
+
policies: [],
|
|
45
|
+
middlewares: [],
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
|
|
2
|
+
{
|
|
3
|
+
"kind": "{{kind}}",
|
|
4
|
+
"collectionName": "{{ collectionName }}",
|
|
5
|
+
"info": {
|
|
6
|
+
"singularName": "{{ singularName }}",
|
|
7
|
+
"pluralName": "{{ pluralName }}",
|
|
8
|
+
"displayName": "{{ displayName }}"
|
|
9
|
+
},
|
|
10
|
+
"options": {
|
|
11
|
+
"draftAndPublish": {{ useDraftAndPublish }},
|
|
12
|
+
"comment": ""
|
|
13
|
+
},
|
|
14
|
+
"attributes": {}
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `{{ name }}` middleware.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import '@strapi/strapi';
|
|
6
|
+
|
|
7
|
+
export default (config, { strapi }: { strapi: Strapi }) => {
|
|
8
|
+
// Add your own logic here.
|
|
9
|
+
return async (ctx, next) => {
|
|
10
|
+
strapi.log.info('In {{ name }} middleware.');
|
|
11
|
+
|
|
12
|
+
await next();
|
|
13
|
+
};
|
|
14
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{ pluginName }}",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "This is the description of the plugin.",
|
|
5
|
+
"strapi": {
|
|
6
|
+
"name": "{{ pluginName }}",
|
|
7
|
+
"description": "Description of {{ pluginName }} plugin",
|
|
8
|
+
"kind": "plugin"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {},
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"typescript": "4.6.3",
|
|
13
|
+
"@strapi/strapi": "4.1.8"
|
|
14
|
+
},
|
|
15
|
+
"author": {
|
|
16
|
+
"name": "A Strapi developer"
|
|
17
|
+
},
|
|
18
|
+
"maintainers": [
|
|
19
|
+
{
|
|
20
|
+
"name": "A Strapi developer"
|
|
21
|
+
}
|
|
22
|
+
],
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=12.x.x <=16.x.x",
|
|
25
|
+
"npm": ">=6.0.0"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"develop": "tsc -w",
|
|
29
|
+
"build": "tsc"
|
|
30
|
+
},
|
|
31
|
+
"license": "MIT"
|
|
32
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `{{id}}` policy.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export default (policyContext, config, { strapi }) => {
|
|
6
|
+
// Add your own logic here.
|
|
7
|
+
strapi.log.info('In {{id}} policy.');
|
|
8
|
+
|
|
9
|
+
const canDoSomething = true;
|
|
10
|
+
|
|
11
|
+
if (canDoSomething) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return false;
|
|
16
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
routes: [
|
|
3
|
+
{
|
|
4
|
+
method: 'GET',
|
|
5
|
+
path: '/{{id}}',
|
|
6
|
+
handler: '{{id}}.find',
|
|
7
|
+
config: {
|
|
8
|
+
policies: [],
|
|
9
|
+
middlewares: [],
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
method: 'PUT',
|
|
14
|
+
path: '/{{id}}',
|
|
15
|
+
handler: '{{id}}.update',
|
|
16
|
+
config: {
|
|
17
|
+
policies: [],
|
|
18
|
+
middlewares: [],
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
method: 'DELETE',
|
|
23
|
+
path: '/{{id}}',
|
|
24
|
+
handler: '{{id}}.delete',
|
|
25
|
+
config: {
|
|
26
|
+
policies: [],
|
|
27
|
+
middlewares: [],
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/generators",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.0-beta.2",
|
|
4
4
|
"description": "Interactive API generator.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"strapi",
|
|
@@ -30,7 +30,8 @@
|
|
|
30
30
|
"main": "lib/index.js",
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@sindresorhus/slugify": "1.1.0",
|
|
33
|
-
"@strapi/utils": "4.
|
|
33
|
+
"@strapi/typescript-utils": "4.3.0-beta.2",
|
|
34
|
+
"@strapi/utils": "4.3.0-beta.2",
|
|
34
35
|
"chalk": "4.1.2",
|
|
35
36
|
"fs-extra": "10.0.0",
|
|
36
37
|
"node-plop": "0.26.3",
|
|
@@ -41,5 +42,5 @@
|
|
|
41
42
|
"node": ">=14.19.1 <=16.x.x",
|
|
42
43
|
"npm": ">=6.0.0"
|
|
43
44
|
},
|
|
44
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "42aba356ad1b0751584d3b375e83baa4a2c18f65"
|
|
45
46
|
}
|