Home / File/ utils.js — react Source File

utils.js — react Source File

Architecture documentation for utils.js, a javascript file in the react codebase.

Entity Profile

Relationship Graph

Source Code

'use strict';

const {exec} = require('child-process-promise');
const {createPatch} = require('diff');
const {hashElement} = require('folder-hash');
const {existsSync, readFileSync, writeFileSync} = require('fs');
const {readJson, writeJson} = require('fs-extra');
const logUpdate = require('log-update');
const {join} = require('path');
const createLogger = require('progress-estimator');
const prompt = require('prompt-promise');
const theme = require('./theme');
const {stablePackages, experimentalPackages} = require('../../ReactVersions');

// https://www.npmjs.com/package/progress-estimator#configuration
const logger = createLogger({
  storagePath: join(__dirname, '.progress-estimator'),
});

const addDefaultParamValue = (optionalShortName, longName, defaultValue) => {
  let found = false;
  for (let i = 0; i < process.argv.length; i++) {
    const current = process.argv[i];
    if (current === optionalShortName || current.startsWith(`${longName}=`)) {
      found = true;
      break;
    }
  }

  if (!found) {
    process.argv.push(`${longName}=${defaultValue}`);
  }
};

const confirm = async message => {
  const confirmation = await prompt(theme`\n{caution ${message}} (y/N) `);
  prompt.done();
  if (confirmation !== 'y' && confirmation !== 'Y') {
    console.log(theme`\n{caution Release cancelled.}`);
    process.exit(0);
  }
};

const execRead = async (command, options) => {
  const {stdout} = await exec(command, options);

  return stdout.trim();
};

const extractCommitFromVersionNumber = version => {
  // Support stable version format e.g. "0.0.0-0e526bcec-20210202"
  // and experimental version format e.g. "0.0.0-experimental-0e526bcec-20210202"
  const match = version.match(/0\.0\.0\-([a-z]+\-){0,1}([^-]+).+/);
  if (match === null) {
    throw Error(`Could not extra commit from version "${version}"`);
  }
  return match[2];
};

const getBuildInfo = async () => {
// ... (214 more lines)

Domain

Subdomains

Frequently Asked Questions

What does utils.js do?
utils.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain, Entrypoint subdomain.
What functions are defined in utils.js?
utils.js defines 14 function(s): addDefaultParamValue, confirm, execRead, extractCommitFromVersionNumber, getBuildInfo, getChecksumForCurrentRevision, getCommitFromCurrentBuild, getDateStringForCommit, getPublicPackages, handleError, and 4 more.
Where is utils.js in the architecture?
utils.js is located at scripts/release/utils.js (domain: BabelCompiler, subdomain: Entrypoint, directory: scripts/release).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free