0

在 grunt 文档中有很多关于“warnOn”的例子:

exports.warnOn = 'grunt.js';        // Warn on a grunt.js file.
exports.warnOn = '*.js';            // Warn on any .js file.
exports.warnOn = '*';               // Warn on any non-dotfile or non-dotdir.
exports.warnOn = '.*';              // Warn on any dotfile or dotdir.
exports.warnOn = '{.*,*}';          // Warn on any file or dir (dot or non-dot).
exports.warnOn = '!*/**';           // Warn on any file (ignoring dirs).
exports.warnOn = '*.{png,gif,jpg}'; // Warn on any image file.

但是我只看到了一些示例,这些示例会在提示中提出或回答任何问题之前向您发出警告。只有当我创建的文件已经存在于项目中(或指定路径中)时,我才需要在填写答案后收到警告。就像是:

**Please answer the following:**
Project name: example

假设一个名为“example”的文件已经存在,我想在那时得到警告,以便我可以将名称更改为其他名称。我想它会是这样的:

warnOn = '{%= name %}';     // File being created already exists in project

但我不知道如何实现这一点,因此它只会在我输入值后发出警告。

希望这是有道理的,我很高兴澄清。

4

1 回答 1

2

不可能,因为warnOn检查只在提示之前完成。

但是它只是 Node.js,因此您可以轻松地自己实现检查:

if (grunt.file.expand(name).length) {
    grunt.warn('Existing files may be overwritten!');
}
于 2013-01-10T11:13:11.623 回答