12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- "use strict";
- const fs = require("fs");
- const path = require("path");
- const rimrafSync = require("rimraf").sync;
- exports.removeDirSync = function removeDirSync(dir) {
- fs.readdirSync(dir);
- rimrafSync(dir, {
- disableGlob: true,
- });
- };
- exports.copySubtreeSync = function copySubtreeSync(src, dest) {
- const files = fs.readdirSync(src);
- if (!fs.existsSync(dest)) {
- fs.mkdirSync(dest);
- }
- files.forEach(function (filename) {
- const srcFile = path.join(src, filename);
- const file = path.join(dest, filename);
- const stats = fs.statSync(srcFile);
- if (stats.isDirectory()) {
- copySubtreeSync(srcFile, file);
- } else {
- fs.writeFileSync(file, fs.readFileSync(srcFile));
- }
- });
- };
- exports.ensureDirSync = function ensureDirSync(dir) {
- if (fs.existsSync(dir)) {
- return;
- }
- const parts = dir.split(path.sep);
- let i = parts.length;
- while (i > 1 && !fs.existsSync(parts.slice(0, i - 1).join(path.sep))) {
- i--;
- }
- if (i < 0 || (i === 0 && parts[0])) {
- throw new Error();
- }
- while (i <= parts.length) {
- fs.mkdirSync(parts.slice(0, i).join(path.sep));
- i++;
- }
- };
|