copyFile.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /**
  2. * Copyright 1999-2019 Seata.io Group.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. const fs = require('fs');
  17. const path = require('path');
  18. // 默认打包存放地址
  19. const srcDir = path.join(__dirname, '../dist');
  20. // 打包后文件存放地址
  21. const destDir = path.join(__dirname, '../../');
  22. const mkdir = dir => {
  23. if (!fs.existsSync(dir)) {
  24. fs.mkdirSync(dir);
  25. }
  26. };
  27. const copyList = ['js/main.js', 'css/main.css'];
  28. copyList.forEach(_fileName => {
  29. const srcFileName = path.join(srcDir, _fileName);
  30. const destFileName = path.join(destDir, _fileName);
  31. if (!fs.existsSync(srcFileName)) {
  32. return;
  33. }
  34. mkdir(path.dirname(destFileName));
  35. const readStream = fs.createReadStream(srcFileName);
  36. const writeStream = fs.createWriteStream(destFileName);
  37. readStream.pipe(writeStream);
  38. });