From c10df701ba6d6000356c2b295b4d3c38a0328de7 Mon Sep 17 00:00:00 2001 From: Amine Bouzahar Date: Thu, 25 Jul 2024 16:58:52 +0200 Subject: [PATCH] feat: fix scripts addscope missing --- package.json | 3 ++- tools/cleanup.js | 38 ++++++++++++++++++++++++++++++++++++++ tools/packagejson.js | 25 +++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 tools/cleanup.js create mode 100644 tools/packagejson.js diff --git a/package.json b/package.json index 9fa258f..0457614 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "advanced-color-utils", + "name": "@aminekun90/advanced-color-utils", "version": "1.0.1", "description": "Unleash the full potential of color manipulation with the ColorUtils library! Designed for developers who need precise control over color processing", "main": "dist/ColorUtils.js", @@ -8,6 +8,7 @@ "start": "ts-node -r tsconfig-paths/register src/index.ts", "test": "jest --no-cache --runInBand", "test:cov": "jest --coverage --no-cache --runInBand", + "addscope": "node tools/packagejson name @aminekun90/advanced-color-utils", "build": "tsc" }, "author": "aminekun90", diff --git a/tools/cleanup.js b/tools/cleanup.js new file mode 100644 index 0000000..e0c9003 --- /dev/null +++ b/tools/cleanup.js @@ -0,0 +1,38 @@ +/* eslint-disable */ +const fs = require('fs') +const Path = require('path') +/* eslint-enable */ + +const allowedDirectories = [Path.join(__dirname, '../dist')]; // Define allowed directories + +const deleteFolderRecursive = (dirPath) => { + const sanitizedPath = Path.resolve(dirPath); + + if (!allowedDirectories.some(directory => sanitizedPath.includes(directory))) { + console.error('Invalid path.'); // Input path is not in the allowed directories + return; + } + + if (fs.existsSync(sanitizedPath)) { + fs.readdirSync(sanitizedPath).forEach((file) => { + const curPath = Path.join(sanitizedPath, file); + if (fs.lstatSync(curPath).isDirectory()) { + deleteFolderRecursive(curPath); + } else { + fs.unlinkSync(curPath); + } + }); + fs.rmdirSync(sanitizedPath); + } +}; + +const folder = process.argv.slice(2)[0] + +if (folder) { + deleteFolderRecursive(Path.join(__dirname, '../dist', folder)) +} else { + deleteFolderRecursive(Path.join(__dirname, '../dist/cjs')) + deleteFolderRecursive(Path.join(__dirname, '../dist/esm')) + deleteFolderRecursive(Path.join(__dirname, '../dist/umd')) + deleteFolderRecursive(Path.join(__dirname, '../dist/types')) +} diff --git a/tools/packagejson.js b/tools/packagejson.js new file mode 100644 index 0000000..9f5bc92 --- /dev/null +++ b/tools/packagejson.js @@ -0,0 +1,25 @@ +/* eslint-disable */ +const fs = require('fs') +const Path = require('path') +const fileName = '../package.json' +const file = require(fileName) +/* eslint-enable */ + +const args = process.argv.slice(2) + +for (let i = 0, l = args.length; i < l; i++) { + if (i % 2 === 0) { + file[args[i]] = args[i + 1] + } +} + +fs.writeFile( + Path.join(__dirname, fileName), + JSON.stringify(file, null, 2), + (err) => { + if (err) { + return console.log(err) + } + console.log('Writing to ' + fileName) + } +)