2016-10-02 178 views
0

我使用npm创建构建脚本。Shell命令将html文件复制到正确的文件夹

构建脚本包括typescript编译。

打字稿编译将文件夹结构从ts文件夹复制到dist/js文件夹。

的TS文件夹就像

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

    two 
    -- two.html 
    -- two.ts 

,并建立了DIST/JS文件夹是像

js 
-- one 
    -- one.js 

    two 
    -- two.js  

的TS文件夹总是包含HTML,我需要复制到JS编译有后跑。

我可以使用什么shell命令将html文件从ts文件夹复制到输出js文件夹中的正确文件夹中。

更新

我曾尝试下面的命令

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

,但得到的

发现错误:CP:未知的主或经营

UPDATE

在TS文件夹我有

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

我需要的JS文件夹是

js 
    --home 
     --home.html 
     --home.js 
+0

'find','cpio'和'tar'是你的朋友 – GMichael

+0

GMichael我还看着你的建议,并更新了我的问题,你可以提供任何更多的建议如何我可以做到这一点。 – ttmt

+0

查看'find'的* man *页面:为了在找到的文件上运行命令,您需要使用'-exec'选项。 – user1934428

回答

1

我通常做到以下几点:

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

我想你想复制所有保存目录结构的app/tsapp/js目录中的'* .html'文件,文件名中没有空格。

还有一些方法。 findcpio组合通常出现在find手册页喜欢这里:https://linux.die.net/man/1/find

+0

GMichael如何在我的脚本中工作 - '“build:copy-html”:“tar -cf - 'cd app/ts; find。-name'* .html''|(cd app/js; tar - xf - )“,' – ttmt

+0

如果我运行脚本,我会出错 - 'sh:line 0:cd:app/js:没有这样的文件或目录 tar:./home/home.html:Can not stat:No such文件或目录 tar:错误退出延迟以前的错误。' – ttmt

+0

@ttmt'app/ts'的真正完整路径是什么? – GMichael

相关问题