How to use package.json scripts to copy files with specific file extension
<p>I am trying out npm as a build tool.</p>

<p>One stumbling block I have encountered is that I need to copy javascript files from one folder to another. The source folder contains typescript files, javascript files and map files, but in the target folder I am only interested in javascript files. </p>

<p>I do not want to make a copy-statement for each file, but would like to copy all .js files. Also, my source folder contains subfolders that also contains javascript files. These need to be copied as well, and maintain the subfolder structure.</p>

<p>What I have tried is using <a href="https://github.com/AvianFlu/ncp" rel="noreferrer">NCP</a> with a filter, but I cannot get the filter to work. I have tested the regex used in the filter and it appears to work fine. The test was done at <a href="http://www.regextester.com" rel="noreferrer">Regex Tester</a> with regular expression <code>.*\.js$</code> and test-strings like <code>main.ts</code>, <code>main.js</code> <code>main.js.map</code> etc, and only the .js strings were matched.</p>

<p>My package json contains the following (abbreviated):</p>

<pre><code>{
    "scripts": {
        "copy": "ncp scripts wwwroot/scripts --filter=\".*(\\\\.js$)\"" 
    }, 
    "devDependencies": { 
        "ncp": "2.0.0.0" 
    }
}
</code></pre>

<p>Since my regex is in a string in a string I have double-escaped it. I have also tried other variations, for example:</p>

<pre><code>--filter=/.*\.js$/g       - compilation error
--filter=/.*\\.js$/g      - no files copied
--filter=\".*\\.js$\"     - no files copied
--filter=\"/.*\\.js$/g\"  - no files copied
(no filter)               - all files copied
</code></pre>

<p>I am in no way married to NCP. If something else works better then I will use that.</p>

<p>So: How do I, inside package.json's scripts section copy only files with a speific extension to another folder? I am pretty sure I have overlooked something blindingly obvious...</p>