Пример #1
0
 close: function() {
     return fs.closeSync(this.fd);
 },
Пример #2
0
  // Public: Create a temporary file with the provided code
  //
  // * `code`    A {String} containing some code
  //
  // Returns the {String} filepath of the new file
  createTempFileWithCode(code, extension = '') {
    try {
      if (!fs.existsSync(this.tempFilesDir)) {
        fs.mkdirSync(this.tempFilesDir);
      }

      const tempFilePath = this.tempFilesDir + path.sep + uuid.v1() + extension;

      const file = fs.openSync(tempFilePath, 'w');
      fs.writeSync(file, code);
      fs.closeSync(file);

      return tempFilePath;
    } catch (error) {
      throw new Error(`Error while creating temporary file (${error})`);
    }
  },

  // Public: Delete all temporary files and the directory created by
  // {GrammarUtils::createTempFileWithCode}
  deleteTempFiles() {
    try {
      if (fs.existsSync(this.tempFilesDir)) {
        const files = fs.readdirSync(this.tempFilesDir);
        if (files.length) {
          files.forEach(file => fs.unlinkSync(this.tempFilesDir + path.sep + file));
Пример #3
0
	function getArticlewashington(array){
      //console.log("i made it");
	  var j = 0;
	  var filedescriptor = [];
	  console.log(array);
	  while (j<array.length-1)
	  {
		var tmyfile = j.toString()+".txt";
		fd = fs.openSync("Articles/WASHINGTON/WASHINGTON_"+tmyfile, "w");
		fs.closeSync(fd);
		//console.log(myfile);
		request({
		  uri: array[j] + "?&tldrj=" + j,
		}, function(error, response, body) {
		
		  var $ = cheerio.load(body);
		  
		  var pathname = this.uri.query;
		  
		  //if blank, dont do anything
		  if(!pathname) return;
		  
		  var k = pathname.substring(pathname.indexOf("tldrj=") + 6);
		  
		  
		  k = parseInt(k);
          //console.log(k);
		
		//console.log(j);
		var myfile = k.toString()+".txt";
		//console.log(array[k]);
		//console.log(filedescriptor);
		fs.appendFile("Articles/WASHINGTON/WASHINGTON_"+myfile, array[k]+"\n", function (err) {});
	
		  //console.log("hey");
		  /*$("div div div div div img").each(function(element) {
			//console.log(myfile);
			var paragraph = $(this);
			var text = paragraph.attr("src")+"\n";
			//console.log(text);
			fs.appendFile("Articles/WASHINGTON/WASHINGTON_"+myfile, text, function (err) {});
		  });*/
		  $("#content #article-leaf-page div h1 .entry-title").each(function(element) {
			//console.log(myfile);
			var paragraph = $(this);
			var text = paragraph.text()+"\n";
			console.log(text);
			fs.appendFile("Articles/WASHINGTON/WASHINGTON_"+myfile, text, function (err) {});
		  });
          $("#content #article-leaf-page div div h3 span").each(function(element) {
			//console.log(myfile);
			var paragraph = $(this);
			var text = paragraph.text()+"\n";
			//console.log(text);
			fs.appendFile("Articles/WASHINGTON/WASHINGTON_"+myfile, text, function (err) {});
		  });
		  $("#content #article-leaf-page div #article #article_body div article p").each(function(element) {
			//console.log(myfile);
			var paragraph = $(this);
			var text = "\n"+paragraph.text()+"\n";
			fs.appendFile("Articles/WASHINGTON/WASHINGTON_"+myfile, text, function (err) {});
		  });
		});
		j++;
	  }
	}
Пример #4
0
  versions.forEach(function(version) {
    var stillUnsupported = version === '*';

    logger.debug(' %s', stillUnsupported ? '-' : version);

    var bundleFilename = browser + (prevVersion + (stillUnsupported ? '+' : '-' + version)) + '.js';
    var mainFilePath = path.join(browserBuildPath, bundleFilename);

    var deps = features[version].map(function(feature) {
      var sourcePath = feature.split(':');
      return 'liftjs/modules/' + sourcePath.join('/');
    });


    var mainFp = fs.openSync(mainFilePath, 'w');
    try {
      fs.writeSync(mainFp, 'require(["');

      fs.writeSync(mainFp, deps.join('", "'));

      fs.writeSync(mainFp, '"]);\n');
    } finally {
      fs.closeSync(mainFp);
    }

    var bundleConfig = {
      skipModuleInsertion: true,
      optimize: 'none',
      baseUrl: 'dist/bundles/',
      name: path.basename(bundleFilename, '.js'),
      wrap: true,
      out: mainFilePath,
      // logLevel: 4, // change to 0 for trace
      paths: {
        liftjs: '../'
      }
    };

    promises.push(new Promise(function(resolve, reject) {
      requirejs.optimize(bundleConfig, function(/* buildResponse */) {
        //buildResponse is just a text output of the modules included. Load the
        //built file for the contents. Use bundleConfig.out to get the optimized
        //file contents.
        // var contents = fs.readFileSync(bundleConfig.out, 'utf8');

        logger.debug('');
        console.log(chalk.blue('Created bundle ' + bundleFilename));
        logger.debug('');

        // console.log(contents);

        resolve();
      }, function(err) {
        console.error(err);
        //optimization err callback
        reject(err);
      });
    }));

    prevVersion = version;
  });
Пример #5
0
}).then(() => {
    console.log('started');
    fs.closeSync(1);
}).catch(err => {
Пример #6
0
var fs = require('fs');
var path = require('path');

var f = path.join(common.fixturesDir, 'x.txt');

console.log('watching for changes of ' + f);

var changes = 0;
function watchFile() {
  fs.watchFile(f, function(curr, prev) {
    console.log(f + ' change');
    changes++;
    assert.ok(curr.mtime != prev.mtime);
    fs.unwatchFile(f);
    watchFile();
    fs.unwatchFile(f);
  });
}

watchFile();


var fd = fs.openSync(f, 'w+');
fs.writeSync(fd, 'xyz\n');
fs.closeSync(fd);

process.on('exit', function() {
  assert.ok(changes > 0);
});
Пример #7
0
 this.repl.on("exit", function() {
   closeSync(historyFd);
   historyFd = -1;
 });