当前位置:K88软件开发文章中心编程工具Grunt → 文章内容

grunt.file

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-24 10:34:16

文件路径也是相对于当前路径的。grunt.file.expandMapping返回一个src-dest文件映射对象的数组。通过所指定的模式来匹配每一个源文件,然后将匹配的文件路径加入指定的dest中(dest存放匹配的文件路径)。这个文件路径会按照指定的选项加工或者重命名过。 查看grunt.file.expand方法文档可以了解如何指定patterns和optionsgrunt.file.expandMapping(patterns, dest [, options])注意:这个方法可以用于以编程的方式针对多任务的情况生成一个files数组,它会优先使用在配置任务指南中"动态构建文件对象"一节所描述的语法。除了支持那些grunt.file.expand方法之外,options对象还支持下面这些属性:var options = { // The directory from which patterns are matched. Any string specified as // cwd is effectively stripped from the beginning of all matched paths. cwd: String, // Remove the path component from all matched src files. The src file path // is still joined to the specified dest. flatten: Boolean, // Remove anything after (and including) either the first or last "." in the // destination path (indicated by options.extDot), then append this value. ext: String, // *Added in 0.4.3* // Indicates where the period demarcating the extension is located. Can take: // - 'first' (extension begins after the first period in the file name) // - 'last' (extension begins after the last period) // Default: 'first' extDot: String, // If specified, this function will be responsible for returning the final // dest filepath. By default, it joins dest and matchedSrcPath like so: rename: function(dest, matchedSrcPath, options) { return path.join(dest, matchedSrcPath); }};grunt.file.match针对一个或者多个文件路径来匹配一个或者多个匹配模式。返回一个特殊的数组,这个数组包含与指定的通配符模式任意匹配的所有文件路径。patterns和filepaths参数可以是一个单一的字符串或者也可以是一个字符串数组.如果匹配模式以!开头,就会从返回的数组从排除模式匹配的路径。模式会按指定的顺序进行处理,因此包含和排除文件的顺序是重要的。grunt.file.match([options, ] patterns, filepaths)options对象也支持minimatch库提供的所有选项。例如:如果options.matchBase为true,即使模式中不带斜线,这个模式也会匹配包含斜线的基本名称。例如:*.js模式将匹配path/to/file.js文件路径。grunt.file.isMatch这个方法与grunt.file.match方法包含同样的签名和逻辑,但是如果它匹配任意文件,就会简单的返回ture,否则返回false。判断文件类型grunt.file.exists检测给定的路径是否存在,返回boolean类型的值。和Node.js 中的 path.join 方法一样,此方法将所有参数连接在一起,并对结果做规范化。grunt.file.exists(path1 [, path2 [, ...]])grunt.file.isLink给定的路径是否是符号链接,返回boolean类型的值。和 Node.js 中的 path.join 方法一样,此方法此方法将所有参数连接在一起,并对结果做规范化。grunt.file.isLink(path1 [, path2 [, ...]])如果路径不存在则返回false。grunt.file.isDir指定的路径是否是一个目录?返回boolean类型的值。和 Node.js 中的 path.join 方法一样,此方法此方法将所有参数连接在一起,并对结果做规范化。grunt.file.isDir(path1 [, path2 [, ...]])如果路径不存在它也会返回false。grunt.file.isFile指定的路径是否是一个文件? 返回boolean类型的值。和 Node.js 中的 path.join 方法一样,此方法此方法将所有参数连接在一起,并对结果做规范化。grunt.file.isFile(path1 [, path2 [, ...]])如果路径不存在将返回false。路径grunt.file.isPathAbsolute指定的文件路径是否是绝对路径? 返回boolean类型的值。和 Node.js 中的 path.join 方法一样,此方法此方法将所有参数连接在一起,并对结果做规范化。grunt.file.isPathAbsolute(path1 [, path2 [, ...]])grunt.file.arePathsEquivalent所有给出的路径是否都是同一个路径?返回boolean类型的值。grunt.file.arePathsEquivalent(path1 [, path2 [, ...]])grunt.file.doesPathContain所有descendant路径是否全部包含在指定的ancestor路径中?返回boolean类型的值。注意:不需要检查路径是否真的存在。grunt.file.doesPathContain(ancestorPath, descendantPath1 [, descendantPath2 [, ...]])grunt.file.isPathCwd指定的文件路径是否是CWD?返回boolean类型的值。和 Node.js 中的 path.join 方法一样,此方法此方法将所有参数连接在一起,并对结果做规范化。grunt.file.isPathCwd(path1 [, path2 [, ...]])grunt.file.isPathInCwd指定的文件路径是否在在CWD中?注意:CWD不在CWD中 。返回boolean类型的值。和 Node.js 中的 path.join 方法一样,此方法此方法将所有参数连接在一起,并对结果做规范化。grunt.file.isPathInCwd(path1 [, path2 [, ...]])grunt.file.setBase改变Grunt的当前工作目录(CWD)。默认情况下,所有文件路径都是参照 Gruntfile 文件的相对路径。此函数和 --base 命令行参数的工作方式一致。grunt.file.setBase(path1 [, path2 [, ...]])和 Node.js 中的 path.join 方法一样,此方法此方法将所有参数连接在一起,并对结果做规范化。外部工具库不建议使用下面列出的所有外部工具库已经不再建议使用了。请使用 npm 管理项目中对第三方工具库的依赖。例如,如果你需要使用 Lo-Dash,首先通过 npm install lodash 安装,然后在 Gruntfile 文件中使用即可: var _ = require('lodash');grunt.file.glob不建议使用glob - File globbing utility.grunt.file.minimatch不建议使用minimatch - File pattern matching utility.grunt.file.findup不建议使用findup-sync - Search upwards for matching file patterns.

上一页  [1] [2] 


grunt.file