Exemple #1
0
        function(source, itemCallback) {
            if (getit.isRemote(source)) {
                processor.out('!{grey}loading: !{underline}{0}', source);
            }
            
            getit(source, { cwd: processor.basePath }, function(err, data) {
                if (! err) {
                    var parser = new Parser(processor, source, data.split(/\n/));
                    
                    parser.on('item', function(item) {
                        debug('found item: ', item);
                        processor.items.push(item);
                    });
                    
                    parser.on('end', itemCallback);
                    parser.on('error', itemCallback);

                    processor.out('!{grey}parsing: !{underline}{0}', source);
                    parser.process();
                }
                else {
                    itemCallback(err);
                }
            });
            
        },
Exemple #2
0
module.exports = function(processor, input, callback) {
  // split the fields on spaces
  var fields = (input || '').split(/\s/);
  var extensionMatch;
  var extension;
  var content;
      
  if (fields.length > 0) {
    // TODO: check to see if a line range was requested
    
    extensionMatch = reExtension.exec(fields[0]);
    extension = (extensionMatch ? extensionMatch[1] || 'js' : 'js').toLowerCase();
    content = '<pre><code>' + fields[0] + ' not found</code></pre>';
    
    getit(fields[0], processor._getitOpts(), function(err, data) {
      if (! err) {
        // require hljs for the appropriate language and style
        var language = processor.highlight(extension, fields[1]);

        // wrap the content in a pre code block
        content = '<pre><code class="' + language + '">' + data + '</pre></code>';
      }

      // TODO: include highlight js library in the base of the doc
      callback(null, content);
    });
  }
};
Exemple #3
0
 function(item, itemCallback) {
     getit(item.include, opts, function(err, data) {
         if (! err) {
             processor[item.key] = data;
         }
         
         itemCallback(err);
     });
 },
Exemple #4
0
 function(item, dlCallback) {
     getit(item, getItOpts, function(err, data) {
         if (err) {
             err = new Error('Unable to download: ' + recipe.name + ', could not resolve include: ' + item);
         }
         
         dlCallback(err, data);
     });
 },
 rigger.process('//=shim Array.indexOf', function(err, output) {
     assert.ifError(err);
     
     getit('github://buildjs/shims/array/indexof.js', function(err, reference) {
         assert.ifError(err, 'Could not retrieve reference sample from github');
         assert.equal(output, reference);
         
         done();
     });
 });
Exemple #6
0
Processor.prototype.processItems = function(callback) {
    var processor = this,
        targetFile = this.template.basePath + '/' + this.template.templateFile;
    
    this.out('!{grey}loading: !{underline}{0}', targetFile);
    getit(targetFile, function(err, content) {
        if (! err) {
            var data = _.extend({}, processor.template, processor);
            
            processor.output = handlebars.compile(content)(data);
        }
        
        callback(err);
    });
};
Exemple #7
0
exports = module.exports = function(opts) {
    var datapath = opts.bakery,
        promises = [], target;
        
    function extractEntry(entry) {
        var realPath = path.join(datapath, entry.path.replace(reLibrary, '$1')),
            deferred = when.defer(), writer;
        
        // create the directory, synchronous feels dirty but oh well...
        mkdirp.sync(path.dirname(realPath));
        
        // create the writer
        writer = fstream.Writer({ path: realPath });
        
        // pipe the entry to the file
        entry
            .on('end', deferred.resolve.bind(deferred))
            .pipe(writer);
        
        return deferred;
    }
    
    // ensure we have options
    opts = opts || {};
    opts.repository = opts.repository || 'buildjs';
    
    // initialise the target
    target = 'https://github.com/' + opts.repository + '/parts/tarball/master';
    
    out('!{grey}retrieving recipes from !{grey,underline}{0}', target);
    getit(target)
        .on('end', out.bind(null, '!{grey}extracting recipes'))
        .pipe(zlib.Gunzip())
        .pipe(tar.Parse({ path: opts.bakery }))
        .on('entry', function(entry) {
            if (reLibrary.test(entry.path) && entry.type == 'File') {
                promises.push(extractEntry(entry));
            }
        })
        .on('end', function() {
            when.all(promises, function() {
                out('!{check,green} done');
                if (callback) {
                    callback();
                }
            });
        });
};
Exemple #8
0
    function(callback) {
      getit(scaffoldPath + 'index.json', opts, function(err, data) {
        var targetFile;
        var template;

        if (err) {
          return callback(err);
        }

        targetFile = path.join(
          opts.path,
          path.basename(opts.filename || 'index', '.json') + '.json'
        );

        // compile the template
        template = handlebars.compile(data);

        // write the file to the output path
        fs.writeFile(targetFile, template(opts), 'utf8', callback);
      });
    },
                mkdirp(path.dirname(outputFile), function(err) {
                    if (! err) {
                        var stream = getit(match[3], processor._getitOpts());
                        
                        debug('attempting to download: ' + match[3]);
                        downloader.emit('start', match[3], outputFile);

                        stream.pipe(fs.createWriteStream(outputFile));
                        stream.on('end', function() {
                            debug('finished download of: ' + match[3]);
                            downloader.emit('done', match[3], outputFile);
                            ok();
                        });
                        
                        stream.on('error', function(err) {
                            callback(new Error('Unable to download: ' + match[3]));
                        });
                    }
                    else {
                        callback(err);
                    }
                });
Exemple #10
0
        function(item, itemCallback) {
            var index = itemCount++;

            if (item) {
                reporter('<= {0}: \t!{underline}{1}', recipe.name, item);

                // get the item and check the cache directory
                getit(item, getItOpts, function(err, data) {
                    results[index] = data;

                    // if we have received an error, then make it meaningful
                    if (err) {
                        err = new Error('Unable to fetch recipe "' + recipe.name + '" contents');
                    }

                    itemCallback(err);
                });
            }
            else {
                itemCallback();
            }
        },
Exemple #11
0
Processor.prototype.loadTemplate = function(callback) {
    var processor = this;
    
    if (this.templateFile) {
        var isRemote = getit.isRemote(this.templateFile),
            templateFile = (this.templateFile || '').replace(rePackageJson, '') + '/template.json',
            templateBase = isRemote ? 
                this.templateFile.replace(reTrailingSlash) : 
                path.resolve(this.basePath, this.templateFile);
            
        // load the template definition
        this.out('!{grey}loading: !{underline}{0}', templateFile);
        getit(templateFile, { cwd: this.basePath }, function(err, data) {
            if (! err) {
                try {
                    // parse the data from the template
                    var templateOpts = JSON.parse(data);
                    
                    // set the template base path and output directory
                    templateOpts.basePath = templateBase;
                    
                    // create the template
                    processor.template = new Template(templateOpts);
                    processor.template.downloader = new Downloader(processor, templateOpts);
                }
                catch (e) {
                    err = new Error('Unable to parse template.json definition');
                }
            }

            if (callback) {
                callback(err);
            }
        });
    }
};