@strapi/strapi 4.0.0-next.8 → 4.0.2
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/README.md +14 -14
- package/bin/strapi.js +46 -60
- package/lib/Strapi.js +152 -74
- package/lib/commands/build.js +19 -8
- package/lib/commands/console.js +1 -1
- package/lib/commands/content-types/list.js +22 -0
- package/lib/commands/controllers/list.js +22 -0
- package/lib/commands/develop.js +22 -27
- package/lib/commands/generate-template.js +4 -5
- package/lib/commands/hooks/list.js +22 -0
- package/lib/commands/middlewares/list.js +22 -0
- package/lib/commands/new.js +3 -1
- package/lib/commands/policies/list.js +22 -0
- package/lib/commands/routes/list.js +28 -0
- package/lib/commands/services/list.js +22 -0
- package/lib/commands/watchAdmin.js +18 -9
- package/lib/core/app-configuration/index.js +3 -19
- package/lib/core/bootstrap.js +3 -95
- package/lib/core/domain/content-type/index.js +5 -11
- package/lib/core/domain/module/index.js +42 -11
- package/lib/core/domain/module/validation.js +16 -19
- package/lib/core/loaders/admin.js +2 -2
- package/lib/core/loaders/apis.js +148 -9
- package/lib/core/loaders/components.js +4 -6
- package/lib/core/loaders/index.js +1 -0
- package/lib/core/loaders/middlewares.js +23 -123
- package/lib/core/loaders/plugins/get-enabled-plugins.js +55 -19
- package/lib/core/loaders/plugins/get-user-plugins-config.js +37 -0
- package/lib/core/loaders/plugins/index.js +30 -16
- package/lib/core/loaders/policies.js +1 -1
- package/lib/core/loaders/src-index.js +39 -0
- package/lib/core/registries/apis.js +29 -0
- package/lib/core/registries/content-types.js +61 -12
- package/lib/core/registries/controllers.d.ts +7 -0
- package/lib/core/registries/controllers.js +91 -7
- package/lib/core/registries/hooks.d.ts +20 -0
- package/lib/core/registries/hooks.js +87 -0
- package/lib/core/registries/middlewares.d.ts +5 -0
- package/lib/core/registries/middlewares.js +64 -5
- package/lib/core/registries/modules.js +3 -3
- package/lib/core/registries/plugins.js +2 -2
- package/lib/core/registries/policies.d.ts +9 -0
- package/lib/core/registries/policies.js +64 -5
- package/lib/core/registries/services.d.ts +7 -0
- package/lib/core/registries/services.js +86 -17
- package/lib/core/utils.js +22 -0
- package/lib/core-api/controller/collection-type.js +45 -26
- package/lib/core-api/controller/index.d.ts +25 -0
- package/lib/core-api/controller/index.js +33 -11
- package/lib/core-api/controller/single-type.js +29 -15
- package/lib/core-api/controller/transform.js +62 -6
- package/lib/core-api/routes/index.js +71 -0
- package/lib/core-api/service/collection-type.js +43 -21
- package/lib/core-api/service/index.d.ts +21 -0
- package/lib/core-api/service/index.js +8 -67
- package/lib/core-api/service/pagination.js +125 -0
- package/lib/core-api/service/single-type.js +17 -19
- package/lib/factories.d.ts +48 -0
- package/lib/factories.js +84 -0
- package/lib/index.d.ts +10 -31
- package/lib/index.js +5 -1
- package/lib/middlewares/body.js +33 -0
- package/lib/middlewares/compression.js +8 -0
- package/lib/middlewares/cors.js +58 -0
- package/lib/middlewares/errors.js +40 -0
- package/lib/middlewares/favicon.js +19 -0
- package/lib/middlewares/index.d.ts +5 -0
- package/lib/middlewares/index.js +30 -116
- package/lib/middlewares/ip.js +8 -0
- package/lib/middlewares/logger.js +27 -0
- package/lib/middlewares/powered-by.js +20 -0
- package/lib/middlewares/public/index.js +72 -77
- package/lib/middlewares/query.js +46 -0
- package/lib/middlewares/response-time.js +15 -0
- package/lib/middlewares/responses.js +19 -0
- package/lib/middlewares/security.js +51 -0
- package/lib/middlewares/session/index.js +6 -6
- package/lib/migrations/draft-publish.js +57 -0
- package/lib/services/auth/index.js +87 -0
- package/lib/services/core-store.js +64 -49
- package/lib/services/cron.js +54 -0
- package/lib/services/entity-service/attributes/index.js +31 -0
- package/lib/services/entity-service/attributes/transforms.js +20 -0
- package/lib/services/entity-service/components.js +39 -15
- package/lib/services/entity-service/index.d.ts +91 -0
- package/lib/services/entity-service/index.js +118 -60
- package/lib/services/entity-service/params.js +52 -94
- package/lib/services/entity-validator/index.js +76 -43
- package/lib/services/entity-validator/validators.js +131 -43
- package/lib/services/errors.js +77 -0
- package/lib/services/fs.js +1 -1
- package/lib/services/metrics/index.js +38 -36
- package/lib/services/server/admin-api.js +14 -0
- package/lib/services/server/api.js +36 -0
- package/lib/services/server/compose-endpoint.js +141 -0
- package/lib/services/server/content-api.js +16 -0
- package/lib/{server.js → services/server/http-server.js} +0 -0
- package/lib/services/server/index.js +127 -0
- package/lib/services/server/koa.js +64 -0
- package/lib/services/server/middleware.js +122 -0
- package/lib/services/server/policy.js +32 -0
- package/lib/services/server/register-middlewares.js +110 -0
- package/lib/services/server/register-routes.js +106 -0
- package/lib/services/server/routing.js +120 -0
- package/lib/services/webhook-runner.js +1 -1
- package/lib/utils/ee.js +3 -3
- package/lib/utils/get-dirs.js +17 -0
- package/lib/utils/index.js +2 -0
- package/lib/utils/signals.js +24 -0
- package/lib/utils/update-notifier/index.js +2 -1
- package/package.json +94 -97
- package/lib/commands/generate.js +0 -76
- package/lib/core/app-configuration/load-functions.js +0 -28
- package/lib/core-api/index.js +0 -39
- package/lib/load/check-reserved-filename.js +0 -10
- package/lib/load/load-config-files.js +0 -22
- package/lib/load/require-file-parse.js +0 -15
- package/lib/middlewares/boom/defaults.json +0 -5
- package/lib/middlewares/boom/index.js +0 -147
- package/lib/middlewares/cors/index.js +0 -66
- package/lib/middlewares/cron/defaults.json +0 -5
- package/lib/middlewares/cron/index.js +0 -43
- package/lib/middlewares/favicon/defaults.json +0 -7
- package/lib/middlewares/favicon/index.js +0 -32
- package/lib/middlewares/gzip/defaults.json +0 -6
- package/lib/middlewares/gzip/index.js +0 -19
- package/lib/middlewares/helmet/defaults.json +0 -18
- package/lib/middlewares/helmet/index.js +0 -9
- package/lib/middlewares/ip/defaults.json +0 -7
- package/lib/middlewares/ip/index.js +0 -25
- package/lib/middlewares/language/defaults.json +0 -9
- package/lib/middlewares/language/index.js +0 -40
- package/lib/middlewares/logger/defaults.json +0 -5
- package/lib/middlewares/logger/index.js +0 -37
- package/lib/middlewares/parser/defaults.json +0 -11
- package/lib/middlewares/parser/index.js +0 -71
- package/lib/middlewares/poweredBy/defaults.json +0 -5
- package/lib/middlewares/poweredBy/index.js +0 -16
- package/lib/middlewares/public/defaults.json +0 -8
- package/lib/middlewares/responseTime/defaults.json +0 -5
- package/lib/middlewares/responseTime/index.js +0 -25
- package/lib/middlewares/responses/defaults.json +0 -5
- package/lib/middlewares/responses/index.js +0 -18
- package/lib/middlewares/router/defaults.json +0 -7
- package/lib/middlewares/router/index.js +0 -58
- package/lib/middlewares/router/utils/composeEndpoint.js +0 -177
- package/lib/utils/get-prefixed-dependencies.js +0 -7
package/lib/commands/build.js
CHANGED
|
@@ -1,23 +1,32 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
const { green } = require('chalk');
|
|
3
3
|
|
|
4
|
-
// eslint-disable-next-line node/no-extraneous-require
|
|
5
4
|
const strapiAdmin = require('@strapi/admin');
|
|
6
5
|
const { getConfigUrls } = require('@strapi/utils');
|
|
7
|
-
const loadConfiguration = require('../core/app-configuration');
|
|
8
|
-
const ee = require('../utils/ee');
|
|
9
6
|
|
|
7
|
+
const ee = require('../utils/ee');
|
|
10
8
|
const addSlash = require('../utils/addSlash');
|
|
9
|
+
const strapi = require('../index');
|
|
10
|
+
const getEnabledPlugins = require('../core/loaders/plugins/get-enabled-plugins');
|
|
11
|
+
|
|
11
12
|
/**
|
|
12
13
|
* `$ strapi build`
|
|
13
14
|
*/
|
|
14
|
-
module.exports = async ({ clean, optimization }) => {
|
|
15
|
+
module.exports = async ({ clean, optimization, forceBuild = true }) => {
|
|
15
16
|
const dir = process.cwd();
|
|
16
|
-
const config = loadConfiguration(dir);
|
|
17
17
|
|
|
18
|
-
const
|
|
18
|
+
const strapiInstance = strapi({
|
|
19
|
+
dir,
|
|
20
|
+
autoReload: true,
|
|
21
|
+
serveAdminPanel: false,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const plugins = await getEnabledPlugins(strapiInstance);
|
|
25
|
+
|
|
26
|
+
const env = strapiInstance.config.get('environment');
|
|
27
|
+
const { serverUrl, adminPath } = getConfigUrls(strapiInstance.config, true);
|
|
19
28
|
|
|
20
|
-
console.log(`Building your admin UI with ${green(
|
|
29
|
+
console.log(`Building your admin UI with ${green(env)} configuration ...`);
|
|
21
30
|
|
|
22
31
|
if (clean) {
|
|
23
32
|
await strapiAdmin.clean({ dir });
|
|
@@ -27,7 +36,9 @@ module.exports = async ({ clean, optimization }) => {
|
|
|
27
36
|
|
|
28
37
|
return strapiAdmin
|
|
29
38
|
.build({
|
|
39
|
+
forceBuild,
|
|
30
40
|
dir,
|
|
41
|
+
plugins,
|
|
31
42
|
// front end build env is always production for now
|
|
32
43
|
env: 'production',
|
|
33
44
|
optimize: optimization,
|
|
@@ -37,7 +48,7 @@ module.exports = async ({ clean, optimization }) => {
|
|
|
37
48
|
},
|
|
38
49
|
})
|
|
39
50
|
.then(() => {
|
|
40
|
-
|
|
51
|
+
console.log('Admin UI built successfully');
|
|
41
52
|
})
|
|
42
53
|
.catch(err => {
|
|
43
54
|
console.error(err);
|
package/lib/commands/console.js
CHANGED
|
@@ -10,7 +10,7 @@ module.exports = () => {
|
|
|
10
10
|
// Now load up the Strapi framework for real.
|
|
11
11
|
const app = strapi();
|
|
12
12
|
|
|
13
|
-
app.start(() => {
|
|
13
|
+
app.start().then(() => {
|
|
14
14
|
const repl = REPL.start(app.config.info.name + ' > ' || 'strapi > '); // eslint-disable-line prefer-template
|
|
15
15
|
|
|
16
16
|
repl.on('exit', function(err) {
|
|
@@ -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('content-types').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('controllers').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
|
+
};
|
package/lib/commands/develop.js
CHANGED
|
@@ -10,6 +10,7 @@ const { getOr } = require('lodash/fp');
|
|
|
10
10
|
const { createLogger } = require('@strapi/logger');
|
|
11
11
|
const loadConfiguration = require('../core/app-configuration');
|
|
12
12
|
const strapi = require('../index');
|
|
13
|
+
const buildAdmin = require('./build');
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* `$ strapi develop`
|
|
@@ -20,23 +21,20 @@ module.exports = async function({ build, watchAdmin, polling, browser }) {
|
|
|
20
21
|
const config = loadConfiguration(dir);
|
|
21
22
|
const logger = createLogger(config.logger, {});
|
|
22
23
|
|
|
23
|
-
const adminWatchIgnoreFiles = getOr([], 'server.admin.watchIgnoreFiles')(config);
|
|
24
|
-
const serveAdminPanel = getOr(true, 'server.admin.serveAdminPanel')(config);
|
|
25
|
-
|
|
26
|
-
const buildExists = fs.existsSync(path.join(dir, 'build'));
|
|
27
|
-
// Don't run the build process if the admin is in watch mode
|
|
28
|
-
if (build && !watchAdmin && serveAdminPanel && !buildExists) {
|
|
29
|
-
try {
|
|
30
|
-
execa.shellSync('npm run -s build -- --no-optimization', {
|
|
31
|
-
stdio: 'inherit',
|
|
32
|
-
});
|
|
33
|
-
} catch (err) {
|
|
34
|
-
process.exit(1);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
24
|
try {
|
|
39
25
|
if (cluster.isMaster) {
|
|
26
|
+
const serveAdminPanel = getOr(true, 'admin.serveAdminPanel')(config);
|
|
27
|
+
|
|
28
|
+
const buildExists = fs.existsSync(path.join(dir, 'build'));
|
|
29
|
+
// Don't run the build process if the admin is in watch mode
|
|
30
|
+
if (build && !watchAdmin && serveAdminPanel && !buildExists) {
|
|
31
|
+
try {
|
|
32
|
+
await buildAdmin({ clean: false, optimization: false, forceBuild: false });
|
|
33
|
+
} catch (err) {
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
40
38
|
if (watchAdmin) {
|
|
41
39
|
try {
|
|
42
40
|
execa('npm', ['run', '-s', 'strapi', 'watch-admin', '--', '--browser', browser], {
|
|
@@ -51,14 +49,12 @@ module.exports = async function({ build, watchAdmin, polling, browser }) {
|
|
|
51
49
|
switch (message) {
|
|
52
50
|
case 'reload':
|
|
53
51
|
logger.info('The server is restarting\n');
|
|
54
|
-
worker.send('
|
|
52
|
+
worker.send('kill');
|
|
55
53
|
break;
|
|
56
|
-
case '
|
|
57
|
-
worker.kill();
|
|
54
|
+
case 'killed':
|
|
58
55
|
cluster.fork();
|
|
59
56
|
break;
|
|
60
57
|
case 'stop':
|
|
61
|
-
worker.kill();
|
|
62
58
|
process.exit(1);
|
|
63
59
|
default:
|
|
64
60
|
return;
|
|
@@ -75,6 +71,7 @@ module.exports = async function({ build, watchAdmin, polling, browser }) {
|
|
|
75
71
|
serveAdminPanel: watchAdmin ? false : true,
|
|
76
72
|
});
|
|
77
73
|
|
|
74
|
+
const adminWatchIgnoreFiles = getOr([], 'admin.watchIgnoreFiles')(config);
|
|
78
75
|
watchFileChanges({
|
|
79
76
|
dir,
|
|
80
77
|
strapiInstance,
|
|
@@ -84,10 +81,10 @@ module.exports = async function({ build, watchAdmin, polling, browser }) {
|
|
|
84
81
|
|
|
85
82
|
process.on('message', async message => {
|
|
86
83
|
switch (message) {
|
|
87
|
-
case '
|
|
88
|
-
await strapiInstance.
|
|
89
|
-
process.send('
|
|
90
|
-
|
|
84
|
+
case 'kill':
|
|
85
|
+
await strapiInstance.destroy();
|
|
86
|
+
process.send('killed');
|
|
87
|
+
process.exit();
|
|
91
88
|
default:
|
|
92
89
|
// Do nothing.
|
|
93
90
|
}
|
|
@@ -122,10 +119,8 @@ function watchFileChanges({ dir, strapiInstance, watchIgnoreFiles, polling }) {
|
|
|
122
119
|
ignored: [
|
|
123
120
|
/(^|[/\\])\../, // dot files
|
|
124
121
|
/tmp/,
|
|
125
|
-
'**/admin',
|
|
126
|
-
'**/admin
|
|
127
|
-
'extensions/**/admin',
|
|
128
|
-
'extensions/**/admin/**',
|
|
122
|
+
'**/src/admin/**',
|
|
123
|
+
'**/src/plugins/**/admin/',
|
|
129
124
|
'**/documentation',
|
|
130
125
|
'**/documentation/**',
|
|
131
126
|
'**/node_modules',
|
|
@@ -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 = ['
|
|
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
|
|
58
|
-
|
|
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
|
+
};
|
package/lib/commands/new.js
CHANGED
|
@@ -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
|
|
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,33 +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
|
-
const { getOr } = require('lodash/fp');
|
|
6
4
|
const { getConfigUrls, getAbsoluteServerUrl } = require('@strapi/utils');
|
|
7
|
-
|
|
5
|
+
|
|
8
6
|
const ee = require('../utils/ee');
|
|
9
7
|
const addSlash = require('../utils/addSlash');
|
|
8
|
+
const strapi = require('../index');
|
|
9
|
+
const getEnabledPlugins = require('../core/loaders/plugins/get-enabled-plugins');
|
|
10
10
|
|
|
11
11
|
module.exports = async function({ browser }) {
|
|
12
12
|
const dir = process.cwd();
|
|
13
13
|
|
|
14
|
-
const
|
|
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);
|
|
15
23
|
|
|
16
|
-
const
|
|
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', []);
|
|
17
27
|
|
|
18
|
-
const
|
|
19
|
-
const adminHost = getOr('localhost', 'server.admin.host')(config);
|
|
20
|
-
const adminWatchIgnoreFiles = getOr([], 'server.admin.watchIgnoreFiles')(config);
|
|
28
|
+
const backendURL = getAbsoluteServerUrl(strapiInstance.config, true);
|
|
21
29
|
|
|
22
30
|
ee({ dir });
|
|
23
31
|
|
|
24
32
|
strapiAdmin.watchAdmin({
|
|
25
33
|
dir,
|
|
34
|
+
plugins,
|
|
26
35
|
port: adminPort,
|
|
27
36
|
host: adminHost,
|
|
28
37
|
browser,
|
|
29
38
|
options: {
|
|
30
|
-
backend:
|
|
39
|
+
backend: backendURL,
|
|
31
40
|
adminPath: addSlash(adminPath),
|
|
32
41
|
watchIgnoreFiles: adminWatchIgnoreFiles,
|
|
33
42
|
features: ee.isEE ? ee.features.getEnabled() : [],
|
|
@@ -10,18 +10,10 @@ dotenv.config({ path: process.env.ENV_PATH });
|
|
|
10
10
|
|
|
11
11
|
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
|
12
12
|
|
|
13
|
-
const getPrefixedDeps = require('../../utils/get-prefixed-dependencies');
|
|
14
13
|
const loadConfigDir = require('./config-loader');
|
|
15
|
-
const loadFunction = require('./load-functions');
|
|
16
14
|
|
|
17
15
|
const { version: strapiVersion } = require(path.join(__dirname, '../../../package.json'));
|
|
18
16
|
|
|
19
|
-
const CONFIG_PATHS = {
|
|
20
|
-
config: 'config',
|
|
21
|
-
static: 'public',
|
|
22
|
-
views: 'views',
|
|
23
|
-
};
|
|
24
|
-
|
|
25
17
|
const defaultConfig = {
|
|
26
18
|
server: {
|
|
27
19
|
host: process.env.HOST || os.hostname() || 'localhost',
|
|
@@ -31,14 +23,10 @@ const defaultConfig = {
|
|
|
31
23
|
admin: { autoOpen: false },
|
|
32
24
|
},
|
|
33
25
|
admin: {},
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
before: ['responseTime', 'logger', 'cors', 'responses', 'gzip'],
|
|
38
|
-
order: [],
|
|
39
|
-
after: ['parser', 'router'],
|
|
26
|
+
api: {
|
|
27
|
+
rest: {
|
|
28
|
+
prefix: '/api',
|
|
40
29
|
},
|
|
41
|
-
settings: {},
|
|
42
30
|
},
|
|
43
31
|
};
|
|
44
32
|
|
|
@@ -51,8 +39,6 @@ module.exports = (dir, initialConfig = {}) => {
|
|
|
51
39
|
|
|
52
40
|
const rootConfig = {
|
|
53
41
|
launchedAt: Date.now(),
|
|
54
|
-
appPath: dir,
|
|
55
|
-
paths: CONFIG_PATHS,
|
|
56
42
|
serveAdminPanel,
|
|
57
43
|
autoReload,
|
|
58
44
|
environment: process.env.NODE_ENV,
|
|
@@ -62,8 +48,6 @@ module.exports = (dir, initialConfig = {}) => {
|
|
|
62
48
|
...pkgJSON,
|
|
63
49
|
strapi: strapiVersion,
|
|
64
50
|
},
|
|
65
|
-
functions: loadFunction(path.join(configDir, 'functions')),
|
|
66
|
-
installedMiddlewares: getPrefixedDeps('@strapi/middleware', pkgJSON),
|
|
67
51
|
};
|
|
68
52
|
|
|
69
53
|
const baseConfig = omit('plugins', loadConfigDir(configDir)); // plugin config will be loaded later
|
package/lib/core/bootstrap.js
CHANGED
|
@@ -1,104 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const _ = require('lodash');
|
|
4
|
-
const { toLower, kebabCase } = require('lodash/fp');
|
|
5
3
|
const { getConfigUrls } = require('@strapi/utils');
|
|
6
|
-
const pluralize = require('pluralize');
|
|
7
4
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
// TODO: function to be moved next to where the api will be loaded
|
|
11
|
-
const validateContentTypesUnicity = schemas => {
|
|
12
|
-
const names = [];
|
|
13
|
-
schemas.forEach(schema => {
|
|
14
|
-
if (schema.info.singularName) {
|
|
15
|
-
const singularName = kebabCase(schema.info.singularName);
|
|
16
|
-
if (names.includes(singularName)) {
|
|
17
|
-
throw new Error(`The singular name "${schema.info.singularName}" should be unique`);
|
|
18
|
-
}
|
|
19
|
-
names.push(singularName);
|
|
20
|
-
}
|
|
21
|
-
if (schema.info.pluralName) {
|
|
22
|
-
const pluralName = kebabCase(schema.info.pluralName);
|
|
23
|
-
if (names.includes(pluralName)) {
|
|
24
|
-
throw new Error(`The plural name "${schema.info.pluralName}" should be unique`);
|
|
25
|
-
}
|
|
26
|
-
names.push(pluralName);
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
module.exports = function(strapi) {
|
|
32
|
-
// validate Content-Types unicity
|
|
33
|
-
const allApisSchemas = Object.values(strapi.api).flatMap(api => Object.values(api.models));
|
|
34
|
-
validateContentTypesUnicity(allApisSchemas);
|
|
35
|
-
|
|
36
|
-
// set default services and default controllers
|
|
37
|
-
for (const apiName in strapi.api) {
|
|
38
|
-
const api = strapi.api[apiName];
|
|
39
|
-
for (const modelName in api.models) {
|
|
40
|
-
const model = api.models[modelName];
|
|
41
|
-
model.info.displayName = model.info.displayName || model.info.name;
|
|
42
|
-
model.info.singularName = model.info.singularName || modelName;
|
|
43
|
-
model.info.pluralName = model.info.pluralName || pluralize(modelName);
|
|
44
|
-
|
|
45
|
-
strapi.container.get('content-types').add(`api::${apiName}`, {
|
|
46
|
-
[modelName]: { schema: model, actions: model.actions, lifecycles: model.lifecycles },
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
const contentType = strapi.contentType(`api::${apiName}.${modelName}`);
|
|
50
|
-
|
|
51
|
-
const { service, controller } = createCoreApi({ model: contentType, api, strapi });
|
|
52
|
-
_.set(strapi.api[apiName], ['services', modelName], service);
|
|
53
|
-
_.set(strapi.api[apiName], ['controllers', modelName], controller);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Set user's controllers.
|
|
58
|
-
strapi.controllers = Object.keys(strapi.api || []).reduce((acc, apiName) => {
|
|
59
|
-
strapi.container.get('controllers').add(`api::${apiName}`, strapi.api[apiName].controllers);
|
|
60
|
-
for (let controllerName in strapi.api[apiName].controllers) {
|
|
61
|
-
let controller = strapi.api[apiName].controllers[controllerName];
|
|
62
|
-
acc[controllerName] = controller;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return acc;
|
|
66
|
-
}, {});
|
|
67
|
-
|
|
68
|
-
// Set routes.
|
|
69
|
-
strapi.config.routes = Object.keys(strapi.api || []).reduce((acc, key) => {
|
|
70
|
-
return acc.concat(_.get(strapi.api[key], 'config.routes') || {});
|
|
71
|
-
}, []);
|
|
72
|
-
|
|
73
|
-
// TODO: delete v3 code
|
|
74
|
-
_.forEach(strapi.plugins, plugin => {
|
|
75
|
-
_.forEach(plugin.middlewares, (middleware, middlewareUID) => {
|
|
76
|
-
const middlewareName = toLower(middlewareUID.split('.')[1]);
|
|
77
|
-
strapi.middleware[middlewareName] = middleware;
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
// Preset config in alphabetical order.
|
|
82
|
-
strapi.config.middleware.settings = Object.keys(strapi.middleware).reduce((acc, current) => {
|
|
83
|
-
// Try to find the settings in the current environment, then in the main configurations.
|
|
84
|
-
const currentSettings = _.merge(
|
|
85
|
-
_.cloneDeep(_.get(strapi.middleware[current], ['defaults', current], {})),
|
|
86
|
-
strapi.config.get(['middleware', 'settings', current], {})
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
acc[current] = !_.isObject(currentSettings) ? {} : currentSettings;
|
|
90
|
-
|
|
91
|
-
// Ensure that enabled key exist by forcing to false.
|
|
92
|
-
_.defaults(acc[current], { enabled: false });
|
|
93
|
-
|
|
94
|
-
return acc;
|
|
95
|
-
}, {});
|
|
96
|
-
|
|
97
|
-
// default settings
|
|
5
|
+
module.exports = function({ strapi }) {
|
|
98
6
|
strapi.config.port = strapi.config.get('server.port') || strapi.config.port;
|
|
99
7
|
strapi.config.host = strapi.config.get('server.host') || strapi.config.host;
|
|
100
8
|
|
|
101
|
-
const { serverUrl, adminUrl, adminPath } = getConfigUrls(strapi.config
|
|
9
|
+
const { serverUrl, adminUrl, adminPath } = getConfigUrls(strapi.config);
|
|
102
10
|
|
|
103
11
|
strapi.config.server = strapi.config.server || {};
|
|
104
12
|
strapi.config.server.url = serverUrl;
|
|
@@ -107,7 +15,7 @@ module.exports = function(strapi) {
|
|
|
107
15
|
|
|
108
16
|
// check if we should serve admin panel
|
|
109
17
|
const shouldServeAdmin = strapi.config.get(
|
|
110
|
-
'
|
|
18
|
+
'admin.serveAdminPanel',
|
|
111
19
|
strapi.config.get('serveAdminPanel')
|
|
112
20
|
);
|
|
113
21
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const { cloneDeep } = require('lodash/fp');
|
|
4
4
|
const _ = require('lodash');
|
|
5
|
-
const { hasDraftAndPublish } = require('@strapi/utils').contentTypes;
|
|
5
|
+
const { hasDraftAndPublish, getPrivateAttributes } = require('@strapi/utils').contentTypes;
|
|
6
6
|
const {
|
|
7
7
|
CREATED_AT_ATTRIBUTE,
|
|
8
8
|
UPDATED_AT_ATTRIBUTE,
|
|
@@ -60,9 +60,7 @@ const createContentType = (uid, definition) => {
|
|
|
60
60
|
|
|
61
61
|
Object.defineProperty(schema, 'privateAttributes', {
|
|
62
62
|
get() {
|
|
63
|
-
|
|
64
|
-
// return strapi.getModel(model.uid).privateAttributes;
|
|
65
|
-
return [];
|
|
63
|
+
return getPrivateAttributes(schema);
|
|
66
64
|
},
|
|
67
65
|
});
|
|
68
66
|
|
|
@@ -70,12 +68,10 @@ const createContentType = (uid, definition) => {
|
|
|
70
68
|
Object.assign(schema.attributes, {
|
|
71
69
|
[CREATED_AT_ATTRIBUTE]: {
|
|
72
70
|
type: 'datetime',
|
|
73
|
-
default: () => new Date(),
|
|
74
71
|
},
|
|
75
72
|
// TODO: handle on edit set to new date
|
|
76
73
|
[UPDATED_AT_ATTRIBUTE]: {
|
|
77
74
|
type: 'datetime',
|
|
78
|
-
default: () => new Date(),
|
|
79
75
|
},
|
|
80
76
|
});
|
|
81
77
|
|
|
@@ -112,11 +108,9 @@ const createContentType = (uid, definition) => {
|
|
|
112
108
|
private: isPrivate,
|
|
113
109
|
};
|
|
114
110
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
lifecycles: lifecycles,
|
|
119
|
-
};
|
|
111
|
+
Object.assign(schema, { actions, lifecycles });
|
|
112
|
+
|
|
113
|
+
return schema;
|
|
120
114
|
};
|
|
121
115
|
|
|
122
116
|
const getGlobalId = (model, modelName, prefix) => {
|