ttmt ttmt - 2 months ago 8
TypeScript Question

Shell command to copy just html files to the correct folder

I'm creating a build script using npm.

The build script includes typescript compiling.

The typescript compiling copies the folder structure from a ts folder to a dist/js folder.

The ts folder is like

ts
-- one
-- one.html
-- one.ts

two
-- two.html
-- two.ts


And the dist/js folder created is like

js
-- one
-- one.js

two
-- two.js


The ts folders always contain html that I need to copy to the js after the compiling has run.

What shell command can I use to copy the html from the ts folder to the correct folder in the outputed js folder.

Update

I have tried the following command

"build:copy-html": "find ./app/ts -name '*.html' cp ./dist/js \\;",


but get an error of

find: cp: unknown primary or operator

UPDATE

In the ts folder I have

ts
--home
--home.html
--home.ts


I need the js folder to be

js
--home
--home.html
--home.js

Answer

I usually do the following:

  (cd app/ts; tar -cf - `find . -name '*.html' `) | (cd app/dist/js ; tar -xf -)

I suppose that you want to copy all the '*.html' files from app/ts to app/js directory keeping the directory structure and there are no spaces in the file names.

There are some more methods. find and cpio combination usually appears in the manual page of find like here: https://linux.die.net/man/1/find