From 75066a4071f6dfa57dad815c8548bef0c02c479b Mon Sep 17 00:00:00 2001 From: soupette Date: Wed, 9 Mar 2022 18:26:17 +0100 Subject: [PATCH] Fix watch-admin command Signed-off-by: soupette --- .../src/plugins/test/admin/src/index.tsx | 2 +- .../test/admin/src/pages/HomePage/index.tsx | 2 +- examples/kitchensink-ts/tsconfig-server.json | 1 - packages/core/admin/index.js | 31 ++++++++++++------- .../core/admin/utils/should-build-admin.js | 4 +-- packages/core/strapi/lib/commands/develop.js | 3 ++ .../core/strapi/lib/commands/watchAdmin.js | 28 +++++++---------- 7 files changed, 38 insertions(+), 33 deletions(-) diff --git a/examples/kitchensink-ts/src/plugins/test/admin/src/index.tsx b/examples/kitchensink-ts/src/plugins/test/admin/src/index.tsx index 0a1802e892..39d03b4bbe 100644 --- a/examples/kitchensink-ts/src/plugins/test/admin/src/index.tsx +++ b/examples/kitchensink-ts/src/plugins/test/admin/src/index.tsx @@ -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 { diff --git a/examples/kitchensink-ts/src/plugins/test/admin/src/pages/HomePage/index.tsx b/examples/kitchensink-ts/src/plugins/test/admin/src/pages/HomePage/index.tsx index 471e1db776..24ce835333 100644 --- a/examples/kitchensink-ts/src/plugins/test/admin/src/pages/HomePage/index.tsx +++ b/examples/kitchensink-ts/src/plugins/test/admin/src/pages/HomePage/index.tsx @@ -11,7 +11,7 @@ const HomePage: React.VoidFunctionComponent = () => { return (

{pluginId}'s HomePage

-

Happy codineg

+

Happy coding

); }; diff --git a/examples/kitchensink-ts/tsconfig-server.json b/examples/kitchensink-ts/tsconfig-server.json index 261d6070d3..be92561d6d 100644 --- a/examples/kitchensink-ts/tsconfig-server.json +++ b/examples/kitchensink-ts/tsconfig-server.json @@ -16,6 +16,5 @@ "resolveJsonModule": true }, "include": ["src/plugins/**/*.json", "./"], - "exclude": ["node_modules/", "dist/", "src/admin", ".cache/", ".tmp/"] } diff --git a/packages/core/admin/index.js b/packages/core/admin/index.js index 46fcd558e9..6910636580 100644 --- a/packages/core/admin/index.js +++ b/packages/core/admin/index.js @@ -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 = { diff --git a/packages/core/admin/utils/should-build-admin.js b/packages/core/admin/utils/should-build-admin.js index 1d4c7b82ae..6f8993ef37 100644 --- a/packages/core/admin/utils/should-build-admin.js +++ b/packages/core/admin/utils/should-build-admin.js @@ -8,8 +8,8 @@ const DEFAULT_PLUGINS = [ 'content-manager', 'upload', 'email', - // 'i18n', - // 'users-permissions', + 'i18n', + 'users-permissions', ]; /** diff --git a/packages/core/strapi/lib/commands/develop.js b/packages/core/strapi/lib/commands/develop.js index 7e22eb1695..aeee70d4ee 100644 --- a/packages/core/strapi/lib/commands/develop.js +++ b/packages/core/strapi/lib/commands/develop.js @@ -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', diff --git a/packages/core/strapi/lib/commands/watchAdmin.js b/packages/core/strapi/lib/commands/watchAdmin.js index d7d2a4b089..a88c538e06 100644 --- a/packages/core/strapi/lib/commands/watchAdmin.js +++ b/packages/core/strapi/lib/commands/watchAdmin.js @@ -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, }); };