Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@intuita-inc/filemod-engine

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@intuita-inc/filemod-engine

## Local Installation pnpm link --global # link this local package system-wide

  • 1.0.1
  • unpublished
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

@intuita-inc/filemod-engine

Local Installation

pnpm link --global # link this local package system-wide

Usage

filemod-engine --help

Usage with a declarative filemod

filemod-engine transform [transformFilePath] [rootDirectoryPath]

Where:

  • transformFilePath is the absolute path to the YML file (DSL) that contains the transform declaration
  • rootDirectoryPath is the absolute path to the root of your project

You can also pass --dryRun if you want to see what changes will be written.

In order to use a declarative filemod, one needs to be written. Such codemods are written in YAML, like this:

version: 1
posix: true
includePattern: '**/pages/**/*.{js,jsx,ts,tsx}'
excludePatterns:
    - '**/node_modules/**'
    - '**/pages/api/**'
deleteRules:
    fileRoot:
        - '_app'
        - '_document'
        - '_error'
replaceRules:
    - replaceDirectoryName:
          - 'pages'
          - 'app'
    - appendDirectoryName:
          - '@fileRoot'
          - fileRootNot: 'index'
    - replaceFileRoot: 'page'
tests:
    - - 'move'
      - '/opt/project/pages/index.tsx'
      - '/opt/project/app/page.tsx'

You need to define the following properties:

  • version: 1
  • posix (for now we support only POSIX platforms)
  • includePattern - the glob pattern to run against the root directory path
  • excludePattern - the glob pattern to run against the root directory path for exclusion of file paths
  • deleteRules - the union of rules that tell whether to remove the files or not
  • replaceRules - the ordered list of rules that modify the filePath
  • tests - the set of tests for patterns

How to work on paths?

Any path is split into the following elements:

  • pathRoot
  • directoryNames
  • fileRoot
  • fileExtension

For instance, a path like opt/project/pages/index.tsx has the following properties (defined using pseudocode):

  • pathRoot = "/"
  • directoryNames = ["", "project", "pages"]
  • fileRoot = "index"
  • fileExtension = "tsx"

These properties are accessible for reading and writing in the DSL.

Delete Rules

The fileRoot equals rule delete a file path if any of the provided labels match the file root. Check the example below:

fileRoot:
    - '_app'
    - '_document'
    - '_error'

Replace Rules

Each replace rule with have a read/write access to all the 4 path properties mentioned before. Each rule is executed in the declaration order.

The replaceDirectoryName rule replaces any directory Name that matches the 0th literal with the 1st literal. Check the example below:

replaceDirectoryName:
        - 'pages'
        - 'app'

The appendDirectoryName rule add a new directory name to the end of the list of directory names based on a condition. In the following example, if the file root does not equal index, a new directory named the same as file root will be appended.

appendDirectoryName:
      - '@fileRoot'
      - fileRootNot: 'index'

The replaceFileRoot rule replaces the the existing file root with a new literal, like page in the following example:

replaceFileRoot: 'page'

Usage with an imperative codemod

TBD

FAQs

Package last updated on 03 Feb 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc