本文整理匯總了TypeScript中webreed-core/lib/Environment.Environment.use方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Environment.use方法的具體用法?TypeScript Environment.use怎麽用?TypeScript Environment.use使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類webreed-core/lib/Environment.Environment
的用法示例。
在下文中一共展示了Environment.use方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: setupDefaultPlugins
function setupDefaultPlugins(env: Environment): void {
env
.use(setupBinaryMode)
.use(setupTextMode)
.use(setupStandardGenerator)
.use(setupTemplateTransformer)
.use(setupJsonHandler)
.use(setupYamlHandler)
.use(setupNunjucksTemplateEngine);
}
示例2: applyProjectConfigToEnvironment
export function applyProjectConfigToEnvironment(env: Environment, config: any): void {
if (!(env instanceof Environment)) {
throw new TypeError("argument 'env' must be a webreed environment");
}
validateProjectConfig(config);
if (config.baseUrl) {
env.baseUrl = config.baseUrl;
}
if (config.defaultGeneratorName) {
env.defaultGeneratorName = config.defaultGeneratorName;
}
if (config.defaultModeName) {
env.defaultModeName = config.defaultModeName;
}
if (config.hiddenUrlExtensions) {
env.hiddenUrlExtensions.clear();
for (let ext of config.hiddenUrlExtensions) {
env.hiddenUrlExtensions.add(ext);
}
}
if (config.hiddenUrlFileNames) {
env.hiddenUrlFileNames.clear();
for (let ext of config.hiddenUrlFileNames) {
env.hiddenUrlFileNames.add(ext);
}
}
if (config.paths) {
for (let pathName of Object.keys(config.paths)) {
env.setPath(pathName, config.paths[pathName]);
}
}
if (config.resourceTypes) {
for (let key of Object.keys(config.resourceTypes)) {
let resourceTypeConfig = config.resourceTypes[key] || {};
let resourceType = new ResourceType();
if (resourceTypeConfig.conversions) {
for (let targetKey of Object.keys(resourceTypeConfig.conversions)) {
resourceType.conversions[targetKey] = pluginContextFromConfigMany(
"transformer",
resourceTypeConfig.conversions[targetKey]
);
}
}
if (resourceTypeConfig.custom) {
Object.assign(resourceType.custom, resourceTypeConfig.custom);
}
if (resourceTypeConfig.encoding) {
resourceType.encoding = resourceTypeConfig.encoding;
}
if (resourceTypeConfig.parseFrontmatter) {
resourceType.parseFrontmatter = resourceTypeConfig.parseFrontmatter;
}
if (resourceTypeConfig.targetExtension) {
resourceType.targetExtension = resourceTypeConfig.targetExtension;
}
if (resourceTypeConfig.mode) {
resourceType.mode = resourceTypeConfig.mode;
}
if (resourceTypeConfig.handler) {
resourceType.handler = pluginContextFromConfig("name", resourceTypeConfig.handler);
}
if (resourceTypeConfig.generator) {
resourceType.generator = pluginContextFromConfig("name", resourceTypeConfig.generator);
}
if (resourceTypeConfig.process) {
resourceType.process = pluginContextFromConfigMany("transformer", resourceTypeConfig.process);
}
if (resourceTypeConfig.templateEngine) {
resourceType.templateEngine = pluginContextFromConfig("name", resourceTypeConfig.templateEngine);
}
env.resourceTypes.set(key, resourceType);
}
}
if (config.plugins) {
for (let plugin of config.plugins) {
let pluginModule = requirePlugin(env, plugin.package);
if (typeof pluginModule.default !== "function") {
let err = new Error(`Webreed plugin package '${plugin.package}' does not export a default setup function!`);
err["code"] = "WEBREED_PLUGIN_MISSING_SETUP_FUNCTION";
err["packageName"] = plugin.package;
throw err;
}
env.use(pluginModule.default, plugin.options);
}
}
}