{"id":15391027,"url":"https://github.com/quramy/better-name","last_synced_at":"2025-04-15T21:45:19.942Z","repository":{"id":31543229,"uuid":"128240043","full_name":"Quramy/better-name","owner":"Quramy","description":"CLI tool to move JavaScript(ES2015) or TypeScript module files","archived":false,"fork":false,"pushed_at":"2022-12-08T19:13:08.000Z","size":745,"stargazers_count":35,"open_issues_count":12,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-19T10:48:32.422Z","etag":null,"topics":["cli","es2015","javascript","refactoring","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Quramy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-05T17:21:58.000Z","updated_at":"2024-07-17T15:27:41.000Z","dependencies_parsed_at":"2023-01-14T19:16:58.261Z","dependency_job_id":null,"html_url":"https://github.com/Quramy/better-name","commit_stats":null,"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Quramy%2Fbetter-name","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Quramy%2Fbetter-name/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Quramy%2Fbetter-name/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Quramy%2Fbetter-name/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Quramy","download_url":"https://codeload.github.com/Quramy/better-name/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241190655,"owners_count":19925073,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","es2015","javascript","refactoring","typescript"],"created_at":"2024-10-01T15:09:40.690Z","updated_at":"2025-02-28T17:31:35.785Z","avatar_url":"https://github.com/Quramy.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# better-name\n[![CircleCI](https://circleci.com/gh/Quramy/better-name.svg?style=svg)](https://circleci.com/gh/Quramy/better-name)\n[![Coverage Status](https://coveralls.io/repos/github/Quramy/better-name/badge.svg?branch=master)](https://coveralls.io/github/Quramy/better-name?branch=master)\n[![npm version](https://badge.fury.io/js/better-name.svg)](https://badge.fury.io/js/better-name)\n\nA CLI to move JavaScript(ES2015) module files keeping dependencies.\n\nIf you have the following JavaScript files coupled with import/export dependencies and you want to refactor via moving the `target.js` to another directory.\n\n```js\n// src/index.js\n\nimport { someFn } from './oldFile';\n\nexport default function main() {\n  someFn();\n}\n```\n\n```js\n// src/oldFile.js\n\nexport function someFn() {\n  return 'test';\n}\n```\n\nThis 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:\n\n```js\n// src/index.js\n\nimport { someFn } from './feat/newFile';\n\nexport default function main() {\n  someFn();\n}\n```\n\n## Install\n\n```sh\nnpm -g install better-name\n```\n\n## Usage\n\n```sh\nbetter-name [options] \u003cfromFile\u003e \u003ctoFile\u003e\n```\n\nExec `better-name --help` if you want more details :smile:\n\n### Configure\n\n#### Project file patterns\n\nBy default, this CLI searches files to be replaced via `src/**/*.{js,jsx,mjs,ts,tsx}` glob pattern.\nYou can customize the glob pattern with `--pattern` option or configuring in package.json:\n\n```js\n  /* package.json */\n  \"betterName\": {\n    \"patterns\": [\n      \"src/javascript/**/*.{js,jsx}\",\n      \"src/styles/**/*.css\"\n    ]\n  },\n```\n\n#### Root import\nRoot path mapping using [babel-plugin-root-import](https://github.com/entwicklerstube/babel-plugin-root-import) is supported.\nPath mapping configuration is loaded automaticcaly if your .babelrc has `babel-plugin-root-import` section.\n\nYou also can configure path mapping via package.json such as:\n\n```js\n  /* package.json */\n  \"betterName\": {\n    \"rootImport\": [{\n      \"rootPathPrefix\": \"~\",\n      \"rootPathSuffix\": \"src/js\"\n    }, {\n      \"rootPathPrefix\": \"@\",\n      \"rootPathSuffix\": \"other-src/js\"\n    }, {\n      \"rootPathPrefix\": \"#\",\n      \"rootPathSuffix\": \"../../src/in/parent\"\n    }]\n  }\n```\n\nIf you want to avoid prefixing after replacing, `--normalize-root-import` CLI option or the following package.json setting is available:\n\n```js\n  /* package.json */\n  \"betterName\": {\n    \"normalizeRootImport\": true\n  }\n```\n\n#### Format with Prettier\nThis CLI format your code after replace import declarations if your project has Prettier config file(.prettierrc, .prettierrc.js,,,).\nYou can turn on this behavior passing `--prettier` options to CLI.\n\n## Remarks\n### Available file types\nThis CLI can replace import declarations in the following file types:\n\n- JavaScript: .js, .jsx, .mjs\n- TypeScript: .ts, .tsx\n\nAnd imports non-JavaScript files are allowed. For example:\n\n\n```js\n/* some.component.jsx */\n\nimport styles from './some.component.css';\n\n// ...\n```\n\nHowever, non-JavaScript import(i.e. `@import` in CSS) could not be replaced.\n\n## License\nMIT. See LICENSE file under the this repository.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquramy%2Fbetter-name","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fquramy%2Fbetter-name","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquramy%2Fbetter-name/lists"}