copy.js 944 B

123456789101112131415161718192021222324252627282930
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. const fs = require('fs');
  6. const path = require('path');
  7. const source = path.join(process.cwd(), process.argv[2]);
  8. const destination = path.join(process.cwd(), process.argv[3]);
  9. // ensure target dir
  10. (function () {
  11. let dirs = [];
  12. let dirname = path.dirname(destination);
  13. while (dirname !== process.cwd()) {
  14. dirs.push(dirname);
  15. dirname = path.dirname(dirname);
  16. }
  17. dirs.reverse();
  18. dirs.forEach((dir) => {
  19. try { fs.mkdirSync(dir); } catch (err) { }
  20. })
  21. })();
  22. fs.writeFileSync(destination, fs.readFileSync(source));
  23. console.log(`Copied ${process.argv[2]} to ${process.argv[3]}`);