mirror of
https://github.com/strapi/strapi.git
synced 2025-10-21 21:13:17 +00:00
Merge pull request #10569 from strapi/core/switch-plan
Allow to switch plan at runtime
This commit is contained in:
commit
c4adf3790a
@ -38,14 +38,16 @@ module.exports = {
|
||||
__webpack_public_path__: 'http://localhost:4000',
|
||||
strapi: {
|
||||
backendURL: 'http://localhost:1337',
|
||||
isEE: false,
|
||||
features: [],
|
||||
projectType: 'Community',
|
||||
},
|
||||
BACKEND_URL: 'http://localhost:1337',
|
||||
ADMIN_PATH: '/admin',
|
||||
NODE_ENV: 'test',
|
||||
'process.env.STRAPI_ADMIN_ENABLED_EE_FEATURES': [],
|
||||
STRAPI_ADMIN_ENABLED_EE_FEATURES: [],
|
||||
'process.env.STRAPI_ADMIN_SHOW_TUTORIALS': 'false',
|
||||
'process.env.STRAPI_ADMIN_UPDATE_NOTIFICATION': 'false',
|
||||
// FIXME create a clean config file
|
||||
},
|
||||
moduleDirectories: [
|
||||
'node_modules',
|
||||
|
@ -10,7 +10,7 @@ import { useAppInfos } from '@strapi/helper-plugin';
|
||||
import Wrapper, { A } from './Wrapper';
|
||||
|
||||
function LeftMenuFooter() {
|
||||
const projectType = process.env.STRAPI_ADMIN_PROJECT_TYPE;
|
||||
const projectType = strapi.projectType;
|
||||
const { strapiVersion } = useAppInfos();
|
||||
|
||||
return (
|
||||
|
@ -10,6 +10,10 @@ import appReducers from './reducers';
|
||||
window.strapi = {
|
||||
backendURL: process.env.STRAPI_ADMIN_BACKEND_URL,
|
||||
isEE: false,
|
||||
features: {
|
||||
SSO: 'sso',
|
||||
},
|
||||
projectType: 'Community',
|
||||
};
|
||||
|
||||
const appConfig = {
|
||||
@ -38,11 +42,18 @@ const run = async () => {
|
||||
try {
|
||||
const {
|
||||
data: {
|
||||
data: { isEE },
|
||||
data: { isEE, features },
|
||||
},
|
||||
} = await axiosInstance.get('/admin/project-type');
|
||||
|
||||
window.strapi.isEE = isEE;
|
||||
window.strapi.features = {
|
||||
...window.strapi.features,
|
||||
allFeatures: features,
|
||||
isEnabled: f => features.includes(f),
|
||||
};
|
||||
|
||||
window.strapi.projectType = isEE ? 'Enterprise' : 'Community';
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
|
@ -1,5 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
jest.mock('@strapi/strapi/lib/utils/ee', () => {
|
||||
const eeModule = () => false;
|
||||
|
||||
Object.assign(eeModule, {
|
||||
features: {
|
||||
isEnabled() {
|
||||
return false;
|
||||
},
|
||||
getEnabled() {
|
||||
return [];
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return eeModule;
|
||||
});
|
||||
|
||||
const adminController = require('../admin');
|
||||
|
||||
describe('Admin Controller', () => {
|
||||
|
@ -3,6 +3,10 @@
|
||||
const execa = require('execa');
|
||||
const _ = require('lodash');
|
||||
|
||||
// FIXME
|
||||
// eslint-disable-next-line node/no-extraneous-require
|
||||
const { features } = require('@strapi/strapi/lib/utils/ee');
|
||||
|
||||
const PLUGIN_NAME_REGEX = /^[A-Za-z][A-Za-z0-9-_]+$/;
|
||||
|
||||
/**
|
||||
@ -21,7 +25,7 @@ module.exports = {
|
||||
// When removing this we need to update the /admin/src/index.js file
|
||||
// where we set the strapi.window.isEE value
|
||||
async getProjectType() {
|
||||
return { data: { isEE: strapi.EE } };
|
||||
return { data: { isEE: strapi.EE, features: features.getEnabled() } };
|
||||
},
|
||||
|
||||
async init() {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import baseModel from '../../../../../../admin/src/components/Users/ModalCreateBody/utils/formDataModel';
|
||||
|
||||
const ssoInputsModel = process.env.STRAPI_ADMIN_ENABLED_EE_FEATURES.includes('sso')
|
||||
const ssoInputsModel = strapi.features.isEnabled(strapi.features.SSO)
|
||||
? {
|
||||
useSSORegistration: true,
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import baseForm from '../../../../../../admin/src/components/Users/ModalCreateBody/utils/roleSettingsForm';
|
||||
|
||||
const ssoInputs = process.env.STRAPI_ADMIN_ENABLED_EE_FEATURES.includes('sso')
|
||||
const ssoInputs = strapi.features.isEnabled(strapi.features.SSO)
|
||||
? {
|
||||
useSSORegistration: {
|
||||
label: 'Settings.permissions.users.form.sso',
|
||||
|
@ -1,6 +1,6 @@
|
||||
import adminPermissions from '../../../../../admin/src/permissions';
|
||||
|
||||
const ssoGlobalRoutes = process.env.STRAPI_ADMIN_ENABLED_EE_FEATURES.includes('sso')
|
||||
const ssoGlobalRoutes = strapi.features.isEnabled(strapi.features.SSO)
|
||||
? [
|
||||
{
|
||||
intlLabel: { id: 'Settings.sso.title', defaultMessage: 'Single Sign-On' },
|
||||
|
@ -16,7 +16,7 @@ import {
|
||||
import { useAuthProviders } from '../../../../hooks';
|
||||
|
||||
const Login = loginProps => {
|
||||
const ssoEnabled = process.env.STRAPI_ADMIN_ENABLED_EE_FEATURES.includes('sso');
|
||||
const ssoEnabled = strapi.features.isEnabled(strapi.features.SSO);
|
||||
|
||||
const theme = useTheme();
|
||||
const { isLoading, data: providers } = useAuthProviders({ ssoEnabled });
|
||||
|
@ -16,7 +16,7 @@ const ProviderWrapper = styled.div`
|
||||
`;
|
||||
|
||||
const Providers = () => {
|
||||
const ssoEnabled = process.env.STRAPI_ADMIN_ENABLED_EE_FEATURES.includes('sso');
|
||||
const ssoEnabled = strapi.features.isEnabled(strapi.features.SSO);
|
||||
|
||||
const { push } = useHistory();
|
||||
const { formatMessage } = useIntl();
|
||||
|
@ -1,6 +1,6 @@
|
||||
import SingleSignOn from '../SingleSignOn';
|
||||
|
||||
const ssoRoutes = process.env.STRAPI_ADMIN_ENABLED_EE_FEATURES.includes('sso')
|
||||
const ssoRoutes = strapi.features.isEnabled(strapi.features.SSO)
|
||||
? [
|
||||
{
|
||||
Component: SingleSignOn,
|
||||
|
@ -12,7 +12,7 @@ if (fs.existsSync(dotenvFilePath)) {
|
||||
|
||||
const STRAPI_ADMIN = /^STRAPI_ADMIN_/i;
|
||||
|
||||
const getClientEnvironment = (useEE, options) => {
|
||||
const getClientEnvironment = options => {
|
||||
const raw = Object.keys(process.env)
|
||||
.filter(key => STRAPI_ADMIN.test(key))
|
||||
.reduce(
|
||||
@ -25,8 +25,6 @@ const getClientEnvironment = (useEE, options) => {
|
||||
ADMIN_PATH: options.adminPath,
|
||||
NODE_ENV: options.env || 'development',
|
||||
STRAPI_ADMIN_BACKEND_URL: options.backend,
|
||||
STRAPI_ADMIN_ENABLED_EE_FEATURES: options.features,
|
||||
STRAPI_ADMIN_PROJECT_TYPE: useEE ? 'Enterprise' : 'Community',
|
||||
STRAPI_ADMIN_SHOW_TUTORIALS: 'true',
|
||||
STRAPI_ADMIN_UPDATE_NOTIFICATION: 'true',
|
||||
}
|
||||
|
@ -7,8 +7,6 @@ const webpack = require('webpack');
|
||||
const WebpackDevServer = require('webpack-dev-server');
|
||||
const chalk = require('chalk');
|
||||
const chokidar = require('chokidar');
|
||||
// eslint-disable-next-line node/no-extraneous-require
|
||||
const hasEE = require('@strapi/strapi/lib/utils/ee');
|
||||
const getWebpackConfig = require('./webpack.config');
|
||||
|
||||
const getPkgPath = name => path.dirname(require.resolve(`${name}/package.json`));
|
||||
@ -16,7 +14,7 @@ const getPkgPath = name => path.dirname(require.resolve(`${name}/package.json`))
|
||||
function getCustomWebpackConfig(dir, config) {
|
||||
const adminConfigPath = path.join(dir, 'admin', 'admin.config.js');
|
||||
|
||||
let webpackConfig = getWebpackConfig({ useEE: hasEE({ dir }), ...config });
|
||||
let webpackConfig = getWebpackConfig(config);
|
||||
|
||||
if (fs.existsSync(adminConfigPath)) {
|
||||
const adminConfig = require(path.resolve(adminConfigPath));
|
||||
@ -242,12 +240,21 @@ async function watchAdmin({ dir, host, port, browser, options }) {
|
||||
const dest = path.join(dir, 'build');
|
||||
const env = 'development';
|
||||
|
||||
const cacheDir = path.join(dir, '.cache');
|
||||
|
||||
// Roots for the @strapi/babel-plugin-switch-ee-ce
|
||||
const roots = {
|
||||
eeRoot: path.resolve(cacheDir, 'ee', 'admin'),
|
||||
ceRoot: path.resolve(cacheDir, 'admin', 'src'),
|
||||
};
|
||||
|
||||
const args = {
|
||||
entry,
|
||||
dest,
|
||||
env,
|
||||
port,
|
||||
options,
|
||||
roots,
|
||||
};
|
||||
|
||||
const opts = {
|
||||
|
@ -16,9 +16,7 @@ const buildAdmin = async () => {
|
||||
options: {
|
||||
backend: 'http://localhost:1337',
|
||||
adminPath: '/admin/',
|
||||
features: [],
|
||||
},
|
||||
useEE: false,
|
||||
};
|
||||
|
||||
const compiler = webpack(webpackConfig(args));
|
||||
|
@ -18,17 +18,13 @@ module.exports = () => {
|
||||
const options = {
|
||||
backend: 'http://localhost:1337',
|
||||
adminPath: '/admin/',
|
||||
features: process.env.STRAPI_ADMIN_ENABLED_EE_FEATURES || ['sso'],
|
||||
};
|
||||
|
||||
const useEE = process.env.STRAPI_DISABLE_EE === 'true' ? false : true;
|
||||
|
||||
const args = {
|
||||
entry,
|
||||
dest,
|
||||
env,
|
||||
options,
|
||||
useEE,
|
||||
};
|
||||
|
||||
const config = webpackConfig(args);
|
||||
|
@ -12,7 +12,6 @@ const alias = require('./webpack.alias');
|
||||
const getClientEnvironment = require('./env');
|
||||
|
||||
module.exports = ({
|
||||
useEE,
|
||||
entry,
|
||||
dest,
|
||||
env,
|
||||
@ -29,7 +28,7 @@ module.exports = ({
|
||||
}) => {
|
||||
const isProduction = env === 'production';
|
||||
|
||||
const envVariables = getClientEnvironment(useEE, { ...options, env });
|
||||
const envVariables = getClientEnvironment({ ...options, env });
|
||||
|
||||
const webpackPlugins = isProduction
|
||||
? [
|
||||
|
@ -11,7 +11,7 @@ const useTracking = () => {
|
||||
try {
|
||||
axios.post('https://analytics.strapi.io/track', {
|
||||
event,
|
||||
properties: { ...properties, projectType: process.env.STRAPI_ADMIN_PROJECT_TYPE },
|
||||
properties: { ...properties, projectType: strapi.projectType },
|
||||
uuid,
|
||||
});
|
||||
} catch (err) {
|
||||
|
@ -34,7 +34,6 @@ module.exports = async ({ clean, optimization }) => {
|
||||
options: {
|
||||
backend: serverUrl,
|
||||
adminPath: addSlash(adminPath),
|
||||
features: ee.isEE ? ee.features.getEnabled() : [],
|
||||
},
|
||||
})
|
||||
.then(() => {
|
||||
|
@ -0,0 +1,3 @@
|
||||
# Strapi babel plugin switch EE CE
|
||||
|
||||
This plugin allows to switch from EE to CE at runtime.
|
@ -1,5 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
// Widely inspired from https://github.com/tleunen/babel-plugin-module-resolver/tree/master/src
|
||||
|
||||
const transformImport = require('./transformers/import');
|
||||
const normalizeOptions = require('./normalizeOptions');
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
// From https://github.com/tleunen/babel-plugin-module-resolver/blob/master/src/mapToRelative.js
|
||||
|
||||
const path = require('path');
|
||||
|
||||
const { toPosixPath } = require('./utils');
|
||||
|
@ -1,5 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
// Adapted from https://github.com/tleunen/babel-plugin-module-resolver/blob/master/src/normalizeOptions.js
|
||||
|
||||
const path = require('path');
|
||||
const { createSelector } = require('reselect');
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
// Adapted from https://github.com/tleunen/babel-plugin-module-resolver/blob/master/src/resolvePath.js
|
||||
|
||||
const path = require('path');
|
||||
const normalizeOptions = require('./normalizeOptions');
|
||||
const mapToRelative = require('./mapToRelative');
|
||||
|
@ -1,5 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
// From https://github.com/tleunen/babel-plugin-module-resolver/blob/master/src/utils.js
|
||||
|
||||
const path = require('path');
|
||||
const resolve = require('resolve');
|
||||
|
||||
@ -48,7 +50,6 @@ const isRelativePath = nodePath => {
|
||||
|
||||
module.exports = {
|
||||
nodeResolvePath,
|
||||
|
||||
replaceExtension,
|
||||
stripExtension,
|
||||
toPosixPath,
|
||||
|
@ -7,35 +7,18 @@
|
||||
|
||||
// Setup the strapi function global variable
|
||||
|
||||
// FIXME create a better jest setup
|
||||
import '@testing-library/jest-dom/extend-expect';
|
||||
|
||||
const React = require('react');
|
||||
const hoistNonReactStatics = require('hoist-non-react-statics');
|
||||
|
||||
const hoc = () => WrappedComponent => {
|
||||
class HocInjector extends React.Component {
|
||||
static WrappedComponent = WrappedComponent;
|
||||
|
||||
render() {
|
||||
return <WrappedComponent {...this.props} />;
|
||||
}
|
||||
}
|
||||
|
||||
return hoistNonReactStatics(HocInjector, WrappedComponent);
|
||||
};
|
||||
|
||||
// FIXME
|
||||
global.process.env.STRAPI_ADMIN_ENABLED_EE_FEATURES = [];
|
||||
global.process.env.ADMIN_PATH = '/admin/';
|
||||
|
||||
global.strapi = {
|
||||
backendURL: 'http://localhost:1337',
|
||||
injectReducer: hoc,
|
||||
injectSaga: hoc,
|
||||
notification: {
|
||||
error: jest.fn(),
|
||||
info: jest.fn(),
|
||||
success: jest.fn(),
|
||||
warning: jest.fn(),
|
||||
isEE: false,
|
||||
features: {
|
||||
SSO: 'sso',
|
||||
allFeatures: [],
|
||||
isEnabled: () => false,
|
||||
},
|
||||
projectType: 'Community',
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user