From 523c2c08977c050809145d454cf507fbfd424855 Mon Sep 17 00:00:00 2001 From: Vordgi Date: Thu, 18 Apr 2024 22:14:31 +0400 Subject: [PATCH 1/2] cm-23 add disabledistdeletion option --- src/lib/types/plugin.ts | 1 + src/lib/validateDist.ts | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/lib/types/plugin.ts b/src/lib/types/plugin.ts index 6c6d3a5..24673b8 100644 --- a/src/lib/types/plugin.ts +++ b/src/lib/types/plugin.ts @@ -3,4 +3,5 @@ export type Config = { distDir?: string; prefix?: string; reservedNames?: string[]; + disableDistDeletion?: boolean; }; diff --git a/src/lib/validateDist.ts b/src/lib/validateDist.ts index 1706bd2..752622e 100644 --- a/src/lib/validateDist.ts +++ b/src/lib/validateDist.ts @@ -13,7 +13,7 @@ const readManifest = (manifestPath: string) => { }; const validateDist = (pluginOptions: Config) => { - const { cacheDir, distDir, prefix, reservedNames } = pluginOptions; + const { cacheDir, distDir, prefix, reservedNames, disableDistDeletion } = pluginOptions; if (!cacheDir || !distDir) { console.log( @@ -56,9 +56,13 @@ const validateDist = (pluginOptions: Config) => { configurationError = `Can not find the package cache manifest at ${manifestPath}\n`; } if (configurationError) { - console.log(`classnames-minifier: ${configurationError}Cleaning the dist folder...`); - fs.rmSync(distDir, { recursive: true, force: true }); - console.log("classnames-minifier: Dist folder cleared"); + if (!disableDistDeletion) { + console.log(`classnames-minifier: ${configurationError}Cleaning the dist folder...`); + fs.rmSync(distDir, { recursive: true, force: true }); + console.log("classnames-minifier: Dist folder cleared"); + } else { + console.log(`classnames-minifier: ${configurationError}"disableDistDeletion" option was set to true`); + } } if (!fs.existsSync(manifestDir)) fs.mkdirSync(manifestDir, { recursive: true }); fs.writeFileSync(manifestPath, JSON.stringify({ ...pluginOptions, version: CODE_VERSION }), { encoding: "utf-8" }); From b2dbf7d6e9a9f99a3551238cf2c192fb1c1aaf6f Mon Sep 17 00:00:00 2001 From: Vordgi Date: Thu, 18 Apr 2024 22:19:24 +0400 Subject: [PATCH 2/2] cm-23 describe disabledistdeletion option in readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3e3d52b..0aedff8 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ yarn add classnames-minifier * `reservedNames` - array of reserved names that should not be used by this package (must include prefix); * `cacheDir` - directory where this library will write the cache. Passing this parameter will enable caching. Use this option only if your framework really needs it; * `distDir` - directory where the project is being assembled. Used only when caching is enabled to synchronize caches between this library and the project; +* `disableDistDeletion` - option that allows you to disable the automatic deletion of the dist folder if necessary (*f.e. differences in package setup in cache and now or first launch*); Configuration example: ```js