mirror of
https://github.com/strapi/strapi.git
synced 2025-12-27 15:13:21 +00:00
Cleanup
This commit is contained in:
parent
6b7f1e0c4e
commit
21728d60ac
@ -9,7 +9,16 @@ const chalk = require('chalk');
|
||||
const chokidar = require('chokidar');
|
||||
const getWebpackConfig = require('./webpack.config');
|
||||
|
||||
const getPkgPath = (name) => path.dirname(require.resolve(`${name}/package.json`));
|
||||
const getPkgPath = name => path.dirname(require.resolve(`${name}/package.json`));
|
||||
|
||||
const DEFAULT_PLUGINS = [
|
||||
'content-type-builder',
|
||||
'content-manager',
|
||||
'upload',
|
||||
'email',
|
||||
'i18n',
|
||||
'users-permissions',
|
||||
];
|
||||
|
||||
function getCustomWebpackConfig(dir, config) {
|
||||
const adminConfigPath = path.join(dir, 'src', 'admin', 'webpack.config.js');
|
||||
@ -35,7 +44,8 @@ function getCustomWebpackConfig(dir, config) {
|
||||
}
|
||||
|
||||
async function build({ plugins, dir, env, options, optimize }) {
|
||||
if (!(await shouldBuildAdmin({ dir, plugins }))) {
|
||||
const buildAdmin = await shouldBuildAdmin({ dir, plugins });
|
||||
if (!buildAdmin) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -52,7 +62,7 @@ async function build({ plugins, dir, env, options, optimize }) {
|
||||
ceRoot: path.resolve(cacheDir, 'admin', 'src'),
|
||||
};
|
||||
|
||||
const pluginsPath = Object.keys(plugins).map((pluginName) => plugins[pluginName].pathToPlugin);
|
||||
const pluginsPath = Object.keys(plugins).map(pluginName => plugins[pluginName].pathToPlugin);
|
||||
|
||||
const config = getCustomWebpackConfig(dir, {
|
||||
entry,
|
||||
@ -165,11 +175,11 @@ async function createCacheDir({ dir, plugins }) {
|
||||
const cacheDir = path.resolve(dir, '.cache');
|
||||
|
||||
const pluginsWithFront = Object.keys(plugins)
|
||||
.filter((pluginName) => {
|
||||
.filter(pluginName => {
|
||||
const pluginInfo = plugins[pluginName];
|
||||
return fs.existsSync(path.resolve(pluginInfo.pathToPlugin, 'strapi-admin.js'));
|
||||
})
|
||||
.map((name) => ({ name, ...plugins[name] }));
|
||||
.map(name => ({ name, ...plugins[name] }));
|
||||
|
||||
// create .cache dir
|
||||
await fs.emptyDir(cacheDir);
|
||||
@ -210,7 +220,7 @@ async function watchAdmin({ plugins, dir, host, port, browser, options }) {
|
||||
ceRoot: path.resolve(cacheDir, 'admin', 'src'),
|
||||
};
|
||||
|
||||
const pluginsPath = Object.keys(plugins).map((pluginName) => plugins[pluginName].pathToPlugin);
|
||||
const pluginsPath = Object.keys(plugins).map(pluginName => plugins[pluginName].pathToPlugin);
|
||||
|
||||
const args = {
|
||||
entry,
|
||||
@ -247,7 +257,7 @@ async function watchAdmin({ plugins, dir, host, port, browser, options }) {
|
||||
|
||||
const server = new WebpackDevServer(opts, webpack(webpackConfig));
|
||||
|
||||
server.start(port, host, function (err) {
|
||||
server.start(port, host, function(err) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
}
|
||||
@ -308,7 +318,7 @@ async function watchFiles(dir) {
|
||||
});
|
||||
}
|
||||
|
||||
const hasCustomAdminCode = async (dir) => {
|
||||
const hasCustomAdminCode = async dir => {
|
||||
const customAdminPath = path.join(dir, 'src/admin');
|
||||
|
||||
if (!(await fs.pathExists(customAdminPath))) {
|
||||
@ -320,16 +330,7 @@ const hasCustomAdminCode = async (dir) => {
|
||||
return files.length > 0;
|
||||
};
|
||||
|
||||
const DEFAULT_PLUGINS = [
|
||||
'content-type-builder',
|
||||
'content-manager',
|
||||
'upload',
|
||||
'email',
|
||||
'i18n',
|
||||
'users-permissions',
|
||||
];
|
||||
|
||||
const hasNonDefaultPlugins = (plugins) => {
|
||||
const hasNonDefaultPlugins = plugins => {
|
||||
const diff = _.difference(Object.keys(plugins), DEFAULT_PLUGINS);
|
||||
|
||||
return diff.length > 0;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const serveAdmin = require('./routes/serve-admin');
|
||||
const registerAdminPanelRoute = require('./routes/serve-admin-panel');
|
||||
const adminAuthStrategy = require('./strategies/admin');
|
||||
const apiTokenAuthStrategy = require('./strategies/api-token');
|
||||
|
||||
@ -12,6 +12,6 @@ module.exports = ({ strapi }) => {
|
||||
strapi.container.get('auth').register('content-api', apiTokenAuthStrategy);
|
||||
|
||||
if (strapi.config.serveAdminPanel) {
|
||||
serveAdmin({ strapi });
|
||||
registerAdminPanelRoute({ strapi });
|
||||
}
|
||||
};
|
||||
|
||||
@ -4,14 +4,14 @@ const path = require('path');
|
||||
const fse = require('fs-extra');
|
||||
const koaStatic = require('koa-static');
|
||||
|
||||
const serveAdmin = ({ strapi }) => {
|
||||
const registerAdminPanelRoute = ({ strapi }) => {
|
||||
let buildDir = path.resolve(strapi.dirs.root, 'build');
|
||||
|
||||
if (!fse.pathExistsSync(buildDir)) {
|
||||
buildDir = path.resolve(__dirname, '../../build');
|
||||
}
|
||||
|
||||
const serveAdmin = async (ctx, next) => {
|
||||
const serveAdminMiddleware = async (ctx, next) => {
|
||||
await next();
|
||||
|
||||
if (ctx.method !== 'HEAD' && ctx.method !== 'GET') {
|
||||
@ -31,7 +31,7 @@ const serveAdmin = ({ strapi }) => {
|
||||
method: 'GET',
|
||||
path: `${strapi.config.admin.path}/:path*`,
|
||||
handler: [
|
||||
serveAdmin,
|
||||
serveAdminMiddleware,
|
||||
serveStatic(buildDir, { maxage: 60000, defer: false, index: 'index.html' }),
|
||||
],
|
||||
config: { auth: false },
|
||||
@ -56,4 +56,4 @@ const serveStatic = (filesDir, koaStaticOptions = {}) => {
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = serveAdmin;
|
||||
module.exports = registerAdminPanelRoute;
|
||||
Loading…
x
Reference in New Issue
Block a user