跳转到内容

virtuals/utils

此内容尚不支持你的语言。

function buildDefaultOnlyVirtual(mod: any): string

Defined in: studiocms/packages/studiocms/src/virtuals/utils.ts:14^

Builds a string representing a default export of the provided module object.

any

The module object to be stringified and exported as default.

string

A string containing a TypeScript/JavaScript default export statement with the serialized module.


function buildLoggerVirtual(verbose: boolean): string

Defined in: studiocms/packages/studiocms/src/virtuals/utils.ts:127^

Builds the content for a logger virtual file by reading a logger stub file and replacing the $$verbose$$ placeholder with the provided verbosity flag.

boolean

Determines whether verbose logging should be enabled.

string

The logger file content with the verbosity setting applied.


function buildNamedMultiExportVirtual(items: Record<string, string>): string

Defined in: studiocms/packages/studiocms/src/virtuals/utils.ts:34^

Builds a string containing multiple named ES module exports from a record of key-value pairs.

Each key in the input object becomes the exported constant’s name, and each value is stringified and assigned to the corresponding export.

Record<string, string>

An object where each key-value pair represents the name and value of an export.

string

A string containing multiple export statements, one for each entry in the input object.

const exports = buildNamedMultiExportVirtual({ foo: "bar", baz: "qux" });
// exports:
// export const foo = "bar";
// export const baz = "qux";

function buildVirtualConfig(options: {
componentRegistry: Record<string, string>;
dbStartPage: boolean;
features: {
authConfig: {
enabled: boolean;
providers: {
usernameAndPassword: boolean;
usernameAndPasswordConfig: {
allowUserRegistration: boolean;
};
};
};
dashboardConfig: {
dashboardEnabled: boolean;
dashboardRouteOverride: string;
faviconURL: string;
inject404Route: boolean;
versionCheck: boolean;
};
developerConfig: {
demoMode: | false
| {
password: string;
username: string;
};
};
injectQuickActionsMenu: boolean;
preferredImageService: string;
robotsTXT: | boolean
| {
host: string | boolean;
policy: {
allow: string | string[];
cleanParam: string | string[];
crawlDelay: number;
disallow: string | string[];
userAgent: | "*"
| "360Spider"
| "360Spider-Image"
| "360Spider-Video"
| "HaoSouSpider"
| "AdsBot-Google"
| "AdsBot-Google-Mobile"
| "AdsBot-Google-Mobile-Apps"
| "Googlebot"
| "Googlebot-Image"
| "Googlebot-Mobile"
| "Googlebot-News"
| "Googlebot-Video"
| "Mediapartners-Google"
| "adidxbot"
| "bingbot"
| "BingPreview"
| "MicrosoftPreview"
| "msnbot"
| "msnbot-media"
| "Applebot"
| "AppleNewsBot"
| "Baiduspider"
| "Baiduspider-image"
| "Baiduspider-mobile"
| "Baiduspider-news"
| "Baiduspider-video"
| "coccoc"
| "coccocbot-image"
| "coccocbot-web"
| "DuckDuckBot"
| "DuckDuckGo-Favicons-Bot"
| "facebookcatalog"
| "facebookexternalhit"
| "Facebot"
| "gooblog"
| "ichiro"
| "Sogou blog"
| "Sogou inst spider"
| "Sogou News Spider"
| "Sogou Orion spider"
| "Sogou spider2"
| "Sogou web spider"
| "Yandex"
| "YandexMobileBot"
| "Algolia Crawler"
| "BublupBot"
| "CCBot"
| "Cliqzbot"
| "Daumoa"
| "DeuSu"
| "EuripBot"
| "Exploratodo"
| "Feedly"
| "Findxbot"
| "istellabot"
| "JikeSpider"
| "Lycos"
| "Mail.Ru"
| "MojeekBot"
| "OrangeBot"
| "Pinterest"
| "Plukkie"
| "Qwantify"
| "Rambler"
| "SemanticScholarBot"
| "SeznamBot"
| "Sosospider"
| "Slurp"
| "Twitterbot"
| "WhatsApp"
| "yacybot"
| "YepBot"
| "Yeti"
| "YioopBot"
| "yoozBot"
| "YoudaoBot"
| (
| "*"
| "360Spider"
| "360Spider-Image"
| "360Spider-Video"
| "HaoSouSpider"
| "AdsBot-Google"
| "AdsBot-Google-Mobile"
| "AdsBot-Google-Mobile-Apps"
| "Googlebot"
| "Googlebot-Image"
| "Googlebot-Mobile"
| "Googlebot-News"
| "Googlebot-Video"
| "Mediapartners-Google"
| "adidxbot"
| "bingbot"
| "BingPreview"
| "MicrosoftPreview"
| "msnbot"
| "msnbot-media"
| "Applebot"
| "AppleNewsBot"
| "Baiduspider"
| "Baiduspider-image"
| "Baiduspider-mobile"
| "Baiduspider-news"
| "Baiduspider-video"
| "coccoc"
| "coccocbot-image"
| "coccocbot-web"
| "DuckDuckBot"
| "DuckDuckGo-Favicons-Bot"
| "facebookcatalog"
| "facebookexternalhit"
| "Facebot"
| "gooblog"
| "ichiro"
| "Sogou blog"
| "Sogou inst spider"
| "Sogou News Spider"
| "Sogou Orion spider"
| "Sogou spider2"
| "Sogou web spider"
| "Yandex"
| "YandexMobileBot"
| "Algolia Crawler"
| "BublupBot"
| "CCBot"
| "Cliqzbot"
| "Daumoa"
| "DeuSu"
| "EuripBot"
| "Exploratodo"
| "Feedly"
| "Findxbot"
| "istellabot"
| "JikeSpider"
| "Lycos"
| "Mail.Ru"
| "MojeekBot"
| "OrangeBot"
| "Pinterest"
| "Plukkie"
| "Qwantify"
| "Rambler"
| "SemanticScholarBot"
| "SeznamBot"
| "Sosospider"
| "Slurp"
| "Twitterbot"
| "WhatsApp"
| "yacybot"
| "YepBot"
| "Yeti"
| "YioopBot"
| "yoozBot"
| "YoudaoBot")[];
}[];
sitemap: string | boolean | string[];
};
sdk: {
cacheConfig: {
enabled: boolean;
lifetime: number;
};
};
};
locale: {
dateLocale: string;
dateTimeFormat: DateTimeFormatOptions;
};
logLevel: "All" | "Fatal" | "Error" | "Warning" | "Info" | "Debug" | "Trace" | "None";
plugins: StudioCMSPlugin[];
verbose: boolean;
}): string

Defined in: studiocms/packages/studiocms/src/virtuals/utils.ts:115^

Builds the virtual configuration file content by injecting the provided StudioCMS options into a configuration stub template.

The configuration options to be injected into the stub template.

Record<string, string> = ...

Component Registry

boolean = ...

Project Initialization Page - Used during First Time Setup to initialize the database

Default

true

{ authConfig: { enabled: boolean; providers: { usernameAndPassword: boolean; usernameAndPasswordConfig: { allowUserRegistration: boolean; }; }; }; dashboardConfig: { dashboardEnabled: boolean; dashboardRouteOverride: string; faviconURL: string; inject404Route: boolean; versionCheck: boolean; }; developerConfig: { demoMode: | false | { password: string; username: string; }; }; injectQuickActionsMenu: boolean; preferredImageService: string; robotsTXT: | boolean | { host: string | boolean; policy: { allow: string | string[]; cleanParam: string | string[]; crawlDelay: number; disallow: string | string[]; userAgent: | "*" | "360Spider" | "360Spider-Image" | "360Spider-Video" | "HaoSouSpider" | "AdsBot-Google" | "AdsBot-Google-Mobile" | "AdsBot-Google-Mobile-Apps" | "Googlebot" | "Googlebot-Image" | "Googlebot-Mobile" | "Googlebot-News" | "Googlebot-Video" | "Mediapartners-Google" | "adidxbot" | "bingbot" | "BingPreview" | "MicrosoftPreview" | "msnbot" | "msnbot-media" | "Applebot" | "AppleNewsBot" | "Baiduspider" | "Baiduspider-image" | "Baiduspider-mobile" | "Baiduspider-news" | "Baiduspider-video" | "coccoc" | "coccocbot-image" | "coccocbot-web" | "DuckDuckBot" | "DuckDuckGo-Favicons-Bot" | "facebookcatalog" | "facebookexternalhit" | "Facebot" | "gooblog" | "ichiro" | "Sogou blog" | "Sogou inst spider" | "Sogou News Spider" | "Sogou Orion spider" | "Sogou spider2" | "Sogou web spider" | "Yandex" | "YandexMobileBot" | "Algolia Crawler" | "BublupBot" | "CCBot" | "Cliqzbot" | "Daumoa" | "DeuSu" | "EuripBot" | "Exploratodo" | "Feedly" | "Findxbot" | "istellabot" | "JikeSpider" | "Lycos" | "Mail.Ru" | "MojeekBot" | "OrangeBot" | "Pinterest" | "Plukkie" | "Qwantify" | "Rambler" | "SemanticScholarBot" | "SeznamBot" | "Sosospider" | "Slurp" | "Twitterbot" | "WhatsApp" | "yacybot" | "YepBot" | "Yeti" | "YioopBot" | "yoozBot" | "YoudaoBot" | ( | "*" | "360Spider" | "360Spider-Image" | "360Spider-Video" | "HaoSouSpider" | "AdsBot-Google" | "AdsBot-Google-Mobile" | "AdsBot-Google-Mobile-Apps" | "Googlebot" | "Googlebot-Image" | "Googlebot-Mobile" | "Googlebot-News" | "Googlebot-Video" | "Mediapartners-Google" | "adidxbot" | "bingbot" | "BingPreview" | "MicrosoftPreview" | "msnbot" | "msnbot-media" | "Applebot" | "AppleNewsBot" | "Baiduspider" | "Baiduspider-image" | "Baiduspider-mobile" | "Baiduspider-news" | "Baiduspider-video" | "coccoc" | "coccocbot-image" | "coccocbot-web" | "DuckDuckBot" | "DuckDuckGo-Favicons-Bot" | "facebookcatalog" | "facebookexternalhit" | "Facebot" | "gooblog" | "ichiro" | "Sogou blog" | "Sogou inst spider" | "Sogou News Spider" | "Sogou Orion spider" | "Sogou spider2" | "Sogou web spider" | "Yandex" | "YandexMobileBot" | "Algolia Crawler" | "BublupBot" | "CCBot" | "Cliqzbot" | "Daumoa" | "DeuSu" | "EuripBot" | "Exploratodo" | "Feedly" | "Findxbot" | "istellabot" | "JikeSpider" | "Lycos" | "Mail.Ru" | "MojeekBot" | "OrangeBot" | "Pinterest" | "Plukkie" | "Qwantify" | "Rambler" | "SemanticScholarBot" | "SeznamBot" | "Sosospider" | "Slurp" | "Twitterbot" | "WhatsApp" | "yacybot" | "YepBot" | "Yeti" | "YioopBot" | "yoozBot" | "YoudaoBot")[]; }[]; sitemap: string | boolean | string[]; }; sdk: { cacheConfig: { enabled: boolean; lifetime: number; }; }; } = ...

Allows adjusting the StudioCMS Dashboard features

{ enabled: boolean; providers: { usernameAndPassword: boolean; usernameAndPasswordConfig: { allowUserRegistration: boolean; }; }; } = authConfigSchema

Auth Configuration - Allows customization of the Authentication Configuration

boolean = ...

Auth Enabled - Allows enabling or disabling of the Authentication Configuration

Default

true

{ usernameAndPassword: boolean; usernameAndPasswordConfig: { allowUserRegistration: boolean; }; } = authProviderSchema

Auth Providers - Allows enabling or disabling of the Authentication Providers

features.authConfig.providers.usernameAndPassword
Section titled “features.authConfig.providers.usernameAndPassword”

boolean = ...

Username and Password Auth Provider

features.authConfig.providers.usernameAndPasswordConfig
Section titled “features.authConfig.providers.usernameAndPasswordConfig”

{ allowUserRegistration: boolean; } = localUsernameAndPasswordConfig

features.authConfig.providers.usernameAndPasswordConfig.allowUserRegistration
Section titled “features.authConfig.providers.usernameAndPasswordConfig.allowUserRegistration”

boolean = ...

Allow User Registration - Allows users to register an account

Default

false

{ dashboardEnabled: boolean; dashboardRouteOverride: string; faviconURL: string; inject404Route: boolean; versionCheck: boolean; } = dashboardConfigSchema

Allows customization of the Dashboard Configuration

boolean = ...

OPTIONAL - This allows the user to enable or disable the Astro StudioCMS dashboard but still provide all the helper’s and utilities to those who are customizing their setup, doing so will disable the dashboard and you will need to manage your content via your database

Default

true
features.dashboardConfig.dashboardRouteOverride?
Section titled “features.dashboardConfig.dashboardRouteOverride?”

string = ...

OPTIONAL - This allows the user to override the default dashboard route to a custom route

Note: Use with caution, this is an advanced feature

Usage

  • The default route is dashboard without any / or \ characters. If you want to override the route to /admin you would set this value to admin

Default

"dashboard"

string = ...

OPTIONAL - This allows the user to override the default Favicon URL to a custom URL

boolean = ...

OPTIONAL - This allows the user to enable or disable the default 404 route for the dashboard

Default

true

boolean = ...

OPTIONAL - This allows the user to enable or disable the version check for the dashboard

This will check for the latest version of StudioCMS and notify the user if there is a new version available.

Default

true

{ demoMode: | false | { password: string; username: string; }; } = developerConfigSchema

Developer Options/Configuration

| false | { password: string; username: string; } = ...

Enable demo mode for the site

If set to an object, the site will be in demo mode, and the user will be able to login with the provided username and password.

Default

false

Example

{
demoMode: {
username: "demo_user",
password: "some-demo-password"
}
}

boolean = ...

Enable Quick Actions Menu - Whether to enable the quick actions menu which allows easy access to your dashboard while logged in on non-dashboard pages.

Default

true

string = ...

Set the identifier of the Preferred Image Service

Requires an Image Service to be installed such as ‘cloudinary-js’

| boolean | { host: string | boolean; policy: { allow: string | string[]; cleanParam: string | string[]; crawlDelay: number; disallow: string | string[]; userAgent: | "*" | "360Spider" | "360Spider-Image" | "360Spider-Video" | "HaoSouSpider" | "AdsBot-Google" | "AdsBot-Google-Mobile" | "AdsBot-Google-Mobile-Apps" | "Googlebot" | "Googlebot-Image" | "Googlebot-Mobile" | "Googlebot-News" | "Googlebot-Video" | "Mediapartners-Google" | "adidxbot" | "bingbot" | "BingPreview" | "MicrosoftPreview" | "msnbot" | "msnbot-media" | "Applebot" | "AppleNewsBot" | "Baiduspider" | "Baiduspider-image" | "Baiduspider-mobile" | "Baiduspider-news" | "Baiduspider-video" | "coccoc" | "coccocbot-image" | "coccocbot-web" | "DuckDuckBot" | "DuckDuckGo-Favicons-Bot" | "facebookcatalog" | "facebookexternalhit" | "Facebot" | "gooblog" | "ichiro" | "Sogou blog" | "Sogou inst spider" | "Sogou News Spider" | "Sogou Orion spider" | "Sogou spider2" | "Sogou web spider" | "Yandex" | "YandexMobileBot" | "Algolia Crawler" | "BublupBot" | "CCBot" | "Cliqzbot" | "Daumoa" | "DeuSu" | "EuripBot" | "Exploratodo" | "Feedly" | "Findxbot" | "istellabot" | "JikeSpider" | "Lycos" | "Mail.Ru" | "MojeekBot" | "OrangeBot" | "Pinterest" | "Plukkie" | "Qwantify" | "Rambler" | "SemanticScholarBot" | "SeznamBot" | "Sosospider" | "Slurp" | "Twitterbot" | "WhatsApp" | "yacybot" | "YepBot" | "Yeti" | "YioopBot" | "yoozBot" | "YoudaoBot" | ( | "*" | "360Spider" | "360Spider-Image" | "360Spider-Video" | "HaoSouSpider" | "AdsBot-Google" | "AdsBot-Google-Mobile" | "AdsBot-Google-Mobile-Apps" | "Googlebot" | "Googlebot-Image" | "Googlebot-Mobile" | "Googlebot-News" | "Googlebot-Video" | "Mediapartners-Google" | "adidxbot" | "bingbot" | "BingPreview" | "MicrosoftPreview" | "msnbot" | "msnbot-media" | "Applebot" | "AppleNewsBot" | "Baiduspider" | "Baiduspider-image" | "Baiduspider-mobile" | "Baiduspider-news" | "Baiduspider-video" | "coccoc" | "coccocbot-image" | "coccocbot-web" | "DuckDuckBot" | "DuckDuckGo-Favicons-Bot" | "facebookcatalog" | "facebookexternalhit" | "Facebot" | "gooblog" | "ichiro" | "Sogou blog" | "Sogou inst spider" | "Sogou News Spider" | "Sogou Orion spider" | "Sogou spider2" | "Sogou web spider" | "Yandex" | "YandexMobileBot" | "Algolia Crawler" | "BublupBot" | "CCBot" | "Cliqzbot" | "Daumoa" | "DeuSu" | "EuripBot" | "Exploratodo" | "Feedly" | "Findxbot" | "istellabot" | "JikeSpider" | "Lycos" | "Mail.Ru" | "MojeekBot" | "OrangeBot" | "Pinterest" | "Plukkie" | "Qwantify" | "Rambler" | "SemanticScholarBot" | "SeznamBot" | "Sosospider" | "Slurp" | "Twitterbot" | "WhatsApp" | "yacybot" | "YepBot" | "Yeti" | "YioopBot" | "yoozBot" | "YoudaoBot")[]; }[]; sitemap: string | boolean | string[]; } = ...

Allows the user to enable/disable the use of the StudioCMS Custom astro-robots-txt Integration

Default

robotsTXT: { policy: [ { userAgent: ['*'], allow: ['/'], disallow: ['/dashboard/'] } ] }

{ cacheConfig: { enabled: boolean; lifetime: number; }; } = SDKSchema

SDKSchema is a Zod schema that validates the SDK configuration. It can either be a boolean or an object containing cache configuration.

If it is a boolean, it defaults to true and transforms into an object with default cache configuration.

If it is an object, it must contain the cacheConfig property which is validated by the SDKCacheSchema.

{ enabled: boolean; lifetime: number; } = ProcessedCacheConfigSchema

Cache Configuration

Default

cacheConfig: { lifetime: '5m' }

boolean = ...

Cache Enabled

Default

true

number = ...

Cache Lifetime

{number}{unit} - e.g. ‘5m’ for 5 minutes or ‘1h’ for 1 hour

Default

'5m'

{ dateLocale: string; dateTimeFormat: DateTimeFormatOptions; } = ...

Locale specific settings

string = ...

Date Locale used for formatting dates

DateTimeFormatOptions = ...

DateTime Format Options

"All" | "Fatal" | "Error" | "Warning" | "Info" | "Debug" | "Trace" | "None" = ...

Set the LogLevel for Effect based code

StudioCMSPlugin[] = ...

Add Plugins to the StudioCMS

boolean = ...

Whether to show verbose output

Default

false

string

The resulting configuration file content as a string with the options embedded.


function buildVirtualModules(resolve: (...path: string[]) => string): {
ambientScripts: (items: string[]) => string;
astroComponentVirtual: (items: Record<string, string>) => string;
dynamicVirtual: (items: string[]) => string;
dynamicWithAstroVirtual: (__namedParameters: {
astroComponents: Record<string, string>;
dynamicExports: string[];
}) => string;
namedVirtual: (__namedParameters: {
exportDefault: boolean;
namedExport: string;
path: string;
}) => string;
}

Defined in: studiocms/packages/studiocms/src/virtuals/utils.ts:50^

Factory function to build utilities for generating virtual module code strings.

(…path: string[]) => string

A function that resolves a list of path segments into a string path.

{
ambientScripts: (items: string[]) => string;
astroComponentVirtual: (items: Record<string, string>) => string;
dynamicVirtual: (items: string[]) => string;
dynamicWithAstroVirtual: (__namedParameters: {
astroComponents: Record<string, string>;
dynamicExports: string[];
}) => string;
namedVirtual: (__namedParameters: {
exportDefault: boolean;
namedExport: string;
path: string;
}) => string;
}

An object containing utilities for generating virtual module code:

  • dynamicVirtual: Generates export statements for a list of module paths.
  • ambientScripts: Generates import statements for a list of module paths (for side effects).
  • namedVirtual: Generates code to re-export a named export (and optionally as default) from a module.
  • astroComponentVirtual: Generates export statements for Astro components with custom names.
  • dynamicWithAstroVirtual: Generates combined exports for dynamic modules and Astro components.
ambientScripts: (items: string[]) => string;

Generates import statements for a list of module paths (for side effects).

string[]

string

astroComponentVirtual: (items: Record<string, string>) => string;

Generates export statements for Astro components with custom names.

Record<string, string>

string

dynamicVirtual: (items: string[]) => string;

Generates export statements for a list of module paths.

string[]

string

dynamicWithAstroVirtual: (__namedParameters: {
astroComponents: Record<string, string>;
dynamicExports: string[];
}) => string;

Generates combined exports for dynamic modules and Astro components.

Record<string, string>

string[]

string

namedVirtual: (__namedParameters: {
exportDefault: boolean;
namedExport: string;
path: string;
}) => string;

Generates code to re-export a named export (and optionally as default) from a module.

boolean

string

string

string