How to use the mz.fs.readFile 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 kondi / rxjs-grpc / src / cli.ts View on Github external
const jsFile = await call(tempDir.name, pbjsMain, protoFiles, 'js', ['keep-case'], {
      target: 'static-module',
      wrap: 'commonjs',
    });

    const jsonDescriptor = await call(tempDir.name, pbjsMain, protoFiles, 'js', ['keep-case'], {
      target: 'json',
    });
    const root = protobuf.loadSync(jsonDescriptor);

    const js = transformJavaScriptSource(await fs.readFile(jsFile, 'utf8'), root);
    await fs.writeFile(jsFile, js);

    // Create TypeScript file
    const tsFile = await call(tempDir.name, pbtsMain, [jsFile], 'ts');
    return transformTypeScriptSource(await fs.readFile(tsFile, 'utf8'));
  } finally {
    tempDir.removeCallback();
  }
}
github Cedware / electron-angular-toolkit / src / index.ts View on Github external
private static async prepareIndexHtml(): Promise {
        console.log('preparing index.html');
        try {
            let indexHtmlPath = path.join('src', 'index.html');
            let indexHtml = await fs.readFile(indexHtmlPath, 'utf-8');
            let updatedIndexHtml = indexHtml.replace('', '');
            await fs.writeFile(indexHtmlPath, updatedIndexHtml);
            console.log(chalk.green('finished preparing index.html'));
        }
        catch (error) {
            console.log(chalk.red('failed preparing index.html'));
            console.log(chalk.red(error));
            process.exit(1);
        }
    }
github Cedware / electron-angular-toolkit / src / index.ts View on Github external
private static async modifyWebpackConfig(packageJson: Package): Promise {
        console.log('modifying webpack config');
        try {
            let originalConfig = await fs.readFile(this.copyConfigPath, 'utf-8');
            let nativeDependencies = ['fs', 'child_process', 'electron', 'path', 'assert', 'cluster', 'crypto', 'dns', 'domain', 'events', 'http', 'https', 'net', 'os', 'process', 'punycode',
                'querystring', 'readline', 'repl', 'stream', 'string_decoder', 'tls', 'tty', 'dgram', 'url', 'util', 'v8', 'vm', 'zlib'];
            if (packageJson.nativeModules) {
                nativeDependencies = nativeDependencies.concat(packageJson.nativeModules);
            }
            let externalsTemplate = await fs.readFile(path.join(__dirname, '..', 'res', 'externals.template'), 'utf-8');
            let externals = externalsTemplate.replace('{ignores}', JSON.stringify(nativeDependencies));
            let newConfig = originalConfig.replace(/return ?{/g, `return {\n${externals}`);
            await fs.writeFile(this.configPath, newConfig);
            console.log(chalk.green('finished modifying webpack config'));
        }
        catch (error) {
            console.log(chalk.red('failed modifying webpack config'));
            console.log(chalk.red(error));
            process.exit(1);
        }
    }
github Cedware / electron-angular-toolkit / src / index.ts View on Github external
private static async copyWebpackConfig(): Promise {
        console.log('copying webpack config');
        try {
            let configContent = await fs.readFile(this.configPath, 'utf-8');
            await fs.writeFile(this.copyConfigPath, configContent);
            console.log(chalk.green('finished copying webpack config'));
        }
        catch (error) {
            console.log(chalk.red('failed copying webpack config'));
            console.log(chalk.red(error));
            process.exit(1);
        }
    }
github Cedware / electron-angular-toolkit / src / index.ts View on Github external
private static async modifyWebpackConfig(packageJson: Package): Promise {
        console.log('modifying webpack config');
        try {
            let originalConfig = await fs.readFile(this.copyConfigPath, 'utf-8');
            let nativeDependencies = ['fs', 'child_process', 'electron', 'path', 'assert', 'cluster', 'crypto', 'dns', 'domain', 'events', 'http', 'https', 'net', 'os', 'process', 'punycode',
                'querystring', 'readline', 'repl', 'stream', 'string_decoder', 'tls', 'tty', 'dgram', 'url', 'util', 'v8', 'vm', 'zlib'];
            if (packageJson.nativeModules) {
                nativeDependencies = nativeDependencies.concat(packageJson.nativeModules);
            }
            let externalsTemplate = await fs.readFile(path.join(__dirname, '..', 'res', 'externals.template'), 'utf-8');
            let externals = externalsTemplate.replace('{ignores}', JSON.stringify(nativeDependencies));
            let newConfig = originalConfig.replace(/return ?{/g, `return {\n${externals}`);
            await fs.writeFile(this.configPath, newConfig);
            console.log(chalk.green('finished modifying webpack config'));
        }
        catch (error) {
            console.log(chalk.red('failed modifying webpack config'));
            console.log(chalk.red(error));
            process.exit(1);
        }
github Cedware / electron-angular-toolkit / src / index.ts View on Github external
private static async createElectronEntryPoint(): Promise {
        console.log('creating entry point');
        var targetDir = path.join('src', 'electron');
        if (!fs.existsSync(targetDir)){
            fs.mkdirSync(targetDir);
        }
        let sourcePath = path.join(__dirname, '..', 'res', 'electron-main.js.template');
        let targetPath = path.join(targetDir, 'electron.js');
        let template = await fs.readFile(sourcePath, 'utf-8');
        await fs.writeFile(targetPath, template);
    }
github mozilla / web-ext / src / cmd / build.js View on Github external
export async function getDefaultLocalizedName(
  {messageFile, manifestData}: LocalizedNameParams
): Promise {

  let messageData: LocalizedMessageData;
  let messageContents: string | Buffer;
  let extensionName: string = manifestData.name;

  try {
    messageContents = await fs.readFile(messageFile, {encoding: 'utf-8'});
  } catch (error) {
    throw new UsageError(
      `Error reading messages.json file at ${messageFile}: ${error}`);
  }

  messageContents = stripBom(messageContents);

  try {
    messageData = parseJSON(stripJsonComments(messageContents));
  } catch (error) {
    throw new UsageError(
      `Error parsing messages.json file at ${messageFile}: ${error}`);
  }

  extensionName = manifestData.name.replace(
    /__MSG_([A-Za-z0-9@_]+?)__/g,
github DeepCodeAI / vscode-extension / src / deepcode / utils / filesUtils.ts View on Github external
export const readFile = async (filePath: string): Promise => {
  return await fs.readFile(filePath, { encoding: FILE_FORMAT });
};