How to use the mz/fs.readFileSync function in mz

To help you get started, we’ve selected a few mz examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Kaixhin / FGMachine / test / rand.js View on Github external
opts[process.argv[i]] = process.argv[i + 1];
}
console.log("Options: ");
console.log(opts);


// Make results directory
if (!fs.existsSync("experiments")) {
  fs.mkdirSync("experiments");
}
fs.mkdirSync(path.join("experiments", opts._id));

// Store source code
fs.writeFileSync(path.join("experiments", opts._id, "source_code.js"), fs.readFileSync("./rand.js"));
// Store image
fs.writeFileSync(path.join("experiments", opts._id, "mnist.png"), fs.readFileSync("./mnist.png"));
// Store custom fields
fs.writeFileSync(path.join("experiments", opts._id, "notes.json"), JSON.stringify({"Notes": "This field is being used to store notes about the experiment.", "Version": "Node.js " + process.version}));


// Creates a linear scale
var linScale = function(numEls, step, start) {
  return _.map(Array(numEls), (val, ind) => {
    return start + step*ind;
  });
};

// Creates an exponential decay curve with noise
var noisyExp = function(val, ind, coll) {
  var exp = Math.pow(0.9, ind/coll.length) - 0.9;
  return exp + exp*Math.random();
};
github mntnr / build-a-space / src / checkers / community.js View on Github external
if (file.name === 'readme') {
      fileContent = Buffer.from(`# ${github.repoName.split('/')[1]}

TODO This needs to be filled out!`)

      console.robowarn('You need to fill out the README manually!')

      file.content = fileContent.toString('base64')
    } else {
      if (file.name === 'contributing' && opts.contributing) {
        fileContent = await fs.readFileSync(path.join(__dirname, '../../', opts.contributing)).toString('utf8')
      } else {
        const {data} = await github.get(`/repos/${github.repoName}/readme`)
        const readme = Buffer.from(data.content, 'base64')
        const filePath = path.join(__dirname, '..', '..', 'fixtures', file.filePath)
        fileContent = getSection(readme, 'contribute') || await fs.readFileSync(filePath, 'utf8')
      }

      // Text Replacements
      if (file.name === 'code_of_conduct') {
        fileContent = fileContent.replace('[INSERT EMAIL ADDRESS]', email)
        file.note.push(`Check the email in the Code of Conduct. We've added in "${email}".`)
      } else if (file.name === 'license') {
        fileContent = fileContent.replace('[INSERT LICENSEE]', licensee)
        file.note.push(`Check the licensee in the License. We've licensed this to "${licensee}".`)
      } else if (file.name === 'contributing') {
        fileContent = fileContent.replace('[GITHUB REPONAME]', github.repoName)
      }

      file.content = btoa(fileContent)
    }
github GoogleChromeLabs / ui-element-samples / service-worker / index.js View on Github external
res.set({
      'ETag': hash,
      'Cache-Control': 'public, no-cache'
    });
    res.send(content);
  })
  .catch(error => res.status(500).send(error.toString()));
});
app.use(express.static('app'));

// Self-signed certificate generated by `simplehttp2server`
// @see https://github.com/GoogleChrome/simplehttp2server
const options = {
  key: fs.readFileSync('key.pem'),
  cert: fs.readFileSync('cert.pem')
};
// It says spdy, but it's actually HTTP/2 :)
require('http').createServer(app).listen(8081);
github flutter-view / flutter-view / src / watcher.ts View on Github external
// try to find a matching css or sass file
		const p = parseFileName(file)
		let css
		const sassFile = `${p.dir}/${p.name}.sass`
		const cssFile = `${p.dir}/${p.name}.css`
		if(fs.existsSync(sassFile)) {
			const cssResult = renderSync({
				file: sassFile,
				includePaths: [process.cwd()+'/lib'],
				outputStyle: 'expanded',
				indentedSyntax: true
			})
			css = cssResult.css.toLocaleString()
		} else if(fs.existsSync(cssFile)) {
			css = fs.readFileSync(cssFile).toString()
		}
		if(css) {
			// merge the css styles into the html
			const mergedHtml = juice.inlineContent(html, css, {
				xmlMode: false,
				webResources: {
					relativeTo: process.cwd()+'/lib'
				}
			})
			return await parse(mergedHtml)
		} else {
			return await parse(html)
		}

		async function parse(htm: string): Promise{
			return await new Promise(function(resolve, reject) {
github ccckmit / road_to_bookdown / 10-editServer / server.js View on Github external
var fs    = require('mz/fs');
var koa   = require('koa');
var serve = require('koa-static');
var route = require('koa-route');
var parse = require('co-body');
var path  = require('path');
var showdown = require('showdown');
var handlebars = require('handlebars');

var converter = new showdown.Converter();
converter.setOption('tables', true);

var userPath = path.join(__dirname, 'user');

var render = { 
  view:handlebars.compile(fs.readFileSync("render/view.html", "utf8")),
}

var getFilePath=function(book, file) {
  return path.join(userPath, "/book/"+book+"/"+file);
}

function *view(book, file) { // view(mdFile):convert *.md to html
  var bookPath = path.join(userPath, "/book/"+book);
  var filePath = path.join(userPath, "/book/"+book+"/"+file);
  var fstat = yield fs.stat(filePath);
  if (fstat.isFile()) {
    if (this.path.endsWith(".md")) {
      this.type = "html";
      var md = yield fs.readFile(filePath, "utf8");
      var bookJson = yield fs.readFile(bookPath+"/book.json", "utf8");
      var bookObj = JSON.parse(bookJson);
github flutter-view / flutter-view / src / watcher.ts View on Github external
async function processFile(file: string, isUpdate: boolean) : Promise {
		const relativeFile = relative(process.cwd(), file)
		// extract the html from the file, depending on the type
		let html
		switch(extname(file)) {
			case '.pug': {
				html = renderPugFileAsHtml(file)
				// html = await renderFile(file)
				break
			}
			case '.htm': case '.html': {
				html = fs.readFileSync(file).toString()
				break
			}
			case '.css': case '.sass': {
				if(isUpdate) {
					const p = parseFileName(relative(process.cwd(), file))
					const pugFile = `${p.dir}/${p.name}.pug`
					const htmlFile = `${p.dir}/${p.name}.html`
					if(fs.existsSync(pugFile)) {
						return await processFile(pugFile, isUpdate)
					} else if(fs.existsSync(htmlFile)) {
						return await processFile(htmlFile, isUpdate)
					}
				}
				return null
			}
		}
github surf-build / surf / test / git-api.ts View on Github external
describe('The parseGitDiffOutput function', function() {
  let diffStatFile = path.join(__dirname, '..', 'fixtures', 'diffstat.txt');
  let fixtureData = fs.readFileSync(diffStatFile, 'utf8');

  it('should parse the fixture file', () => {
    let result = parseGitDiffOutput(fixtureData);

    expect(result).to.contain('src/build-discover-base.ts');
    expect(result).to.contain('test/job-installers.ts');
  });
});
github ETCDEVTeam / emerald-js / src / download / downloader.js View on Github external
verifyArchive(zip: string, signature: string): Promise {
    this.emit('notify', 'Verifying PGP signature');
    const v = new Verify();
    v.init(this.signerKeys);
    return v.verify(fs.readFileSync(zip), signature)
      .then(() => zip);
  }
github erzu / porter / packages / porter / lib / porter.js View on Github external
constructor({ app, dir, paths, parent }) {
    const { packageCache } = app
    if (packageCache[dir]) return packageCache[dir]
    packageCache[dir] = this

    const pkg = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8'))
    this.app = app
    this.dir = dir
    this.name = pkg.name
    this.version = pkg.version
    this.paths = paths || [dir]
    this.parent = parent
    this.dependencies = {}
    this.entries = {}
    this.files = {}
    this.alias = {}
    this.transform = (pkg.browserify && pkg.browserify.transform) || []
    this.depPaths = []
    this.loaderCache = {}

    if (app.transpile.only.includes(pkg.name) && pkg.babel) {
      this.transpiler = 'babel'
github pedromsilvapt / unicast / src / ExtensionsManager.ts View on Github external
export function loadTypescriptFile ( module, filename ) {
    if ( ts == null ) ts = require( 'typescript' );

    var content = fs.readFileSync( filename, 'utf8' );

    var code = ts.transpileModule( content, {
        compilerOptions: { module: ts.ModuleKind.CommonJS }
    } );

    module._compile( code, filename );
}