• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rokucommunity / ropm / #874

23 Jan 2024 06:13PM CUT coverage: 89.291%. Remained the same
#874

push

GitHub
Merge 741ad53e2 into 803e66631

517 of 626 branches covered (0.0%)

Branch coverage included in aggregate %.

642 of 672 relevant lines covered (95.54%)

66.73 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.0
/src/commands/CleanCommand.ts
1
import * as path from 'path';
1✔
2
import * as fsExtra from 'fs-extra';
1✔
3
import type { RopmPackageJson } from '../util';
4
import { util } from '../util';
1✔
5
import { InitCommand } from './InitCommand';
1✔
6
import * as del from 'del';
1✔
7

8
export class CleanCommand {
1✔
9
    constructor(
10
        public args: CleanCommandArgs
25✔
11
    ) {
12
    }
13

14
    private hostPackageJson?: RopmPackageJson;
15

16
    private get hostRootDir() {
17
        if (this.args.rootDir) {
25!
18
            return path.resolve(this.cwd, this.args.rootDir);
×
19
        } else {
20
            const packageJsonRootDir = this.hostPackageJson?.ropm?.rootDir;
25!
21
            if (packageJsonRootDir) {
25✔
22
                return path.resolve(this.cwd, packageJsonRootDir);
7✔
23
            } else {
24
                return this.cwd;
18✔
25
            }
26
        }
27
    }
28

29
    /**
30
     * Determine if we should load the host package.json from disk or not
31
     */
32
    private get skipLoadHostPackageJson() {
33
        return !!this.args.rootDir;
25✔
34
    }
35

36
    /**
37
     * A "host" is the project we are currently operating upon. This method
38
     * finds the package.json file for the current host
39
     */
40
    private async loadHostPackageJson() {
41
        if (this.skipLoadHostPackageJson === false) {
25!
42
            //if the host doesn't currently have a package.json
43
            if (await fsExtra.pathExists(path.resolve(this.cwd, 'package.json')) === false) {
25✔
44
                console.log('Creating package.json');
2✔
45
                //init package.json for the host
46
                await new InitCommand({ cwd: this.cwd, force: true }).run();
2✔
47
            }
48
            this.hostPackageJson = await util.getPackageJson(this.cwd);
25✔
49
        }
50
    }
51

52
    public async run() {
53
        await this.loadHostPackageJson();
25✔
54
        await this.deleteAllRokuModulesFolders();
25✔
55
    }
56

57
    private async deleteAllRokuModulesFolders() {
58
        const rokuModulesFolders = await util.globAll([
25✔
59
            '*/roku_modules',
60
            '!node_modules/**/*'
61
        ], {
62
            cwd: this.hostRootDir,
63
            absolute: true
64
        });
65

66
        //delete the roku_modules folders
67
        await Promise.all(
25✔
68
            rokuModulesFolders.map(async (rokuModulesDir) => {
69
                console.log(`ropm: deleting ${rokuModulesDir}`);
7✔
70
                await del(rokuModulesDir, {
7✔
71
                    force: true
72
                });
73

74
                //if the parent dir is now empty, delete that folder too
75
                const parentDir = path.dirname(rokuModulesDir);
7✔
76
                if (await util.isEmptyDir(parentDir)) {
7!
77
                    console.log(`ropm: deleting empty ${parentDir}`);
7✔
78
                    await del(parentDir, {
7✔
79
                        force: true
80
                    });
81
                }
82
            })
83
        );
84
    }
85

86
    private get cwd() {
87
        if (this.args?.cwd) {
77!
88
            return path.resolve(process.cwd(), this.args?.cwd);
77!
89
        } else {
90
            return process.cwd();
×
91
        }
92
    }
93
}
94

95
export interface CleanCommandArgs {
96
    /**
97
     * The current working directory for the command.
98
     */
99
    cwd?: string;
100
    /**
101
     * The path to the root directory for the project that should be cleaned
102
     */
103
    rootDir?: string;
104
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc