How to use the file function from grunt
Find comprehensive JavaScript grunt.file code examples handpicked from public code repositorys.
51 52 53 54 55 56 57 58 59 60
BowerAssets.prototype = Object.create(Emitter.prototype); BowerAssets.prototype.constructor = BowerAssets; BowerAssets.prototype.get = function() { var bower = this.bower; var bowerConfig = grunt.file.readJSON(path.join(this.cwd, this.config)); var exportsOverride = bowerConfig.exportsOverride; var paths = bower.commands.list({paths: true}); paths.on('end', function(data) {
121
495
13
+ 15 other calls in file
21 22 23 24 25 26 27 28 29 30
function existsFileInOutput(filename) { return fs.existsSync(path.join(outputDirectory, filename)); } grunt.config.init({ pkg: grunt.file.readJSON(path.join(__dirname, 'fixtures', 'app', 'resources', 'app', 'package.json')), 'create-windows-installer': { config: { appDirectory: path.join(__dirname, 'fixtures', 'app'), outputDirectory: outputDirectory
104
392
21
10 11 12 13 14 15 16 17 18 19
// the exported value of the file's module. function loadConfig(path) { var object = {}; var key; grunt.file.expand({ cwd: path + '/' }, '*.{js,txt}').forEach(function(filename) { key = filename.replace(/\.[^.]+$/,''); if (filename.indexOf('.txt') >= 0) { object[key] = grunt.file.read(path + '/' + filename);
9
301
15
+ 23 other calls in file
23 24 25 26 27 28 29 30 31 32
initTasks(grunt, 'node_tasks') initConfigs(grunt, 'node_configs') } function initTasks(grunt, folderPath) { var pkg = grunt.file.readJSON('package.json') var tasks = pkg.devDependencies delete tasks.grunt for ( var task in tasks ) { grunt.loadNpmTasks(task)
1
3
3
+ 5 other calls in file
1 2 3 4 5 6 7 8 9 10
var grunt = require('grunt'); module.exports = { get: function() { replacements = []; _.mapObject( grunt.file.readJSON("package.json"), function( val, key ) { if ( !_.isObject(val) ){ replacements.push( { pattern: new RegExp( 'taskRunner_set_' + key, 'g'),
1
3
1
12 13 14 15 16 17 18 19 20 21
process.env.KARMA_BROWSERS = browsers; process.env.PROTRACTOR_BROWSERS = browsers; } Helpers.config = { pkg: grunt.file.readJSON('./package.json'), env: process.env }; Helpers.loadConfig = function(path) {
45
1
31
-1
module.exports = grunt.file.readJSON('package.json');
9
301
15
145 146 147 148 149 150 151 152 153 154
``` var grunt = require('grunt') // 配置 grunt.config.init({ pkg: grunt.file.readJSON('package.json'), // 这里会去获取版本号 'create-windows-installer': { x64: { authors: 'xiaobinwu <xiaobin_wu@yahoo.com>', // 作者 projectUrl: '',
68
268
8
27 28 29 30 31 32 33 34 35 36
}; var banner = (function () { var pkg = grunt.file.readJSON(path.join(__dirname, '..', '..', 'package.json')); var template = [ '/**!', ' This notice must be untouched at all times.', '',
3
0
5
GitHub: JulienCabanes/Pattern-Kit
0 1 2 3 4 5 6 7 8 9
var grunt = require('grunt'); // grunt.renameTask('http', 'http_pages'); // grunt.loadNpmTasks('grunt-http'); function getHttpPathsFromJSON(jsonPath) { var pages = grunt.file.readJSON(jsonPath), paths = {}; grunt.util._.forEach(pages, function(page, page_name) { paths[page_name] = {
1
2
3
140 141 142 143 144 145 146 147 148 149
delete expandOptions.src; delete expandOptions.dest; // Expand file mappings. if (obj.expand) { return grunt.file.expandMapping(obj.src, obj.dest, expandOptions).map(function(mapObj) { // Copy obj properties to result. var result = grunt.util._.extend({}, obj); // Make a clone of the orig obj available. result.orig = grunt.util._.extend({}, obj);
3
0
0
+ 11 other calls in file
60 61 62 63 64 65 66 67 68 69
tmp: '.tmp', //hostname: 'localhost' hostname: nconf.get('SERVER_HOSTNAME') }; var config = { pkg: grunt.file.readJSON('package.json'), env: process.env }; grunt.util._.extend(config, loadConfig('./tasks/options/'));
16
0
2
GitHub: jesseditson/Urza
25 26 27 28 29 30 31 32 33 34
program .command('build') .description('Builds the current urza app.') .action(function(type,info){ // set grunt's dir to the urza dir grunt.file.setBase(__dirname + '/..') setup() grunt.tasks(['build']) });
4
10
3
+ 3 other calls in file
GitHub: upstage/grunt-reverse
94 95 96 97 98 99 100 101 102 103
// Prettify HTML and add a separator between any sibling components. var result = Utils.format(components[i], Utils.sep(slug)); // Write the component to disk. grunt.file.write(path.join(dest, basename, slug + '.' + options.ext), result); } else { if (cb2) { cb2(null, true); }
2
4
7
+ 5 other calls in file
GitHub: Gerzer/waltz
96 97 98 99 100 101 102 103 104 105
return object1; }; var iterateThroughFiles = function(filename){ var relativePath = _this.data.src + '/' + filename; siteConfig = grunt.file.readJSON(relativePath); for (var domain in siteConfig) { siteConfig[domain].key = filename.split('.')[0]; }
37
0
2
+ 7 other calls in file
GitHub: yapplabs/glazier
117 118 119 120 121 122 123 124 125
function readChanges() { var json; try { json = grunt.file.readJSON('tmp/changes.json'); } catch(error) { json = {}; }
12
79
19
+ 3 other calls in file
GitHub: maxov/gulp-grunt
39 40 41 42 43 44 45 46 47 48
var opt = makeOptions(options); var oldCwd = process.cwd(); var cwd = opt.base != null ? opt.base : oldCwd; grunt.file.setBase(cwd); var gruntCliDir = opt.base ? (opt.base + "/") : ""; grunt.task.init([]);
22
167
4
GitHub: livedata/grunt-devcode
85 86 87 88 89 90 91 92 93
if ( obody != body ) { console.log ( 'Writing ', tfile ); grunt.file.write(tfile, body); } }); };
7
20
2
+ 3 other calls in file
GitHub: wacky6/grunt-fontmin
19 20 21 22 23 24 25 26 27
// prase options let opts = this.options() let data = this.data let destdir = opts.dest || './' let basedir = opts.basedir || './' let src = grunt.file.expand(data.src) let fonts = grunt.file.expand(join(basedir, this.target)) let getText = opts.getText!==undefined ? opts.getText : (content)=>html2text.fromString(content) let type='woff', typeOpts=true
1
2
2
+ 9 other calls in file
20 21 22 23 24 25 26 27 28 29
var findBowerJSON = function (BI) { var bowerJSON; grunt.util._.each(['bower.json', 'component.json'], function (configFile) { if (!helpers.is(bowerJSON, 'object') && grunt.file.isFile(configFile)) { bowerJSON = grunt.file.readJSON(configFile); if (configFile !== 'bower.json') { grunt.log.writeln(); grunt.log.warn(configFile.yellow + ' is deprecated.'.yellow);
87
0
1
+ 7 other calls in file
grunt.file is the most popular function in grunt (372 examples)