Compare commits

...
4 Commits
Author SHA1 Message Date
Benjamin Toby ab998dc531 Updates 2025-01-16 08:16:27 +01:00
Benjamin Toby c358cc8f26 Updates 2025-01-16 07:45:52 +01:00
Benjamin Toby 7c34ff6be7 Updates 2025-01-16 07:24:44 +01:00
Benjamin Toby de8191edca Updates 2025-01-16 07:24:22 +01:00
8 changed files with 85 additions and 31 deletions
+2
View File
@@ -0,0 +1,2 @@
@moduletrace:registry=https://git.tben.me/api/packages/moduletrace/npm/
//git.tben.me/api/packages/moduletrace/npm/:_authToken=${GITBEN_NPM_TOKEN}
+9
View File
@@ -0,0 +1,9 @@
#!/usr/bin/env node
export type LessCssWatcherConfigObject = {
src?: string | string[];
dst?: string | string[];
srcDst?: {
src?: string;
dst?: string;
}[];
};
+31 -2
View File
@@ -1,4 +1,4 @@
#! /usr/bin/env node #!/usr/bin/env node
"use strict"; "use strict";
var __importDefault = (this && this.__importDefault) || function (mod) { var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod }; return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -74,6 +74,9 @@ const grabSrcDisStrings = () => {
process.exit(); process.exit();
} }
} }
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
return { return {
sourceFile: srcArray.join(","), sourceFile: srcArray.join(","),
destinationFile: dstArray.join(","), destinationFile: dstArray.join(","),
@@ -83,11 +86,20 @@ const { sourceFile, destinationFile } = grabSrcDisStrings();
if (sourceFile && destinationFile) { if (sourceFile && destinationFile) {
process.argv.push("--src", sourceFile, "--dst", destinationFile); process.argv.push("--src", sourceFile, "--dst", destinationFile);
} }
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
console.log("- \x1b[35mStart:\x1b[0m Running Less compiler ..."); console.log("- \x1b[35mStart:\x1b[0m Running Less compiler ...");
if (!sourceFile || !destinationFile) { if (!sourceFile || !destinationFile) {
console.log("- \x1b[31mERROR:\x1b[0m => Missing source or destination file"); console.log("- \x1b[31mERROR:\x1b[0m => Missing source or destination file");
process.exit(); process.exit();
} }
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
/**
* Loop through source files and destination files and run the compile function
*/
function traverseFiles(src, dst) { function traverseFiles(src, dst) {
var _a; var _a;
const sourceFiles = src.split(","); const sourceFiles = src.split(",");
@@ -196,6 +208,16 @@ function traverseFiles(src, dst) {
} }
} }
traverseFiles(sourceFile, destinationFile); traverseFiles(sourceFile, destinationFile);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
/**
* Compile less file to css function
* @param fileName - less file path or folder path
* @param dst - destination file path or folder path
* @param evtType - event type (change, rename, etc.) or null
* @returns
*/
function compile(fileName, dst, evtType) { function compile(fileName, dst, evtType) {
if ((fileName === null || fileName === void 0 ? void 0 : fileName.match(/\(/)) || if ((fileName === null || fileName === void 0 ? void 0 : fileName.match(/\(/)) ||
(fileName.match(/\.[\/]$/) && !(fileName === null || fileName === void 0 ? void 0 : fileName.match(/\.less$/i)))) { (fileName.match(/\.[\/]$/) && !(fileName === null || fileName === void 0 ? void 0 : fileName.match(/\.less$/i)))) {
@@ -220,8 +242,9 @@ function compile(fileName, dst, evtType) {
finalSrcPath = fileName; finalSrcPath = fileName;
finalDstPath = targetDstFilePath; finalDstPath = targetDstFilePath;
} }
const executionCmd = `lessc ${finalSrcPath} ${finalDstPath}`; const executionCmd = `npx lessc ${finalSrcPath} ${finalDstPath}`;
(0, child_process_1.exec)(executionCmd, (error, stdout, stderr) => { (0, child_process_1.exec)(executionCmd, (error, stdout, stderr) => {
/** @type {Error} */
if (error) { if (error) {
console.log("- \x1b[33mWarn:\x1b[0m Compilation didn't run successfully. ERROR =>", error.message); console.log("- \x1b[33mWarn:\x1b[0m Compilation didn't run successfully. ERROR =>", error.message);
if (!(evtType === null || evtType === void 0 ? void 0 : evtType.match(/change/i)) && if (!(evtType === null || evtType === void 0 ? void 0 : evtType.match(/change/i)) &&
@@ -234,6 +257,12 @@ function compile(fileName, dst, evtType) {
console.log("- \x1b[32mCompiled:\x1b[0m Less Compilation Successful!"); console.log("- \x1b[32mCompiled:\x1b[0m Less Compilation Successful!");
}); });
} }
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
/**
* watch for changes to the config file
*/
if (fs_1.default.existsSync("./lesscw.config.json")) { if (fs_1.default.existsSync("./lesscw.config.json")) {
fs_1.default.watchFile("./lesscw.config.json", { interval: 500 }, (evtType, fileName) => { fs_1.default.watchFile("./lesscw.config.json", { interval: 500 }, (evtType, fileName) => {
console.log("- \x1b[34mInfo:\x1b[0m Restarting process..."); console.log("- \x1b[34mInfo:\x1b[0m Restarting process...");
+1
View File
File diff suppressed because one or more lines are too long
+29 -28
View File
@@ -1,30 +1,31 @@
{ {
"name": "lessc-watcher", "name": "@moduletrace/less-watcher",
"version": "1.2.2", "version": "1.0.3",
"description": "A minimal package to watch less files and compile them to css", "description": "A minimal package to watch less files and compile them to css",
"main": "dist/index.js", "main": "dist/index.js",
"bin": { "bin": {
"lessc-watcher": "./dist/index.js" "lessc-watcher": "dist/index.js",
}, "less-watcher": "dist/index.js"
"repository": { },
"type": "git", "repository": {
"url": "git+https://github.com/BenjaminToby/less-watcher.git" "type": "git",
}, "url": "https://git.tben.me/Moduletrace/less-watcher.git"
"keywords": [ },
"less", "keywords": [
"watcher", "less",
"css" "watcher",
], "css"
"author": "Benjamin Toby", ],
"license": "MIT", "author": "Benjamin Toby",
"devDependencies": { "license": "MIT",
"@types/node": "^20.4.5", "devDependencies": {
"@types/bun": "latest" "@types/node": "^20.4.5",
}, "@types/bun": "latest"
"dependencies": { },
"less": "^4.2.0" "dependencies": {
}, "less": "^4.2.0"
"peerDependencies": { },
"typescript": "^5.0.0" "peerDependencies": {
} "typescript": "^5.0.0"
}
} }
Regular → Executable
View File
Executable
+10
View File
@@ -0,0 +1,10 @@
#!/bin/bash
if command -v bun >/dev/null 2>&1; then
exec bun dist/index.js "$@"
elif command -v node >/dev/null 2>&1; then
exec node dist/index.js "$@"
else
echo "Neither Bun nor Node.js is installed."
exit 1
fi
+2
View File
@@ -1,3 +1,5 @@
#!/usr/bin/env node
import fs from "fs"; import fs from "fs";
import { exec } from "child_process"; import { exec } from "child_process";