@strapi/admin 4.2.0-alpha.1 → 4.2.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/admin/src/app.js +7 -4
  2. package/admin/src/components/GuidedTour/Homepage/index.js +13 -3
  3. package/admin/src/components/GuidedTour/Modal/index.js +4 -1
  4. package/admin/src/components/GuidedTour/layout.js +9 -0
  5. package/admin/src/content-manager/components/Inputs/index.js +3 -4
  6. package/admin/src/pages/AuthPage/index.js +1 -0
  7. package/admin/src/translations/en.json +2 -2
  8. package/admin/src/translations/ja.json +2 -2
  9. package/admin/src/translations/ko.json +2 -2
  10. package/build/{4362.86a4e939.chunk.js → 4362.ce36d91a.chunk.js} +1 -1
  11. package/build/9260.d9bb874f.chunk.js +2 -0
  12. package/build/{9260.fa40c7bd.chunk.js.LICENSE.txt → 9260.d9bb874f.chunk.js.LICENSE.txt} +0 -0
  13. package/build/Admin-authenticatedApp.0b6b5c7e.chunk.js +1 -0
  14. package/build/Admin_homePage.fd1fc572.chunk.js +1 -0
  15. package/build/content-manager.f1c46a88.chunk.js +1 -0
  16. package/build/en-json.98c7c4be.chunk.js +1 -0
  17. package/build/index.html +1 -1
  18. package/build/ja-json.e13f04e8.chunk.js +1 -0
  19. package/build/ko-json.2200c9c9.chunk.js +1 -0
  20. package/build/{main.34ee547b.js → main.1f025df1.js} +2 -2
  21. package/build/{main.34ee547b.js.LICENSE.txt → main.1f025df1.js.LICENSE.txt} +0 -0
  22. package/build/{runtime~main.3ef9943c.js → runtime~main.53294538.js} +1 -1
  23. package/index.js +53 -244
  24. package/package.json +7 -5
  25. package/server/routes/serve-admin-panel.js +1 -1
  26. package/utils/create-cache-dir.js +119 -0
  27. package/utils/get-custom-webpack-config.js +38 -0
  28. package/utils/index.js +13 -0
  29. package/utils/should-build-admin.js +51 -0
  30. package/utils/watch-admin-files.js +56 -0
  31. package/webpack.config.js +36 -3
  32. package/build/9260.fa40c7bd.chunk.js +0 -2
  33. package/build/Admin-authenticatedApp.2d44e117.chunk.js +0 -1
  34. package/build/Admin_homePage.d6754c66.chunk.js +0 -1
  35. package/build/content-manager.de808f2c.chunk.js +0 -1
  36. package/build/en-json.b35c285f.chunk.js +0 -1
  37. package/build/ja-json.46e29f04.chunk.js +0 -1
  38. package/build/ko-json.dd36fdc0.chunk.js +0 -1
@@ -0,0 +1,51 @@
1
+ 'use strict';
2
+
3
+ const path = require('path');
4
+ const fs = require('fs-extra');
5
+
6
+ const DEFAULT_PLUGINS = [
7
+ 'content-type-builder',
8
+ 'content-manager',
9
+ 'upload',
10
+ 'email',
11
+ 'i18n',
12
+ 'users-permissions',
13
+ ];
14
+
15
+ /**
16
+ * Checks if the project's installed plugins are not the same as a default one.
17
+ * @param {Object} plugins
18
+ * @returns {boolean}
19
+ */
20
+ const hasNonDefaultPlugins = plugins => {
21
+ // List of plugins that are not the ones installed in a generated app
22
+ const installedPlugins = Object.keys(plugins).filter(x => !DEFAULT_PLUGINS.includes(x));
23
+
24
+ // List of default plugins uninstalled from a generated app
25
+ const missingPlugins = DEFAULT_PLUGINS.filter(x => !Object.keys(plugins).includes(x));
26
+
27
+ const diff = [...installedPlugins, ...missingPlugins];
28
+
29
+ return diff.length > 0;
30
+ };
31
+
32
+ const hasCustomAdminCode = async (dir, useTypeScript) => {
33
+ const customAdminPath = path.join(dir, 'src', 'admin');
34
+ const customAdminConfigFileExtension = useTypeScript ? 'app.tsx' : 'app.js';
35
+ const customAdminConfigFile = path.join(customAdminPath, customAdminConfigFileExtension);
36
+ const customAdminWebpackFile = path.join(customAdminPath, 'webpack.config.js');
37
+
38
+ const hasCustomConfigFile = await fs.pathExists(customAdminConfigFile);
39
+ const hasCustomWebpackFile = await fs.pathExists(customAdminWebpackFile);
40
+
41
+ return hasCustomConfigFile || hasCustomWebpackFile;
42
+ };
43
+
44
+ const shouldBuildAdmin = async ({ appDir, plugins, useTypeScript }) => {
45
+ const appHasCustomAdminCode = await hasCustomAdminCode(appDir, useTypeScript);
46
+ const appHasNonDefaultPlugins = hasNonDefaultPlugins(plugins);
47
+
48
+ return appHasCustomAdminCode || appHasNonDefaultPlugins;
49
+ };
50
+
51
+ module.exports = shouldBuildAdmin;
@@ -0,0 +1,56 @@
1
+ 'use strict';
2
+
3
+ const path = require('path');
4
+ const fs = require('fs-extra');
5
+ const chokidar = require('chokidar');
6
+
7
+ /**
8
+ * Listen to files change and copy the changed files in the .cache/admin folder
9
+ * when using the dev mode
10
+ * @param {string} dir
11
+ */
12
+ async function watchAdminFiles(dir, useTypeScript) {
13
+ const cacheDir = path.join(dir, '.cache');
14
+ const targetExtensionFile = useTypeScript ? 'app.tsx' : 'app.js';
15
+ const appExtensionFile = path.join(dir, 'src', 'admin', targetExtensionFile);
16
+ const extensionsPath = path.join(dir, 'src', 'admin', 'extensions');
17
+
18
+ // Only watch the admin/app.js file and the files that are in the ./admin/extensions/folder
19
+ const filesToWatch = [appExtensionFile, extensionsPath];
20
+
21
+ const watcher = chokidar.watch(filesToWatch, {
22
+ ignoreInitial: true,
23
+ ignorePermissionErrors: true,
24
+ });
25
+
26
+ watcher.on('all', async (event, filePath) => {
27
+ const isAppFile = filePath.includes(appExtensionFile);
28
+
29
+ // The app.js file needs to be copied in the .cache/admin/src/app.js and the other ones needs to
30
+ // be copied in the .cache/admin/src/extensions folder
31
+ const targetPath = isAppFile
32
+ ? path.join(path.normalize(filePath.split(appExtensionFile)[1]), targetExtensionFile)
33
+ : path.join('extensions', path.normalize(filePath.split(extensionsPath)[1]));
34
+
35
+ const destFolder = path.join(cacheDir, 'admin', 'src');
36
+
37
+ if (event === 'unlink' || event === 'unlinkDir') {
38
+ // Remove the file or folder
39
+ // We need to copy the original files when deleting an override one
40
+ try {
41
+ fs.removeSync(path.join(destFolder, targetPath));
42
+ } catch (err) {
43
+ console.log('An error occured while deleting the file', err);
44
+ }
45
+ } else {
46
+ // In any other case just copy the file into the .cache/admin/src folder
47
+ try {
48
+ await fs.copy(filePath, path.join(destFolder, targetPath));
49
+ } catch (err) {
50
+ console.log(err);
51
+ }
52
+ }
53
+ });
54
+ }
55
+
56
+ module.exports = watchAdminFiles;
package/webpack.config.js CHANGED
@@ -3,6 +3,7 @@
3
3
  const path = require('path');
4
4
  const webpack = require('webpack');
5
5
  const MiniCssExtractPlugin = require('mini-css-extract-plugin');
6
+ const ForkTsCheckerPlugin = require('fork-ts-checker-webpack-plugin');
6
7
  const HtmlWebpackPlugin = require('html-webpack-plugin');
7
8
  const TerserPlugin = require('terser-webpack-plugin');
8
9
  const WebpackBar = require('webpackbar');
@@ -12,12 +13,13 @@ const alias = require('./webpack.alias');
12
13
  const getClientEnvironment = require('./env');
13
14
 
14
15
  module.exports = ({
15
- entry,
16
+ appDir,
16
17
  cacheDir,
17
- pluginsPath,
18
18
  dest,
19
+ entry,
19
20
  env,
20
21
  optimize,
22
+ pluginsPath,
21
23
  options = {
22
24
  backend: 'http://localhost:1337',
23
25
  adminPath: '/admin/',
@@ -27,6 +29,7 @@ module.exports = ({
27
29
  eeRoot: './ee/admin',
28
30
  ceRoot: './admin/src',
29
31
  },
32
+ useTypeScript,
30
33
  }) => {
31
34
  const isProduction = env === 'production';
32
35
 
@@ -47,6 +50,35 @@ module.exports = ({
47
50
  ]
48
51
  : [];
49
52
 
53
+ if (useTypeScript) {
54
+ const tsChecker = new ForkTsCheckerPlugin({
55
+ typescript: {
56
+ // FIXME
57
+ configFile: path.join(appDir, 'tsconfig-admin.json'),
58
+ },
59
+ });
60
+
61
+ webpackPlugins.push(tsChecker);
62
+ }
63
+
64
+ const rules = [];
65
+
66
+ // webpack is quite slow to compile so it is best not to use the ts loader when
67
+ // it is not needed in javascript apps.
68
+ // Users can still add it by using the custom webpack config.
69
+ if (useTypeScript) {
70
+ rules.push({
71
+ test: /\.tsx?$/,
72
+ loader: require.resolve('esbuild-loader'),
73
+ include: [cacheDir, ...pluginsPath],
74
+ exclude: /node_modules/,
75
+ options: {
76
+ loader: 'tsx',
77
+ target: 'es2015',
78
+ },
79
+ });
80
+ }
81
+
50
82
  return {
51
83
  mode: isProduction ? 'production' : 'development',
52
84
  bail: isProduction ? true : false,
@@ -166,12 +198,13 @@ module.exports = ({
166
198
  },
167
199
  },
168
200
  },
201
+ ...rules,
169
202
  ],
170
203
  },
171
204
  resolve: {
172
205
  alias,
173
206
  symlinks: false,
174
- extensions: ['.js', '.jsx', '.react.js'],
207
+ extensions: ['.js', '.jsx', '.react.js', '.ts', '.tsx'],
175
208
  mainFields: ['browser', 'jsnext:main', 'main'],
176
209
  modules: ['node_modules', path.resolve(__dirname, 'node_modules')],
177
210
  },