Skip to content

Commit

Permalink
Merge pull request #24 from vordgi/cm-23
Browse files Browse the repository at this point in the history
cm-23 add disabledistdeletion option
  • Loading branch information
vordgi authored Apr 18, 2024
2 parents 48d651e + b2dbf7d commit 1d09c55
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/lib/types/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export type Config = {
distDir?: string;
prefix?: string;
reservedNames?: string[];
disableDistDeletion?: boolean;
};
12 changes: 8 additions & 4 deletions src/lib/validateDist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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" });
Expand Down

0 comments on commit 1d09c55

Please sign in to comment.