1.0.1 • Published 5 years ago

action-comment v1.0.1

Weekly downloads
6
License
ISC
Repository
github
Last release
5 years ago

actionComment

Matipulate files, text or scripts, enabling the modification of pre-defined blocks with intelligent comments.

Reason

Need a handler to modify scripts according to need, before running the build

actionComment(content || String, handlers || Object{Function}, commentTag = '#!')

Use

myFile.txt

#!addName:start
My name is #name,
your name
is #name too.
#!addName:end

My name is Jack,
your name
is #!insertName too.

example.js

actionComment(
    fs.readFileSync('myFile.txt').toString(), 
    {
      insertName(){
          return `Jack`
      },
      addName(line){
          return line.replace('#name', 'Martin')
      }
    }, 
    '#!'
)

Result

My name is Martin,
your name
is Martin too.

My name is Jack,
your name
is Jack too.

Create handles

Handlers receive the following parameters:

They may return a promise

Handler example

function handler(content, line, position){
    return line
}

async function handlerPromise(content, line, position){
    return line
}

CLI

action-comment [target: path] --handler [path] --output [path] --tag [string] 
  • target: Target file
  • output: File that will be created, if nothing happens, exit stdout.
  • handler: Nodejs module with handlers
  • tag: Comment tag