How to use kyt-utils - 10 common examples

To help you get started, we’ve selected a few kyt-utils 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 nytimes / kyt / packages / kyt-core / utils / jest / preprocessor.js View on Github external
const normalizeDep = (prefix, dep) => {
  let resolved;
  try {
    // Prefix babel when babel doesn't exist
    if (dep.indexOf('babel') < 0) {
      resolved = resolve.sync(`${prefix}-${dep}`, { basedir: userRootPath });
    }
    return resolved || resolve.sync(dep, { basedir: userRootPath });
  } catch (e) {
    logger.error('Could not resolve dependency', dep);
    logger.error('Error output', e);
    logger.error('Exiting...');
    return process.exit(1);
  }
};
github nytimes / kyt / packages / kyt-core / cli / actions / proto.js View on Github external
compiler = webpack(webpackConfig);
    } catch (error) {
      logger.error('Webpack config is invalid\n', error);
      process.exit();
    }

    // Creates a webpack dev server at the specified port
    server = new WebpackDevServer(compiler, webpackConfig.devServer);
    server.listen(prototypeURL.port, prototypeURL.hostname, () => {
      logger.end(`webpack-dev-server ${prototypeURL.href}prototype`);
    });
  };
  logger.start('Configuring Prototype...');

  if (!shell.test('-f', userPrototypePath)) {
    logger.error('Prototype.js entry file does not exist.');
    logger.error('See the kyt Readme for details.');
    process.exit();
  }

  ifPortIsFreeDo(prototypeURL.port, startPrototype);
};
github nytimes / kyt / packages / kyt-core / utils / jest / preprocessor.js View on Github external
const normalizeDep = (prefix, dep) => {
  let resolved;
  try {
    // Prefix babel when babel doesn't exist
    if (dep.indexOf('babel') < 0) {
      resolved = resolve.sync(`${prefix}-${dep}`, { basedir: userRootPath });
    }
    return resolved || resolve.sync(dep, { basedir: userRootPath });
  } catch (e) {
    logger.error('Could not resolve dependency', dep);
    logger.error('Error output', e);
    logger.error('Exiting...');
    return process.exit(1);
  }
};
github nytimes / kyt / packages / kyt-core / utils / jest / preprocessor.js View on Github external
const normalizeDep = (prefix, dep) => {
  let resolved;
  try {
    // Prefix babel when babel doesn't exist
    if (dep.indexOf('babel') < 0) {
      resolved = resolve.sync(`${prefix}-${dep}`, { basedir: userRootPath });
    }
    return resolved || resolve.sync(dep, { basedir: userRootPath });
  } catch (e) {
    logger.error('Could not resolve dependency', dep);
    logger.error('Error output', e);
    logger.error('Exiting...');
    return process.exit(1);
  }
};
github nytimes / kyt / packages / kyt-core / utils / webpackCompiler.js View on Github external
module.exports = (webpackConfig, cb) => {
  let webpackCompiler;
  const type = webpackConfig.target === 'web' ? 'Client' : 'Server';

  // Compile the webpack config
  try {
    webpackCompiler = webpack(webpackConfig);
    logger.task(`${type} webpack configuration compiled`);
  } catch (error) {
    logger.error(`${type} webpack config is invalid\n`, error);
    process.exit();
  }

  webpackCompiler.hooks.beforeRun.tap('kyt', () => {
    // Temporarily set the build type in the process.
    // This is used by the babel-preset-kyt-core plugin.
    process.env.KYT_ENV_TYPE = type.toLowerCase();
  });

  // Handle errors in webpack build
  webpackCompiler.hooks.done.tap('kyt', stats => {
    if (stats.hasErrors()) {
      logger.error(`${type} build failed\n`, stats.toString());
      logger.info('See webpack error above');
    } else if (stats.hasWarnings()) {
      logger.warn(`${type} build warnings`, stats.toJson().warnings.join('\n'));
github nytimes / kyt / packages / kyt-core / utils / buildConfigs.js View on Github external
clientConfig = config.modifyWebpackConfig(clone(clientConfig), clientOptions);
    serverConfig = config.modifyWebpackConfig(clone(serverConfig), serverOptions);
  } catch (error) {
    logger.error('Error in your kyt.config.js modifyWebpackConfig():', error);
    process.exit(1);
  }

  if (config.debug) {
    logger.debug('Client webpack configuration:', clientConfig);
    logger.debug('\n\n');
    logger.debug('Server webpack configuration:', serverConfig);
  }

  // A "main" entry is required in the server config.
  if (!serverConfig.entry.main) {
    logger.error(
      'A main entry is required in the server configuration. Found: ',
      serverConfig.entry
    );
    process.exit(1);
  }

  return {
    clientConfig,
    serverConfig,
  };
};
github nytimes / kyt / packages / kyt-core / cli / actions / build.js View on Github external
module.exports = config => {
  logger.start('Starting production build...');

  let serverCompiler;

  const { clientConfig, serverConfig } = buildConfigs(config, 'production');

  // Clean the build directory.
  if (shell.rm('-rf', buildPath).code === 0) {
    shell.mkdir(buildPath);
    logger.task('Cleaned ./build');
  }

  // Copy public folder into build
  if (shell.test('-d', publicSrcPath)) {
    // Create build folder if it doesnt exist
    if (!shell.test('-d', buildPath)) {
      shell.mkdir(buildPath);
    }
    shell.cp('-r', publicSrcPath, publicBuildPath);
    logger.task('Copied /src/public to /build/public');
  } else {
    shell.mkdir('-p', `${buildPath}/public`);
  }

  // Compiles server code using the prod.server config
  const buildServer = () => {
github nytimes / kyt / packages / kyt-cli / cli / actions / setup.js View on Github external
const createEditorconfigLink = () => {
    const editorPath = path.join(__dirname, '../../config/user/.kyt-editorconfig');
    const configPath = path.join(paths.userRootPath, '.editorconfig');

    // Backup existing editor config
    if (shell.test('-f', configPath)) {
      const mvTo = path.join(paths.userRootPath, `editorconfig-${date}.bak`);
      shell.mv(configPath, mvTo);
      logger.info(`Backed up current editor config to ${mvTo}`);
    }

    shell.cp(editorPath, configPath);
    logger.task('Created .editorconfig file');
  };
github nytimes / kyt / packages / kyt-cli / cli / actions / setup.js View on Github external
const createBabelrc = () => {
    // back up existing .babelrc, if it exists
    if (shell.test('-f', paths.userBabelrcPath)) {
      const mvTo = path.join(paths.userRootPath, `.babelrc-${date}.bak`);
      shell.mv(paths.userBabelrcPath, mvTo);
      logger.info(`Backed up current .babelrc to ${mvTo}`);
    }
    shell.cp(`${tmpDir}/.babelrc`, paths.userBabelrcPath);
    logger.task('Created .babelrc');
  };
github nytimes / kyt / packages / kyt-cli / cli / actions / setup.js View on Github external
const createPrototypeFile = () => {
    const starterProto = `${tmpDir}/prototype.js`;
    // No need to copy file if it doesn't exist
    if (!shell.test('-f', starterProto)) return;
    // Backup user's prototype file if they already have one
    if (shell.test('-f', paths.userPrototypePath)) {
      const prototypeBackup = path.join(paths.userRootPath, `prototype-${date}.js.bak`);
      shell.mv(paths.userPrototypePath, prototypeBackup);
      logger.info(`Backed up current prototype file to: ${prototypeBackup}`);
    }
    // Copy the prototype file from the starter-kyt into the users repo
    shell.cp(starterProto, paths.userPrototypePath);
    logger.task('copied prototype.js file into root');
  };

kyt-utils

A shared kyt utility library.

Apache-2.0
Latest version published 7 months ago

Package Health Score

70 / 100
Full package analysis

Similar packages