From ae9066bbbfa05e43175e576d2f139c708dccd1bb Mon Sep 17 00:00:00 2001 From: soupette Date: Wed, 12 May 2021 11:42:20 +0200 Subject: [PATCH] Fix generated app Signed-off-by: soupette --- .../plugins/myplugin/admin/src/index.js | 55 +++++++++------- packages/core/admin/index.js | 65 +++++++++++-------- .../core/strapi/lib/commands/watchAdmin.js | 2 +- 3 files changed, 70 insertions(+), 52 deletions(-) diff --git a/examples/getstarted/plugins/myplugin/admin/src/index.js b/examples/getstarted/plugins/myplugin/admin/src/index.js index 3be1ae8651..0c5ee9f361 100644 --- a/examples/getstarted/plugins/myplugin/admin/src/index.js +++ b/examples/getstarted/plugins/myplugin/admin/src/index.js @@ -1,28 +1,37 @@ import pluginPkg from '../../package.json'; import pluginId from './pluginId'; -// TODO -export default strapi => { - const pluginDescription = pluginPkg.strapi.description || pluginPkg.description; +const pluginDescription = pluginPkg.strapi.description || pluginPkg.description; +const icon = pluginPkg.strapi.icon; +const name = pluginPkg.strapi.name; - const plugin = { - blockerComponent: null, - blockerComponentProps: {}, - description: pluginDescription, - icon: pluginPkg.strapi.icon, - id: pluginId, - initializer: () => null, - injectedComponents: [], - isReady: true, - isRequired: pluginPkg.strapi.required || false, - leftMenuLinks: [], - leftMenuSections: [], - mainComponent: null, - name: pluginPkg.strapi.name, - preventComponentRendering: false, - settings: null, - trads: {}, - }; - - return strapi.registerPlugin(plugin); +export default { + register(app) { + app.registerPlugin({ + description: pluginDescription, + icon, + id: pluginId, + isReady: true, + isRequired: pluginPkg.strapi.required || false, + mainComponent: () => 'My plugin', + name, + settings: null, + trads: {}, + menu: { + pluginsSectionLinks: [ + { + destination: `/plugins/${pluginId}`, + icon, + label: { + id: `${pluginId}.plugin.name`, + defaultMessage: 'My plugin', + }, + name, + permissions: null, + }, + ], + }, + }); + }, + boot() {}, }; diff --git a/packages/core/admin/index.js b/packages/core/admin/index.js index 33c096a265..ea5a072b89 100644 --- a/packages/core/admin/index.js +++ b/packages/core/admin/index.js @@ -79,26 +79,42 @@ async function build({ dir, env, options, optimize }) { }); } -// TODO remove async function createPluginsJs(plugins, localPlugins, dest) { + const createPluginsArray = plugins => + plugins.map(name => { + const shortName = _.camelCase(name.replace(/^@strapi\/plugin-/i, '')); + + return { name, shortName }; + }); + const appPluginsArray = createPluginsArray(plugins); + const localPluginsArray = createPluginsArray(localPlugins); + const content = ` -module.exports = { - ${plugins - .map(name => { - const shortName = name.replace(/^@strapi\/plugin-/i, ''); - const req = `require('../../plugins/${name}/admin/src').default`; - return `'${shortName}': ${req},`; - }) - .join('\n')} - ${localPlugins - .map(name => { - const shortName = name.replace(/^@strapi\/plugin-/i, ''); - const req = `require('../../../plugins/${name}/admin/src').default`; - return `'${shortName}': ${req}`; - }) - .join(',\n')} -} - `; +${appPluginsArray + .map(({ name, shortName }) => { + const req = `'../../plugins/${name}/admin/src'`; + + return `import ${shortName} from ${req};`; + }) + .join('\n')} +${localPluginsArray + .map(({ name, shortName }) => { + const req = `'../../../plugins/${name}/admin/src'`; + + return `import ${shortName} from ${req};`; + }) + .join('\n')} + +const plugins = { +${[...appPluginsArray, ...localPluginsArray] + .map(({ name, shortName }) => { + return ` '${name}': ${shortName},`; + }) + .join('\n')} +}; + +export default plugins; +`; return fs.writeFile(path.resolve(dest, 'admin', 'src', 'plugins.js'), content); } @@ -123,13 +139,6 @@ async function copyPlugin(name, dest) { // Copy the entire admin folder await copy('admin'); - - // Copy the layout.js if it exists - if (await fs.exists(path.resolve(pkgFilePath, 'config', 'layout.js'))) { - await fs.ensureDir(resolveDest('config')); - await copy('config', 'layout.js'); - } - await copy('package.json'); } @@ -218,7 +227,7 @@ async function watchAdmin({ dir, host, port, browser, options }) { // Create the cache dir containing the front-end files. await createCacheDir(dir); - const entry = path.join(dir, '.cache', 'admin', 'src', 'app.js'); + const entry = path.join(dir, '.cache', 'admin', 'src'); const dest = path.join(dir, 'build'); const env = 'development'; @@ -234,9 +243,9 @@ async function watchAdmin({ dir, host, port, browser, options }) { clientLogLevel: 'silent', quiet: true, open: browser === 'true' ? true : browser, - publicPath: options.publicPath, + publicPath: options.adminPath, historyApiFallback: { - index: options.publicPath, + index: options.adminPath, disableDotRule: true, }, }; diff --git a/packages/core/strapi/lib/commands/watchAdmin.js b/packages/core/strapi/lib/commands/watchAdmin.js index 184f2c5de1..bde03411d7 100644 --- a/packages/core/strapi/lib/commands/watchAdmin.js +++ b/packages/core/strapi/lib/commands/watchAdmin.js @@ -27,7 +27,7 @@ module.exports = async function({ browser }) { browser, options: { backend: getAbsoluteServerUrl(config, true), - publicPath: addSlash(adminPath), + adminPath: addSlash(adminPath), watchIgnoreFiles: adminWatchIgnoreFiles, features: ee.isEE ? ee.features.getEnabled() : [], },