Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
67 lines (51 loc) · 1.73 KB
/
Copy pathindex.js
File metadata and controls
67 lines (51 loc) · 1.73 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
7C33
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"use strict";
const path = require("path");
const pMap = require("p-map");
const { Command } = require("@lerna/command");
const { rimrafDir } = require("@lerna/rimraf-dir");
const { promptConfirmation } = require("@lerna/prompt");
const { getFilteredPackages } = require("@lerna/filter-options");
const { pulseTillDone } = require("@lerna/pulse-till-done");
module.exports = factory;
function factory(argv) {
return new CleanCommand(argv);
}
class CleanCommand extends Command {
get requiresGit() {
return false;
}
initialize() {
let chain = Promise.resolve();
chain = chain.then(() => getFilteredPackages(this.packageGraph, this.execOpts, this.options));
chain = chain.then((filteredPackages) => {
this.directoriesToDelete = filteredPackages.map((pkg) => pkg.nodeModulesLocation);
});
return chain.then(() => {
if (this.options.yes) {
return true;
}
this.logger.info("", "Removing the following directories:");
this.logger.info(
"clean",
this.directoriesToDelete.map((dir) => path.relative(this.project.rootPath, dir)).join("\n")
);
return promptConfirmation("Proceed?");
});
}
execute() {
this.enableProgressBar();
const tracker = this.logger.newItem("clean");
const mapper = (dirPath) => {
tracker.info("clean", "removing", dirPath);
return pulseTillDone(rimrafDir(dirPath)).then(() => {
tracker.completeWork(1);
});
};
tracker.addWork(this.directoriesToDelete.length);
return pMap(this.directoriesToDelete, mapper, { concurrency: this.concurrency }).then(() => {
tracker.finish();
this.logger.success("clean", "finished");
});
}
}
module.exports.CleanCommand = CleanCommand;