@strapi/strapi 4.2.0-beta.2 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/strapi.js +1 -2
- package/lib/Strapi.js +15 -37
- package/lib/commands/admin-create.js +1 -8
- package/lib/commands/admin-reset.js +1 -8
- package/lib/commands/build.js +44 -18
- package/lib/commands/configurationDump.js +1 -8
- package/lib/commands/configurationRestore.js +1 -9
- package/lib/commands/console.js +2 -10
- package/lib/commands/develop.js +74 -113
- package/lib/commands/routes/list.js +1 -8
- package/lib/commands/start.js +2 -8
- package/lib/commands/watchAdmin.js +10 -10
- package/lib/core/app-configuration/index.js +3 -4
- package/lib/core/app-configuration/load-config-file.js +1 -3
- package/lib/core/bootstrap.js +2 -2
- package/lib/core/loaders/apis.js +16 -13
- package/lib/core/loaders/components.js +4 -5
- package/lib/core/loaders/index.js +1 -0
- package/lib/core/loaders/middlewares.js +3 -5
- package/lib/core/loaders/plugins/get-enabled-plugins.js +1 -2
- package/lib/core/loaders/plugins/get-user-plugins-config.js +2 -2
- package/lib/core/loaders/plugins/index.js +1 -1
- package/lib/core/loaders/policies.js +2 -4
- package/lib/core/loaders/sanitizers.js +5 -0
- package/lib/core/loaders/src-index.js +4 -6
- package/lib/core/registries/sanitizers.js +26 -0
- package/lib/factories.d.ts +3 -3
- package/lib/index.d.ts +1 -1
- package/lib/load/load-files.js +1 -3
- package/lib/middlewares/body.js +38 -10
- package/lib/middlewares/favicon.js +1 -1
- package/lib/middlewares/public/index.js +1 -2
- package/lib/services/entity-validator/validators.js +3 -1
- package/lib/services/fs.js +1 -1
- package/lib/services/metrics/index.js +1 -5
- package/lib/services/metrics/sender.js +0 -7
- package/lib/services/server/middleware.js +1 -1
- package/lib/utils/get-dirs.js +10 -24
- package/lib/utils/index.js +0 -2
- package/lib/utils/update-notifier/index.js +3 -3
- package/package.json +15 -16
- package/lib/commands/builders/admin.js +0 -59
- package/lib/commands/builders/index.js +0 -9
- package/lib/commands/builders/typescript.js +0 -32
- package/lib/utils/import-default.js +0 -9
package/bin/strapi.js
CHANGED
|
@@ -95,13 +95,12 @@ program
|
|
|
95
95
|
.option('--dbssl <dbssl>', 'Database SSL')
|
|
96
96
|
.option('--dbfile <dbfile>', 'Database file path for sqlite')
|
|
97
97
|
.option('--dbforce', 'Allow overwriting existing database content')
|
|
98
|
-
.option('-ts, --typescript', 'Create a typescript project')
|
|
99
98
|
.description('Create a new application')
|
|
100
99
|
.action(require('../lib/commands/new'));
|
|
101
100
|
|
|
102
101
|
// `$ strapi start`
|
|
103
102
|
program
|
|
104
|
-
.command('start
|
|
103
|
+
.command('start')
|
|
105
104
|
.description('Start your Strapi application')
|
|
106
105
|
.action(getLocalScript('start'));
|
|
107
106
|
|
package/lib/Strapi.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const path = require('path');
|
|
4
3
|
const _ = require('lodash');
|
|
5
4
|
const { isFunction } = require('lodash/fp');
|
|
6
5
|
const { createLogger } = require('@strapi/logger');
|
|
@@ -38,6 +37,7 @@ const apisRegistry = require('./core/registries/apis');
|
|
|
38
37
|
const bootstrap = require('./core/bootstrap');
|
|
39
38
|
const loaders = require('./core/loaders');
|
|
40
39
|
const { destroyOnSignal } = require('./utils/signals');
|
|
40
|
+
const sanitizersRegistry = require('./core/registries/sanitizers');
|
|
41
41
|
|
|
42
42
|
// TODO: move somewhere else
|
|
43
43
|
const draftAndPublishSync = require('./migrations/draft-publish');
|
|
@@ -48,39 +48,12 @@ const LIFECYCLES = {
|
|
|
48
48
|
DESTROY: 'destroy',
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
-
/**
|
|
52
|
-
* Resolve the working directories based on the instance options.
|
|
53
|
-
*
|
|
54
|
-
* Behavior:
|
|
55
|
-
* - `appDir` is the directory where Strapi will write every file (schemas, generated APIs, controllers or services)
|
|
56
|
-
* - `distDir` is the directory where Strapi will read configurations, schemas and any compiled code
|
|
57
|
-
*
|
|
58
|
-
* Default values:
|
|
59
|
-
* - If `appDir` is `undefined`, it'll be set to `process.cwd()`
|
|
60
|
-
* - If `distDir` is `undefined`, it'll be set to `appDir`
|
|
61
|
-
*/
|
|
62
|
-
const resolveWorkingDirectories = opts => {
|
|
63
|
-
const cwd = process.cwd();
|
|
64
|
-
|
|
65
|
-
const appDir = opts.appDir ? path.resolve(cwd, opts.appDir) : cwd;
|
|
66
|
-
const distDir = opts.distDir ? path.resolve(cwd, opts.distDir) : appDir;
|
|
67
|
-
|
|
68
|
-
return { app: appDir, dist: distDir };
|
|
69
|
-
};
|
|
70
|
-
|
|
71
51
|
class Strapi {
|
|
72
52
|
constructor(opts = {}) {
|
|
73
53
|
destroyOnSignal(this);
|
|
74
|
-
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
// Load the app configuration from the dist directory
|
|
78
|
-
const appConfig = loadConfiguration({ appDir: rootDirs.app, distDir: rootDirs.dist }, opts);
|
|
79
|
-
|
|
80
|
-
// Instanciate the Strapi container
|
|
54
|
+
const rootDir = opts.dir || process.cwd();
|
|
55
|
+
const appConfig = loadConfiguration(rootDir, opts);
|
|
81
56
|
this.container = createContainer(this);
|
|
82
|
-
|
|
83
|
-
// Register every Strapi registry in the container
|
|
84
57
|
this.container.register('config', createConfigProvider(appConfig));
|
|
85
58
|
this.container.register('content-types', contentTypesRegistry(this));
|
|
86
59
|
this.container.register('services', servicesRegistry(this));
|
|
@@ -92,18 +65,14 @@ class Strapi {
|
|
|
92
65
|
this.container.register('plugins', pluginsRegistry(this));
|
|
93
66
|
this.container.register('apis', apisRegistry(this));
|
|
94
67
|
this.container.register('auth', createAuth(this));
|
|
68
|
+
this.container.register('sanitizers', sanitizersRegistry(this));
|
|
95
69
|
|
|
96
|
-
|
|
97
|
-
this.dirs = utils.getDirs(rootDirs, { strapi: this });
|
|
70
|
+
this.dirs = utils.getDirs(rootDir, { strapi: this });
|
|
98
71
|
|
|
99
|
-
// Strapi state management variables
|
|
100
72
|
this.isLoaded = false;
|
|
101
73
|
this.reload = this.reload();
|
|
102
|
-
|
|
103
|
-
// Instanciate the Koa app & the HTTP server
|
|
104
74
|
this.server = createServer(this);
|
|
105
75
|
|
|
106
|
-
// Strapi utils instanciation
|
|
107
76
|
this.fs = createStrapiFs(this);
|
|
108
77
|
this.eventHub = createEventHub();
|
|
109
78
|
this.startupLogger = createStartupLogger(this);
|
|
@@ -119,7 +88,7 @@ class Strapi {
|
|
|
119
88
|
}
|
|
120
89
|
|
|
121
90
|
get EE() {
|
|
122
|
-
return ee({ dir: this.dirs.
|
|
91
|
+
return ee({ dir: this.dirs.root, logger: this.log });
|
|
123
92
|
}
|
|
124
93
|
|
|
125
94
|
get services() {
|
|
@@ -190,6 +159,10 @@ class Strapi {
|
|
|
190
159
|
return this.container.get('auth');
|
|
191
160
|
}
|
|
192
161
|
|
|
162
|
+
get sanitizers() {
|
|
163
|
+
return this.container.get('sanitizers');
|
|
164
|
+
}
|
|
165
|
+
|
|
193
166
|
async start() {
|
|
194
167
|
try {
|
|
195
168
|
if (!this.isLoaded) {
|
|
@@ -337,6 +310,10 @@ class Strapi {
|
|
|
337
310
|
this.app = await loaders.loadSrcIndex(this);
|
|
338
311
|
}
|
|
339
312
|
|
|
313
|
+
async loadSanitizers() {
|
|
314
|
+
await loaders.loadSanitizers(this);
|
|
315
|
+
}
|
|
316
|
+
|
|
340
317
|
registerInternalHooks() {
|
|
341
318
|
this.container.get('hooks').set('strapi::content-types.beforeSync', createAsyncParallelHook());
|
|
342
319
|
this.container.get('hooks').set('strapi::content-types.afterSync', createAsyncParallelHook());
|
|
@@ -348,6 +325,7 @@ class Strapi {
|
|
|
348
325
|
async register() {
|
|
349
326
|
await Promise.all([
|
|
350
327
|
this.loadApp(),
|
|
328
|
+
this.loadSanitizers(),
|
|
351
329
|
this.loadPlugins(),
|
|
352
330
|
this.loadAdmin(),
|
|
353
331
|
this.loadAPIs(),
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const path = require('path');
|
|
4
3
|
const { yup } = require('@strapi/utils');
|
|
5
4
|
const _ = require('lodash');
|
|
6
5
|
const inquirer = require('inquirer');
|
|
7
|
-
const tsUtils = require('@strapi/typescript-utils');
|
|
8
6
|
const strapi = require('../index');
|
|
9
7
|
|
|
10
8
|
const emailValidator = yup
|
|
@@ -92,12 +90,7 @@ module.exports = async function(cmdOptions = {}) {
|
|
|
92
90
|
};
|
|
93
91
|
|
|
94
92
|
async function createAdmin({ email, password, firstname, lastname }) {
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
|
98
|
-
const distDir = isTSProject ? path.join(appDir, 'dist') : appDir;
|
|
99
|
-
|
|
100
|
-
const app = await strapi({ appDir, distDir }).load();
|
|
93
|
+
const app = await strapi().load();
|
|
101
94
|
|
|
102
95
|
const user = await app.admin.services.user.exists({ email });
|
|
103
96
|
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const path = require('path');
|
|
4
3
|
const _ = require('lodash');
|
|
5
4
|
const inquirer = require('inquirer');
|
|
6
|
-
const tsUtils = require('@strapi/typescript-utils');
|
|
7
5
|
const strapi = require('../index');
|
|
8
6
|
|
|
9
7
|
const promptQuestions = [
|
|
@@ -44,12 +42,7 @@ module.exports = async function(cmdOptions = {}) {
|
|
|
44
42
|
};
|
|
45
43
|
|
|
46
44
|
async function changePassword({ email, password }) {
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
|
50
|
-
const distDir = isTSProject ? path.join(appDir, 'dist') : appDir;
|
|
51
|
-
|
|
52
|
-
const app = await strapi({ appDir, distDir }).load();
|
|
45
|
+
const app = await strapi().load();
|
|
53
46
|
|
|
54
47
|
await app.admin.services.user.resetPasswordByEmail(email, password);
|
|
55
48
|
|
package/lib/commands/build.js
CHANGED
|
@@ -1,30 +1,56 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const
|
|
2
|
+
const { green } = require('chalk');
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
const {
|
|
4
|
+
const strapiAdmin = require('@strapi/admin');
|
|
5
|
+
const { getConfigUrls } = require('@strapi/utils');
|
|
6
|
+
|
|
7
|
+
const ee = require('../utils/ee');
|
|
8
|
+
const addSlash = require('../utils/addSlash');
|
|
9
|
+
const strapi = require('../index');
|
|
10
|
+
const getEnabledPlugins = require('../core/loaders/plugins/get-enabled-plugins');
|
|
6
11
|
|
|
7
12
|
/**
|
|
8
13
|
* `$ strapi build`
|
|
9
14
|
*/
|
|
10
15
|
module.exports = async ({ optimization, forceBuild = true }) => {
|
|
11
|
-
|
|
12
|
-
const srcDir = process.cwd();
|
|
16
|
+
const dir = process.cwd();
|
|
13
17
|
|
|
14
|
-
const
|
|
18
|
+
const strapiInstance = strapi({
|
|
19
|
+
dir,
|
|
20
|
+
autoReload: true,
|
|
21
|
+
serveAdminPanel: false,
|
|
22
|
+
});
|
|
15
23
|
|
|
16
|
-
|
|
17
|
-
if (useTypeScriptServer) {
|
|
18
|
-
await buildTypeScript({ srcDir, watch: false });
|
|
24
|
+
const plugins = await getEnabledPlugins(strapiInstance);
|
|
19
25
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
26
|
+
const env = strapiInstance.config.get('environment');
|
|
27
|
+
const { serverUrl, adminPath } = getConfigUrls(strapiInstance.config, true);
|
|
23
28
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
});
|
|
29
|
+
console.log(`Building your admin UI with ${green(env)} configuration ...`);
|
|
30
|
+
|
|
31
|
+
// Always remove the .cache and build folders
|
|
32
|
+
await strapiAdmin.clean({ dir });
|
|
33
|
+
|
|
34
|
+
ee({ dir });
|
|
35
|
+
|
|
36
|
+
return strapiAdmin
|
|
37
|
+
.build({
|
|
38
|
+
forceBuild,
|
|
39
|
+
dir,
|
|
40
|
+
plugins,
|
|
41
|
+
// front end build env is always production for now
|
|
42
|
+
env: 'production',
|
|
43
|
+
optimize: optimization,
|
|
44
|
+
options: {
|
|
45
|
+
backend: serverUrl,
|
|
46
|
+
adminPath: addSlash(adminPath),
|
|
47
|
+
},
|
|
48
|
+
})
|
|
49
|
+
.then(() => {
|
|
50
|
+
console.log('Admin UI built successfully');
|
|
51
|
+
})
|
|
52
|
+
.catch(err => {
|
|
53
|
+
console.error(err);
|
|
54
|
+
process.exit(1);
|
|
55
|
+
});
|
|
30
56
|
};
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const fs = require('fs');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const tsUtils = require('@strapi/typescript-utils');
|
|
6
4
|
const strapi = require('../index');
|
|
7
5
|
|
|
8
6
|
const CHUNK_SIZE = 100;
|
|
@@ -14,12 +12,7 @@ const CHUNK_SIZE = 100;
|
|
|
14
12
|
module.exports = async function({ file: filePath, pretty }) {
|
|
15
13
|
const output = filePath ? fs.createWriteStream(filePath) : process.stdout;
|
|
16
14
|
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
|
20
|
-
const distDir = isTSProject ? path.join(appDir, 'dist') : appDir;
|
|
21
|
-
|
|
22
|
-
const app = await strapi({ appDir, distDir }).load();
|
|
15
|
+
const app = await strapi().load();
|
|
23
16
|
|
|
24
17
|
const count = await app.query('strapi::core-store').count();
|
|
25
18
|
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const fs = require('fs');
|
|
4
|
-
const path = require('path');
|
|
5
4
|
const _ = require('lodash');
|
|
6
|
-
const tsUtils = require('@strapi/typescript-utils');
|
|
7
|
-
|
|
8
5
|
const strapi = require('../index');
|
|
9
6
|
|
|
10
7
|
/**
|
|
@@ -15,12 +12,7 @@ const strapi = require('../index');
|
|
|
15
12
|
module.exports = async function({ file: filePath, strategy = 'replace' }) {
|
|
16
13
|
const input = filePath ? fs.readFileSync(filePath) : await readStdin(process.stdin);
|
|
17
14
|
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
|
21
|
-
const distDir = isTSProject ? path.join(appDir, 'dist') : appDir;
|
|
22
|
-
|
|
23
|
-
const app = await strapi({ appDir, distDir }).load();
|
|
15
|
+
const app = await strapi().load();
|
|
24
16
|
|
|
25
17
|
let dataToImport;
|
|
26
18
|
try {
|
package/lib/commands/console.js
CHANGED
|
@@ -1,22 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const REPL = require('repl');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const tsUtils = require('@strapi/typescript-utils');
|
|
6
|
-
|
|
7
4
|
const strapi = require('../index');
|
|
8
5
|
|
|
9
6
|
/**
|
|
10
7
|
* `$ strapi console`
|
|
11
8
|
*/
|
|
12
|
-
module.exports =
|
|
9
|
+
module.exports = () => {
|
|
13
10
|
// Now load up the Strapi framework for real.
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
|
17
|
-
const distDir = isTSProject ? path.join(appDir, 'dist') : appDir;
|
|
18
|
-
|
|
19
|
-
const app = await strapi({ appDir, distDir }).load();
|
|
11
|
+
const app = strapi();
|
|
20
12
|
|
|
21
13
|
app.start().then(() => {
|
|
22
14
|
const repl = REPL.start(app.config.info.name + ' > ' || 'strapi > '); // eslint-disable-line prefer-template
|
package/lib/commands/develop.js
CHANGED
|
@@ -6,150 +6,115 @@ const fs = require('fs-extra');
|
|
|
6
6
|
const chokidar = require('chokidar');
|
|
7
7
|
const execa = require('execa');
|
|
8
8
|
const { getOr } = require('lodash/fp');
|
|
9
|
-
const { joinBy } = require('@strapi/utils');
|
|
10
|
-
const tsUtils = require('@strapi/typescript-utils');
|
|
11
9
|
|
|
10
|
+
const { createLogger } = require('@strapi/logger');
|
|
11
|
+
const { joinBy } = require('@strapi/utils');
|
|
12
12
|
const loadConfiguration = require('../core/app-configuration');
|
|
13
13
|
const strapi = require('../index');
|
|
14
|
-
const
|
|
14
|
+
const buildAdmin = require('./build');
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* `$ strapi develop`
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
|
-
|
|
21
20
|
module.exports = async function({ build, watchAdmin, polling, browser }) {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
const distDir = isTSProject ? path.join(appDir, 'dist') : appDir;
|
|
21
|
+
const dir = process.cwd();
|
|
22
|
+
const config = loadConfiguration(dir);
|
|
23
|
+
const logger = createLogger(config.logger, {});
|
|
26
24
|
|
|
27
25
|
try {
|
|
28
26
|
if (cluster.isMaster || cluster.isPrimary) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
27
|
+
const serveAdminPanel = getOr(true, 'admin.serveAdminPanel')(config);
|
|
28
|
+
|
|
29
|
+
const buildExists = fs.existsSync(path.join(dir, 'build'));
|
|
30
|
+
// Don't run the build process if the admin is in watch mode
|
|
31
|
+
if (build && !watchAdmin && serveAdminPanel && !buildExists) {
|
|
32
|
+
try {
|
|
33
|
+
await buildAdmin({ optimization: false, forceBuild: false });
|
|
34
|
+
} catch (err) {
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (watchAdmin) {
|
|
40
|
+
try {
|
|
41
|
+
execa('npm', ['run', '-s', 'strapi', 'watch-admin', '--', '--browser', browser], {
|
|
42
|
+
stdio: 'inherit',
|
|
43
|
+
});
|
|
44
|
+
} catch (err) {
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
cluster.on('message', (worker, message) => {
|
|
50
|
+
switch (message) {
|
|
51
|
+
case 'reload':
|
|
52
|
+
logger.info('The server is restarting\n');
|
|
53
|
+
worker.send('kill');
|
|
54
|
+
break;
|
|
55
|
+
case 'killed':
|
|
56
|
+
cluster.fork();
|
|
57
|
+
break;
|
|
58
|
+
case 'stop':
|
|
59
|
+
process.exit(1);
|
|
60
|
+
default:
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
36
63
|
});
|
|
37
|
-
}
|
|
38
64
|
|
|
39
|
-
|
|
40
|
-
return workerProcess({ appDir, distDir, watchAdmin, polling, isTSProject });
|
|
65
|
+
cluster.fork();
|
|
41
66
|
}
|
|
42
|
-
} catch (e) {
|
|
43
|
-
console.error(e);
|
|
44
|
-
process.exit(1);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const primaryProcess = async ({ distDir, appDir, build, isTSProject, watchAdmin, browser }) => {
|
|
49
|
-
if (isTSProject) {
|
|
50
|
-
await buildTypeScript({ srcDir: appDir, distDir, watch: false });
|
|
51
|
-
}
|
|
52
67
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
// Don't run the build process if the admin is in watch mode
|
|
59
|
-
if (build && !watchAdmin && serveAdminPanel && !buildExists) {
|
|
60
|
-
try {
|
|
61
|
-
await buildAdmin({
|
|
62
|
-
buildDestDir: distDir,
|
|
63
|
-
forceBuild: false,
|
|
64
|
-
optimization: false,
|
|
65
|
-
srcDir: appDir,
|
|
68
|
+
if (cluster.isWorker) {
|
|
69
|
+
const strapiInstance = strapi({
|
|
70
|
+
dir,
|
|
71
|
+
autoReload: true,
|
|
72
|
+
serveAdminPanel: watchAdmin ? false : true,
|
|
66
73
|
});
|
|
67
|
-
} catch (err) {
|
|
68
|
-
process.exit(1);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
74
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
const adminWatchIgnoreFiles = getOr([], 'admin.watchIgnoreFiles')(config);
|
|
76
|
+
watchFileChanges({
|
|
77
|
+
dir,
|
|
78
|
+
strapiInstance,
|
|
79
|
+
watchIgnoreFiles: adminWatchIgnoreFiles,
|
|
80
|
+
polling,
|
|
76
81
|
});
|
|
77
|
-
} catch (err) {
|
|
78
|
-
process.exit(1);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
82
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
process.on('message', async message => {
|
|
84
|
+
switch (message) {
|
|
85
|
+
case 'kill':
|
|
86
|
+
await strapiInstance.destroy();
|
|
87
|
+
process.send('killed');
|
|
88
|
+
process.exit();
|
|
89
|
+
default:
|
|
90
|
+
// Do nothing.
|
|
87
91
|
}
|
|
92
|
+
});
|
|
88
93
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
worker.send('kill');
|
|
92
|
-
break;
|
|
93
|
-
case 'killed':
|
|
94
|
-
cluster.fork();
|
|
95
|
-
break;
|
|
96
|
-
case 'stop':
|
|
97
|
-
process.exit(1);
|
|
98
|
-
default:
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
cluster.fork();
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
const workerProcess = ({ appDir, distDir, watchAdmin, polling, isTSProject }) => {
|
|
107
|
-
const strapiInstance = strapi({
|
|
108
|
-
distDir,
|
|
109
|
-
autoReload: true,
|
|
110
|
-
serveAdminPanel: watchAdmin ? false : true,
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
const adminWatchIgnoreFiles = strapiInstance.config.get('admin.watchIgnoreFiles', []);
|
|
114
|
-
watchFileChanges({
|
|
115
|
-
appDir,
|
|
116
|
-
strapiInstance,
|
|
117
|
-
watchIgnoreFiles: adminWatchIgnoreFiles,
|
|
118
|
-
polling,
|
|
119
|
-
isTSProject,
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
process.on('message', async message => {
|
|
123
|
-
switch (message) {
|
|
124
|
-
case 'kill':
|
|
125
|
-
await strapiInstance.destroy();
|
|
126
|
-
process.send('killed');
|
|
127
|
-
process.exit();
|
|
128
|
-
default:
|
|
129
|
-
// Do nothing.
|
|
94
|
+
return strapiInstance.start();
|
|
130
95
|
}
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
|
|
96
|
+
} catch (e) {
|
|
97
|
+
logger.error(e);
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
134
100
|
};
|
|
135
101
|
|
|
136
102
|
/**
|
|
137
103
|
* Init file watching to auto restart strapi app
|
|
138
104
|
* @param {Object} options - Options object
|
|
139
|
-
* @param {string} options.
|
|
105
|
+
* @param {string} options.dir - This is the path where the app is located, the watcher will watch the files under this folder
|
|
140
106
|
* @param {Strapi} options.strapi - Strapi instance
|
|
141
107
|
* @param {array} options.watchIgnoreFiles - Array of custom file paths that should not be watched
|
|
142
108
|
*/
|
|
143
|
-
function watchFileChanges({
|
|
144
|
-
const restart =
|
|
109
|
+
function watchFileChanges({ dir, strapiInstance, watchIgnoreFiles, polling }) {
|
|
110
|
+
const restart = () => {
|
|
145
111
|
if (strapiInstance.reload.isWatching && !strapiInstance.reload.isReloading) {
|
|
146
112
|
strapiInstance.reload.isReloading = true;
|
|
147
113
|
strapiInstance.reload();
|
|
148
114
|
}
|
|
149
115
|
};
|
|
150
116
|
|
|
151
|
-
|
|
152
|
-
const watcher = chokidar.watch(appDir, {
|
|
117
|
+
const watcher = chokidar.watch(dir, {
|
|
153
118
|
ignoreInitial: true,
|
|
154
119
|
usePolling: polling,
|
|
155
120
|
ignored: [
|
|
@@ -157,9 +122,6 @@ function watchFileChanges({ appDir, strapiInstance, watchIgnoreFiles, polling })
|
|
|
157
122
|
/tmp/,
|
|
158
123
|
'**/src/admin/**',
|
|
159
124
|
'**/src/plugins/**/admin/**',
|
|
160
|
-
// FIXME pass the plugin path to the strapiAdmin.build and strapiAdmin.watch in order to stop copying
|
|
161
|
-
// the FE files when using TS
|
|
162
|
-
'**/dist/src/plugins/test/admin/**',
|
|
163
125
|
'**/documentation',
|
|
164
126
|
'**/documentation/**',
|
|
165
127
|
'**/node_modules',
|
|
@@ -170,11 +132,10 @@ function watchFileChanges({ appDir, strapiInstance, watchIgnoreFiles, polling })
|
|
|
170
132
|
'**/index.html',
|
|
171
133
|
'**/public',
|
|
172
134
|
'**/public/**',
|
|
173
|
-
strapiInstance.dirs.
|
|
174
|
-
joinBy('/', strapiInstance.dirs.
|
|
135
|
+
strapiInstance.dirs.public,
|
|
136
|
+
joinBy('/', strapiInstance.dirs.public, '**'),
|
|
175
137
|
'**/*.db*',
|
|
176
138
|
'**/exports/**',
|
|
177
|
-
'**/dist/**',
|
|
178
139
|
...watchIgnoreFiles,
|
|
179
140
|
],
|
|
180
141
|
});
|
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const path = require('path');
|
|
4
3
|
const CLITable = require('cli-table3');
|
|
5
4
|
const chalk = require('chalk');
|
|
6
5
|
const { toUpper } = require('lodash/fp');
|
|
7
|
-
const tsUtils = require('@strapi/typescript-utils');
|
|
8
6
|
|
|
9
7
|
const strapi = require('../../index');
|
|
10
8
|
|
|
11
9
|
module.exports = async function() {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
|
15
|
-
const distDir = isTSProject ? path.join(appDir, 'dist') : appDir;
|
|
16
|
-
|
|
17
|
-
const app = await strapi({ appDir, distDir }).load();
|
|
10
|
+
const app = await strapi().load();
|
|
18
11
|
|
|
19
12
|
const list = app.server.listRoutes();
|
|
20
13
|
|
package/lib/commands/start.js
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
const strapi = require('../index');
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* `$ strapi start`
|
|
7
7
|
*/
|
|
8
|
-
module.exports =
|
|
9
|
-
const appDir = process.cwd();
|
|
10
|
-
const isTSProject = await tsUtils.isUsingTypeScript(appDir)
|
|
11
|
-
const distDir = isTSProject && !specifiedDir ? 'dist' : specifiedDir;
|
|
12
|
-
|
|
13
|
-
strapi({ distDir }).start()
|
|
14
|
-
};
|
|
8
|
+
module.exports = () => strapi().start();
|
|
@@ -1,22 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const path = require('path');
|
|
4
3
|
const strapiAdmin = require('@strapi/admin');
|
|
5
|
-
const tsUtils = require('@strapi/typescript-utils');
|
|
6
4
|
const { getConfigUrls, getAbsoluteServerUrl } = require('@strapi/utils');
|
|
7
5
|
|
|
8
|
-
const
|
|
6
|
+
const ee = require('../utils/ee');
|
|
9
7
|
const addSlash = require('../utils/addSlash');
|
|
10
8
|
const strapi = require('../index');
|
|
9
|
+
const getEnabledPlugins = require('../core/loaders/plugins/get-enabled-plugins');
|
|
11
10
|
|
|
12
11
|
module.exports = async function({ browser }) {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
const isTSProject = await tsUtils.isUsingTypeScript(currentDirectory);
|
|
16
|
-
const buildDestDir = isTSProject ? path.join(currentDirectory, 'dist') : currentDirectory;
|
|
12
|
+
const dir = process.cwd();
|
|
17
13
|
|
|
18
14
|
const strapiInstance = strapi({
|
|
19
|
-
|
|
15
|
+
dir,
|
|
20
16
|
autoReload: true,
|
|
21
17
|
serveAdminPanel: false,
|
|
22
18
|
});
|
|
@@ -27,12 +23,14 @@ module.exports = async function({ browser }) {
|
|
|
27
23
|
|
|
28
24
|
const adminPort = strapiInstance.config.get('admin.port', 8000);
|
|
29
25
|
const adminHost = strapiInstance.config.get('admin.host', 'localhost');
|
|
26
|
+
const adminWatchIgnoreFiles = strapiInstance.config.get('admin.watchIgnoreFiles', []);
|
|
30
27
|
|
|
31
28
|
const backendURL = getAbsoluteServerUrl(strapiInstance.config, true);
|
|
32
29
|
|
|
30
|
+
ee({ dir });
|
|
31
|
+
|
|
33
32
|
strapiAdmin.watchAdmin({
|
|
34
|
-
|
|
35
|
-
buildDestDir,
|
|
33
|
+
dir,
|
|
36
34
|
plugins,
|
|
37
35
|
port: adminPort,
|
|
38
36
|
host: adminHost,
|
|
@@ -40,6 +38,8 @@ module.exports = async function({ browser }) {
|
|
|
40
38
|
options: {
|
|
41
39
|
backend: backendURL,
|
|
42
40
|
adminPath: addSlash(adminPath),
|
|
41
|
+
watchIgnoreFiles: adminWatchIgnoreFiles,
|
|
42
|
+
features: ee.isEE ? ee.features.getEnabled() : [],
|
|
43
43
|
},
|
|
44
44
|
});
|
|
45
45
|
};
|