UNPKG

2.37 kBJavaScriptView Raw
1"use strict";
2/* -----------------------------------------------------------------------------
3| Copyright (c) Jupyter Development Team.
4| Distributed under the terms of the Modified BSD License.
5|----------------------------------------------------------------------------*/
6var __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};
13Object.defineProperty(exports, "__esModule", { value: true });
14const fs = __importStar(require("fs-extra"));
15const path = __importStar(require("path"));
16const glob = __importStar(require("glob"));
17const utils_1 = require("./utils");
18// Get all of the packages.
19const basePath = path.resolve('.');
20const baseConfig = utils_1.readJSONFile(path.join(basePath, 'package.json'));
21const packageConfig = baseConfig.workspaces;
22const skipSource = process.argv.indexOf('packages') === -1;
23const skipExamples = process.argv.indexOf('examples') === -1;
24// Handle the packages
25for (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 const 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 * Handle an individual package on the path - update the dependency.
44 */
45function handlePackage(packagePath) {
46 // Read in the package.json.
47 const packageJSONPath = path.join(packagePath, 'package.json');
48 let data;
49 try {
50 data = require(packageJSONPath);
51 }
52 catch (e) {
53 console.debug('skipping', packagePath);
54 return;
55 }
56 if (!data.scripts || !data.scripts.clean) {
57 return;
58 }
59 const 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//# sourceMappingURL=clean-packages.js.map
\No newline at end of file