当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Environment.Environment类代码示例

本文整理汇总了TypeScript中webreed-core/lib/Environment.Environment的典型用法代码示例。如果您正苦于以下问题:TypeScript Environment类的具体用法?TypeScript Environment怎么用?TypeScript Environment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Environment类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: setupDefaultPlugins

function setupDefaultPlugins(env: Environment): void {
  env
    .use(setupBinaryMode)
    .use(setupTextMode)
    .use(setupStandardGenerator)
    .use(setupTemplateTransformer)
    .use(setupJsonHandler)
    .use(setupYamlHandler)
    .use(setupNunjucksTemplateEngine);
}
开发者ID:gitter-badger,项目名称:webreed,代码行数:10,代码来源:setup.ts

示例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);
    }
  }
}
开发者ID:webreed,项目名称:webreed,代码行数:98,代码来源:applyProjectConfigToEnvironment.ts

示例3: _initNunjucksEnvironment

  private _initNunjucksEnvironment(): void {
    let templateLoader = new nunjucks.FileSystemLoader();
    templateLoader.init([ this._env.resolvePath("templates") ], null);

    this._nunjucksEnvironment = new nunjucks.Environment(templateLoader, this._nunjucksOptions);
  }
开发者ID:webreed,项目名称:webreed-nunjucks-template-engine,代码行数:6,代码来源:NunjucksTemplateEngine.ts

示例4: require

 () => require(env.resolvePath("node_modules", packageName)),
开发者ID:webreed,项目名称:webreed,代码行数:1,代码来源:applyProjectConfigToEnvironment.ts


注:本文中的webreed-core/lib/Environment.Environment类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。