本文整理汇总了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);
}
}
}