tractor-js-file-transformer v0.2.0-beta.0
tractor-js-file-transformer
A bunch of AST manipulation utilities for tractor.
API:
transformIdentifiers:
Renames an identifier within an AST
Arguments:
file:JavaScriptFile- The JavaScript file to manipulateoldName: string- the name of the identifiers that you want to changenewName: string- the new name for the identifierscontextName?: string- a context for selecting the elements, which should be a esquery queryUsage:
import { transformIdentifiers } from 'tractor-js-file-transformer';// Replace all instances of
foowithbartransformIdentifiers(file, 'foo', 'bar');// Replace all instances of
var foowithvar bartransformIdentifiers(file, 'foo', 'bar', 'VariableDeclarator');
transformMetadata:
Renames an metadata object stored in the first comment of a JS file
Arguments:
file:JavaScriptFile- The JavaScript file to manipulateoldName: string- the name of the identifiers that you want to changenewName: string- the new name for the identifierstype?: string- the type of the metadata objectUsage:
import { transformMetadata } from 'tractor-js-file-transformer';// Changes metadata comment from // / { "name": "foo" } / // to // / { "name": "bar" } / transformMetadata(file, 'foo', 'bar');
// Changes metadata comment from // / { "items": { "name": "foo" }, { "name": "baz" } } / // to // / { "items": { "name": "bar" }, { "name": "baz" } } / transformMetadata(file, 'foo', 'bar', 'items');
transformRequirePaths:
Updates the path in a
requirecall when a file moves.Arguments:
file:JavaScriptFile- The JavaScript file to manipulateoptions:TransformRequireOptionsUsage:
import { transformRequirePaths } from 'tractor-js-file-transformer';// Replace //
require('../../../that/goes/to/another/file')// with //require('../../../that/goes/to/a/new/file')transformRequirePaths(file, { fromPath: '/some/path/to/a/file', oldToPath: '/some/path/that/goes/to/another/file', newToPath: '/some/path/that/goes/to/a/new/file' });
Interfaces:
TransformRequireOptions:
interface TransformRequireOptions {
oldFromPath?: string;
newFromPath?: string;
fromPath?: string;
oldToPath?: string;
newToPath?: string;
toPath?: string;
}9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago