How to use the mz/fs.writeFile 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 xpepermint / migratablejs / tests / migratings.ts View on Github external
test.serial("method `upgrade` runs only new migrations", async (t) => {
  let count = 0;
  let migrator = new Migrator({ cacheFilePath });

  await fs.writeFile(cacheFilePath, 1); // migration index=1 has already been executed

  migrator.add({
    index: 1,
    upgrade: () => count++,
  });
  migrator.add({
    index: 3,
    upgrade: () => count++,
  });

  let index = await migrator.upgrade();

  t.is(count, 1);
  t.is(index, 3);
});
github agreatfool / SASDN / src / bin / sasdn-gateway.ts View on Github external
let tmp = str.split('_');
        for (let i = 0; i < tmp.length; i++) {
          if (i > 0 || type == 'ucfirst') {
            name += tmp[i].charAt(0).toUpperCase() + tmp[i].slice(1);
          } else {
            name += tmp[i];
          }
        }
        return name;
      });

      // write file Router.ts in OUTPUT_DIR/router/
      let routerContent = TplEngine.render('router/router', {
        infos: gatewayInfoList,
      });
      await LibFs.writeFile(LibPath.join(OUTPUT_DIR, 'router', 'Router.ts'), routerContent);

      // write file RouterAPITest.ts in OUTPUT_DIR/router/
      let testContent = TplEngine.render('router/test', {
        infos: gatewayInfoList,
      });
      await LibFs.writeFile(LibPath.join(OUTPUT_DIR, 'router', 'RouterAPITest.ts'), testContent);

      // write file ${gatewayApiName}.ts in OUTPUT_DIR/router/${gatewayApiService}/
      for (let gatewayInfo of gatewayInfoList) {
        const relativePath = this._protoMsgImportInfos[`${gatewayInfo.packageName}${gatewayInfo.serviceName}`].protoFile.relativePath;
        await mkdir(LibPath.join(OUTPUT_DIR, 'router', relativePath, gatewayInfo.serviceName));

        let apiContent = TplEngine.render('router/api', {
          info: gatewayInfo,
        });
github brave / brave-browser / components / webpack / gen-webpack-grd.js View on Github external
// normalize path so relative path ignores leading path.sep
  if (!targetDir.endsWith(path.sep)) {
    targetDir += path.sep
  }
  const gdrPath = path.join(targetDir, grdName)
  // remove previously generated file
  try {
    await fs.unlink(gdrPath)
  } catch (e) {}
  // build file list from target dir
  const filePaths = await getFileListDeep(targetDir)
  const relativeFilePaths = filePaths.map(filePath => filePath.replace(targetDir, ''))
  // get gdr string
  const gdrFileContents = getGrdString(name, idPrefix, relativeFilePaths)
  // write to file
  await fs.writeFile(gdrPath, gdrFileContents, { encoding: 'utf8' })
}
github Swiip / generator-gulp-angular / test / template-tools.js View on Github external
]).then(function (results) {
    var packageFileContent = processTemplate(results[1]);
    var bowerFileContent = processTemplate(results[2]);
    return Promise.all([
      fs.writeFile(packageDestinationPath, packageFileContent),
      fs.writeFile(bowerDestinationPath, bowerFileContent)
    ]);
  })
  .catch(function (error) {
github firebase / firebase-admin-node / docgen / generate-docs.js View on Github external
return fs.readFile(file, 'utf8').then(data => {
    const flattenedLinks = data
      .replace(/\.\.\//g, '')
      .replace(/(modules|interfaces|classes)\//g, '');
    let caseFixedLinks = flattenedLinks;
    for (const lower in lowerToUpperLookup) {
      const re = new RegExp(lower, 'g');
      caseFixedLinks = caseFixedLinks.replace(re, lowerToUpperLookup[lower]);
    }
    return fs.writeFile(file, caseFixedLinks);
  });
}
github bcherny / json-schema-to-typescript / src / cli.ts View on Github external
function writeOutput(ts: string, argOut: string): Promise {
  if (!argOut) {
    try {
      process.stdout.write(ts)
      return Promise.resolve()
    } catch (err) {
      return Promise.reject(err)
    }
  }
  return writeFile(argOut, ts)
}
github hellopao / vscode-wechat / src / codeSnippet.ts View on Github external
.then(results => {
            const [current, wechatSnippets, configSnippets] = results;
            if (crypto.createHash('md5').update(current).digest('hex') === crypto.createHash('md5').update(wechatSnippets).digest('hex')) {
                return; 
            }
            return Promise.all([
                fs.writeFile(wechatSnippetFile, wechatSnippets),
                fs.writeFile(configSnippetFile, configSnippets)
            ]); 
        })
        .catch(err => {
github d6u / web-playground / src / util / FileUtil.js View on Github external
export function writeStrTo(fpath, fcontent) {
  return writeFile(fpath, fcontent, 'utf8');
}
github macacajs / macaca-datahub / app / service / database.js View on Github external
async exportScene(scene, projectName, exportInterfaceName) {
    await fs.writeFile(
      path.join(
        this.baseDir,
        projectName,
        exportInterfaceName,
        'scene',
        `${scene.sceneName}.json`
      ),
      JSON.stringify(scene, null, 2)
    );
  }