fs-extra#outputFile TypeScript Examples

The following examples show how to use fs-extra#outputFile. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestProject.ts    From yarn-plugins with MIT License 6 votes vote down vote up
public static async setup(): Promise<TestProject> {
    const dir = await tmp.dir();
    const pluginBundles = await globby('packages/*/bundles/**/*.js', {
      cwd: PROJECT_DIR,
    });
    const plugins = pluginBundles.map((src) => ({
      src,
      name: '@yarnpkg/' + basename(src, extname(src)),
      dest: posix.join('.yarn', 'plugins', ...src.split(sep).slice(3)),
    }));

    for (const path of plugins) {
      await copy(join(PROJECT_DIR, path.src), join(dir.path, path.dest));
    }

    const yarnConfig = safeLoad(
      await readFile(join(PROJECT_DIR, '.yarnrc.yml'), 'utf8'),
    ) as Record<string, unknown>;

    // Create .yarnrc.yml
    await outputFile(
      join(dir.path, '.yarnrc.yml'),
      safeDump({
        yarnPath: join(PROJECT_DIR, yarnConfig.yarnPath as string),
        plugins: plugins.map((plugin) => ({
          path: plugin.dest,
          spec: plugin.name,
        })),
      }),
    );

    // Create package.json
    await outputJSON(join(dir.path, 'package.json'), {
      private: true,
      workspaces: ['packages/*'],
    });

    return new TestProject(dir);
  }
Example #2
Source File: index.ts    From mordred with MIT License 6 votes vote down vote up
async writeGraphQL() {
    try {
      const outContent = graphqlTemplate({
        typeDefs: this.typeDefs,
        plugins: this.plugins,
      })

      await outputFile(this.graphqlClientPath, outContent, 'utf8')
      await outputFile(
        join(this.outDir, 'graphql.d.ts'),
        graphqlDefinitionTemplate,
        'utf8',
      )
    } catch (err) {
      console.error(err)
      throw err
    }
  }
Example #3
Source File: index.ts    From mordred with MIT License 6 votes vote down vote up
async writeZeus() {
    const tree = Parser.parse(this.typeDefs)
    const jsDefinition = TreeToTS.javascript(tree)
    await Promise.all([
      outputFile(
        join(this.outDir, 'zeus.d.ts'),
        jsDefinition.definitions,
        'utf8',
      ),
      outputFile(join(this.outDir, 'zeus.js'), jsDefinition.javascript, 'utf8'),
    ])
  }
Example #4
Source File: AppUpdater.ts    From electron-differential-updater with MIT License 6 votes vote down vote up
private async getOrCreateStagingUserId(): Promise<string> {
    const file = path.join(this.app.userDataPath, ".updaterId");
    try {
      const id = await readFile(file, "utf-8");
      if (UUID.check(id)) {
        return id;
      } else {
        this._logger.warn(
          `Staging user id file exists, but content was invalid: ${id}`
        );
      }
    } catch (e) {
      if (e.code !== "ENOENT") {
        this._logger.warn(
          `Couldn't read staging user ID, creating a blank one: ${e}`
        );
      }
    }

    const id = UUID.v5(randomBytes(4096), UUID.OID);
    this._logger.info(`Generated new staging user ID: ${id}`);
    try {
      await outputFile(file, id);
    } catch (e) {
      this._logger.warn(`Couldn't write out staging user ID: ${e}`);
    }
    return id;
  }
Example #5
Source File: index.ts    From mordred with MIT License 5 votes vote down vote up
async writeNodes() {
    const outPath = join(this.outDir, 'nodes.json')
    const outContent = `${serialize([...this.nodes.values()], {
      isJSON: true,
    })}`
    await outputFile(outPath, outContent, 'utf8')
  }