npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

test5amir

v0.1.4

Published

```javascript create-react-app test5 npm run eject npm i babel-loader chalk babel-core object-assign whatwg-fetch highlight.js npm-run-all chokidar react-docgen ``` * In Package.json in make it like ```javascript "scripts": { "prestart": "npm run g

Downloads

7

Readme

Document

create-react-app test5
npm run eject
npm i babel-loader chalk babel-core object-assign whatwg-fetch highlight.js npm-run-all chokidar react-docgen
  • In Package.json in make it like
"scripts": {
    "prestart": "npm run gen:docs",
    "start:docs": "node scripts/start.js",
    "start": "npm-run-all --parallel start:docs gen:docs-watch",
    "gen:docs": "node scripts/generateComponentData.js",
    "gen:docs-watch": "npm run gen:docs -- --watch",
    "build": "node scripts/build.js",
    "test": "node scripts/test.js --env=jsdom"
  },
  • In components create HelloWorld/Helloworld.js and index.js as
export {default} from './HelloWorld';
import React from 'react';
import PropTypes from 'prop-types';

/** A super lame component that says Hello with a custom message. */
function HelloWorld({message}) {
  return <div>Hello {message}</div>
}

HelloWorld.propTypes = {
  /** Message to display */
  message: PropTypes.string
};

HelloWorld.defaultProps = {
  message: 'World'
};
export default HelloWorld;
  • Then add generateComponentData.js in script folder as it is in bottom
var fs = require('fs');
var path = require('path');
var chalk = require('chalk');
var parse = require('react-docgen').parse;
var chokidar = require('chokidar');

var paths = {
  examples: path.join(__dirname, '../src', 'docs', 'examples'),
  components: path.join(__dirname, '../src', 'components'),
  output: path.join(__dirname, '../config', 'componentData.js')
};

const enableWatchMode = process.argv.slice(2) == '--watch';
if (enableWatchMode) {
  // Regenerate component metadata when components or examples change.
  chokidar.watch([paths.examples, paths.components]).on('change', function(event, path) {
    generate(paths);
  });
} else {
  // Generate component metadata
  generate(paths);
}

function generate(paths) {
  var errors = [];
  var componentData = getDirectories(paths.components).map(function(componentName) {
    try {
      return getComponentData(paths, componentName)
    } catch(error) {
      errors.push('An error occurred while attempting to generate metadata for ' + componentName + '. ' + error);
    }
  });
  writeFile(paths.output, "module.exports = " + JSON.stringify(errors.length ? errors : componentData));
}

function getComponentData(paths, componentName) {
  var content = readFile(path.join(paths.components, componentName, componentName + '.js'));
  var info = parse(content);
  return {
    name: componentName,
    description: info.description,
    props: info.props,
    code: content,
    examples: getExampleData(paths.examples, componentName)
  }
}

function getExampleData(examplesPath, componentName) {
  var examples = getExampleFiles(examplesPath, componentName);
  return examples.map(function(file) {
    var filePath = path.join(examplesPath, componentName, file)
    var content = readFile(filePath)
    var info = parse(content);
    return {
      // By convention, component name should match the filename.
      // So remove the .js extension to get the component name.
      name: file.slice(0, -3),
      description: info.description,
      code: content
    };
  });
}

function getExampleFiles(examplesPath, componentName) {
  var exampleFiles = [];
  try {
    exampleFiles = getFiles(path.join(examplesPath, componentName));
  } catch(error) {
    console.log(chalk.red(`No examples found for ${componentName}.`));
  }
  return exampleFiles;
}

function getDirectories(filepath) {
  return fs.readdirSync(filepath).filter(function(file) {
    return fs.statSync(path.join(filepath, file)).isDirectory();
  });
}

function getFiles(filepath) {
  return fs.readdirSync(filepath).filter(function(file) {
    return fs.statSync(path.join(filepath, file)).isFile();
  });
}

function writeFile(filepath, content) {
  fs.writeFile(filepath, content, function (err) {
    err ? console.log(chalk.red(err)) : console.log(chalk.green("Component data saved."));
  });
}

function readFile(filePath) {
  return fs.readFileSync(filePath, 'utf-8');
}
  • Now running npm run start should work
  • inside src folder create docs and added CodeExample.js , ComponentPage.js , Docs.js, Example.js, Navigation.js and props.js
  • In config/webpack.congig.dev.js and prodution comment it out line 103
  • Now it should work
  • copy index.css to have better look
/* Global styles */
body {
  font-family: Arial, Helvetica, sans-serif;
  color: #666666;
}

a, a:visited {
  color: #666666;
}

.clear {
  clear: both;
}

td {
  border-top: solid 1px #d3d3d3;
}

td, th {
  padding: 10px;
}

table {
  border-collapse:collapse;
}

/* Documentation site component styles */
.example {
  border: solid 1px #d3d3d3;
  padding: 16px;
  margin-bottom: 16px;
  background-color: #f4f6f9;
}

.example h4:first-of-type {
   margin-top: 0;
}

.example p:last-of-type {
   margin-bottom: 0;
}

.props tr td:last-of-type {
  text-align: center;
}

.props th, td {
  text-align: left;
  padding: 5px;
}

.navigation {
  float: left;
  width: 250px;
  list-style-type: none;
  padding: 0;
}

.componentpage {
  margin-left: 275px;
}
  • Add into index.js below highlight
import '../node_modules/highlight.js/styles/ocean.css';