How to use fs-extra - 10 common examples

To help you get started, we’ve selected a few fs-extra 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 computestdev / Openrunner / building / buildFirefoxProfile.js View on Github external
const buildCachedFirefoxExtensionDirectory = async ({tempDirectory, extensionOptions = {}, buildCacheDirectory}) => {
    const cacheName = `firefox-extension-${packageVersion}-${Number(extensionOptions.cncPort)}`;
    const extensionPath = joinPath(buildCacheDirectory, cacheName);

    // quick check to see if the extension directory looks valid
    const manifestValid = await fs.pathExists(joinPath(extensionPath, 'manifest.json'));
    const buildConfigValid = await fs.pathExists(joinPath(extensionPath, 'build', 'buildConfig.json'));
    const scriptEnvValid = await fs.pathExists(joinPath(extensionPath, 'build', 'script-env.js'));

    if (manifestValid && buildConfigValid && scriptEnvValid) {
        log.debug({cncPort: extensionOptions.cncPort, extensionPath}, 'Using cached extension directory');
        return extensionPath;
    }

    await fs.mkdirp(extensionPath).catch(err => {
        err[ERROR_FAILED_TO_CREATE_EXTENSION_CACHE] = true;
        throw err;
    });

    await buildFirefoxExtension({tempDirectory, extensionOptions, outputPath: extensionPath, zipped: false});
    return extensionPath;
};
github namics / frontend-defaults / cli / __tests__ / shared.tsx View on Github external
const tmpPath = path.join(tmpPathRoot, tmpPathName);
	options.cwd = tmpPath;
	if (options.force === undefined) {
		options.force = true;
	}

	jest.setTimeout(10000);
	await deleteDir(tmpPath);
	try {
		await fs.mkdir(tmpPathRoot);
	} catch (err) {}
	await fs.mkdir(tmpPath);

	await api(options);

	const files = (await fs.readdir(tmpPath))
		.filter((dirName: string) => !fs.statSync(path.join(tmpPath, dirName)).isDirectory())
		.filter(removeIgnoredFiles)
		.sort();

	let i = 0;
	for (i = 0; i < files.length; i += 1) {
		const fileData = await fs.readFile(path.join(tmpPath, files[i]), 'utf8');
		const tree = renderer.create().toJSON();
		expect(tree).toMatchSnapshot();
	}

	// normalize pathes to look the same on windows, linux and mac
	// expect.addSnapshotSerializer({
	// 	test: (val) => typeof val === 'string',
	// 	print(val) {
	// 		return `${val.replace(/\\/g, '/')}`;
github stream-labs / streamlabs-obs / test / selective-recording.ts View on Github external
// Check that source is set to record only
  t.true(await client.isExisting('.sl-vue-tree-sidebar .source-selector-action.icon-studio'));

  // Start recording
  await client.click('.record-button');
  await sleep(2000);

  // Ensure recording indicator is active
  t.true(await client.isExisting('.record-button.active'));

  // Stop recording
  await client.click('.record-button');
  await client.waitForVisible('.record-button:not(.active)', 60000);

  // Check that file exists
  const files = await readdir(tmpDir);
  t.is(files.length, 1);
});
github IBM / watson-discovery-news-alerting / app / scripts / build.js View on Github external
require('../config/env');

const path = require('path');
const chalk = require('chalk');
const fs = require('fs-extra');
const webpack = require('webpack');
const config = require('../config/webpack.config.prod');
const paths = require('../config/paths');
const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages');
const printHostingInstructions = require('react-dev-utils/printHostingInstructions');
const FileSizeReporter = require('react-dev-utils/FileSizeReporter');

const measureFileSizesBeforeBuild = FileSizeReporter.measureFileSizesBeforeBuild;
const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild;
const useYarn = fs.existsSync(paths.yarnLockFile);

// Warn and crash if required files are missing
if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
  process.exit(1);
}

function copyPublicFolder() {
  fs.copySync(paths.appPublic, paths.appBuild, {
    dereference: true,
    filter: file => file !== paths.appHtml,
  });
}

// Create the production build and print the deployment instructions.
function build(previousFileSizes) {
  console.log('Creating an optimized production build...');
github webiny / webiny-js / packages / cli / create / index.js View on Github external
module.exports = async ({ name, tag }) => {
    const root = join(process.cwd(), name);

    if (fs.existsSync(root)) {
        console.log(
            `🚨 Aborting: destination folder ${green(
                name
            )} already exists! Please enter a different folder name.`
        );
        process.exit(1);
    }

    console.log(`📦 Creating a new Webiny project in ${green(root)}...`);
    fs.ensureDirSync(root);
    process.chdir(root);

    fs.ensureDirSync("apps");
    fs.ensureDirSync("packages");

    // Copy project files
github fredsiika / 30-seconds-of-c / scripts / util.js View on Github external
const readSnippets = snippetsPath => {
    const snippetFilenames = getFilesInDir(snippetsPath, false);
  
    let snippets = {};
    try {
      for (let snippet of snippetFilenames)
        snippets[snippet] = fs.readFileSync(path.join(snippetsPath, snippet), 'utf8');
    } catch (err) {
      console.log(`${chalk.red('ERROR!')} During snippet loading: ${err}`);
      process.exit(1);
    }
    return snippets;
  };
  // Creates an object from pairs
github fredsiika / 30-seconds-of-c / scripts / build.js View on Github external
misc.image('Logo', '/logo.png') +
      headers.h1('Snippets Archive') +
      "These snippets, while useful and interesting, didn't quite make it into the repository due to either having very specific use-cases or being outdated. However we felt like they might still be useful to some readers, so here they are." +
      headers.h2('Table of Contents');

    output += lists.ul(Object.entries(snippets), snippet =>
      misc.link(`\`${snippet[0].slice(0, -3)}\``, misc.anchor(snippet[0].slice(0, -3)))
    );
    output += misc.hr();

    for (const snippet of Object.entries(snippets)) {
      output += makeExamples(snippet[1]);
    }

    // Write to the README file of the archive
    fs.writeFileSync(path.join(SNIPPETS_ARCHIVE_PATH, 'README.md'), output);
  } catch (err) {
    console.log(`${chalk.red('ERROR!')} During README generation for snippets archive: ${err}`);
    process.exit(1);
  }

  console.log(`${chalk.green('SUCCESS!')} README file generated for snippets archive!`);
  console.timeEnd('Builder');
}
let snippets = {};
const EMOJIS = {
  adapter: '🔌',
  array: '📚',
  browser: '🌐',
  date: '⏱️',
  function: '🎛️',
  logic: '🔮',
github mayeaux / nodetube / lib / livestreaming / postNewRecordings.js View on Github external
async function main(){

  const folderToScan = './recordings';

  fs.readdir(folderToScan, (err, files) => {

    // console.log(files);

    if(!files){
      console.log('no files in directory')
      return
    }

    files.forEach(async (file) => {

      // console.log(file);

      const split = file.split('&');

      const username = split[0];
      const filename = split[1];
github richardfrost / AdvancedProfanityFilter / bin / package-extension.js View on Github external
function buildEdge(manifest, zip) {
  if (!fse.existsSync('./store/edge')) { return false; }
  console.log('Building ./extension-edge.zip');
  let msPreload = {
    backgroundScript: "backgroundScriptsAPIBridge.js",
    contentScript: "contentScriptsAPIBridge.js"
  }

  // Fix options_page
  manifest.options_page = manifest.options_ui.page;
  delete manifest.options_ui;

  // Add ms-proload polyfills
  manifest['-ms-preload'] = msPreload;
  updateManifestFileInZip(zip, manifest);
  zip.addLocalFile('./store/edge/src/backgroundScriptsAPIBridge.js', null);
  zip.addLocalFile('./store/edge/src/contentScriptsAPIBridge.js', null);
  fse.removeSync('./extension-edge.zip');
github fusepilot / create-cep-extension / packages / create-cep-extension-scripts / scripts / eject.js View on Github external
}
      content =
        content
          // Remove dead code from .js files on eject
          .replace(
            /\/\/ @remove-on-eject-begin([\s\S]*?)\/\/ @remove-on-eject-end/gm,
            ''
          )
          // Remove dead code from .applescript files on eject
          .replace(
            /-- @remove-on-eject-begin([\s\S]*?)-- @remove-on-eject-end/gm,
            ''
          )
          .trim() + '\n';
      console.log(`  Adding ${cyan(file.replace(ownPath, ''))} to the project`);
      fs.writeFileSync(file.replace(ownPath, appPath), content);
    });
    console.log();