fs-extra#outputFileSync TypeScript Examples

The following examples show how to use fs-extra#outputFileSync. 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: index.ts    From nestjs-proto-gen-ts with MIT License 6 votes vote down vote up
private output(file: string, pkg: string, tmpl: string): void {
        const root = new Root();

        this.resolveRootPath(root);

        root.loadSync(file, {
            keepCase: this.options.keepCase,
            alternateCommentMode: this.options.comments
        }).resolveAll();

        this.walkTree(root);

        const results = compile(tmpl)(root);
        const outputFile = this.options.output ? join(this.options.output, file.replace(/^.+?[/\\]/, '')) : file;
        const outputPath = join(dirname(outputFile), `${basename(file, extname(file))}.ts`);

        outputFileSync(outputPath, results, 'utf8');
    }
Example #2
Source File: build.ts    From sonolus-bandori-engine with MIT License 5 votes vote down vote up
outputFileSync(
    `${distPath}/EngineConfiguration`,
    buildOutput.engine.configuration.buffer
)
Example #3
Source File: build.ts    From sonolus-bandori-engine with MIT License 5 votes vote down vote up
outputFileSync(`${distPath}/EngineData`, buildOutput.engine.data.buffer)
Example #4
Source File: purchase.ts    From epicgames-freegames-node with MIT License 4 votes vote down vote up
/**
   * Completes a purchase starting from the purchase iframe using its namespace and offerId
   */
  public async purchaseShort(namespace: string, offer: string): Promise<void> {
    const page = await this.setupPage();
    try {
      const purchaseUrl = `${EPIC_PURCHASE_ENDPOINT}?highlightColor=0078f2&offers=1-${namespace}-${offer}&orderId&purchaseToken&showNavigation=true`;

      /**
       * This inner function is declared to allow the page to be refreshed after a 3 hour timeout
       */
      // eslint-disable-next-line consistent-return
      const initPurchase = async (): Promise<void> => {
        this.L.info({ purchaseUrl }, 'Loading purchase page');
        await page.goto(purchaseUrl, { waitUntil: 'networkidle0' });
        await page.waitForNetworkIdle({ idleTime: 2000 });
        try {
          this.L.trace('Waiting for cookieDialog');
          const cookieDialog = (await page.waitForSelector(`button#onetrust-accept-btn-handler`, {
            timeout: 3000,
          })) as ElementHandle<HTMLButtonElement>;
          this.L.trace('Clicking cookieDialog');
          await cookieDialog.click({ delay: 100 });
        } catch (err) {
          if (!err.message.includes('timeout')) {
            throw err;
          }
          this.L.trace('No cookie dialog presented');
        }
        this.L.trace('Waiting for placeOrderButton');
        const placeOrderButton = (await page.waitForSelector(
          `button.payment-btn:not([disabled])`
        )) as ElementHandle<HTMLButtonElement>;
        this.L.debug('Clicking placeOrderButton');
        await placeOrderButton.click({ delay: 100 });
        try {
          const euRefundAgreeButton = (await page.waitForSelector(
            `div.payment-confirm__actions > button.payment-btn.payment-confirm__btn.payment-btn--primary`,
            { timeout: 3000 }
          )) as ElementHandle<HTMLButtonElement>;
          this.L.debug('Clicking euRefundAgreeButton');
          await euRefundAgreeButton.click({ delay: 100 });
        } catch (err) {
          if (!err.message.includes('timeout')) {
            throw err;
          }
          this.L.trace('No EU "Refund and Right of Withdrawal Information" dialog presented');
        }
        this.L.debug('Waiting for receipt');
        const purchaseEvent = await Promise.race([
          page
            .waitForFunction(() => document.location.hash.includes('/purchase/receipt'))
            .then(() => 'nav'),
          page
            .waitForSelector('.payment-alert--ERROR > span.payment-alert__content')
            .then((errorHandle: ElementHandle<HTMLSpanElement> | null) =>
              errorHandle ? errorHandle.evaluate((el) => el.innerText) : 'Unknown purchase error'
            ),
          this.waitForHCaptcha(page),
        ]);
        if (purchaseEvent === 'captcha') {
          this.L.debug('Captcha detected');
          // Keep the existing portal open
          if (!page.hasOpenPortal()) {
            await this.openPortalAndNotify(page, NotificationReason.PURCHASE);
          }
          const interactionResult = await Promise.race([
            page
              .waitForFunction(() => document.location.hash.includes('/purchase/receipt'), {
                timeout: NOTIFICATION_TIMEOUT,
              })
              .then(() => 'nav'),
            page.waitForTimeout(3 * 60 * 60 * 1000).then(() => 'timeout'),
          ]);
          if (interactionResult === 'timeout') {
            this.L.info('Reloading purchase page...'); // Reload page after 3 hour timeout
            return initPurchase();
          }
          await page.closePortal();
        } else if (purchaseEvent !== 'nav') {
          throw new Error(purchaseEvent);
        }
      };

      await initPurchase();
      this.L.trace(`Puppeteer purchase successful`);
      await this.teardownPage(page);
    } catch (err) {
      let success = false;
      if (page) {
        const errorPrefix = `error-${new Date().toISOString()}`.replace(/:/g, '-');
        const errorImage = path.join(CONFIG_DIR, `${errorPrefix}.png`);
        await page.screenshot({ path: errorImage });
        const errorHtml = path.join(CONFIG_DIR, `${errorPrefix}.html`);
        const htmlContent = await page.content();
        outputFileSync(errorHtml, htmlContent, 'utf8');
        this.L.warn(err);
        this.L.error(
          { errorImage, errorHtml },
          'Encountered an error during browser automation. Saved a screenshot and page HTML for debugging purposes.'
        );
        if (!config.noHumanErrorHelp) success = await this.sendErrorManualHelpNotification(page);
        await page.close();
      }
      if (!success) throw err;
    }
  }