@strapi/admin 4.2.0-beta.4 → 4.2.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.
Files changed (151) hide show
  1. package/admin/src/app.js +4 -7
  2. package/admin/src/components/OverlayBlocker/index.js +4 -0
  3. package/admin/src/content-manager/components/Wysiwyg/EditorStylesContainer.js +1 -1
  4. package/admin/src/hooks/{useFetchInstalledPlugins → useFetchEnabledPlugins}/index.js +4 -4
  5. package/admin/src/hooks/{useFetchInstalledPlugins → useFetchEnabledPlugins}/utils/api.js +2 -2
  6. package/admin/src/hooks/useFetchMarketplaceProviders/index.js +23 -0
  7. package/admin/src/hooks/useFetchMarketplaceProviders/utils/api.js +11 -0
  8. package/admin/src/pages/Admin/index.js +5 -15
  9. package/admin/src/pages/App/index.js +3 -17
  10. package/admin/src/pages/InstalledPluginsPage/Plugins.js +2 -2
  11. package/admin/src/pages/MarketplacePage/components/{EmptyPluginSearch/EmptyPluginGrid.js → EmptyNpmPackageSearch/EmptyNpmPackageGrid.js} +1 -1
  12. package/admin/src/pages/MarketplacePage/components/{EmptyPluginSearch → EmptyNpmPackageSearch}/index.js +6 -4
  13. package/admin/src/pages/MarketplacePage/components/{PluginCard → NpmPackageCard}/InstallPluginButton.js +0 -0
  14. package/admin/src/pages/MarketplacePage/components/{PluginCard → NpmPackageCard}/index.js +22 -11
  15. package/admin/src/pages/MarketplacePage/components/NpmPackagesGrid/index.js +48 -0
  16. package/admin/src/pages/MarketplacePage/components/PageHeader/index.js +12 -5
  17. package/admin/src/pages/MarketplacePage/index.js +91 -59
  18. package/admin/src/reducers.js +2 -4
  19. package/admin/src/translations/en.json +7 -3
  20. package/admin/src/translations/hi.json +699 -0
  21. package/admin/src/translations/languageNativeNames.js +1 -0
  22. package/admin/src/translations/pl.json +335 -78
  23. package/admin/src/translations/vi.json +17 -17
  24. package/admin/src/translations/zh-Hans.json +28 -1
  25. package/build/1856.6a94980b.chunk.js +172 -0
  26. package/build/2077.5456ccd1.chunk.js +194 -0
  27. package/build/2758.9475712b.chunk.js +162 -0
  28. package/build/2912.dd031292.chunk.js +253 -0
  29. package/build/4715.a6e62860.chunk.js +385 -0
  30. package/build/4982.c57c5675.chunk.js +308 -0
  31. package/build/7197.74d81c4c.chunk.js +113 -0
  32. package/build/{6229.a5cca9f2.chunk.js → 7589.77ef4fbf.chunk.js} +2 -2
  33. package/build/{472.0350a5bd.chunk.js → 7757.f6eb5e92.chunk.js} +58 -58
  34. package/build/7841.9e9cf739.chunk.js +253 -0
  35. package/build/8681.2fd4020a.chunk.js +163 -0
  36. package/build/9066.2847fdff.chunk.js +101 -0
  37. package/build/{4073.e144a91a.chunk.js → 9115.623dc4f7.chunk.js} +1 -1
  38. package/build/9158.c5f772d6.chunk.js +503 -0
  39. package/build/{9298.aff28744.chunk.js → 9298.cb3b6bc1.chunk.js} +93 -93
  40. package/build/9420.ba035f29.chunk.js +508 -0
  41. package/build/Admin-authenticatedApp.2a22d6f4.chunk.js +80 -0
  42. package/build/{Admin_homePage.0ac648e8.chunk.js → Admin_homePage.447df176.chunk.js} +1 -1
  43. package/build/Admin_marketplace.0724f650.chunk.js +11 -0
  44. package/build/Admin_pluginsPage.6f1187fe.chunk.js +1 -0
  45. package/build/{Admin_profilePage.27191ed2.chunk.js → Admin_profilePage.249cbfc9.chunk.js} +2 -2
  46. package/build/Admin_settingsPage.0d138832.chunk.js +180 -0
  47. package/build/{admin-edit-roles-page.fb374555.chunk.js → admin-edit-roles-page.7c2c9752.chunk.js} +1 -1
  48. package/build/admin-edit-users.b835bc48.chunk.js +11 -0
  49. package/build/admin-users.19900b75.chunk.js +12 -0
  50. package/build/{api-tokens-create-page.698f132d.chunk.js → api-tokens-create-page.8d299dde.chunk.js} +1 -1
  51. package/build/{api-tokens-edit-page.afece2fe.chunk.js → api-tokens-edit-page.3e453fc1.chunk.js} +1 -1
  52. package/build/{api-tokens-list-page.46d96dee.chunk.js → api-tokens-list-page.872c3800.chunk.js} +1 -1
  53. package/build/{codemirror-css.b467b1de.chunk.js → codemirror-css.98490df3.chunk.js} +2 -2
  54. package/build/{codemirror-javacript.41bdefda.chunk.js → codemirror-javacript.cafbda9c.chunk.js} +1 -1
  55. package/build/codemirror-theme.b3c64617.chunk.js +34 -0
  56. package/build/{content-manager.7cd28f84.chunk.js → content-manager.18834aa8.chunk.js} +10 -10
  57. package/build/content-type-builder-translation-pl-json.4a42349b.chunk.js +1 -0
  58. package/build/content-type-builder.55dd9554.chunk.js +142 -0
  59. package/build/{cropper-css.ecc0d670.chunk.js → cropper-css.0055cd53.chunk.js} +2 -2
  60. package/build/email-settings-page.1f235173.chunk.js +103 -0
  61. package/build/email-translation-pl-json.a03bcf98.chunk.js +1 -0
  62. package/build/en-json.0a5ba154.chunk.js +1 -0
  63. package/build/{fontawesome-css-all.04f33619.chunk.js → fontawesome-css-all.b88d464e.chunk.js} +3 -3
  64. package/build/{fontawesome-css.477ba714.chunk.js → fontawesome-css.a92a7b6c.chunk.js} +2 -2
  65. package/build/hi-json.b4ae16d1.chunk.js +1 -0
  66. package/build/highlight.js.9d8ef460.chunk.js +86 -0
  67. package/build/i18n-settings-page.06e88cf2.chunk.js +101 -0
  68. package/build/i18n-translation-pl-json.cea5bf23.chunk.js +1 -0
  69. package/build/index.html +1 -1
  70. package/build/main.fcb539e3.js +8406 -0
  71. package/build/pl-json.4d11f53d.chunk.js +1 -0
  72. package/build/runtime~main.ade14a85.js +2 -0
  73. package/build/sso-settings-page.a7c2e854.chunk.js +1 -0
  74. package/build/upload-settings.4ee2f135.chunk.js +101 -0
  75. package/build/upload-translation-pl-json.bb2aa937.chunk.js +1 -0
  76. package/build/upload.0d4153e8.chunk.js +105 -0
  77. package/build/users-advanced-settings-page.583c5dda.chunk.js +101 -0
  78. package/build/users-email-settings-page.8b9a266d.chunk.js +1 -0
  79. package/build/users-permissions-translation-en-json.765abf48.chunk.js +1 -0
  80. package/build/users-permissions-translation-pl-json.1dbdd4a1.chunk.js +1 -0
  81. package/build/users-providers-settings-page.fc9d8f9d.chunk.js +1 -0
  82. package/build/{users-roles-settings-page.988ebc3b.chunk.js → users-roles-settings-page.1bf4ffc5.chunk.js} +2 -2
  83. package/build/vi-json.bf3424be.chunk.js +1 -0
  84. package/build/{webhook-edit-page.a7ae6e3b.chunk.js → webhook-edit-page.142b23ac.chunk.js} +2 -2
  85. package/build/webhook-list-page.671582a0.chunk.js +133 -0
  86. package/build/zh-Hans-json.562f3b6f.chunk.js +1 -0
  87. package/index.js +239 -53
  88. package/package.json +9 -11
  89. package/scripts/build.js +3 -17
  90. package/server/controllers/admin.js +2 -15
  91. package/server/policies/index.js +0 -1
  92. package/server/routes/admin.js +0 -9
  93. package/server/routes/serve-admin-panel.js +1 -1
  94. package/webpack.alias.js +30 -19
  95. package/webpack.config.js +9 -29
  96. package/admin/src/pages/App/constants.js +0 -1
  97. package/admin/src/pages/App/reducer.js +0 -22
  98. package/admin/src/pages/MarketplacePage/utils/api.js +0 -9
  99. package/admin/src/tsconfig.json +0 -10
  100. package/build/1541.6c1c96f9.chunk.js +0 -307
  101. package/build/1856.521a99fd.chunk.js +0 -172
  102. package/build/2077.51485bfb.chunk.js +0 -194
  103. package/build/2912.79c2b3c8.chunk.js +0 -253
  104. package/build/3214.9196aeff.chunk.js +0 -235
  105. package/build/3865.21cec9de.chunk.js +0 -310
  106. package/build/4715.77e04177.chunk.js +0 -385
  107. package/build/4982.f53b78a4.chunk.js +0 -308
  108. package/build/7351.b95e65ae.chunk.js +0 -428
  109. package/build/7418.6db737ce.chunk.js +0 -112
  110. package/build/7841.f0e7d629.chunk.js +0 -253
  111. package/build/8826.58e236d4.chunk.js +0 -1057
  112. package/build/9066.118ecccd.chunk.js +0 -101
  113. package/build/9420.cb0b75e8.chunk.js +0 -508
  114. package/build/9988.f84412d9.chunk.js +0 -162
  115. package/build/Admin-authenticatedApp.162a5805.chunk.js +0 -80
  116. package/build/Admin_marketplace.0bb91ec8.chunk.js +0 -11
  117. package/build/Admin_pluginsPage.788fb2f6.chunk.js +0 -1
  118. package/build/Admin_settingsPage.23e873f0.chunk.js +0 -178
  119. package/build/admin-edit-users.a360deaf.chunk.js +0 -10
  120. package/build/admin-users.47d06d24.chunk.js +0 -11
  121. package/build/codemirror-theme.cf9f9eb6.chunk.js +0 -34
  122. package/build/content-type-builder-translation-pl-json.a866acda.chunk.js +0 -1
  123. package/build/content-type-builder.7456cabe.chunk.js +0 -141
  124. package/build/email-settings-page.f67d13b2.chunk.js +0 -103
  125. package/build/email-translation-pl-json.6da50d0f.chunk.js +0 -1
  126. package/build/en-json.40ee00aa.chunk.js +0 -1
  127. package/build/highlight.js.3381ffc3.chunk.js +0 -86
  128. package/build/i18n-settings-page.6b67cb75.chunk.js +0 -101
  129. package/build/main.b632a0d6.js +0 -11625
  130. package/build/pl-json.94f05d2c.chunk.js +0 -1
  131. package/build/runtime~main.38d418e9.js +0 -2
  132. package/build/sso-settings-page.dfb0b917.chunk.js +0 -1
  133. package/build/upload-settings.3db55de0.chunk.js +0 -101
  134. package/build/upload-translation-pl-json.6071e38c.chunk.js +0 -1
  135. package/build/upload.070c189b.chunk.js +0 -105
  136. package/build/users-advanced-settings-page.a23cda17.chunk.js +0 -101
  137. package/build/users-email-settings-page.0a096388.chunk.js +0 -1
  138. package/build/users-permissions-translation-en-json.3fe86528.chunk.js +0 -1
  139. package/build/users-permissions-translation-pl-json.3c4fe81c.chunk.js +0 -1
  140. package/build/users-providers-settings-page.bfe7755a.chunk.js +0 -1
  141. package/build/vi-json.3d14e91e.chunk.js +0 -1
  142. package/build/webhook-list-page.83297d98.chunk.js +0 -133
  143. package/build/zh-Hans-json.c84ce330.chunk.js +0 -1
  144. package/server/policies/isTelemetryEnabled.js +0 -16
  145. package/utils/create-cache-dir.js +0 -161
  146. package/utils/get-custom-app-config-file.js +0 -23
  147. package/utils/get-custom-webpack-config.js +0 -38
  148. package/utils/get-plugins-path.js +0 -26
  149. package/utils/index.js +0 -13
  150. package/utils/should-build-admin.js +0 -52
  151. package/utils/watch-admin-files.js +0 -59
@@ -1,161 +0,0 @@
1
- 'use strict';
2
-
3
- const path = require('path');
4
- const _ = require('lodash');
5
- const fs = require('fs-extra');
6
- const { isUsingTypeScript } = require('@strapi/typescript-utils');
7
- const getCustomAppConfigFile = require('./get-custom-app-config-file');
8
-
9
- const getPkgPath = name => path.dirname(require.resolve(`${name}/package.json`));
10
-
11
- async function createPluginsJs(plugins, dest) {
12
- const pluginsArray = plugins.map(({ pathToPlugin, name }) => {
13
- const shortName = _.camelCase(name);
14
-
15
- /**
16
- * path.join, on windows, it uses backslashes to resolve path.
17
- * The problem is that Webpack does not windows paths
18
- * With this tool, we need to rely on "/" and not "\".
19
- * This is the reason why '..\\..\\..\\node_modules\\@strapi\\plugin-content-type-builder/strapi-admin.js' was not working.
20
- * The regexp at line 105 aims to replace the windows backslashes by standard slash so that webpack can deal with them.
21
- * Backslash looks to work only for absolute paths with webpack => https://webpack.js.org/concepts/module-resolution/#absolute-paths
22
- */
23
- const realPath = path
24
- .join(path.relative(path.resolve(dest, 'admin', 'src'), pathToPlugin), 'strapi-admin.js')
25
- .replace(/\\/g, '/');
26
-
27
- return {
28
- name,
29
- pathToPlugin: realPath,
30
- shortName,
31
- };
32
- });
33
-
34
- const content = `
35
- ${pluginsArray
36
- .map(({ pathToPlugin, shortName }) => {
37
- const req = `'${pathToPlugin}'`;
38
-
39
- return `import ${shortName} from ${req};`;
40
- })
41
- .join('\n')}
42
-
43
-
44
- const plugins = {
45
- ${[...pluginsArray]
46
- .map(({ name, shortName }) => {
47
- return ` '${name}': ${shortName},`;
48
- })
49
- .join('\n')}
50
- };
51
-
52
- export default plugins;
53
- `;
54
-
55
- return fs.writeFile(path.resolve(dest, 'admin', 'src', 'plugins.js'), content);
56
- }
57
-
58
- async function copyAdmin(dest) {
59
- const adminPath = getPkgPath('@strapi/admin');
60
-
61
- // TODO copy ee folders for plugins
62
- await fs.copy(path.resolve(adminPath, 'ee', 'admin'), path.resolve(dest, 'ee', 'admin'));
63
-
64
- await fs.ensureDir(path.resolve(dest, 'config'));
65
- await fs.copy(path.resolve(adminPath, 'admin'), path.resolve(dest, 'admin'));
66
-
67
- // Copy package.json
68
- await fs.copy(path.resolve(adminPath, 'package.json'), path.resolve(dest, 'package.json'));
69
- }
70
-
71
- async function createCacheDir({ appDir, plugins }) {
72
- const cacheDir = path.resolve(appDir, '.cache');
73
-
74
- const useTypeScript = await isUsingTypeScript(path.join(appDir, 'src', 'admin'), 'tsconfig.json');
75
-
76
- const pluginsWithFront = Object.keys(plugins)
77
- .filter(pluginName => {
78
- const pluginInfo = plugins[pluginName];
79
- return fs.existsSync(path.resolve(pluginInfo.pathToPlugin, 'strapi-admin.js'));
80
- })
81
- .map(name => ({ name, ...plugins[name] }));
82
-
83
- // create .cache dir
84
- await fs.emptyDir(cacheDir);
85
-
86
- // copy admin core code
87
- await copyAdmin(cacheDir);
88
-
89
- // Retrieve the custom config file extension
90
- const customAdminAppConfigFile = await getCustomAppConfigFile(appDir, useTypeScript);
91
-
92
- if (customAdminAppConfigFile) {
93
- const defaultAdminConfigFilePath = path.resolve(cacheDir, 'admin', 'src', 'app.js');
94
- const customAdminAppConfigFilePath = path.join(
95
- appDir,
96
- 'src',
97
- 'admin',
98
- customAdminAppConfigFile
99
- );
100
- const dest = path.resolve(cacheDir, 'admin', 'src', customAdminAppConfigFile);
101
-
102
- if (useTypeScript) {
103
- // Remove the default config file
104
- await fs.remove(defaultAdminConfigFilePath);
105
- // Copy the custom one
106
- await fs.copy(customAdminAppConfigFilePath, dest);
107
- } else {
108
- await fs.copy(customAdminAppConfigFilePath, dest);
109
- }
110
- }
111
-
112
- // Copy admin extensions folder
113
- const adminExtensionFolder = path.join(appDir, 'src', 'admin', 'extensions');
114
-
115
- if (fs.existsSync(adminExtensionFolder)) {
116
- await fs.copy(adminExtensionFolder, path.resolve(cacheDir, 'admin', 'src', 'extensions'));
117
- }
118
-
119
- // create plugins.js with plugins requires
120
- await createPluginsJs(pluginsWithFront, cacheDir);
121
-
122
- // create the tsconfig.json file so we can develop plugins in ts while being in a JS project
123
- if (!useTypeScript) {
124
- await createTSConfigFile(cacheDir);
125
- }
126
- }
127
-
128
- async function createTSConfigFile(dest) {
129
- const tsConfig = {
130
- compilerOptions: {
131
- lib: ['es2019', 'es2020.promise', 'es2020.bigint', 'es2020.string', 'DOM'],
132
- noImplicitAny: false,
133
- module: 'es2020',
134
- target: 'es5',
135
- jsx: 'react',
136
- allowJs: true,
137
- strict: true,
138
- moduleResolution: 'node',
139
- skipLibCheck: true,
140
- esModuleInterop: true,
141
- allowSyntheticDefaultImports: true,
142
- resolveJsonModule: true,
143
- noEmit: false,
144
- incremental: true,
145
- },
146
- include: ['../../../src/admin/*', '../../../src/**/**/admin/src/*'],
147
- exclude: ['node_modules', '**/*.test.js', '*.js'],
148
- };
149
-
150
- const filePath = path.join(dest, 'admin', 'src', 'tsconfig.json');
151
-
152
- try {
153
- await fs.ensureFile(filePath);
154
-
155
- await fs.writeJSON(filePath, tsConfig, { spaces: 2 });
156
- } catch (err) {
157
- console.log(err);
158
- }
159
- }
160
-
161
- module.exports = createCacheDir;
@@ -1,23 +0,0 @@
1
- 'use strict';
2
-
3
- const { join } = require('path');
4
- const fse = require('fs-extra');
5
- const { isUsingTypeScript } = require('@strapi/typescript-utils');
6
-
7
- /**
8
- * Retrieve the custom admin entry file name
9
- * @param {String} dir - Directory of the admin panel
10
- * @returns String
11
- */
12
- const getCustomAppConfigFile = async dir => {
13
- const adminSrcPath = join(dir, 'src', 'admin');
14
- const useTypeScript = await isUsingTypeScript(adminSrcPath, 'tsconfig.json');
15
-
16
- const files = await fse.readdir(adminSrcPath);
17
-
18
- const appRegex = new RegExp(`app.${useTypeScript ? 't' : 'j'}sx?$`);
19
-
20
- return files.find(file => file.match(appRegex));
21
- };
22
-
23
- module.exports = getCustomAppConfigFile;
@@ -1,38 +0,0 @@
1
- 'use strict';
2
-
3
- const path = require('path');
4
- const chalk = require('chalk');
5
- const _ = require('lodash');
6
- const webpack = require('webpack');
7
- const fs = require('fs-extra');
8
- const getWebpackConfig = require('../webpack.config');
9
-
10
- const getCustomWebpackConfig = (dir, config) => {
11
- const adminConfigPath = path.join(dir, 'src', 'admin', 'webpack.config.js');
12
-
13
- let webpackConfig = getWebpackConfig(config);
14
-
15
- if (fs.existsSync(adminConfigPath)) {
16
- const webpackAdminConfig = require(path.resolve(adminConfigPath));
17
-
18
- if (_.isFunction(webpackAdminConfig)) {
19
- // Expose the devServer configuration
20
- if (config.devServer) {
21
- webpackConfig.devServer = config.devServer;
22
- }
23
-
24
- webpackConfig = webpackAdminConfig(webpackConfig, webpack);
25
-
26
- if (!webpackConfig) {
27
- console.error(
28
- `${chalk.red('Error:')} Nothing was returned from your custom webpack configuration`
29
- );
30
- process.exit(1);
31
- }
32
- }
33
- }
34
-
35
- return webpackConfig;
36
- };
37
-
38
- module.exports = getCustomWebpackConfig;
@@ -1,26 +0,0 @@
1
- 'use strict';
2
-
3
- const { join, resolve } = require('path');
4
- const fs = require('fs-extra');
5
- // eslint-disable-next-line node/no-extraneous-require
6
- const glob = require('glob');
7
-
8
- const getPluginsPath = () => {
9
- const rootPath = resolve(__dirname, '..', join('..', '..', '..', 'packages'));
10
- const corePath = join(rootPath, 'core', '*');
11
- const pluginsPath = join(rootPath, 'plugins', '*');
12
- const corePackageDirs = glob.sync(corePath);
13
- const pluginsPackageDirs = glob.sync(pluginsPath);
14
-
15
- const packageDirs = [...corePackageDirs, ...pluginsPackageDirs].filter(dir => {
16
- const isCoreAdmin = dir.includes('packages/core/admin');
17
- const pathToEntryPoint = join(dir, 'admin', 'src', 'index.js');
18
- const doesAdminFolderExist = fs.pathExistsSync(pathToEntryPoint);
19
-
20
- return !isCoreAdmin && doesAdminFolderExist;
21
- });
22
-
23
- return packageDirs.map(dir => resolve(__dirname, '..', join(dir, 'admin', 'src')));
24
- };
25
-
26
- module.exports = getPluginsPath;
package/utils/index.js DELETED
@@ -1,13 +0,0 @@
1
- 'use strict';
2
-
3
- const createCacheDir = require('./create-cache-dir');
4
- const getCustomWebpackConfig = require('./get-custom-webpack-config');
5
- const shouldBuildAdmin = require('./should-build-admin');
6
- const watchAdminFiles = require('./watch-admin-files');
7
-
8
- module.exports = {
9
- createCacheDir,
10
- getCustomWebpackConfig,
11
- shouldBuildAdmin,
12
- watchAdminFiles,
13
- };
@@ -1,52 +0,0 @@
1
- 'use strict';
2
-
3
- const path = require('path');
4
- const fs = require('fs-extra');
5
- const getCustomAppConfigFile = require('./get-custom-app-config-file');
6
-
7
- const DEFAULT_PLUGINS = [
8
- 'content-type-builder',
9
- 'content-manager',
10
- 'upload',
11
- 'email',
12
- 'i18n',
13
- 'users-permissions',
14
- ];
15
-
16
- /**
17
- * Checks if the project's installed plugins are not the same as a default one.
18
- * @param {Object} plugins
19
- * @returns {boolean}
20
- */
21
- const hasNonDefaultPlugins = plugins => {
22
- // List of plugins that are not the ones installed in a generated app
23
- const installedPlugins = Object.keys(plugins).filter(x => !DEFAULT_PLUGINS.includes(x));
24
-
25
- // List of default plugins uninstalled from a generated app
26
- const missingPlugins = DEFAULT_PLUGINS.filter(x => !Object.keys(plugins).includes(x));
27
-
28
- const diff = [...installedPlugins, ...missingPlugins];
29
-
30
- return diff.length > 0;
31
- };
32
-
33
- const hasCustomAdminCode = async dir => {
34
- const customAdminPath = path.join(dir, 'src', 'admin');
35
-
36
- const customAdminAppConfigFile = await getCustomAppConfigFile(dir);
37
- const customAdminWebpackFile = path.join(customAdminPath, 'webpack.config.js');
38
-
39
- const hasCustomConfigFile = !!customAdminAppConfigFile;
40
- const hasCustomWebpackFile = await fs.pathExists(customAdminWebpackFile);
41
-
42
- return hasCustomConfigFile || hasCustomWebpackFile;
43
- };
44
-
45
- const shouldBuildAdmin = async ({ appDir, plugins }) => {
46
- const appHasCustomAdminCode = await hasCustomAdminCode(appDir);
47
- const appHasNonDefaultPlugins = hasNonDefaultPlugins(plugins);
48
-
49
- return appHasCustomAdminCode || appHasNonDefaultPlugins;
50
- };
51
-
52
- module.exports = shouldBuildAdmin;
@@ -1,59 +0,0 @@
1
- 'use strict';
2
-
3
- const path = require('path');
4
- const fs = require('fs-extra');
5
- const chokidar = require('chokidar');
6
- const { isUsingTypeScript } = require('@strapi/typescript-utils');
7
-
8
- /**
9
- * Listen to files change and copy the changed files in the .cache/admin folder
10
- * when using the dev mode
11
- * @param {string} dir
12
- */
13
- async function watchAdminFiles(dir) {
14
- const useTypeScript = await isUsingTypeScript(path.join(dir, 'src', 'admin'), 'tsconfig.json');
15
-
16
- const cacheDir = path.join(dir, '.cache');
17
- const targetExtensionFile = useTypeScript ? 'app.tsx' : 'app.js';
18
- const appExtensionFile = path.join(dir, 'src', 'admin', targetExtensionFile);
19
- const extensionsPath = path.join(dir, 'src', 'admin', 'extensions');
20
-
21
- // Only watch the admin/app.js file and the files that are in the ./admin/extensions/folder
22
- const filesToWatch = [appExtensionFile, extensionsPath];
23
-
24
- const watcher = chokidar.watch(filesToWatch, {
25
- ignoreInitial: true,
26
- ignorePermissionErrors: true,
27
- });
28
-
29
- watcher.on('all', async (event, filePath) => {
30
- const isAppFile = filePath.includes(appExtensionFile);
31
-
32
- // The app.js file needs to be copied in the .cache/admin/src/app.js and the other ones needs to
33
- // be copied in the .cache/admin/src/extensions folder
34
- const targetPath = isAppFile
35
- ? path.join(path.normalize(filePath.split(appExtensionFile)[1]), targetExtensionFile)
36
- : path.join('extensions', path.normalize(filePath.split(extensionsPath)[1]));
37
-
38
- const destFolder = path.join(cacheDir, 'admin', 'src');
39
-
40
- if (event === 'unlink' || event === 'unlinkDir') {
41
- // Remove the file or folder
42
- // We need to copy the original files when deleting an override one
43
- try {
44
- fs.removeSync(path.join(destFolder, targetPath));
45
- } catch (err) {
46
- console.log('An error occured while deleting the file', err);
47
- }
48
- } else {
49
- // In any other case just copy the file into the .cache/admin/src folder
50
- try {
51
- await fs.copy(filePath, path.join(destFolder, targetPath));
52
- } catch (err) {
53
- console.log(err);
54
- }
55
- }
56
- });
57
- }
58
-
59
- module.exports = watchAdminFiles;