• Stars
    star
    132
  • Rank 274,205 (Top 6 %)
  • Language
    JavaScript
  • Created about 7 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🛠️ A codemod to do large-scale refactor of your relative path imports to alias.

Travis build status

A tiny cli tool (codemod) to replace relative paths to defined alias in your project.

You can use anything to define alias for your files/directory (Aliasing modules) and then use this module to refactor your code to start using those alias instead of relative paths.

Install

npm install -g relative-to-alias

Usage

On your project root directory

relative-to-alias --src ./src --alias utils --alias-path ./src/util

Note: alias-path is relative to root-path argument. while src path is relative to the current directory.

Options:
  --version                           Show version number  [boolean]
  --root-path, -r                     Root path of your project
                                      folder. Your imports /
                                      requires will be resolved
                                      based on this
                                            [string] [default: "./"]
  --src, -s                           Source folder or file in which
                                      you want to run the script
                                                 [string] [required]
  --alias, -a                         Alias for a given path
                                                 [string] [required]
  --alias-path, --ap                  Path which you want to be
                                      replaced with alias
                                                 [string] [required]
  --extensions, -e                    File extensions which has to
                                      be parsed.
                                        [string] [default: "js,jsx"]
  --language, -l                      Typed language the project is
                                      in (flow/typescript).
                                          [string] [default: "flow"]
  --include-alias-path-directory, -i  If true it will replace path
                                      to alias for the alias path
                                      directory.
                                          [boolean] [default: false]
  --ignore                            Exclude given glob paths for
                                      the parsing.
                         [array] [default: ["./**/node_modules/**"]]
  --help                              Show help            [boolean]

Example

Consider this folder directory

|-- src
|   |-- util
|   |   |-- common.js
|   |-- index.js
|   |-- component
|   |   |-- header.js
|   |   |-- body.js
|   |   |-- util
|   |   |   |-- common.js

-- index.js

import {debounce} from './util/common';
/***
 Other code
***/

-- header.js

import {debounce} from '../util/common';
import {hideScrollbar} from './util/common'; //This will not change as its not on alias path

/***
 Other code
***/

-- body.js

const {debounce} = require('../util/common');
/***
 Other code
***/

After compile

-- index.js

import {debounce} from 'utils/common';
/***
 Other code
***/

-- header.js

import {debounce} from 'utils/common';
import {hideScrollbar} from './util/common'; //This will not change as its not on alias path

/***
 Other code
***/

-- body.js

const {debounce} = require('utils/common');
/***
 Other code
***/

Ignoring folders

By default node_modules are excluded from parsing, you may want to override ignore option. You can pass multiple glob patterns space separated.

relative-to-alias --src ./src --alias utils --alias-path ./src/util --ignore node_modules/**/* test/**/*

Note: If you are passing ignore option, you might have to define node_modules pattern again (only if the node_module folder is inside the provided src) as the option overrides the default value.

Aliasing modules

You can use one of the following to define alias for your files/directory in your application.

Like this

⭐ this repo

Notes

  • This is a codemod which will replace your source files, so make sure to either backup or commit uncommitted changes before running this tool.

More Repositories

1

react-number-format

React component to format numbers in an input or as a text.
JavaScript
3,858
star
2

iv-viewer

A zooming and panning plugin inspired by google photos for your web images.
JavaScript
449
star
3

patternLock

A light weight plugin to simulate android like pattern lock interface for your hybrid app or website.
JavaScript
378
star
4

angulargrid

Pinterest like responsive masonry grid system for angular
JavaScript
277
star
5

radialIndicator

A simple and light weight circular indicator / progressbar plugin.
JavaScript
232
star
6

react-meta-tags

Handle document meta/head tags in isomorphic react with ease.
JavaScript
226
star
7

contextMenu.js

contextMenu.js is a plugin to create windows like context menu with keyboard interaction, different type of inputs ,trigger events and much more.
JavaScript
208
star
8

ScrollMenu

A new interface to replace your old boring scrollbar
JavaScript
201
star
9

jsonQ

A JavaScript library to make manipulation and extraction of data from a JSON very easy and fast.
JavaScript
201
star
10

FlakeId

Twittter Snowflake like unique id generator plugin for nodejs and browser
JavaScript
76
star
11

modalBox.js

A very light weight and minimal plugin to display modal window.
JavaScript
43
star
12

patternCaptcha

Android like pattern matching captcha system for your node webapps.
JavaScript
42
star
13

github-turbo-pr

Chrome extension to optimize github for handling big pull request. 🚀
JavaScript
25
star
14

eventPause.js

eventPause is a tiny plugin with lots of methods to control events. So whenever you want you can pause and activate any event.
JavaScript
21
star
15

create-effect

A small utility to create custom hooks using useEffect
JavaScript
9
star
16

fqueue

A micro-plugin to queue function execution to handle asynchronous flow and stepping through functions.
JavaScript
7
star
17

coequal.js

coequal is a small utility function to check equality of all data types and objects in JavaScript.
JavaScript
6
star
18

node-website-build-script

Boilerplate to use node.js as a build script for web projects.
CSS
5
star
19

LongListScroller

A small plugin to handle long list scroll using IScroll
JavaScript
3
star
20

findR.js

A find and replace JavaScript plugin for webpages.
JavaScript
3
star
21

deferred

A mini deferred plugin, having just what you need
JavaScript
2
star
22

ask-me-anything

A place where you can ask me anything about frontend, architecture, performance or general career stuff
2
star
23

number-format-app

JavaScript
1
star
24

class-to-function-with-react-hooks

Examples to map lifecycle method of a class component to a functional component with react hooks
JavaScript
1
star
25

isomorphic_react_sample

An isomorphic react sample app.
JavaScript
1
star
26

babel-plugin-react-create-element-alias

A babel plugin to replace React.createElement to an alias
JavaScript
1
star
27

patch-commits

Patch all commits to have desired changes in a branch
JavaScript
1
star
28

s-yadav.github.com

HTML
1
star
29

useful-array-prototypes

This repository contains some useful prototypes which native javascript dont provide or have some perfomance gain over native javascript functionality.
JavaScript
1
star