node package manager
Easy sharing. Manage teams and permissions with one click. Create a free org »

sync-snippet

sync-snippet

Synchronize code snippet among files.

NPM version

How to use it?

npm i -D sync-snippet

1.Use ////sync-code-snippet:ws:start and ////sync-code-snippet:ws:end to mark snippet area in files.

a.js:

////sync-code-snippet:ws:start 
////sync-code-snippet:ws:end 

b.js:

////sync-code-snippet:ws:start 
var a=1;
////sync-code-snippet:ws:end 

c.js:

////sync-code-snippet:ws:start 
////sync-code-snippet:ws:end 

2.Invoke it in nodejs:

const sync = require("sync-snippet")
 
sync({
    name: "ws", //should be unique in this pc 
    regexp: /\/\/\/\/sync-code-snippet:(\w+):(\w+) */g, //should be like this:  ////sync-code-snippet:ws:end 
    files: [
        {
            path: "/home/blackmiaool/a.js"
        },
        {
            path: "/home/blackmiaool/b.js"
        },
        {
            path: "/home/blackmiaool/c.js"
        },
    ]
});

3.Try to edit the code in the snippet area and check the area in other files

Does it support indent?

Yes. It get the indentation by calculating the spaces between the column0 and the start mark and synchronize the snippet area accordingly. Remember to make the snippet area and the start mark have the same indent.

Wrong:

////sync-code-snippet:ws:start 
  var a=1;
////sync-code-snippet:ws:end 

Right:

  ////sync-code-snippet:ws:start 
  var a=1;
  ////sync-code-snippet:ws:end 

How to test it?

Clone the repo, run the start.js and try to edit the files in ./test folder.