@strapi/strapi 4.0.0-next.6 → 4.0.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.
Files changed (166) hide show
  1. package/README.md +12 -12
  2. package/bin/strapi.js +41 -60
  3. package/lib/Strapi.js +234 -114
  4. package/lib/commands/build.js +16 -6
  5. package/lib/commands/console.js +1 -1
  6. package/lib/commands/content-types/list.js +22 -0
  7. package/lib/commands/develop.js +17 -18
  8. package/lib/commands/generate-template.js +4 -5
  9. package/lib/commands/hooks/list.js +22 -0
  10. package/lib/commands/middlewares/list.js +22 -0
  11. package/lib/commands/new.js +3 -1
  12. package/lib/commands/policies/list.js +22 -0
  13. package/lib/commands/routes/list.js +28 -0
  14. package/lib/commands/services/list.js +22 -0
  15. package/lib/commands/watchAdmin.js +18 -8
  16. package/lib/container.js +6 -6
  17. package/lib/core/app-configuration/config-loader.js +1 -37
  18. package/lib/core/app-configuration/index.js +6 -46
  19. package/lib/core/app-configuration/load-config-file.js +43 -0
  20. package/lib/core/bootstrap.js +5 -117
  21. package/lib/core/domain/component/index.js +24 -0
  22. package/lib/core/domain/component/validator.js +29 -0
  23. package/lib/core/domain/content-type/index.js +140 -0
  24. package/lib/core/domain/content-type/validator.js +64 -0
  25. package/lib/core/domain/module/index.js +108 -0
  26. package/lib/core/domain/module/validation.js +33 -0
  27. package/lib/core/loaders/admin.js +16 -0
  28. package/lib/core/loaders/apis.js +159 -0
  29. package/lib/core/{load-components.js → loaders/components.js} +5 -7
  30. package/lib/core/loaders/index.js +11 -0
  31. package/lib/core/loaders/middlewares.js +36 -0
  32. package/lib/core/loaders/plugins/get-enabled-plugins.js +116 -0
  33. package/lib/core/loaders/plugins/index.js +123 -0
  34. package/lib/core/loaders/policies.js +28 -0
  35. package/lib/core/loaders/src-index.js +39 -0
  36. package/lib/core/registries/apis.js +29 -0
  37. package/lib/core/{app-configuration/config-provider.js → registries/config.js} +4 -11
  38. package/lib/core/registries/content-types.js +97 -0
  39. package/lib/core/registries/controllers.d.ts +7 -0
  40. package/lib/core/registries/controllers.js +114 -0
  41. package/lib/core/registries/hooks.d.ts +20 -0
  42. package/lib/core/registries/hooks.js +87 -0
  43. package/lib/core/registries/middlewares.d.ts +5 -0
  44. package/lib/core/registries/middlewares.js +89 -0
  45. package/lib/core/registries/modules.js +44 -0
  46. package/lib/core/registries/plugins.js +28 -0
  47. package/lib/core/registries/policies.d.ts +9 -0
  48. package/lib/core/registries/policies.js +89 -0
  49. package/lib/core/registries/services.d.ts +7 -0
  50. package/lib/core/registries/services.js +114 -0
  51. package/lib/core/utils.js +35 -0
  52. package/lib/core-api/controller/collection-type.js +45 -26
  53. package/lib/core-api/controller/index.d.ts +25 -0
  54. package/lib/core-api/controller/index.js +33 -11
  55. package/lib/core-api/controller/single-type.js +29 -15
  56. package/lib/core-api/controller/transform.js +62 -6
  57. package/lib/core-api/routes/index.js +71 -0
  58. package/lib/core-api/service/collection-type.js +43 -21
  59. package/lib/core-api/service/index.d.ts +21 -0
  60. package/lib/core-api/service/index.js +8 -67
  61. package/lib/core-api/service/pagination.js +130 -0
  62. package/lib/core-api/service/single-type.js +17 -19
  63. package/lib/factories.d.ts +48 -0
  64. package/lib/factories.js +84 -0
  65. package/lib/index.d.ts +10 -31
  66. package/lib/index.js +5 -1
  67. package/lib/middlewares/body.js +33 -0
  68. package/lib/middlewares/compression.js +8 -0
  69. package/lib/middlewares/cors.js +58 -0
  70. package/lib/middlewares/errors.js +40 -0
  71. package/lib/middlewares/favicon.js +19 -0
  72. package/lib/middlewares/index.d.ts +5 -0
  73. package/lib/middlewares/index.js +30 -117
  74. package/lib/middlewares/ip.js +8 -0
  75. package/lib/middlewares/logger.js +27 -0
  76. package/lib/middlewares/powered-by.js +20 -0
  77. package/lib/middlewares/public/index.js +98 -73
  78. package/lib/middlewares/query.js +46 -0
  79. package/lib/middlewares/response-time.js +15 -0
  80. package/lib/middlewares/responses.js +19 -0
  81. package/lib/middlewares/security.js +51 -0
  82. package/lib/middlewares/session/index.js +6 -6
  83. package/lib/migrations/draft-publish.js +57 -0
  84. package/lib/services/auth/index.js +87 -0
  85. package/lib/services/core-store.js +64 -51
  86. package/lib/services/cron.js +54 -0
  87. package/lib/services/entity-service/attributes/index.js +31 -0
  88. package/lib/services/entity-service/attributes/transforms.js +20 -0
  89. package/lib/services/entity-service/components.js +39 -15
  90. package/lib/services/entity-service/index.d.ts +91 -0
  91. package/lib/services/entity-service/index.js +120 -59
  92. package/lib/services/entity-service/params.js +52 -94
  93. package/lib/services/entity-validator/index.js +76 -43
  94. package/lib/services/entity-validator/validators.js +129 -43
  95. package/lib/services/errors.js +77 -0
  96. package/lib/{core → services}/fs.js +10 -2
  97. package/lib/services/metrics/index.js +41 -38
  98. package/lib/services/metrics/sender.js +2 -2
  99. package/lib/services/server/admin-api.js +14 -0
  100. package/lib/services/server/api.js +36 -0
  101. package/lib/services/server/compose-endpoint.js +141 -0
  102. package/lib/services/server/content-api.js +16 -0
  103. package/lib/{server.js → services/server/http-server.js} +0 -0
  104. package/lib/services/server/index.js +127 -0
  105. package/lib/services/server/koa.js +64 -0
  106. package/lib/services/server/middleware.js +122 -0
  107. package/lib/services/server/policy.js +32 -0
  108. package/lib/services/server/register-middlewares.js +110 -0
  109. package/lib/services/server/register-routes.js +106 -0
  110. package/lib/services/server/routing.js +120 -0
  111. package/lib/services/utils/upload-files.js +1 -1
  112. package/lib/services/webhook-runner.js +1 -1
  113. package/lib/utils/ee.js +3 -3
  114. package/lib/utils/get-dirs.js +17 -0
  115. package/lib/utils/index.js +2 -0
  116. package/lib/utils/is-initialized.js +1 -1
  117. package/lib/utils/run-checks.js +0 -15
  118. package/lib/utils/signals.js +24 -0
  119. package/lib/utils/startup-logger.js +2 -2
  120. package/lib/utils/update-notifier/index.js +3 -2
  121. package/package.json +93 -96
  122. package/lib/commands/generate.js +0 -76
  123. package/lib/core/index.js +0 -17
  124. package/lib/core/load-apis.js +0 -20
  125. package/lib/core/load-extensions.js +0 -71
  126. package/lib/core/load-functions.js +0 -21
  127. package/lib/core/load-middlewares.js +0 -130
  128. package/lib/core/load-modules.js +0 -55
  129. package/lib/core/load-plugins.js +0 -68
  130. package/lib/core/load-policies.js +0 -36
  131. package/lib/core/walk.js +0 -27
  132. package/lib/core-api/index.js +0 -39
  133. package/lib/load/check-reserved-filename.js +0 -10
  134. package/lib/load/load-config-files.js +0 -22
  135. package/lib/load/require-file-parse.js +0 -15
  136. package/lib/middlewares/boom/defaults.json +0 -5
  137. package/lib/middlewares/boom/index.js +0 -147
  138. package/lib/middlewares/cors/index.js +0 -66
  139. package/lib/middlewares/cron/defaults.json +0 -5
  140. package/lib/middlewares/cron/index.js +0 -43
  141. package/lib/middlewares/favicon/defaults.json +0 -7
  142. package/lib/middlewares/favicon/index.js +0 -32
  143. package/lib/middlewares/gzip/defaults.json +0 -6
  144. package/lib/middlewares/gzip/index.js +0 -19
  145. package/lib/middlewares/helmet/defaults.json +0 -18
  146. package/lib/middlewares/helmet/index.js +0 -9
  147. package/lib/middlewares/ip/defaults.json +0 -7
  148. package/lib/middlewares/ip/index.js +0 -25
  149. package/lib/middlewares/language/defaults.json +0 -9
  150. package/lib/middlewares/language/index.js +0 -40
  151. package/lib/middlewares/logger/defaults.json +0 -5
  152. package/lib/middlewares/logger/index.js +0 -37
  153. package/lib/middlewares/parser/defaults.json +0 -11
  154. package/lib/middlewares/parser/index.js +0 -71
  155. package/lib/middlewares/poweredBy/defaults.json +0 -5
  156. package/lib/middlewares/poweredBy/index.js +0 -16
  157. package/lib/middlewares/public/defaults.json +0 -8
  158. package/lib/middlewares/responseTime/defaults.json +0 -5
  159. package/lib/middlewares/responseTime/index.js +0 -25
  160. package/lib/middlewares/responses/defaults.json +0 -5
  161. package/lib/middlewares/responses/index.js +0 -18
  162. package/lib/middlewares/router/defaults.json +0 -7
  163. package/lib/middlewares/router/index.js +0 -64
  164. package/lib/middlewares/router/utils/composeEndpoint.js +0 -25
  165. package/lib/middlewares/router/utils/routerChecker.js +0 -92
  166. package/lib/utils/get-prefixed-dependencies.js +0 -7
@@ -6,7 +6,7 @@ const chalk = require('chalk');
6
6
  const inquirer = require('inquirer');
7
7
 
8
8
  // All directories that a template could need
9
- const TEMPLATE_CONTENT = ['api', 'components', 'config/functions/bootstrap.js', 'data'];
9
+ const TEMPLATE_CONTENT = ['src', 'data'];
10
10
 
11
11
  /**
12
12
  *
@@ -54,10 +54,9 @@ async function writeTemplateJson(rootPath) {
54
54
  * @returns boolean
55
55
  */
56
56
  async function templateConfigExists(rootPath) {
57
- const jsonConfig = await fse.pathExists(join(rootPath, 'template.json'));
58
- const functionConfig = await fse.pathExists(join(rootPath, 'template.js'));
59
-
60
- return jsonConfig || functionConfig;
57
+ const configExists = await fse.pathExists(join(rootPath, 'template.json'));
58
+ console.log(`checking: ${join(rootPath, 'template.json')}. result ${configExists}`);
59
+ return configExists;
61
60
  }
62
61
 
63
62
  module.exports = async function generateTemplate(directory) {
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ const CLITable = require('cli-table3');
4
+ const chalk = require('chalk');
5
+
6
+ const strapi = require('../../index');
7
+
8
+ module.exports = async function() {
9
+ const app = await strapi().register();
10
+
11
+ const list = app.container.get('hooks').keys();
12
+
13
+ const infoTable = new CLITable({
14
+ head: [chalk.blue('Name')],
15
+ });
16
+
17
+ list.forEach(name => infoTable.push([name]));
18
+
19
+ console.log(infoTable.toString());
20
+
21
+ await app.destroy();
22
+ };
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ const CLITable = require('cli-table3');
4
+ const chalk = require('chalk');
5
+
6
+ const strapi = require('../../index');
7
+
8
+ module.exports = async function() {
9
+ const app = await strapi().register();
10
+
11
+ const list = app.container.get('middlewares').keys();
12
+
13
+ const infoTable = new CLITable({
14
+ head: [chalk.blue('Name')],
15
+ });
16
+
17
+ list.forEach(name => infoTable.push([name]));
18
+
19
+ console.log(infoTable.toString());
20
+
21
+ await app.destroy();
22
+ };
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ const { generateNewApp } = require('@strapi/generate-new');
4
+
3
5
  /**
4
6
  * `$ strapi new`
5
7
  *
@@ -7,5 +9,5 @@
7
9
  */
8
10
 
9
11
  module.exports = function(...args) {
10
- return require('@strapi/generate-new')(...args);
12
+ return generateNewApp(...args);
11
13
  };
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ const CLITable = require('cli-table3');
4
+ const chalk = require('chalk');
5
+
6
+ const strapi = require('../../index');
7
+
8
+ module.exports = async function() {
9
+ const app = await strapi().register();
10
+
11
+ const list = app.container.get('policies').keys();
12
+
13
+ const infoTable = new CLITable({
14
+ head: [chalk.blue('Name')],
15
+ });
16
+
17
+ list.forEach(name => infoTable.push([name]));
18
+
19
+ console.log(infoTable.toString());
20
+
21
+ await app.destroy();
22
+ };
@@ -0,0 +1,28 @@
1
+ 'use strict';
2
+
3
+ const CLITable = require('cli-table3');
4
+ const chalk = require('chalk');
5
+ const { toUpper } = require('lodash/fp');
6
+
7
+ const strapi = require('../../index');
8
+
9
+ module.exports = async function() {
10
+ const app = await strapi().load();
11
+
12
+ const list = app.server.listRoutes();
13
+
14
+ const infoTable = new CLITable({
15
+ head: [chalk.blue('Method'), chalk.blue('Path')],
16
+ colWidths: [20],
17
+ });
18
+
19
+ list
20
+ .filter(route => route.methods.length)
21
+ .forEach(route => {
22
+ infoTable.push([route.methods.map(toUpper).join('|'), route.path]);
23
+ });
24
+
25
+ console.log(infoTable.toString());
26
+
27
+ await app.destroy();
28
+ };
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ const CLITable = require('cli-table3');
4
+ const chalk = require('chalk');
5
+
6
+ const strapi = require('../../index');
7
+
8
+ module.exports = async function() {
9
+ const app = await strapi().register();
10
+
11
+ const list = app.container.get('services').keys();
12
+
13
+ const infoTable = new CLITable({
14
+ head: [chalk.blue('Name')],
15
+ });
16
+
17
+ list.forEach(name => infoTable.push([name]));
18
+
19
+ console.log(infoTable.toString());
20
+
21
+ await app.destroy();
22
+ };
@@ -1,32 +1,42 @@
1
1
  'use strict';
2
2
 
3
- // eslint-disable-next-line node/no-extraneous-require
4
3
  const strapiAdmin = require('@strapi/admin');
5
4
  const { getConfigUrls, getAbsoluteServerUrl } = require('@strapi/utils');
6
- const loadConfiguration = require('../core/app-configuration');
5
+
7
6
  const ee = require('../utils/ee');
8
7
  const addSlash = require('../utils/addSlash');
8
+ const strapi = require('../index');
9
+ const getEnabledPlugins = require('../core/loaders/plugins/get-enabled-plugins');
9
10
 
10
11
  module.exports = async function({ browser }) {
11
12
  const dir = process.cwd();
12
13
 
13
- const config = loadConfiguration(dir);
14
+ const strapiInstance = strapi({
15
+ dir,
16
+ autoReload: true,
17
+ serveAdminPanel: false,
18
+ });
19
+
20
+ const plugins = await getEnabledPlugins(strapiInstance);
21
+
22
+ const { adminPath } = getConfigUrls(strapiInstance.config, true);
14
23
 
15
- const { adminPath } = getConfigUrls(config.get('server'), true);
24
+ const adminPort = strapiInstance.config.get('admin.port', 8000);
25
+ const adminHost = strapiInstance.config.get('admin.host', 'localhost');
26
+ const adminWatchIgnoreFiles = strapiInstance.config.get('admin.watchIgnoreFiles', []);
16
27
 
17
- const adminPort = config.get('server.admin.port', 8000);
18
- const adminHost = config.get('server.admin.host', 'localhost');
19
- const adminWatchIgnoreFiles = config.get('server.admin.watchIgnoreFiles', []);
28
+ const backendURL = getAbsoluteServerUrl(strapiInstance.config, true);
20
29
 
21
30
  ee({ dir });
22
31
 
23
32
  strapiAdmin.watchAdmin({
24
33
  dir,
34
+ plugins,
25
35
  port: adminPort,
26
36
  host: adminHost,
27
37
  browser,
28
38
  options: {
29
- backend: getAbsoluteServerUrl(config, true),
39
+ backend: backendURL,
30
40
  adminPath: addSlash(adminPath),
31
41
  watchIgnoreFiles: adminWatchIgnoreFiles,
32
42
  features: ee.isEE ? ee.features.getEnabled() : [],
package/lib/container.js CHANGED
@@ -1,16 +1,16 @@
1
1
  'use strict';
2
2
 
3
3
  const createContainer = strapi => {
4
- const registerd = new Map();
4
+ const registered = new Map();
5
5
  const resolved = new Map();
6
6
 
7
7
  return {
8
8
  register(name, resolver) {
9
- if (registerd.has(name)) {
9
+ if (registered.has(name)) {
10
10
  throw new Error(`Cannot register already registered service ${name}`);
11
11
  }
12
12
 
13
- registerd.set(name, resolver);
13
+ registered.set(name, resolver);
14
14
  return this;
15
15
  },
16
16
 
@@ -20,8 +20,8 @@ const createContainer = strapi => {
20
20
  return resolved.get(name);
21
21
  }
22
22
 
23
- if (registerd.has(name)) {
24
- const resolver = registerd.get(name);
23
+ if (registered.has(name)) {
24
+ const resolver = registered.get(name);
25
25
 
26
26
  if (typeof resolver === 'function') {
27
27
  resolved.set(name, resolver({ strapi }, args));
@@ -32,7 +32,7 @@ const createContainer = strapi => {
32
32
  return resolved.get(name);
33
33
  }
34
34
 
35
- throw new Error(`Could not resovle service ${name}`);
35
+ throw new Error(`Could not resolve service ${name}`);
36
36
  },
37
37
 
38
38
  // TODO: implement
@@ -2,7 +2,7 @@
2
2
 
3
3
  const path = require('path');
4
4
  const fs = require('fs');
5
- const { templateConfiguration, env } = require('@strapi/utils');
5
+ const loadFile = require('./load-config-file');
6
6
 
7
7
  module.exports = dir => {
8
8
  if (!fs.existsSync(dir)) return {};
@@ -18,39 +18,3 @@ module.exports = dir => {
18
18
  return acc;
19
19
  }, {});
20
20
  };
21
-
22
- const loadFile = file => {
23
- const ext = path.extname(file);
24
-
25
- switch (ext) {
26
- case '.js':
27
- return loadJsFile(file);
28
- case '.json':
29
- return loadJSONFile(file);
30
- default:
31
- return {};
32
- }
33
- };
34
-
35
- const loadJsFile = file => {
36
- try {
37
- const jsModule = require(file);
38
-
39
- // call if function
40
- if (typeof jsModule === 'function') {
41
- return jsModule({ env });
42
- }
43
-
44
- return jsModule;
45
- } catch (error) {
46
- throw new Error(`Could not load js config file ${file}: ${error.message}`);
47
- }
48
- };
49
-
50
- const loadJSONFile = file => {
51
- try {
52
- return templateConfiguration(JSON.parse(fs.readFileSync(file)));
53
- } catch (error) {
54
- throw new Error(`Could not load json config file ${file}: ${error.message}`);
55
- }
56
- };
@@ -3,35 +3,17 @@
3
3
  const os = require('os');
4
4
  const path = require('path');
5
5
  const _ = require('lodash');
6
+ const { omit } = require('lodash/fp');
6
7
  const dotenv = require('dotenv');
7
8
 
8
9
  dotenv.config({ path: process.env.ENV_PATH });
9
10
 
10
11
  process.env.NODE_ENV = process.env.NODE_ENV || 'development';
11
12
 
12
- const getPrefixedDeps = require('../../utils/get-prefixed-dependencies');
13
- const loadPolicies = require('../load-policies');
14
- const loadFunctions = require('../load-functions');
15
13
  const loadConfigDir = require('./config-loader');
16
- const createConfigProvider = require('./config-provider');
17
14
 
18
15
  const { version: strapiVersion } = require(path.join(__dirname, '../../../package.json'));
19
16
 
20
- const CONFIG_PATHS = {
21
- admin: 'admin',
22
- api: 'api',
23
- config: 'config',
24
- controllers: 'controllers',
25
- models: 'models',
26
- plugins: 'plugins',
27
- policies: 'policies',
28
- tmp: '.tmp',
29
- services: 'services',
30
- static: 'public',
31
- validators: 'validators',
32
- views: 'views',
33
- };
34
-
35
17
  const defaultConfig = {
36
18
  server: {
37
19
  host: process.env.HOST || os.hostname() || 'localhost',
@@ -41,23 +23,11 @@ const defaultConfig = {
41
23
  admin: { autoOpen: false },
42
24
  },
43
25
  admin: {},
44
- middleware: {
45
- timeout: 1000,
46
- load: {
47
- before: ['responseTime', 'logger', 'cors', 'responses', 'gzip'],
48
- order: [],
49
- after: ['parser', 'router'],
26
+ api: {
27
+ rest: {
28
+ prefix: '/api',
50
29
  },
51
- settings: {},
52
30
  },
53
- hook: {
54
- timeout: 1000,
55
- load: { before: [], order: [], after: [] },
56
- settings: {},
57
- },
58
- routes: {},
59
- functions: {},
60
- policies: {},
61
31
  };
62
32
 
63
33
  module.exports = (dir, initialConfig = {}) => {
@@ -69,8 +39,6 @@ module.exports = (dir, initialConfig = {}) => {
69
39
 
70
40
  const rootConfig = {
71
41
  launchedAt: Date.now(),
72
- appPath: dir,
73
- paths: CONFIG_PATHS,
74
42
  serveAdminPanel,
75
43
  autoReload,
76
44
  environment: process.env.NODE_ENV,
@@ -80,20 +48,12 @@ module.exports = (dir, initialConfig = {}) => {
80
48
  ...pkgJSON,
81
49
  strapi: strapiVersion,
82
50
  },
83
- installedPlugins: getPrefixedDeps('@strapi/plugin', pkgJSON),
84
- installedMiddlewares: getPrefixedDeps('@strapi/middleware', pkgJSON),
85
- installedHooks: getPrefixedDeps('@strapi/hook', pkgJSON),
86
- installedProviders: getPrefixedDeps('@strapi/provider', pkgJSON),
87
51
  };
88
52
 
89
- const baseConfig = {
90
- ...loadConfigDir(configDir),
91
- policies: loadPolicies(path.resolve(configDir, 'policies')),
92
- functions: loadFunctions(path.resolve(configDir, 'functions')),
93
- };
53
+ const baseConfig = omit('plugins', loadConfigDir(configDir)); // plugin config will be loaded later
94
54
 
95
55
  const envDir = path.resolve(configDir, 'env', process.env.NODE_ENV);
96
56
  const envConfig = loadConfigDir(envDir);
97
57
 
98
- return createConfigProvider(_.merge(rootConfig, defaultConfig, baseConfig, envConfig));
58
+ return _.merge(rootConfig, defaultConfig, baseConfig, envConfig);
99
59
  };
@@ -0,0 +1,43 @@
1
+ 'use strict';
2
+
3
+ const path = require('path');
4
+ const fs = require('fs');
5
+ const { templateConfiguration, env } = require('@strapi/utils');
6
+
7
+ const loadJsFile = file => {
8
+ try {
9
+ const jsModule = require(file);
10
+
11
+ // call if function
12
+ if (typeof jsModule === 'function') {
13
+ return jsModule({ env });
14
+ }
15
+
16
+ return jsModule;
17
+ } catch (error) {
18
+ throw new Error(`Could not load js config file ${file}: ${error.message}`);
19
+ }
20
+ };
21
+
22
+ const loadJSONFile = file => {
23
+ try {
24
+ return templateConfiguration(JSON.parse(fs.readFileSync(file)));
25
+ } catch (error) {
26
+ throw new Error(`Could not load json config file ${file}: ${error.message}`);
27
+ }
28
+ };
29
+
30
+ const loadFile = file => {
31
+ const ext = path.extname(file);
32
+
33
+ switch (ext) {
34
+ case '.js':
35
+ return loadJsFile(file);
36
+ case '.json':
37
+ return loadJSONFile(file);
38
+ default:
39
+ return {};
40
+ }
41
+ };
42
+
43
+ module.exports = loadFile;
@@ -1,124 +1,12 @@
1
1
  'use strict';
2
2
 
3
- const _ = require('lodash');
4
- const { getConfigUrls, contentTypes: contentTypesUtils } = require('@strapi/utils');
3
+ const { getConfigUrls } = require('@strapi/utils');
5
4
 
6
- const { createCoreApi } = require('../core-api');
7
-
8
- module.exports = function(strapi) {
9
- strapi.contentTypes = {};
10
-
11
- // Set models.
12
- strapi.models = Object.keys(strapi.api || []).reduce((acc, apiName) => {
13
- const api = strapi.api[apiName];
14
-
15
- for (let modelName in api.models) {
16
- let model = strapi.api[apiName].models[modelName];
17
-
18
- // mutate model
19
- contentTypesUtils.createContentType(model, { modelName }, { apiName });
20
-
21
- strapi.contentTypes[model.uid] = model;
22
-
23
- const { service, controller } = createCoreApi({ model, api, strapi });
24
-
25
- _.set(strapi.api[apiName], ['services', modelName], service);
26
- _.set(strapi.api[apiName], ['controllers', modelName], controller);
27
-
28
- acc[modelName] = model;
29
- }
30
- return acc;
31
- }, {});
32
-
33
- // Set controllers.
34
- strapi.controllers = Object.keys(strapi.api || []).reduce((acc, key) => {
35
- for (let index in strapi.api[key].controllers) {
36
- let controller = strapi.api[key].controllers[index];
37
- controller.identity = controller.identity || _.upperFirst(index);
38
- acc[index] = controller;
39
- }
40
-
41
- return acc;
42
- }, {});
43
-
44
- // Set services.
45
- strapi.services = Object.keys(strapi.api || []).reduce((acc, key) => {
46
- for (let index in strapi.api[key].services) {
47
- acc[index] = strapi.api[key].services[index];
48
- }
49
-
50
- return acc;
51
- }, {});
52
-
53
- // Set routes.
54
- strapi.config.routes = Object.keys(strapi.api || []).reduce((acc, key) => {
55
- return acc.concat(_.get(strapi.api[key], 'config.routes') || {});
56
- }, []);
57
-
58
- // Init admin controllers.
59
- Object.keys(strapi.admin.controllers || []).forEach(key => {
60
- if (!strapi.admin.controllers[key].identity) {
61
- strapi.admin.controllers[key].identity = key;
62
- }
63
- });
64
-
65
- // Init admin models.
66
- Object.keys(strapi.admin.models || []).forEach(modelName => {
67
- let model = strapi.admin.models[modelName];
68
-
69
- // mutate model
70
- contentTypesUtils.createContentType(model, { modelName });
71
-
72
- strapi.contentTypes[model.uid] = model;
73
- });
74
-
75
- Object.keys(strapi.plugins).forEach(pluginName => {
76
- let plugin = strapi.plugins[pluginName];
77
- Object.assign(plugin, {
78
- controllers: plugin.controllers || [],
79
- services: plugin.services || [],
80
- models: plugin.models || [],
81
- });
82
-
83
- Object.keys(plugin.controllers).forEach(key => {
84
- let controller = plugin.controllers[key];
85
-
86
- Object.assign(controller, {
87
- identity: controller.identity || key,
88
- });
89
- });
90
-
91
- Object.keys(plugin.models || []).forEach(modelName => {
92
- let model = plugin.models[modelName];
93
-
94
- // mutate model
95
- contentTypesUtils.createContentType(model, { modelName }, { pluginName });
96
-
97
- strapi.contentTypes[model.uid] = model;
98
- });
99
- });
100
-
101
- // Preset config in alphabetical order.
102
- strapi.config.middleware.settings = Object.keys(strapi.middleware).reduce((acc, current) => {
103
- // Try to find the settings in the current environment, then in the main configurations.
104
- const currentSettings = _.merge(
105
- _.cloneDeep(_.get(strapi.middleware[current], ['defaults', current], {})),
106
- strapi.config.get(['middleware', 'settings', current], {})
107
- );
108
-
109
- acc[current] = !_.isObject(currentSettings) ? {} : currentSettings;
110
-
111
- // Ensure that enabled key exist by forcing to false.
112
- _.defaults(acc[current], { enabled: false });
113
-
114
- return acc;
115
- }, {});
116
-
117
- // default settings
5
+ module.exports = function({ strapi }) {
118
6
  strapi.config.port = strapi.config.get('server.port') || strapi.config.port;
119
7
  strapi.config.host = strapi.config.get('server.host') || strapi.config.host;
120
8
 
121
- const { serverUrl, adminUrl, adminPath } = getConfigUrls(strapi.config.get('server'));
9
+ const { serverUrl, adminUrl, adminPath } = getConfigUrls(strapi.config);
122
10
 
123
11
  strapi.config.server = strapi.config.server || {};
124
12
  strapi.config.server.url = serverUrl;
@@ -127,8 +15,8 @@ module.exports = function(strapi) {
127
15
 
128
16
  // check if we should serve admin panel
129
17
  const shouldServeAdmin = strapi.config.get(
130
- 'server.admin.serveAdminPanel',
131
- strapi.config.serveAdminPanel
18
+ 'admin.serveAdminPanel',
19
+ strapi.config.get('serveAdminPanel')
132
20
  );
133
21
 
134
22
  if (!shouldServeAdmin) {
@@ -0,0 +1,24 @@
1
+ 'use strict';
2
+
3
+ const { cloneDeep, camelCase } = require('lodash/fp');
4
+ const { validateComponentDefinition } = require('./validator');
5
+
6
+ const createComponent = (definition = {}) => {
7
+ validateComponentDefinition(definition);
8
+
9
+ const createdComponent = cloneDeep(definition);
10
+ const category = camelCase(definition.info.category);
11
+
12
+ const uid = `${category}.${definition.info.singularModelName}`;
13
+
14
+ Object.assign(createdComponent, {
15
+ uid,
16
+ category,
17
+ });
18
+
19
+ return createdComponent;
20
+ };
21
+
22
+ module.exports = {
23
+ createComponent,
24
+ };
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ const { yup } = require('@strapi/utils');
4
+
5
+ const componentSchemaValidator = () =>
6
+ yup.object().shape({
7
+ info: yup
8
+ .object()
9
+ .shape({
10
+ singularName: yup
11
+ .string()
12
+ .isCamelCase()
13
+ .required(),
14
+ pluralName: yup
15
+ .string()
16
+ .isCamelCase()
17
+ .required(),
18
+ displayName: yup.string().required(),
19
+ })
20
+ .required(),
21
+ });
22
+
23
+ const validateComponentDefinition = data => {
24
+ return componentSchemaValidator.validateSync(data, { strict: true, abortEarly: false });
25
+ };
26
+
27
+ module.exports = {
28
+ validateComponentDefinition,
29
+ };