# fancy-react-code

> Development tools and code generation for react development

Latest version **2.2.7** (published 2018-06-26) · 0 weekly downloads

## Install

```sh
npm install fancy-react-code
pnpm add fancy-react-code
yarn add fancy-react-code
bun add fancy-react-code
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.7 |
| Published | 2018-06-26 |
| First published | 2018-06-09 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 119.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 1 |
| Maintainers | eddiesholl |

## Links

- npm: https://www.npmjs.com/package/fancy-react-code
- Repository: https://github.com/eddiesholl/fancy-react-code
- Homepage: https://github.com/eddiesholl/fancy-react-code#readme
- Issues: https://github.com/eddiesholl/fancy-react-code/issues
- npm.io page: https://npm.io/package/fancy-react-code

## Dependencies (5)

- [glob](https://npm.io/package/glob.md) ^7.1.2
- [ramda](https://npm.io/package/ramda.md) ^0.25.0
- [node-glob](https://npm.io/package/node-glob.md) ^1.2.0
- [@types/ramda](https://npm.io/package/@types/ramda.md) ^0.25.32
- [fancy-react-core](https://npm.io/package/fancy-react-core.md) ^2.2.6

## Recent versions

- 2.2.7 (latest) — 2018-06-26
- 2.2.6 — 2018-06-23
- 2.2.5 — 2018-06-23
- 2.2.4 — 2018-06-23
- 2.2.3 — 2018-06-23
- 2.2.2 — 2018-06-21
- 2.2.1 — 2018-06-19
- 2.2.0 — 2018-06-18
- 2.1.2 — 2018-06-14
- 2.1.1 — 2018-06-14
- 2.1.0 — 2018-06-13
- 2.0.0 — 2018-06-12
- 1.0.1 — 2018-06-09

## README

# fancy-react-code

An extension for `Visual Studio Code` that helps to automate building react apps, following your preferred project layout.

Currently it is assumed that unit test files are using `jest`, `enzyme` and `chai`.

# Commands

## `generate`

Start from a snippet of a proposed React component in some jsx somewhere, and generate a skeleton implementation of that new component. The intention is that the component name, and the names of the essential properties passed to the component, can be typed directly in an existing parent, pretending that it already exists. The code generation can then scaffold as much of that new component as possible.

Default key binding: `ctrl-alt-g`

![generate](https://github.com/eddiesholl/fancy-react-code/raw/master/doc/generate-component.gif "generate")

## `tests`

Start from a source code file containing exported functions and classes, and generate a test file with suites for each export. If the test file doesn't exist, then create it using a sensible path and naming structure. If the file does already exist, then merge any existing tests and suites with the ones that have been generated for you.

Default key binding: `ctrl-alt-t`

![tests](https://github.com/eddiesholl/fancy-react-code/raw/master/doc/generate-tests.gif "tests")

## `switch`

A handy shortcut to quickly jump between a source file and it's corresponding test file, and back.

Default key binding: `ctrl-alt-s`

![switch](https://github.com/eddiesholl/fancy-react-code/raw/master/doc/switch-files.gif "switch")

# Views

## Component tree view
Get a preview of the components found in your project, with details like the properties found on each component. This feature is quite new and will be under active development. Right now, it only detects class based components.

This is currently disabled by default, you will need to set `fancyReact.treeViewEnabled = true`.

![tree](https://github.com/eddiesholl/fancy-react-code/raw/master/doc/tree-view.png "tree")

# Package configuration

The current workflows and generated code are built around a few basic assumptions about how the React project is laid out. The set of supported configurations and conventions will be expanding over time.

All configuration items can be set globally using the standard vscode settings format, using the key names listed below. For example, to define a standard test suffix for all repos you edit, you would set the settings key `fancyReact.testSuffix = "-test"`. If you have a React repo that needs some specific configuration, you can include keys inside that repo's `package.json` file, under a `fancyReact` key.

```json
},
"devDependencies": {
  "chai": "^4.0.2",
  "react-dom": "^15.6.1",
  "react-test-renderer": "^15.6.1"
},
"fancyReact": {
  "testStructure": "SubDir",
  "packagePath": "client",
  "sourcePath": "src",
  "testPath": "test",
  "testSuffix": "-test",
  "treeViewEnabled": true
}
```
You can see an example config in the [package.json](https://github.com/eddiesholl/atom-fancy-react-test/blob/master/package.json#L43) file for `atom-fancy-react-test`.

The examples here all describe a component defined at `<rootDir>/client/src/components/Foo/Foo.js`.

Currently you need to restart VSCode to pick up any changes to settings.

## testStructure
Specify the general strategy for storing test files.

- ParallelDirs - The entire src folder is mirrored, and contains all of your tests. For example `client/src/components/Foo/Foo.js` -> `client/test/components/Foo/Foo-test.js`

- SameDir - Every test lives in the same folder as its source file. For example `client/src/components/Foo/Foo.js` -> `client/src/components/Foo/Foo-test.js`

- SubDir - Every test lives in a sub folder of where the source file is. For example `client/src/components/Foo/Foo.js` -> `client/src/components/Foo/test/Foo-test.js`

## packagePath
What is the path within the repo to the start of the react code. For example, `client`
## sourcePath
What is the path within the react root to get to the source files. For example, `src`
## testPath
What is the path within the react root to get to the test files. In `ParallelDirs` mode, for the example above, `test`. This is also a valid value for `SubDir` mode, it will nest test files under their source folder at `test`.
## testSuffix
The suffix to append to the source file name. For example, `-test`.

# Integration

A goal of the project is to 'automagically' detect as much as possible about the patterns and tools of the current project. The current integrations supported are:

 ## eslint
If your project uses `eslint` to enforce syntax requirements, any code generation will try to find local eslint configuration, and use this to 'fix' generated syntax. This is not perfect but will generally do a good match of creating acceptable syntax.

Specifically, this is how it works:
 - check if `eslint` appears in the list of `dependencies` or `devDependencies`
 - if so, spin up an `eslint` instance using http://eslint.org/docs/developer-guide/nodejs-api#cliengine
 - this will be able to respect all of the `.eslintrc` files that may exist in your project
 - the generated code is passed through in `fix` mode. This means that rules can only be respected if they implement a fix

# History

This extension for VSCode has been ported from an atom plugin with the same goals, which is available [here](https://github.com/eddiesholl/atom-fancy-react). The bulk of the parsing code has been extracted to a dedicated platform agnostic library https://github.com/eddiesholl/fancy-react-core/ At some point, the atom version could be migrated to consume this new code base, but for now it is not under development.

# Troubleshooting

In general if the plugin is not behaving how you expect, it can be useful to open up the `Output` window and have a look for any error messages.

# Resources

There is a sample package available at https://github.com/eddiesholl/atom-fancy-react-test that offers an example package structure that works with this plugin, and some sample components to play around with. For example, there are some missing components that can be `generate`d to complete the implementation.

# Contributing

The success of this package is based on supporting a wide range of dependencies, styles, approaches and package conventions. If your particular configuration is not supported, feel free to open an issue and describe the changes you are looking for. Pull requests are also most welcome!

# Implementation & Dependencies

The plugin makes heavy use of javascript ASTs to process input source code, and to generate output code. Currently the parsing is done using `acorn` and `acorn-jsx`, node construction via `estree-builder`, and generation by `astring`. This is more labor intensive than simple string templates but should allow much richer functionality and opportunity for extension.

# Future items

## Display a component hierarchy

It would be awesome to get an overview of all the components in the current repo, how they are nested, and the props each one exposes.

## Wider configuration for project structure

There are many conventions and possible structures for how to lay out a `React` project. For example, maybe you store test files next to source files, or in a subfolder, or maybe you use a different naming format.

## Modernise generated code

There are some limitations in the node types currently supported by `estree-builder`. For example, functions are all declared using traditional function syntax, rather than 'fat arrow' style.

## Plugin extension

It should be possible to expose hook points that let others develop plugins that extend this one. For example, other unit test syntax could be provided with, for example, a `fancy-react-jasmine` plugin.

## CLI

There's no reason that these command should only be available within atom. They could be re-exposed by a CLI wrapper that can run outside of atom.

---
_Source: https://npm.io/package/fancy-react-code · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
