How to use the fs-extra.writeFile function in fs-extra

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 cmux / koot / core / webpack / plugins / spa-template.js View on Github external
} else {
                // Before Webpack 4 - fileDepenencies was an array
                compilation.fileDependencies.push(filename)
            }
            compilation.assets[filename] = {
                source: () => html,
                size: () => html.length
            }

            // console.log(html)

            // 生产环境:写入文件
            if (process.env.WEBPACK_BUILD_ENV === 'prod') {
                const pathname = path.resolve(getDistPath(), 'public/', filename)
                await fs.ensureFile(pathname)
                await fs.writeFile(
                    pathname,
                    html,
                    'utf-8'
                )
            }

            callback()
        })
github samuelmaddock / metastream / app / browser / platform / swarm / identity.ts View on Github external
let localKeyPair: KeyPair

  // 1. check if identity exists
  const userPath = app.getPath('userData')
  const keyPath = path.join(userPath, `${KEYNAME}.pub`)
  const skeyPath = path.join(userPath, KEYNAME)

  const exists = await fs.pathExists(keyPath)

  // 2. create keypair
  if (!exists) {
    // 3. save keypair on disk
    localKeyPair = keyPair()
    try {
      await fs.writeFile(keyPath, localKeyPair.publicKey)
      await fs.writeFile(skeyPath, localKeyPair.secretKey)
    } catch (e) {}
  } else {
    try {
      localKeyPair = {
        publicKey: await fs.readFile(keyPath),
        secretKey: await fs.readFile(skeyPath)
      }
    } catch (e) {
      localKeyPair = keyPair()
    }
  }

  // convert old sodium-native keys to use new length compatible with libsodium-wrappers
  if (localKeyPair.secretKey.length > sodium.crypto_box_PUBLICKEYBYTES) {
    localKeyPair.secretKey = localKeyPair.secretKey.slice(0, sodium.crypto_box_PUBLICKEYBYTES)
github jasonelle / jay / jay / build.js View on Github external
fs.open(file, 'w', err => {
      if (err) {
        throw err;
      }

      fs.writeFile(file, json, er => {
        if (er) {
          return console.error(er);
        }
        console.log(`Created File ${colors.green(file)}`);
        return file;
      });
    });
  });
github microsoft / vscode-azure-blockchain-ethereum / src / services / openZeppelin / OpenZeppelinMigrationsService.ts View on Github external
const truffleConfigPath = TruffleConfiguration.getTruffleConfigUri();
  const truffleConfig = new TruffleConfiguration.TruffleConfig(truffleConfigPath);
  const configuration = truffleConfig.getConfiguration();
  const migrationFilePath = configuration.migrations_directory;
  const filePath = path.join(
    getWorkspaceRoot()!,
    migrationFilePath,
    migrationFilename,
  );

  Output.outputLine(
    Constants.outputChannel.azureBlockchain,
    `New migration for OpenZeppelin contracts was stored to file ${migrationFilename}`,
  );

  return fs.writeFile(filePath, content, { encoding: 'utf8' });
}
github PufferPanel / Scales / lib / plugins / old / mcserver.js View on Github external
function(cb) {
						fs.writeFile(webadminPath, ini.stringify(webadminConfig), function(error) {

							if(error) {
								log.error("An error occured trying to update the " + settings.webadmin + " file for " + config.name, error);
								return;
							} else {
								log.verbose("Updated webadmin.ini file for " + config.name);
								log.verbose("Completed plugin preflight for " + config.name);
								callback();
							}

						});
					}
				]);
github sinedied / smoke / lib / recorder.js View on Github external
async function writeMock(mock, outputFolder, depth) {
  let content = mock.data;

  if (content === null) {
    content = '';
  } else if (typeof content === 'function') {
    content = `module.exports = ${content.toString()};`;
  } else if (typeof content === 'object' && !(content instanceof Buffer)) {
    content = JSON.stringify(content, null, 2);
  }

  const outputFile = path.join(outputFolder, buildFile(mock, depth));
  await fs.mkdirp(path.dirname(outputFile));
  await fs.writeFile(outputFile, content);
}
github bazzite / nuxt-netlify / lib / utils.js View on Github external
const createFile = async (filePath, content) => {
  if (await fs.exists(filePath)) {
    await fs.appendFile(filePath, `\n\n${content}`)
  } else {
    await fs.ensureFile(filePath)
    await fs.writeFile(filePath, content)
  }
}
github imlucas / lone / lib / compile.js View on Github external
.replace(/VALUE "ProductVersion", .*/, 'VALUE "ProductVersion", "' + config.app.version + '"')
      .replace(/VALUE "OriginalFilename", ".*"/, 'VALUE "OriginalFilename", "' + config.app.name + '.exe"')
      .replace(/VALUE "InternalName", ".*"/, 'VALUE "InternalName", "' + config.app.name + '"');

    if (config.icon) {
      custom = custom.replace(/1 ICON .*/, '1 ICON ' + config.icon);
    }

    var patch = dmp.patch_make(data, custom);
    if (patch.length === 0) {
      debug('dont need to patch for icon');
      return fn(null, config);
    }
    debug('icon patch', patch.toString());
    debug('writing patched rc');
    fs.writeFile(rc, dmp.patch_apply(patch, data)[0], function(_err) {
      if (_err) {
        return fn(_err);
      }
      debug('patch applied!');
      return fn(null, config);
    });
  });
}