@strapi/strapi 4.2.0-beta.4 → 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 +4 -42
- package/lib/commands/admin-create.js +1 -15
- package/lib/commands/admin-reset.js +1 -15
- package/lib/commands/build.js +44 -18
- package/lib/commands/configurationDump.js +1 -14
- package/lib/commands/configurationRestore.js +1 -16
- package/lib/commands/console.js +2 -16
- package/lib/commands/develop.js +74 -114
- package/lib/commands/routes/list.js +1 -15
- package/lib/commands/start.js +2 -12
- 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 +5 -6
- package/lib/core/loaders/components.js +4 -5
- 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/src-index.js +4 -6
- package/lib/core/registries/policies.d.ts +1 -1
- package/lib/core-api/controller/index.d.ts +9 -14
- package/lib/core-api/service/index.d.ts +9 -10
- package/lib/factories.d.ts +18 -22
- package/lib/index.d.ts +6 -7
- package/lib/load/load-files.js +1 -3
- package/lib/middlewares/favicon.js +1 -1
- package/lib/middlewares/public/index.js +1 -2
- 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 +1 -1
- package/package.json +13 -15
- 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/types/strapi.d.ts +0 -291
- package/lib/types/utils.d.ts +0 -1
- 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');
|
|
@@ -43,50 +42,18 @@ const sanitizersRegistry = require('./core/registries/sanitizers');
|
|
|
43
42
|
// TODO: move somewhere else
|
|
44
43
|
const draftAndPublishSync = require('./migrations/draft-publish');
|
|
45
44
|
|
|
46
|
-
/**
|
|
47
|
-
* A map of all the available Strapi lifecycles
|
|
48
|
-
* @type {import('@strapi/strapi').Core.Lifecycles}
|
|
49
|
-
*/
|
|
50
45
|
const LIFECYCLES = {
|
|
51
46
|
REGISTER: 'register',
|
|
52
47
|
BOOTSTRAP: 'bootstrap',
|
|
53
48
|
DESTROY: 'destroy',
|
|
54
49
|
};
|
|
55
50
|
|
|
56
|
-
/**
|
|
57
|
-
* Resolve the working directories based on the instance options.
|
|
58
|
-
*
|
|
59
|
-
* Behavior:
|
|
60
|
-
* - `appDir` is the directory where Strapi will write every file (schemas, generated APIs, controllers or services)
|
|
61
|
-
* - `distDir` is the directory where Strapi will read configurations, schemas and any compiled code
|
|
62
|
-
*
|
|
63
|
-
* Default values:
|
|
64
|
-
* - If `appDir` is `undefined`, it'll be set to `process.cwd()`
|
|
65
|
-
* - If `distDir` is `undefined`, it'll be set to `appDir`
|
|
66
|
-
*/
|
|
67
|
-
const resolveWorkingDirectories = opts => {
|
|
68
|
-
const cwd = process.cwd();
|
|
69
|
-
|
|
70
|
-
const appDir = opts.appDir ? path.resolve(cwd, opts.appDir) : cwd;
|
|
71
|
-
const distDir = opts.distDir ? path.resolve(cwd, opts.distDir) : appDir;
|
|
72
|
-
|
|
73
|
-
return { app: appDir, dist: distDir };
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
/** @implements {import('@strapi/strapi').Strapi} */
|
|
77
51
|
class Strapi {
|
|
78
52
|
constructor(opts = {}) {
|
|
79
53
|
destroyOnSignal(this);
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
// Load the app configuration from the dist directory
|
|
84
|
-
const appConfig = loadConfiguration({ appDir: rootDirs.app, distDir: rootDirs.dist }, opts);
|
|
85
|
-
|
|
86
|
-
// Instanciate the Strapi container
|
|
54
|
+
const rootDir = opts.dir || process.cwd();
|
|
55
|
+
const appConfig = loadConfiguration(rootDir, opts);
|
|
87
56
|
this.container = createContainer(this);
|
|
88
|
-
|
|
89
|
-
// Register every Strapi registry in the container
|
|
90
57
|
this.container.register('config', createConfigProvider(appConfig));
|
|
91
58
|
this.container.register('content-types', contentTypesRegistry(this));
|
|
92
59
|
this.container.register('services', servicesRegistry(this));
|
|
@@ -100,17 +67,12 @@ class Strapi {
|
|
|
100
67
|
this.container.register('auth', createAuth(this));
|
|
101
68
|
this.container.register('sanitizers', sanitizersRegistry(this));
|
|
102
69
|
|
|
103
|
-
|
|
104
|
-
this.dirs = utils.getDirs(rootDirs, { strapi: this });
|
|
70
|
+
this.dirs = utils.getDirs(rootDir, { strapi: this });
|
|
105
71
|
|
|
106
|
-
// Strapi state management variables
|
|
107
72
|
this.isLoaded = false;
|
|
108
73
|
this.reload = this.reload();
|
|
109
|
-
|
|
110
|
-
// Instanciate the Koa app & the HTTP server
|
|
111
74
|
this.server = createServer(this);
|
|
112
75
|
|
|
113
|
-
// Strapi utils instanciation
|
|
114
76
|
this.fs = createStrapiFs(this);
|
|
115
77
|
this.eventHub = createEventHub();
|
|
116
78
|
this.startupLogger = createStartupLogger(this);
|
|
@@ -126,7 +88,7 @@ class Strapi {
|
|
|
126
88
|
}
|
|
127
89
|
|
|
128
90
|
get EE() {
|
|
129
|
-
return ee({ dir: this.dirs.
|
|
91
|
+
return ee({ dir: this.dirs.root, logger: this.log });
|
|
130
92
|
}
|
|
131
93
|
|
|
132
94
|
get services() {
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
const { yup } = require('@strapi/utils');
|
|
4
4
|
const _ = require('lodash');
|
|
5
5
|
const inquirer = require('inquirer');
|
|
6
|
-
const tsUtils = require('@strapi/typescript-utils');
|
|
7
6
|
const strapi = require('../index');
|
|
8
7
|
|
|
9
8
|
const emailValidator = yup
|
|
@@ -91,20 +90,7 @@ module.exports = async function(cmdOptions = {}) {
|
|
|
91
90
|
};
|
|
92
91
|
|
|
93
92
|
async function createAdmin({ email, password, firstname, lastname }) {
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
|
97
|
-
const outDir = await tsUtils.resolveOutDir(appDir);
|
|
98
|
-
|
|
99
|
-
if (isTSProject)
|
|
100
|
-
await tsUtils.compile(appDir, {
|
|
101
|
-
watch: false,
|
|
102
|
-
configOptions: { options: { incremental: true } },
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
const distDir = isTSProject ? outDir : appDir;
|
|
106
|
-
|
|
107
|
-
const app = await strapi({ appDir, distDir }).load();
|
|
93
|
+
const app = await strapi().load();
|
|
108
94
|
|
|
109
95
|
const user = await app.admin.services.user.exists({ email });
|
|
110
96
|
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
const _ = require('lodash');
|
|
4
4
|
const inquirer = require('inquirer');
|
|
5
|
-
const tsUtils = require('@strapi/typescript-utils');
|
|
6
5
|
const strapi = require('../index');
|
|
7
6
|
|
|
8
7
|
const promptQuestions = [
|
|
@@ -43,20 +42,7 @@ module.exports = async function(cmdOptions = {}) {
|
|
|
43
42
|
};
|
|
44
43
|
|
|
45
44
|
async function changePassword({ email, password }) {
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
|
49
|
-
const outDir = await tsUtils.resolveOutDir(appDir);
|
|
50
|
-
|
|
51
|
-
if (isTSProject)
|
|
52
|
-
await tsUtils.compile(appDir, {
|
|
53
|
-
watch: false,
|
|
54
|
-
configOptions: { options: { incremental: true } },
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
const distDir = isTSProject ? outDir : appDir;
|
|
58
|
-
|
|
59
|
-
const app = await strapi({ appDir, distDir }).load();
|
|
45
|
+
const app = await strapi().load();
|
|
60
46
|
|
|
61
47
|
await app.admin.services.user.resetPasswordByEmail(email, password);
|
|
62
48
|
|
package/lib/commands/build.js
CHANGED
|
@@ -1,30 +1,56 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
const { green } = require('chalk');
|
|
2
3
|
|
|
3
|
-
const
|
|
4
|
-
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');
|
|
5
11
|
|
|
6
12
|
/**
|
|
7
13
|
* `$ strapi build`
|
|
8
14
|
*/
|
|
9
15
|
module.exports = async ({ optimization, forceBuild = true }) => {
|
|
10
|
-
|
|
11
|
-
const srcDir = process.cwd();
|
|
16
|
+
const dir = process.cwd();
|
|
12
17
|
|
|
13
|
-
const
|
|
14
|
-
|
|
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,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const fs = require('fs');
|
|
4
|
-
const tsUtils = require('@strapi/typescript-utils');
|
|
5
4
|
const strapi = require('../index');
|
|
6
5
|
|
|
7
6
|
const CHUNK_SIZE = 100;
|
|
@@ -13,19 +12,7 @@ const CHUNK_SIZE = 100;
|
|
|
13
12
|
module.exports = async function({ file: filePath, pretty }) {
|
|
14
13
|
const output = filePath ? fs.createWriteStream(filePath) : process.stdout;
|
|
15
14
|
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
|
19
|
-
const outDir = await tsUtils.resolveOutDir(appDir);
|
|
20
|
-
if (isTSProject)
|
|
21
|
-
await tsUtils.compile(appDir, {
|
|
22
|
-
watch: false,
|
|
23
|
-
configOptions: { options: { incremental: true } },
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
const distDir = isTSProject ? outDir : appDir;
|
|
27
|
-
|
|
28
|
-
const app = await strapi({ appDir, distDir }).load();
|
|
15
|
+
const app = await strapi().load();
|
|
29
16
|
|
|
30
17
|
const count = await app.query('strapi::core-store').count();
|
|
31
18
|
|
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const _ = require('lodash');
|
|
5
|
-
const tsUtils = require('@strapi/typescript-utils');
|
|
6
|
-
|
|
7
5
|
const strapi = require('../index');
|
|
8
6
|
|
|
9
7
|
/**
|
|
@@ -14,20 +12,7 @@ const strapi = require('../index');
|
|
|
14
12
|
module.exports = async function({ file: filePath, strategy = 'replace' }) {
|
|
15
13
|
const input = filePath ? fs.readFileSync(filePath) : await readStdin(process.stdin);
|
|
16
14
|
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
|
20
|
-
const outDir = await tsUtils.resolveOutDir(appDir);
|
|
21
|
-
|
|
22
|
-
if (isTSProject)
|
|
23
|
-
await tsUtils.compile(appDir, {
|
|
24
|
-
watch: false,
|
|
25
|
-
configOptions: { options: { incremental: true } },
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
const distDir = isTSProject ? outDir : appDir;
|
|
29
|
-
|
|
30
|
-
const app = await strapi({ appDir, distDir }).load();
|
|
15
|
+
const app = await strapi().load();
|
|
31
16
|
|
|
32
17
|
let dataToImport;
|
|
33
18
|
try {
|
package/lib/commands/console.js
CHANGED
|
@@ -1,28 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const REPL = require('repl');
|
|
4
|
-
const tsUtils = require('@strapi/typescript-utils');
|
|
5
|
-
|
|
6
4
|
const strapi = require('../index');
|
|
7
5
|
|
|
8
6
|
/**
|
|
9
7
|
* `$ strapi console`
|
|
10
8
|
*/
|
|
11
|
-
module.exports =
|
|
9
|
+
module.exports = () => {
|
|
12
10
|
// Now load up the Strapi framework for real.
|
|
13
|
-
const
|
|
14
|
-
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
|
15
|
-
const outDir = await tsUtils.resolveOutDir(appDir);
|
|
16
|
-
|
|
17
|
-
if (isTSProject)
|
|
18
|
-
await tsUtils.compile(appDir, {
|
|
19
|
-
watch: false,
|
|
20
|
-
configOptions: { options: { incremental: true } },
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
const distDir = isTSProject ? outDir : appDir;
|
|
24
|
-
|
|
25
|
-
const app = await strapi({ appDir, distDir }).load();
|
|
11
|
+
const app = strapi();
|
|
26
12
|
|
|
27
13
|
app.start().then(() => {
|
|
28
14
|
const repl = REPL.start(app.config.info.name + ' > ' || 'strapi > '); // eslint-disable-line prefer-template
|
package/lib/commands/develop.js
CHANGED
|
@@ -6,151 +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 outDir = await tsUtils.resolveOutDir(appDir);
|
|
26
|
-
const distDir = isTSProject ? outDir : appDir;
|
|
21
|
+
const dir = process.cwd();
|
|
22
|
+
const config = loadConfiguration(dir);
|
|
23
|
+
const logger = createLogger(config.logger, {});
|
|
27
24
|
|
|
28
25
|
try {
|
|
29
26
|
if (cluster.isMaster || cluster.isPrimary) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
+
}
|
|
37
63
|
});
|
|
38
|
-
}
|
|
39
64
|
|
|
40
|
-
|
|
41
|
-
return workerProcess({ appDir, distDir, watchAdmin, polling, isTSProject });
|
|
65
|
+
cluster.fork();
|
|
42
66
|
}
|
|
43
|
-
} catch (e) {
|
|
44
|
-
console.error(e);
|
|
45
|
-
process.exit(1);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const primaryProcess = async ({ distDir, appDir, build, isTSProject, watchAdmin, browser }) => {
|
|
50
|
-
if (isTSProject) {
|
|
51
|
-
await buildTypeScript({ srcDir: appDir, distDir, watch: false });
|
|
52
|
-
}
|
|
53
67
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
// Don't run the build process if the admin is in watch mode
|
|
60
|
-
if (build && !watchAdmin && serveAdminPanel && !buildExists) {
|
|
61
|
-
try {
|
|
62
|
-
await buildAdmin({
|
|
63
|
-
buildDestDir: distDir,
|
|
64
|
-
forceBuild: false,
|
|
65
|
-
optimization: false,
|
|
66
|
-
srcDir: appDir,
|
|
68
|
+
if (cluster.isWorker) {
|
|
69
|
+
const strapiInstance = strapi({
|
|
70
|
+
dir,
|
|
71
|
+
autoReload: true,
|
|
72
|
+
serveAdminPanel: watchAdmin ? false : true,
|
|
67
73
|
});
|
|
68
|
-
} catch (err) {
|
|
69
|
-
process.exit(1);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
74
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
const adminWatchIgnoreFiles = getOr([], 'admin.watchIgnoreFiles')(config);
|
|
76
|
+
watchFileChanges({
|
|
77
|
+
dir,
|
|
78
|
+
strapiInstance,
|
|
79
|
+
watchIgnoreFiles: adminWatchIgnoreFiles,
|
|
80
|
+
polling,
|
|
77
81
|
});
|
|
78
|
-
} catch (err) {
|
|
79
|
-
process.exit(1);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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.
|
|
88
91
|
}
|
|
92
|
+
});
|
|
89
93
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
worker.send('kill');
|
|
93
|
-
break;
|
|
94
|
-
case 'killed':
|
|
95
|
-
cluster.fork();
|
|
96
|
-
break;
|
|
97
|
-
case 'stop':
|
|
98
|
-
process.exit(1);
|
|
99
|
-
default:
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
cluster.fork();
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
const workerProcess = ({ appDir, distDir, watchAdmin, polling, isTSProject }) => {
|
|
108
|
-
const strapiInstance = strapi({
|
|
109
|
-
distDir,
|
|
110
|
-
autoReload: true,
|
|
111
|
-
serveAdminPanel: watchAdmin ? false : true,
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
const adminWatchIgnoreFiles = strapiInstance.config.get('admin.watchIgnoreFiles', []);
|
|
115
|
-
watchFileChanges({
|
|
116
|
-
appDir,
|
|
117
|
-
strapiInstance,
|
|
118
|
-
watchIgnoreFiles: adminWatchIgnoreFiles,
|
|
119
|
-
polling,
|
|
120
|
-
isTSProject,
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
process.on('message', async message => {
|
|
124
|
-
switch (message) {
|
|
125
|
-
case 'kill':
|
|
126
|
-
await strapiInstance.destroy();
|
|
127
|
-
process.send('killed');
|
|
128
|
-
process.exit();
|
|
129
|
-
default:
|
|
130
|
-
// Do nothing.
|
|
94
|
+
return strapiInstance.start();
|
|
131
95
|
}
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
|
|
96
|
+
} catch (e) {
|
|
97
|
+
logger.error(e);
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
135
100
|
};
|
|
136
101
|
|
|
137
102
|
/**
|
|
138
103
|
* Init file watching to auto restart strapi app
|
|
139
104
|
* @param {Object} options - Options object
|
|
140
|
-
* @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
|
|
141
106
|
* @param {Strapi} options.strapi - Strapi instance
|
|
142
107
|
* @param {array} options.watchIgnoreFiles - Array of custom file paths that should not be watched
|
|
143
108
|
*/
|
|
144
|
-
function watchFileChanges({
|
|
145
|
-
const restart =
|
|
109
|
+
function watchFileChanges({ dir, strapiInstance, watchIgnoreFiles, polling }) {
|
|
110
|
+
const restart = () => {
|
|
146
111
|
if (strapiInstance.reload.isWatching && !strapiInstance.reload.isReloading) {
|
|
147
112
|
strapiInstance.reload.isReloading = true;
|
|
148
113
|
strapiInstance.reload();
|
|
149
114
|
}
|
|
150
115
|
};
|
|
151
116
|
|
|
152
|
-
|
|
153
|
-
const watcher = chokidar.watch(appDir, {
|
|
117
|
+
const watcher = chokidar.watch(dir, {
|
|
154
118
|
ignoreInitial: true,
|
|
155
119
|
usePolling: polling,
|
|
156
120
|
ignored: [
|
|
@@ -158,9 +122,6 @@ function watchFileChanges({ appDir, strapiInstance, watchIgnoreFiles, polling })
|
|
|
158
122
|
/tmp/,
|
|
159
123
|
'**/src/admin/**',
|
|
160
124
|
'**/src/plugins/**/admin/**',
|
|
161
|
-
// FIXME pass the plugin path to the strapiAdmin.build and strapiAdmin.watch in order to stop copying
|
|
162
|
-
// the FE files when using TS
|
|
163
|
-
'**/dist/src/plugins/test/admin/**',
|
|
164
125
|
'**/documentation',
|
|
165
126
|
'**/documentation/**',
|
|
166
127
|
'**/node_modules',
|
|
@@ -171,11 +132,10 @@ function watchFileChanges({ appDir, strapiInstance, watchIgnoreFiles, polling })
|
|
|
171
132
|
'**/index.html',
|
|
172
133
|
'**/public',
|
|
173
134
|
'**/public/**',
|
|
174
|
-
strapiInstance.dirs.
|
|
175
|
-
joinBy('/', strapiInstance.dirs.
|
|
135
|
+
strapiInstance.dirs.public,
|
|
136
|
+
joinBy('/', strapiInstance.dirs.public, '**'),
|
|
176
137
|
'**/*.db*',
|
|
177
138
|
'**/exports/**',
|
|
178
|
-
'**/dist/**',
|
|
179
139
|
...watchIgnoreFiles,
|
|
180
140
|
],
|
|
181
141
|
});
|
|
@@ -3,25 +3,11 @@
|
|
|
3
3
|
const CLITable = require('cli-table3');
|
|
4
4
|
const chalk = require('chalk');
|
|
5
5
|
const { toUpper } = require('lodash/fp');
|
|
6
|
-
const tsUtils = require('@strapi/typescript-utils');
|
|
7
6
|
|
|
8
7
|
const strapi = require('../../index');
|
|
9
8
|
|
|
10
9
|
module.exports = async function() {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
|
14
|
-
const outDir = await tsUtils.resolveOutDir(appDir);
|
|
15
|
-
|
|
16
|
-
if (isTSProject)
|
|
17
|
-
await tsUtils.compile(appDir, {
|
|
18
|
-
watch: false,
|
|
19
|
-
configOptions: { options: { incremental: true } },
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
const distDir = isTSProject ? outDir : appDir;
|
|
23
|
-
|
|
24
|
-
const app = await strapi({ appDir, distDir }).load();
|
|
10
|
+
const app = await strapi().load();
|
|
25
11
|
|
|
26
12
|
const list = app.server.listRoutes();
|
|
27
13
|
|
package/lib/commands/start.js
CHANGED
|
@@ -1,18 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
3
|
-
const tsUtils = require('@strapi/typescript-utils');
|
|
2
|
+
|
|
4
3
|
const strapi = require('../index');
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* `$ strapi start`
|
|
8
7
|
*/
|
|
9
|
-
module.exports =
|
|
10
|
-
const appDir = process.cwd();
|
|
11
|
-
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
|
12
|
-
const outDir = await tsUtils.resolveOutDir(appDir);
|
|
13
|
-
const buildDirExists = fs.existsSync(outDir);
|
|
14
|
-
if (isTSProject && !buildDirExists) throw new Error(`${outDir} directory not found. Please run the build command before starting your application`);
|
|
15
|
-
const distDir = isTSProject && !specifiedDir ? outDir : specifiedDir;
|
|
16
|
-
|
|
17
|
-
strapi({ distDir }).start();
|
|
18
|
-
};
|
|
8
|
+
module.exports = () => strapi().start();
|
|
@@ -1,22 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const strapiAdmin = require('@strapi/admin');
|
|
4
|
-
const tsUtils = require('@strapi/typescript-utils');
|
|
5
4
|
const { getConfigUrls, getAbsoluteServerUrl } = require('@strapi/utils');
|
|
6
5
|
|
|
7
|
-
const
|
|
6
|
+
const ee = require('../utils/ee');
|
|
8
7
|
const addSlash = require('../utils/addSlash');
|
|
9
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
|
-
const
|
|
13
|
-
|
|
14
|
-
const isTSProject = await tsUtils.isUsingTypeScript(currentDirectory);
|
|
15
|
-
const outDir = await tsUtils.resolveOutDir(currentDirectory);
|
|
16
|
-
const buildDestDir = isTSProject ? outDir : 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
|
};
|