@strapi/strapi 4.25.2 → 4.25.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Strapi.js +3 -3
- package/dist/Strapi.js.map +1 -1
- package/dist/commands/actions/routes/list/action.js +2 -2
- package/dist/commands/actions/routes/list/action.js.map +1 -1
- package/dist/commands/utils/helpers.js +2 -2
- package/dist/commands/utils/helpers.js.map +1 -1
- package/dist/core/app-configuration/index.js +2 -2
- package/dist/core/app-configuration/index.js.map +1 -1
- package/dist/core/domain/content-type/index.js +4 -4
- package/dist/core/domain/content-type/index.js.map +1 -1
- package/dist/core/loaders/apis.js +2 -2
- package/dist/core/loaders/apis.js.map +1 -1
- package/dist/core/loaders/plugins/get-enabled-plugins.js +8 -8
- package/dist/core/loaders/plugins/get-enabled-plugins.js.map +1 -1
- package/dist/core/loaders/plugins/get-user-plugins-config.js +2 -2
- package/dist/core/loaders/plugins/get-user-plugins-config.js.map +1 -1
- package/dist/core/loaders/plugins/index.js +6 -6
- package/dist/core/loaders/plugins/index.js.map +1 -1
- package/dist/core/registries/apis.js +2 -2
- package/dist/core/registries/apis.js.map +1 -1
- package/dist/core/registries/content-types.js +3 -3
- package/dist/core/registries/content-types.js.map +1 -1
- package/dist/core/registries/controllers.js +3 -3
- package/dist/core/registries/controllers.js.map +1 -1
- package/dist/core/registries/custom-fields.js +4 -4
- package/dist/core/registries/custom-fields.js.map +1 -1
- package/dist/core/registries/hooks.js +2 -2
- package/dist/core/registries/hooks.js.map +1 -1
- package/dist/core/registries/middlewares.js +3 -3
- package/dist/core/registries/middlewares.js.map +1 -1
- package/dist/core/registries/modules.js +3 -3
- package/dist/core/registries/modules.js.map +1 -1
- package/dist/core/registries/plugins.js +2 -2
- package/dist/core/registries/plugins.js.map +1 -1
- package/dist/core/registries/policies.js +3 -3
- package/dist/core/registries/policies.js.map +1 -1
- package/dist/core/registries/services.js +3 -3
- package/dist/core/registries/services.js.map +1 -1
- package/dist/core-api/controller/collection-type.js +3 -3
- package/dist/core-api/controller/collection-type.js.map +1 -1
- package/dist/core-api/controller/index.js +2 -2
- package/dist/core-api/controller/index.js.map +1 -1
- package/dist/core-api/controller/single-type.js +2 -2
- package/dist/core-api/controller/single-type.js.map +1 -1
- package/dist/core-api/controller/transform.js +7 -7
- package/dist/core-api/controller/transform.js.map +1 -1
- package/dist/core-api/service/collection-type.js +2 -2
- package/dist/core-api/service/collection-type.js.map +1 -1
- package/dist/core-api/service/pagination.js +10 -10
- package/dist/core-api/service/pagination.js.map +1 -1
- package/dist/core-api/service/single-type.js +2 -2
- package/dist/core-api/service/single-type.js.map +1 -1
- package/dist/ee/index.js +3 -3
- package/dist/ee/index.js.map +1 -1
- package/dist/factories.js +4 -4
- package/dist/factories.js.map +1 -1
- package/dist/load/filepath-to-prop-path.d.ts +1 -1
- package/dist/load/filepath-to-prop-path.d.ts.map +1 -1
- package/dist/load/filepath-to-prop-path.js +27 -6
- package/dist/load/filepath-to-prop-path.js.map +1 -1
- package/dist/load/filepath-to-prop-path.mjs +25 -5
- package/dist/load/filepath-to-prop-path.mjs.map +1 -1
- package/dist/load/load-files.js +2 -2
- package/dist/load/load-files.js.map +1 -1
- package/dist/load/load-files.mjs +2 -2
- package/dist/load/load-files.mjs.map +1 -1
- package/dist/middlewares/body.js +2 -2
- package/dist/middlewares/body.js.map +1 -1
- package/dist/middlewares/public/index.js +4 -4
- package/dist/middlewares/public/index.js.map +1 -1
- package/dist/middlewares/responses.js +2 -2
- package/dist/middlewares/responses.js.map +1 -1
- package/dist/middlewares/security.js +3 -3
- package/dist/middlewares/security.js.map +1 -1
- package/dist/middlewares/session.js +2 -2
- package/dist/middlewares/session.js.map +1 -1
- package/dist/services/auth/index.js +3 -3
- package/dist/services/auth/index.js.map +1 -1
- package/dist/services/core-store.js +3 -3
- package/dist/services/core-store.js.map +1 -1
- package/dist/services/cron.js +3 -3
- package/dist/services/cron.js.map +1 -1
- package/dist/services/entity-service/attributes/transforms.js +3 -3
- package/dist/services/entity-service/attributes/transforms.js.map +1 -1
- package/dist/services/entity-service/components.js +18 -18
- package/dist/services/entity-service/components.js.map +1 -1
- package/dist/services/entity-service/params.js +2 -2
- package/dist/services/entity-service/params.js.map +1 -1
- package/dist/services/entity-validator/index.js +19 -19
- package/dist/services/entity-validator/index.js.map +1 -1
- package/dist/services/server/compose-endpoint.js +7 -7
- package/dist/services/server/compose-endpoint.js.map +1 -1
- package/dist/services/server/koa.js +3 -3
- package/dist/services/server/koa.js.map +1 -1
- package/dist/services/server/middleware.js +3 -3
- package/dist/services/server/middleware.js.map +1 -1
- package/dist/services/server/routing.js +2 -2
- package/dist/services/server/routing.js.map +1 -1
- package/dist/services/utils/dynamic-zones.js +5 -5
- package/dist/services/utils/dynamic-zones.js.map +1 -1
- package/dist/utils/cron.js +3 -3
- package/dist/utils/cron.js.map +1 -1
- package/dist/utils/is-initialized.js +3 -3
- package/dist/utils/is-initialized.js.map +1 -1
- package/dist/utils/startup-logger.js +4 -4
- package/dist/utils/startup-logger.js.map +1 -1
- package/dist/utils/startup-logger.mjs +3 -3
- package/dist/utils/startup-logger.mjs.map +1 -1
- package/package.json +21 -21
- package/dist/load/glob.d.ts +0 -7
- package/dist/load/glob.d.ts.map +0 -1
- package/dist/load/glob.js +0 -15
- package/dist/load/glob.js.map +0 -1
- package/dist/load/glob.mjs +0 -14
- package/dist/load/glob.mjs.map +0 -1
package/dist/Strapi.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const path = require("path");
|
|
3
3
|
const _ = require("lodash");
|
|
4
|
-
const
|
|
4
|
+
const fp = require("lodash/fp");
|
|
5
5
|
const logger = require("@strapi/logger");
|
|
6
6
|
const database = require("@strapi/database");
|
|
7
7
|
const strapiUtils = require("@strapi/utils");
|
|
@@ -439,11 +439,11 @@ class Strapi {
|
|
|
439
439
|
async runLifecyclesFunctions(lifecycleName) {
|
|
440
440
|
await this.container.get("modules")[lifecycleName]();
|
|
441
441
|
const adminLifecycleFunction = this.admin && this.admin[lifecycleName];
|
|
442
|
-
if (
|
|
442
|
+
if (fp.isFunction(adminLifecycleFunction)) {
|
|
443
443
|
await adminLifecycleFunction({ strapi: this });
|
|
444
444
|
}
|
|
445
445
|
const userLifecycleFunction = this.app && this.app[lifecycleName];
|
|
446
|
-
if (
|
|
446
|
+
if (fp.isFunction(userLifecycleFunction)) {
|
|
447
447
|
await userLifecycleFunction({ strapi: this });
|
|
448
448
|
}
|
|
449
449
|
}
|
package/dist/Strapi.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Strapi.js","sources":["../src/Strapi.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-namespace */\n/* eslint-disable vars-on-top */\n/* eslint-disable no-var */\nimport path from 'path';\nimport _ from 'lodash';\nimport { isFunction } from 'lodash/fp';\nimport { Logger, createLogger } from '@strapi/logger';\nimport { Database } from '@strapi/database';\nimport { hooks } from '@strapi/utils';\nimport type {\n Strapi as StrapiI,\n Server,\n Container,\n EntityService,\n EventHub,\n StartupLogger,\n CronService,\n WebhookStore,\n CoreStore,\n TelemetryService,\n RequestContext,\n CustomFields,\n Fetch,\n StrapiFS,\n StrapiDirectories,\n Reloader,\n EntityValidator,\n Common,\n Shared,\n Schema,\n} from '@strapi/types';\n\nimport loadConfiguration from './core/app-configuration';\n\nimport * as factories from './factories';\nimport compile from './compile';\n\nimport * as utils from './utils';\nimport { createContainer } from './container';\nimport createStrapiFs from './services/fs';\nimport createEventHub from './services/event-hub';\nimport { createServer } from './services/server';\nimport createWebhookRunner, { WebhookRunner } from './services/webhook-runner';\nimport { webhookModel, createWebhookStore } from './services/webhook-store';\nimport { createCoreStore, coreStoreModel } from './services/core-store';\nimport createEntityService from './services/entity-service';\nimport createCronService from './services/cron';\nimport entityValidator from './services/entity-validator';\nimport createTelemetry from './services/metrics';\nimport requestContext from './services/request-context';\nimport createAuth from './services/auth';\nimport createCustomFields from './services/custom-fields';\nimport createContentAPI from './services/content-api';\nimport createUpdateNotifier from './utils/update-notifier';\nimport createStartupLogger from './utils/startup-logger';\nimport { createStrapiFetch } from './utils/fetch';\nimport { LIFECYCLES } from './utils/lifecycles';\nimport ee from './utils/ee';\nimport contentTypesRegistry from './core/registries/content-types';\nimport servicesRegistry from './core/registries/services';\nimport policiesRegistry from './core/registries/policies';\nimport middlewaresRegistry from './core/registries/middlewares';\nimport hooksRegistry from './core/registries/hooks';\nimport controllersRegistry from './core/registries/controllers';\nimport modulesRegistry from './core/registries/modules';\nimport pluginsRegistry from './core/registries/plugins';\nimport customFieldsRegistry from './core/registries/custom-fields';\nimport createConfigProvider from './core/registries/config';\nimport apisRegistry from './core/registries/apis';\nimport bootstrap from './core/bootstrap';\nimport loaders from './core/loaders';\nimport { destroyOnSignal } from './utils/signals';\nimport getNumberOfDynamicZones from './services/utils/dynamic-zones';\nimport sanitizersRegistry from './core/registries/sanitizers';\nimport validatorsRegistry from './core/registries/validators';\nimport convertCustomFieldType from './utils/convert-custom-field-type';\n\n// TODO: move somewhere else\nimport * as draftAndPublishSync from './migrations/draft-publish';\nimport { FeaturesService, createFeaturesService } from './services/features';\n\n/**\n * Resolve the working directories based on the instance options.\n *\n * Behavior:\n * - `appDir` is the directory where Strapi will write every file (schemas, generated APIs, controllers or services)\n * - `distDir` is the directory where Strapi will read configurations, schemas and any compiled code\n *\n * Default values:\n * - If `appDir` is `undefined`, it'll be set to `process.cwd()`\n * - If `distDir` is `undefined`, it'll be set to `appDir`\n */\nconst resolveWorkingDirectories = (opts: { appDir?: string; distDir?: string }) => {\n const cwd = process.cwd();\n\n const appDir = opts.appDir ? path.resolve(cwd, opts.appDir) : cwd;\n const distDir = opts.distDir ? path.resolve(cwd, opts.distDir) : appDir;\n\n return { app: appDir, dist: distDir };\n};\n\nconst reloader = (strapi: Strapi) => {\n const state = {\n shouldReload: 0,\n isWatching: true,\n };\n\n function reload() {\n if (state.shouldReload > 0) {\n // Reset the reloading state\n state.shouldReload -= 1;\n reload.isReloading = false;\n return;\n }\n\n if (strapi.config.get('autoReload')) {\n process.send?.('reload');\n }\n }\n\n Object.defineProperty(reload, 'isWatching', {\n configurable: true,\n enumerable: true,\n set(value) {\n // Special state when the reloader is disabled temporarly (see GraphQL plugin example).\n if (state.isWatching === false && value === true) {\n state.shouldReload += 1;\n }\n state.isWatching = value;\n },\n get() {\n return state.isWatching;\n },\n });\n\n reload.isReloading = false;\n reload.isWatching = true;\n\n return reload;\n};\n\nexport type LoadedStrapi = Required<Strapi>;\n\nclass Strapi implements StrapiI {\n server: Server;\n\n container: Container;\n\n log: Logger;\n\n fs: StrapiFS;\n\n eventHub: EventHub;\n\n startupLogger: StartupLogger;\n\n cron: CronService;\n\n webhookRunner?: WebhookRunner;\n\n webhookStore?: WebhookStore;\n\n store?: CoreStore;\n\n entityValidator?: EntityValidator;\n\n entityService?: EntityService.EntityService;\n\n telemetry: TelemetryService;\n\n requestContext: RequestContext;\n\n customFields: CustomFields.CustomFields;\n\n fetch: Fetch;\n\n dirs: StrapiDirectories;\n\n admin?: Common.Module;\n\n isLoaded: boolean;\n\n db?: Database;\n\n app: any;\n\n EE?: boolean;\n\n components: Shared.Components;\n\n reload: Reloader;\n\n features: FeaturesService;\n\n constructor(opts: StrapiOptions = {}) {\n destroyOnSignal(this);\n\n const rootDirs = resolveWorkingDirectories(opts);\n\n // Load the app configuration from the dist directory\n const appConfig = loadConfiguration(rootDirs, opts);\n\n // Instantiate the Strapi container\n this.container = createContainer(this)\n .register('config', createConfigProvider(appConfig))\n .register('content-types', contentTypesRegistry())\n .register('services', servicesRegistry(this))\n .register('policies', policiesRegistry())\n .register('middlewares', middlewaresRegistry())\n .register('hooks', hooksRegistry())\n .register('controllers', controllersRegistry(this))\n .register('modules', modulesRegistry(this))\n .register('plugins', pluginsRegistry(this))\n .register('custom-fields', customFieldsRegistry(this))\n .register('apis', apisRegistry(this))\n .register('auth', createAuth())\n .register('content-api', createContentAPI(this))\n .register('sanitizers', sanitizersRegistry())\n .register('validators', validatorsRegistry());\n\n this.components = {};\n\n // Create a mapping of every useful directory (for the app, dist and static directories)\n this.dirs = utils.getDirs(rootDirs, { strapi: this });\n\n // Strapi state management variables\n this.isLoaded = false;\n this.reload = reloader(this);\n\n // Instantiate the Koa app & the HTTP server\n this.server = createServer(this);\n\n // Strapi utils instantiation\n this.fs = createStrapiFs(this);\n this.eventHub = createEventHub();\n this.startupLogger = createStartupLogger(this);\n this.log = createLogger(this.config.get('logger', {}));\n this.cron = createCronService();\n this.telemetry = createTelemetry(this);\n this.requestContext = requestContext;\n this.customFields = createCustomFields(this);\n this.fetch = createStrapiFetch(this);\n this.features = createFeaturesService(this);\n\n createUpdateNotifier(this).notify();\n\n Object.defineProperty<Strapi>(this, 'EE', {\n get: () => {\n ee.init(this.dirs.app.root, this.log);\n return ee.isEE;\n },\n configurable: false,\n });\n }\n\n get config() {\n return this.container.get('config');\n }\n\n get services() {\n return this.container.get('services').getAll();\n }\n\n service(uid: Common.UID.Service) {\n return this.container.get('services').get(uid);\n }\n\n get controllers() {\n return this.container.get('controllers').getAll();\n }\n\n controller(uid: Common.UID.Controller) {\n return this.container.get('controllers').get(uid);\n }\n\n get contentTypes(): Shared.ContentTypes {\n return this.container.get('content-types').getAll();\n }\n\n contentType(name: Common.UID.ContentType) {\n return this.container.get('content-types').get(name);\n }\n\n get policies() {\n return this.container.get('policies').getAll();\n }\n\n policy(name: string) {\n return this.container.get('policies').get(name);\n }\n\n get middlewares() {\n return this.container.get('middlewares').getAll();\n }\n\n middleware(name: string) {\n return this.container.get('middlewares').get(name);\n }\n\n get plugins(): Record<string, Common.Plugin> {\n return this.container.get('plugins').getAll();\n }\n\n plugin(name: string): Common.Plugin {\n return this.container.get('plugins').get(name);\n }\n\n get hooks() {\n return this.container.get('hooks').getAll();\n }\n\n hook(name: string) {\n return this.container.get('hooks').get(name);\n }\n\n // api(name) {\n // return this.container.get('apis').get(name);\n // }\n\n get api(): Record<string, Common.Module> {\n return this.container.get('apis').getAll();\n }\n\n get auth() {\n return this.container.get('auth');\n }\n\n get contentAPI() {\n return this.container.get('content-api');\n }\n\n get sanitizers() {\n return this.container.get('sanitizers');\n }\n\n get validators() {\n return this.container.get('validators');\n }\n\n async start() {\n try {\n if (!this.isLoaded) {\n await this.load();\n }\n\n await this.listen();\n\n return this;\n } catch (error) {\n return this.stopWithError(error);\n }\n }\n\n async destroy() {\n await this.server.destroy();\n await this.runLifecyclesFunctions(LIFECYCLES.DESTROY);\n\n this.eventHub.destroy();\n\n await this.db?.destroy();\n\n this.telemetry.destroy();\n this.cron.destroy();\n\n process.removeAllListeners();\n\n // @ts-expect-error: Allow clean delete of global.strapi to allow re-instanciation\n delete global.strapi;\n }\n\n sendStartupTelemetry() {\n // Emit started event.\n // do not await to avoid slower startup\n // This event is anonymous\n this.telemetry\n .send('didStartServer', {\n groupProperties: {\n database: this.config.get('database.connection.client'),\n plugins: Object.keys(this.plugins),\n numberOfAllContentTypes: _.size(this.contentTypes), // TODO: V5: This event should be renamed numberOfContentTypes in V5 as the name is already taken to describe the number of content types using i18n.\n numberOfComponents: _.size(this.components),\n numberOfDynamicZones: getNumberOfDynamicZones(),\n numberOfCustomControllers: Object.values<Common.Controller>(this.controllers).filter(\n // TODO: Fix this at the content API loader level to prevent future types issues\n (controller) => controller !== undefined && factories.isCustomController(controller)\n ).length,\n environment: this.config.environment,\n // TODO: to add back\n // providers: this.config.installedProviders,\n },\n })\n .catch(this.log.error);\n }\n\n async openAdmin({ isInitialized }: { isInitialized: boolean }) {\n const shouldOpenAdmin =\n this.config.get('environment') === 'development' &&\n this.config.get('admin.autoOpen', true) !== false;\n\n if (shouldOpenAdmin && !isInitialized) {\n try {\n await utils.openBrowser(this.config);\n this.telemetry.send('didOpenTab');\n } catch (e) {\n this.telemetry.send('didNotOpenTab');\n }\n }\n }\n\n async postListen() {\n const isInitialized = await utils.isInitialized(this);\n\n this.startupLogger.logStartupMessage({ isInitialized });\n\n this.sendStartupTelemetry();\n this.openAdmin({ isInitialized });\n }\n\n /**\n * Add behaviors to the server\n */\n async listen() {\n return new Promise<void>((resolve, reject) => {\n const onListen = async () => {\n try {\n await this.postListen();\n\n resolve();\n } catch (error) {\n reject(error);\n }\n };\n\n const listenSocket = this.config.get('server.socket');\n\n if (listenSocket) {\n this.server.listen(listenSocket, onListen);\n } else {\n const { host, port } = this.config.get('server');\n\n this.server.listen(port, host, onListen);\n }\n });\n }\n\n stopWithError(err: unknown, customMessage?: string): never {\n this.log.debug(`⛔️ Server wasn't able to start properly.`);\n if (customMessage) {\n this.log.error(customMessage);\n }\n\n this.log.error(err);\n return this.stop();\n }\n\n stop(exitCode = 1): never {\n this.destroy();\n\n if (this.config.get('autoReload')) {\n process.send?.('stop');\n }\n\n // Kill process\n process.exit(exitCode);\n }\n\n async loadAdmin() {\n await loaders.loadAdmin(this);\n }\n\n async loadPlugins() {\n await loaders.loadPlugins(this);\n }\n\n async loadPolicies() {\n await loaders.loadPolicies(this);\n }\n\n async loadAPIs() {\n await loaders.loadAPIs(this);\n }\n\n async loadComponents() {\n this.components = await loaders.loadComponents(this);\n }\n\n async loadMiddlewares() {\n await loaders.loadMiddlewares(this);\n }\n\n async loadApp() {\n this.app = await loaders.loadSrcIndex(this);\n }\n\n async loadSanitizers() {\n await loaders.loadSanitizers(this);\n }\n\n async loadValidators() {\n await loaders.loadValidators(this);\n }\n\n registerInternalHooks() {\n this.container\n .get('hooks')\n .set('strapi::content-types.beforeSync', hooks.createAsyncParallelHook());\n\n this.container\n .get('hooks')\n .set('strapi::content-types.afterSync', hooks.createAsyncParallelHook());\n\n this.hook('strapi::content-types.beforeSync').register(draftAndPublishSync.disable);\n this.hook('strapi::content-types.afterSync').register(draftAndPublishSync.enable);\n }\n\n async register() {\n await Promise.all([\n this.loadApp(),\n this.loadSanitizers(),\n this.loadValidators(),\n this.loadPlugins(),\n this.loadAdmin(),\n this.loadAPIs(),\n this.loadComponents(),\n this.loadMiddlewares(),\n this.loadPolicies(),\n ]);\n\n await bootstrap({ strapi: this });\n\n // init webhook runner\n this.webhookRunner = createWebhookRunner({\n eventHub: this.eventHub,\n logger: this.log,\n configuration: this.config.get('server.webhooks', {}),\n fetch: this.fetch,\n });\n\n this.registerInternalHooks();\n\n this.telemetry.register();\n\n await this.runLifecyclesFunctions(LIFECYCLES.REGISTER);\n // NOTE: Swap type customField for underlying data type\n convertCustomFieldType(this);\n\n return this;\n }\n\n async bootstrap() {\n const contentTypes = [\n coreStoreModel,\n webhookModel,\n ...Object.values(this.contentTypes),\n ...Object.values(this.components),\n ];\n\n this.db = await Database.init({\n ...this.config.get('database'),\n models: Database.transformContentTypes(contentTypes),\n });\n\n this.store = createCoreStore({ db: this.db });\n this.webhookStore = createWebhookStore({ db: this.db });\n\n this.entityValidator = entityValidator;\n this.entityService = createEntityService({\n strapi: this,\n db: this.db,\n eventHub: this.eventHub,\n entityValidator: this.entityValidator,\n });\n\n if (this.config.get('server.cron.enabled', true)) {\n const cronTasks = this.config.get('server.cron.tasks', {});\n this.cron.add(cronTasks);\n }\n\n this.telemetry.bootstrap();\n\n let oldContentTypes;\n if (await this.db.getSchemaConnection().hasTable(coreStoreModel.collectionName)) {\n oldContentTypes = await this.store.get({\n type: 'strapi',\n name: 'content_types',\n key: 'schema',\n });\n }\n\n await this.hook('strapi::content-types.beforeSync').call({\n oldContentTypes,\n contentTypes: this.contentTypes,\n });\n\n await this.db.schema.sync();\n\n if (this.EE) {\n await ee.checkLicense({ strapi: this });\n }\n\n await this.hook('strapi::content-types.afterSync').call({\n oldContentTypes,\n contentTypes: this.contentTypes,\n });\n\n await this.store.set({\n type: 'strapi',\n name: 'content_types',\n key: 'schema',\n value: this.contentTypes,\n });\n\n await this.startWebhooks();\n\n await this.server.initMiddlewares();\n this.server.initRouting();\n\n await this.contentAPI.permissions.registerActions();\n\n await this.runLifecyclesFunctions(LIFECYCLES.BOOTSTRAP);\n\n this.cron.start();\n\n return this;\n }\n\n async load() {\n await this.register();\n await this.bootstrap();\n\n this.isLoaded = true;\n\n return this as this & Required<StrapiI>;\n }\n\n async startWebhooks() {\n const webhooks = await this.webhookStore?.findWebhooks();\n if (!webhooks) {\n return;\n }\n\n for (const webhook of webhooks) {\n this.webhookRunner?.add(webhook);\n }\n }\n\n async runLifecyclesFunctions(lifecycleName: 'register' | 'bootstrap' | 'destroy') {\n // plugins\n await this.container.get('modules')[lifecycleName]();\n\n // admin\n const adminLifecycleFunction = this.admin && this.admin[lifecycleName];\n if (isFunction(adminLifecycleFunction)) {\n await adminLifecycleFunction({ strapi: this });\n }\n\n // user\n const userLifecycleFunction = this.app && this.app[lifecycleName];\n if (isFunction(userLifecycleFunction)) {\n await userLifecycleFunction({ strapi: this });\n }\n }\n\n getModel(uid: Common.UID.ContentType): Schema.ContentType;\n getModel(uid: Common.UID.Component): Schema.Component;\n getModel<TUID extends Common.UID.Schema>(\n uid: TUID\n ): Schema.ContentType | Schema.Component | undefined {\n if (uid in this.contentTypes) {\n return this.contentTypes[uid as Common.UID.ContentType];\n }\n\n if (uid in this.components) {\n return this.components[uid as Common.UID.Component];\n }\n }\n\n /**\n * Binds queries with a specific model\n * @param {string} uid\n */\n query(uid: Common.UID.Schema) {\n return this.db!.query(uid);\n }\n}\n\ninterface StrapiOptions {\n appDir?: string;\n distDir?: string;\n autoReload?: boolean;\n serveAdminPanel?: boolean;\n}\n\ninterface Init {\n (options?: StrapiOptions): Strapi;\n factories: typeof factories;\n compile: typeof compile;\n}\n\nconst initFn = (options: StrapiOptions = {}) => {\n const strapi = new Strapi(options);\n global.strapi = strapi as LoadedStrapi;\n return strapi;\n};\n\nconst init: Init = Object.assign(initFn, { factories, compile });\n\nexport default init;\n"],"names":["path","destroyOnSignal","loadConfiguration","createContainer","createConfigProvider","contentTypesRegistry","servicesRegistry","policiesRegistry","middlewaresRegistry","hooksRegistry","controllersRegistry","modulesRegistry","pluginsRegistry","customFieldsRegistry","apisRegistry","createAuth","createContentAPI","sanitizersRegistry","validatorsRegistry","utils.getDirs","createServer","createStrapiFs","createEventHub","createStartupLogger","createLogger","createCronService","createTelemetry","createCustomFields","createStrapiFetch","createFeaturesService","createUpdateNotifier","ee","LIFECYCLES","_","getNumberOfDynamicZones","factories.isCustomController","isInitialized","utils.openBrowser","utils.isInitialized","loaders","hooks","draftAndPublishSync.disable","draftAndPublishSync.enable","createWebhookRunner","contentTypes","coreStoreModel","webhookModel","Database","createCoreStore","createWebhookStore","entityValidator","createEntityService","isFunction"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4FA,MAAM,4BAA4B,CAAC,SAAgD;AAC3E,QAAA,MAAM,QAAQ;AAEd,QAAA,SAAS,KAAK,SAASA,cAAA,QAAK,QAAQ,KAAK,KAAK,MAAM,IAAI;AACxD,QAAA,UAAU,KAAK,UAAUA,cAAA,QAAK,QAAQ,KAAK,KAAK,OAAO,IAAI;AAEjE,SAAO,EAAE,KAAK,QAAQ,MAAM,QAAQ;AACtC;AAEA,MAAM,WAAW,CAAC,WAAmB;AACnC,QAAM,QAAQ;AAAA,IACZ,cAAc;AAAA,IACd,YAAY;AAAA,EAAA;AAGd,WAAS,SAAS;AACZ,QAAA,MAAM,eAAe,GAAG;AAE1B,YAAM,gBAAgB;AACtB,aAAO,cAAc;AACrB;AAAA,IACF;AAEA,QAAI,OAAO,OAAO,IAAI,YAAY,GAAG;AACnC,cAAQ,OAAO,QAAQ;AAAA,IACzB;AAAA,EACF;AAEO,SAAA,eAAe,QAAQ,cAAc;AAAA,IAC1C,cAAc;AAAA,IACd,YAAY;AAAA,IACZ,IAAI,OAAO;AAET,UAAI,MAAM,eAAe,SAAS,UAAU,MAAM;AAChD,cAAM,gBAAgB;AAAA,MACxB;AACA,YAAM,aAAa;AAAA,IACrB;AAAA,IACA,MAAM;AACJ,aAAO,MAAM;AAAA,IACf;AAAA,EAAA,CACD;AAED,SAAO,cAAc;AACrB,SAAO,aAAa;AAEb,SAAA;AACT;AAIA,MAAM,OAA0B;AAA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AO,SAAS;AACT,SAAA;AACT;AAEA,MAAM,OAAa,OAAO,OAAO,QAAQ,EAAE,WAAW,QAAS,CAAA;;"}
|
|
1
|
+
{"version":3,"file":"Strapi.js","sources":["../src/Strapi.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-namespace */\n/* eslint-disable vars-on-top */\n/* eslint-disable no-var */\nimport path from 'path';\nimport _ from 'lodash';\nimport { isFunction } from 'lodash/fp';\nimport { Logger, createLogger } from '@strapi/logger';\nimport { Database } from '@strapi/database';\nimport { hooks } from '@strapi/utils';\nimport type {\n Strapi as StrapiI,\n Server,\n Container,\n EntityService,\n EventHub,\n StartupLogger,\n CronService,\n WebhookStore,\n CoreStore,\n TelemetryService,\n RequestContext,\n CustomFields,\n Fetch,\n StrapiFS,\n StrapiDirectories,\n Reloader,\n EntityValidator,\n Common,\n Shared,\n Schema,\n} from '@strapi/types';\n\nimport loadConfiguration from './core/app-configuration';\n\nimport * as factories from './factories';\nimport compile from './compile';\n\nimport * as utils from './utils';\nimport { createContainer } from './container';\nimport createStrapiFs from './services/fs';\nimport createEventHub from './services/event-hub';\nimport { createServer } from './services/server';\nimport createWebhookRunner, { WebhookRunner } from './services/webhook-runner';\nimport { webhookModel, createWebhookStore } from './services/webhook-store';\nimport { createCoreStore, coreStoreModel } from './services/core-store';\nimport createEntityService from './services/entity-service';\nimport createCronService from './services/cron';\nimport entityValidator from './services/entity-validator';\nimport createTelemetry from './services/metrics';\nimport requestContext from './services/request-context';\nimport createAuth from './services/auth';\nimport createCustomFields from './services/custom-fields';\nimport createContentAPI from './services/content-api';\nimport createUpdateNotifier from './utils/update-notifier';\nimport createStartupLogger from './utils/startup-logger';\nimport { createStrapiFetch } from './utils/fetch';\nimport { LIFECYCLES } from './utils/lifecycles';\nimport ee from './utils/ee';\nimport contentTypesRegistry from './core/registries/content-types';\nimport servicesRegistry from './core/registries/services';\nimport policiesRegistry from './core/registries/policies';\nimport middlewaresRegistry from './core/registries/middlewares';\nimport hooksRegistry from './core/registries/hooks';\nimport controllersRegistry from './core/registries/controllers';\nimport modulesRegistry from './core/registries/modules';\nimport pluginsRegistry from './core/registries/plugins';\nimport customFieldsRegistry from './core/registries/custom-fields';\nimport createConfigProvider from './core/registries/config';\nimport apisRegistry from './core/registries/apis';\nimport bootstrap from './core/bootstrap';\nimport loaders from './core/loaders';\nimport { destroyOnSignal } from './utils/signals';\nimport getNumberOfDynamicZones from './services/utils/dynamic-zones';\nimport sanitizersRegistry from './core/registries/sanitizers';\nimport validatorsRegistry from './core/registries/validators';\nimport convertCustomFieldType from './utils/convert-custom-field-type';\n\n// TODO: move somewhere else\nimport * as draftAndPublishSync from './migrations/draft-publish';\nimport { FeaturesService, createFeaturesService } from './services/features';\n\n/**\n * Resolve the working directories based on the instance options.\n *\n * Behavior:\n * - `appDir` is the directory where Strapi will write every file (schemas, generated APIs, controllers or services)\n * - `distDir` is the directory where Strapi will read configurations, schemas and any compiled code\n *\n * Default values:\n * - If `appDir` is `undefined`, it'll be set to `process.cwd()`\n * - If `distDir` is `undefined`, it'll be set to `appDir`\n */\nconst resolveWorkingDirectories = (opts: { appDir?: string; distDir?: string }) => {\n const cwd = process.cwd();\n\n const appDir = opts.appDir ? path.resolve(cwd, opts.appDir) : cwd;\n const distDir = opts.distDir ? path.resolve(cwd, opts.distDir) : appDir;\n\n return { app: appDir, dist: distDir };\n};\n\nconst reloader = (strapi: Strapi) => {\n const state = {\n shouldReload: 0,\n isWatching: true,\n };\n\n function reload() {\n if (state.shouldReload > 0) {\n // Reset the reloading state\n state.shouldReload -= 1;\n reload.isReloading = false;\n return;\n }\n\n if (strapi.config.get('autoReload')) {\n process.send?.('reload');\n }\n }\n\n Object.defineProperty(reload, 'isWatching', {\n configurable: true,\n enumerable: true,\n set(value) {\n // Special state when the reloader is disabled temporarly (see GraphQL plugin example).\n if (state.isWatching === false && value === true) {\n state.shouldReload += 1;\n }\n state.isWatching = value;\n },\n get() {\n return state.isWatching;\n },\n });\n\n reload.isReloading = false;\n reload.isWatching = true;\n\n return reload;\n};\n\nexport type LoadedStrapi = Required<Strapi>;\n\nclass Strapi implements StrapiI {\n server: Server;\n\n container: Container;\n\n log: Logger;\n\n fs: StrapiFS;\n\n eventHub: EventHub;\n\n startupLogger: StartupLogger;\n\n cron: CronService;\n\n webhookRunner?: WebhookRunner;\n\n webhookStore?: WebhookStore;\n\n store?: CoreStore;\n\n entityValidator?: EntityValidator;\n\n entityService?: EntityService.EntityService;\n\n telemetry: TelemetryService;\n\n requestContext: RequestContext;\n\n customFields: CustomFields.CustomFields;\n\n fetch: Fetch;\n\n dirs: StrapiDirectories;\n\n admin?: Common.Module;\n\n isLoaded: boolean;\n\n db?: Database;\n\n app: any;\n\n EE?: boolean;\n\n components: Shared.Components;\n\n reload: Reloader;\n\n features: FeaturesService;\n\n constructor(opts: StrapiOptions = {}) {\n destroyOnSignal(this);\n\n const rootDirs = resolveWorkingDirectories(opts);\n\n // Load the app configuration from the dist directory\n const appConfig = loadConfiguration(rootDirs, opts);\n\n // Instantiate the Strapi container\n this.container = createContainer(this)\n .register('config', createConfigProvider(appConfig))\n .register('content-types', contentTypesRegistry())\n .register('services', servicesRegistry(this))\n .register('policies', policiesRegistry())\n .register('middlewares', middlewaresRegistry())\n .register('hooks', hooksRegistry())\n .register('controllers', controllersRegistry(this))\n .register('modules', modulesRegistry(this))\n .register('plugins', pluginsRegistry(this))\n .register('custom-fields', customFieldsRegistry(this))\n .register('apis', apisRegistry(this))\n .register('auth', createAuth())\n .register('content-api', createContentAPI(this))\n .register('sanitizers', sanitizersRegistry())\n .register('validators', validatorsRegistry());\n\n this.components = {};\n\n // Create a mapping of every useful directory (for the app, dist and static directories)\n this.dirs = utils.getDirs(rootDirs, { strapi: this });\n\n // Strapi state management variables\n this.isLoaded = false;\n this.reload = reloader(this);\n\n // Instantiate the Koa app & the HTTP server\n this.server = createServer(this);\n\n // Strapi utils instantiation\n this.fs = createStrapiFs(this);\n this.eventHub = createEventHub();\n this.startupLogger = createStartupLogger(this);\n this.log = createLogger(this.config.get('logger', {}));\n this.cron = createCronService();\n this.telemetry = createTelemetry(this);\n this.requestContext = requestContext;\n this.customFields = createCustomFields(this);\n this.fetch = createStrapiFetch(this);\n this.features = createFeaturesService(this);\n\n createUpdateNotifier(this).notify();\n\n Object.defineProperty<Strapi>(this, 'EE', {\n get: () => {\n ee.init(this.dirs.app.root, this.log);\n return ee.isEE;\n },\n configurable: false,\n });\n }\n\n get config() {\n return this.container.get('config');\n }\n\n get services() {\n return this.container.get('services').getAll();\n }\n\n service(uid: Common.UID.Service) {\n return this.container.get('services').get(uid);\n }\n\n get controllers() {\n return this.container.get('controllers').getAll();\n }\n\n controller(uid: Common.UID.Controller) {\n return this.container.get('controllers').get(uid);\n }\n\n get contentTypes(): Shared.ContentTypes {\n return this.container.get('content-types').getAll();\n }\n\n contentType(name: Common.UID.ContentType) {\n return this.container.get('content-types').get(name);\n }\n\n get policies() {\n return this.container.get('policies').getAll();\n }\n\n policy(name: string) {\n return this.container.get('policies').get(name);\n }\n\n get middlewares() {\n return this.container.get('middlewares').getAll();\n }\n\n middleware(name: string) {\n return this.container.get('middlewares').get(name);\n }\n\n get plugins(): Record<string, Common.Plugin> {\n return this.container.get('plugins').getAll();\n }\n\n plugin(name: string): Common.Plugin {\n return this.container.get('plugins').get(name);\n }\n\n get hooks() {\n return this.container.get('hooks').getAll();\n }\n\n hook(name: string) {\n return this.container.get('hooks').get(name);\n }\n\n // api(name) {\n // return this.container.get('apis').get(name);\n // }\n\n get api(): Record<string, Common.Module> {\n return this.container.get('apis').getAll();\n }\n\n get auth() {\n return this.container.get('auth');\n }\n\n get contentAPI() {\n return this.container.get('content-api');\n }\n\n get sanitizers() {\n return this.container.get('sanitizers');\n }\n\n get validators() {\n return this.container.get('validators');\n }\n\n async start() {\n try {\n if (!this.isLoaded) {\n await this.load();\n }\n\n await this.listen();\n\n return this;\n } catch (error) {\n return this.stopWithError(error);\n }\n }\n\n async destroy() {\n await this.server.destroy();\n await this.runLifecyclesFunctions(LIFECYCLES.DESTROY);\n\n this.eventHub.destroy();\n\n await this.db?.destroy();\n\n this.telemetry.destroy();\n this.cron.destroy();\n\n process.removeAllListeners();\n\n // @ts-expect-error: Allow clean delete of global.strapi to allow re-instanciation\n delete global.strapi;\n }\n\n sendStartupTelemetry() {\n // Emit started event.\n // do not await to avoid slower startup\n // This event is anonymous\n this.telemetry\n .send('didStartServer', {\n groupProperties: {\n database: this.config.get('database.connection.client'),\n plugins: Object.keys(this.plugins),\n numberOfAllContentTypes: _.size(this.contentTypes), // TODO: V5: This event should be renamed numberOfContentTypes in V5 as the name is already taken to describe the number of content types using i18n.\n numberOfComponents: _.size(this.components),\n numberOfDynamicZones: getNumberOfDynamicZones(),\n numberOfCustomControllers: Object.values<Common.Controller>(this.controllers).filter(\n // TODO: Fix this at the content API loader level to prevent future types issues\n (controller) => controller !== undefined && factories.isCustomController(controller)\n ).length,\n environment: this.config.environment,\n // TODO: to add back\n // providers: this.config.installedProviders,\n },\n })\n .catch(this.log.error);\n }\n\n async openAdmin({ isInitialized }: { isInitialized: boolean }) {\n const shouldOpenAdmin =\n this.config.get('environment') === 'development' &&\n this.config.get('admin.autoOpen', true) !== false;\n\n if (shouldOpenAdmin && !isInitialized) {\n try {\n await utils.openBrowser(this.config);\n this.telemetry.send('didOpenTab');\n } catch (e) {\n this.telemetry.send('didNotOpenTab');\n }\n }\n }\n\n async postListen() {\n const isInitialized = await utils.isInitialized(this);\n\n this.startupLogger.logStartupMessage({ isInitialized });\n\n this.sendStartupTelemetry();\n this.openAdmin({ isInitialized });\n }\n\n /**\n * Add behaviors to the server\n */\n async listen() {\n return new Promise<void>((resolve, reject) => {\n const onListen = async () => {\n try {\n await this.postListen();\n\n resolve();\n } catch (error) {\n reject(error);\n }\n };\n\n const listenSocket = this.config.get('server.socket');\n\n if (listenSocket) {\n this.server.listen(listenSocket, onListen);\n } else {\n const { host, port } = this.config.get('server');\n\n this.server.listen(port, host, onListen);\n }\n });\n }\n\n stopWithError(err: unknown, customMessage?: string): never {\n this.log.debug(`⛔️ Server wasn't able to start properly.`);\n if (customMessage) {\n this.log.error(customMessage);\n }\n\n this.log.error(err);\n return this.stop();\n }\n\n stop(exitCode = 1): never {\n this.destroy();\n\n if (this.config.get('autoReload')) {\n process.send?.('stop');\n }\n\n // Kill process\n process.exit(exitCode);\n }\n\n async loadAdmin() {\n await loaders.loadAdmin(this);\n }\n\n async loadPlugins() {\n await loaders.loadPlugins(this);\n }\n\n async loadPolicies() {\n await loaders.loadPolicies(this);\n }\n\n async loadAPIs() {\n await loaders.loadAPIs(this);\n }\n\n async loadComponents() {\n this.components = await loaders.loadComponents(this);\n }\n\n async loadMiddlewares() {\n await loaders.loadMiddlewares(this);\n }\n\n async loadApp() {\n this.app = await loaders.loadSrcIndex(this);\n }\n\n async loadSanitizers() {\n await loaders.loadSanitizers(this);\n }\n\n async loadValidators() {\n await loaders.loadValidators(this);\n }\n\n registerInternalHooks() {\n this.container\n .get('hooks')\n .set('strapi::content-types.beforeSync', hooks.createAsyncParallelHook());\n\n this.container\n .get('hooks')\n .set('strapi::content-types.afterSync', hooks.createAsyncParallelHook());\n\n this.hook('strapi::content-types.beforeSync').register(draftAndPublishSync.disable);\n this.hook('strapi::content-types.afterSync').register(draftAndPublishSync.enable);\n }\n\n async register() {\n await Promise.all([\n this.loadApp(),\n this.loadSanitizers(),\n this.loadValidators(),\n this.loadPlugins(),\n this.loadAdmin(),\n this.loadAPIs(),\n this.loadComponents(),\n this.loadMiddlewares(),\n this.loadPolicies(),\n ]);\n\n await bootstrap({ strapi: this });\n\n // init webhook runner\n this.webhookRunner = createWebhookRunner({\n eventHub: this.eventHub,\n logger: this.log,\n configuration: this.config.get('server.webhooks', {}),\n fetch: this.fetch,\n });\n\n this.registerInternalHooks();\n\n this.telemetry.register();\n\n await this.runLifecyclesFunctions(LIFECYCLES.REGISTER);\n // NOTE: Swap type customField for underlying data type\n convertCustomFieldType(this);\n\n return this;\n }\n\n async bootstrap() {\n const contentTypes = [\n coreStoreModel,\n webhookModel,\n ...Object.values(this.contentTypes),\n ...Object.values(this.components),\n ];\n\n this.db = await Database.init({\n ...this.config.get('database'),\n models: Database.transformContentTypes(contentTypes),\n });\n\n this.store = createCoreStore({ db: this.db });\n this.webhookStore = createWebhookStore({ db: this.db });\n\n this.entityValidator = entityValidator;\n this.entityService = createEntityService({\n strapi: this,\n db: this.db,\n eventHub: this.eventHub,\n entityValidator: this.entityValidator,\n });\n\n if (this.config.get('server.cron.enabled', true)) {\n const cronTasks = this.config.get('server.cron.tasks', {});\n this.cron.add(cronTasks);\n }\n\n this.telemetry.bootstrap();\n\n let oldContentTypes;\n if (await this.db.getSchemaConnection().hasTable(coreStoreModel.collectionName)) {\n oldContentTypes = await this.store.get({\n type: 'strapi',\n name: 'content_types',\n key: 'schema',\n });\n }\n\n await this.hook('strapi::content-types.beforeSync').call({\n oldContentTypes,\n contentTypes: this.contentTypes,\n });\n\n await this.db.schema.sync();\n\n if (this.EE) {\n await ee.checkLicense({ strapi: this });\n }\n\n await this.hook('strapi::content-types.afterSync').call({\n oldContentTypes,\n contentTypes: this.contentTypes,\n });\n\n await this.store.set({\n type: 'strapi',\n name: 'content_types',\n key: 'schema',\n value: this.contentTypes,\n });\n\n await this.startWebhooks();\n\n await this.server.initMiddlewares();\n this.server.initRouting();\n\n await this.contentAPI.permissions.registerActions();\n\n await this.runLifecyclesFunctions(LIFECYCLES.BOOTSTRAP);\n\n this.cron.start();\n\n return this;\n }\n\n async load() {\n await this.register();\n await this.bootstrap();\n\n this.isLoaded = true;\n\n return this as this & Required<StrapiI>;\n }\n\n async startWebhooks() {\n const webhooks = await this.webhookStore?.findWebhooks();\n if (!webhooks) {\n return;\n }\n\n for (const webhook of webhooks) {\n this.webhookRunner?.add(webhook);\n }\n }\n\n async runLifecyclesFunctions(lifecycleName: 'register' | 'bootstrap' | 'destroy') {\n // plugins\n await this.container.get('modules')[lifecycleName]();\n\n // admin\n const adminLifecycleFunction = this.admin && this.admin[lifecycleName];\n if (isFunction(adminLifecycleFunction)) {\n await adminLifecycleFunction({ strapi: this });\n }\n\n // user\n const userLifecycleFunction = this.app && this.app[lifecycleName];\n if (isFunction(userLifecycleFunction)) {\n await userLifecycleFunction({ strapi: this });\n }\n }\n\n getModel(uid: Common.UID.ContentType): Schema.ContentType;\n getModel(uid: Common.UID.Component): Schema.Component;\n getModel<TUID extends Common.UID.Schema>(\n uid: TUID\n ): Schema.ContentType | Schema.Component | undefined {\n if (uid in this.contentTypes) {\n return this.contentTypes[uid as Common.UID.ContentType];\n }\n\n if (uid in this.components) {\n return this.components[uid as Common.UID.Component];\n }\n }\n\n /**\n * Binds queries with a specific model\n * @param {string} uid\n */\n query(uid: Common.UID.Schema) {\n return this.db!.query(uid);\n }\n}\n\ninterface StrapiOptions {\n appDir?: string;\n distDir?: string;\n autoReload?: boolean;\n serveAdminPanel?: boolean;\n}\n\ninterface Init {\n (options?: StrapiOptions): Strapi;\n factories: typeof factories;\n compile: typeof compile;\n}\n\nconst initFn = (options: StrapiOptions = {}) => {\n const strapi = new Strapi(options);\n global.strapi = strapi as LoadedStrapi;\n return strapi;\n};\n\nconst init: Init = Object.assign(initFn, { factories, compile });\n\nexport default init;\n"],"names":["path","destroyOnSignal","loadConfiguration","createContainer","createConfigProvider","contentTypesRegistry","servicesRegistry","policiesRegistry","middlewaresRegistry","hooksRegistry","controllersRegistry","modulesRegistry","pluginsRegistry","customFieldsRegistry","apisRegistry","createAuth","createContentAPI","sanitizersRegistry","validatorsRegistry","utils.getDirs","createServer","createStrapiFs","createEventHub","createStartupLogger","createLogger","createCronService","createTelemetry","createCustomFields","createStrapiFetch","createFeaturesService","createUpdateNotifier","ee","LIFECYCLES","_","getNumberOfDynamicZones","factories.isCustomController","isInitialized","utils.openBrowser","utils.isInitialized","loaders","hooks","draftAndPublishSync.disable","draftAndPublishSync.enable","createWebhookRunner","contentTypes","coreStoreModel","webhookModel","Database","createCoreStore","createWebhookStore","entityValidator","createEntityService","isFunction"],"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A,EACT;AAAA,EAEA,MAAM,gBAAgB;AACpB,UAAM,WAAW,MAAM,KAAK,cAAc,aAAa;AACvD,QAAI,CAAC,UAAU;AACb;AAAA,IACF;AAEA,eAAW,WAAW,UAAU;AACzB,WAAA,eAAe,IAAI,OAAO;AAAA,IACjC;AAAA,EACF;AAAA,EAEA,MAAM,uBAAuB,eAAqD;AAEhF,UAAM,KAAK,UAAU,IAAI,SAAS,EAAE,aAAa;AAGjD,UAAM,yBAAyB,KAAK,SAAS,KAAK,MAAM,aAAa;AACjE,QAAAoB,GAAAA,WAAW,sBAAsB,GAAG;AACtC,YAAM,uBAAuB,EAAE,QAAQ,KAAM,CAAA;AAAA,IAC/C;AAGA,UAAM,wBAAwB,KAAK,OAAO,KAAK,IAAI,aAAa;AAC5D,QAAAA,GAAAA,WAAW,qBAAqB,GAAG;AACrC,YAAM,sBAAsB,EAAE,QAAQ,KAAM,CAAA;AAAA,IAC9C;AAAA,EACF;AAAA,EAIA,SACE,KACmD;AAC/C,QAAA,OAAO,KAAK,cAAc;AACrB,aAAA,KAAK,aAAa,GAA6B;AAAA,IACxD;AAEI,QAAA,OAAO,KAAK,YAAY;AACnB,aAAA,KAAK,WAAW,GAA2B;AAAA,IACpD;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,KAAwB;AACrB,WAAA,KAAK,GAAI,MAAM,GAAG;AAAA,EAC3B;AACF;AAeA,MAAM,SAAS,CAAC,UAAyB,OAAO;AACxC,QAAA,SAAS,IAAI,OAAO,OAAO;AACjC,SAAO,SAAS;AACT,SAAA;AACT;AAEA,MAAM,OAAa,OAAO,OAAO,QAAQ,EAAE,WAAW,QAAS,CAAA;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const CLITable = require("cli-table3");
|
|
3
3
|
const chalk = require("chalk");
|
|
4
|
-
const
|
|
4
|
+
const fp = require("lodash/fp");
|
|
5
5
|
const Strapi = require("../../../../Strapi.js");
|
|
6
6
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
7
7
|
const CLITable__default = /* @__PURE__ */ _interopDefault(CLITable);
|
|
@@ -15,7 +15,7 @@ const action = async () => {
|
|
|
15
15
|
colWidths: [20]
|
|
16
16
|
});
|
|
17
17
|
list.filter((route) => route.methods.length).forEach((route) => {
|
|
18
|
-
infoTable.push([route.methods.map(
|
|
18
|
+
infoTable.push([route.methods.map(fp.toUpper).join("|"), route.path]);
|
|
19
19
|
});
|
|
20
20
|
console.log(infoTable.toString());
|
|
21
21
|
await app.destroy();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action.js","sources":["../../../../../src/commands/actions/routes/list/action.ts"],"sourcesContent":["import CLITable from 'cli-table3';\nimport chalk from 'chalk';\nimport { toUpper } from 'lodash/fp';\n\nimport strapi from '../../../../Strapi';\n\nexport default async () => {\n const appContext = await strapi.compile();\n const app = await strapi(appContext).load();\n\n const list = app.server.mount().listRoutes();\n\n const infoTable = new CLITable({\n head: [chalk.blue('Method'), chalk.blue('Path')],\n colWidths: [20],\n });\n\n list\n .filter((route) => route.methods.length)\n .forEach((route) => {\n infoTable.push([route.methods.map(toUpper).join('|'), route.path]);\n });\n\n console.log(infoTable.toString());\n\n await app.destroy();\n};\n"],"names":["strapi","CLITable","chalk","toUpper"],"mappings":";;;;;;;;AAMA,MAAA,SAAe,YAAY;AACnB,QAAA,aAAa,MAAMA,OAAO;AAChC,QAAM,MAAM,MAAMA,OAAO,UAAU,EAAE,KAAK;AAE1C,QAAM,OAAO,IAAI,OAAO,QAAQ,WAAW;AAErC,QAAA,YAAY,IAAIC,0BAAS;AAAA,IAC7B,MAAM,CAACC,eAAM,QAAA,KAAK,QAAQ,GAAGA,uBAAM,KAAK,MAAM,CAAC;AAAA,IAC/C,WAAW,CAAC,EAAE;AAAA,EAAA,CACf;AAGE,OAAA,OAAO,CAAC,UAAU,MAAM,QAAQ,MAAM,EACtC,QAAQ,CAAC,UAAU;AAClB,cAAU,KAAK,CAAC,MAAM,QAAQ,IAAIC,
|
|
1
|
+
{"version":3,"file":"action.js","sources":["../../../../../src/commands/actions/routes/list/action.ts"],"sourcesContent":["import CLITable from 'cli-table3';\nimport chalk from 'chalk';\nimport { toUpper } from 'lodash/fp';\n\nimport strapi from '../../../../Strapi';\n\nexport default async () => {\n const appContext = await strapi.compile();\n const app = await strapi(appContext).load();\n\n const list = app.server.mount().listRoutes();\n\n const infoTable = new CLITable({\n head: [chalk.blue('Method'), chalk.blue('Path')],\n colWidths: [20],\n });\n\n list\n .filter((route) => route.methods.length)\n .forEach((route) => {\n infoTable.push([route.methods.map(toUpper).join('|'), route.path]);\n });\n\n console.log(infoTable.toString());\n\n await app.destroy();\n};\n"],"names":["strapi","CLITable","chalk","toUpper"],"mappings":";;;;;;;;AAMA,MAAA,SAAe,YAAY;AACnB,QAAA,aAAa,MAAMA,OAAO;AAChC,QAAM,MAAM,MAAMA,OAAO,UAAU,EAAE,KAAK;AAE1C,QAAM,OAAO,IAAI,OAAO,QAAQ,WAAW;AAErC,QAAA,YAAY,IAAIC,0BAAS;AAAA,IAC7B,MAAM,CAACC,eAAM,QAAA,KAAK,QAAQ,GAAGA,uBAAM,KAAK,MAAM,CAAC;AAAA,IAC/C,WAAW,CAAC,EAAE;AAAA,EAAA,CACf;AAGE,OAAA,OAAO,CAAC,UAAU,MAAM,QAAQ,MAAM,EACtC,QAAQ,CAAC,UAAU;AAClB,cAAU,KAAK,CAAC,MAAM,QAAQ,IAAIC,GAAAA,OAAO,EAAE,KAAK,GAAG,GAAG,MAAM,IAAI,CAAC;AAAA,EAAA,CAClE;AAEK,UAAA,IAAI,UAAU,SAAU,CAAA;AAEhC,QAAM,IAAI;AACZ;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const chalk = require("chalk");
|
|
4
|
-
const
|
|
4
|
+
const fp = require("lodash/fp");
|
|
5
5
|
const inquirer = require("inquirer");
|
|
6
6
|
const boxen = require("boxen");
|
|
7
7
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
@@ -18,7 +18,7 @@ const assertCwdContainsStrapiProject = (name) => {
|
|
|
18
18
|
};
|
|
19
19
|
try {
|
|
20
20
|
const pkgJSON = require(`${process.cwd()}/package.json`);
|
|
21
|
-
if (!
|
|
21
|
+
if (!fp.has("dependencies.@strapi/strapi", pkgJSON) && !fp.has("devDependencies.@strapi/strapi", pkgJSON)) {
|
|
22
22
|
logErrorAndExit();
|
|
23
23
|
}
|
|
24
24
|
} catch (err) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sources":["../../../src/commands/utils/helpers.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-var-requires */\nimport chalk from 'chalk';\nimport { has, isString, isArray } from 'lodash/fp';\nimport { prompt } from 'inquirer';\nimport boxen from 'boxen';\nimport type { Command } from 'commander';\n\n/**\n * Helper functions for the Strapi CLI\n */\nconst bytesPerKb = 1024;\nconst sizes = ['B ', 'KB', 'MB', 'GB', 'TB', 'PB'];\n\n/**\n * Convert bytes to a human readable formatted string, for example \"1024\" becomes \"1KB\"\n */\nconst readableBytes = (bytes: number, decimals = 1, padStart = 0) => {\n if (!bytes) {\n return '0';\n }\n const i = Math.floor(Math.log(bytes) / Math.log(bytesPerKb));\n const result = `${parseFloat((bytes / bytesPerKb ** i).toFixed(decimals))} ${sizes[i].padStart(\n 2\n )}`;\n\n return result.padStart(padStart);\n};\n\ninterface ExitWithOptions {\n logger?: Console;\n prc?: NodeJS.Process;\n}\n\n/**\n *\n * Display message(s) to console and then call process.exit with code.\n * If code is zero, console.log and green text is used for messages, otherwise console.error and red text.\n *\n */\nconst exitWith = (code: number, message?: string | string[], options: ExitWithOptions = {}) => {\n const { logger = console, prc = process } = options;\n\n const log = (message: string) => {\n if (code === 0) {\n logger.log(chalk.green(message));\n } else {\n logger.error(chalk.red(message));\n }\n };\n\n if (isString(message)) {\n log(message);\n } else if (isArray(message)) {\n message.forEach((msg) => log(msg));\n }\n\n prc.exit(code);\n};\n\n/**\n * assert that a URL object has a protocol value\n *\n */\nconst assertUrlHasProtocol = (url: URL, protocol?: string | string[]) => {\n if (!url.protocol) {\n exitWith(1, `${url.toString()} does not have a protocol`);\n }\n\n // if just checking for the existence of a protocol, return\n if (!protocol) {\n return;\n }\n\n if (isString(protocol)) {\n if (protocol !== url.protocol) {\n exitWith(1, `${url.toString()} must have the protocol ${protocol}`);\n }\n return;\n }\n\n // assume an array\n if (!protocol.some((protocol) => url.protocol === protocol)) {\n return exitWith(\n 1,\n `${url.toString()} must have one of the following protocols: ${protocol.join(',')}`\n );\n }\n};\n\ntype ConditionCallback = (opts: Record<string, any>) => Promise<boolean>;\ntype IsMetCallback = (command: Command) => Promise<void>;\ntype IsNotMetCallback = (command: Command) => Promise<void>;\n\n/**\n * Passes commander options to conditionCallback(). If it returns true, call isMetCallback otherwise call isNotMetCallback\n */\nconst ifOptions = (\n conditionCallback: ConditionCallback,\n isMetCallback: IsMetCallback = async () => {},\n isNotMetCallback: IsNotMetCallback = async () => {}\n) => {\n return async (command: Command) => {\n const opts = command.opts();\n if (await conditionCallback(opts)) {\n await isMetCallback(command);\n } else {\n await isNotMetCallback(command);\n }\n };\n};\n\nconst assertCwdContainsStrapiProject = (name: string) => {\n const logErrorAndExit = () => {\n console.log(\n `You need to run ${chalk.yellow(\n `strapi ${name}`\n )} in a Strapi project. Make sure you are in the right directory.`\n );\n process.exit(1);\n };\n\n try {\n const pkgJSON = require(`${process.cwd()}/package.json`);\n if (\n !has('dependencies.@strapi/strapi', pkgJSON) &&\n !has('devDependencies.@strapi/strapi', pkgJSON)\n ) {\n logErrorAndExit();\n }\n } catch (err) {\n logErrorAndExit();\n }\n};\n\nconst runAction =\n (name: string, action: (...args: any[]) => Promise<void>) =>\n (...args: unknown[]) => {\n assertCwdContainsStrapiProject(name);\n\n Promise.resolve()\n .then(() => {\n return action(...args);\n })\n .catch((error) => {\n console.error(error);\n process.exit(1);\n });\n };\n\n/**\n * @description Notify users this is an experimental command and get them to approve first\n * this can be opted out by passing `yes` as a property of the args object.\n *\n * @example\n * ```ts\n * const { notifyExperimentalCommand } = require('../utils/helpers');\n *\n * const myCommand = async ({ force }) => {\n * await notifyExperimentalCommand('plugin:build', { force });\n * }\n * ```\n */\nconst notifyExperimentalCommand = async (name: string, { force }: { force?: boolean } = {}) => {\n console.log(\n boxen(\n `The ${chalk.bold(\n chalk.underline(name)\n )} command is considered experimental, use at your own risk.`,\n {\n title: 'Warning',\n padding: 1,\n margin: 1,\n align: 'center',\n borderColor: 'yellow',\n borderStyle: 'bold',\n }\n )\n );\n\n if (!force) {\n const { confirmed } = await prompt({\n type: 'confirm',\n name: 'confirmed',\n message: 'Do you want to continue?',\n });\n\n if (!confirmed) {\n process.exit(0);\n }\n }\n};\n\nexport {\n exitWith,\n assertUrlHasProtocol,\n ifOptions,\n readableBytes,\n runAction,\n assertCwdContainsStrapiProject,\n notifyExperimentalCommand,\n};\n"],"names":["chalk","has","boxen","prompt"],"mappings":";;;;;;;;;AA+GM,MAAA,iCAAiC,CAAC,SAAiB;AACvD,QAAM,kBAAkB,MAAM;AACpB,YAAA;AAAA,MACN,mBAAmBA,eAAAA,QAAM;AAAA,QACvB,UAAU,IAAI;AAAA,MACf,CAAA;AAAA,IAAA;AAEH,YAAQ,KAAK,CAAC;AAAA,EAAA;AAGZ,MAAA;AACF,UAAM,UAAU,QAAQ,GAAG,QAAQ,IAAK,CAAA,eAAe;AAErD,QAAA,CAACC,
|
|
1
|
+
{"version":3,"file":"helpers.js","sources":["../../../src/commands/utils/helpers.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-var-requires */\nimport chalk from 'chalk';\nimport { has, isString, isArray } from 'lodash/fp';\nimport { prompt } from 'inquirer';\nimport boxen from 'boxen';\nimport type { Command } from 'commander';\n\n/**\n * Helper functions for the Strapi CLI\n */\nconst bytesPerKb = 1024;\nconst sizes = ['B ', 'KB', 'MB', 'GB', 'TB', 'PB'];\n\n/**\n * Convert bytes to a human readable formatted string, for example \"1024\" becomes \"1KB\"\n */\nconst readableBytes = (bytes: number, decimals = 1, padStart = 0) => {\n if (!bytes) {\n return '0';\n }\n const i = Math.floor(Math.log(bytes) / Math.log(bytesPerKb));\n const result = `${parseFloat((bytes / bytesPerKb ** i).toFixed(decimals))} ${sizes[i].padStart(\n 2\n )}`;\n\n return result.padStart(padStart);\n};\n\ninterface ExitWithOptions {\n logger?: Console;\n prc?: NodeJS.Process;\n}\n\n/**\n *\n * Display message(s) to console and then call process.exit with code.\n * If code is zero, console.log and green text is used for messages, otherwise console.error and red text.\n *\n */\nconst exitWith = (code: number, message?: string | string[], options: ExitWithOptions = {}) => {\n const { logger = console, prc = process } = options;\n\n const log = (message: string) => {\n if (code === 0) {\n logger.log(chalk.green(message));\n } else {\n logger.error(chalk.red(message));\n }\n };\n\n if (isString(message)) {\n log(message);\n } else if (isArray(message)) {\n message.forEach((msg) => log(msg));\n }\n\n prc.exit(code);\n};\n\n/**\n * assert that a URL object has a protocol value\n *\n */\nconst assertUrlHasProtocol = (url: URL, protocol?: string | string[]) => {\n if (!url.protocol) {\n exitWith(1, `${url.toString()} does not have a protocol`);\n }\n\n // if just checking for the existence of a protocol, return\n if (!protocol) {\n return;\n }\n\n if (isString(protocol)) {\n if (protocol !== url.protocol) {\n exitWith(1, `${url.toString()} must have the protocol ${protocol}`);\n }\n return;\n }\n\n // assume an array\n if (!protocol.some((protocol) => url.protocol === protocol)) {\n return exitWith(\n 1,\n `${url.toString()} must have one of the following protocols: ${protocol.join(',')}`\n );\n }\n};\n\ntype ConditionCallback = (opts: Record<string, any>) => Promise<boolean>;\ntype IsMetCallback = (command: Command) => Promise<void>;\ntype IsNotMetCallback = (command: Command) => Promise<void>;\n\n/**\n * Passes commander options to conditionCallback(). If it returns true, call isMetCallback otherwise call isNotMetCallback\n */\nconst ifOptions = (\n conditionCallback: ConditionCallback,\n isMetCallback: IsMetCallback = async () => {},\n isNotMetCallback: IsNotMetCallback = async () => {}\n) => {\n return async (command: Command) => {\n const opts = command.opts();\n if (await conditionCallback(opts)) {\n await isMetCallback(command);\n } else {\n await isNotMetCallback(command);\n }\n };\n};\n\nconst assertCwdContainsStrapiProject = (name: string) => {\n const logErrorAndExit = () => {\n console.log(\n `You need to run ${chalk.yellow(\n `strapi ${name}`\n )} in a Strapi project. Make sure you are in the right directory.`\n );\n process.exit(1);\n };\n\n try {\n const pkgJSON = require(`${process.cwd()}/package.json`);\n if (\n !has('dependencies.@strapi/strapi', pkgJSON) &&\n !has('devDependencies.@strapi/strapi', pkgJSON)\n ) {\n logErrorAndExit();\n }\n } catch (err) {\n logErrorAndExit();\n }\n};\n\nconst runAction =\n (name: string, action: (...args: any[]) => Promise<void>) =>\n (...args: unknown[]) => {\n assertCwdContainsStrapiProject(name);\n\n Promise.resolve()\n .then(() => {\n return action(...args);\n })\n .catch((error) => {\n console.error(error);\n process.exit(1);\n });\n };\n\n/**\n * @description Notify users this is an experimental command and get them to approve first\n * this can be opted out by passing `yes` as a property of the args object.\n *\n * @example\n * ```ts\n * const { notifyExperimentalCommand } = require('../utils/helpers');\n *\n * const myCommand = async ({ force }) => {\n * await notifyExperimentalCommand('plugin:build', { force });\n * }\n * ```\n */\nconst notifyExperimentalCommand = async (name: string, { force }: { force?: boolean } = {}) => {\n console.log(\n boxen(\n `The ${chalk.bold(\n chalk.underline(name)\n )} command is considered experimental, use at your own risk.`,\n {\n title: 'Warning',\n padding: 1,\n margin: 1,\n align: 'center',\n borderColor: 'yellow',\n borderStyle: 'bold',\n }\n )\n );\n\n if (!force) {\n const { confirmed } = await prompt({\n type: 'confirm',\n name: 'confirmed',\n message: 'Do you want to continue?',\n });\n\n if (!confirmed) {\n process.exit(0);\n }\n }\n};\n\nexport {\n exitWith,\n assertUrlHasProtocol,\n ifOptions,\n readableBytes,\n runAction,\n assertCwdContainsStrapiProject,\n notify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}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
const os = require("os");
|
|
3
3
|
const path = require("path");
|
|
4
4
|
const _ = require("lodash");
|
|
5
|
-
const
|
|
5
|
+
const fp = require("lodash/fp");
|
|
6
6
|
const dotenv = require("dotenv");
|
|
7
7
|
const configLoader = require("./config-loader.js");
|
|
8
8
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
@@ -46,7 +46,7 @@ const loadConfiguration = (dirs, initialConfig = {}) => {
|
|
|
46
46
|
strapi: strapiVersion
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
-
const baseConfig =
|
|
49
|
+
const baseConfig = fp.omit("plugins", configLoader(configDir));
|
|
50
50
|
const envDir = path__default.default.resolve(configDir, "env", process.env.NODE_ENV);
|
|
51
51
|
const envConfig = configLoader(envDir);
|
|
52
52
|
return ___default.default.merge(rootConfig, defaultConfig, baseConfig, envConfig);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/core/app-configuration/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-var-requires */\nimport os from 'os';\nimport path from 'path';\nimport _ from 'lodash';\nimport { omit } from 'lodash/fp';\nimport dotenv from 'dotenv';\n\nimport loadConfigDir from './config-loader';\n\ndotenv.config({ path: process.env.ENV_PATH });\n\nprocess.env.NODE_ENV = process.env.NODE_ENV || 'development';\n\nconst { version: strapiVersion } = require(path.join(__dirname, '../../../package.json'));\n\nconst defaultConfig = {\n server: {\n host: process.env.HOST || os.hostname() || 'localhost',\n port: process.env.PORT || 1337,\n proxy: false,\n cron: { enabled: false },\n admin: { autoOpen: false },\n dirs: { public: './public' },\n },\n admin: {},\n api: {\n rest: {\n prefix: '/api',\n },\n },\n};\n\nexport default (dirs: { app: string; dist: string }, initialConfig: any = {}) => {\n const { app: appDir, dist: distDir } = dirs;\n const { autoReload = false, serveAdminPanel = true } = initialConfig;\n\n const pkgJSON = require(path.resolve(appDir, 'package.json'));\n\n const configDir = path.resolve(distDir || process.cwd(), 'config');\n\n const rootConfig = {\n launchedAt: Date.now(),\n serveAdminPanel,\n autoReload,\n environment: process.env.NODE_ENV,\n uuid: _.get(pkgJSON, 'strapi.uuid'),\n packageJsonStrapi: _.omit(_.get(pkgJSON, 'strapi', {}), 'uuid'),\n info: {\n ...pkgJSON,\n strapi: strapiVersion,\n },\n };\n\n const baseConfig = omit('plugins', loadConfigDir(configDir)); // plugin config will be loaded later\n\n const envDir = path.resolve(configDir, 'env', process.env.NODE_ENV as string);\n const envConfig = loadConfigDir(envDir);\n\n return _.merge(rootConfig, defaultConfig, baseConfig, envConfig);\n};\n"],"names":["dotenv","path","os","_","omit","loadConfigDir"],"mappings":";;;;;;;;;;;;AASAA,gBAAAA,QAAO,OAAO,EAAE,MAAM,QAAQ,IAAI,UAAU;AAE5C,QAAQ,IAAI,WAAW,QAAQ,IAAI,YAAY;AAE/C,MAAM,EAAE,SAAS,cAAc,IAAI,QAAQC,cAAK,QAAA,KAAK,WAAW,uBAAuB,CAAC;AAExF,MAAM,gBAAgB;AAAA,EACpB,QAAQ;AAAA,IACN,MAAM,QAAQ,IAAI,QAAQC,YAAA,QAAG,cAAc;AAAA,IAC3C,MAAM,QAAQ,IAAI,QAAQ;AAAA,IAC1B,OAAO;AAAA,IACP,MAAM,EAAE,SAAS,MAAM;AAAA,IACvB,OAAO,EAAE,UAAU,MAAM;AAAA,IACzB,MAAM,EAAE,QAAQ,WAAW;AAAA,EAC7B;AAAA,EACA,OAAO,CAAC;AAAA,EACR,KAAK;AAAA,IACH,MAAM;AAAA,MACJ,QAAQ;AAAA,IACV;AAAA,EACF;AACF;AAEA,MAAA,oBAAe,CAAC,MAAqC,gBAAqB,OAAO;AAC/E,QAAM,EAAE,KAAK,QAAQ,MAAM,YAAY;AACvC,QAAM,EAAE,aAAa,OAAO,kBAAkB,SAAS;AAEvD,QAAM,UAAU,QAAQD,cAAA,QAAK,QAAQ,QAAQ,cAAc,CAAC;AAE5D,QAAM,YAAYA,cAAK,QAAA,QAAQ,WAAW,QAAQ,IAAA,GAAO,QAAQ;AAEjE,QAAM,aAAa;AAAA,IACjB,YAAY,KAAK,IAAI;AAAA,IACrB;AAAA,IACA;AAAA,IACA,aAAa,QAAQ,IAAI;AAAA,IACzB,MAAME,WAAA,QAAE,IAAI,SAAS,aAAa;AAAA,IAClC,mBAAmBA,WAAAA,QAAE,KAAKA,mBAAE,IAAI,SAAS,UAAU,EAAE,GAAG,MAAM;AAAA,IAC9D,MAAM;AAAA,MACJ,GAAG;AAAA,MACH,QAAQ;AAAA,IACV;AAAA,EAAA;AAGF,QAAM,aAAaC,
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/core/app-configuration/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-var-requires */\nimport os from 'os';\nimport path from 'path';\nimport _ from 'lodash';\nimport { omit } from 'lodash/fp';\nimport dotenv from 'dotenv';\n\nimport loadConfigDir from './config-loader';\n\ndotenv.config({ path: process.env.ENV_PATH });\n\nprocess.env.NODE_ENV = process.env.NODE_ENV || 'development';\n\nconst { version: strapiVersion } = require(path.join(__dirname, '../../../package.json'));\n\nconst defaultConfig = {\n server: {\n host: process.env.HOST || os.hostname() || 'localhost',\n port: process.env.PORT || 1337,\n proxy: false,\n cron: { enabled: false },\n admin: { autoOpen: false },\n dirs: { public: './public' },\n },\n admin: {},\n api: {\n rest: {\n prefix: '/api',\n },\n },\n};\n\nexport default (dirs: { app: string; dist: string }, initialConfig: any = {}) => {\n const { app: appDir, dist: distDir } = dirs;\n const { autoReload = false, serveAdminPanel = true } = initialConfig;\n\n const pkgJSON = require(path.resolve(appDir, 'package.json'));\n\n const configDir = path.resolve(distDir || process.cwd(), 'config');\n\n const rootConfig = {\n launchedAt: Date.now(),\n serveAdminPanel,\n autoReload,\n environment: process.env.NODE_ENV,\n uuid: _.get(pkgJSON, 'strapi.uuid'),\n packageJsonStrapi: _.omit(_.get(pkgJSON, 'strapi', {}), 'uuid'),\n info: {\n ...pkgJSON,\n strapi: strapiVersion,\n },\n };\n\n const baseConfig = omit('plugins', loadConfigDir(configDir)); // plugin config will be loaded later\n\n const envDir = path.resolve(configDir, 'env', process.env.NODE_ENV as string);\n const envConfig = loadConfigDir(envDir);\n\n return _.merge(rootConfig, defaultConfig, baseConfig, envConfig);\n};\n"],"names":["dotenv","path","os","_","omit","loadConfigDir"],"mappings":";;;;;;;;;;;;AASAA,gBAAAA,QAAO,OAAO,EAAE,MAAM,QAAQ,IAAI,UAAU;AAE5C,QAAQ,IAAI,WAAW,QAAQ,IAAI,YAAY;AAE/C,MAAM,EAAE,SAAS,cAAc,IAAI,QAAQC,cAAK,QAAA,KAAK,WAAW,uBAAuB,CAAC;AAExF,MAAM,gBAAgB;AAAA,EACpB,QAAQ;AAAA,IACN,MAAM,QAAQ,IAAI,QAAQC,YAAA,QAAG,cAAc;AAAA,IAC3C,MAAM,QAAQ,IAAI,QAAQ;AAAA,IAC1B,OAAO;AAAA,IACP,MAAM,EAAE,SAAS,MAAM;AAAA,IACvB,OAAO,EAAE,UAAU,MAAM;AAAA,IACzB,MAAM,EAAE,QAAQ,WAAW;AAAA,EAC7B;AAAA,EACA,OAAO,CAAC;AAAA,EACR,KAAK;AAAA,IACH,MAAM;AAAA,MACJ,QAAQ;AAAA,IACV;AAAA,EACF;AACF;AAEA,MAAA,oBAAe,CAAC,MAAqC,gBAAqB,OAAO;AAC/E,QAAM,EAAE,KAAK,QAAQ,MAAM,YAAY;AACvC,QAAM,EAAE,aAAa,OAAO,kBAAkB,SAAS;AAEvD,QAAM,UAAU,QAAQD,cAAA,QAAK,QAAQ,QAAQ,cAAc,CAAC;AAE5D,QAAM,YAAYA,cAAK,QAAA,QAAQ,WAAW,QAAQ,IAAA,GAAO,QAAQ;AAEjE,QAAM,aAAa;AAAA,IACjB,YAAY,KAAK,IAAI;AAAA,IACrB;AAAA,IACA;AAAA,IACA,aAAa,QAAQ,IAAI;AAAA,IACzB,MAAME,WAAA,QAAE,IAAI,SAAS,aAAa;AAAA,IAClC,mBAAmBA,WAAAA,QAAE,KAAKA,mBAAE,IAAI,SAAS,UAAU,EAAE,GAAG,MAAM;AAAA,IAC9D,MAAM;AAAA,MACJ,GAAG;AAAA,MACH,QAAQ;AAAA,IACV;AAAA,EAAA;AAGF,QAAM,aAAaC,GAAAA,KAAK,WAAWC,aAAc,SAAS,CAAC;AAE3D,QAAM,SAASJ,cAAK,QAAA,QAAQ,WAAW,OAAO,QAAQ,IAAI,QAAkB;AACtE,QAAA,YAAYI,aAAc,MAAM;AAEtC,SAAOF,WAAAA,QAAE,MAAM,YAAY,eAAe,YAAY,SAAS;AACjE;;"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
4
|
-
const _
|
|
3
|
+
const fp = require("lodash/fp");
|
|
4
|
+
const _ = require("lodash");
|
|
5
5
|
const strapiUtils = require("@strapi/utils");
|
|
6
6
|
const validator = require("./validator.js");
|
|
7
7
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
8
|
-
const ___default = /* @__PURE__ */ _interopDefault(_
|
|
8
|
+
const ___default = /* @__PURE__ */ _interopDefault(_);
|
|
9
9
|
const {
|
|
10
10
|
CREATED_AT_ATTRIBUTE,
|
|
11
11
|
UPDATED_AT_ATTRIBUTE,
|
|
@@ -23,7 +23,7 @@ ${e.errors}`);
|
|
|
23
23
|
}
|
|
24
24
|
throw e;
|
|
25
25
|
}
|
|
26
|
-
const { schema, actions, lifecycles } =
|
|
26
|
+
const { schema, actions, lifecycles } = fp.cloneDeep(definition);
|
|
27
27
|
Object.assign(schema, {
|
|
28
28
|
kind: schema.kind || "collectionType",
|
|
29
29
|
__schema__: pickSchema(definition.schema),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/core/domain/content-type/index.ts"],"sourcesContent":["import { cloneDeep } from 'lodash/fp';\nimport _ from 'lodash';\nimport { yup, contentTypes as contentTypesUtils } from '@strapi/utils';\nimport type { Schema } from '@strapi/types';\nimport { validateContentTypeDefinition } from './validator';\n\nexport type ContentTypeDefinition = {\n schema: Schema.ContentType;\n actions: Record<string, unknown>;\n lifecycles: Record<string, unknown>;\n};\n\nconst {\n CREATED_AT_ATTRIBUTE,\n UPDATED_AT_ATTRIBUTE,\n PUBLISHED_AT_ATTRIBUTE,\n CREATED_BY_ATTRIBUTE,\n UPDATED_BY_ATTRIBUTE,\n} = contentTypesUtils.constants;\n\nconst createContentType = (uid: string, definition: ContentTypeDefinition) => {\n try {\n validateContentTypeDefinition(definition);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n throw new Error(`Content Type Definition is invalid for ${uid}'.\\n${e.errors}`);\n }\n\n throw e;\n }\n\n const { schema, actions, lifecycles } = cloneDeep(definition);\n\n // general info\n Object.assign(schema, {\n kind: schema.kind || 'collectionType',\n __schema__: pickSchema(definition.schema),\n modelType: 'contentType',\n modelName: definition.schema.info.singularName,\n connection: 'default',\n });\n\n if (uid.startsWith('api::')) {\n Object.assign(schema, {\n uid,\n apiName: uid.split('::')[1].split('.')[0],\n collectionName: schema.collectionName || schema.info.singularName,\n globalId: getGlobalId(schema, schema.info.singularName),\n });\n } else if (uid.startsWith('plugin::')) {\n const pluginName = uid.split('::')[1].split('.')[0];\n Object.assign(schema, {\n uid,\n plugin: pluginName, // TODO: to be set in load-plugins.js\n collectionName:\n schema.collectionName || `${pluginName}_${schema.info.singularName}`.toLowerCase(),\n globalId: getGlobalId(schema, schema.info.singularName, pluginName),\n });\n } else if (uid.startsWith('admin::')) {\n Object.assign(schema, {\n uid,\n plugin: 'admin',\n globalId: getGlobalId(schema, schema.info.singularName, 'admin'),\n });\n } else {\n throw new Error(\n `Incorrect Content Type UID \"${uid}\". The UID should start with api::, plugin:: or admin::.`\n );\n }\n\n // attributes\n Object.assign(schema.attributes, {\n [CREATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n // TODO: handle on edit set to new date\n [UPDATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n });\n\n if (contentTypesUtils.hasDraftAndPublish(schema as any)) {\n schema.attributes[PUBLISHED_AT_ATTRIBUTE] = {\n type: 'datetime',\n configurable: false,\n writable: true,\n visible: false,\n };\n }\n\n const isPrivate = !_.get(schema, 'options.populateCreatorFields', false);\n\n schema.attributes[CREATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n\n schema.attributes[UPDATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n\n Object.assign(schema, { actions, lifecycles });\n\n return schema;\n};\n\nconst getGlobalId = (model: any, modelName: string, prefix?: string) => {\n const globalId = prefix ? `${prefix}-${modelName}` : modelName;\n\n return model.globalId || _.upperFirst(_.camelCase(globalId));\n};\n\nconst pickSchema = (model: Schema.ContentType) => {\n const schema = _.cloneDeep(\n _.pick(model, [\n 'connection',\n 'collectionName',\n 'info',\n 'options',\n 'pluginOptions',\n 'attributes',\n ])\n );\n\n schema.kind = model.kind || 'collectionType';\n return schema;\n};\n\nexport { createContentType };\n"],"names":["contentTypesUtils","validateContentTypeDefinition","yup","cloneDeep","_"],"mappings":";;;;;;;;AAYA,MAAM;AAAA,EACJ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,IAAIA,YAAAA,aAAkB;AAEhB,MAAA,oBAAoB,CAAC,KAAa,eAAsC;AACxE,MAAA;AACFC,cAAA,8BAA8B,UAAU;AAAA,WACjC,GAAG;AACN,QAAA,aAAaC,gBAAI,iBAAiB;AAC9B,YAAA,IAAI,MAAM,0CAA0C,GAAG;AAAA,EAAO,EAAE,MAAM,EAAE;AAAA,IAChF;AAEM,UAAA;AAAA,EACR;AAEA,QAAM,EAAE,QAAQ,SAAS,WAAW,IAAIC,
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/core/domain/content-type/index.ts"],"sourcesContent":["import { cloneDeep } from 'lodash/fp';\nimport _ from 'lodash';\nimport { yup, contentTypes as contentTypesUtils } from '@strapi/utils';\nimport type { Schema } from '@strapi/types';\nimport { validateContentTypeDefinition } from './validator';\n\nexport type ContentTypeDefinition = {\n schema: Schema.ContentType;\n actions: Record<string, unknown>;\n lifecycles: Record<string, unknown>;\n};\n\nconst {\n CREATED_AT_ATTRIBUTE,\n UPDATED_AT_ATTRIBUTE,\n PUBLISHED_AT_ATTRIBUTE,\n CREATED_BY_ATTRIBUTE,\n UPDATED_BY_ATTRIBUTE,\n} = contentTypesUtils.constants;\n\nconst createContentType = (uid: string, definition: ContentTypeDefinition) => {\n try {\n validateContentTypeDefinition(definition);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n throw new Error(`Content Type Definition is invalid for ${uid}'.\\n${e.errors}`);\n }\n\n throw e;\n }\n\n const { schema, actions, lifecycles } = cloneDeep(definition);\n\n // general info\n Object.assign(schema, {\n kind: schema.kind || 'collectionType',\n __schema__: pickSchema(definition.schema),\n modelType: 'contentType',\n modelName: definition.schema.info.singularName,\n connection: 'default',\n });\n\n if (uid.startsWith('api::')) {\n Object.assign(schema, {\n uid,\n apiName: uid.split('::')[1].split('.')[0],\n collectionName: schema.collectionName || schema.info.singularName,\n globalId: getGlobalId(schema, schema.info.singularName),\n });\n } else if (uid.startsWith('plugin::')) {\n const pluginName = uid.split('::')[1].split('.')[0];\n Object.assign(schema, {\n uid,\n plugin: pluginName, // TODO: to be set in load-plugins.js\n collectionName:\n schema.collectionName || `${pluginName}_${schema.info.singularName}`.toLowerCase(),\n globalId: getGlobalId(schema, schema.info.singularName, pluginName),\n });\n } else if (uid.startsWith('admin::')) {\n Object.assign(schema, {\n uid,\n plugin: 'admin',\n globalId: getGlobalId(schema, schema.info.singularName, 'admin'),\n });\n } else {\n throw new Error(\n `Incorrect Content Type UID \"${uid}\". The UID should start with api::, plugin:: or admin::.`\n );\n }\n\n // attributes\n Object.assign(schema.attributes, {\n [CREATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n // TODO: handle on edit set to new date\n [UPDATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n });\n\n if (contentTypesUtils.hasDraftAndPublish(schema as any)) {\n schema.attributes[PUBLISHED_AT_ATTRIBUTE] = {\n type: 'datetime',\n configurable: false,\n writable: true,\n visible: false,\n };\n }\n\n const isPrivate = !_.get(schema, 'options.populateCreatorFields', false);\n\n schema.attributes[CREATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n\n schema.attributes[UPDATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n\n Object.assign(schema, { actions, lifecycles });\n\n return schema;\n};\n\nconst getGlobalId = (model: any, modelName: string, prefix?: string) => {\n const globalId = prefix ? `${prefix}-${modelName}` : modelName;\n\n return model.globalId || _.upperFirst(_.camelCase(globalId));\n};\n\nconst pickSchema = (model: Schema.ContentType) => {\n const schema = _.cloneDeep(\n _.pick(model, [\n 'connection',\n 'collectionName',\n 'info',\n 'options',\n 'pluginOptions',\n 'attributes',\n ])\n );\n\n schema.kind = model.kind || 'collectionType';\n return schema;\n};\n\nexport { createContentType };\n"],"names":["contentTypesUtils","validateContentTypeDefinition","yup","cloneDeep","_"],"mappings":";;;;;;;;AAYA,MAAM;AAAA,EACJ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,IAAIA,YAAAA,aAAkB;AAEhB,MAAA,oBAAoB,CAAC,KAAa,eAAsC;AACxE,MAAA;AACFC,cAAA,8BAA8B,UAAU;AAAA,WACj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GI,SAAA,OAAO,MAAM,QAAQ;AACrB,SAAA;AACT;;"}
|
|
@@ -3,7 +3,7 @@ const path = require("path");
|
|
|
3
3
|
const fse = require("fs-extra");
|
|
4
4
|
const _ = require("lodash");
|
|
5
5
|
const strapiUtils = require("@strapi/utils");
|
|
6
|
-
const
|
|
6
|
+
const fp = require("lodash/fp");
|
|
7
7
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
8
8
|
const fse__default = /* @__PURE__ */ _interopDefault(fse);
|
|
9
9
|
const ___default = /* @__PURE__ */ _interopDefault(_);
|
|
@@ -90,7 +90,7 @@ const loadContentTypes = async (dir) => {
|
|
|
90
90
|
}
|
|
91
91
|
const contentTypeName = normalizeName(fd.name);
|
|
92
92
|
const contentType = await loadDir(path.join(dir, fd.name));
|
|
93
|
-
if (
|
|
93
|
+
if (fp.isEmpty(contentType) || fp.isEmpty(contentType.schema)) {
|
|
94
94
|
throw new Error(`Could not load content type found at ${dir}`);
|
|
95
95
|
}
|
|
96
96
|
contentTypes[normalizeName(contentTypeName)] = ___default.default.defaults(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apis.js","sources":["../../../src/core/loaders/apis.ts"],"sourcesContent":["import { join, extname, basename } from 'path';\nimport fse, { existsSync } from 'fs-extra';\nimport _ from 'lodash';\nimport { isKebabCase, importDefault } from '@strapi/utils';\nimport { isEmpty } from 'lodash/fp';\nimport type { Strapi, Common, Schema } from '@strapi/types';\n\ninterface API {\n bootstrap: () => void | Promise<void>;\n destroy: () => void | Promise<void>;\n register: () => void | Promise<void>;\n config: Record<string, unknown>;\n routes: Record<string, Common.Router>;\n controllers: Record<string, Common.Controller>;\n services: Record<string, Common.Service>;\n policies: Record<string, Common.Policy>;\n middlewares: Record<string, Common.Middleware>;\n contentTypes: Record<string, { schema: Schema.ContentType }>;\n}\n\ninterface APIs {\n [key: string]: API;\n}\n\nconst DEFAULT_CONTENT_TYPE = {\n schema: {},\n actions: {},\n lifecycles: {},\n};\n\n// to handle names with numbers in it we first check if it is already in kebabCase\nconst normalizeName = (name: string) => (isKebabCase(name) ? name : _.kebabCase(name));\n\nconst isDirectory = (fd: fse.Dirent) => fd.isDirectory();\nconst isDotFile = (fd: fse.Dirent) => fd.name.startsWith('.');\n\nexport default async function loadAPIs(strapi: Strapi) {\n if (!existsSync(strapi.dirs.dist.api)) {\n return;\n }\n\n const apisFDs = await (await fse.readdir(strapi.dirs.dist.api, { withFileTypes: true }))\n .filter(isDirectory)\n .filter(_.negate(isDotFile));\n\n const apis: APIs = {};\n\n // only load folders\n for (const apiFD of apisFDs) {\n const apiName = normalizeName(apiFD.name);\n const api = await loadAPI(join(strapi.dirs.dist.api, apiFD.name));\n\n apis[apiName] = api;\n }\n\n validateContentTypesUnicity(apis);\n\n for (const apiName of Object.keys(apis)) {\n strapi.container.get('apis').add(apiName, apis[apiName]);\n }\n}\n\nconst validateContentTypesUnicity = (apis: APIs) => {\n const allApisSchemas = Object.values(apis).flatMap((api) => Object.values(api.contentTypes));\n\n const names: string[] = [];\n allApisSchemas.forEach(({ schema }) => {\n if (schema.info.singularName) {\n const singularName = _.kebabCase(schema.info.singularName);\n if (names.includes(singularName)) {\n throw new Error(`The singular name \"${schema.info.singularName}\" should be unique`);\n }\n names.push(singularName);\n }\n\n if (schema.info.pluralName) {\n const pluralName = _.kebabCase(schema.info.pluralName);\n if (names.includes(pluralName)) {\n throw new Error(`The plural name \"${schema.info.pluralName}\" should be unique`);\n }\n names.push(pluralName);\n }\n });\n};\n\nconst loadAPI = async (dir: string) => {\n const [index, config, routes, controllers, services, policies, middlewares, contentTypes] =\n await Promise.all([\n loadIndex(dir),\n loadDir(join(dir, 'config')),\n loadDir(join(dir, 'routes')),\n loadDir(join(dir, 'controllers')),\n loadDir(join(dir, 'services')),\n loadDir(join(dir, 'policies')),\n loadDir(join(dir, 'middlewares')),\n loadContentTypes(join(dir, 'content-types')),\n ]);\n\n return {\n ...(index || {}),\n config: config || {},\n routes: routes || [],\n controllers: controllers || {},\n services: services || {},\n policies: policies || {},\n middlewares: middlewares || {},\n contentTypes: contentTypes || {},\n };\n};\n\nconst loadIndex = async (dir: string) => {\n if (await fse.pathExists(join(dir, 'index.js'))) {\n return loadFile(join(dir, 'index.js'));\n }\n};\n\nconst loadContentTypes = async (dir: string) => {\n if (!(await fse.pathExists(dir))) {\n return;\n }\n\n const fds = await fse.readdir(dir, { withFileTypes: true });\n const contentTypes: API['contentTypes'] = {};\n\n // only load folders\n for (const fd of fds) {\n if (fd.isFile()) {\n continue;\n }\n\n const contentTypeName = normalizeName(fd.name);\n const contentType = await loadDir(join(dir, fd.name));\n\n if (isEmpty(contentType) || isEmpty(contentType.schema)) {\n throw new Error(`Could not load content type found at ${dir}`);\n }\n\n contentTypes[normalizeName(contentTypeName)] = _.defaults(\n contentType as { schema: Schema.ContentType },\n DEFAULT_CONTENT_TYPE\n );\n }\n\n return contentTypes;\n};\n\nconst loadDir = async (dir: string) => {\n if (!(await fse.pathExists(dir))) {\n return;\n }\n\n const fds = await fse.readdir(dir, { withFileTypes: true });\n\n const root: Record<string, unknown> = {};\n for (const fd of fds) {\n if (!fd.isFile() || extname(fd.name) === '.map') {\n continue;\n }\n\n const key = basename(fd.name, extname(fd.name));\n\n root[normalizeName(key)] = await loadFile(join(dir, fd.name));\n }\n\n return root;\n};\n\nconst loadFile = (file: string) => {\n const ext = extname(file);\n\n switch (ext) {\n case '.js':\n return importDefault(file);\n case '.json':\n return fse.readJSON(file);\n default:\n return {};\n }\n};\n"],"names":["isKebabCase","_","existsSync","fse","join","isEmpty","extname","basename","importDefault"],"mappings":";;;;;;;;;AAwBA,MAAM,uBAAuB;AAAA,EAC3B,QAAQ,CAAC;AAAA,EACT,SAAS,CAAC;AAAA,EACV,YAAY,CAAC;AACf;AAGA,MAAM,gBAAgB,CAAC,SAAkBA,YAAAA,YAAY,IAAI,IAAI,OAAOC,WAAE,QAAA,UAAU,IAAI;AAEpF,MAAM,cAAc,CAAC,OAAmB,GAAG,Y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QAAQ,KAAK,EAAE,eAAe,MAAM;AAC1D,QAAM,eAAoC,CAAA;AAG1C,aAAW,MAAM,KAAK;AAChB,QAAA,GAAG,UAAU;AACf;AAAA,IACF;AAEM,UAAA,kBAAkB,cAAc,GAAG,IAAI;AAC7C,UAAM,cAAc,MAAM,QAAQC,KAAAA,KAAK,KAAK,GAAG,IAAI,CAAC;AAEpD,QAAIC,
|
|
1
|
+
{"version":3,"file":"apis.js","sources":["../../../src/core/loaders/apis.ts"],"sourcesContent":["import { join, extname, basename } from 'path';\nimport fse, { existsSync } from 'fs-extra';\nimport _ from 'lodash';\nimport { isKebabCase, importDefault } from '@strapi/utils';\nimport { isEmpty } from 'lodash/fp';\nimport type { Strapi, Common, Schema } from '@strapi/types';\n\ninterface API {\n bootstrap: () => void | Promise<void>;\n destroy: () => void | Promise<void>;\n register: () => void | Promise<void>;\n config: Record<string, unknown>;\n routes: Record<string, Common.Router>;\n controllers: Record<string, Common.Controller>;\n services: Record<string, Common.Service>;\n policies: Record<string, Common.Policy>;\n middlewares: Record<string, Common.Middleware>;\n contentTypes: Record<string, { schema: Schema.ContentType }>;\n}\n\ninterface APIs {\n [key: string]: API;\n}\n\nconst DEFAULT_CONTENT_TYPE = {\n schema: {},\n actions: {},\n lifecycles: {},\n};\n\n// to handle names with numbers in it we first check if it is already in kebabCase\nconst normalizeName = (name: string) => (isKebabCase(name) ? name : _.kebabCase(name));\n\nconst isDirectory = (fd: fse.Dirent) => fd.isDirectory();\nconst isDotFile = (fd: fse.Dirent) => fd.name.startsWith('.');\n\nexport default async function loadAPIs(strapi: Strapi) {\n if (!existsSync(strapi.dirs.dist.api)) {\n return;\n }\n\n const apisFDs = await (await fse.readdir(strapi.dirs.dist.api, { withFileTypes: true }))\n .filter(isDirectory)\n .filter(_.negate(isDotFile));\n\n const apis: APIs = {};\n\n // only load folders\n for (const apiFD of apisFDs) {\n const apiName = normalizeName(apiFD.name);\n const api = await loadAPI(join(strapi.dirs.dist.api, apiFD.name));\n\n apis[apiName] = api;\n }\n\n validateContentTypesUnicity(apis);\n\n for (const apiName of Object.keys(apis)) {\n strapi.container.get('apis').add(apiName, apis[apiName]);\n }\n}\n\nconst validateContentTypesUnicity = (apis: APIs) => {\n const allApisSchemas = Object.values(apis).flatMap((api) => Object.values(api.contentTypes));\n\n const names: string[] = [];\n allApisSchemas.forEach(({ schema }) => {\n if (schema.info.singularName) {\n const singularName = _.kebabCase(schema.info.singularName);\n if (names.includes(singularName)) {\n throw new Error(`The singular name \"${schema.info.singularName}\" should be unique`);\n }\n names.push(singularName);\n }\n\n if (schema.info.pluralName) {\n const pluralName = _.kebabCase(schema.info.pluralName);\n if (names.includes(pluralName)) {\n throw new Error(`The plural name \"${schema.info.pluralName}\" should be unique`);\n }\n names.push(pluralName);\n }\n });\n};\n\nconst loadAPI = async (dir: string) => {\n const [index, config, routes, controllers, services, policies, middlewares, contentTypes] =\n await Promise.all([\n loadIndex(dir),\n loadDir(join(dir, 'config')),\n loadDir(join(dir, 'routes')),\n loadDir(join(dir, 'controllers')),\n loadDir(join(dir, 'services')),\n loadDir(join(dir, 'policies')),\n loadDir(join(dir, 'middlewares')),\n loadContentTypes(join(dir, 'content-types')),\n ]);\n\n return {\n ...(index || {}),\n config: config || {},\n routes: routes || [],\n controllers: controllers || {},\n services: services || {},\n policies: policies || {},\n middlewares: middlewares || {},\n contentTypes: contentTypes || {},\n };\n};\n\nconst loadIndex = async (dir: string) => {\n if (await fse.pathExists(join(dir, 'index.js'))) {\n return loadFile(join(dir, 'index.js'));\n }\n};\n\nconst loadContentTypes = async (dir: string) => {\n if (!(await fse.pathExists(dir))) {\n return;\n }\n\n const fds = await fse.readdir(dir, { withFileTypes: true });\n const contentTypes: API['contentTypes'] = {};\n\n // only load folders\n for (const fd of fds) {\n if (fd.isFile()) {\n continue;\n }\n\n const contentTypeName = normalizeName(fd.name);\n const contentType = await loadDir(join(dir, fd.name));\n\n if (isEmpty(contentType) || isEmpty(contentType.schema)) {\n throw new Error(`Could not load content type found at ${dir}`);\n }\n\n contentTypes[normalizeName(contentTypeName)] = _.defaults(\n contentType as { schema: Schema.ContentType },\n DEFAULT_CONTENT_TYPE\n );\n }\n\n return contentTypes;\n};\n\nconst loadDir = async (dir: string) => {\n if (!(await fse.pathExists(dir))) {\n return;\n }\n\n const fds = await fse.readdir(dir, { withFileTypes: true });\n\n const root: Record<string, unknown> = {};\n for (const fd of fds) {\n if (!fd.isFile() || extname(fd.name) === '.map') {\n continue;\n }\n\n const key = basename(fd.name, extname(fd.name));\n\n root[normalizeName(key)] = await loadFile(join(dir, fd.name));\n }\n\n return root;\n};\n\nconst loadFile = (file: string) => {\n const ext = extname(file);\n\n switch (ext) {\n case '.js':\n return importDefault(file);\n case '.json':\n return fse.readJSON(file);\n default:\n return {};\n }\n};\n"],"names":["isKebabCase","_","existsSync","fse","join","isEmpty","extname","basename","importDefault"],"mappings":";;;;;;;;;AAwBA,MAAM,uBAAuB;AAAA,EAC3B,QAAQ,CAAC;AAAA,EACT,SAAS,CAAC;AAAA,EACV,YAAY,CAAC;AACf;AAGA,MAAM,gBAAgB,CAAC,SAAkBA,YAAAA,YAAY,IAAI,IAAI,OAAOC,WAAE,QAAA,UAAU,IAAI;AAEpF,MAAM,cAAc,CAAC,OAAmB,GAAG,YAAY;AACvD,MAAM,YAAY,CAAC,OAAmB,GAAG,KAAK,WAAW,GAAG;AAE5D,eAA8B,SAAS,QAAgB;AACrD,MAAI,CAACC,IAAW,WAAA,OAAO,KAAK,KAAK,GAAG,GAAG;AACrC;AAAA,EACF;AAEM,QAAA,UAAU,OAAO,MAAMC,aAAA,QAAI,QAAQ,OAAO,KAAK,KAAK,KAAK,EAAE,eAAe,KAAM,CAAA,GACnF,OAAO,WAAW,EAClB,OAAOF,mBAAE,OAAO,SAAS,CAAC;AAE7B,QAAM,OAAa,CAAA;AAGnB,aAAW,SAAS,SAAS;AACrB,UAAA,UAAU,cAAc,MAAM,IAAI;AAClC,UAAA,MAAM,MAAM,QAAQG,KAAA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,IAAA;AAAA,EAEJ;AAEO,SAAA;AACT;AAEA,MAAM,UAAU,OAAO,QAAgB;AACrC,MAAI,CAAE,MAAME,aAAAA,QAAI,WAAW,GAAG,GAAI;AAChC;AAAA,EACF;AAEM,QAAA,MAAM,MAAMA,aAAAA,QAAI,QAAQ,KAAK,EAAE,eAAe,MAAM;AAE1D,QAAM,OAAgC,CAAA;AACtC,aAAW,MAAM,KAAK;AAChB,QAAA,CAAC,GAAG,OAAO,KAAKG,aAAQ,GAAG,IAAI,MAAM,QAAQ;AAC/C;AAAA,IACF;AAEA,UAAM,MAAMC,KAAS,SAAA,GAAG,MAAMD,KAAAA,QAAQ,GAAG,IAAI,CAAC;AAEzC,SAAA,cAAc,GAAG,CAAC,IAAI,MAAM,SAASF,KAAK,KAAA,KAAK,GAAG,IAAI,CAAC;AAAA,EAC9D;AAEO,SAAA;AACT;AAEA,MAAM,WAAW,CAAC,SAAiB;AAC3B,QAAA,MAAME,aAAQ,IAAI;AAExB,UAAQ,KAAK;AAAA,IACX,KAAK;AACH,aAAOE,YAAAA,cAAc,IAAI;AAAA,IAC3B,KAAK;AACI,aAAAL,aAAA,QAAI,SAAS,IAAI;AAAA,IAC1B;AACE,aAAO;EACX;AACF;;"}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const path = require("path");
|
|
4
4
|
const fs = require("fs");
|
|
5
5
|
const _ = require("lodash");
|
|
6
|
-
const
|
|
6
|
+
const fp = require("lodash/fp");
|
|
7
7
|
const strapiUtils = require("@strapi/utils");
|
|
8
8
|
const getUserPluginsConfig = require("./get-user-plugins-config.js");
|
|
9
9
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
@@ -15,7 +15,7 @@ const INTERNAL_PLUGINS = [
|
|
|
15
15
|
"@strapi/plugin-upload",
|
|
16
16
|
"@strapi/content-releases"
|
|
17
17
|
];
|
|
18
|
-
const isStrapiPlugin = (info) =>
|
|
18
|
+
const isStrapiPlugin = (info) => fp.get("strapi.kind", info) === "plugin";
|
|
19
19
|
const validatePluginName = (pluginName) => {
|
|
20
20
|
if (!strapiUtils.isKebabCase(pluginName)) {
|
|
21
21
|
throw new Error(`Plugin name "${pluginName}" is not in kebab (an-example-of-kebab-case)`);
|
|
@@ -95,15 +95,15 @@ const getEnabledPlugins = async (strapi2, { client } = { client: false }) => {
|
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
});
|
|
98
|
-
const declaredPluginsResolves =
|
|
99
|
-
const installedPluginsNotAlreadyUsed =
|
|
98
|
+
const declaredPluginsResolves = fp.map(fp.prop("pathToPlugin"), declaredPlugins);
|
|
99
|
+
const installedPluginsNotAlreadyUsed = fp.pickBy(
|
|
100
100
|
(p) => !declaredPluginsResolves.includes(p.pathToPlugin),
|
|
101
101
|
installedPlugins
|
|
102
102
|
);
|
|
103
|
-
const enabledPlugins =
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
const enabledPlugins = fp.pipe(
|
|
104
|
+
fp.defaultsDeep(declaredPlugins),
|
|
105
|
+
fp.defaultsDeep(installedPluginsNotAlreadyUsed),
|
|
106
|
+
fp.pickBy((p) => p.enabled)
|
|
107
107
|
)(internalPlugins);
|
|
108
108
|
return enabledPlugins;
|
|
109
109
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-enabled-plugins.js","sources":["../../../../src/core/loaders/plugins/get-enabled-plugins.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-var-requires */\nimport { dirname, join, resolve } from 'path';\nimport { statSync, existsSync } from 'fs';\nimport _ from 'lodash';\nimport { get, pickBy, defaultsDeep, map, prop, pipe } from 'lodash/fp';\nimport { isKebabCase } from '@strapi/utils';\nimport type { Strapi } from '@strapi/types';\nimport { getUserPluginsConfig } from './get-user-plugins-config';\n\ninterface PluginMeta {\n enabled: boolean;\n pathToPlugin?: string;\n info: Record<string, unknown>;\n}\n\ntype PluginMetas = Record<string, PluginMeta>;\n\ninterface PluginInfo {\n name: string;\n kind: string;\n}\n\ninterface PluginDeclaration {\n enabled: boolean;\n resolve: string;\n isModule: boolean;\n}\n\n/**\n * otherwise known as \"core features\"\n */\nconst INTERNAL_PLUGINS = [\n '@strapi/plugin-content-manager',\n '@strapi/plugin-content-type-builder',\n '@strapi/plugin-email',\n '@strapi/plugin-upload',\n '@strapi/content-releases',\n];\n\nconst isStrapiPlugin = (info: PluginInfo) => get('strapi.kind', info) === 'plugin';\n\nconst validatePluginName = (pluginName: string) => {\n if (!isKebabCase(pluginName)) {\n throw new Error(`Plugin name \"${pluginName}\" is not in kebab (an-example-of-kebab-case)`);\n }\n};\n\nconst toDetailedDeclaration = (declaration: boolean | PluginDeclaration) => {\n if (typeof declaration === 'boolean') {\n return { enabled: declaration };\n }\n\n const detailedDeclaration: { enabled: boolean; pathToPlugin?: string } = {\n enabled: declaration.enabled,\n };\n\n if (declaration?.resolve) {\n let pathToPlugin = '';\n\n if (declaration.isModule) {\n /**\n * we only want the node_module here, not the package.json\n */\n pathToPlugin = join(declaration.resolve, '..');\n } else {\n try {\n pathToPlugin = dirname(require.resolve(declaration.resolve));\n } catch (e) {\n pathToPlugin = resolve(strapi.dirs.app.root, declaration.resolve);\n\n if (!existsSync(pathToPlugin) || !statSync(pathToPlugin).isDirectory()) {\n throw new Error(`${declaration.resolve} couldn't be resolved`);\n }\n }\n }\n\n detailedDeclaration.pathToPlugin = pathToPlugin;\n }\n\n return detailedDeclaration;\n};\n\nexport const getEnabledPlugins = async (strapi: Strapi, { client } = { client: false }) => {\n const internalPlugins: PluginMetas = {};\n\n for (const dep of INTERNAL_PLUGINS) {\n const packagePath = join(dep, 'package.json');\n const packageInfo = require(packagePath);\n\n validatePluginName(packageInfo.strapi.name);\n internalPlugins[packageInfo.strapi.name] = {\n ...toDetailedDeclaration({ enabled: true, resolve: packagePath, isModule: client }),\n info: packageInfo.strapi,\n };\n }\n\n const installedPlugins: PluginMetas = {};\n const dependencies = strapi.config.get('info.dependencies', {});\n\n for (const dep of Object.keys(dependencies)) {\n const packagePath = join(dep, 'package.json');\n let packageInfo;\n try {\n packageInfo = require(packagePath);\n } catch {\n continue;\n }\n\n if (isStrapiPlugin(packageInfo)) {\n validatePluginName(packageInfo.strapi.name);\n installedPlugins[packageInfo.strapi.name] = {\n ...toDetailedDeclaration({ enabled: true, resolve: packagePath, isModule: client }),\n info: {\n ...packageInfo.strapi,\n packageName: packageInfo.name,\n },\n };\n }\n }\n\n const declaredPlugins: PluginMetas = {};\n const userPluginsConfig = await getUserPluginsConfig();\n\n _.forEach(userPluginsConfig, (declaration, pluginName) => {\n validatePluginName(pluginName);\n\n declaredPlugins[pluginName] = {\n ...toDetailedDeclaration(declaration),\n info: {},\n };\n\n const { pathToPlugin } = declaredPlugins[pluginName];\n\n // for manually resolved plugins\n if (pathToPlugin) {\n const packagePath = join(pathToPlugin, 'package.json');\n const packageInfo = require(packagePath);\n\n if (isStrapiPlugin(packageInfo)) {\n declaredPlugins[pluginName].info = packageInfo.strapi || {};\n }\n }\n });\n\n const declaredPluginsResolves = map(prop('pathToPlugin'), declaredPlugins);\n const installedPluginsNotAlreadyUsed = pickBy(\n (p) => !declaredPluginsResolves.includes(p.pathToPlugin),\n installedPlugins\n );\n\n const enabledPlugins = pipe(\n defaultsDeep(declaredPlugins),\n defaultsDeep(installedPluginsNotAlreadyUsed),\n pickBy((p: PluginMeta) => p.enabled)\n )(internalPlugins);\n\n return enabledPlugins;\n};\n"],"names":["get","isKebabCase","join","dirname","resolve","existsSync","statSync","strapi","getUserPluginsConfig","_","map","prop","pickBy","pipe","defaultsDeep"],"mappings":";;;;;;;;;;AA+BA,MAAM,mBAAmB;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,iBAAiB,CAAC,SAAqBA,
|
|
1
|
+
{"version":3,"file":"get-enabled-plugins.js","sources":["../../../../src/core/loaders/plugins/get-enabled-plugins.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-var-requires */\nimport { dirname, join, resolve } from 'path';\nimport { statSync, existsSync } from 'fs';\nimport _ from 'lodash';\nimport { get, pickBy, defaultsDeep, map, prop, pipe } from 'lodash/fp';\nimport { isKebabCase } from '@strapi/utils';\nimport type { Strapi } from '@strapi/types';\nimport { getUserPluginsConfig } from './get-user-plugins-config';\n\ninterface PluginMeta {\n enabled: boolean;\n pathToPlugin?: string;\n info: Record<string, unknown>;\n}\n\ntype PluginMetas = Record<string, PluginMeta>;\n\ninterface PluginInfo {\n name: string;\n kind: string;\n}\n\ninterface PluginDeclaration {\n enabled: boolean;\n resolve: string;\n isModule: boolean;\n}\n\n/**\n * otherwise known as \"core features\"\n */\nconst INTERNAL_PLUGINS = [\n '@strapi/plugin-content-manager',\n '@strapi/plugin-content-type-builder',\n '@strapi/plugin-email',\n '@strapi/plugin-upload',\n '@strapi/content-releases',\n];\n\nconst isStrapiPlugin = (info: PluginInfo) => get('strapi.kind', info) === 'plugin';\n\nconst validatePluginName = (pluginName: string) => {\n if (!isKebabCase(pluginName)) {\n throw new Error(`Plugin name \"${pluginName}\" is not in kebab (an-example-of-kebab-case)`);\n }\n};\n\nconst toDetailedDeclaration = (declaration: boolean | PluginDeclaration) => {\n if (typeof declaration === 'boolean') {\n return { enabled: declaration };\n }\n\n const detailedDeclaration: { enabled: boolean; pathToPlugin?: string } = {\n enabled: declaration.enabled,\n };\n\n if (declaration?.resolve) {\n let pathToPlugin = '';\n\n if (declaration.isModule) {\n /**\n * we only want the node_module here, not the package.json\n */\n pathToPlugin = join(declaration.resolve, '..');\n } else {\n try {\n pathToPlugin = dirname(require.resolve(declaration.resolve));\n } catch (e) {\n pathToPlugin = resolve(strapi.dirs.app.root, declaration.resolve);\n\n if (!existsSync(pathToPlugin) || !statSync(pathToPlugin).isDirectory()) {\n throw new Error(`${declaration.resolve} couldn't be resolved`);\n }\n }\n }\n\n detailedDeclaration.pathToPlugin = pathToPlugin;\n }\n\n return detailedDeclaration;\n};\n\nexport const getEnabledPlugins = async (strapi: Strapi, { client } = { client: false }) => {\n const internalPlugins: PluginMetas = {};\n\n for (const dep of INTERNAL_PLUGINS) {\n const packagePath = join(dep, 'package.json');\n const packageInfo = require(packagePath);\n\n validatePluginName(packageInfo.strapi.name);\n internalPlugins[packageInfo.strapi.name] = {\n ...toDetailedDeclaration({ enabled: true, resolve: packagePath, isModule: client }),\n info: packageInfo.strapi,\n };\n }\n\n const installedPlugins: PluginMetas = {};\n const dependencies = strapi.config.get('info.dependencies', {});\n\n for (const dep of Object.keys(dependencies)) {\n const packagePath = join(dep, 'package.json');\n let packageInfo;\n try {\n packageInfo = require(packagePath);\n } catch {\n continue;\n }\n\n if (isStrapiPlugin(packageInfo)) {\n validatePluginName(packageInfo.strapi.name);\n installedPlugins[packageInfo.strapi.name] = {\n ...toDetailedDeclaration({ enabled: true, resolve: packagePath, isModule: client }),\n info: {\n ...packageInfo.strapi,\n packageName: packageInfo.name,\n },\n };\n }\n }\n\n const declaredPlugins: PluginMetas = {};\n const userPluginsConfig = await getUserPluginsConfig();\n\n _.forEach(userPluginsConfig, (declaration, pluginName) => {\n validatePluginName(pluginName);\n\n declaredPlugins[pluginName] = {\n ...toDetailedDeclaration(declaration),\n info: {},\n };\n\n const { pathToPlugin } = declaredPlugins[pluginName];\n\n // for manually resolved plugins\n if (pathToPlugin) {\n const packagePath = join(pathToPlugin, 'package.json');\n const packageInfo = require(packagePath);\n\n if (isStrapiPlugin(packageInfo)) {\n declaredPlugins[pluginName].info = packageInfo.strapi || {};\n }\n }\n });\n\n const declaredPluginsResolves = map(prop('pathToPlugin'), declaredPlugins);\n const installedPluginsNotAlreadyUsed = pickBy(\n (p) => !declaredPluginsResolves.includes(p.pathToPlugin),\n installedPlugins\n );\n\n const enabledPlugins = pipe(\n defaultsDeep(declaredPlugins),\n defaultsDeep(installedPluginsNotAlreadyUsed),\n pickBy((p: PluginMeta) => p.enabled)\n )(internalPlugins);\n\n return enabledPlugins;\n};\n"],"names":["get","isKebabCase","join","dirname","resolve","existsSync","statSync","strapi","getUserPluginsConfig","_","map","prop","pickBy","pipe","defaultsDeep"],"mappings":";;;;;;;;;;AA+BA,MAAM,mBAAmB;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,iBAAiB,CAAC,SAAqBA,GAAAA,IAAI,eAAe,IAAI,MAAM;AAE1E,MAAM,qBAAqB,CAAC,eAAuB;AAC7C,MAAA,CAACC,YAAAA,YAAY,UAAU,GAAG;AAC5B,UAAM,IAAI,MAAM,gBAAgB,UAAU,8CAA8C;AAAA,EAC1F;AACF;AAEA,MAAM,wBAAwB,CAAC,gBAA6C;AACtE,MAAA,OAAO,gBAAgB,WAAW;AAC7B,WAAA,EAAE,SAAS;EACpB;AAEA,QAAM,sBAAmE;AAAA,IACvE,SAAS,YAAY;AAAA,EAAA;AAGvB,MAAI,aAAa,SAAS;AACxB,QAAI,eAAe;AAEnB,QAAI,YAAY,UAAU;AAIT,qBAAAC,KAAAA,KAAK,YAAY,SAAS,IAAI;AAAA,IAAA,OACxC;AACD,UAAA;AACF,uBAAeC,KAAQ,QAAA,QAAQ,QAAQ,YAAY,OAAO,CAAC;AAAA,eACpD,GAAG;AACV,uBAAeC,KAAAA,QAAQ,OAAO,KAAK,IAAI,MAAM,YAAY,OAAO;AAE5D,YAAA,CAACC,cAAW,YAAY,KAAK,CAACC,GAAAA,SAAS,YAAY,EAAE,eAAe;AACtE,gBAAM,IAAI,MAAM,GAAG,YAAY,OAAO,uBAAuB;AAAA,QAC/D;AAAA,MACF;AAAA,IACF;AAEA,wBAAoB,eAAe;AAAA,EACrC;AAEO,SAAA;AACT;AAEa,MAAA,oBAAoB,OAAOC,SAAgB,EAAE,OAAW,IAAA,EAAE,QAAQ,YAAY;AACzF,QAAM,kBAA+B,CAAA;AAErC,aAAW,OAAO,kBAAkB;AAC5B,UAAA,cAAcL,KAAAA,KAAK,KAAK,cAAc;AACtC,UA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IACF;AAAA,EAAA,CACD;AAED,QAAM,0BAA0BQ,GAAAA,IAAIC,GAAAA,KAAK,cAAc,GAAG,eAAe;AACzE,QAAM,iCAAiCC,GAAA;AAAA,IACrC,CAAC,MAAM,CAAC,wBAAwB,SAAS,EAAE,YAAY;AAAA,IACvD;AAAA,EAAA;AAGF,QAAM,iBAAiBC,GAAA;AAAA,IACrBC,GAAAA,aAAa,eAAe;AAAA,IAC5BA,GAAAA,aAAa,8BAA8B;AAAA,IAC3CF,GAAAA,OAAO,CAAC,MAAkB,EAAE,OAAO;AAAA,IACnC,eAAe;AAEV,SAAA;AACT;;"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const path = require("path");
|
|
4
4
|
const fse = require("fs-extra");
|
|
5
|
-
const
|
|
5
|
+
const fp = require("lodash/fp");
|
|
6
6
|
const loadConfigFile = require("../../app-configuration/load-config-file.js");
|
|
7
7
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
8
8
|
const fse__default = /* @__PURE__ */ _interopDefault(fse);
|
|
@@ -19,7 +19,7 @@ const getUserPluginsConfig = async () => {
|
|
|
19
19
|
config = loadConfigFile.loadFile(globalUserConfigPath);
|
|
20
20
|
}
|
|
21
21
|
if (await fse__default.default.pathExists(currentEnvUserConfigPath)) {
|
|
22
|
-
config =
|
|
22
|
+
config = fp.merge(config, loadConfigFile.loadFile(currentEnvUserConfigPath));
|
|
23
23
|
}
|
|
24
24
|
return config;
|
|
25
25
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-user-plugins-config.js","sources":["../../../../src/core/loaders/plugins/get-user-plugins-config.ts"],"sourcesContent":["import { join } from 'path';\nimport fse from 'fs-extra';\nimport { merge } from 'lodash/fp';\nimport { loadFile } from '../../app-configuration/load-config-file';\n\n/**\n * Return user defined plugins' config\n * first load config from `config/plugins.js`\n * and then merge config from `config/env/{env}/plugins.js`\n */\nexport const getUserPluginsConfig = async () => {\n const globalUserConfigPath = join(strapi.dirs.dist.config, 'plugins.js');\n const currentEnvUserConfigPath = join(\n strapi.dirs.dist.config,\n 'env',\n process.env.NODE_ENV as string,\n 'plugins.js'\n );\n let config = {};\n\n // assign global user config if exists\n if (await fse.pathExists(globalUserConfigPath)) {\n config = loadFile(globalUserConfigPath);\n }\n\n // and merge user config by environment if exists\n if (await fse.pathExists(currentEnvUserConfigPath)) {\n config = merge(config, loadFile(currentEnvUserConfigPath));\n }\n\n return config;\n};\n"],"names":["join","fse","loadFile","merge"],"mappings":";;;;;;;;AAUO,MAAM,uBAAuB,YAAY;AAC9C,QAAM,uBAAuBA,KAAAA,KAAK,OAAO,KAAK,KAAK,QAAQ,YAAY;AACvE,QAAM,2BAA2BA,KAAA;AAAA,IAC/B,OAAO,KAAK,KAAK;AAAA,IACjB;AAAA,IACA,QAAQ,IAAI;AAAA,IACZ;AAAA,EAAA;AAEF,MAAI,SAAS,CAAA;AAGb,MAAI,MAAMC,aAAA,QAAI,WAAW,oBAAoB,GAAG;AAC9C,aAASC,eAAAA,SAAS,oBAAoB;AAAA,EACxC;AAGA,MAAI,MAAMD,aAAA,QAAI,WAAW,wBAAwB,GAAG;AAClD,aAASE,
|
|
1
|
+
{"version":3,"file":"get-user-plugins-config.js","sources":["../../../../src/core/loaders/plugins/get-user-plugins-config.ts"],"sourcesContent":["import { join } from 'path';\nimport fse from 'fs-extra';\nimport { merge } from 'lodash/fp';\nimport { loadFile } from '../../app-configuration/load-config-file';\n\n/**\n * Return user defined plugins' config\n * first load config from `config/plugins.js`\n * and then merge config from `config/env/{env}/plugins.js`\n */\nexport const getUserPluginsConfig = async () => {\n const globalUserConfigPath = join(strapi.dirs.dist.config, 'plugins.js');\n const currentEnvUserConfigPath = join(\n strapi.dirs.dist.config,\n 'env',\n process.env.NODE_ENV as string,\n 'plugins.js'\n );\n let config = {};\n\n // assign global user config if exists\n if (await fse.pathExists(globalUserConfigPath)) {\n config = loadFile(globalUserConfigPath);\n }\n\n // and merge user config by environment if exists\n if (await fse.pathExists(currentEnvUserConfigPath)) {\n config = merge(config, loadFile(currentEnvUserConfigPath));\n }\n\n return config;\n};\n"],"names":["join","fse","loadFile","merge"],"mappings":";;;;;;;;AAUO,MAAM,uBAAuB,YAAY;AAC9C,QAAM,uBAAuBA,KAAAA,KAAK,OAAO,KAAK,KAAK,QAAQ,YAAY;AACvE,QAAM,2BAA2BA,KAAA;AAAA,IAC/B,OAAO,KAAK,KAAK;AAAA,IACjB;AAAA,IACA,QAAQ,IAAI;AAAA,IACZ;AAAA,EAAA;AAEF,MAAI,SAAS,CAAA;AAGb,MAAI,MAAMC,aAAA,QAAI,WAAW,oBAAoB,GAAG;AAC9C,aAASC,eAAAA,SAAS,oBAAoB;AAAA,EACxC;AAGA,MAAI,MAAMD,aAAA,QAAI,WAAW,wBAAwB,GAAG;AAClD,aAASE,GAAAA,MAAM,QAAQD,eAAAA,SAAS,wBAAwB,CAAC;AAAA,EAC3D;AAEO,SAAA;AACT;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const path = require("path");
|
|
3
3
|
const fse = require("fs-extra");
|
|
4
|
-
const
|
|
4
|
+
const fp = require("lodash/fp");
|
|
5
5
|
const strapiUtils = require("@strapi/utils");
|
|
6
6
|
const loadConfigFile = require("../../app-configuration/load-config-file.js");
|
|
7
7
|
const loadFiles = require("../../../load/load-files.js");
|
|
@@ -38,7 +38,7 @@ const applyUserExtension = async (plugins) => {
|
|
|
38
38
|
for (const pluginName of Object.keys(plugins)) {
|
|
39
39
|
const plugin = plugins[pluginName];
|
|
40
40
|
for (const ctName of Object.keys(plugin.contentTypes)) {
|
|
41
|
-
const extendedSchema =
|
|
41
|
+
const extendedSchema = fp.get([pluginName, "content-types", ctName, "schema"], extendedSchemas);
|
|
42
42
|
if (extendedSchema) {
|
|
43
43
|
plugin.contentTypes[ctName].schema = {
|
|
44
44
|
...plugin.contentTypes[ctName].schema,
|
|
@@ -46,7 +46,7 @@ const applyUserExtension = async (plugins) => {
|
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
const strapiServer =
|
|
49
|
+
const strapiServer = fp.get([pluginName, "strapi-server"], strapiServers);
|
|
50
50
|
if (strapiServer) {
|
|
51
51
|
plugins[pluginName] = await strapiServer(plugin);
|
|
52
52
|
}
|
|
@@ -56,9 +56,9 @@ const applyUserConfig = async (plugins) => {
|
|
|
56
56
|
const userPluginsConfig = await getUserPluginsConfig.getUserPluginsConfig();
|
|
57
57
|
for (const pluginName of Object.keys(plugins)) {
|
|
58
58
|
const plugin = plugins[pluginName];
|
|
59
|
-
const userPluginConfig =
|
|
59
|
+
const userPluginConfig = fp.getOr({}, `${pluginName}.config`, userPluginsConfig);
|
|
60
60
|
const defaultConfig = typeof plugin.config.default === "function" ? plugin.config.default({ env: strapiUtils.env }) : plugin.config.default;
|
|
61
|
-
const config =
|
|
61
|
+
const config = fp.defaultsDeep(defaultConfig, userPluginConfig);
|
|
62
62
|
try {
|
|
63
63
|
plugin.config.validator(config);
|
|
64
64
|
} catch (e) {
|
|
@@ -91,7 +91,7 @@ async function loadPlugins(strapi2) {
|
|
|
91
91
|
plugins[pluginName] = {
|
|
92
92
|
...defaultPlugin,
|
|
93
93
|
...pluginServer,
|
|
94
|
-
config:
|
|
94
|
+
config: fp.defaults(defaultPlugin.config, pluginServer.config),
|
|
95
95
|
routes: pluginServer.routes ?? defaultPlugin.routes
|
|
96
96
|
};
|
|
97
97
|
}
|