mirror of
https://github.com/strapi/strapi.git
synced 2025-11-10 23:29:33 +00:00
Use enabled plugins to build admin
This commit is contained in:
parent
76d1ac7ada
commit
eb522e73e2
@ -34,9 +34,9 @@ function getCustomWebpackConfig(dir, config) {
|
|||||||
return webpackConfig;
|
return webpackConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function build({ dir, env, options, optimize }) {
|
async function build({ plugins, dir, env, options, optimize }) {
|
||||||
// Create the cache dir containing the front-end files.
|
// Create the cache dir containing the front-end files.
|
||||||
await createCacheDir(dir);
|
await createCacheDir({ dir, plugins });
|
||||||
|
|
||||||
const cacheDir = path.resolve(dir, '.cache');
|
const cacheDir = path.resolve(dir, '.cache');
|
||||||
const entry = path.resolve(cacheDir, 'admin', 'src');
|
const entry = path.resolve(cacheDir, 'admin', 'src');
|
||||||
@ -78,34 +78,24 @@ async function build({ dir, env, options, optimize }) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createPluginsJs(plugins, localPlugins, dest) {
|
async function createPluginsJs(plugins, dest) {
|
||||||
const createPluginsArray = plugins =>
|
const pluginsArray = plugins.map(({ name }) => {
|
||||||
plugins.map(name => {
|
const shortName = _.camelCase(name);
|
||||||
const shortName = _.camelCase(name.replace(/^@strapi\/plugin-/i, ''));
|
|
||||||
|
|
||||||
return { name, shortName };
|
return { name, shortName };
|
||||||
});
|
});
|
||||||
const appPluginsArray = createPluginsArray(plugins);
|
|
||||||
const localPluginsArray = createPluginsArray(localPlugins);
|
|
||||||
|
|
||||||
const content = `
|
const content = `
|
||||||
${appPluginsArray
|
${pluginsArray
|
||||||
.map(({ name, shortName }) => {
|
.map(({ name, shortName }) => {
|
||||||
const req = `'../../plugins/${name}/admin/src'`;
|
const req = `'../../plugins/${name}/admin/src'`;
|
||||||
|
|
||||||
return `import ${shortName} from ${req};`;
|
return `import ${shortName} from ${req};`;
|
||||||
})
|
})
|
||||||
.join('\n')}
|
.join('\n')}
|
||||||
${localPluginsArray
|
|
||||||
.map(({ name, shortName }) => {
|
|
||||||
const req = `'../../../plugins/${name}/admin/src'`;
|
|
||||||
|
|
||||||
return `import ${shortName} from ${req};`;
|
|
||||||
})
|
|
||||||
.join('\n')}
|
|
||||||
|
|
||||||
const plugins = {
|
const plugins = {
|
||||||
${[...appPluginsArray, ...localPluginsArray]
|
${[...pluginsArray]
|
||||||
.map(({ name, shortName }) => {
|
.map(({ name, shortName }) => {
|
||||||
return ` '${name}': ${shortName},`;
|
return ` '${name}': ${shortName},`;
|
||||||
})
|
})
|
||||||
@ -126,8 +116,8 @@ async function clean({ dir }) {
|
|||||||
fs.removeSync(cacheDir);
|
fs.removeSync(cacheDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function copyPlugin(name, dest) {
|
async function copyPlugin({ name, pathToPlugin }, dest) {
|
||||||
const pkgFilePath = getPkgPath(name);
|
const pkgFilePath = getPkgPath(pathToPlugin);
|
||||||
|
|
||||||
const resolveDepPath = (...args) => path.resolve(pkgFilePath, ...args);
|
const resolveDepPath = (...args) => path.resolve(pkgFilePath, ...args);
|
||||||
const resolveDest = (...args) => path.resolve(dest, 'plugins', name, ...args);
|
const resolveDest = (...args) => path.resolve(dest, 'plugins', name, ...args);
|
||||||
@ -158,25 +148,16 @@ async function copyAdmin(dest) {
|
|||||||
await fs.copy(path.resolve(adminPath, 'package.json'), path.resolve(dest, 'package.json'));
|
await fs.copy(path.resolve(adminPath, 'package.json'), path.resolve(dest, 'package.json'));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createCacheDir(dir) {
|
async function createCacheDir({ dir, plugins }) {
|
||||||
const cacheDir = path.resolve(dir, '.cache');
|
const cacheDir = path.resolve(dir, '.cache');
|
||||||
|
|
||||||
const pkgJSON = require(path.join(dir, 'package.json'));
|
const pluginsToCopy = Object.keys(plugins)
|
||||||
|
.filter(pluginName => {
|
||||||
const pluginsToCopy = Object.keys(pkgJSON.dependencies).filter(
|
const pluginInfo = plugins[pluginName];
|
||||||
dep =>
|
// TODO: use strapi-admin
|
||||||
dep.startsWith('@strapi/plugin') &&
|
return fs.existsSync(path.resolve(pluginInfo.pathToPlugin, 'admin', 'src', 'index.js'));
|
||||||
fs.existsSync(path.resolve(getPkgPath(dep), 'admin', 'src', 'index.js'))
|
})
|
||||||
);
|
.map(name => ({ name, ...plugins[name] }));
|
||||||
|
|
||||||
let localPluginsToCopy = [];
|
|
||||||
if (fs.existsSync(path.join(dir, 'plugins'))) {
|
|
||||||
localPluginsToCopy = fs
|
|
||||||
.readdirSync(path.join(dir, 'plugins'))
|
|
||||||
.filter(plugin =>
|
|
||||||
fs.existsSync(path.resolve(dir, 'plugins', plugin, 'admin', 'src', 'index.js'))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// create .cache dir
|
// create .cache dir
|
||||||
await fs.emptyDir(cacheDir);
|
await fs.emptyDir(cacheDir);
|
||||||
@ -185,7 +166,7 @@ async function createCacheDir(dir) {
|
|||||||
await copyAdmin(cacheDir);
|
await copyAdmin(cacheDir);
|
||||||
|
|
||||||
// copy plugins code
|
// copy plugins code
|
||||||
await Promise.all(pluginsToCopy.map(name => copyPlugin(name, cacheDir)));
|
await Promise.all(pluginsToCopy.map(plugin => copyPlugin(plugin, cacheDir)));
|
||||||
|
|
||||||
// Copy app.js
|
// Copy app.js
|
||||||
const customAdminConfigFilePath = path.join(dir, 'admin', 'app.js');
|
const customAdminConfigFilePath = path.join(dir, 'admin', 'app.js');
|
||||||
@ -202,12 +183,12 @@ async function createCacheDir(dir) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create plugins.js with plugins requires
|
// create plugins.js with plugins requires
|
||||||
await createPluginsJs(pluginsToCopy, localPluginsToCopy, cacheDir);
|
await createPluginsJs(pluginsToCopy, cacheDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function watchAdmin({ dir, host, port, browser, options }) {
|
async function watchAdmin({ plugins, dir, host, port, browser, options }) {
|
||||||
// Create the cache dir containing the front-end files.
|
// Create the cache dir containing the front-end files.
|
||||||
await createCacheDir(dir);
|
await createCacheDir({ dir, plugins });
|
||||||
|
|
||||||
const entry = path.join(dir, '.cache', 'admin', 'src');
|
const entry = path.join(dir, '.cache', 'admin', 'src');
|
||||||
const dest = path.join(dir, 'build');
|
const dest = path.join(dir, 'build');
|
||||||
|
|||||||
@ -1,23 +1,32 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
const { green } = require('chalk');
|
const { green } = require('chalk');
|
||||||
|
|
||||||
// eslint-disable-next-line node/no-extraneous-require
|
|
||||||
const strapiAdmin = require('@strapi/admin');
|
const strapiAdmin = require('@strapi/admin');
|
||||||
const { getConfigUrls } = require('@strapi/utils');
|
const { getConfigUrls } = require('@strapi/utils');
|
||||||
const loadConfiguration = require('../core/app-configuration');
|
|
||||||
const ee = require('../utils/ee');
|
|
||||||
|
|
||||||
|
const ee = require('../utils/ee');
|
||||||
const addSlash = require('../utils/addSlash');
|
const addSlash = require('../utils/addSlash');
|
||||||
|
const strapi = require('../index');
|
||||||
|
const getEnabledPlugins = require('../core/loaders/plugins/get-enabled-plugins');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* `$ strapi build`
|
* `$ strapi build`
|
||||||
*/
|
*/
|
||||||
module.exports = async ({ clean, optimization }) => {
|
module.exports = async ({ clean, optimization }) => {
|
||||||
const dir = process.cwd();
|
const dir = process.cwd();
|
||||||
const config = loadConfiguration(dir);
|
|
||||||
|
|
||||||
const { serverUrl, adminPath } = getConfigUrls(config.server, true);
|
const strapiInstance = strapi({
|
||||||
|
dir,
|
||||||
|
autoReload: true,
|
||||||
|
serveAdminPanel: false,
|
||||||
|
});
|
||||||
|
|
||||||
console.log(`Building your admin UI with ${green(config.environment)} configuration ...`);
|
const plugins = await getEnabledPlugins(strapiInstance);
|
||||||
|
|
||||||
|
const env = strapiInstance.config.get('environment');
|
||||||
|
const { serverUrl, adminPath } = getConfigUrls(strapiInstance.config.get('server'), true);
|
||||||
|
|
||||||
|
console.log(`Building your admin UI with ${green(env)} configuration ...`);
|
||||||
|
|
||||||
if (clean) {
|
if (clean) {
|
||||||
await strapiAdmin.clean({ dir });
|
await strapiAdmin.clean({ dir });
|
||||||
@ -28,6 +37,7 @@ module.exports = async ({ clean, optimization }) => {
|
|||||||
return strapiAdmin
|
return strapiAdmin
|
||||||
.build({
|
.build({
|
||||||
dir,
|
dir,
|
||||||
|
plugins,
|
||||||
// front end build env is always production for now
|
// front end build env is always production for now
|
||||||
env: 'production',
|
env: 'production',
|
||||||
optimize: optimization,
|
optimize: optimization,
|
||||||
|
|||||||
@ -2,32 +2,42 @@
|
|||||||
|
|
||||||
// eslint-disable-next-line node/no-extraneous-require
|
// eslint-disable-next-line node/no-extraneous-require
|
||||||
const strapiAdmin = require('@strapi/admin');
|
const strapiAdmin = require('@strapi/admin');
|
||||||
const { getOr } = require('lodash/fp');
|
|
||||||
const { getConfigUrls, getAbsoluteServerUrl } = require('@strapi/utils');
|
const { getConfigUrls, getAbsoluteServerUrl } = require('@strapi/utils');
|
||||||
const loadConfiguration = require('../core/app-configuration');
|
|
||||||
const ee = require('../utils/ee');
|
const ee = require('../utils/ee');
|
||||||
const addSlash = require('../utils/addSlash');
|
const addSlash = require('../utils/addSlash');
|
||||||
|
const strapi = require('../index');
|
||||||
|
const getEnabledPlugins = require('../core/loaders/plugins/get-enabled-plugins');
|
||||||
|
|
||||||
module.exports = async function({ browser }) {
|
module.exports = async function({ browser }) {
|
||||||
const dir = process.cwd();
|
const dir = process.cwd();
|
||||||
|
|
||||||
const config = loadConfiguration(dir);
|
const strapiInstance = strapi({
|
||||||
|
dir,
|
||||||
|
autoReload: true,
|
||||||
|
serveAdminPanel: false,
|
||||||
|
});
|
||||||
|
|
||||||
const { adminPath } = getConfigUrls(config.server, true);
|
const plugins = await getEnabledPlugins(strapiInstance);
|
||||||
|
|
||||||
const adminPort = getOr(8000, 'server.admin.port')(config);
|
const { adminPath } = getConfigUrls(strapiInstance.config.get('server'), true);
|
||||||
const adminHost = getOr('localhost', 'server.admin.host')(config);
|
|
||||||
const adminWatchIgnoreFiles = getOr([], 'server.admin.watchIgnoreFiles')(config);
|
const adminPort = strapiInstance.config.get('server.admin.port', 8000);
|
||||||
|
const adminHost = strapiInstance.config.get('server.admin.host', 'localhost');
|
||||||
|
const adminWatchIgnoreFiles = strapiInstance.config.get('server.admin.watchIgnoreFiles', []);
|
||||||
|
|
||||||
|
const backendURL = getAbsoluteServerUrl(strapiInstance.config, true);
|
||||||
|
|
||||||
ee({ dir });
|
ee({ dir });
|
||||||
|
|
||||||
strapiAdmin.watchAdmin({
|
strapiAdmin.watchAdmin({
|
||||||
dir,
|
dir,
|
||||||
|
plugins,
|
||||||
port: adminPort,
|
port: adminPort,
|
||||||
host: adminHost,
|
host: adminHost,
|
||||||
browser,
|
browser,
|
||||||
options: {
|
options: {
|
||||||
backend: getAbsoluteServerUrl(config, true),
|
backend: backendURL,
|
||||||
adminPath: addSlash(adminPath),
|
adminPath: addSlash(adminPath),
|
||||||
watchIgnoreFiles: adminWatchIgnoreFiles,
|
watchIgnoreFiles: adminWatchIgnoreFiles,
|
||||||
features: ee.isEE ? ee.features.getEnabled() : [],
|
features: ee.isEE ? ee.features.getEnabled() : [],
|
||||||
|
|||||||
@ -50,8 +50,6 @@ module.exports = (projectDirectory, cliArguments) => {
|
|||||||
installDependencies: true,
|
installDependencies: true,
|
||||||
strapiDependencies: [
|
strapiDependencies: [
|
||||||
'@strapi/strapi',
|
'@strapi/strapi',
|
||||||
'@strapi/admin',
|
|
||||||
'@strapi/utils',
|
|
||||||
'@strapi/plugin-users-permissions',
|
'@strapi/plugin-users-permissions',
|
||||||
'@strapi/plugin-i18n',
|
'@strapi/plugin-i18n',
|
||||||
],
|
],
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user