Adding string to javascript files

Viewed 136

I need something like this:

Think that I have already have a project module.(which includes js files,package.json,html files vs)

What I need is to add some strings to specific files.(Not by manually.I need to do it by running extra command from terminal or something else).

For example I need to add extra modules to package.json devdependencies.And add some strings to js files.And I don't want do it by manually.I need that changes to be automatically.(By running extra command or something else.)

How can I create module,project or plugin for that?What can I use for that types of changes? Any suggestion?

1 Answers

You can achieve this using creating simple command here 'add_string' using shell or python etc language and add to it your package.json script.

'npm run add_string' will install new packages and add a string to your javascript files.

package.json

{
  "name": "project",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "add_string": "sh add_string.sh"
  },
  "author": "",
  "license": "ISC"
}

add_string.sh

for pkg in "express" "moment"
do
   npm i $pkg --save
done

for filename in *.js; do
  echo "/**Author name : abc@example.com **/" >> "$filename"
done

Also, you can save extra modules dependencies using npm i --save

Related