mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-14 12:04:39 +00:00
update Rollup, remove some superfluous deps
This commit is contained in:
46
src/api/utils/fs_utils.ts
Normal file
46
src/api/utils/fs_utils.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
export function mkdirp(dir: string) {
|
||||
const parent = path.dirname(dir);
|
||||
if (parent === dir) return;
|
||||
|
||||
mkdirp(parent);
|
||||
|
||||
try {
|
||||
fs.mkdirSync(dir);
|
||||
} catch (err) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
export function rimraf(thing: string) {
|
||||
if (!fs.existsSync(thing)) return;
|
||||
|
||||
const stats = fs.statSync(thing);
|
||||
|
||||
if (stats.isDirectory()) {
|
||||
fs.readdirSync(thing).forEach(file => {
|
||||
rimraf(path.join(thing, file));
|
||||
});
|
||||
|
||||
fs.rmdirSync(thing);
|
||||
} else {
|
||||
fs.unlinkSync(thing);
|
||||
}
|
||||
}
|
||||
|
||||
export function copy(from: string, to: string) {
|
||||
if (!fs.existsSync(from)) return;
|
||||
|
||||
const stats = fs.statSync(from);
|
||||
|
||||
if (stats.isDirectory()) {
|
||||
fs.readdirSync(from).forEach(file => {
|
||||
copy(path.join(from, file), path.join(to, file));
|
||||
});
|
||||
} else {
|
||||
mkdirp(path.dirname(to));
|
||||
fs.writeFileSync(to, fs.readFileSync(from));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user