'use strict'; var fs = require('fs'); var shell = require('shelljs'); var grunt = require('grunt'); var spawn = require('npm-run').spawn; var CSP_CSS_HEADER = '/* Include this file in your html if you are using the CSP mode. */\n\n'; const docsScriptFolder = 'scripts/docs.angularjs.org-firebase'; module.exports = { startKarma: function(config, singleRun, done) { var browsers = grunt.option('browsers'); var reporters = grunt.option('reporters'); var noColor = grunt.option('no-colors'); var port = grunt.option('port'); var p = spawn('karma', ['start', config, singleRun ? '--single-run=true' : '', reporters ? '--reporters=' + reporters : '', browsers ? '--browsers=' + browsers : '', noColor ? '--no-colors' : '', port ? '--port=' + port : '' ]); p.stdout.pipe(process.stdout); p.stderr.pipe(process.stderr); p.on('exit', function(code) { if (code !== 0) grunt.fail.warn('Karma test(s) failed. Exit code: ' + code); done(); }); }, updateWebdriver: function(done) { if (process.env.CI) { // Skip the webdriver-manager update on CI, since the browsers will // be provided remotely. done(); return; } var p = spawn('webdriver-manager', ['update']); p.stdout.pipe(process.stdout); p.stderr.pipe(process.stderr); p.on('exit', function(code) { if (code !== 0) grunt.fail.warn('Webdriver failed to update'); done(); }); }, startProtractor: function(config, done) { var sauceUser = grunt.option('sauceUser'); var sauceKey = grunt.option('sauceKey'); var tunnelIdentifier = grunt.option('capabilities.tunnel-identifier'); var sauceBuild = grunt.option('capabilities.build'); var browser = grunt.option('browser'); var specs = grunt.option('specs'); var args = [config]; if (sauceUser) args.push('--sauceUser=' + sauceUser); if (sauceKey) args.push('--sauceKey=' + sauceKey); if (tunnelIdentifier) args.push('--capabilities.tunnel-identifier=' + tunnelIdentifier); if (sauceBuild) args.push('--capabilities.build=' + sauceBuild); if (specs) args.push('--specs=' + specs); if (browser) { args.push('--browser=' + browser); } var p = spawn('protractor', args); p.stdout.pipe(process.stdout); p.stderr.pipe(process.stderr); p.on('exit', function(code) { if (code !== 0) grunt.fail.warn('Protractor test(s) failed. Exit code: ' + code); done(); }); }, wrap(src, name) { return [`src/${name}.prefix`, ...src, `src/${name}.suffix`]; }, addStyle: function(src, styles, minify) { styles = styles.reduce(processCSS.bind(this), { js: [src], css: [] }); return { js: styles.js.join('\n'), css: styles.css.join('\n') }; function processCSS(state, file) { var css = fs.readFileSync(file).toString(), js; state.css.push(css); if (minify) { css = css .replace(/\r?\n/g, '') .replace(/\/\*.*?\*\//g, '') .replace(/:\s+/g, ':') .replace(/\s*\{\s*/g, '{') .replace(/\s*\}\s*/g, '}') .replace(/\s*,\s*/g, ',') .replace(/\s*;\s*/g, ';'); } //escape for js css = css .replace(/\\/g, '\\\\') .replace(/'/g, '\\\'') .replace(/\r?\n/g, '\\n'); js = '!window.angular.$$csp().noInlineStyle && window.angular.element(document.head).prepend(window.angular.element(\'