@strapi/generators 4.2.0-alpha.1 → 4.2.0-alpha.5
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/js/plugin/admin/src/pluginId.js +5 -0
- 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 +3 -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 +8 -0
- package/lib/files/ts/plugin/server/destroy.ts +3 -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 +3 -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 +5 -0
- package/lib/files/ts/plugin/strapi-admin.js +3 -0
- package/lib/files/ts/plugin/strapi-server.js +3 -0
- package/lib/index.js +1 -1
- 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 +15 -7
- package/lib/plops/policy.js +6 -2
- package/lib/plops/prompts/get-attributes-prompts.js +4 -1
- package/lib/plops/service.js +6 -2
- package/lib/plops/utils/validate-attribute-input.js +3 -3
- package/lib/plops/utils/validate-input.js +2 -2
- 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} +1 -1
- 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 +12 -0
- package/lib/templates/ts/plugin-package.json.hbs +24 -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
- package/lib/files/plugin/admin/src/pluginId.js +0 -5
|
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 {};
|
package/lib/index.js
CHANGED
|
@@ -7,7 +7,7 @@ const nodePlop = require('node-plop');
|
|
|
7
7
|
/**
|
|
8
8
|
* Starts the Plop CLI programmatically
|
|
9
9
|
*/
|
|
10
|
-
const runCLI = () => {
|
|
10
|
+
const runCLI = async () => {
|
|
11
11
|
Plop.launch({ configPath: join(__dirname, 'plopfile.js') }, env =>
|
|
12
12
|
run({ ...env, dest: join(process.cwd(), 'src') }, undefined, true)
|
|
13
13
|
);
|
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.isTypeScriptProjectSync(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.isTypeScriptProjectSync(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.isTypeScriptProjectSync(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 getFilePath = require('./utils/get-file-path');
|
|
5
7
|
|
|
@@ -17,11 +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.isTypeScriptProjectSync(currentDir) ? 'ts' : 'js';
|
|
24
|
+
|
|
20
25
|
return [
|
|
21
26
|
{
|
|
22
27
|
type: 'add',
|
|
23
|
-
path: `${filePath}/middlewares/{{ name }}
|
|
24
|
-
templateFile:
|
|
28
|
+
path: `${filePath}/middlewares/{{ name }}.${language}`,
|
|
29
|
+
templateFile: `templates/${language}/middleware.${language}.hbs`,
|
|
25
30
|
},
|
|
26
31
|
];
|
|
27
32
|
},
|
package/lib/plops/plugin.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const chalk = require('chalk');
|
|
4
|
+
const tsUtils = require('@strapi/typescript-utils');
|
|
4
5
|
|
|
5
|
-
const logInstructions = pluginName => {
|
|
6
|
+
const logInstructions = (pluginName, { language }) => {
|
|
6
7
|
const maxLength = ` resolve: './src/plugins/${pluginName}'`.length;
|
|
7
8
|
const separator = Array(maxLength)
|
|
8
9
|
.fill('─')
|
|
9
10
|
.join('');
|
|
10
11
|
|
|
11
12
|
return `
|
|
12
|
-
You can now enable your plugin by adding the following in ${chalk.yellow(
|
|
13
|
+
You can now enable your plugin by adding the following in ${chalk.yellow(
|
|
14
|
+
`./config/plugins.${language}`
|
|
15
|
+
)}
|
|
13
16
|
${separator}
|
|
14
17
|
module.exports = {
|
|
15
18
|
${chalk.gray('// ...')}
|
|
@@ -35,24 +38,29 @@ module.exports = plop => {
|
|
|
35
38
|
},
|
|
36
39
|
],
|
|
37
40
|
actions(answers) {
|
|
41
|
+
const currentDir = process.cwd();
|
|
42
|
+
const language = tsUtils.isTypeScriptProjectSync(currentDir) ? 'ts' : 'js';
|
|
43
|
+
|
|
44
|
+
// TODO: Adds tsconfig & build command for TS plugins?
|
|
45
|
+
|
|
38
46
|
return [
|
|
39
47
|
{
|
|
40
48
|
type: 'addMany',
|
|
41
49
|
destination: 'plugins/{{ pluginName }}',
|
|
42
|
-
base:
|
|
43
|
-
templateFiles:
|
|
50
|
+
base: `files/${language}/plugin`,
|
|
51
|
+
templateFiles: `files/${language}/plugin/**`,
|
|
44
52
|
},
|
|
45
53
|
{
|
|
46
54
|
type: 'add',
|
|
47
55
|
path: 'plugins/{{ pluginName }}/README.md',
|
|
48
|
-
templateFile:
|
|
56
|
+
templateFile: `templates/${language}/README.md.hbs`,
|
|
49
57
|
},
|
|
50
58
|
{
|
|
51
59
|
type: 'add',
|
|
52
60
|
path: 'plugins/{{ pluginName }}/package.json',
|
|
53
|
-
templateFile:
|
|
61
|
+
templateFile: `templates/${language}/plugin-package.json.hbs`,
|
|
54
62
|
},
|
|
55
|
-
() => plop.renderString(logInstructions(answers.pluginName)),
|
|
63
|
+
() => plop.renderString(logInstructions(answers.pluginName, { language })),
|
|
56
64
|
];
|
|
57
65
|
},
|
|
58
66
|
});
|
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 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.isTypeScriptProjectSync(currentDir) ? 'ts' : 'js';
|
|
20
24
|
|
|
21
25
|
return [
|
|
22
26
|
{
|
|
23
27
|
type: 'add',
|
|
24
|
-
path: `${filePath}/policies/{{id}}
|
|
25
|
-
templateFile:
|
|
28
|
+
path: `${filePath}/policies/{{id}}.${language}`,
|
|
29
|
+
templateFile: `templates/${language}/policy.${language}.hbs`,
|
|
26
30
|
},
|
|
27
31
|
];
|
|
28
32
|
},
|
|
@@ -72,7 +72,10 @@ module.exports = async inquirer => {
|
|
|
72
72
|
type: 'list',
|
|
73
73
|
name: 'multiple',
|
|
74
74
|
message: 'Choose media type',
|
|
75
|
-
choices: [
|
|
75
|
+
choices: [
|
|
76
|
+
{ name: 'Multiple', value: true },
|
|
77
|
+
{ name: 'Single', value: false },
|
|
78
|
+
],
|
|
76
79
|
},
|
|
77
80
|
{
|
|
78
81
|
type: 'confirm',
|
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.isTypeScriptProjectSync(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
|
},
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
module.exports =
|
|
4
|
-
const regex =
|
|
3
|
+
module.exports = input => {
|
|
4
|
+
const regex = /^[A-Za-z-|_]+$/g;
|
|
5
5
|
|
|
6
6
|
if (!input) {
|
|
7
|
-
return
|
|
7
|
+
return 'You must provide an input';
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
return regex.test(input) || "Please use only letters, '-', '_', and no spaces";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
module.exports =
|
|
3
|
+
module.exports = input => {
|
|
4
4
|
const regex = /^[A-Za-z-]+$/g;
|
|
5
5
|
|
|
6
6
|
if (!input) {
|
|
7
|
-
return
|
|
7
|
+
return 'You must provide an input';
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
return regex.test(input) || "Please use only letters, '-' and no spaces";
|
|
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
|
+
module.exports = {
|
|
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,24 @@
|
|
|
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
|
+
"author": {
|
|
12
|
+
"name": "A Strapi developer"
|
|
13
|
+
},
|
|
14
|
+
"maintainers": [
|
|
15
|
+
{
|
|
16
|
+
"name": "A Strapi developer"
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=12.x.x <=16.x.x",
|
|
21
|
+
"npm": ">=6.0.0"
|
|
22
|
+
},
|
|
23
|
+
"license": "MIT"
|
|
24
|
+
}
|
|
@@ -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.2.0-alpha.
|
|
3
|
+
"version": "4.2.0-alpha.5",
|
|
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.2.0-alpha.
|
|
33
|
+
"@strapi/typescript-utils": "4.2.0-alpha.5",
|
|
34
|
+
"@strapi/utils": "4.2.0-alpha.5",
|
|
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": ">=12.22.0 <=16.x.x",
|
|
42
43
|
"npm": ">=6.0.0"
|
|
43
44
|
},
|
|
44
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "0095f4ec55ca381a4d1bb7d4fdfc105fa38f8fe7"
|
|
45
46
|
}
|