better-name
CLI to rename ES2015 module files
Last updated 22 days ago by quramy .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install better-name 
SYNC missed versions from official npm registry.

better-name

CircleCI Coverage Status npm version

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.

// src/index.js

import { someFn } from './oldFile';

export default function main() {
  someFn();
}
// src/oldFile.js

export 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:

// src/index.js

import { someFn } from './feat/newFile';

export default function main() {
  someFn();
}

Install

npm -g install better-name

Usage

better-name [options] <fromFile> <toFile>

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:

  /* package.json */
  "betterName": {
    "patterns": [
      "src/javascript/**/*.{js,jsx}",
      "src/styles/**/*.css"
    ]
  },

Root import

Root path mapping using 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:

  /* 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:

  /* 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, .tsx

And imports non-JavaScript files are allowed. For example:

/* 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.

Current Tags

  • 0.7.1                                ...           latest (22 days ago)

25 Versions

  • 0.7.1                                ...           22 days ago
  • 0.6.2                                ...           2 months ago
  • 0.6.1                                ...           a year ago
  • 0.6.0                                ...           2 years ago
  • 0.5.6                                ...           2 years ago
  • 0.5.5                                ...           2 years ago
  • 0.5.4                                ...           2 years ago
  • 0.5.3                                ...           2 years ago
  • 0.5.2                                ...           2 years ago
  • 0.5.1                                ...           2 years ago
  • 0.5.0                                ...           2 years ago
  • 0.4.3                                ...           2 years ago
  • 0.4.2                                ...           2 years ago
  • 0.4.1                                ...           2 years ago
  • 0.4.0                                ...           2 years ago
  • 0.3.4                                ...           2 years ago
  • 0.3.2                                ...           2 years ago
  • 0.3.1                                ...           2 years ago
  • 0.3.0                                ...           2 years ago
  • 0.2.3                                ...           2 years ago
  • 0.2.2                                ...           2 years ago
  • 0.2.1                                ...           2 years ago
  • 0.2.0                                ...           2 years ago
  • 0.1.1                                ...           2 years ago
  • 0.1.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 25
Dependencies (9)
Dev Dependencies (16)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |