Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Quramy/better-name
CLI tool to move JavaScript(ES2015) or TypeScript module files
https://github.com/Quramy/better-name
cli es2015 javascript refactoring typescript
Last synced: 3 months ago
JSON representation
CLI tool to move JavaScript(ES2015) or TypeScript module files
- Host: GitHub
- URL: https://github.com/Quramy/better-name
- Owner: Quramy
- License: mit
- Created: 2018-04-05T17:21:58.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-08T19:13:08.000Z (almost 2 years ago)
- Last Synced: 2024-07-28T14:17:18.417Z (4 months ago)
- Topics: cli, es2015, javascript, refactoring, typescript
- Language: TypeScript
- Homepage:
- Size: 728 KB
- Stars: 35
- Watchers: 3
- Forks: 1
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# better-name
[![CircleCI](https://circleci.com/gh/Quramy/better-name.svg?style=svg)](https://circleci.com/gh/Quramy/better-name)
[![Coverage Status](https://coveralls.io/repos/github/Quramy/better-name/badge.svg?branch=master)](https://coveralls.io/github/Quramy/better-name?branch=master)
[![npm version](https://badge.fury.io/js/better-name.svg)](https://badge.fury.io/js/better-name)A CLI to move JavaScript(ES2015) module files keeping dependencies.
If you have the following JavaScript files coupled with import/export dependencies and you want to refactor via moving the `target.js` to another directory.
```js
// src/index.jsimport { someFn } from './oldFile';
export default function main() {
someFn();
}
``````js
// src/oldFile.jsexport function someFn() {
return 'test';
}
```This CLI keeps their dependencies. In other words, after `better-name src/oldFile.js src/feat/newFile.js`, the import declaration in the `index.js` file gets updated with the new dependencies:
```js
// src/index.jsimport { someFn } from './feat/newFile';
export default function main() {
someFn();
}
```## Install
```sh
npm -g install better-name
```## Usage
```sh
better-name [options]
```Exec `better-name --help` if you want more details :smile:
### Configure
#### Project file patterns
By default, this CLI searches files to be replaced via `src/**/*.{js,jsx,mjs,ts,tsx}` glob pattern.
You can customize the glob pattern with `--pattern` option or configuring in package.json:```js
/* package.json */
"betterName": {
"patterns": [
"src/javascript/**/*.{js,jsx}",
"src/styles/**/*.css"
]
},
```#### Root import
Root path mapping using [babel-plugin-root-import](https://github.com/entwicklerstube/babel-plugin-root-import) is supported.
Path mapping configuration is loaded automaticcaly if your .babelrc has `babel-plugin-root-import` section.You also can configure path mapping via package.json such as:
```js
/* package.json */
"betterName": {
"rootImport": [{
"rootPathPrefix": "~",
"rootPathSuffix": "src/js"
}, {
"rootPathPrefix": "@",
"rootPathSuffix": "other-src/js"
}, {
"rootPathPrefix": "#",
"rootPathSuffix": "../../src/in/parent"
}]
}
```If you want to avoid prefixing after replacing, `--normalize-root-import` CLI option or the following package.json setting is available:
```js
/* package.json */
"betterName": {
"normalizeRootImport": true
}
```#### Format with Prettier
This CLI format your code after replace import declarations if your project has Prettier config file(.prettierrc, .prettierrc.js,,,).
You can turn on this behavior passing `--prettier` options to CLI.## Remarks
### Available file types
This CLI can replace import declarations in the following file types:- JavaScript: .js, .jsx, .mjs
- TypeScript: .ts, .tsxAnd imports non-JavaScript files are allowed. For example:
```js
/* some.component.jsx */import styles from './some.component.css';
// ...
```However, non-JavaScript import(i.e. `@import` in CSS) could not be replaced.
## License
MIT. See LICENSE file under the this repository.