Example #1
0
    testFoxxDirectories : function () {
      var appPath = fs.join(FoxxService._appPath, ".."); 

      assertTrue(fs.isDirectory(fs.join(appPath, "UnitTestsRecovery1")));
      assertTrue(fs.isFile(fs.join(appPath, "UnitTestsRecovery1", "foo.json")));

      assertTrue(fs.isDirectory(fs.join(appPath, "UnitTestsRecovery2")));
      assertFalse(fs.isFile(fs.join(appPath, "UnitTestsRecovery2", "bar.json")));
    }
Example #2
0
exports.get_configs = function(key, default_value){
    if ( typeof default_value === 'undefined' )
        default_value = null;

    var path = exports.get_config_file_path(key);
    if (!path || !_fs.isDirectory(path)) {
        return default_value;
    }

    var result = {}

    try {
        var files = _fs.readdirSync(path);
        files.forEach(function(file_name){
            var file_path = _path.join(path, file_name);
            if (_fs.isFile(file_path)){
                result[file_name] = get_config(_path.join(key, file_name));
            }
        });

    } catch (err) {
        console.error(err);
    }
    return result;
};
  page.onCallback = function (message) {
    var result,
        failed;

    if (message) {
      if (message.name === 'QUnit.done') {
        result = message.data;
        failed = !result || !result.total || result.failed;

        if (!result.total) {
          console.error('No tests were executed. Are you loading tests asynchronously?');
        }

        exit(failed ? 1 : 0);

        // EXPERIMENTAL: if there is a istanbul coverage report
        // write it out into coverage/coverage.json
        var coverage = page.evaluate(function() {
          return window.__coverage__;
        });
        if (coverage) {
          var pFs = require('fs');
          var reportFolder = 'coverage';
          if (!pFs.exists(reportFolder)) {
            pFs.makeDirectory(reportFolder);
          } else if (!pFs.isDirectory(reportFolder)) {
            throw new Error('Location for coverage report is not a folder.');
          }
          pFs.write(reportFolder + '/coverage.json', JSON.stringify(coverage), 'w');
        }
      }
    }
  };
Example #4
0
HttpServer.prototype.serveStatic = function(mountpoint, directory, options) {
    if (typeof(mountpoint) !== "string") {
        throw new Error("Missing mountpoint argument");
    }
    if (typeof(directory) !== "string") {
        throw new Error("Missing directory argument");
    } else if (!fs.exists(directory) || !fs.isDirectory(directory)) {
        throw new Error("Directory '" + directory + "' doesn't exist or is not a directory");
    }
    options || (options = {});
    const initParameters = {
        "acceptRanges": options.acceptRanges === true,
        "dirAllowed": options.allowDirectoryListing === true,
        "gzip": options.gzip === true,
        "stylesheet": options.stylesheet || null,
        "etags": options.etags !== false,
        "maxCacheSize": options.maxCacheSize || 0,
        "maxCachedFileSize": options.maxCachedFileSize || 0,
        "maxCachedFiles": options.maxCachedFiles || 0,
        "cacheControl": options.cacheControl || null,
        "otherGzipFileExtensions": options.gzipExtensions || null
    };
    const parentContainer = this.getContextHandlerCollection();
    const context = new StaticContext(parentContainer, mountpoint, {
            "security": options.security === true,
            "sessions": options.sessions === true,
            "virtualHosts": options.virtualHosts
        });
    context.serve(directory, initParameters);
    return this.addContext(context);
};
Example #5
0
 Array.prototype.forEach.call(files, function (file) {
     if (fs.isDirectory(file) && fs.exists(file + "/scrape.json")) {
         casper.then(function () {
             casper.loadScrape(file);
         });
     }
 });
Example #6
0
/**
*Returns all the files paths in a directory
*@param {string} directory The directory path
*@param {Object=} options Options (optional): exclude (an array of dir paths) , extension (a String)
*/
function getFiles(directory, options){
    var i;
    if(options && options.excludeDirs){
        for(i = 0; i < options.excludeDirs.length; i++){
            if(directory === options.excludeDirs[i]){
                return [];
            }
        }
    }
    var stuff = fs.list(directory);
    var files = [];
    var directories = [];
    for(i = 2; i< stuff.length; i++){//starts at 2 to skip "." and ".."
        
        var path = directory + fs.separator + stuff[i];
        if(fs.isFile(path) &&
            (!options || !options.extension || fileHasExtension(stuff[i], options.extension)) &&
            (!options || !options.excludeFiles || notInArray(stuff[i], options.excludeFiles))) {
            files.push(path);
        }
        
        if(fs.isDirectory(path)){
            directories.push(path);
        }
    }   
    for(i = 0; i < directories.length; i++){
        var files = files.concat(getFiles(directories[i], options));
    }
    return files;
}
Example #7
0
function findTests(currentDir){
    if (!currentDir) {
        return [];
    }

    var fs = require('fs');
    var testsWithinFolder = fs.list(currentDir);

    var modules = [];

    for (var index = 0; index < testsWithinFolder.length; index++) {
        var directoryContent = testsWithinFolder[index];

        if ('.' === directoryContent || '..' === directoryContent) {
            continue;
        }

        if (fs.isDirectory(currentDir + directoryContent)) {

            var subDir = currentDir + directoryContent + '/';
            modules    = modules.concat(findTests(subDir));

        } else if (isTestFile(directoryContent)) {

            modules.push(currentDir + (directoryContent));
        }
    }

    return modules;
}
Example #8
0
var moveAppToServer = function(serviceInfo) {
  if (! fs.exists(serviceInfo)) {
    throwFileNotFound("Cannot find file: " + serviceInfo + ".");
  }
  var filePath;
  var shouldDelete = false;
  if (fs.isDirectory(serviceInfo)) {
    filePath = utils.zipDirectory(serviceInfo);
    shouldDelete = true;
  }
  if (fs.isFile(serviceInfo)) {
    filePath = serviceInfo;
  }
  if (!filePath) {
    throwBadParameter("Invalid file: " + serviceInfo + ". Has to be a direcotry or zip archive");
  }
  var response = arango.SEND_FILE("/_api/upload", filePath);
  if (shouldDelete) {
    try {
      fs.remove(filePath);
    }
    catch (err2) {
      arangodb.printf("Cannot remove temporary file '%s'\n", filePath);
    }
  }
  if (! response.filename) {
    throw new ArangoError({
      errorNum: errors.ERROR_SERVICE_UPLOAD_FAILED.code,
      errorMessage: errors.ERROR_SERVICE_UPLOAD_FAILED.message
                  + ": " + String(response.errorMessage)
    });
  }
  return response.filename;
};
Example #9
0
var zipDirectory = function(directory) {
  "use strict";
  if (!fs.isDirectory(directory)) {
    throw directory + " is not a directory.";
  }
  var tempFile = fs.getTempFile("zip", false);

  var tree = fs.listTree(directory);
  var files = [];
  var i;
  var filename;

  for (i = 0;  i < tree.length;  ++i) {
    filename = fs.join(directory, tree[i]);

    if (fs.isFile(filename)) {
      files.push(tree[i]);
    }
  }
  if (files.length === 0) {
    throwFileNotFound("Directory '" + String(directory) + "' is empty");
  }
  fs.zipFile(tempFile, directory, files);
  return tempFile;
};
function getDiffs (path){

        var filePath;

        if(({'..':1,'.':1})[path]){ return true; }

        if(_realPath){
                _realPath += fs.separator + path;
        } else {
                _realPath = path;
        }

        filePath = _realPath;

        if(fs.isDirectory(_realPath) ){
                fs.list(_realPath).forEach(getDiffs);
        } else {
                if( /\.diff\./.test(path.toLowerCase()) ){
                        if(_test_match){
                                if( _test_match.test(_realPath.toLowerCase()) ){
                                        if( !(_test_exclude && _test_exclude.test(_realPath.toLowerCase())) ){
                                                console.log('Analysing', _realPath);
                                                _diffsToProcess.push(filePath);
                                        }
                                }
                        } else {
                                if( !(_test_exclude && _test_exclude.test(_realPath.toLowerCase())) ){
                                        _diffsToProcess.push(filePath);
                                }
                        }
                }
        }

        _realPath = _realPath.replace(fs.separator + path, '');
}
Example #11
0
    apps.forEach(function (appName) {
      var mount = systemMountPoint(appName);

      // for all unknown system apps: check that the directory actually exists
      if (! mount && ! fs.isDirectory(fs.join(systemAppPath, appName))) {
        return;
      }

      try {
        if (! mount) {
          mount = '/_system/' + appName;
        }

        var found = aal.firstExample({ type: "mount", mount: mount });

        if (found === null) {
          exports.mount(appName, mount, {reload: false});

          var doc = mountFromId(mount);
          var app = appFromAppId(doc.app);

          setupApp(app, mount, doc.options.collectionPrefix);
        }
      }
      catch (err) {
        console.error("unable to mount system application '%s': %s", appName, String(err));
      }
    });
Example #12
0
	function fileNameGetter( root, fileName ) {
		var diffDir, origFile, diffFile;

		var increment = count ? '.' + count : '';
		diffDir = root + '/' + currentFilename + '/' + currentDescribe;
		origFile = diffDir + '/' + currentWhen + increment + '.png';
		diffFile = diffDir + '/' + currentWhen + increment + '.diff.png';

		if ( !fs.isDirectory( diffDir ) ) {
			fs.makeDirectory( diffDir );
		}

		casper.emit( 'phantomcss.screenshot', {
			path: origFile.replace( visualTestsRoot, '' )
		} );

		if ( !fs.isFile( origFile ) ) {
			casper.test.info( "return origfile" );
			casper.test.info( "New screenshot created for " + currentWhen );
			return origFile;
		} else {
			casper.test.info( "return diffile" );
			return diffFile.replace( /\/\//g, '/' );
		}
	}
Example #13
0
  this.repackZipFile = function (path) {
    if (! fs.exists(path) || ! fs.isDirectory(path)) {
      throw "'" + String(path) + "' is not a directory";
    }

    var tree = fs.listTree(path);
    var files = [];
    var i;

    for (i = 0;  i < tree.length;  ++i) {
      var filename = fs.join(path, tree[i]);

      if (fs.isFile(filename)) {
        files.push(tree[i]);
      }
    }

    if (files.length === 0) {
      throw "Directory '" + String(path) + "' is empty";
    }

    var tempFile = fs.getTempFile("downloads", false);

    fs.zipFile(tempFile, path, files);

    return tempFile;
  };
Example #14
0
var modelFiles = fs.list(pageModelRoot).map(function(folder)
{
    var caseFolder = pageModelRoot + fs.separator + folder;
    if(fs.isDirectory(caseFolder) && caseFolder.indexOf(".") == -1 && caseFolder.indexOf("fullPages") == -1)
    {
        return (caseFolder + fs.separator + "index.json").replace("C:\\GitWebStorm\\", "http:\\\\localhost\\").replace(/\\/g, "/");
    }
}).filter(function(item){ return item != null; });
Example #15
0
 tests.forEach(function(test) {
     var testDir = fs.absolute(fs.dirname(test));
     if (fs.isDirectory(testDir)) {
         if (fs.exists(fs.pathJoin(testDir, '.casper'))) {
             isCasperTest = true;
         }
     }
 });
/*
  这种保存微博搜索信息的方法只适合演示对fs模块的使用,已经废弃!
 */
function saveTopicToFile(){
  var working_directory = args.output;
  if(fs.isAbsolute(working_directory)){
    if(fs.makeDirectory(working_directory) || fs.isDirectory(working_directory)){
      this.working_directory = working_directory;
      return this;
    }
  }else{
    var path = [fs.workingDirectory, working_directory].join(fs.separator);
    path = fs.absolute(path);
    if(fs.makeDirectory(path) || fs.isDirectory(path)){
      this.working_directory = path;
      return this;
    }
  }
  console.error(working_directory, ':this directory is unable to access or not exists.');
  return null;
}
Example #17
0
test(function () {
    fs.makeDirectory(TEST_DIR);
    this.add_cleanup(function () { fs.removeTree(TEST_DIR); });
    fs.write(TEST_FILE_PATH, TEST_CONTENT, "w");

    assert_is_true(fs.exists(TEST_FILE_PATH));
    assert_is_true(fs.exists(TEST_DIR));
    assert_is_false(fs.exists(ABSENT_FILE));
    assert_is_false(fs.exists(ABSENT_DIR));

    assert_is_true(fs.isDirectory(TEST_DIR));
    assert_is_false(fs.isDirectory(ABSENT_DIR));


    assert_is_true(fs.isFile(TEST_FILE_PATH));
    assert_is_false(fs.isFile(ABSENT_FILE));

    var absPath = fs.absolute(TEST_FILE_PATH);
    assert_is_false(fs.isAbsolute(TEST_FILE_PATH));
    assert_is_true(fs.isAbsolute(absPath));

    assert_is_true(fs.isReadable(TEST_FILE_PATH));
    assert_is_true(fs.isWritable(TEST_FILE_PATH));
    assert_is_false(fs.isExecutable(TEST_FILE_PATH));

    assert_is_false(fs.isReadable(ABSENT_FILE));
    assert_is_false(fs.isWritable(ABSENT_FILE));
    assert_is_false(fs.isExecutable(ABSENT_FILE));

    assert_is_true(fs.isReadable(TEST_DIR));
    assert_is_true(fs.isWritable(TEST_DIR));
    assert_is_true(fs.isExecutable(TEST_DIR));

    assert_is_false(fs.isReadable(ABSENT_DIR));
    assert_is_false(fs.isWritable(ABSENT_DIR));
    assert_is_false(fs.isExecutable(ABSENT_DIR));

    assert_is_false(fs.isLink(TEST_DIR));
    assert_is_false(fs.isLink(TEST_FILE_PATH));
    assert_is_false(fs.isLink(ABSENT_DIR));
    assert_is_false(fs.isLink(ABSENT_FILE));

}, "file types and access modes");
Example #18
0
function getProcessedFilePath(fileName) {
    var dirsBase = app.runner.suite.baseDirectory,
        processedScreenshotDir = path.join(options['store-in-ui-tests-repo'] ? uiTestsDir : dirsBase, config.processedScreenshotsDir);

    if (!fs.isDirectory(processedScreenshotDir)) {
        fs.makeTree(processedScreenshotDir);
    }

    return path.join(processedScreenshotDir, fileName);
}
Example #19
0
 fs.list(path).forEach(function(entry) {
   if (entry !== '.' && entry !== '..') {
     entry = path + fs.separator + entry;
     if (fs.isDirectory(entry)) {
       files.push.apply(files, findFiles(entry, re));
     } else if (entry.match(re)) {
       files.push(entry);
     }
   }
 });
Example #20
0
 Array.prototype.forEach.call(arguments, function(path) {
     if (!fs.exists(path)) {
         self.bar(f("Path %s doesn't exist", path), "RED_BAR");
     }
     if (fs.isDirectory(path)) {
         testFiles = testFiles.concat(self.findTestFiles(path));
     } else if (fs.isFile(path)) {
         testFiles.push(path);
     }
 });
Example #21
0
var CacheManager = exports.CacheManager = function(directoryOrFile) {
   var pkg = Packages.net.sf.ehcache;

   // the wrapped cache manager
   var manager;

   if (fs.isFile(directoryOrFile) === true) {
      // directoryOrFile is a file
      manager = new pkg.CacheManager(directoryOrFile);
   } else {
      // directoryOrFile is a directory
      if (fs.isDirectory(directoryOrFile) === false) {
         // try creating the directory if it does not exist
         if (fs.makeTree(directoryOrFile) === false) {
            throw new Error('Path is neither a creatable directory nor a file.');
         }
      }
      // disk store configuration
      var diskStoreConfig = new pkg.config.DiskStoreConfiguration();
      diskStoreConfig.setPath(fs.absolute(directoryOrFile));

      // default cache configuration
      var cacheConfig = new pkg.config.CacheConfiguration();
      cacheConfig.setOverflowToDisk(true);
      cacheConfig.setMemoryStoreEvictionPolicy(pkg.store.MemoryStoreEvictionPolicy.LRU);
      cacheConfig.setMaxElementsOnDisk(10000);
      cacheConfig.setMaxElementsInMemory(2000);
      cacheConfig.setEternal(true);
      cacheConfig.setDiskSpoolBufferSizeMB(20);
      cacheConfig.setDiskPersistent(true);
      cacheConfig.setStatistics(true);

      // cache manager configuration
      var config = new pkg.config.Configuration();
      config.addDefaultCache(cacheConfig);
      config.addDiskStore(diskStoreConfig);

      manager = new pkg.CacheManager(config);
   }

   /**
    * Returns the wrapped cache manager
    * @returns The wrapped cache manager
    * @type Packages.net.sf.ehcache.CacheManager
    */
   this.getCacheManager = function() {
      return manager;
   };

   this.getCacheDirectory = function() {
      return fs.absolute(directoryOrFile);
   };

   return this;
};
Example #22
0
File: doc.js Project: earl/ringojs
/**
 * Create static documentation for a Repository.
 *
 *   ringo doc.js -s /home/foo/ringojs/modules/
 *
 * You can specify a human readable name for the module which will
 * be display in the documentation:
 *
 *   ringo doc.js -s /home/foo/ringojs/modules -n "Ringojs Modules"
 *
 * @param args
 */
function main(args) {

    /**
     * Print script help
     */
    function help() {
        print('Create JsDoc documentation for CommonJs modules.');
        print('Usage:');
        print('  ringo ' + script + ' -s [sourcepath]');
        print('Options:');
        print(parser.help());
        return;
    };

    var script = args.shift();
    var parser = new Parser();
    parser.addOption('s', 'source', 'repository', 'Path to repository');
    parser.addOption('d', 'directory', 'directory', 'Directory for output files (default: "out")');
    parser.addOption('n', 'name', 'name', 'Name of the Repository (default: auto generated from path)');
    parser.addOption('q', 'quiet', null, 'Do not output any messages.');
    parser.addOption('h', 'help', null, 'Print help message and exit');
    var opts = parser.parse(args);
    if (opts.help) {
        help();
        return;
    }
    if (!opts.source) {
        throw new Error('No source specified.');
    }

    var exportDirectory = join(opts.directory || './out/');
    var repository = {
        path: opts.source,
        name: opts.name || getRepositoryName(opts.source)
    };
    var quiet = opts.quiet || false;

    // check if export dir exists & is empty
    var dest = new Path(exportDirectory);
    if (dest.exists() && !dest.isDirectory()) {
        throw new Error(dest + ' exists but is not a directory.');
    } else if (dest.isDirectory() && dest.list().length > 0) {
        throw new Error('Directory ' + dest + ' exists but is not empty');
    }

    // figure out what type of doc we write, single module, multi repos
    // or single repo
    if (!isDirectory(repository.path)) {
        throw new Error('Invalid source specified. Must be directory.');
        return;
    }

    renderRepository(repository, exportDirectory, quiet);
    return;
};
Example #23
0
	casper.on('run.complete', function(){

		var suite;
		var describe;
		var when;
		var xmlReport = '';
		var count;
		var directory = xUnitOutputRoot; // set in start.js
		var writtenFiles = [];
		var xmlName;

		//fs.write('_report/result.json', JSON.stringify(report), 'w');

		if ( !fs.isDirectory(directory) ){
			fs.makeDirectory(directory);
		}

		for (suite in report){

			count = 0;

			for (describe in report[suite]){
				xmlReport += '<testsuite name="['+makeXmlSafe(suite)+'] '+makeXmlSafe(describe)+'" tests="'+figures[suite][describe].tests+'" failures="'+figures[suite][describe].failures+'">\n';

				for (when in report[suite][describe]){

					report[suite][describe][when].forEach(function(test){
						xmlReport +='  <testcase classname="'+makeXmlSafe(when)+'" name="'+ makeXmlSafe(test.msg)+'">';
						if(test.type === 'fail'){
							xmlReport += '\n    <failure type="fail">'+makeXmlSafe(test.reason)+'</failure>\n  ';
						}
						xmlReport += '</testcase>\n';
					});

				}
				xmlReport += '</testsuite>';

				if(shouldWrite(xmlReport, suite)){
					xmlName = directory + suite.split('/').pop()+'.' + (count++) + '.xml';
					fs.write(xmlName, xmlReport, 'w');
					writtenFiles.push(xmlName);
				}
				xmlReport = '';
			}
		}

		var filesList = filterFiles(writtenFiles);
		if(waitSeconds(function(){return filesList.length === writtenFiles.length;},10000)){
			console.log('XUNIT: '+writtenFiles.length+' reports have been written to ' + directory);
		} else {
			casper.warn('XUNIT: '+filesList.length+' reports have been found in '+directory+', expected '+writtenFiles.length +'.');
		}

	});
var coverageTypeFolderNames = fs.list(scenarioCoverageDataFolder).map(function(itemName)
{
    if(itemName == "." || itemName == "..") { return null; }

    var fullPath = scenarioCoverageDataFolder + itemName;

    if(fs.isDirectory(fullPath))
    {
        return itemName;
    }
}).filter(function(item){ return item != null; });
Example #25
0
                fs.list('../../samples/' + section + group).forEach(function (sample) {
                    var details;
                    if (/^[a-z0-9\-\,]+$/.test(sample) && fs.isDirectory('../../samples/' + section + group + sample + '/')) {
                        details = '../../samples/' + section + group + sample + '/demo.details';
                        details = fs.isFile(details) && fs.read(details);

                        if (!details || details.indexOf('requiresManualTesting: true') === -1) {
                            samples.push(section + group + sample);
                        }
                    }
                });
Example #26
0
function getProcessedFilePath(fileName) {
    var pathToUITests = options['store-in-ui-tests-repo'] ? uiTestsDir : app.runner.suite.baseDirectory;
    var processedScreenshotDir = path.join(pathToUITests, config.processedScreenshotsDir);

    if (!fs.isDirectory(processedScreenshotDir)) {
        fs.makeTree(processedScreenshotDir);
    }
    fileName = assumeFileIsImageIfNotSpecified(fileName);

    return path.join(processedScreenshotDir, fileName);
}
Example #27
0
		ls.forEach(function(entry) {
			/**
			 * README.md will be listed as an entry. That caused issue #409:
			 * SlimerJS raised: "Component returned failure code: 0x80520005 (NS_ERROR_FILE_DESTINATION_NOT_DIR) [nsILocalFile.isFile]"
			 *
			 * First check whether an entry is a directory, than check if it contains a module file
			 */
			if (fs.isDirectory(modulesDir + '/' + entry) && fs.isFile(modulesDir + '/' + entry + '/' + entry + '.js')) {
				modules.push(entry);
			}
		});
Example #28
0
var scanDirectory = function (path) {
    var fs = require('fs');
    if (fs.exists(path) && fs.isFile(path)) {
        console.log(path);
    } else if (fs.isDirectory(path)) {
        fs.list(path).forEach(function (e) {
            if ( e !== "." && e !== ".." ) {    //< Avoid loops
                scanDirectory(path + '/' + e);
            }
        });
    }
};
Example #29
0
exports.run = function () {
    if (fs.isDirectory("output")) {
        fs.list("output").forEach(function (path) {
            if (path != "." && path != "..") {
                fs.remove("output/" + path);
            }
        });
    } else {
        fs.makeDirectory("output");
    }
    run_example(0);
};
Example #30
0
    function startReport() {
        var rules = page.evaluate(function(width, height) {
            // Insert styles
            var rulesList = {},
                cssEl = document.createElement('style');

            cssEl.innerHTML = '.sm-viewport { position: absolute; top: '+height+'px; left: 0; width: '+width+'px; height: '+document.body.offsetHeight+'px; background: rgba(255,255,255,0.9); z-index: 10000; } '
                            + '.sm-critical { boz-sizing: border-box; background: rgba(255,0,0,0.2) !important; }';

            document.getElementsByTagName('head')[0].appendChild(cssEl);

            // Find elements visible within viewport
            var elements = document.body.getElementsByTagName('*');
            for (var i=0; i<elements.length; i++) {
                var el   = elements[i],
                    rect = el.getBoundingClientRect();

                if (rect.top <= window.innerHeight) {
                        var rules = window.getMatchedCSSRules(el) || [];
                        for(var r=0; r<rules.length; r++) {
                            var rule = rules[r];
                            rulesList[rule.parentStyleSheet.href] = rulesList[rule.parentStyleSheet.href] || {};
                            rulesList[rule.parentStyleSheet.href][rule.selectorText] = {
                                css: rule.cssText
                            };
                            //rulesList.push(rule);
                        }

                        el.className += ' sm-critical';
                };
            }

            // Highlight viewport
            var viewportEl = document.createElement('div');
            viewportEl.className = 'sm-viewport';
            document.body.appendChild(viewportEl);

            return rulesList;
        }, width, height);

        var pageSafeAddress = page.url.replace("http://","").replace(/\/$/,"").replace(/\//gi,"_");
        var outputDir = 'output/' + pageSafeAddress + "/";
        if (!fs.isDirectory(outputDir)) fs.makeDirectory(outputDir);

        outputFileName = pageSafeAddress + '.' + width + 'x' + height + '-' + page.startTime.toISOString() + '-' + 'abovethefold';

        generateCSS(rules,outputDir+outputFileName);

        page.render(outputDir+outputFileName+'.png');
        console.log("*******************\nFiles saved to:\n" + outputDir + outputFileName + ".{css,js}");
        phantom.exit();
    }