npm.io
1.0.1 • Published 7 years agoCLI

action-comment

Licence
ISC
Version
1.0.1
Deps
1
Size
7 kB
Vulns
0
Weekly
0

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:

  • content: String
  • line: Int line number
  • position: array: [init position, end position]

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