@strapi/generators 4.10.1-experimental.0 → 4.10.2-alpha.0
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/dist/files/js/plugin/.editorconfig +7 -0
- package/dist/files/js/plugin/.gitattributes +103 -0
- package/dist/files/ts/plugin/.editorconfig +7 -0
- package/dist/files/ts/plugin/.gitattributes +103 -0
- package/package.json +22 -5
- package/.eslintignore +0 -3
- package/.eslintrc.js +0 -4
- package/lib/files/js/plugin/admin/src/components/Initializer/index.js +0 -26
- package/lib/files/js/plugin/admin/src/components/PluginIcon/index.js +0 -12
- package/lib/files/js/plugin/admin/src/index.js +0 -63
- package/lib/files/js/plugin/admin/src/pages/App/index.js +0 -25
- package/lib/files/js/plugin/admin/src/pages/HomePage/index.js +0 -20
- package/lib/files/js/plugin/admin/src/pluginId.js +0 -5
- package/lib/files/js/plugin/admin/src/translations/en.json +0 -1
- package/lib/files/js/plugin/admin/src/translations/fr.json +0 -1
- package/lib/files/js/plugin/admin/src/utils/getTrad.js +0 -5
- package/lib/files/js/plugin/server/bootstrap.js +0 -5
- package/lib/files/js/plugin/server/config/index.js +0 -6
- package/lib/files/js/plugin/server/content-types/index.js +0 -3
- package/lib/files/js/plugin/server/controllers/index.js +0 -7
- package/lib/files/js/plugin/server/controllers/my-controller.js.hbs +0 -10
- package/lib/files/js/plugin/server/destroy.js +0 -5
- package/lib/files/js/plugin/server/index.js +0 -25
- package/lib/files/js/plugin/server/middlewares/index.js +0 -3
- package/lib/files/js/plugin/server/policies/index.js +0 -3
- package/lib/files/js/plugin/server/register.js +0 -5
- package/lib/files/js/plugin/server/routes/index.js +0 -10
- package/lib/files/js/plugin/server/services/index.js +0 -7
- package/lib/files/js/plugin/server/services/my-service.js +0 -7
- package/lib/files/js/plugin/strapi-admin.js +0 -3
- package/lib/files/js/plugin/strapi-server.js +0 -3
- package/lib/files/ts/plugin/admin/src/components/Initializer/index.tsx +0 -24
- package/lib/files/ts/plugin/admin/src/components/PluginIcon/index.tsx +0 -12
- package/lib/files/ts/plugin/admin/src/index.tsx +0 -67
- package/lib/files/ts/plugin/admin/src/pages/App/index.tsx +0 -25
- package/lib/files/ts/plugin/admin/src/pages/HomePage/index.tsx +0 -19
- package/lib/files/ts/plugin/admin/src/pluginId.ts +0 -5
- package/lib/files/ts/plugin/admin/src/translations/en.json +0 -1
- package/lib/files/ts/plugin/admin/src/translations/fr.json +0 -1
- package/lib/files/ts/plugin/admin/src/utils/getTrad.ts +0 -5
- package/lib/files/ts/plugin/custom.d.ts +0 -5
- package/lib/files/ts/plugin/server/bootstrap.ts +0 -5
- package/lib/files/ts/plugin/server/config/index.ts +0 -4
- package/lib/files/ts/plugin/server/content-types/index.ts +0 -1
- package/lib/files/ts/plugin/server/controllers/index.ts +0 -5
- package/lib/files/ts/plugin/server/controllers/my-controller.ts.hbs +0 -10
- package/lib/files/ts/plugin/server/destroy.ts +0 -5
- package/lib/files/ts/plugin/server/index.ts +0 -23
- package/lib/files/ts/plugin/server/middlewares/index.ts +0 -1
- package/lib/files/ts/plugin/server/policies/index.ts +0 -1
- package/lib/files/ts/plugin/server/register.ts +0 -5
- package/lib/files/ts/plugin/server/routes/index.ts +0 -10
- package/lib/files/ts/plugin/server/services/index.ts +0 -5
- package/lib/files/ts/plugin/server/services/my-service.ts +0 -7
- package/lib/files/ts/plugin/strapi-admin.js +0 -3
- package/lib/files/ts/plugin/strapi-server.js +0 -3
- package/lib/files/ts/plugin/tsconfig.json +0 -20
- package/lib/files/ts/plugin/tsconfig.server.json +0 -25
- package/lib/index.js +0 -37
- package/lib/plopfile.js +0 -28
- package/lib/plops/__tests__/content-type.test.js +0 -179
- package/lib/plops/api.js +0 -82
- package/lib/plops/content-type.js +0 -148
- package/lib/plops/controller.js +0 -36
- package/lib/plops/middleware.js +0 -36
- package/lib/plops/migration.js +0 -33
- package/lib/plops/plugin.js +0 -91
- package/lib/plops/policy.js +0 -36
- package/lib/plops/prompts/bootstrap-api-prompts.js +0 -10
- package/lib/plops/prompts/ct-names-prompts.js +0 -44
- package/lib/plops/prompts/draft-and-publish-prompts.js +0 -10
- package/lib/plops/prompts/get-attributes-prompts.js +0 -105
- package/lib/plops/prompts/get-destination-prompts.js +0 -79
- package/lib/plops/prompts/kind-prompts.js +0 -17
- package/lib/plops/service.js +0 -34
- package/lib/plops/utils/__tests__/get-file-path.test.js +0 -25
- package/lib/plops/utils/get-file-path.js +0 -17
- package/lib/plops/utils/get-formatted-date.js +0 -8
- package/lib/plops/utils/validate-attribute-input.js +0 -11
- package/lib/plops/utils/validate-file-name-input.js +0 -11
- package/lib/plops/utils/validate-input.js +0 -11
- package/lib/templates/js/README.md.hbs +0 -3
- package/lib/templates/js/collection-type-routes.js.hbs +0 -49
- package/lib/templates/js/content-type.schema.json.hbs +0 -15
- package/lib/templates/js/controller.js.hbs +0 -15
- package/lib/templates/js/core-controller.js.hbs +0 -9
- package/lib/templates/js/core-router.js.hbs +0 -9
- package/lib/templates/js/core-service.js.hbs +0 -9
- package/lib/templates/js/middleware.js.hbs +0 -14
- package/lib/templates/js/migration.js.hbs +0 -15
- package/lib/templates/js/plugin-package.json.hbs +0 -42
- package/lib/templates/js/policy.js.hbs +0 -18
- package/lib/templates/js/service.js.hbs +0 -7
- package/lib/templates/js/single-route.js.hbs +0 -13
- package/lib/templates/js/single-type-routes.js.hbs +0 -33
- package/lib/templates/ts/README.md.hbs +0 -3
- package/lib/templates/ts/collection-type-routes.ts.hbs +0 -49
- package/lib/templates/ts/content-type.schema.json.hbs +0 -15
- package/lib/templates/ts/controller.ts.hbs +0 -13
- package/lib/templates/ts/core-controller.ts.hbs +0 -7
- package/lib/templates/ts/core-router.ts.hbs +0 -7
- package/lib/templates/ts/core-service.ts.hbs +0 -7
- package/lib/templates/ts/middleware.ts.hbs +0 -14
- package/lib/templates/ts/migration.ts.hbs +0 -11
- package/lib/templates/ts/plugin-package.json.hbs +0 -51
- package/lib/templates/ts/policy.ts.hbs +0 -16
- package/lib/templates/ts/service.ts.hbs +0 -5
- package/lib/templates/ts/single-route.ts.hbs +0 -13
- package/lib/templates/ts/single-type-routes.ts.hbs +0 -31
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { prefixPluginTranslations } from '@strapi/helper-plugin';
|
|
2
|
-
|
|
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: any) {
|
|
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: any) {},
|
|
43
|
-
|
|
44
|
-
async registerTrads(app: any) {
|
|
45
|
-
const { locales } = app;
|
|
46
|
-
|
|
47
|
-
const importedTrads = await Promise.all(
|
|
48
|
-
(locales as any[]).map((locale) => {
|
|
49
|
-
return import(`./translations/${locale}.json`)
|
|
50
|
-
.then(({ default: data }) => {
|
|
51
|
-
return {
|
|
52
|
-
data: prefixPluginTranslations(data, pluginId),
|
|
53
|
-
locale,
|
|
54
|
-
};
|
|
55
|
-
})
|
|
56
|
-
.catch(() => {
|
|
57
|
-
return {
|
|
58
|
-
data: {},
|
|
59
|
-
locale,
|
|
60
|
-
};
|
|
61
|
-
});
|
|
62
|
-
})
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
return Promise.resolve(importedTrads);
|
|
66
|
-
},
|
|
67
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
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 { AnErrorOccurred } from '@strapi/helper-plugin';
|
|
11
|
-
import pluginId from '../../pluginId';
|
|
12
|
-
import HomePage from '../HomePage';
|
|
13
|
-
|
|
14
|
-
const App = () => {
|
|
15
|
-
return (
|
|
16
|
-
<div>
|
|
17
|
-
<Switch>
|
|
18
|
-
<Route path={`/plugins/${pluginId}`} component={HomePage} exact />
|
|
19
|
-
<Route component={AnErrorOccurred} />
|
|
20
|
-
</Switch>
|
|
21
|
-
</div>
|
|
22
|
-
);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export default App;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
*
|
|
3
|
-
* HomePage
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import React from 'react';
|
|
8
|
-
import pluginId from '../../pluginId';
|
|
9
|
-
|
|
10
|
-
const HomePage = () => {
|
|
11
|
-
return (
|
|
12
|
-
<div>
|
|
13
|
-
<h1>{pluginId}'s HomePage</h1>
|
|
14
|
-
<p>Happy coding</p>
|
|
15
|
-
</div>
|
|
16
|
-
);
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export default HomePage;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default {};
|
|
@@ -1,23 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default {};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "@strapi/typescript-utils/tsconfigs/admin",
|
|
3
|
-
|
|
4
|
-
"compilerOptions": {
|
|
5
|
-
"target": "ESNext",
|
|
6
|
-
"strict": true
|
|
7
|
-
},
|
|
8
|
-
|
|
9
|
-
"include": ["admin", "custom.d.ts"],
|
|
10
|
-
|
|
11
|
-
"exclude": [
|
|
12
|
-
"node_modules/",
|
|
13
|
-
"dist/",
|
|
14
|
-
|
|
15
|
-
// Do not include server files in the server compilation
|
|
16
|
-
"server/",
|
|
17
|
-
// Do not include test files
|
|
18
|
-
"**/*.test.ts"
|
|
19
|
-
]
|
|
20
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
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/index.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { join } = require('path');
|
|
4
|
-
const { Plop, run } = require('plop');
|
|
5
|
-
const nodePlop = require('node-plop');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Starts the Plop CLI programmatically
|
|
9
|
-
*/
|
|
10
|
-
const runCLI = () => {
|
|
11
|
-
Plop.launch({ configPath: join(__dirname, 'plopfile.js') }, (env) =>
|
|
12
|
-
run({ ...env, dest: join(process.cwd(), 'src') }, undefined, true)
|
|
13
|
-
);
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Runs a generator programmatically without prompts
|
|
18
|
-
* @param {string} generatorName
|
|
19
|
-
* @param {Object} options generator options replacing the prompts answers
|
|
20
|
-
* @param {Object} plopOptions
|
|
21
|
-
* @param {string} plopOptions.dir base path for plop to generate the files from
|
|
22
|
-
*/
|
|
23
|
-
const generate = async (generatorName, options, { dir = process.cwd() } = {}) => {
|
|
24
|
-
const plop = nodePlop(join(__dirname, 'plopfile.js'), { destBasePath: join(dir, 'src') });
|
|
25
|
-
|
|
26
|
-
const generator = plop.getGenerator(generatorName);
|
|
27
|
-
await generator.runActions(options, {
|
|
28
|
-
onSuccess() {},
|
|
29
|
-
onFailure() {},
|
|
30
|
-
onComment() {},
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
module.exports = {
|
|
35
|
-
generate,
|
|
36
|
-
runCLI,
|
|
37
|
-
};
|
package/lib/plopfile.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const pluralize = require('pluralize');
|
|
4
|
-
|
|
5
|
-
const generateApi = require('./plops/api');
|
|
6
|
-
const generateController = require('./plops/controller');
|
|
7
|
-
const generateContentType = require('./plops/content-type');
|
|
8
|
-
const generatePlugin = require('./plops/plugin');
|
|
9
|
-
const generatePolicy = require('./plops/policy');
|
|
10
|
-
const generateMiddleware = require('./plops/middleware');
|
|
11
|
-
const generateMigration = require('./plops/migration');
|
|
12
|
-
const generateService = require('./plops/service');
|
|
13
|
-
|
|
14
|
-
module.exports = (plop) => {
|
|
15
|
-
// Plop config
|
|
16
|
-
plop.setWelcomeMessage('Strapi Generators');
|
|
17
|
-
plop.addHelper('pluralize', (text) => pluralize(text));
|
|
18
|
-
|
|
19
|
-
// Generators
|
|
20
|
-
generateApi(plop);
|
|
21
|
-
generateController(plop);
|
|
22
|
-
generateContentType(plop);
|
|
23
|
-
generatePlugin(plop);
|
|
24
|
-
generatePolicy(plop);
|
|
25
|
-
generateMiddleware(plop);
|
|
26
|
-
generateMigration(plop);
|
|
27
|
-
generateService(plop);
|
|
28
|
-
};
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const { readFile, remove, stat } = require('fs-extra');
|
|
5
|
-
const strapiGenerators = require('../../index');
|
|
6
|
-
|
|
7
|
-
describe('Content Type Generator', () => {
|
|
8
|
-
const outputDirectory = path.join(__dirname, 'output');
|
|
9
|
-
|
|
10
|
-
afterEach(async () => {
|
|
11
|
-
await remove(outputDirectory);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
test('it generates the schema', async () => {
|
|
15
|
-
await strapiGenerators.generate(
|
|
16
|
-
'content-type',
|
|
17
|
-
{
|
|
18
|
-
displayName: 'testContentType',
|
|
19
|
-
singularName: 'testContentType',
|
|
20
|
-
pluralName: 'testContentTypes',
|
|
21
|
-
kind: 'singleType',
|
|
22
|
-
id: 'testContentType',
|
|
23
|
-
useDraftAndPublish: false,
|
|
24
|
-
destination: 'new',
|
|
25
|
-
bootstrapApi: false,
|
|
26
|
-
attributes: [],
|
|
27
|
-
},
|
|
28
|
-
{ dir: outputDirectory }
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
const generatedSchemaPath = path.join(
|
|
32
|
-
outputDirectory,
|
|
33
|
-
'src/api/testContentType',
|
|
34
|
-
'content-types/testContentType/schema.json'
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
expect((await stat(generatedSchemaPath)).isFile()).toBeTruthy();
|
|
38
|
-
|
|
39
|
-
const fileContent = await readFile(generatedSchemaPath, 'utf-8');
|
|
40
|
-
|
|
41
|
-
expect(fileContent).not.toBeNull();
|
|
42
|
-
|
|
43
|
-
const schema = JSON.parse(fileContent.toString());
|
|
44
|
-
|
|
45
|
-
expect(schema).toStrictEqual({
|
|
46
|
-
kind: 'singleType',
|
|
47
|
-
collectionName: 'test_content_types',
|
|
48
|
-
info: {
|
|
49
|
-
singularName: 'testContentType',
|
|
50
|
-
pluralName: 'testContentTypes',
|
|
51
|
-
displayName: 'testContentType',
|
|
52
|
-
},
|
|
53
|
-
options: {
|
|
54
|
-
draftAndPublish: false,
|
|
55
|
-
comment: '',
|
|
56
|
-
},
|
|
57
|
-
attributes: {},
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
test('it scaffolds a new API', async () => {
|
|
62
|
-
await strapiGenerators.generate(
|
|
63
|
-
'content-type',
|
|
64
|
-
{
|
|
65
|
-
displayName: 'testContentType',
|
|
66
|
-
singularName: 'testContentType',
|
|
67
|
-
pluralName: 'testContentTypes',
|
|
68
|
-
kind: 'singleType',
|
|
69
|
-
id: 'testContentType',
|
|
70
|
-
useDraftAndPublish: false,
|
|
71
|
-
destination: 'new',
|
|
72
|
-
bootstrapApi: true,
|
|
73
|
-
attributes: [],
|
|
74
|
-
},
|
|
75
|
-
{ dir: outputDirectory }
|
|
76
|
-
);
|
|
77
|
-
const generatedApiPath = path.join(outputDirectory, 'src/api/testContentType');
|
|
78
|
-
|
|
79
|
-
expect((await stat(generatedApiPath)).isDirectory()).toBeTruthy();
|
|
80
|
-
expect(
|
|
81
|
-
(await stat(path.join(generatedApiPath, 'controllers/testContentType.js'))).isFile()
|
|
82
|
-
).toBeTruthy();
|
|
83
|
-
expect(
|
|
84
|
-
(await stat(path.join(generatedApiPath, 'services/testContentType.js'))).isFile()
|
|
85
|
-
).toBeTruthy();
|
|
86
|
-
expect(
|
|
87
|
-
(await stat(path.join(generatedApiPath, 'routes/testContentType.js'))).isFile()
|
|
88
|
-
).toBeTruthy();
|
|
89
|
-
|
|
90
|
-
const controller = await readFile(
|
|
91
|
-
path.join(generatedApiPath, 'controllers/testContentType.js')
|
|
92
|
-
);
|
|
93
|
-
const router = await readFile(path.join(generatedApiPath, 'routes/testContentType.js'));
|
|
94
|
-
const service = await readFile(path.join(generatedApiPath, 'services/testContentType.js'));
|
|
95
|
-
|
|
96
|
-
expect(controller.toString()).toMatchInlineSnapshot(`
|
|
97
|
-
"'use strict';
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* testContentType controller
|
|
101
|
-
*/
|
|
102
|
-
|
|
103
|
-
const { createCoreController } = require('@strapi/strapi').factories;
|
|
104
|
-
|
|
105
|
-
module.exports = createCoreController('api::testContentType.testContentType');
|
|
106
|
-
"
|
|
107
|
-
`);
|
|
108
|
-
expect(router.toString()).toMatchInlineSnapshot(`
|
|
109
|
-
"'use strict';
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* testContentType router.
|
|
113
|
-
*/
|
|
114
|
-
|
|
115
|
-
const { createCoreRouter } = require('@strapi/strapi').factories;
|
|
116
|
-
|
|
117
|
-
module.exports = createCoreRouter('api::testContentType.testContentType');
|
|
118
|
-
"
|
|
119
|
-
`);
|
|
120
|
-
expect(service.toString()).toMatchInlineSnapshot(`
|
|
121
|
-
"'use strict';
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* testContentType service.
|
|
125
|
-
*/
|
|
126
|
-
|
|
127
|
-
const { createCoreService } = require('@strapi/strapi').factories;
|
|
128
|
-
|
|
129
|
-
module.exports = createCoreService('api::testContentType.testContentType');
|
|
130
|
-
"
|
|
131
|
-
`);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
test('it generates the schema, then adds the attributes', async () => {
|
|
135
|
-
await strapiGenerators.generate(
|
|
136
|
-
'content-type',
|
|
137
|
-
{
|
|
138
|
-
displayName: 'testContentType',
|
|
139
|
-
singularName: 'testContentType',
|
|
140
|
-
pluralName: 'testContentTypes',
|
|
141
|
-
kind: 'singleType',
|
|
142
|
-
id: 'testContentType',
|
|
143
|
-
useDraftAndPublish: false,
|
|
144
|
-
destination: 'new',
|
|
145
|
-
bootstrapApi: false,
|
|
146
|
-
attributes: [
|
|
147
|
-
{
|
|
148
|
-
attributeName: 'name',
|
|
149
|
-
attributeType: 'string',
|
|
150
|
-
},
|
|
151
|
-
{
|
|
152
|
-
attributeName: 'email',
|
|
153
|
-
attributeType: 'string',
|
|
154
|
-
},
|
|
155
|
-
],
|
|
156
|
-
},
|
|
157
|
-
{ dir: outputDirectory }
|
|
158
|
-
);
|
|
159
|
-
|
|
160
|
-
const generatedSchemaPath = path.join(
|
|
161
|
-
outputDirectory,
|
|
162
|
-
'src/api/testContentType',
|
|
163
|
-
'content-types/testContentType/schema.json'
|
|
164
|
-
);
|
|
165
|
-
|
|
166
|
-
expect((await stat(generatedSchemaPath)).isFile()).toBeTruthy();
|
|
167
|
-
|
|
168
|
-
const fileContent = await readFile(generatedSchemaPath, 'utf-8');
|
|
169
|
-
|
|
170
|
-
expect(fileContent).not.toBeNull();
|
|
171
|
-
|
|
172
|
-
const schema = JSON.parse(fileContent.toString());
|
|
173
|
-
|
|
174
|
-
expect(schema.attributes).toStrictEqual({
|
|
175
|
-
email: { type: 'string' },
|
|
176
|
-
name: { type: 'string' },
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
});
|
package/lib/plops/api.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { join } = require('path');
|
|
4
|
-
const fs = require('fs-extra');
|
|
5
|
-
const tsUtils = require('@strapi/typescript-utils');
|
|
6
|
-
|
|
7
|
-
const validateInput = require('./utils/validate-input');
|
|
8
|
-
|
|
9
|
-
module.exports = (plop) => {
|
|
10
|
-
// API generator
|
|
11
|
-
plop.setGenerator('api', {
|
|
12
|
-
description: 'Generate a basic API',
|
|
13
|
-
prompts: [
|
|
14
|
-
{
|
|
15
|
-
type: 'input',
|
|
16
|
-
name: 'id',
|
|
17
|
-
message: 'API name',
|
|
18
|
-
validate: (input) => validateInput(input),
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
type: 'confirm',
|
|
22
|
-
name: 'isPluginApi',
|
|
23
|
-
message: 'Is this API for a plugin?',
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
when: (answers) => answers.isPluginApi,
|
|
27
|
-
type: 'list',
|
|
28
|
-
name: 'plugin',
|
|
29
|
-
message: 'Plugin name',
|
|
30
|
-
async choices() {
|
|
31
|
-
const pluginsPath = join(plop.getDestBasePath(), 'plugins');
|
|
32
|
-
const exists = await fs.pathExists(pluginsPath);
|
|
33
|
-
|
|
34
|
-
if (!exists) {
|
|
35
|
-
throw Error('Couldn\'t find a "plugins" directory');
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const pluginsDir = await fs.readdir(pluginsPath, { withFileTypes: true });
|
|
39
|
-
const pluginsDirContent = pluginsDir.filter((fd) => fd.isDirectory());
|
|
40
|
-
|
|
41
|
-
if (pluginsDirContent.length === 0) {
|
|
42
|
-
throw Error('The "plugins" directory is empty');
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return pluginsDirContent;
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
],
|
|
49
|
-
actions(answers) {
|
|
50
|
-
const filePath =
|
|
51
|
-
answers.isPluginApi && answers.plugin ? 'plugins/{{ plugin }}' : 'api/{{ id }}';
|
|
52
|
-
const currentDir = process.cwd();
|
|
53
|
-
const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
54
|
-
|
|
55
|
-
const baseActions = [
|
|
56
|
-
{
|
|
57
|
-
type: 'add',
|
|
58
|
-
path: `${filePath}/controllers/{{ id }}.${language}`,
|
|
59
|
-
templateFile: `templates/${language}/controller.${language}.hbs`,
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
type: 'add',
|
|
63
|
-
path: `${filePath}/services/{{ id }}.${language}`,
|
|
64
|
-
templateFile: `templates/${language}/service.${language}.hbs`,
|
|
65
|
-
},
|
|
66
|
-
];
|
|
67
|
-
|
|
68
|
-
if (answers.isPluginApi) {
|
|
69
|
-
return baseActions;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return [
|
|
73
|
-
{
|
|
74
|
-
type: 'add',
|
|
75
|
-
path: `${filePath}/routes/{{ id }}.${language}`,
|
|
76
|
-
templateFile: `templates/${language}/single-route.${language}.hbs`,
|
|
77
|
-
},
|
|
78
|
-
...baseActions,
|
|
79
|
-
];
|
|
80
|
-
},
|
|
81
|
-
});
|
|
82
|
-
};
|