@strapi/strapi 4.2.1-alpha.0 → 4.3.0-beta.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/bin/strapi.js +19 -1
- package/lib/Strapi.js +37 -8
- package/lib/commands/admin-create.js +2 -1
- package/lib/commands/admin-reset.js +2 -1
- package/lib/commands/build.js +8 -46
- package/lib/commands/builders/admin.js +56 -0
- package/lib/commands/builders/index.js +9 -0
- package/lib/commands/builders/typescript.js +32 -0
- package/lib/commands/configurationDump.js +2 -1
- package/lib/commands/configurationRestore.js +3 -1
- package/lib/commands/console.js +4 -3
- package/lib/commands/content-types/generate-types.js +20 -0
- package/lib/commands/content-types/list.js +2 -1
- package/lib/commands/controllers/list.js +2 -1
- package/lib/commands/develop.js +111 -74
- package/lib/commands/hooks/list.js +2 -1
- package/lib/commands/middlewares/list.js +2 -1
- package/lib/commands/opt-in-telemetry.js +100 -0
- package/lib/commands/policies/list.js +2 -1
- package/lib/commands/routes/list.js +2 -1
- package/lib/commands/services/list.js +2 -1
- package/lib/commands/start.js +18 -2
- package/lib/commands/watchAdmin.js +5 -10
- package/lib/compile.js +20 -0
- package/lib/core/app-configuration/config-loader.js +3 -1
- package/lib/core/app-configuration/index.js +4 -3
- package/lib/core/app-configuration/load-config-file.js +3 -1
- package/lib/core/bootstrap.js +2 -2
- package/lib/core/loaders/apis.js +6 -5
- package/lib/core/loaders/components.js +5 -4
- package/lib/core/loaders/middlewares.js +4 -2
- package/lib/core/loaders/plugins/get-enabled-plugins.js +2 -1
- 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 +4 -2
- package/lib/core/loaders/src-index.js +6 -4
- package/lib/core/registries/policies.d.ts +1 -1
- package/lib/core-api/controller/index.d.ts +16 -14
- package/lib/core-api/service/index.d.ts +10 -9
- package/lib/global.d.ts +61 -0
- package/lib/index.d.ts +2 -24
- package/lib/index.js +1 -0
- package/lib/load/load-files.js +3 -1
- package/lib/middlewares/favicon.js +1 -1
- package/lib/middlewares/public/index.js +1 -1
- package/lib/services/entity-service/index.d.ts +7 -1
- package/lib/services/entity-service/index.js +11 -1
- package/lib/services/fs.js +1 -1
- package/lib/services/metrics/index.js +5 -1
- package/lib/services/metrics/sender.js +7 -0
- package/lib/services/server/middleware.js +1 -1
- package/lib/services/utils/upload-files.js +1 -1
- package/lib/types/core/attributes/base.d.ts +74 -0
- package/lib/types/core/attributes/biginteger.d.ts +22 -0
- package/lib/types/core/attributes/boolean.d.ts +20 -0
- package/lib/types/core/attributes/common.d.ts +42 -0
- package/lib/types/core/attributes/component.d.ts +41 -0
- package/lib/types/core/attributes/date-time.d.ts +22 -0
- package/lib/types/core/attributes/date.d.ts +22 -0
- package/lib/types/core/attributes/decimal.d.ts +22 -0
- package/lib/types/core/attributes/dynamic-zone.d.ts +29 -0
- package/lib/types/core/attributes/email.d.ts +24 -0
- package/lib/types/core/attributes/enumeration.d.ts +28 -0
- package/lib/types/core/attributes/float.d.ts +22 -0
- package/lib/types/core/attributes/index.d.ts +26 -0
- package/lib/types/core/attributes/integer.d.ts +22 -0
- package/lib/types/core/attributes/json.d.ts +14 -0
- package/lib/types/core/attributes/media.d.ts +36 -0
- package/lib/types/core/attributes/password.d.ts +22 -0
- package/lib/types/core/attributes/relation.d.ts +66 -0
- package/lib/types/core/attributes/richtext.d.ts +22 -0
- package/lib/types/core/attributes/string.d.ts +30 -0
- package/lib/types/core/attributes/text.d.ts +30 -0
- package/lib/types/core/attributes/time.d.ts +22 -0
- package/lib/types/core/attributes/timestamp.d.ts +22 -0
- package/lib/types/core/attributes/uid.d.ts +57 -0
- package/lib/types/core/attributes/utils.d.ts +99 -0
- package/lib/types/core/index.d.ts +3 -0
- package/lib/types/core/schemas/index.d.ts +126 -0
- package/lib/types/core/strapi/index.d.ts +370 -0
- package/lib/types/factories.d.ts +52 -0
- package/lib/types/index.d.ts +4 -0
- package/lib/types/utils.d.ts +95 -0
- package/lib/utils/get-dirs.js +24 -10
- package/lib/utils/import-default.js +10 -0
- package/lib/utils/index.js +2 -0
- package/lib/utils/lifecycles.js +15 -0
- package/lib/utils/update-notifier/index.js +1 -1
- package/package.json +19 -17
- package/lib/factories.d.ts +0 -48
package/bin/strapi.js
CHANGED
|
@@ -95,6 +95,7 @@ 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')
|
|
98
99
|
.description('Create a new application')
|
|
99
100
|
.action(require('../lib/commands/new'));
|
|
100
101
|
|
|
@@ -212,6 +213,17 @@ program
|
|
|
212
213
|
.description('List all the application content-types')
|
|
213
214
|
.action(getLocalScript('content-types/list'));
|
|
214
215
|
|
|
216
|
+
program
|
|
217
|
+
.command('content-types:generate-types')
|
|
218
|
+
.description('Generate TypeScript typings for the content-types')
|
|
219
|
+
.option(
|
|
220
|
+
'-o, --out-dir <outDir>',
|
|
221
|
+
'Specify a relative directory in which the schemas definitions will be generated'
|
|
222
|
+
)
|
|
223
|
+
.option('-f, --file <file>', 'Specify a filename to store the schemas definitions')
|
|
224
|
+
.option('--verbose', `Display more information about the types generation`, false)
|
|
225
|
+
.action(getLocalScript('content-types/generate-types'));
|
|
226
|
+
|
|
215
227
|
program
|
|
216
228
|
.command('hooks:list')
|
|
217
229
|
.description('List all the application hooks')
|
|
@@ -230,7 +242,13 @@ program
|
|
|
230
242
|
// `$ strapi opt-out-telemetry`
|
|
231
243
|
program
|
|
232
244
|
.command('telemetry:disable')
|
|
233
|
-
.description('
|
|
245
|
+
.description('Disable anonymous telemetry and metadata sending to Strapi analytics')
|
|
234
246
|
.action(getLocalScript('opt-out-telemetry'));
|
|
235
247
|
|
|
248
|
+
// `$ strapi opt-in-telemetry`
|
|
249
|
+
program
|
|
250
|
+
.command('telemetry:enable')
|
|
251
|
+
.description('Enable anonymous telemetry and metadata sending to Strapi analytics')
|
|
252
|
+
.action(getLocalScript('opt-in-telemetry'));
|
|
253
|
+
|
|
236
254
|
program.parseAsync(process.argv);
|
package/lib/Strapi.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const path = require('path');
|
|
3
4
|
const _ = require('lodash');
|
|
4
5
|
const { isFunction } = require('lodash/fp');
|
|
5
6
|
const { createLogger } = require('@strapi/logger');
|
|
@@ -23,6 +24,7 @@ const createTelemetry = require('./services/metrics');
|
|
|
23
24
|
const createAuth = require('./services/auth');
|
|
24
25
|
const createUpdateNotifier = require('./utils/update-notifier');
|
|
25
26
|
const createStartupLogger = require('./utils/startup-logger');
|
|
27
|
+
const { LIFECYCLES } = require('./utils/lifecycles');
|
|
26
28
|
const ee = require('./utils/ee');
|
|
27
29
|
const contentTypesRegistry = require('./core/registries/content-types');
|
|
28
30
|
const servicesRegistry = require('./core/registries/services');
|
|
@@ -42,18 +44,40 @@ const sanitizersRegistry = require('./core/registries/sanitizers');
|
|
|
42
44
|
// TODO: move somewhere else
|
|
43
45
|
const draftAndPublishSync = require('./migrations/draft-publish');
|
|
44
46
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Resolve the working directories based on the instance options.
|
|
49
|
+
*
|
|
50
|
+
* Behavior:
|
|
51
|
+
* - `appDir` is the directory where Strapi will write every file (schemas, generated APIs, controllers or services)
|
|
52
|
+
* - `distDir` is the directory where Strapi will read configurations, schemas and any compiled code
|
|
53
|
+
*
|
|
54
|
+
* Default values:
|
|
55
|
+
* - If `appDir` is `undefined`, it'll be set to `process.cwd()`
|
|
56
|
+
* - If `distDir` is `undefined`, it'll be set to `appDir`
|
|
57
|
+
*/
|
|
58
|
+
const resolveWorkingDirectories = opts => {
|
|
59
|
+
const cwd = process.cwd();
|
|
60
|
+
|
|
61
|
+
const appDir = opts.appDir ? path.resolve(cwd, opts.appDir) : cwd;
|
|
62
|
+
const distDir = opts.distDir ? path.resolve(cwd, opts.distDir) : appDir;
|
|
63
|
+
|
|
64
|
+
return { app: appDir, dist: distDir };
|
|
49
65
|
};
|
|
50
66
|
|
|
67
|
+
/** @implements {import('@strapi/strapi').Strapi} */
|
|
51
68
|
class Strapi {
|
|
52
69
|
constructor(opts = {}) {
|
|
53
70
|
destroyOnSignal(this);
|
|
54
|
-
|
|
55
|
-
const
|
|
71
|
+
|
|
72
|
+
const rootDirs = resolveWorkingDirectories(opts);
|
|
73
|
+
|
|
74
|
+
// Load the app configuration from the dist directory
|
|
75
|
+
const appConfig = loadConfiguration({ appDir: rootDirs.app, distDir: rootDirs.dist }, opts);
|
|
76
|
+
|
|
77
|
+
// Instanciate the Strapi container
|
|
56
78
|
this.container = createContainer(this);
|
|
79
|
+
|
|
80
|
+
// Register every Strapi registry in the container
|
|
57
81
|
this.container.register('config', createConfigProvider(appConfig));
|
|
58
82
|
this.container.register('content-types', contentTypesRegistry(this));
|
|
59
83
|
this.container.register('services', servicesRegistry(this));
|
|
@@ -67,12 +91,17 @@ class Strapi {
|
|
|
67
91
|
this.container.register('auth', createAuth(this));
|
|
68
92
|
this.container.register('sanitizers', sanitizersRegistry(this));
|
|
69
93
|
|
|
70
|
-
|
|
94
|
+
// Create a mapping of every useful directory (for the app, dist and static directories)
|
|
95
|
+
this.dirs = utils.getDirs(rootDirs, { strapi: this });
|
|
71
96
|
|
|
97
|
+
// Strapi state management variables
|
|
72
98
|
this.isLoaded = false;
|
|
73
99
|
this.reload = this.reload();
|
|
100
|
+
|
|
101
|
+
// Instanciate the Koa app & the HTTP server
|
|
74
102
|
this.server = createServer(this);
|
|
75
103
|
|
|
104
|
+
// Strapi utils instanciation
|
|
76
105
|
this.fs = createStrapiFs(this);
|
|
77
106
|
this.eventHub = createEventHub();
|
|
78
107
|
this.startupLogger = createStartupLogger(this);
|
|
@@ -88,7 +117,7 @@ class Strapi {
|
|
|
88
117
|
}
|
|
89
118
|
|
|
90
119
|
get EE() {
|
|
91
|
-
return ee({ dir: this.dirs.root, logger: this.log });
|
|
120
|
+
return ee({ dir: this.dirs.dist.root, logger: this.log });
|
|
92
121
|
}
|
|
93
122
|
|
|
94
123
|
get services() {
|
|
@@ -90,7 +90,8 @@ module.exports = async function(cmdOptions = {}) {
|
|
|
90
90
|
};
|
|
91
91
|
|
|
92
92
|
async function createAdmin({ email, password, firstname, lastname }) {
|
|
93
|
-
const
|
|
93
|
+
const appContext = await strapi.compile();
|
|
94
|
+
const app = await strapi(appContext).load();
|
|
94
95
|
|
|
95
96
|
const user = await app.admin.services.user.exists({ email });
|
|
96
97
|
|
|
@@ -42,7 +42,8 @@ module.exports = async function(cmdOptions = {}) {
|
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
async function changePassword({ email, password }) {
|
|
45
|
-
const
|
|
45
|
+
const appContext = await strapi.compile();
|
|
46
|
+
const app = await strapi(appContext).load();
|
|
46
47
|
|
|
47
48
|
await app.admin.services.user.resetPasswordByEmail(email, password);
|
|
48
49
|
|
package/lib/commands/build.js
CHANGED
|
@@ -1,56 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const { green } = require('chalk');
|
|
3
2
|
|
|
4
|
-
const
|
|
5
|
-
const {
|
|
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');
|
|
3
|
+
const strapi = require('../');
|
|
4
|
+
const { buildAdmin } = require('./builders');
|
|
11
5
|
|
|
12
6
|
/**
|
|
13
7
|
* `$ strapi build`
|
|
14
8
|
*/
|
|
15
9
|
module.exports = async ({ optimization, forceBuild = true }) => {
|
|
16
|
-
const
|
|
10
|
+
const { appDir, distDir } = await strapi.compile();
|
|
17
11
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
await buildAdmin({
|
|
13
|
+
forceBuild,
|
|
14
|
+
optimization,
|
|
15
|
+
buildDestDir: distDir,
|
|
16
|
+
srcDir: appDir,
|
|
22
17
|
});
|
|
23
|
-
|
|
24
|
-
const plugins = await getEnabledPlugins(strapiInstance);
|
|
25
|
-
|
|
26
|
-
const env = strapiInstance.config.get('environment');
|
|
27
|
-
const { serverUrl, adminPath } = getConfigUrls(strapiInstance.config, true);
|
|
28
|
-
|
|
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
|
-
});
|
|
56
18
|
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { green } = require('chalk');
|
|
4
|
+
|
|
5
|
+
const strapiAdmin = require('@strapi/admin');
|
|
6
|
+
const { getConfigUrls } = require('@strapi/utils');
|
|
7
|
+
|
|
8
|
+
const ee = require('../../utils/ee');
|
|
9
|
+
const addSlash = require('../../utils/addSlash');
|
|
10
|
+
const strapi = require('../../index');
|
|
11
|
+
const getEnabledPlugins = require('../../core/loaders/plugins/get-enabled-plugins');
|
|
12
|
+
|
|
13
|
+
module.exports = async ({ buildDestDir, forceBuild = true, optimization, srcDir }) => {
|
|
14
|
+
const strapiInstance = strapi({
|
|
15
|
+
// Directories
|
|
16
|
+
appDir: srcDir,
|
|
17
|
+
distDir: buildDestDir,
|
|
18
|
+
// Options
|
|
19
|
+
autoReload: true,
|
|
20
|
+
serveAdminPanel: false,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const plugins = await getEnabledPlugins(strapiInstance);
|
|
24
|
+
|
|
25
|
+
const env = strapiInstance.config.get('environment');
|
|
26
|
+
const { serverUrl, adminPath } = getConfigUrls(strapiInstance.config, true);
|
|
27
|
+
|
|
28
|
+
console.log(`Building your admin UI with ${green(env)} configuration...`);
|
|
29
|
+
|
|
30
|
+
// Always remove the .cache and build folders
|
|
31
|
+
await strapiAdmin.clean({ appDir: srcDir, buildDestDir });
|
|
32
|
+
|
|
33
|
+
ee({ dir: srcDir });
|
|
34
|
+
|
|
35
|
+
return strapiAdmin
|
|
36
|
+
.build({
|
|
37
|
+
appDir: srcDir,
|
|
38
|
+
buildDestDir,
|
|
39
|
+
// front end build env is always production for now
|
|
40
|
+
env: 'production',
|
|
41
|
+
forceBuild,
|
|
42
|
+
plugins,
|
|
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
|
+
});
|
|
56
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const fs = require('fs-extra');
|
|
5
|
+
const tsUtils = require('@strapi/typescript-utils');
|
|
6
|
+
|
|
7
|
+
const cleanupDistDirectory = async distDir => {
|
|
8
|
+
if (!(await fs.pathExists(distDir))) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const dirContent = await fs.readdir(distDir);
|
|
13
|
+
const validFilenames = dirContent
|
|
14
|
+
// Ignore the admin build folder
|
|
15
|
+
.filter(filename => filename !== 'build');
|
|
16
|
+
|
|
17
|
+
for (const filename of validFilenames) {
|
|
18
|
+
await fs.remove(path.resolve(distDir, filename));
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
module.exports = async ({ srcDir, distDir, watch = false }) => {
|
|
23
|
+
const isTSProject = await tsUtils.isUsingTypeScript(srcDir);
|
|
24
|
+
|
|
25
|
+
if (!isTSProject) {
|
|
26
|
+
throw new Error(`tsconfig file not found in ${srcDir}`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
await cleanupDistDirectory(distDir);
|
|
30
|
+
|
|
31
|
+
return tsUtils.compile(srcDir, { watch });
|
|
32
|
+
};
|
|
@@ -12,7 +12,8 @@ const CHUNK_SIZE = 100;
|
|
|
12
12
|
module.exports = async function({ file: filePath, pretty }) {
|
|
13
13
|
const output = filePath ? fs.createWriteStream(filePath) : process.stdout;
|
|
14
14
|
|
|
15
|
-
const
|
|
15
|
+
const appContext = await strapi.compile();
|
|
16
|
+
const app = await strapi(appContext).load();
|
|
16
17
|
|
|
17
18
|
const count = await app.query('strapi::core-store').count();
|
|
18
19
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const _ = require('lodash');
|
|
5
|
+
|
|
5
6
|
const strapi = require('../index');
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -12,7 +13,8 @@ const strapi = require('../index');
|
|
|
12
13
|
module.exports = async function({ file: filePath, strategy = 'replace' }) {
|
|
13
14
|
const input = filePath ? fs.readFileSync(filePath) : await readStdin(process.stdin);
|
|
14
15
|
|
|
15
|
-
const
|
|
16
|
+
const appContext = await strapi.compile();
|
|
17
|
+
const app = await strapi(appContext).load();
|
|
16
18
|
|
|
17
19
|
let dataToImport;
|
|
18
20
|
try {
|
package/lib/commands/console.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const REPL = require('repl');
|
|
4
|
+
|
|
4
5
|
const strapi = require('../index');
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* `$ strapi console`
|
|
8
9
|
*/
|
|
9
|
-
module.exports = () => {
|
|
10
|
-
|
|
11
|
-
const app = strapi();
|
|
10
|
+
module.exports = async () => {
|
|
11
|
+
const appContext = await strapi.compile();
|
|
12
|
+
const app = await strapi(appContext).load();
|
|
12
13
|
|
|
13
14
|
app.start().then(() => {
|
|
14
15
|
const repl = REPL.start(app.config.info.name + ' > ' || 'strapi > '); // eslint-disable-line prefer-template
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const tsUtils = require('@strapi/typescript-utils');
|
|
4
|
+
|
|
5
|
+
const strapi = require('../../index');
|
|
6
|
+
|
|
7
|
+
module.exports = async function({ outDir, file, verbose }) {
|
|
8
|
+
const appContext = await strapi.compile();
|
|
9
|
+
const app = await strapi(appContext).register();
|
|
10
|
+
|
|
11
|
+
await tsUtils.generators.generateSchemasDefinitions({
|
|
12
|
+
strapi: app,
|
|
13
|
+
outDir: outDir || appContext.appDir,
|
|
14
|
+
file,
|
|
15
|
+
dirs: appContext,
|
|
16
|
+
verbose,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
app.destroy();
|
|
20
|
+
};
|
|
@@ -6,7 +6,8 @@ const chalk = require('chalk');
|
|
|
6
6
|
const strapi = require('../../index');
|
|
7
7
|
|
|
8
8
|
module.exports = async function() {
|
|
9
|
-
const
|
|
9
|
+
const appContext = await strapi.compile();
|
|
10
|
+
const app = await strapi(appContext).register();
|
|
10
11
|
|
|
11
12
|
const list = app.container.get('content-types').keys();
|
|
12
13
|
|
|
@@ -6,7 +6,8 @@ const chalk = require('chalk');
|
|
|
6
6
|
const strapi = require('../../index');
|
|
7
7
|
|
|
8
8
|
module.exports = async function() {
|
|
9
|
-
const
|
|
9
|
+
const appContext = await strapi.compile();
|
|
10
|
+
const app = await strapi(appContext).register();
|
|
10
11
|
|
|
11
12
|
const list = app.container.get('controllers').keys();
|
|
12
13
|
|
package/lib/commands/develop.js
CHANGED
|
@@ -6,115 +6,150 @@ 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
|
-
|
|
10
|
-
const { createLogger } = require('@strapi/logger');
|
|
11
9
|
const { joinBy } = require('@strapi/utils');
|
|
10
|
+
const tsUtils = require('@strapi/typescript-utils');
|
|
11
|
+
|
|
12
12
|
const loadConfiguration = require('../core/app-configuration');
|
|
13
13
|
const strapi = require('../index');
|
|
14
|
-
const buildAdmin = require('./
|
|
14
|
+
const { buildTypeScript, buildAdmin } = require('./builders');
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* `$ strapi develop`
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
|
+
|
|
20
21
|
module.exports = async function({ build, watchAdmin, polling, browser }) {
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
const
|
|
22
|
+
const appDir = process.cwd();
|
|
23
|
+
|
|
24
|
+
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
|
|
25
|
+
const outDir = await tsUtils.resolveOutDir(appDir);
|
|
26
|
+
const distDir = isTSProject ? outDir : appDir;
|
|
24
27
|
|
|
25
28
|
try {
|
|
26
29
|
if (cluster.isMaster || cluster.isPrimary) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
}
|
|
30
|
+
return primaryProcess({
|
|
31
|
+
distDir,
|
|
32
|
+
appDir,
|
|
33
|
+
build,
|
|
34
|
+
browser,
|
|
35
|
+
isTSProject,
|
|
36
|
+
watchAdmin,
|
|
63
37
|
});
|
|
64
|
-
|
|
65
|
-
cluster.fork();
|
|
66
38
|
}
|
|
67
39
|
|
|
68
40
|
if (cluster.isWorker) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
41
|
+
return workerProcess({ appDir, distDir, watchAdmin, polling, isTSProject });
|
|
42
|
+
}
|
|
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
|
+
|
|
54
|
+
const config = loadConfiguration({ appDir, distDir });
|
|
55
|
+
const serveAdminPanel = getOr(true, 'admin.serveAdminPanel')(config);
|
|
56
|
+
|
|
57
|
+
const buildExists = fs.existsSync(path.join(distDir, 'build'));
|
|
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,
|
|
73
67
|
});
|
|
68
|
+
} catch (err) {
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
74
72
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
watchIgnoreFiles: adminWatchIgnoreFiles,
|
|
80
|
-
polling,
|
|
73
|
+
if (watchAdmin) {
|
|
74
|
+
try {
|
|
75
|
+
execa('npm', ['run', '-s', 'strapi', 'watch-admin', '--', '--browser', browser], {
|
|
76
|
+
stdio: 'inherit',
|
|
81
77
|
});
|
|
78
|
+
} catch (err) {
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
process.exit();
|
|
89
|
-
default:
|
|
90
|
-
// Do nothing.
|
|
83
|
+
cluster.on('message', async (worker, message) => {
|
|
84
|
+
switch (message) {
|
|
85
|
+
case 'reload':
|
|
86
|
+
if (isTSProject) {
|
|
87
|
+
await buildTypeScript({ srcDir: appDir, distDir, watch: false });
|
|
91
88
|
}
|
|
92
|
-
});
|
|
93
89
|
|
|
94
|
-
|
|
90
|
+
console.info('The server is restarting\n');
|
|
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;
|
|
95
101
|
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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.
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
return strapiInstance.start();
|
|
100
135
|
};
|
|
101
136
|
|
|
102
137
|
/**
|
|
103
138
|
* Init file watching to auto restart strapi app
|
|
104
139
|
* @param {Object} options - Options object
|
|
105
|
-
* @param {string} options.
|
|
140
|
+
* @param {string} options.appDir - This is the path where the app is located, the watcher will watch the files under this folder
|
|
106
141
|
* @param {Strapi} options.strapi - Strapi instance
|
|
107
142
|
* @param {array} options.watchIgnoreFiles - Array of custom file paths that should not be watched
|
|
108
143
|
*/
|
|
109
|
-
function watchFileChanges({
|
|
110
|
-
const restart = () => {
|
|
144
|
+
function watchFileChanges({ appDir, strapiInstance, watchIgnoreFiles, polling }) {
|
|
145
|
+
const restart = async () => {
|
|
111
146
|
if (strapiInstance.reload.isWatching && !strapiInstance.reload.isReloading) {
|
|
112
147
|
strapiInstance.reload.isReloading = true;
|
|
113
148
|
strapiInstance.reload();
|
|
114
149
|
}
|
|
115
150
|
};
|
|
116
151
|
|
|
117
|
-
const watcher = chokidar.watch(
|
|
152
|
+
const watcher = chokidar.watch(appDir, {
|
|
118
153
|
ignoreInitial: true,
|
|
119
154
|
usePolling: polling,
|
|
120
155
|
ignored: [
|
|
@@ -122,6 +157,7 @@ function watchFileChanges({ dir, strapiInstance, watchIgnoreFiles, polling }) {
|
|
|
122
157
|
/tmp/,
|
|
123
158
|
'**/src/admin/**',
|
|
124
159
|
'**/src/plugins/**/admin/**',
|
|
160
|
+
'**/dist/src/plugins/test/admin/**',
|
|
125
161
|
'**/documentation',
|
|
126
162
|
'**/documentation/**',
|
|
127
163
|
'**/node_modules',
|
|
@@ -132,10 +168,11 @@ function watchFileChanges({ dir, strapiInstance, watchIgnoreFiles, polling }) {
|
|
|
132
168
|
'**/index.html',
|
|
133
169
|
'**/public',
|
|
134
170
|
'**/public/**',
|
|
135
|
-
strapiInstance.dirs.public,
|
|
136
|
-
joinBy('/', strapiInstance.dirs.public, '**'),
|
|
171
|
+
strapiInstance.dirs.static.public,
|
|
172
|
+
joinBy('/', strapiInstance.dirs.static.public, '**'),
|
|
137
173
|
'**/*.db*',
|
|
138
174
|
'**/exports/**',
|
|
175
|
+
'**/dist/**',
|
|
139
176
|
...watchIgnoreFiles,
|
|
140
177
|
],
|
|
141
178
|
});
|
|
@@ -6,7 +6,8 @@ const chalk = require('chalk');
|
|
|
6
6
|
const strapi = require('../../index');
|
|
7
7
|
|
|
8
8
|
module.exports = async function() {
|
|
9
|
-
const
|
|
9
|
+
const appContext = await strapi.compile();
|
|
10
|
+
const app = await strapi(appContext).register();
|
|
10
11
|
|
|
11
12
|
const list = app.container.get('hooks').keys();
|
|
12
13
|
|
|
@@ -6,7 +6,8 @@ const chalk = require('chalk');
|
|
|
6
6
|
const strapi = require('../../index');
|
|
7
7
|
|
|
8
8
|
module.exports = async function() {
|
|
9
|
-
const
|
|
9
|
+
const appContext = await strapi.compile();
|
|
10
|
+
const app = await strapi(appContext).register();
|
|
10
11
|
|
|
11
12
|
const list = app.container.get('middlewares').keys();
|
|
12
13
|
|