How to use the tmp.fileSync function in tmp

To help you get started, we’ve selected a few tmp 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 transmute-industries / transmute / packages / transmute-did / src / lib / wallet / __tests__ / wallet.spec.js View on Github external
//   eslint-disable-next-line
const { sha3_256 } = require('js-sha3');

const {
  createWallet,
  TransmuteDIDWallet,
  schema,
  sodiumExtensions,
  ethereumExtensions,
} = require('../../../index');

const pack = require('../../../../package.json');

const emptyWalletPath = tmp.fileSync().name;
const fullWalletPath = tmp.fileSync().name;
const cipherTextWalletPath = tmp.fileSync().name;
const recoveredPlaintextWalletPath = tmp.fileSync().name;

const passphrase = 'yolo';

describe('did-wallet', () => {
  describe('createWallet', () => {
    it('has a version', async () => {
      const wallet = await createWallet();
      expect(wallet.data.version).toBe(pack.version);
      expect(schema.validator.isValid(wallet.data, schema.schemas.didWalletPlaintext)).toBe(
        true,
      );
      fs.writeFileSync(emptyWalletPath, stringify(wallet.data, null, 2));
    });
  });
github artilleryio / chaos-lambda / lib / commands / deploy.js View on Github external
function createLambda(role, llamaFile, done) {
  var lambda = new aws.Lambda({apiVersion: '2015-03-31'});

  var archive = archiver.create('zip', {});

  var lambdaPath = path.join(__dirname, '../../lambda/index.js');
  var tmpf = tmp.fileSync();
  var tmpfStream = fs.createWriteStream(tmpf.name);
  archive.pipe(tmpfStream);
  archive.append(fs.readFileSync(lambdaPath), { name: 'index.js' });
  if (llamaFile) {
    debug('Adding real Chaosfile to lambda zip');
    llamaFile.region = process.env.AWS_REGION; // FIXME
    archive.append(new Buffer(JSON.stringify(llamaFile)), { name: 'config.json' });
  } else {
    debug('Adding a stub Chaosfile to lambda zip');
    archive.append(new Buffer(JSON.stringify({enableForASGs: []})), { name: 'config.json' });
  }
  lambdaDependencies.forEach( function (moduleName){
    archive.directory(path.join(__dirname, '..', '..', './node_modules/' + moduleName), 'node_modules/'+ moduleName);
  });

  archive.on('error', function(err) {
github informalsystems / themis-contract / src / shared / contract.ts View on Github external
}
    if (!this.template) {
      throw new Error('Missing template for contract')
    }
    this.computeHash()
    await this.prepareTemplateParams(this.filename)
    if (opts && opts.verify) {
      await this.verify({
        useKeybase: true,
      })
    }

    logger.debug(`Using template params: ${JSON.stringify(this.params, null, 2)}`)
    // render the template to a temporary directory
    const templateExt = this.template.ext ? this.template.ext : DEFAULT_TEMPLATE_EXT
    const tmpContract = tmp.fileSync({ postfix: templateExt })
    try {
      const renderedTemplate = this.template.render(this.params)
      await writeFileAsync(
        tmpContract.name,
        renderedTemplate,
      )
      logger.debug(`Wrote contract to temporary file: ${tmpContract.name}`)
      logger.debug(`Wrote rendered template:\n${renderedTemplate}`)

      logger.info('Generating PDF...')
      if (templateExt === '.tex') {
        await this.compileWithTectonic(tmpContract.name, outputFile)
      } else {
        if (opts && opts.defaults) {
          if (await fileExistsAsync(opts.defaults)) {
            logger.debug(`Compiling using pandoc defaults file ${opts.defaults}`)
github antwarjs / antwar / packages / antwar / src / build / worker.js View on Github external
jsFiles.push(`/${filename}.js`);

      const interactiveIndexEntry = ejs.compile(
        templates.interactiveIndex.file
      )({
        components,
      });
      const entry = ejs.compile(templates.interactive.file)({
        components,
      });

      // Touch output so that other processes get a clue
      touch.sync(interactivePath);

      // Write to a temporary files so we can point webpack to that
      const interactiveEntryTmpFile = tmp.fileSync();
      const entryTmpFile = tmp.fileSync();

      // XXX: convert to async
      _fs.writeFileSync(interactiveEntryTmpFile.name, interactiveIndexEntry);
      _fs.writeFileSync(entryTmpFile.name, entry);

      const interactiveConfig = require(configurationPaths.webpack)(
        "interactive"
      );
      const webpackConfig = merge(interactiveConfig, {
        mode: "production",
        resolve: {
          modules: [cwd, _path.join(cwd, "node_modules")],
          alias: generateAliases(components),
        },
        resolveLoader: {
github symfony / webpack-encore / test / generator / init-questioner.js View on Github external
return new Promise((resolve) => {
        const tmpFile = tmp.fileSync();
        responses = [tmpFile.name, inq.ENTER, ...responses];
        inq(cliPath, responses, 500).then(() => {
            resolve(JSON.parse(fs.readFileSync(tmpFile.name)));
        });
    });
}
github stanford-oval / almond-cloud / tests / unit / test_abstract_fs.js View on Github external
async function testCreateWriteStream() {
    const { name: tmpFile, fd: tmpFD } =
        tmpSync.fileSync({ mode: 0o600, dir: '/var/tmp' });
    const tmpSyncStub = {
        fileSync: function() {
            return { name: tmpFile, fd: tmpFD };
        }
    };
    const tmpAFS = proxyquire('../../util/abstract_fs', {
        './command': cmdStub,
        'tmp': tmpSyncStub,
        'fs': { unlink: function(){} },
    });

    try {
        cmdStub.lastCmds = [];
        const stream = tmpAFS.createWriteStream('s3://bucket/dir/file', true);
        const content = 'foobar';
        stream.write(content);
github ZeusWPI / MOZAIC / client / src / ServerRunner.ts View on Github external
private configJSON(): ServerConfigJSON {
        const { ctrl_token, address } = this.params;
        const logFile = tmp.fileSync().name;

        return {
            ctrl_token,
            address: `${address.host}:${address.port}`,
            log_file: logFile,
        };
    }
}
github mucsi96 / nightwatch-cucumber / lib / nightwatch-runner.js View on Github external
'use strict'

const fs = require('fs')
const path = require('path')
const glob = require('glob')
const mkdirp = require('mkdirp')
const tmp = require('tmp')
const co = require('co')
const open = require('open')
const checkSyntaxError = require('syntax-error')
const Cucumber = require.main.require('cucumber/lib/cucumber')
const CucumberAPI = require('./cucumber-api')
const createCucumberHTMLReport = require('./cucumber-html-report')
const tempTestFolder = tmp.dirSync({ unsafeCleanup: true })
const tempLogFile = tmp.fileSync({ unsafeCleanup: true })
let syntaxError = false
let runtime
let currentStep
let client
let cucumber

tmp.setGracefulCleanup()

function bootstrap (options) {
  const configurationArgs = [options.featureFiles]
  const jsonLogPath = path.relative('', tempLogFile.name)
  const configuration = Cucumber.Cli.Configuration({
    source: true,
    snippets: true,
    colors: true,
    format: ['pretty', 'json:' + jsonLogPath]
github njpanderson / push / src / lib / utils.js View on Github external
getTmpFile(getUri = true, extension = null) {
		const tmpobj = tmp.fileSync({
			prefix: TMP_FILE_PREFIX,
			postfix: (typeof extension === 'string' ? extension : '.tmp')
		});

		if (getUri) {
			return vscode.Uri.file(tmpobj.name);
		}

		return tmpobj.name;
	},
github artilleryio / artillery / lib / commands / quick.js View on Github external
if (options.num) {
    requestSpec = {
      loop: [requestSpec],
      count: options.num
    };
  }

  debug('requestSpec: %s', JSON.stringify(requestSpec, null, 2));

  script.scenarios[0].flow.push(requestSpec);
  if (p.protocol.match(/ws/)) {
    script.scenarios[0].engine = 'ws';
  }

  let tmpf = tmp.fileSync();
  fs.writeFileSync(tmpf.name, JSON.stringify(script, null, 2), {flag: 'w'});
  run(tmpf.name, {quiet: options.quiet, output: options.output});
}