Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/*
* grunt-docs
* https://github.com/shama/grunt-docs
*
* Copyright (c) 2013 Kyle Robinson Young
* Licensed under the MIT license.
*/
'use strict';
var grunt = require('grunt');
var docpad = require('docpad');
var path = require('path');
var _ = grunt.util._;
var async = grunt.util.async;
var docs = module.exports = {};
// Guesses a destination given patterns
docs.guessBasePath = function(file, patterns) {
var out = false;
patterns.forEach(function(pattern) {
var base = docs.findBase(pattern);
file = path.normalize(file);
if (file.substr(0, base.length) === base) {
out = file.replace(base, '');
}
});
return docs.resolveExt(out || path.basename(file));
};
if (!task) {
throw new Error('Please specify a task');
}
options = options || {};
// CWD to spawn
var cwd = options.base || options.cwd || process.cwd();
delete options.cwd;
// get next/kill process trigger
var trigger = options.trigger || false;
delete options.trigger;
// turn options into spawn options
var spawnOptions = [process.argv[1]];
grunt.util._.each(options, function(val, key) {
spawnOptions.push('--' + key);
spawnOptions.push(val);
});
spawnOptions.push(task);
// Return an interface for testing this task
return function(runs, done) {
var spawnGrunt = spawn(process.argv[0], spawnOptions, {cwd:cwd});
var out = '';
if (!grunt.util._.isArray(runs)) {
runs = [runs];
}
// Append a last function to kill spawnGrunt
runs.push(function() { spawnGrunt.kill('SIGINT'); });
return new Promise((resolve, reject) => {
grunt.util.spawn({
cmd: 'node',
args: args
}, (error, result, code) => {
var ret: ICompileResult = {
code: code,
// New TypeScript compiler uses stdout for user code errors. Old one used stderr.
output: result.stdout || result.stderr
};
resolve(ret);
});
});
}
Compiler.prototype.compileTemplates = function(files) {
var js = '', _this = this;
// RequireJS
if(!this.opt.requirejs && !this.opt.node) {
if(this.opt.variable.indexOf('.') !== -1) {
js += this.opt.variable + ' = (function(){' + grunt.util.linefeed;
} else {
js += 'var ' + this.opt.variable + ' = (function(){' + grunt.util.linefeed;
}
}
if(this.opt.requirejs && !this.opt.node) {
js += 'if(typeof define !== \'function\') {' + grunt.util.linefeed;
js += ' define = require(\'amdefine\')(module);' + grunt.util.linefeed;
js += '}' + grunt.util.linefeed;
}
if(this.opt.requirejs) {
js += 'define(function() {' + grunt.util.linefeed;
}
// Defining encodeHTML method for the templates
js += 'function encodeHTMLSource() {';
js += ' var encodeHTMLRules = { "&": "&", "<": "<", ">": ">", \'"\': \'"\', "\'": \''\', "/": \'/\' },';
var grunt = require('grunt');
var yaml = require('libyaml');
var hashFile = require('../tasks/lib/common').hashFile;
var s3 = require('../tasks/lib/s3').init(grunt);
var _ = grunt.util._;
var async = grunt.util.async;
var s3Config = grunt.config("s3"),
config = _.extend({}, s3Config.options, s3Config.test.options);
module.exports = {
testUpload : function (test) {
test.expect(2);
async.waterfall([
function (cb) {
var src = __dirname + '/files/a.txt';
var dest = __dirname + '/../s3/127/a.txt/.fakes3_metadataFFF/content';
s3.upload(src, 'a.txt', config)
.done(function () {
setupAndRun: function (fixture, before, done) {
if (!done) {
done = before;
before = function (repo, cb) { cb(); };
}
grunt.file.mkdir('tmp');
var repo = new Repo('tmp/' + fixture);
grunt.file.mkdir(repo.path);
grunt.file.copy('test/fixtures/' + fixture + '.js', repo.path + '/Gruntfile.js');
grunt.util.async.series([
u.genCommand(repo.path, 'git', ['init']),
u.genCommand(repo.path, 'git', ['add', '.']),
u.genCommand(repo.path, 'git', ['commit', '-m', 'Initial commit']),
function (cb) {
repo.initialRef = grunt.file.read(repo.path + '/.git/refs/heads/master').trim();
cb();
},
function (cb) { before(repo, cb); },
u.genCommand(repo.path, 'grunt'),
function (cb) {
repo.currentRef = grunt.file.read(repo.path + '/.git/refs/heads/master').trim();
cb();
},
], function (err) {
done(err, repo);
});
var _ = require('grunt').util._;
var files = {
grunt: 'Gruntfile.js',
source: [
'src/js/helper.module.js',
'src/js/!(helper.module)*.js'
],
sourceStyle: [
'src/less/style.less'
],
distStyle: 'dist/<%= pkg.name %>.css',
distStyleMin: 'dist/<%= pkg.name %>.min.css',
dist: 'dist/<%= pkg.name %>.js',
distMin: 'dist/<%= pkg.name %>.min.js',
dists: 'dist/*',
build: function(config, fn){
var files = grunt.file.expand(config.src);
var styles = config.styles;
//concat
var src = files.map(function(filepath){
return grunt.file.read(filepath);
}).join(grunt.util.normalizelf('\n'));
//process
var processed = this.process(src, grunt.config('NG_VERSION'), config.strict);
if (styles) processed = this.addStyle(processed, styles.css, styles.minify);
//write
grunt.file.write(config.dest, processed);
grunt.log.ok('File ' + config.dest + ' created.');
fn();
},
/*global require:true, process:true, phantomjs:true, __dirname:true*/
var grunt = require('grunt'),
path = require('path'),
_ = grunt.util._;
var HtmlInspector = function HtmlInspector(task, phantomjs) {
this.setOptions(task);
this.filesSrc = task.filesSrc;
this.async = task.async;
this.phantomjs = phantomjs;
};
_.extend(HtmlInspector.prototype, (function () {
'use strict';
/*jshint validthis:true */
var isPass = true;
function onComplete(errors) {
var i = 0,
var gitAddDel = {
cmd: 'git',
args: ['add', '-u'],
opts: opts,
};
var gitCommit = {
cmd: 'git',
args: ['commit', '-m', commitMsg],
opts: opts,
};
var gitTag = {
cmd: 'git',
args: ['tag', tag],
opts: opts,
};
grunt.util.spawn(gitAddAll, function() {
grunt.util.spawn(gitAddDel, function() {
grunt.util.spawn(gitCommit, function() {
if (tag) {
grunt.util.spawn(gitTag, cb);
} else {
cb();
}
});
});
});
}