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";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -74,6 +74,9 @@ const grabSrcDisStrings = () => {
process.exit();
}
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
return {
sourceFile: srcArray.join(","),
destinationFile: dstArray.join(","),
@@ -83,11 +86,20 @@ const { sourceFile, destinationFile } = grabSrcDisStrings();
if (sourceFile && destinationFile) {
process.argv.push("--src", sourceFile, "--dst", destinationFile);
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
console.log("- \x1b[35mStart:\x1b[0m Running Less compiler ...");
if (!sourceFile || !destinationFile) {
console.log("- \x1b[31mERROR:\x1b[0m => Missing source or destination file");
process.exit();
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
/**
* Loop through source files and destination files and run the compile function
*/
function traverseFiles(src, dst) {
var _a;
const sourceFiles = src.split(",");
@@ -196,6 +208,16 @@ function traverseFiles(src, dst) {
}
}
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) {
if ((fileName === null || fileName === void 0 ? void 0 : fileName.match(/\(/)) ||
(fileName.match(/\.[\/]$/) && !(fileName === null || fileName === void 0 ? void 0 : fileName.match(/\.less$/i)))) {
@@ -220,8 +242,9 @@ function compile(fileName, dst, evtType) {
finalSrcPath = fileName;
finalDstPath = targetDstFilePath;
}
const executionCmd = `lessc ${finalSrcPath} ${finalDstPath}`;
const executionCmd = `npx lessc ${finalSrcPath} ${finalDstPath}`;
(0, child_process_1.exec)(executionCmd, (error, stdout, stderr) => {
/** @type {Error} */
if (error) {
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)) &&
@@ -234,6 +257,12 @@ function compile(fileName, dst, evtType) {
console.log("- \x1b[32mCompiled:\x1b[0m Less Compilation Successful!");
});
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
/**
* watch for changes to the config file
*/
if (fs_1.default.existsSync("./lesscw.config.json")) {
fs_1.default.watchFile("./lesscw.config.json", { interval: 500 }, (evtType, fileName) => {
console.log("- \x1b[34mInfo:\x1b[0m Restarting process...");
+1
View File
File diff suppressed because one or more lines are too long
+30 -29
View File
@@ -1,30 +1,31 @@
{
"name": "lessc-watcher",
"version": "1.2.2",
"description": "A minimal package to watch less files and compile them to css",
"main": "dist/index.js",
"bin": {
"lessc-watcher": "./dist/index.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/BenjaminToby/less-watcher.git"
},
"keywords": [
"less",
"watcher",
"css"
],
"author": "Benjamin Toby",
"license": "MIT",
"devDependencies": {
"@types/node": "^20.4.5",
"@types/bun": "latest"
},
"dependencies": {
"less": "^4.2.0"
},
"peerDependencies": {
"typescript": "^5.0.0"
}
}
"name": "@moduletrace/less-watcher",
"version": "1.0.3",
"description": "A minimal package to watch less files and compile them to css",
"main": "dist/index.js",
"bin": {
"lessc-watcher": "dist/index.js",
"less-watcher": "dist/index.js"
},
"repository": {
"type": "git",
"url": "https://git.tben.me/Moduletrace/less-watcher.git"
},
"keywords": [
"less",
"watcher",
"css"
],
"author": "Benjamin Toby",
"license": "MIT",
"devDependencies": {
"@types/node": "^20.4.5",
"@types/bun": "latest"
},
"dependencies": {
"less": "^4.2.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 { exec } from "child_process";