Skip to content
This repository was archived by the owner on May 16, 2020. It is now read-only.

Commit fc7d6c0

Browse files
feat: add in more files for the clean command and more flags for control
1 parent ab687a5 commit fc7d6c0

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

packages/atlauncher-scripts/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,14 @@ This will build the files in the `src/` directory with babel and put the compile
5353

5454
### clean
5555

56-
`atlauncher-scripts clean [--dry-run]`
56+
`atlauncher-scripts clean [--dry-run] [--lock-files] [--node-modules]`
5757

5858
You can provide a `--dry-run` switch to not make any changes to the file system.
5959

60+
You can provide a `--lock-files` switch to clean up Yarn and NPM lock files, which aren't cleaned by default.
61+
62+
You can provide a `--node-modules` switch to clean up the `node_modules` folder, which isn't cleaned by default.
63+
6064
You can optionally provide an array of extra folders/files to clean in your `package.json`:
6165

6266
```json

packages/atlauncher-scripts/scripts/clean.js

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,53 @@ const rimraf = require('rimraf');
44

55
const utils = require('../utils');
66

7-
const baseThingsToClean = ['dist'];
7+
const baseThingsToClean = ['coverage/', 'dist/', 'lerna-debug.log', 'yarn-error.log'];
8+
9+
const lockFilesToClean = ['package-lock.json', 'yarn.lock'];
10+
11+
const nodeModulesToClean = ['node_modules/'];
812

913
const args = process.argv.slice(2);
1014
let dryRun = false;
15+
let lockFiles = false;
16+
let nodeModules = false;
1117

1218
if (args.length) {
1319
args.forEach((arg) => {
1420
if (arg === '--dry-run') {
1521
console.info(chalk`{black.bgWhite Doing a dry run. No changes will be made.\n}`);
1622
dryRun = true;
1723
}
24+
25+
if (arg === '--lock-files') {
26+
lockFiles = true;
27+
}
28+
29+
if (arg === '--node-modules') {
30+
nodeModules = true;
31+
}
1832
});
1933
}
2034

21-
const projectBasePath = utils.getProjectPath();
35+
const projectPaths = [utils.getProjectPath()].concat(utils.getExplicitProjectPaths());
2236

2337
const extraToClean = utils.getConfigFromPackageJson('extraToClean', []);
2438

25-
const toClean = Array.prototype.concat(baseThingsToClean, extraToClean);
39+
const toClean = Array.prototype.concat(
40+
baseThingsToClean,
41+
lockFiles && lockFilesToClean,
42+
nodeModules && nodeModulesToClean,
43+
extraToClean,
44+
);
2645

27-
toClean.forEach((thePathToClean) => {
28-
const pathToClean = path.join(projectBasePath, thePathToClean);
46+
projectPaths.forEach((projectPath) => {
47+
toClean.forEach((thePathToClean) => {
48+
const pathToClean = path.join(projectPath, thePathToClean);
2949

30-
console.info(chalk`{white.bgRed Deleting} {black.bgWhite ${pathToClean}}`);
50+
console.info(chalk`{white.bgRed Deleting} {black.bgWhite ${pathToClean}}`);
3151

32-
if (!dryRun) {
33-
rimraf.sync(pathToClean);
34-
}
52+
if (!dryRun) {
53+
rimraf.sync(pathToClean);
54+
}
55+
});
3556
});

0 commit comments

Comments
 (0)