-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclean.js
More file actions
36 lines (30 loc) · 1.06 KB
/
clean.js
File metadata and controls
36 lines (30 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// scripts/clean.js
const fs = require("fs");
const path = require("path");
const rimraf = require("rimraf");
const config = require("./config/all");
const { merge } = require("lodash");
const messages = require("./messages");
// Set application's environment
const env = process.env.NODE_ENV || config.environment || "development";
let envConfig;
if (fs.existsSync(path.join(__dirname, "config", env + ".js"))) {
envConfig = require(path.join(__dirname, "config", env));
} else {
envConfig = require(path.join(__dirname, "config", "development"));
}
const appConfig = merge(config, envConfig);
const pathsToDelete = [".ledger", ".token", "unprocessible"];
// Preserve .checkpoint only if explicitly set in the configuration
if (!appConfig.checkpoint?.preserve) {
pathsToDelete.push(".checkpoint");
}
pathsToDelete.forEach((fileOrDir) => {
const fullPath = path.join(__dirname, fileOrDir);
if (fs.existsSync(fullPath)) {
rimraf.sync(fullPath);
console.log(messages.clean.deleted(fileOrDir));
} else {
console.log(messages.clean.notFound(fileOrDir));
}
});