How to use the tmp-promise.setGracefulCleanup function in tmp-promise

To help you get started, we’ve selected a few tmp-promise 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 mozilla / addons-linter / tests / integration / run-as-production-env.js View on Github external
const npmScript = process.argv[2];
// Get the path to the test dir to run.
const jestTestsPath = process.argv[3];

if (!npmScript) {
  console.error(chalk.red('Missing mandatory npm script to run'));
  process.exit(1);
}

if (!jestTestsPath) {
  console.error(chalk.red('Missing mandatory path to the tests dir to run'));
  process.exit(1);
}

// Cleanup the temporary even if non empty.
tmp.setGracefulCleanup(tmpOptions);

function spawnWithShell(cmd, args, options) {
  return spawn(cmd, args, { ...baseSpawnOptions, ...options });
}

function getPackedName() {
  return new Promise((resolve, reject) => {
    fs.readFile('package.json', (err, data) => {
      if (err) {
        reject(err);
      } else {
        const info = JSON.parse(data.toString());
        resolve(`${info.name}-${info.version}.tgz`);
      }
    });
  });
github notaryio / notary / packages / notary-rest / src / download_helper.js View on Github external
import fs from 'fs';

import axios from 'axios';
import tmp from 'tmp-promise';
import unzip from 'unzip';

import config from './config';

tmp.setGracefulCleanup();

export default {
  async downloadContract(projectId, revision, contractName) {
    console.log(`${config.coreUrl}/projects/${projectId}/revisions/${revision}/contracts/${contractName}/raw-content`);

    const response = await axios.get(
      `${config.coreUrl}/projects/${projectId}/revisions/${revision}/contracts/${contractName}/raw-content`,
      { responseType: 'arraybuffer', headers: { 'Content-Type': 'application/zip' } }
    );

    return await tmp.dir({ unsafeCleanup: true }) // create a temp directory with random name; this will be cleaned up automatically on process exit
      .then(o => { // save the download ZIP archive
        return new Promise((resolve, reject) => {
          fs.writeFile(`${o.path}/contract-content.zip`, response.data, 'UTF-8', function(err) {
            if (err) reject(err);
            else resolve(o.path);
github pubpub / pubpub / workers / tasks / import / tmpDirectory.js View on Github external
/* eslint-disable no-restricted-syntax */
import path from 'path';
import fs from 'fs';
import { ensureDir } from 'fs-extra';
import tmp from 'tmp-promise';

import { s3bucket } from './s3';

tmp.setGracefulCleanup();

const blockForS3File = (key) =>
	new Promise((resolve, reject) => {
		let attempts = 0;
		const checkForFile = () => {
			s3bucket
				.headObject({ Key: key })
				.promise()
				.then(resolve)
				.catch(() => {
					if (attempts > 5) {
						return reject();
					}
					attempts += 1;
					return setTimeout(() => {
						checkForFile();
github pubpub / pubpub / workers / tasks / export.js View on Github external
import ReactDOMServer from 'react-dom/server';
import YAML from 'yaml';
import { buildSchema, renderStatic, jsonToNode, getNotes } from '@pubpub/editor';

import ensureUserForAttribution from 'shared/utils/ensureUserForAttribution';
import { getPubPublishedDate, getPubUpdatedDate } from 'shared/pub/pubDates';
import { SimpleNotesList } from 'components';
import { Branch, Pub, PubAttribution, User } from '../../server/models';
import { generateHash } from '../../server/utils';
import { getBranchDoc } from '../../server/utils/firebaseAdmin';
import { generateCiteHtmls } from '../../server/editor/queries';

AWS.config.setPromisesDependency(Promise);
const s3bucket = new AWS.S3({ params: { Bucket: 'assets.pubpub.org' } });

tmp.setGracefulCleanup();
const dataDir =
	process.env.NODE_ENV === 'production' ? '--data-dir=/app/.apt/usr/share/pandoc/data ' : '';

const formatTypes = {
	docx: { output: 'docx', extension: 'docx' },
	// pdf: { output: 'latex', extension: 'pdf', flags: ` --pdf-engine=xelatex --template=${__dirname}/template.tex` },
	pdf: { output: 'latex', extension: 'pdf', flags: ' --pdf-engine=xelatex' },
	epub: { output: 'epub', extension: 'epub' },
	html: { output: 'html', extension: 'html' },
	markdown: { output: 'markdown_strict', extension: 'md' },
	odt: { output: 'odt', extension: 'odt' },
	plain: { output: 'plain', extension: 'txt' },
	jats: { output: 'jats', extension: 'xml' },
	tex: { output: 'latex', extension: 'tex' },
};
github pubpub / pubpub / workers / tasks / import.js View on Github external
import tmp from 'tmp-promise';
import AWS from 'aws-sdk';
import cheerio from 'cheerio';
import { generateHash } from '../../server/utils';

const isPubPubProduction = !!process.env.PUBPUB_PRODUCTION;

AWS.config.setPromisesDependency(Promise);
const s3bucket = new AWS.S3({ params: { Bucket: 'assets.pubpub.org' } });

// Need to check for media folder - and upload all assets there to server, and then replace urls
// Send HTML to editor, which converts to json
// And then editor (I think) writes to firebase
// - get file, enter into pandoc, get html, convert into pubpub json

tmp.setGracefulCleanup();
const dataDir =
	process.env.NODE_ENV === 'production' ? '--data-dir=/app/.apt/usr/share/pandoc/data ' : '';

const processImages = (inputHtml) => {
	/* Images are blocks and cannot be nested inside <p> or other tags. */
	/* This moves the image to just before it's containing paragraph. */
	const htmlContext = cheerio.load(inputHtml);
	htmlContext('img').each((index, elem) =&gt; {
		return htmlContext(elem)
			.parent()
			.before(elem);
	});
	return htmlContext('body').html();
};

const processFootnotes = (inputHtml) =&gt; {</p>
github pubpub / pubpub / workers / tasks / export / util.js View on Github external
import fs from 'fs';
import AWS from 'aws-sdk';
import tmp from 'tmp-promise';

import { Export } from '../../../server/models';
import { generateHash } from '../../../server/utils';

tmp.setGracefulCleanup();

AWS.config.setPromisesDependency(Promise);
const s3bucket = new AWS.S3({ params: { Bucket: 'assets.pubpub.org' } });

export const uploadDocument = (branchId, tmpFile, extension) => {
	const readableStream = fs.createReadStream(tmpFile.path);
	const key = `${generateHash(8)}/${branchId}.${extension}`;
	const params = {
		Key: key,
		Body: readableStream,
		ACL: 'public-read',
	};
	return new Promise((resolve, reject) => {
		s3bucket.upload(params, (err) => {
			if (err) {
				reject(err);

tmp-promise

The tmp package with promises support and disposers.

MIT
Latest version published 3 years ago

Package Health Score

72 / 100
Full package analysis