@jpp-toolkit/plugin-clean 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Julien Papini
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,25 @@
1
+ import { Command } from "@jpp-toolkit/core";
2
+ import * as _oclif_core_interfaces0 from "@oclif/core/interfaces";
3
+
4
+ //#region src/clean-command.d.ts
5
+ declare class CleanCommand extends Command {
6
+ static summary: string;
7
+ static flags: {
8
+ 'dry-run': _oclif_core_interfaces0.BooleanFlag<boolean>;
9
+ reset: _oclif_core_interfaces0.BooleanFlag<boolean>;
10
+ root: _oclif_core_interfaces0.BooleanFlag<boolean>;
11
+ };
12
+ static examples: {
13
+ description: string;
14
+ command: string;
15
+ }[];
16
+ run(): Promise<void>;
17
+ }
18
+ //#endregion
19
+ //#region src/index.d.ts
20
+ declare const commands: {
21
+ clean: typeof CleanCommand;
22
+ };
23
+ //#endregion
24
+ export { commands };
25
+ //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs ADDED
@@ -0,0 +1,88 @@
1
+ import path from "node:path";
2
+ import { Command } from "@jpp-toolkit/core";
3
+ import { findProjectRoot } from "@jpp-toolkit/utils";
4
+ import { Flags } from "@oclif/core";
5
+ import { execa } from "execa";
6
+ import { rimraf } from "rimraf";
7
+
8
+ //#region src/clean-command.ts
9
+ const RESET_PATTERNS = ["!old", "!tmp"];
10
+ const CLEAN_PATTERNS = [
11
+ ...RESET_PATTERNS,
12
+ "!node_modules",
13
+ "!node_modules/**",
14
+ "**/node_modules/.cache",
15
+ "!**/hooks/_",
16
+ "!**/hooks/_/**",
17
+ "!.env"
18
+ ];
19
+ var CleanCommand = class CleanCommand extends Command {
20
+ static summary = "Remove build artifacts and temporary files from the project.";
21
+ static flags = {
22
+ "dry-run": Flags.boolean({
23
+ char: "d",
24
+ description: "Perform a dry run without deleting files.",
25
+ default: false
26
+ }),
27
+ "reset": Flags.boolean({
28
+ char: "r",
29
+ description: "Reset the project to a clean state.",
30
+ default: false
31
+ }),
32
+ "root": Flags.boolean({
33
+ char: "R",
34
+ description: "Clean from the project root directory.",
35
+ default: false
36
+ })
37
+ };
38
+ static examples = [
39
+ {
40
+ description: "Perform a dry run of the clean command.",
41
+ command: "<%= config.bin %> <%= command.id %> --dry-run"
42
+ },
43
+ {
44
+ description: "Reset the project to a clean state.",
45
+ command: "<%= config.bin %> <%= command.id %> --reset"
46
+ },
47
+ {
48
+ description: "Clean from the project root directory.",
49
+ command: "<%= config.bin %> <%= command.id %> --root"
50
+ }
51
+ ];
52
+ async run() {
53
+ const { flags } = await this.parse(CleanCommand);
54
+ const cwd = flags.root ? findProjectRoot() : process.cwd();
55
+ const { stdout } = await execa("git", [
56
+ "ls-files",
57
+ "--others",
58
+ "--ignored",
59
+ "--exclude-standard",
60
+ "--directory",
61
+ ...(flags.reset ? RESET_PATTERNS : CLEAN_PATTERNS).map((pattern) => `--exclude=${pattern}`)
62
+ ], {
63
+ cwd,
64
+ lines: true
65
+ });
66
+ const paths = stdout.filter((line) => line.trim().length > 0).map((filePath) => path.resolve(cwd, filePath));
67
+ if (paths.length === 0) {
68
+ this.logger.info("No files to clean");
69
+ return;
70
+ }
71
+ if (flags["dry-run"]) {
72
+ this.logger.info("The following files would be removed:");
73
+ this.logger.paths(paths);
74
+ return;
75
+ }
76
+ await rimraf(paths);
77
+ this.logger.success("Cleaned the following files:");
78
+ this.logger.paths(paths);
79
+ }
80
+ };
81
+
82
+ //#endregion
83
+ //#region src/index.ts
84
+ const commands = { clean: CleanCommand };
85
+
86
+ //#endregion
87
+ export { commands };
88
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/clean-command.ts","../src/index.ts"],"sourcesContent":["import path from 'node:path';\n\nimport { Command } from '@jpp-toolkit/core';\nimport { findProjectRoot } from '@jpp-toolkit/utils';\nimport { Flags } from '@oclif/core';\nimport { execa } from 'execa';\nimport { rimraf } from 'rimraf';\n\nconst RESET_PATTERNS = ['!old', '!tmp'];\nconst CLEAN_PATTERNS = [\n ...RESET_PATTERNS,\n '!node_modules',\n '!node_modules/**',\n '**/node_modules/.cache',\n '!**/hooks/_',\n '!**/hooks/_/**',\n '!.env',\n];\n\nexport class CleanCommand extends Command {\n static override summary = 'Remove build artifacts and temporary files from the project.';\n\n static override flags = {\n 'dry-run': Flags.boolean({\n char: 'd',\n description: 'Perform a dry run without deleting files.',\n default: false,\n }),\n 'reset': Flags.boolean({\n char: 'r',\n description: 'Reset the project to a clean state.',\n default: false,\n }),\n 'root': Flags.boolean({\n char: 'R',\n description: 'Clean from the project root directory.',\n default: false,\n }),\n };\n\n static override examples = [\n {\n description: 'Perform a dry run of the clean command.',\n command: '<%= config.bin %> <%= command.id %> --dry-run',\n },\n {\n description: 'Reset the project to a clean state.',\n command: '<%= config.bin %> <%= command.id %> --reset',\n },\n {\n description: 'Clean from the project root directory.',\n command: '<%= config.bin %> <%= command.id %> --root',\n },\n ];\n\n public async run(): Promise<void> {\n const { flags } = await this.parse(CleanCommand);\n\n const cwd = flags.root ? findProjectRoot() : process.cwd();\n const patterns = flags.reset ? RESET_PATTERNS : CLEAN_PATTERNS;\n\n const { stdout } = await execa(\n 'git',\n [\n 'ls-files',\n '--others',\n '--ignored',\n '--exclude-standard',\n '--directory',\n ...patterns.map((pattern) => `--exclude=${pattern}`),\n ],\n { cwd, lines: true },\n );\n\n const paths = stdout\n .filter((line) => line.trim().length > 0)\n .map((filePath) => path.resolve(cwd, filePath));\n\n if (paths.length === 0) {\n this.logger.info('No files to clean');\n return;\n }\n\n if (flags['dry-run']) {\n this.logger.info('The following files would be removed:');\n this.logger.paths(paths);\n return;\n }\n\n await rimraf(paths);\n\n this.logger.success('Cleaned the following files:');\n this.logger.paths(paths);\n }\n}\n","import { CleanCommand } from './clean-command';\n\nexport const commands = {\n clean: CleanCommand,\n};\n"],"mappings":";;;;;;;;AAQA,MAAM,iBAAiB,CAAC,QAAQ,OAAO;AACvC,MAAM,iBAAiB;CACnB,GAAG;CACH;CACA;CACA;CACA;CACA;CACA;CACH;AAED,IAAa,eAAb,MAAa,qBAAqB,QAAQ;CACtC,OAAgB,UAAU;CAE1B,OAAgB,QAAQ;EACpB,WAAW,MAAM,QAAQ;GACrB,MAAM;GACN,aAAa;GACb,SAAS;GACZ,CAAC;EACF,SAAS,MAAM,QAAQ;GACnB,MAAM;GACN,aAAa;GACb,SAAS;GACZ,CAAC;EACF,QAAQ,MAAM,QAAQ;GAClB,MAAM;GACN,aAAa;GACb,SAAS;GACZ,CAAC;EACL;CAED,OAAgB,WAAW;EACvB;GACI,aAAa;GACb,SAAS;GACZ;EACD;GACI,aAAa;GACb,SAAS;GACZ;EACD;GACI,aAAa;GACb,SAAS;GACZ;EACJ;CAED,MAAa,MAAqB;EAC9B,MAAM,EAAE,UAAU,MAAM,KAAK,MAAM,aAAa;EAEhD,MAAM,MAAM,MAAM,OAAO,iBAAiB,GAAG,QAAQ,KAAK;EAG1D,MAAM,EAAE,WAAW,MAAM,MACrB,OACA;GACI;GACA;GACA;GACA;GACA;GACA,IAVS,MAAM,QAAQ,iBAAiB,gBAU5B,KAAK,YAAY,aAAa,UAAU;GACvD,EACD;GAAE;GAAK,OAAO;GAAM,CACvB;EAED,MAAM,QAAQ,OACT,QAAQ,SAAS,KAAK,MAAM,CAAC,SAAS,EAAE,CACxC,KAAK,aAAa,KAAK,QAAQ,KAAK,SAAS,CAAC;AAEnD,MAAI,MAAM,WAAW,GAAG;AACpB,QAAK,OAAO,KAAK,oBAAoB;AACrC;;AAGJ,MAAI,MAAM,YAAY;AAClB,QAAK,OAAO,KAAK,wCAAwC;AACzD,QAAK,OAAO,MAAM,MAAM;AACxB;;AAGJ,QAAM,OAAO,MAAM;AAEnB,OAAK,OAAO,QAAQ,+BAA+B;AACnD,OAAK,OAAO,MAAM,MAAM;;;;;;AC1FhC,MAAa,WAAW,EACpB,OAAO,cACV"}
@@ -0,0 +1,8 @@
1
+ export default {
2
+ description: 'Plugin that add the clean command to the jpp cli.',
3
+ commands: {
4
+ strategy: 'explicit',
5
+ target: './dist/index.mjs',
6
+ identifier: 'commands',
7
+ },
8
+ };
@@ -0,0 +1,54 @@
1
+ {
2
+ "commands": {
3
+ "clean": {
4
+ "aliases": [],
5
+ "args": {},
6
+ "examples": [
7
+ {
8
+ "description": "Perform a dry run of the clean command.",
9
+ "command": "<%= config.bin %> <%= command.id %> --dry-run"
10
+ },
11
+ {
12
+ "description": "Reset the project to a clean state.",
13
+ "command": "<%= config.bin %> <%= command.id %> --reset"
14
+ },
15
+ {
16
+ "description": "Clean from the project root directory.",
17
+ "command": "<%= config.bin %> <%= command.id %> --root"
18
+ }
19
+ ],
20
+ "flags": {
21
+ "dry-run": {
22
+ "char": "d",
23
+ "description": "Perform a dry run without deleting files.",
24
+ "name": "dry-run",
25
+ "allowNo": false,
26
+ "type": "boolean"
27
+ },
28
+ "reset": {
29
+ "char": "r",
30
+ "description": "Reset the project to a clean state.",
31
+ "name": "reset",
32
+ "allowNo": false,
33
+ "type": "boolean"
34
+ },
35
+ "root": {
36
+ "char": "R",
37
+ "description": "Clean from the project root directory.",
38
+ "name": "root",
39
+ "allowNo": false,
40
+ "type": "boolean"
41
+ }
42
+ },
43
+ "hasDynamicHelp": false,
44
+ "hiddenAliases": [],
45
+ "id": "clean",
46
+ "pluginAlias": "@jpp-toolkit/plugin-clean",
47
+ "pluginName": "@jpp-toolkit/plugin-clean",
48
+ "pluginType": "core",
49
+ "strict": true,
50
+ "summary": "Remove build artifacts and temporary files from the project."
51
+ }
52
+ },
53
+ "version": "0.0.11"
54
+ }
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@jpp-toolkit/plugin-clean",
3
+ "version": "0.0.11",
4
+ "description": "Plugin that add the clean command to the jpp cli.",
5
+ "keywords": [
6
+ "jpp",
7
+ "plugin",
8
+ "clean"
9
+ ],
10
+ "homepage": "https://github.com/jpapini/jpp-toolkit/tree/main/packages/plugin-clean#readme",
11
+ "bugs": {
12
+ "url": "https://github.com/jpapini/jpp-toolkit/issues"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/jpapini/jpp-toolkit.git",
17
+ "directory": "packages/plugin-clean"
18
+ },
19
+ "license": "MIT",
20
+ "author": "Julien Papini <julien.papini@gmail.com> (https://github.com/jpapini)",
21
+ "type": "module",
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/index.d.mts",
25
+ "default": "./dist/index.mjs"
26
+ },
27
+ "./package.json": "./package.json"
28
+ },
29
+ "files": [
30
+ "dist",
31
+ "src",
32
+ "oclif.config.js",
33
+ "oclif.manifest.json"
34
+ ],
35
+ "dependencies": {
36
+ "@oclif/core": "4.8.0",
37
+ "execa": "9.6.1",
38
+ "rimraf": "6.1.2",
39
+ "@jpp-toolkit/core": "0.0.11",
40
+ "@jpp-toolkit/utils": "0.0.11"
41
+ },
42
+ "devDependencies": {
43
+ "oclif": "4.22.52"
44
+ },
45
+ "engines": {
46
+ "node": "24",
47
+ "pnpm": "10"
48
+ },
49
+ "volta": {
50
+ "extends": "../../package.json"
51
+ },
52
+ "publishConfig": {
53
+ "access": "public"
54
+ },
55
+ "scripts": {
56
+ "typecheck": "tsc --noEmit --pretty",
57
+ "dev": "build-lib --watch",
58
+ "build": "build-lib"
59
+ }
60
+ }
@@ -0,0 +1,95 @@
1
+ import path from 'node:path';
2
+
3
+ import { Command } from '@jpp-toolkit/core';
4
+ import { findProjectRoot } from '@jpp-toolkit/utils';
5
+ import { Flags } from '@oclif/core';
6
+ import { execa } from 'execa';
7
+ import { rimraf } from 'rimraf';
8
+
9
+ const RESET_PATTERNS = ['!old', '!tmp'];
10
+ const CLEAN_PATTERNS = [
11
+ ...RESET_PATTERNS,
12
+ '!node_modules',
13
+ '!node_modules/**',
14
+ '**/node_modules/.cache',
15
+ '!**/hooks/_',
16
+ '!**/hooks/_/**',
17
+ '!.env',
18
+ ];
19
+
20
+ export class CleanCommand extends Command {
21
+ static override summary = 'Remove build artifacts and temporary files from the project.';
22
+
23
+ static override flags = {
24
+ 'dry-run': Flags.boolean({
25
+ char: 'd',
26
+ description: 'Perform a dry run without deleting files.',
27
+ default: false,
28
+ }),
29
+ 'reset': Flags.boolean({
30
+ char: 'r',
31
+ description: 'Reset the project to a clean state.',
32
+ default: false,
33
+ }),
34
+ 'root': Flags.boolean({
35
+ char: 'R',
36
+ description: 'Clean from the project root directory.',
37
+ default: false,
38
+ }),
39
+ };
40
+
41
+ static override examples = [
42
+ {
43
+ description: 'Perform a dry run of the clean command.',
44
+ command: '<%= config.bin %> <%= command.id %> --dry-run',
45
+ },
46
+ {
47
+ description: 'Reset the project to a clean state.',
48
+ command: '<%= config.bin %> <%= command.id %> --reset',
49
+ },
50
+ {
51
+ description: 'Clean from the project root directory.',
52
+ command: '<%= config.bin %> <%= command.id %> --root',
53
+ },
54
+ ];
55
+
56
+ public async run(): Promise<void> {
57
+ const { flags } = await this.parse(CleanCommand);
58
+
59
+ const cwd = flags.root ? findProjectRoot() : process.cwd();
60
+ const patterns = flags.reset ? RESET_PATTERNS : CLEAN_PATTERNS;
61
+
62
+ const { stdout } = await execa(
63
+ 'git',
64
+ [
65
+ 'ls-files',
66
+ '--others',
67
+ '--ignored',
68
+ '--exclude-standard',
69
+ '--directory',
70
+ ...patterns.map((pattern) => `--exclude=${pattern}`),
71
+ ],
72
+ { cwd, lines: true },
73
+ );
74
+
75
+ const paths = stdout
76
+ .filter((line) => line.trim().length > 0)
77
+ .map((filePath) => path.resolve(cwd, filePath));
78
+
79
+ if (paths.length === 0) {
80
+ this.logger.info('No files to clean');
81
+ return;
82
+ }
83
+
84
+ if (flags['dry-run']) {
85
+ this.logger.info('The following files would be removed:');
86
+ this.logger.paths(paths);
87
+ return;
88
+ }
89
+
90
+ await rimraf(paths);
91
+
92
+ this.logger.success('Cleaned the following files:');
93
+ this.logger.paths(paths);
94
+ }
95
+ }
package/src/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { CleanCommand } from './clean-command';
2
+
3
+ export const commands = {
4
+ clean: CleanCommand,
5
+ };