1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | var __importStar = (this && this.__importStar) || function (mod) {
|
7 | if (mod && mod.__esModule) return mod;
|
8 | var result = {};
|
9 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
10 | result["default"] = mod;
|
11 | return result;
|
12 | };
|
13 | Object.defineProperty(exports, "__esModule", { value: true });
|
14 | const fs = __importStar(require("fs-extra"));
|
15 | const path = __importStar(require("path"));
|
16 | const glob = __importStar(require("glob"));
|
17 | const utils_1 = require("./utils");
|
18 |
|
19 | let basePath = path.resolve('.');
|
20 | let baseConfig = utils_1.readJSONFile(path.join(basePath, 'package.json'));
|
21 | let packageConfig = baseConfig.workspaces;
|
22 | let skipSource = process.argv.indexOf('packages') === -1;
|
23 | let skipExamples = process.argv.indexOf('examples') === -1;
|
24 |
|
25 | for (let i = 0; i < packageConfig.length; i++) {
|
26 | if (skipSource && packageConfig[i] === 'packages/*') {
|
27 | continue;
|
28 | }
|
29 | if (skipExamples && packageConfig[i] === 'examples/*') {
|
30 | continue;
|
31 | }
|
32 | let files = glob.sync(path.join(basePath, packageConfig[i]));
|
33 | for (let j = 0; j < files.length; j++) {
|
34 | try {
|
35 | handlePackage(files[j]);
|
36 | }
|
37 | catch (e) {
|
38 | console.error(e);
|
39 | }
|
40 | }
|
41 | }
|
42 |
|
43 |
|
44 |
|
45 | function handlePackage(packagePath) {
|
46 |
|
47 | let packageJSONPath = path.join(packagePath, 'package.json');
|
48 | let data;
|
49 | try {
|
50 | data = require(packageJSONPath);
|
51 | }
|
52 | catch (e) {
|
53 | console.log('skipping', packagePath);
|
54 | return;
|
55 | }
|
56 | if (!data.scripts || !data.scripts.clean) {
|
57 | return;
|
58 | }
|
59 | let targets = data.scripts.clean.split('&&');
|
60 | for (let i = 0; i < targets.length; i++) {
|
61 | let target = targets[i].replace('rimraf', '').trim();
|
62 | target = path.join(packagePath, target);
|
63 | if (fs.existsSync(target)) {
|
64 | fs.removeSync(target);
|
65 | }
|
66 | }
|
67 | }
|
68 |
|
\ | No newline at end of file |