mirror of
				https://github.com/strapi/strapi.git
				synced 2025-11-04 03:43:34 +00:00 
			
		
		
		
	Fix watch-admin command
Signed-off-by: soupette <cyril@strapi.io>
This commit is contained in:
		
							parent
							
								
									e99fb210bc
								
							
						
					
					
						commit
						75066a4071
					
				@ -55,7 +55,7 @@ export default {
 | 
			
		||||
    const { locales } = app;
 | 
			
		||||
 | 
			
		||||
    const importedTrads = await Promise.all(
 | 
			
		||||
      locales.map((locale) => {
 | 
			
		||||
      locales.map(locale => {
 | 
			
		||||
        return import(`./translations/${locale}.json`)
 | 
			
		||||
          .then(({ default: data }) => {
 | 
			
		||||
            return {
 | 
			
		||||
 | 
			
		||||
@ -11,7 +11,7 @@ const HomePage: React.VoidFunctionComponent = () => {
 | 
			
		||||
  return (
 | 
			
		||||
    <div>
 | 
			
		||||
      <h1>{pluginId}'s HomePage</h1>
 | 
			
		||||
      <p>Happy codineg</p>
 | 
			
		||||
      <p>Happy coding</p>
 | 
			
		||||
    </div>
 | 
			
		||||
  );
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -16,6 +16,5 @@
 | 
			
		||||
    "resolveJsonModule": true
 | 
			
		||||
  },
 | 
			
		||||
  "include": ["src/plugins/**/*.json", "./"],
 | 
			
		||||
 | 
			
		||||
  "exclude": ["node_modules/", "dist/", "src/admin", ".cache/", ".tmp/"]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -94,16 +94,22 @@ async function clean({ appDir, buildDestDir }) {
 | 
			
		||||
  fs.removeSync(cacheDir);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function watchAdmin({ appDir, plugins, dir, host, port, browser, options, useTypeScript }) {
 | 
			
		||||
  console.log({ appDir });
 | 
			
		||||
  // TODO appDir
 | 
			
		||||
 | 
			
		||||
async function watchAdmin({
 | 
			
		||||
  appDir,
 | 
			
		||||
  browser,
 | 
			
		||||
  buildDestDir,
 | 
			
		||||
  host,
 | 
			
		||||
  options,
 | 
			
		||||
  plugins,
 | 
			
		||||
  port,
 | 
			
		||||
  useTypeScript,
 | 
			
		||||
}) {
 | 
			
		||||
  // 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 });
 | 
			
		||||
 | 
			
		||||
  const entry = path.join(cacheDir, 'admin', 'src');
 | 
			
		||||
  const dest = path.join(dir, 'build');
 | 
			
		||||
  const dest = path.join(buildDestDir, 'build');
 | 
			
		||||
  const env = 'development';
 | 
			
		||||
 | 
			
		||||
  // 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 args = {
 | 
			
		||||
    entry,
 | 
			
		||||
    appDir,
 | 
			
		||||
    cacheDir,
 | 
			
		||||
    pluginsPath,
 | 
			
		||||
    dest,
 | 
			
		||||
    entry,
 | 
			
		||||
    env,
 | 
			
		||||
    port,
 | 
			
		||||
    options,
 | 
			
		||||
    pluginsPath,
 | 
			
		||||
    // port,
 | 
			
		||||
    roots,
 | 
			
		||||
    useTypeScript,
 | 
			
		||||
    devServer: {
 | 
			
		||||
      port,
 | 
			
		||||
      client: {
 | 
			
		||||
@ -143,9 +149,10 @@ async function watchAdmin({ appDir, plugins, dir, host, port, browser, options,
 | 
			
		||||
        disableDotRule: true,
 | 
			
		||||
      },
 | 
			
		||||
    },
 | 
			
		||||
    useTypeScript,
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  const webpackConfig = getCustomWebpackConfig(dir, args);
 | 
			
		||||
  const webpackConfig = getCustomWebpackConfig(appDir, args);
 | 
			
		||||
 | 
			
		||||
  const compiler = webpack(webpackConfig);
 | 
			
		||||
 | 
			
		||||
@ -161,7 +168,7 @@ async function watchAdmin({ appDir, plugins, dir, host, port, browser, options,
 | 
			
		||||
 | 
			
		||||
  runServer();
 | 
			
		||||
 | 
			
		||||
  watchAdminFiles(dir, useTypeScript);
 | 
			
		||||
  watchAdminFiles(appDir, useTypeScript);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports = {
 | 
			
		||||
 | 
			
		||||
@ -8,8 +8,8 @@ const DEFAULT_PLUGINS = [
 | 
			
		||||
  'content-manager',
 | 
			
		||||
  'upload',
 | 
			
		||||
  'email',
 | 
			
		||||
  // 'i18n',
 | 
			
		||||
  // 'users-permissions',
 | 
			
		||||
  'i18n',
 | 
			
		||||
  'users-permissions',
 | 
			
		||||
];
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 | 
			
		||||
@ -151,6 +151,9 @@ function watchFileChanges({ dir, strapiInstance, watchIgnoreFiles, polling }) {
 | 
			
		||||
      /tmp/,
 | 
			
		||||
      '**/src/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/**',
 | 
			
		||||
      '**/node_modules',
 | 
			
		||||
 | 
			
		||||
@ -1,18 +1,21 @@
 | 
			
		||||
'use strict';
 | 
			
		||||
 | 
			
		||||
const path = require('path');
 | 
			
		||||
const strapiAdmin = require('@strapi/admin');
 | 
			
		||||
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 addSlash = require('../utils/addSlash');
 | 
			
		||||
const tsUtils = require('../utils/typescript');
 | 
			
		||||
const strapi = require('../index');
 | 
			
		||||
 | 
			
		||||
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({
 | 
			
		||||
    dir,
 | 
			
		||||
    dir: buildDestDir,
 | 
			
		||||
    autoReload: true,
 | 
			
		||||
    serveAdminPanel: false,
 | 
			
		||||
  });
 | 
			
		||||
@ -23,17 +26,12 @@ module.exports = async function({ browser }) {
 | 
			
		||||
 | 
			
		||||
  const adminPort = strapiInstance.config.get('admin.port', 8000);
 | 
			
		||||
  const adminHost = strapiInstance.config.get('admin.host', 'localhost');
 | 
			
		||||
  const adminWatchIgnoreFiles = strapiInstance.config.get('admin.watchIgnoreFiles', []);
 | 
			
		||||
 | 
			
		||||
  const backendURL = getAbsoluteServerUrl(strapiInstance.config, true);
 | 
			
		||||
 | 
			
		||||
  ee({ dir });
 | 
			
		||||
 | 
			
		||||
  // @convly we need to update this with the real check
 | 
			
		||||
  const useTypeScript = false;
 | 
			
		||||
 | 
			
		||||
  strapiAdmin.watchAdmin({
 | 
			
		||||
    dir,
 | 
			
		||||
    appDir: currentDirectory,
 | 
			
		||||
    buildDestDir,
 | 
			
		||||
    plugins,
 | 
			
		||||
    port: adminPort,
 | 
			
		||||
    host: adminHost,
 | 
			
		||||
@ -41,9 +39,7 @@ module.exports = async function({ browser }) {
 | 
			
		||||
    options: {
 | 
			
		||||
      backend: backendURL,
 | 
			
		||||
      adminPath: addSlash(adminPath),
 | 
			
		||||
      watchIgnoreFiles: adminWatchIgnoreFiles,
 | 
			
		||||
      features: ee.isEE ? ee.features.getEnabled() : [],
 | 
			
		||||
    },
 | 
			
		||||
    useTypeScript,
 | 
			
		||||
    useTypeScript: isTSProject,
 | 
			
		||||
  });
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user