Fix watch-admin command

Signed-off-by: soupette <cyril@strapi.io>
This commit is contained in:
soupette 2022-03-09 18:26:17 +01:00
parent e99fb210bc
commit 75066a4071
7 changed files with 38 additions and 33 deletions

View File

@ -55,7 +55,7 @@ export default {
const { locales } = app; const { locales } = app;
const importedTrads = await Promise.all( const importedTrads = await Promise.all(
locales.map((locale) => { locales.map(locale => {
return import(`./translations/${locale}.json`) return import(`./translations/${locale}.json`)
.then(({ default: data }) => { .then(({ default: data }) => {
return { return {

View File

@ -11,7 +11,7 @@ const HomePage: React.VoidFunctionComponent = () => {
return ( return (
<div> <div>
<h1>{pluginId}&apos;s HomePage</h1> <h1>{pluginId}&apos;s HomePage</h1>
<p>Happy codineg</p> <p>Happy coding</p>
</div> </div>
); );
}; };

View File

@ -16,6 +16,5 @@
"resolveJsonModule": true "resolveJsonModule": true
}, },
"include": ["src/plugins/**/*.json", "./"], "include": ["src/plugins/**/*.json", "./"],
"exclude": ["node_modules/", "dist/", "src/admin", ".cache/", ".tmp/"] "exclude": ["node_modules/", "dist/", "src/admin", ".cache/", ".tmp/"]
} }

View File

@ -94,16 +94,22 @@ async function clean({ appDir, buildDestDir }) {
fs.removeSync(cacheDir); fs.removeSync(cacheDir);
} }
async function watchAdmin({ appDir, plugins, dir, host, port, browser, options, useTypeScript }) { async function watchAdmin({
console.log({ appDir }); appDir,
// TODO appDir browser,
buildDestDir,
host,
options,
plugins,
port,
useTypeScript,
}) {
// Create the cache dir containing the front-end files. // Create the cache dir containing the front-end files.
const cacheDir = path.join(dir, '.cache'); const cacheDir = path.join(appDir, '.cache');
await createCacheDir({ appDir, plugins, useTypeScript }); await createCacheDir({ appDir, plugins, useTypeScript });
const entry = path.join(cacheDir, 'admin', 'src'); const entry = path.join(cacheDir, 'admin', 'src');
const dest = path.join(dir, 'build'); const dest = path.join(buildDestDir, 'build');
const env = 'development'; const env = 'development';
// Roots for the @strapi/babel-plugin-switch-ee-ce // Roots for the @strapi/babel-plugin-switch-ee-ce
@ -115,15 +121,15 @@ async function watchAdmin({ appDir, plugins, dir, host, port, browser, options,
const pluginsPath = Object.keys(plugins).map(pluginName => plugins[pluginName].pathToPlugin); const pluginsPath = Object.keys(plugins).map(pluginName => plugins[pluginName].pathToPlugin);
const args = { const args = {
entry, appDir,
cacheDir, cacheDir,
pluginsPath,
dest, dest,
entry,
env, env,
port,
options, options,
pluginsPath,
// port,
roots, roots,
useTypeScript,
devServer: { devServer: {
port, port,
client: { client: {
@ -143,9 +149,10 @@ async function watchAdmin({ appDir, plugins, dir, host, port, browser, options,
disableDotRule: true, disableDotRule: true,
}, },
}, },
useTypeScript,
}; };
const webpackConfig = getCustomWebpackConfig(dir, args); const webpackConfig = getCustomWebpackConfig(appDir, args);
const compiler = webpack(webpackConfig); const compiler = webpack(webpackConfig);
@ -161,7 +168,7 @@ async function watchAdmin({ appDir, plugins, dir, host, port, browser, options,
runServer(); runServer();
watchAdminFiles(dir, useTypeScript); watchAdminFiles(appDir, useTypeScript);
} }
module.exports = { module.exports = {

View File

@ -8,8 +8,8 @@ const DEFAULT_PLUGINS = [
'content-manager', 'content-manager',
'upload', 'upload',
'email', 'email',
// 'i18n', 'i18n',
// 'users-permissions', 'users-permissions',
]; ];
/** /**

View File

@ -151,6 +151,9 @@ function watchFileChanges({ dir, strapiInstance, watchIgnoreFiles, polling }) {
/tmp/, /tmp/,
'**/src/admin/**', '**/src/admin/**',
'**/src/plugins/**/admin/**', '**/src/plugins/**/admin/**',
// FIXME pass the plugin path to the strapiAdmin.build and strapiAdmin.watch in order to stop copying
// the FE files when using TS
'**/dist/src/plugins/test/admin/**',
'**/documentation', '**/documentation',
'**/documentation/**', '**/documentation/**',
'**/node_modules', '**/node_modules',

View File

@ -1,18 +1,21 @@
'use strict'; 'use strict';
const path = require('path');
const strapiAdmin = require('@strapi/admin'); const strapiAdmin = require('@strapi/admin');
const { getConfigUrls, getAbsoluteServerUrl } = require('@strapi/utils'); const { getConfigUrls, getAbsoluteServerUrl } = require('@strapi/utils');
const ee = require('../utils/ee');
const addSlash = require('../utils/addSlash');
const strapi = require('../index');
const getEnabledPlugins = require('../core/loaders/plugins/get-enabled-plugins'); const getEnabledPlugins = require('../core/loaders/plugins/get-enabled-plugins');
const addSlash = require('../utils/addSlash');
const tsUtils = require('../utils/typescript');
const strapi = require('../index');
module.exports = async function({ browser }) { module.exports = async function({ browser }) {
const dir = process.cwd(); const currentDirectory = process.cwd();
const isTSProject = await tsUtils.isTypeScriptProject(currentDirectory);
const buildDestDir = isTSProject ? path.join(currentDirectory, 'dist') : currentDirectory;
const strapiInstance = strapi({ const strapiInstance = strapi({
dir, dir: buildDestDir,
autoReload: true, autoReload: true,
serveAdminPanel: false, serveAdminPanel: false,
}); });
@ -23,17 +26,12 @@ module.exports = async function({ browser }) {
const adminPort = strapiInstance.config.get('admin.port', 8000); const adminPort = strapiInstance.config.get('admin.port', 8000);
const adminHost = strapiInstance.config.get('admin.host', 'localhost'); const adminHost = strapiInstance.config.get('admin.host', 'localhost');
const adminWatchIgnoreFiles = strapiInstance.config.get('admin.watchIgnoreFiles', []);
const backendURL = getAbsoluteServerUrl(strapiInstance.config, true); const backendURL = getAbsoluteServerUrl(strapiInstance.config, true);
ee({ dir });
// @convly we need to update this with the real check
const useTypeScript = false;
strapiAdmin.watchAdmin({ strapiAdmin.watchAdmin({
dir, appDir: currentDirectory,
buildDestDir,
plugins, plugins,
port: adminPort, port: adminPort,
host: adminHost, host: adminHost,
@ -41,9 +39,7 @@ module.exports = async function({ browser }) {
options: { options: {
backend: backendURL, backend: backendURL,
adminPath: addSlash(adminPath), adminPath: addSlash(adminPath),
watchIgnoreFiles: adminWatchIgnoreFiles,
features: ee.isEE ? ee.features.getEnabled() : [],
}, },
useTypeScript, useTypeScript: isTSProject,
}); });
}; };