UNPKG

aws-cdk-lib

Version:

Version 2 of the AWS Cloud Development Kit library

2 lines (1 loc) 4.43 kB
"use strict";var _a,_b,_c,_d;Object.defineProperty(exports,"__esModule",{value:!0}),exports.DockerIgnoreStrategy=exports.GitIgnoreStrategy=exports.GlobIgnoreStrategy=exports.IgnoreStrategy=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var path=()=>{var tmp=require("path");return path=()=>tmp,tmp},dockerignore_1=()=>{var tmp=require("@balena/dockerignore");return dockerignore_1=()=>tmp,tmp},ignore_1=()=>{var tmp=require("ignore");return ignore_1=()=>tmp,tmp},options_1=()=>{var tmp=require("./options");return options_1=()=>tmp,tmp},errors_1=()=>{var tmp=require("../errors");return errors_1=()=>tmp,tmp},minimatch=()=>{var tmp=require("minimatch");return minimatch=()=>tmp,tmp};class IgnoreStrategy{static glob(absoluteRootPath,patterns){return new GlobIgnoreStrategy(absoluteRootPath,patterns)}static git(absoluteRootPath,patterns){return new GitIgnoreStrategy(absoluteRootPath,patterns)}static docker(absoluteRootPath,patterns){return new DockerIgnoreStrategy(absoluteRootPath,patterns)}static fromCopyOptions(options,absoluteRootPath){try{jsiiDeprecationWarnings().aws_cdk_lib_CopyOptions(options)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.fromCopyOptions),error}const ignoreMode=options.ignoreMode||options_1().IgnoreMode.GLOB,exclude=options.exclude||[];switch(ignoreMode){case options_1().IgnoreMode.GLOB:return this.glob(absoluteRootPath,exclude);case options_1().IgnoreMode.GIT:return this.git(absoluteRootPath,exclude);case options_1().IgnoreMode.DOCKER:return this.docker(absoluteRootPath,exclude)}}}exports.IgnoreStrategy=IgnoreStrategy,_a=JSII_RTTI_SYMBOL_1,IgnoreStrategy[_a]={fqn:"aws-cdk-lib.IgnoreStrategy",version:"2.202.0"};class GlobIgnoreStrategy extends IgnoreStrategy{constructor(absoluteRootPath,patterns){if(super(),!path().isAbsolute(absoluteRootPath))throw new(errors_1()).UnscopedValidationError("GlobIgnoreStrategy expects an absolute file path");this.absoluteRootPath=absoluteRootPath,this.patterns=patterns}add(pattern){this.patterns.push(pattern)}ignores(absoluteFilePath){if(!path().isAbsolute(absoluteFilePath))throw new(errors_1()).UnscopedValidationError("GlobIgnoreStrategy.ignores() expects an absolute path");let relativePath=path().relative(this.absoluteRootPath,absoluteFilePath),excludeOutput=!1;for(const pattern of this.patterns){const negate=pattern.startsWith("!"),match=minimatch()(relativePath,pattern,{matchBase:!0,flipNegate:!0});!negate&&match&&(excludeOutput=!0),negate&&match&&(excludeOutput=!1)}return excludeOutput}}exports.GlobIgnoreStrategy=GlobIgnoreStrategy,_b=JSII_RTTI_SYMBOL_1,GlobIgnoreStrategy[_b]={fqn:"aws-cdk-lib.GlobIgnoreStrategy",version:"2.202.0"};class GitIgnoreStrategy extends IgnoreStrategy{constructor(absoluteRootPath,patterns){if(super(),!path().isAbsolute(absoluteRootPath))throw new(errors_1()).UnscopedValidationError("GitIgnoreStrategy expects an absolute file path");this.absoluteRootPath=absoluteRootPath,this.ignore=(0,ignore_1().default)().add(patterns)}add(pattern){this.ignore.add(pattern)}ignores(absoluteFilePath){if(!path().isAbsolute(absoluteFilePath))throw new(errors_1()).UnscopedValidationError("GitIgnoreStrategy.ignores() expects an absolute path");let relativePath=path().relative(this.absoluteRootPath,absoluteFilePath);return this.ignore.ignores(relativePath)}}exports.GitIgnoreStrategy=GitIgnoreStrategy,_c=JSII_RTTI_SYMBOL_1,GitIgnoreStrategy[_c]={fqn:"aws-cdk-lib.GitIgnoreStrategy",version:"2.202.0"};class DockerIgnoreStrategy extends IgnoreStrategy{constructor(absoluteRootPath,patterns){if(super(),!path().isAbsolute(absoluteRootPath))throw new(errors_1()).UnscopedValidationError("DockerIgnoreStrategy expects an absolute file path");this.absoluteRootPath=absoluteRootPath,this.ignore=(0,dockerignore_1().default)().add(patterns)}add(pattern){this.ignore.add(pattern)}ignores(absoluteFilePath){if(!path().isAbsolute(absoluteFilePath))throw new(errors_1()).UnscopedValidationError("DockerIgnoreStrategy.ignores() expects an absolute path");let relativePath=path().relative(this.absoluteRootPath,absoluteFilePath);return this.ignore.ignores(relativePath)}}exports.DockerIgnoreStrategy=DockerIgnoreStrategy,_d=JSII_RTTI_SYMBOL_1,DockerIgnoreStrategy[_d]={fqn:"aws-cdk-lib.DockerIgnoreStrategy",version:"2.202.0"};