@strapi/strapi 4.10.0-beta.1 → 4.10.1-experimental.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 (193) hide show
  1. package/bin/strapi.js +2 -468
  2. package/coverage/clover.xml +1613 -0
  3. package/coverage/coverage-final.json +48 -0
  4. package/coverage/lcov-report/base.css +224 -0
  5. package/coverage/lcov-report/block-navigation.js +87 -0
  6. package/coverage/lcov-report/commands/__tests__/data-transfer/shared/index.html +116 -0
  7. package/coverage/lcov-report/commands/__tests__/data-transfer/shared/transfer.test.utils.js.html +133 -0
  8. package/coverage/lcov-report/commands/admin-create.js.html +424 -0
  9. package/coverage/lcov-report/commands/admin-reset.js.html +241 -0
  10. package/coverage/lcov-report/commands/generate-template.js.html +373 -0
  11. package/coverage/lcov-report/commands/index.html +146 -0
  12. package/coverage/lcov-report/commands/transfer/export.js.html +619 -0
  13. package/coverage/lcov-report/commands/transfer/import.js.html +562 -0
  14. package/coverage/lcov-report/commands/transfer/index.html +146 -0
  15. package/coverage/lcov-report/commands/transfer/transfer.js.html +532 -0
  16. package/coverage/lcov-report/commands/utils/helpers.js.html +430 -0
  17. package/coverage/lcov-report/commands/utils/index.html +116 -0
  18. package/coverage/lcov-report/core/registries/custom-fields.js.html +301 -0
  19. package/coverage/lcov-report/core/registries/index.html +116 -0
  20. package/coverage/lcov-report/core-api/controller/collection-type.js.html +418 -0
  21. package/coverage/lcov-report/core-api/controller/index.html +161 -0
  22. package/coverage/lcov-report/core-api/controller/index.js.html +220 -0
  23. package/coverage/lcov-report/core-api/controller/single-type.js.html +274 -0
  24. package/coverage/lcov-report/core-api/controller/transform.js.html +376 -0
  25. package/coverage/lcov-report/core-api/service/collection-type.js.html +325 -0
  26. package/coverage/lcov-report/core-api/service/index.html +161 -0
  27. package/coverage/lcov-report/core-api/service/index.js.html +220 -0
  28. package/coverage/lcov-report/core-api/service/pagination.js.html +460 -0
  29. package/coverage/lcov-report/core-api/service/single-type.js.html +301 -0
  30. package/coverage/lcov-report/favicon.png +0 -0
  31. package/coverage/lcov-report/index.html +386 -0
  32. package/coverage/lcov-report/load/filepath-to-prop-path.js.html +151 -0
  33. package/coverage/lcov-report/load/index.html +116 -0
  34. package/coverage/lcov-report/prettify.css +1 -0
  35. package/coverage/lcov-report/prettify.js +2 -0
  36. package/coverage/lcov-report/services/content-api/index.html +116 -0
  37. package/coverage/lcov-report/services/content-api/index.js.html +307 -0
  38. package/coverage/lcov-report/services/content-api/permissions/engine.js.html +100 -0
  39. package/coverage/lcov-report/services/content-api/permissions/index.html +131 -0
  40. package/coverage/lcov-report/services/content-api/permissions/index.js.html +529 -0
  41. package/coverage/lcov-report/services/content-api/permissions/providers/action.js.html +142 -0
  42. package/coverage/lcov-report/services/content-api/permissions/providers/condition.js.html +142 -0
  43. package/coverage/lcov-report/services/content-api/permissions/providers/index.html +146 -0
  44. package/coverage/lcov-report/services/content-api/permissions/providers/index.js.html +112 -0
  45. package/coverage/lcov-report/services/core-store.js.html +520 -0
  46. package/coverage/lcov-report/services/entity-service/attributes/index.html +131 -0
  47. package/coverage/lcov-report/services/entity-service/attributes/index.js.html +178 -0
  48. package/coverage/lcov-report/services/entity-service/attributes/transforms.js.html +145 -0
  49. package/coverage/lcov-report/services/entity-service/components.js.html +1246 -0
  50. package/coverage/lcov-report/services/entity-service/index.html +146 -0
  51. package/coverage/lcov-report/services/entity-service/index.js.html +1120 -0
  52. package/coverage/lcov-report/services/entity-service/params.js.html +112 -0
  53. package/coverage/lcov-report/services/entity-validator/__tests__/relations/utils/index.html +116 -0
  54. package/coverage/lcov-report/services/entity-validator/__tests__/relations/utils/relations.testdata.js.html +544 -0
  55. package/coverage/lcov-report/services/entity-validator/index.html +131 -0
  56. package/coverage/lcov-report/services/entity-validator/index.js.html +1231 -0
  57. package/coverage/lcov-report/services/entity-validator/validators.js.html +733 -0
  58. package/coverage/lcov-report/services/event-hub.js.html +319 -0
  59. package/coverage/lcov-report/services/fs.js.html +259 -0
  60. package/coverage/lcov-report/services/index.html +161 -0
  61. package/coverage/lcov-report/services/metrics/admin-user-hash.js.html +148 -0
  62. package/coverage/lcov-report/services/metrics/index.html +206 -0
  63. package/coverage/lcov-report/services/metrics/index.js.html +265 -0
  64. package/coverage/lcov-report/services/metrics/is-truthy.js.html +112 -0
  65. package/coverage/lcov-report/services/metrics/middleware.js.html +184 -0
  66. package/coverage/lcov-report/services/metrics/rate-limiter.js.html +166 -0
  67. package/coverage/lcov-report/services/metrics/sender.js.html +394 -0
  68. package/coverage/lcov-report/services/metrics/stringify-deep.js.html +151 -0
  69. package/coverage/lcov-report/services/utils/index.html +116 -0
  70. package/coverage/lcov-report/services/utils/upload-files.js.html +322 -0
  71. package/coverage/lcov-report/services/worker-queue.js.html +262 -0
  72. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  73. package/coverage/lcov-report/sorter.js +196 -0
  74. package/coverage/lcov-report/utils/convert-custom-field-type.js.html +151 -0
  75. package/coverage/lcov-report/utils/index.html +146 -0
  76. package/coverage/lcov-report/utils/machine-id.js.html +127 -0
  77. package/coverage/lcov-report/utils/url-from-segments.js.html +121 -0
  78. package/ee/LICENSE.txt +21 -0
  79. package/ee/index.js +3 -1
  80. package/ee/license.js +8 -7
  81. package/lib/Strapi.js +3 -0
  82. package/lib/commands/__tests__/commands.test.js +20 -0
  83. package/lib/commands/__tests__/commands.test.utils.js +16 -0
  84. package/lib/commands/actions/admin/create-user/__tests__/admin.create-user.test.js +450 -0
  85. package/lib/commands/{admin-create.js → actions/admin/create-user/action.js} +2 -2
  86. package/lib/commands/actions/admin/create-user/command.js +19 -0
  87. package/lib/commands/actions/admin/reset-user-password/__tests__/admin.reset-user-password.test.js +145 -0
  88. package/lib/commands/{admin-reset.js → actions/admin/reset-user-password/action.js} +2 -2
  89. package/lib/commands/actions/admin/reset-user-password/command.js +17 -0
  90. package/lib/commands/{build.js → actions/build/action.js} +2 -2
  91. package/lib/commands/actions/build/command.js +15 -0
  92. package/lib/commands/{configurationDump.js → actions/configuration/dump/action.js} +1 -1
  93. package/lib/commands/actions/configuration/dump/command.js +17 -0
  94. package/lib/commands/{configurationRestore.js → actions/configuration/restore/action.js} +1 -1
  95. package/lib/commands/actions/configuration/restore/command.js +17 -0
  96. package/lib/commands/{console.js → actions/console/action.js} +2 -2
  97. package/lib/commands/actions/console/command.js +14 -0
  98. package/lib/commands/{content-types/list.js → actions/content-types/list/action.js} +2 -2
  99. package/lib/commands/actions/content-types/list/command.js +14 -0
  100. package/lib/commands/{controllers/list.js → actions/controllers/list/action.js} +2 -2
  101. package/lib/commands/actions/controllers/list/command.js +14 -0
  102. package/lib/commands/{develop.js → actions/develop/action.js} +3 -3
  103. package/lib/commands/actions/develop/command.js +19 -0
  104. package/lib/commands/actions/export/__tests__/export.test.js +175 -0
  105. package/lib/commands/{transfer/export.js → actions/export/action.js} +3 -2
  106. package/lib/commands/actions/export/command.js +45 -0
  107. package/lib/commands/actions/generate/command.js +18 -0
  108. package/lib/commands/{hooks/list.js → actions/hooks/list/action.js} +2 -2
  109. package/lib/commands/actions/hooks/list/command.js +14 -0
  110. package/lib/commands/actions/import/__tests__/import.test.js +143 -0
  111. package/lib/commands/{transfer/import.js → actions/import/action.js} +2 -2
  112. package/lib/commands/actions/import/command.js +97 -0
  113. package/lib/commands/{install.js → actions/install/action.js} +1 -1
  114. package/lib/commands/actions/install/command.js +14 -0
  115. package/lib/commands/{middlewares/list.js → actions/middlewares/list/action.js} +2 -2
  116. package/lib/commands/actions/middlewares/list/command.js +14 -0
  117. package/lib/commands/{new.js → actions/new/action.js} +1 -1
  118. package/lib/commands/actions/new/command.js +35 -0
  119. package/lib/commands/{policies/list.js → actions/policies/list/action.js} +2 -2
  120. package/lib/commands/actions/policies/list/command.js +14 -0
  121. package/lib/commands/{report.js → actions/report/action.js} +1 -1
  122. package/lib/commands/actions/report/command.js +17 -0
  123. package/lib/commands/{routes/list.js → actions/routes/list/action.js} +2 -2
  124. package/lib/commands/actions/routes/list/command.js +14 -0
  125. package/lib/commands/{services/list.js → actions/services/list/action.js} +2 -2
  126. package/lib/commands/actions/services/list/command.js +14 -0
  127. package/lib/commands/{start.js → actions/start/action.js} +1 -1
  128. package/lib/commands/actions/start/command.js +14 -0
  129. package/lib/commands/{opt-out-telemetry.js → actions/telemetry/disable/action.js} +1 -1
  130. package/lib/commands/actions/telemetry/disable/command.js +14 -0
  131. package/lib/commands/{opt-in-telemetry.js → actions/telemetry/enable/action.js} +1 -1
  132. package/lib/commands/actions/telemetry/enable/command.js +14 -0
  133. package/lib/commands/actions/templates/generate/__tests__/templates.generate.js +118 -0
  134. package/lib/commands/actions/templates/generate/command.js +14 -0
  135. package/lib/commands/actions/transfer/__tests__/transfer.test.js +178 -0
  136. package/lib/commands/{transfer/transfer.js → actions/transfer/action.js} +2 -2
  137. package/lib/commands/actions/transfer/command.js +115 -0
  138. package/lib/commands/{ts/generate-types.js → actions/ts/generate-types/action.js} +2 -2
  139. package/lib/commands/actions/ts/generate-types/command.js +21 -0
  140. package/lib/commands/{uninstall.js → actions/uninstall/action.js} +1 -1
  141. package/lib/commands/actions/uninstall/command.js +15 -0
  142. package/lib/commands/actions/version/command.js +19 -0
  143. package/lib/commands/{watchAdmin.js → actions/watch-admin/action.js} +4 -4
  144. package/lib/commands/actions/watch-admin/command.js +15 -0
  145. package/lib/commands/index.js +66 -0
  146. package/lib/commands/{transfer/utils.js → utils/data-transfer.js} +2 -2
  147. package/lib/commands/utils/helpers.js +54 -3
  148. package/lib/core/registries/__tests__/custom-fields.test.js +152 -0
  149. package/lib/core/registries/custom-fields.js +19 -2
  150. package/lib/core-api/__tests__/controller.test.js +39 -0
  151. package/lib/core-api/controller/__tests__/transform.test.js +226 -0
  152. package/lib/core-api/service/__tests__/index.test.js +127 -0
  153. package/lib/core-api/service/__tests__/pagination.test.js +275 -0
  154. package/lib/load/__tests__/filepath-to-prop-path.test.js +30 -0
  155. package/lib/middlewares/__tests__/errors.test.js +21 -0
  156. package/lib/services/__tests__/content-api-permissions.test.js +291 -0
  157. package/lib/services/__tests__/core-store.test.js +148 -0
  158. package/lib/services/__tests__/event-hub.test.js +126 -0
  159. package/lib/services/__tests__/fs.test.js +78 -0
  160. package/lib/services/__tests__/worker-queue.test.js +47 -0
  161. package/lib/services/entity-service/__tests__/entity-service-events.test.js +117 -0
  162. package/lib/services/entity-service/__tests__/entity-service.test.js +587 -0
  163. package/lib/services/entity-validator/__tests__/biginteger-validators.test.js +220 -0
  164. package/lib/services/entity-validator/__tests__/date-validators.test.js +183 -0
  165. package/lib/services/entity-validator/__tests__/datetime-validators.test.js +183 -0
  166. package/lib/services/entity-validator/__tests__/email-validators.test.js +56 -0
  167. package/lib/services/entity-validator/__tests__/enumeration-validators.test.js +43 -0
  168. package/lib/services/entity-validator/__tests__/float-validators.test.js +278 -0
  169. package/lib/services/entity-validator/__tests__/index.test.js +609 -0
  170. package/lib/services/entity-validator/__tests__/integer-validators.test.js +278 -0
  171. package/lib/services/entity-validator/__tests__/relations/attribute-level.test.js +123 -0
  172. package/lib/services/entity-validator/__tests__/relations/component-level.test.js +275 -0
  173. package/lib/services/entity-validator/__tests__/relations/dynamic-zone-level.test.js +159 -0
  174. package/lib/services/entity-validator/__tests__/relations/media-level.test.js +74 -0
  175. package/lib/services/entity-validator/__tests__/relations/utils/relations.testdata.js +153 -0
  176. package/lib/services/entity-validator/__tests__/string-validators.test.js +374 -0
  177. package/lib/services/entity-validator/__tests__/time-validators.test.js +183 -0
  178. package/lib/services/entity-validator/__tests__/timestamp-validators.test.js +204 -0
  179. package/lib/services/entity-validator/__tests__/uid-validators.test.js +229 -0
  180. package/lib/services/metrics/__tests__/admin-user-hash.test.js +41 -0
  181. package/lib/services/metrics/__tests__/index.test.js +157 -0
  182. package/lib/services/metrics/__tests__/is-truthy.js +33 -0
  183. package/lib/services/metrics/__tests__/middleware.test.js +60 -0
  184. package/lib/services/metrics/__tests__/rate-limiter.test.js +50 -0
  185. package/lib/services/metrics/__tests__/stringify-deep.test.js +27 -0
  186. package/lib/services/metrics/sender.js +1 -2
  187. package/lib/services/webhook-runner.js +4 -4
  188. package/lib/types/core/commands/index.d.ts +6 -0
  189. package/lib/utils/__tests__/convert-custom-field-type.test.js +69 -0
  190. package/lib/utils/__tests__/url-from-segments.test.js +40 -0
  191. package/lib/utils/fetch.js +23 -0
  192. package/package.json +17 -16
  193. /package/lib/commands/{generate-template.js → actions/templates/generate/action.js} +0 -0
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const fs = require('fs');
4
- const strapi = require('../index');
4
+ const strapi = require('../../../../index');
5
5
 
6
6
  const CHUNK_SIZE = 100;
7
7
 
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ const { getLocalScript } = require('../../../utils/helpers');
4
+
5
+ /**
6
+ * `$ strapi configuration:dump`
7
+ * @param {import('../../../../types/core/commands').AddCommandOptions} options
8
+ */
9
+ module.exports = ({ command }) => {
10
+ command
11
+ .command('configuration:dump')
12
+ .alias('config:dump')
13
+ .description('Dump configurations of your application')
14
+ .option('-f, --file <file>', 'Output file, default output is stdout')
15
+ .option('-p, --pretty', 'Format the output JSON with indentation and line breaks', false)
16
+ .action(getLocalScript('configuration/dump'));
17
+ };
@@ -3,7 +3,7 @@
3
3
  const fs = require('fs');
4
4
  const _ = require('lodash');
5
5
 
6
- const strapi = require('../index');
6
+ const strapi = require('../../../../index');
7
7
 
8
8
  /**
9
9
  * Will restore configurations. It reads from a file or stdin
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ const { getLocalScript } = require('../../../utils/helpers');
4
+
5
+ /**
6
+ * `$ strapi configuration:restore`
7
+ * @param {import('../../../../types/core/commands').AddCommandOptions} options
8
+ */
9
+ module.exports = ({ command }) => {
10
+ command
11
+ .command('configuration:restore')
12
+ .alias('config:restore')
13
+ .description('Restore configurations of your application')
14
+ .option('-f, --file <file>', 'Input file, default input is stdin')
15
+ .option('-s, --strategy <strategy>', 'Strategy name, one of: "replace", "merge", "keep"')
16
+ .action(getLocalScript('configuration/restore'));
17
+ };
@@ -2,7 +2,7 @@
2
2
 
3
3
  const REPL = require('repl');
4
4
 
5
- const strapi = require('../index');
5
+ const strapi = require('../../../index');
6
6
 
7
7
  /**
8
8
  * `$ strapi console`
@@ -14,7 +14,7 @@ module.exports = async () => {
14
14
  app.start().then(() => {
15
15
  const repl = REPL.start(app.config.info.name + ' > ' || 'strapi > '); // eslint-disable-line prefer-template
16
16
 
17
- repl.on('exit', function (err) {
17
+ repl.on('exit', (err) => {
18
18
  if (err) {
19
19
  app.log.error(err);
20
20
  process.exit(1);
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ const { getLocalScript } = require('../../utils/helpers');
4
+
5
+ /**
6
+ * `$ strapi console`
7
+ * @param {import('../../../types/core/commands').AddCommandOptions} options
8
+ */
9
+ module.exports = ({ command }) => {
10
+ command
11
+ .command('console')
12
+ .description('Open the Strapi framework console')
13
+ .action(getLocalScript('console'));
14
+ };
@@ -3,9 +3,9 @@
3
3
  const CLITable = require('cli-table3');
4
4
  const chalk = require('chalk');
5
5
 
6
- const strapi = require('../../index');
6
+ const strapi = require('../../../../index');
7
7
 
8
- module.exports = async function () {
8
+ module.exports = async () => {
9
9
  const appContext = await strapi.compile();
10
10
  const app = await strapi(appContext).register();
11
11
 
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ const { getLocalScript } = require('../../../utils/helpers');
4
+
5
+ /**
6
+ * `$ strapi content-types:list`
7
+ * @param {import('../../../../types/core/commands').AddCommandOptions} options
8
+ */
9
+ module.exports = ({ command }) => {
10
+ command
11
+ .command('content-types:list')
12
+ .description('List all the application content-types')
13
+ .action(getLocalScript('content-types/list'));
14
+ };
@@ -3,9 +3,9 @@
3
3
  const CLITable = require('cli-table3');
4
4
  const chalk = require('chalk');
5
5
 
6
- const strapi = require('../../index');
6
+ const strapi = require('../../../../index');
7
7
 
8
- module.exports = async function () {
8
+ module.exports = async () => {
9
9
  const appContext = await strapi.compile();
10
10
  const app = await strapi(appContext).register();
11
11
 
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ const { getLocalScript } = require('../../../utils/helpers');
4
+
5
+ /**
6
+ * `$ strapi controllers:list`
7
+ * @param {import('../../../../types/core/commands').AddCommandOptions} options
8
+ */
9
+ module.exports = ({ command }) => {
10
+ command
11
+ .command('controllers:list')
12
+ .description('List all the application controllers')
13
+ .action(getLocalScript('controllers/list'));
14
+ };
@@ -9,9 +9,9 @@ const { getOr } = require('lodash/fp');
9
9
  const { joinBy } = require('@strapi/utils');
10
10
  const tsUtils = require('@strapi/typescript-utils');
11
11
 
12
- const loadConfiguration = require('../core/app-configuration');
13
- const strapi = require('../index');
14
- const { buildTypeScript, buildAdmin } = require('./builders');
12
+ const loadConfiguration = require('../../../core/app-configuration');
13
+ const strapi = require('../../../index');
14
+ const { buildTypeScript, buildAdmin } = require('../../builders');
15
15
 
16
16
  /**
17
17
  * `$ strapi develop`
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ const { getLocalScript } = require('../../utils/helpers');
4
+
5
+ /**
6
+ * `$ strapi develop`
7
+ * @param {import('../../../types/core/commands').AddCommandOptions} options
8
+ */
9
+ module.exports = ({ command }) => {
10
+ command
11
+ .command('develop')
12
+ .alias('dev')
13
+ .option('--no-build', 'Disable build')
14
+ .option('--watch-admin', 'Enable watch', false)
15
+ .option('--polling', 'Watch for file changes in network directories', false)
16
+ .option('--browser <name>', 'Open the browser', true)
17
+ .description('Start your Strapi application in development mode')
18
+ .action(getLocalScript('develop'));
19
+ };
@@ -0,0 +1,175 @@
1
+ 'use strict';
2
+
3
+ const { expectExit } = require('../../../__tests__/commands.test.utils');
4
+
5
+ describe('Export', () => {
6
+ const defaultFileName = 'defaultFilename';
7
+
8
+ jest.mock('fs-extra', () => ({
9
+ pathExists: jest.fn(() => Promise.resolve(true)),
10
+ }));
11
+
12
+ const mockDataTransfer = {
13
+ file: {
14
+ providers: {
15
+ createLocalFileDestinationProvider: jest.fn().mockReturnValue({ name: 'testDest' }),
16
+ },
17
+ },
18
+ strapi: {
19
+ providers: {
20
+ createLocalStrapiSourceProvider: jest.fn().mockReturnValue({ name: 'testSource' }),
21
+ },
22
+ },
23
+ engine: {
24
+ ...jest.requireActual('@strapi/data-transfer').engine,
25
+ errors: {},
26
+ createTransferEngine() {
27
+ return {
28
+ transfer: jest.fn(() => {
29
+ return {
30
+ engine: {},
31
+ destination: {
32
+ file: {
33
+ path: 'path',
34
+ },
35
+ },
36
+ };
37
+ }),
38
+ progress: {
39
+ on: jest.fn(),
40
+ stream: {
41
+ on: jest.fn(),
42
+ },
43
+ },
44
+ sourceProvider: { name: 'testSource' },
45
+ destinationProvider: { name: 'testDestination' },
46
+ diagnostics: {
47
+ on: jest.fn().mockReturnThis(),
48
+ onDiagnostic: jest.fn().mockReturnThis(),
49
+ },
50
+ };
51
+ },
52
+ },
53
+ };
54
+
55
+ jest.mock('@strapi/data-transfer', () => mockDataTransfer);
56
+
57
+ // command utils
58
+ const mockUtils = {
59
+ getTransferTelemetryPayload: jest.fn().mockReturnValue({}),
60
+ loadersFactory: jest.fn().mockReturnValue({ updateLoader: jest.fn() }),
61
+ formatDiagnostic: jest.fn(),
62
+ createStrapiInstance() {
63
+ return {
64
+ telemetry: {
65
+ send: jest.fn(),
66
+ },
67
+ };
68
+ },
69
+ getDefaultExportName: jest.fn(() => defaultFileName),
70
+ buildTransferTable: jest.fn(() => {
71
+ return {
72
+ toString() {
73
+ return 'table';
74
+ },
75
+ };
76
+ }),
77
+ exitMessageText: jest.fn(),
78
+ };
79
+ jest.mock(
80
+ '../../../utils/data-transfer.js',
81
+ () => {
82
+ return mockUtils;
83
+ },
84
+ { virtual: true }
85
+ );
86
+
87
+ // console spies
88
+ jest.spyOn(console, 'log').mockImplementation(() => {});
89
+ jest.spyOn(console, 'warn').mockImplementation(() => {});
90
+ jest.spyOn(console, 'info').mockImplementation(() => {});
91
+ jest.spyOn(console, 'error').mockImplementation(() => {});
92
+
93
+ // Now that everything is mocked, load the 'export' command
94
+ const exportAction = require('../action');
95
+
96
+ beforeEach(() => {
97
+ jest.clearAllMocks();
98
+ });
99
+
100
+ it('uses path provided by user', async () => {
101
+ const filename = 'test';
102
+
103
+ await expectExit(0, async () => {
104
+ await exportAction({ file: filename });
105
+ });
106
+
107
+ expect(console.error).not.toHaveBeenCalled();
108
+ expect(mockDataTransfer.file.providers.createLocalFileDestinationProvider).toHaveBeenCalledWith(
109
+ expect.objectContaining({
110
+ file: { path: filename },
111
+ })
112
+ );
113
+ expect(mockUtils.getDefaultExportName).not.toHaveBeenCalled();
114
+ });
115
+
116
+ it('uses default path if not provided by user', async () => {
117
+ await expectExit(0, async () => {
118
+ await exportAction({});
119
+ });
120
+
121
+ expect(mockUtils.getDefaultExportName).toHaveBeenCalledTimes(1);
122
+ expect(mockDataTransfer.file.providers.createLocalFileDestinationProvider).toHaveBeenCalledWith(
123
+ expect.objectContaining({
124
+ file: { path: defaultFileName },
125
+ })
126
+ );
127
+ });
128
+
129
+ it('encrypts the output file if specified', async () => {
130
+ const encrypt = true;
131
+ await expectExit(0, async () => {
132
+ await exportAction({ encrypt });
133
+ });
134
+
135
+ expect(mockDataTransfer.file.providers.createLocalFileDestinationProvider).toHaveBeenCalledWith(
136
+ expect.objectContaining({
137
+ encryption: { enabled: encrypt },
138
+ })
139
+ );
140
+ });
141
+
142
+ it('encrypts the output file with the given key', async () => {
143
+ const key = 'secret-key';
144
+ const encrypt = true;
145
+ await expectExit(0, async () => {
146
+ await exportAction({ encrypt, key });
147
+ });
148
+
149
+ expect(mockDataTransfer.file.providers.createLocalFileDestinationProvider).toHaveBeenCalledWith(
150
+ expect.objectContaining({
151
+ encryption: { enabled: encrypt, key },
152
+ })
153
+ );
154
+ });
155
+
156
+ it('uses compress option', async () => {
157
+ await expectExit(0, async () => {
158
+ await exportAction({ compress: false });
159
+ });
160
+
161
+ expect(mockDataTransfer.file.providers.createLocalFileDestinationProvider).toHaveBeenCalledWith(
162
+ expect.objectContaining({
163
+ compression: { enabled: false },
164
+ })
165
+ );
166
+ await expectExit(0, async () => {
167
+ await exportAction({ compress: true });
168
+ });
169
+ expect(mockDataTransfer.file.providers.createLocalFileDestinationProvider).toHaveBeenCalledWith(
170
+ expect.objectContaining({
171
+ compression: { enabled: true },
172
+ })
173
+ );
174
+ });
175
+ });
@@ -25,8 +25,9 @@ const {
25
25
  exitMessageText,
26
26
  abortTransfer,
27
27
  getTransferTelemetryPayload,
28
- } = require('./utils');
29
- const { exitWith } = require('../utils/helpers');
28
+ } = require('../../utils/data-transfer');
29
+ const { exitWith } = require('../../utils/helpers');
30
+
30
31
  /**
31
32
  * @typedef ExportCommandOptions Options given to the CLI import command
32
33
  *
@@ -0,0 +1,45 @@
1
+ 'use strict';
2
+
3
+ const { Option } = require('commander');
4
+ const {
5
+ excludeOption,
6
+ onlyOption,
7
+ throttleOption,
8
+ validateExcludeOnly,
9
+ } = require('../../utils/data-transfer');
10
+ const { promptEncryptionKey } = require('../../utils/commander');
11
+ const { getLocalScript } = require('../../utils/helpers');
12
+
13
+ /**
14
+ * `$ strapi export`
15
+ * @param {import('../../../types/core/commands').AddCommandOptions} options
16
+ */
17
+ module.exports = ({ command }) => {
18
+ command
19
+ .command('export')
20
+ .description('Export data from Strapi to file')
21
+ .allowExcessArguments(false)
22
+ .addOption(
23
+ new Option('--no-encrypt', `Disables 'aes-128-ecb' encryption of the output file`).default(
24
+ true
25
+ )
26
+ )
27
+ .addOption(
28
+ new Option('--no-compress', 'Disables gzip compression of output file').default(true)
29
+ )
30
+ .addOption(
31
+ new Option(
32
+ '-k, --key <string>',
33
+ 'Provide encryption key in command instead of using the prompt'
34
+ )
35
+ )
36
+ .addOption(
37
+ new Option('-f, --file <file>', 'name to use for exported file (without extensions)')
38
+ )
39
+ .addOption(excludeOption)
40
+ .addOption(onlyOption)
41
+ .addOption(throttleOption)
42
+ .hook('preAction', validateExcludeOnly)
43
+ .hook('preAction', promptEncryptionKey)
44
+ .action(getLocalScript('export'));
45
+ };
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ const { assertCwdContainsStrapiProject } = require('../../utils/helpers');
4
+
5
+ /**
6
+ * `$ strapi generate`
7
+ * @param {import('../../../types/core/commands').AddCommandOptions} options
8
+ */
9
+ module.exports = ({ command, argv }) => {
10
+ command
11
+ .command('generate')
12
+ .description('Launch the interactive API generator')
13
+ .action(() => {
14
+ assertCwdContainsStrapiProject('generate');
15
+ argv.splice(2, 1);
16
+ require('@strapi/generators').runCLI();
17
+ });
18
+ };
@@ -3,9 +3,9 @@
3
3
  const CLITable = require('cli-table3');
4
4
  const chalk = require('chalk');
5
5
 
6
- const strapi = require('../../index');
6
+ const strapi = require('../../../../index');
7
7
 
8
- module.exports = async function () {
8
+ module.exports = async () => {
9
9
  const appContext = await strapi.compile();
10
10
  const app = await strapi(appContext).register();
11
11
 
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ const { getLocalScript } = require('../../../utils/helpers');
4
+
5
+ /**
6
+ * `$ strapi hooks:list`
7
+ * @param {import('../../../../types/core/commands').AddCommandOptions} options
8
+ */
9
+ module.exports = ({ command }) => {
10
+ command
11
+ .command('hooks:list')
12
+ .description('List all the application hooks')
13
+ .action(getLocalScript('hooks/list'));
14
+ };
@@ -0,0 +1,143 @@
1
+ 'use strict';
2
+
3
+ const {
4
+ strapi: {
5
+ providers: { DEFAULT_CONFLICT_STRATEGY },
6
+ },
7
+ engine: { DEFAULT_SCHEMA_STRATEGY, DEFAULT_VERSION_STRATEGY },
8
+ } = require('@strapi/data-transfer');
9
+
10
+ const { expectExit } = require('../../../__tests__/commands.test.utils');
11
+
12
+ const createTransferEngine = jest.fn(() => {
13
+ return {
14
+ transfer: jest.fn(() => {
15
+ return {
16
+ engine: {},
17
+ };
18
+ }),
19
+ progress: {
20
+ on: jest.fn(),
21
+ stream: {
22
+ on: jest.fn(),
23
+ },
24
+ },
25
+ sourceProvider: { name: 'testFileSource', type: 'source', getMetadata: jest.fn() },
26
+ destinationProvider: {
27
+ name: 'testStrapiDest',
28
+ type: 'destination',
29
+ getMetadata: jest.fn(),
30
+ },
31
+ diagnostics: {
32
+ on: jest.fn().mockReturnThis(),
33
+ onDiagnostic: jest.fn().mockReturnThis(),
34
+ },
35
+ };
36
+ });
37
+
38
+ describe('Import', () => {
39
+ const mockDataTransfer = {
40
+ file: {
41
+ providers: {
42
+ createLocalFileSourceProvider: jest
43
+ .fn()
44
+ .mockReturnValue({ name: 'testFileSource', type: 'source', getMetadata: jest.fn() }),
45
+ },
46
+ },
47
+ strapi: {
48
+ providers: {
49
+ DEFAULT_CONFLICT_STRATEGY,
50
+ createLocalStrapiDestinationProvider: jest
51
+ .fn()
52
+ .mockReturnValue({ name: 'testStrapiDest', type: 'destination', getMetadata: jest.fn() }),
53
+ },
54
+ },
55
+ engine: {
56
+ ...jest.requireActual('@strapi/data-transfer').engine,
57
+ DEFAULT_SCHEMA_STRATEGY,
58
+ DEFAULT_VERSION_STRATEGY,
59
+ createTransferEngine,
60
+ },
61
+ };
62
+
63
+ jest.mock('@strapi/data-transfer', () => mockDataTransfer);
64
+
65
+ // command utils
66
+ const mockUtils = {
67
+ getTransferTelemetryPayload: jest.fn().mockReturnValue({}),
68
+ loadersFactory: jest.fn().mockReturnValue({ updateLoader: jest.fn() }),
69
+ formatDiagnostic: jest.fn(),
70
+ createStrapiInstance: jest.fn().mockReturnValue({
71
+ telemetry: {
72
+ send: jest.fn(),
73
+ },
74
+ destroy: jest.fn(),
75
+ }),
76
+ buildTransferTable: jest.fn(() => {
77
+ return {
78
+ toString() {
79
+ return 'table';
80
+ },
81
+ };
82
+ }),
83
+ exitMessageText: jest.fn(),
84
+ };
85
+ jest.mock(
86
+ '../../../utils/data-transfer.js',
87
+ () => {
88
+ return mockUtils;
89
+ },
90
+ { virtual: true }
91
+ );
92
+
93
+ // console spies
94
+ jest.spyOn(console, 'log').mockImplementation(() => {});
95
+ jest.spyOn(console, 'warn').mockImplementation(() => {});
96
+ jest.spyOn(console, 'info').mockImplementation(() => {});
97
+ jest.spyOn(console, 'error').mockImplementation(() => {});
98
+
99
+ // Now that everything is mocked, load the 'import' command
100
+ const importAction = require('../action');
101
+
102
+ beforeEach(() => {
103
+ jest.clearAllMocks();
104
+ });
105
+
106
+ it('creates providers with correct options ', async () => {
107
+ const options = {
108
+ file: 'test.tar.gz.enc',
109
+ decrypt: true,
110
+ decompress: true,
111
+ exclude: [],
112
+ only: [],
113
+ };
114
+
115
+ await expectExit(0, async () => {
116
+ await importAction(options);
117
+ });
118
+
119
+ // strapi options
120
+ expect(
121
+ mockDataTransfer.strapi.providers.createLocalStrapiDestinationProvider
122
+ ).toHaveBeenCalledWith(expect.objectContaining({ strategy: DEFAULT_CONFLICT_STRATEGY }));
123
+
124
+ // file options
125
+ expect(mockDataTransfer.file.providers.createLocalFileSourceProvider).toHaveBeenCalledWith(
126
+ expect.objectContaining({
127
+ file: { path: 'test.tar.gz.enc' },
128
+ encryption: { enabled: options.decrypt },
129
+ compression: { enabled: options.decompress },
130
+ })
131
+ );
132
+
133
+ // engine options
134
+ expect(mockDataTransfer.engine.createTransferEngine).toHaveBeenCalledWith(
135
+ expect.objectContaining({ name: 'testFileSource' }),
136
+ expect.objectContaining({ name: 'testStrapiDest' }),
137
+ expect.objectContaining({
138
+ schemaStrategy: DEFAULT_SCHEMA_STRATEGY,
139
+ versionStrategy: DEFAULT_VERSION_STRATEGY,
140
+ })
141
+ );
142
+ });
143
+ });
@@ -21,8 +21,8 @@ const {
21
21
  exitMessageText,
22
22
  abortTransfer,
23
23
  getTransferTelemetryPayload,
24
- } = require('./utils');
25
- const { exitWith } = require('../utils/helpers');
24
+ } = require('../../utils/data-transfer');
25
+ const { exitWith } = require('../../utils/helpers');
26
26
 
27
27
  /**
28
28
  * @typedef {import('@strapi/data-transfer/src/file/providers').ILocalFileSourceProviderOptions} ILocalFileSourceProviderOptions