@strapi/generators 4.9.0-alpha.0 → 4.9.0-exp.90df253ba90fd6879eb56a720a1f80d04ff745b8

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.
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  import React from 'react';
8
- import Puzzle from '@strapi/icons/Puzzle';
8
+ import { Puzzle } from '@strapi/icons';
9
9
 
10
10
  const PluginIcon = () => <Puzzle />;
11
11
 
@@ -4,7 +4,7 @@
4
4
  *
5
5
  */
6
6
 
7
- import React, { useEffect, useRef } from 'react';
7
+ import { useEffect, useRef } from 'react';
8
8
  import pluginId from '../../pluginId';
9
9
 
10
10
  type InitializerProps = {
@@ -7,6 +7,6 @@
7
7
  import React from 'react';
8
8
  import { Puzzle } from '@strapi/icons';
9
9
 
10
- const PluginIcon: React.VoidFunctionComponent = () => <Puzzle />;
10
+ const PluginIcon = () => <Puzzle />;
11
11
 
12
12
  export default PluginIcon;
@@ -1,5 +1,5 @@
1
- import React from 'react';
2
1
  import { prefixPluginTranslations } from '@strapi/helper-plugin';
2
+
3
3
  import pluginPkg from '../../package.json';
4
4
  import pluginId from './pluginId';
5
5
  import Initializer from './components/Initializer';
@@ -8,7 +8,7 @@ import PluginIcon from './components/PluginIcon';
8
8
  const name = pluginPkg.strapi.name;
9
9
 
10
10
  export default {
11
- register(app) {
11
+ register(app: any) {
12
12
  app.addMenuLink({
13
13
  to: `/plugins/${pluginId}`,
14
14
  icon: PluginIcon,
@@ -39,12 +39,13 @@ export default {
39
39
  app.registerPlugin(plugin);
40
40
  },
41
41
 
42
- bootstrap(app) {},
43
- async registerTrads(app) {
42
+ bootstrap(app: any) {},
43
+
44
+ async registerTrads(app: any) {
44
45
  const { locales } = app;
45
46
 
46
47
  const importedTrads = await Promise.all(
47
- locales.map(locale => {
48
+ (locales as any[]).map((locale) => {
48
49
  return import(`./translations/${locale}.json`)
49
50
  .then(({ default: data }) => {
50
51
  return {
@@ -11,7 +11,7 @@ import { NotFound } from '@strapi/helper-plugin';
11
11
  import pluginId from '../../pluginId';
12
12
  import HomePage from '../HomePage';
13
13
 
14
- const App: React.VoidFunctionComponent = () => {
14
+ const App = () => {
15
15
  return (
16
16
  <div>
17
17
  <Switch>
@@ -7,7 +7,7 @@
7
7
  import React from 'react';
8
8
  import pluginId from '../../pluginId';
9
9
 
10
- const HomePage: React.VoidFunctionComponent = () => {
10
+ const HomePage = () => {
11
11
  return (
12
12
  <div>
13
13
  <h1>{pluginId}&apos;s HomePage</h1>
@@ -0,0 +1,5 @@
1
+ declare module '@strapi/design-system/*';
2
+ declare module '@strapi/design-system';
3
+ declare module '@strapi/icons';
4
+ declare module '@strapi/icons/*';
5
+ declare module '@strapi/helper-plugin';
@@ -1,24 +1,19 @@
1
1
  {
2
- "extends": "@strapi/typescript-utils/tsconfigs/server",
2
+ "extends": "@strapi/typescript-utils/tsconfigs/admin",
3
3
 
4
4
  "compilerOptions": {
5
- "outDir": "dist",
6
- "rootDir": "."
5
+ "target": "ESNext",
6
+ "strict": true
7
7
  },
8
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
- ],
9
+ "include": ["admin", "custom.d.ts"],
15
10
 
16
11
  "exclude": [
17
12
  "node_modules/",
18
13
  "dist/",
19
14
 
20
- // Do not include admin files in the server compilation
21
- "admin/",
15
+ // Do not include server files in the server compilation
16
+ "server/",
22
17
  // Do not include test files
23
18
  "**/*.test.ts"
24
19
  ]
@@ -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/plopfile.js CHANGED
@@ -8,6 +8,7 @@ const generateContentType = require('./plops/content-type');
8
8
  const generatePlugin = require('./plops/plugin');
9
9
  const generatePolicy = require('./plops/policy');
10
10
  const generateMiddleware = require('./plops/middleware');
11
+ const generateMigration = require('./plops/migration');
11
12
  const generateService = require('./plops/service');
12
13
 
13
14
  module.exports = (plop) => {
@@ -22,5 +23,6 @@ module.exports = (plop) => {
22
23
  generatePlugin(plop);
23
24
  generatePolicy(plop);
24
25
  generateMiddleware(plop);
26
+ generateMigration(plop);
25
27
  generateService(plop);
26
28
  };
@@ -0,0 +1,33 @@
1
+ 'use strict';
2
+
3
+ const tsUtils = require('@strapi/typescript-utils');
4
+ const validateFileNameInput = require('./utils/validate-file-name-input');
5
+ const getFormattedDate = require('./utils/get-formatted-date');
6
+
7
+ module.exports = (plop) => {
8
+ // Migration generator
9
+ plop.setGenerator('migration', {
10
+ description: 'Generate a migration',
11
+ prompts: [
12
+ {
13
+ type: 'input',
14
+ name: 'name',
15
+ message: 'Migration name',
16
+ validate: (input) => validateFileNameInput(input),
17
+ },
18
+ ],
19
+ actions() {
20
+ const currentDir = process.cwd();
21
+ const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
22
+ const timestamp = getFormattedDate();
23
+
24
+ return [
25
+ {
26
+ type: 'add',
27
+ path: `${currentDir}/database/migrations/${timestamp}.{{ name }}.${language}`,
28
+ templateFile: `templates/${language}/migration.${language}.hbs`,
29
+ },
30
+ ];
31
+ },
32
+ });
33
+ };
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ module.exports = (date = new Date()) => {
4
+ return new Date(date.getTime() - date.getTimezoneOffset() * 60000)
5
+ .toJSON()
6
+ .replace(/[-:]/g, '.')
7
+ .replace(/\....Z/, '');
8
+ };
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ module.exports = (input) => {
4
+ const regex = /^[A-Za-z-_0-9]+$/g;
5
+
6
+ if (!input) {
7
+ return 'You must provide an input';
8
+ }
9
+
10
+ return regex.test(input) || "Please use only letters and number, '-' or '_' and no spaces";
11
+ };
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Migration `{{ name }}`
5
+ */
6
+
7
+ module.exports = {
8
+ /**
9
+ *
10
+ * @param {import('knex').Knex} knex
11
+ */
12
+ async up(knex) {
13
+
14
+ },
15
+ };
@@ -8,7 +8,24 @@
8
8
  "kind": "plugin",
9
9
  "displayName": "{{titleCase pluginName }}"
10
10
  },
11
- "dependencies": {},
11
+ "dependencies": {
12
+ "@strapi/design-system": "^1.6.3",
13
+ "@strapi/helper-plugin": "^4.6.0",
14
+ "@strapi/icons": "^1.6.3",
15
+ "prop-types": "^15.7.2"
16
+ },
17
+ "devDependencies": {
18
+ "react": "^17.0.2",
19
+ "react-dom": "^17.0.2",
20
+ "react-router-dom": "^5.3.4",
21
+ "styled-components": "^5.3.6"
22
+ },
23
+ "peerDependencies": {
24
+ "react": "^17.0.2",
25
+ "react-dom": "^17.0.2",
26
+ "react-router-dom": "^5.3.4",
27
+ "styled-components": "^5.3.6"
28
+ },
12
29
  "author": {
13
30
  "name": "A Strapi developer"
14
31
  },
@@ -0,0 +1,11 @@
1
+ import type { Knex } from 'knex';
2
+
3
+ /**
4
+ * Migration `{{ name }}`
5
+ */
6
+
7
+ export default {
8
+ up: async (knex: Knex) => {
9
+
10
+ },
11
+ };
@@ -8,11 +8,29 @@
8
8
  "kind": "plugin"
9
9
  },
10
10
  "dependencies": {
11
- "@strapi/icons": "^1.3.1"
11
+ "@strapi/design-system": "^1.6.3",
12
+ "@strapi/helper-plugin": "^4.6.0",
13
+ "@strapi/icons": "^1.6.3",
14
+ "prop-types": "^15.7.2"
12
15
  },
13
16
  "devDependencies": {
17
+ "@strapi/typescript-utils": "^4.6.0",
18
+ "@types/react": "^17.0.53",
19
+ "@types/react-dom": "^17.0.18",
20
+ "@types/react-router-dom": "^5.3.3",
21
+ "@types/styled-components": "^5.1.26",
22
+ "react": "^17.0.2",
23
+ "react-dom": "^17.0.2",
24
+ "react-router-dom": "^5.3.4",
25
+ "styled-components": "^5.3.6",
14
26
  "typescript": "4.6.3"
15
27
  },
28
+ "peerDependencies": {
29
+ "react": "^17.0.2",
30
+ "react-dom": "^17.0.2",
31
+ "react-router-dom": "^5.3.4",
32
+ "styled-components": "^5.3.6"
33
+ },
16
34
  "author": {
17
35
  "name": "A Strapi developer"
18
36
  },
@@ -26,8 +44,8 @@
26
44
  "npm": ">=6.0.0"
27
45
  },
28
46
  "scripts": {
29
- "develop": "tsc -w",
30
- "build": "tsc"
47
+ "develop": "tsc -p tsconfig.server.json -w",
48
+ "build": "tsc -p tsconfig.server.json"
31
49
  },
32
50
  "license": "MIT"
33
51
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/generators",
3
- "version": "4.9.0-alpha.0",
3
+ "version": "4.9.0-exp.90df253ba90fd6879eb56a720a1f80d04ff745b8",
4
4
  "description": "Interactive API generator.",
5
5
  "keywords": [
6
6
  "strapi",
@@ -30,8 +30,8 @@
30
30
  "main": "lib/index.js",
31
31
  "dependencies": {
32
32
  "@sindresorhus/slugify": "1.1.0",
33
- "@strapi/typescript-utils": "4.9.0-alpha.0",
34
- "@strapi/utils": "4.9.0-alpha.0",
33
+ "@strapi/typescript-utils": "4.9.0-exp.90df253ba90fd6879eb56a720a1f80d04ff745b8",
34
+ "@strapi/utils": "4.9.0-exp.90df253ba90fd6879eb56a720a1f80d04ff745b8",
35
35
  "chalk": "4.1.2",
36
36
  "fs-extra": "10.0.0",
37
37
  "node-plop": "0.26.3",
@@ -42,5 +42,5 @@
42
42
  "node": ">=14.19.1 <=18.x.x",
43
43
  "npm": ">=6.0.0"
44
44
  },
45
- "gitHead": "35f783d0dc07db101e7e62cb4d682f751551f452"
45
+ "gitHead": "366eb8a0d0f06935914854c6d9c4b3fe859468e0"
46
46
  }
@@ -1,42 +0,0 @@
1
- /**
2
- * axios with a custom config.
3
- */
4
-
5
- import axios from 'axios';
6
- import { auth, wrapAxiosInstance } 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
- const wrapper = wrapAxiosInstance(instance);
41
-
42
- export default wrapper;
@@ -1,42 +0,0 @@
1
- /**
2
- * axios with a custom config.
3
- */
4
-
5
- import axios from 'axios';
6
- import { auth, wrapAxiosInstance } 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
- const wrapper = wrapAxiosInstance(instance);
41
-
42
- export default wrapper;